Added symbols converter

Updated packs
This commit is contained in:
Vlyan
2020-12-28 19:03:29 +01:00
parent b057746ae5
commit fe6508e76a
20 changed files with 306 additions and 102 deletions

View File

@@ -44,3 +44,40 @@ L5R5E.skills.set("labor", "trade");
L5R5E.skills.set("seafaring", "trade");
L5R5E.skills.set("skulduggery", "trade");
L5R5E.skills.set("survival", "trade");
// Symbols Map
L5R5E.symbols = new Map();
L5R5E.symbols.set("(op)", { class: "i_opportunity", label: "l5r5e.chatdices.opportunities" });
L5R5E.symbols.set("(su)", { class: "i_success", label: "l5r5e.chatdices.successes" });
L5R5E.symbols.set("(ex)", { class: "i_explosive", label: "l5r5e.chatdices.explosives" });
L5R5E.symbols.set("(st)", { class: "i_strife", label: "l5r5e.chatdices.strives" });
L5R5E.symbols.set("(earth)", { class: "i_earth", label: "l5r5e.rings.earth" });
L5R5E.symbols.set("(water)", { class: "i_water", label: "l5r5e.rings.water" });
L5R5E.symbols.set("(fire)", { class: "i_fire", label: "l5r5e.rings.fire" });
L5R5E.symbols.set("(air)", { class: "i_air", label: "l5r5e.rings.air" });
L5R5E.symbols.set("(void)", { class: "i_void", label: "l5r5e.rings.void" });
L5R5E.symbols.set("(kiho)", { class: "i_kiho", label: "l5r5e.techniques.kiho" });
L5R5E.symbols.set("(maho)", { class: "i_maho", label: "l5r5e.techniques.maho" });
L5R5E.symbols.set("(ninjitsu)", { class: "i_ninjitsu", label: "l5r5e.techniques.ninjutsu" });
L5R5E.symbols.set("(ritual)", { class: "i_rituals", label: "l5r5e.techniques.ritual" });
L5R5E.symbols.set("(shuji)", { class: "i_shuji", label: "l5r5e.techniques.shuji" });
L5R5E.symbols.set("(invocation)", { class: "i_invocations", label: "l5r5e.techniques.invocation" });
L5R5E.symbols.set("(kata)", { class: "i_kata", label: "l5r5e.techniques.kata" });
L5R5E.symbols.set("(prereq)", { class: "i_prerequisite_exemption", label: "l5r5e.advancements.curriculum" });
L5R5E.symbols.set("(imperial)", { class: "i_imperial", label: "" });
L5R5E.symbols.set("(crab)", { class: "i_crab", label: "" });
L5R5E.symbols.set("(crane)", { class: "i_crane", label: "" });
L5R5E.symbols.set("(dragon)", { class: "i_dragon", label: "" });
L5R5E.symbols.set("(lion)", { class: "i_lion", label: "" });
L5R5E.symbols.set("(mantis)", { class: "i_mantis", label: "" });
L5R5E.symbols.set("(phoenix)", { class: "i_phoenix", label: "" });
L5R5E.symbols.set("(scorpion)", { class: "i_scorpion", label: "" });
L5R5E.symbols.set("(tortoise)", { class: "i_tortoise", label: "" });
L5R5E.symbols.set("(unicorn)", { class: "i_unicorn", label: "" });
L5R5E.symbols.set("(bushi)", { class: "i_bushi", label: "" });
L5R5E.symbols.set("(courtier)", { class: "i_courtier", label: "" });
L5R5E.symbols.set("(shugenja)", { class: "i_shugenja", label: "" });

View File

@@ -122,7 +122,7 @@ export class RollL5r5e extends Roll {
total +=
(this.l5r5e.dicesTypes.std ? " | " : "") +
["success", "explosive", "opportunity", "strife"]
.map((props) => (summary[props] > 0 ? `<i class="${props}"></i> ${summary[props]}` : null))
.map((props) => (summary[props] > 0 ? `<i class="i_${props}"></i> ${summary[props]}` : null))
.filter((c) => !!c)
.join(" | ");
}

View File

@@ -0,0 +1,49 @@
/**
* Base JournalSheet for L5R5e
* @extends {JournalSheet}
*/
export class BaseJournalSheetL5r5e extends JournalSheet {
/**
* Activate a named TinyMCE text editor
* @param {string} name The named data field which the editor modifies.
* @param {object} options TinyMCE initialization options passed to TextEditor.create
* @param {string} initialContent Initial text content for the editor area.
* @override
*/
activateEditor(name, options = {}, initialContent = "") {
if (initialContent) {
initialContent = this._convertSymbols(initialContent, false);
}
super.activateEditor(name, options, initialContent);
}
/**
* This method is called upon form submission after form data is validated
* @param event {Event} The initial triggering submission event
* @param formData {Object} The object of validated form data with which to update the object
* @returns {Promise} A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
// event.type = mcesave / submit
if (formData.content) {
formData.content = this._convertSymbols(formData.content, true);
}
return super._updateObject(event, formData);
}
/**
* Convert (op), (ex)... to associated symbols
* @private
*/
_convertSymbols(text, toSymbol) {
CONFIG.l5r5e.symbols.forEach((cfg, tag) => {
if (toSymbol) {
text = text.replace(tag, `<i class="${cfg.class}" title="${game.i18n.localize(cfg.label)}"></i>`);
} else {
text = text.replace(new RegExp(`<i class="${cfg.class}" title="[^"]*"></i>`, "gi"), tag);
}
});
return text;
}
}

View File

@@ -21,13 +21,16 @@ import { TechniqueSheetL5r5e } from "./items/technique-sheet.js";
import { PropertySheetL5r5e } from "./items/property-sheet.js";
import { AdvancementSheetL5r5e } from "./items/advancement-sheet.js";
import { PeculiaritySheetL5r5e } from "./items/peculiarity-sheet.js";
// JournalEntry
import { JournalL5r5e } from "./journal.js";
import { BaseJournalSheetL5r5e } from "./journals/base-journal-sheet.js";
/* ------------------------------------ */
/* Initialize system */
/* ------------------------------------ */
Hooks.once("init", async function () {
// console.log("L5R5e | Initializing l5r5e");
// Ascii art
// ***** Initializing l5r5e *****
// Ascii art :p
console.log(
" _ ___ ___ ___\n" +
" | | | __| _ \\ | __| ___ \n" +
@@ -36,6 +39,7 @@ Hooks.once("init", async function () {
" "
);
// ***** Config *****
// Global access to L5R Config
CONFIG.l5r5e = L5R5E;
@@ -43,6 +47,8 @@ Hooks.once("init", async function () {
CONFIG.Actor.entityClass = ActorL5r5e;
CONFIG.Actor.sheetClasses = CharacterSheetL5r5e;
CONFIG.Item.entityClass = ItemL5r5e;
CONFIG.JournalEntry.entityClass = JournalL5r5e;
CONFIG.JournalEntry.sheetClass = BaseJournalSheetL5r5e;
// Define custom Roll class
CONFIG.Dice.rolls.push(CONFIG.Dice.rolls[0]);
@@ -64,13 +70,13 @@ Hooks.once("init", async function () {
// Preload Handlebars templates
await PreloadTemplates();
// Register custom sheets (if any)
// Actors sheet
// ***** Register custom sheets *****
// Actors
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("l5r5e", CharacterSheetL5r5e, { types: ["character"], makeDefault: true });
Actors.registerSheet("l5r5e", NpcSheetL5r5e, { types: ["npc"], makeDefault: false });
Actors.registerSheet("l5r5e", NpcSheetL5r5e, { types: ["npc"], makeDefault: true });
// Items sheet
// Items
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("l5r5e", ItemSheetL5r5e, { types: ["item"], makeDefault: true });
Items.registerSheet("l5r5e", ArmorSheetL5r5e, { types: ["armor"], makeDefault: true });
@@ -80,6 +86,11 @@ Hooks.once("init", async function () {
Items.registerSheet("l5r5e", PeculiaritySheetL5r5e, { types: ["peculiarity"], makeDefault: true });
Items.registerSheet("l5r5e", AdvancementSheetL5r5e, { types: ["advancement"], makeDefault: true });
// Journal
Items.unregisterSheet("core", JournalSheet);
Items.registerSheet("l5r5e", BaseJournalSheetL5r5e, { makeDefault: true });
// ***** Handlebars *****
// for debug
Handlebars.registerHelper("json", function (...objects) {
objects.pop(); // remove this function call