From 97060b5666e480f19aad72840564f8e7c770997f Mon Sep 17 00:00:00 2001 From: Vlyan Date: Fri, 18 Dec 2020 13:55:28 +0100 Subject: [PATCH] using helpers for selects --- system/l5r-ui/scripts/help/l5rui-help.js | 2 +- system/scripts/dice/dice-picker-dialog.js | 20 +------ system/scripts/dice/dietype/l5r-base-die.js | 2 +- system/scripts/dice/roll.js | 4 +- system/scripts/helpers-l5r5e.js | 58 +++++++++++++++++++ system/scripts/items/advancement-sheet.js | 3 +- system/scripts/items/armor-sheet.js | 2 +- system/scripts/items/item-sheet.js | 18 +----- system/scripts/items/peculiarity-sheet.js | 2 +- system/scripts/items/quality-sheet.js | 3 +- system/scripts/items/technique-sheet.js | 2 +- system/scripts/items/weapon-sheet.js | 2 +- system/scripts/main-l5r5e.js | 6 +- system/scripts/sheets/actor-sheet.js | 2 +- system/scripts/sheets/base-sheet.js | 2 +- system/scripts/sheets/npc-sheet.js | 2 +- .../scripts/sheets/twenty-questions-dialog.js | 41 ++----------- system/template.json | 6 +- system/templates/dice/dice-picker-dialog.html | 2 +- system/templates/item/advancement-sheet.html | 47 ++++++++++++--- system/templates/item/peculiarity-sheet.html | 4 +- .../sheets/twenty-questions-dialog.html | 10 ++-- 22 files changed, 138 insertions(+), 102 deletions(-) create mode 100644 system/scripts/helpers-l5r5e.js diff --git a/system/l5r-ui/scripts/help/l5rui-help.js b/system/l5r-ui/scripts/help/l5rui-help.js index 3107a30..ca68b8d 100644 --- a/system/l5r-ui/scripts/help/l5rui-help.js +++ b/system/l5r-ui/scripts/help/l5rui-help.js @@ -37,7 +37,7 @@ Hooks.once("ready", async function () { //----logo image var logo = document.getElementById("logo"); - logo.setAttribute("src", CONFIG.L5r5e.paths.assets + "l5r-logo.webp"); + logo.setAttribute("src", CONFIG.l5r5e.paths.assets + "l5r-logo.webp"); //--------------ouvrir le menu lien sur click logo logo.setAttribute("title", "Aide en Ligne"); diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index 8a71dd6..0ff727b 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -42,7 +42,7 @@ export class DicePickerDialog extends FormApplication { return mergeObject(super.defaultOptions, { id: "l5r5e-dice-picker-dialog", classes: ["l5r5e", "dice-picker-dialog"], - template: CONFIG.L5r5e.paths.templates + "dice/dice-picker-dialog.html", + template: CONFIG.l5r5e.paths.templates + "dice/dice-picker-dialog.html", title: "L5R Dice Roller", width: 660, height: 460, @@ -120,7 +120,7 @@ export class DicePickerDialog extends FormApplication { * @param ringId */ set ringId(ringId) { - this._ringId = CONFIG.L5r5e.stances.includes(ringId) || null; + this._ringId = CONFIG.l5r5e.stances.includes(ringId) || null; } /** @@ -197,7 +197,7 @@ export class DicePickerDialog extends FormApplication { getData(options = null) { return { ...super.getData(options), - elementsList: this._getElements(), + ringsList: game.l5r5e.HelpersL5r5e.getRingsList(), dicesList: [0, 1, 2, 3, 4, 5, 6], skillData: this._skillData, actor: this._actor, @@ -386,20 +386,6 @@ export class DicePickerDialog extends FormApplication { return value; } - /** - * Load elements (id, label, value) - * @private - */ - _getElements() { - return CONFIG.L5r5e.stances.map((e) => { - return { - id: e, - label: game.i18n.localize(`l5r5e.rings.${e}`), - value: this._actor?.data?.data?.rings?.[e] || 0, - }; - }); - } - // /** // * Return a reference to the target attribute // * @type {String} diff --git a/system/scripts/dice/dietype/l5r-base-die.js b/system/scripts/dice/dietype/l5r-base-die.js index 29c8701..e8fd667 100644 --- a/system/scripts/dice/dietype/l5r-base-die.js +++ b/system/scripts/dice/dietype/l5r-base-die.js @@ -27,7 +27,7 @@ export class L5rBaseDie extends DiceTerm { * @override */ static getResultLabel(result) { - return `${result}`; + return `${result}`; } /** diff --git a/system/scripts/dice/roll.js b/system/scripts/dice/roll.js index db8e936..3da2f70 100644 --- a/system/scripts/dice/roll.js +++ b/system/scripts/dice/roll.js @@ -173,7 +173,7 @@ export class RollL5r5e extends Roll { displaySummary: contexte?.from !== "render", }; - return renderTemplate(CONFIG.L5r5e.paths.templates + this.constructor.TOOLTIP_TEMPLATE, { chatData }); + return renderTemplate(CONFIG.l5r5e.paths.templates + this.constructor.TOOLTIP_TEMPLATE, { chatData }); } /** @@ -185,7 +185,7 @@ export class RollL5r5e extends Roll { { user: game.user._id, flavor: null, - template: CONFIG.L5r5e.paths.templates + this.constructor.CHAT_TEMPLATE, + template: CONFIG.l5r5e.paths.templates + this.constructor.CHAT_TEMPLATE, blind: false, }, chatOptions diff --git a/system/scripts/helpers-l5r5e.js b/system/scripts/helpers-l5r5e.js new file mode 100644 index 0000000..5dd0d41 --- /dev/null +++ b/system/scripts/helpers-l5r5e.js @@ -0,0 +1,58 @@ +import { L5R5E } from "./l5r5e-config.js"; + +/** + * Extends the actor to process special things from L5R. + */ +export class HelpersL5r5e { + /** + * Get Rings/Element for List / Select + */ + static getRingsList() { + return L5R5E.stances.map((e) => { + return { + id: e, + label: game.i18n.localize(`l5r5e.rings.${e}`), + }; + }); + } + + /** + * Get Skills for List / Select with groups + */ + static getSkillsList(useGroup) { + if (!useGroup) { + return Array.from(L5R5E.skills).map(([id, cat]) => { + return { + id: id, + cat: cat, + label: game.i18n.localize(`l5r5e.skills.${cat}.${id}`), + }; + }); + } + + const skills = {}; + Array.from(L5R5E.skills).forEach(([id, cat]) => { + if (!skills[cat]) { + skills[cat] = []; + } + skills[cat].push({ + id: id, + cat: cat, + label: game.i18n.localize(`l5r5e.skills.${cat}.${id}`), + }); + }); + return skills; + } + + /** + * Get Techniques for List / Select + */ + static getTechniquesList() { + return L5R5E.techniques.map((e) => { + return { + id: e, + label: game.i18n.localize(`l5r5e.techniques.${e}`), + }; + }); + } +} diff --git a/system/scripts/items/advancement-sheet.js b/system/scripts/items/advancement-sheet.js index 2c42080..e6d6d45 100644 --- a/system/scripts/items/advancement-sheet.js +++ b/system/scripts/items/advancement-sheet.js @@ -13,7 +13,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "advancement"], - template: CONFIG.L5r5e.paths.templates + "item/advancement-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/advancement-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], @@ -25,6 +25,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e { sheetData.data.dtypes = ["String", "Number", "Boolean"]; sheetData.data.subTypesList = AdvancementSheetL5r5e.types; + sheetData.data.skillsList = game.l5r5e.HelpersL5r5e.getSkillsList(true); return sheetData; } diff --git a/system/scripts/items/armor-sheet.js b/system/scripts/items/armor-sheet.js index 8f47615..c632f6b 100644 --- a/system/scripts/items/armor-sheet.js +++ b/system/scripts/items/armor-sheet.js @@ -8,7 +8,7 @@ export class ArmorSheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "armor"], - template: CONFIG.L5r5e.paths.templates + "item/armor-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/armor-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/items/item-sheet.js b/system/scripts/items/item-sheet.js index dc577e6..2bcd552 100644 --- a/system/scripts/items/item-sheet.js +++ b/system/scripts/items/item-sheet.js @@ -7,7 +7,7 @@ export class ItemSheetL5r5e extends ItemSheet { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "item"], - template: CONFIG.L5r5e.paths.templates + "item/item-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/item-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], @@ -18,20 +18,8 @@ export class ItemSheetL5r5e extends ItemSheet { const sheetData = super.getData(); sheetData.data.dtypes = ["String", "Number", "Boolean"]; - - sheetData.data.ringsList = CONFIG.L5r5e.stances.map((e) => { - return { - id: e, - label: game.i18n.localize(`l5r5e.rings.${e}`), - }; - }); - - sheetData.data.techniquesList = CONFIG.L5r5e.techniques.map((e) => { - return { - id: e, - label: game.i18n.localize(`l5r5e.techniques.${e}`), - }; - }); + sheetData.data.ringsList = game.l5r5e.HelpersL5r5e.getRingsList(); + sheetData.data.techniquesList = game.l5r5e.HelpersL5r5e.getTechniquesList(); return sheetData; } diff --git a/system/scripts/items/peculiarity-sheet.js b/system/scripts/items/peculiarity-sheet.js index 5046647..8bb631c 100644 --- a/system/scripts/items/peculiarity-sheet.js +++ b/system/scripts/items/peculiarity-sheet.js @@ -14,7 +14,7 @@ export class PeculiaritySheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "peculiarity"], - template: CONFIG.L5r5e.paths.templates + "item/peculiarity-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/peculiarity-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/items/quality-sheet.js b/system/scripts/items/quality-sheet.js index 76436a4..4680c74 100644 --- a/system/scripts/items/quality-sheet.js +++ b/system/scripts/items/quality-sheet.js @@ -8,10 +8,11 @@ export class QualitySheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "quality"], - template: CONFIG.L5r5e.paths.templates + "item/quality-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/quality-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], }); } + // TODO certain propriétés en annule d'autres : aiguisé <-> abimé. voir comment faire. } diff --git a/system/scripts/items/technique-sheet.js b/system/scripts/items/technique-sheet.js index dbe6dbe..612412b 100644 --- a/system/scripts/items/technique-sheet.js +++ b/system/scripts/items/technique-sheet.js @@ -8,7 +8,7 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "technique"], - template: CONFIG.L5r5e.paths.templates + "item/technique-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/technique-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/items/weapon-sheet.js b/system/scripts/items/weapon-sheet.js index df9008e..19af0e5 100644 --- a/system/scripts/items/weapon-sheet.js +++ b/system/scripts/items/weapon-sheet.js @@ -9,7 +9,7 @@ export class WeaponSheetL5r5e extends ItemSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "weapon"], - template: CONFIG.L5r5e.paths.templates + "item/weapon-sheet.html", + template: CONFIG.l5r5e.paths.templates + "item/weapon-sheet.html", width: 520, height: 480, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/main-l5r5e.js b/system/scripts/main-l5r5e.js index 920b0d2..86ca443 100644 --- a/system/scripts/main-l5r5e.js +++ b/system/scripts/main-l5r5e.js @@ -1,5 +1,6 @@ // Import Modules import { L5R5E } from "./l5r5e-config.js"; +import { HelpersL5r5e } from "./helpers-l5r5e.js"; import { RegisterSettings } from "./settings.js"; import { PreloadTemplates } from "./preloadTemplates.js"; import { ActorL5r5e } from "./actor-l5r5e.js"; @@ -32,7 +33,7 @@ Hooks.once("init", async function () { ); // Global access to L5R Config - CONFIG.L5r5e = L5R5E; + CONFIG.l5r5e = L5R5E; // Assign custom classes and constants here CONFIG.Actor.entityClass = ActorL5r5e; @@ -49,6 +50,7 @@ Hooks.once("init", async function () { // Add some helper classes in game game.l5r5e = { + HelpersL5r5e, DicePickerDialog, }; @@ -191,7 +193,7 @@ Hooks.on("renderSidebarTab", (app, html, data) => { /* DiceSoNice Hook */ /* ------------------------------------ */ Hooks.once("diceSoNiceReady", (dice3d) => { - const texturePath = `${CONFIG.L5r5e.paths.assets}dices/default/3d/`; + const texturePath = `${CONFIG.l5r5e.paths.assets}dices/default/3d/`; // dice3d.addSystem({ // id: "l5r5e", diff --git a/system/scripts/sheets/actor-sheet.js b/system/scripts/sheets/actor-sheet.js index ea914dd..60f56be 100644 --- a/system/scripts/sheets/actor-sheet.js +++ b/system/scripts/sheets/actor-sheet.js @@ -8,7 +8,7 @@ export class ActorSheetL5r5e extends BaseSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "actor"], - template: CONFIG.L5r5e.paths.templates + "sheets/actor-sheet.html", + template: CONFIG.l5r5e.paths.templates + "sheets/actor-sheet.html", width: 600, height: 800, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/sheets/base-sheet.js b/system/scripts/sheets/base-sheet.js index b2023ee..e534694 100644 --- a/system/scripts/sheets/base-sheet.js +++ b/system/scripts/sheets/base-sheet.js @@ -9,7 +9,7 @@ export class BaseSheetL5r5e extends ActorSheet { const sheetData = super.getData(); sheetData.data.dtypes = ["String", "Number", "Boolean"]; - sheetData.data.stances = CONFIG.L5r5e.stances; + sheetData.data.stances = CONFIG.l5r5e.stances; return sheetData; } diff --git a/system/scripts/sheets/npc-sheet.js b/system/scripts/sheets/npc-sheet.js index e80317a..d6550ac 100644 --- a/system/scripts/sheets/npc-sheet.js +++ b/system/scripts/sheets/npc-sheet.js @@ -9,7 +9,7 @@ export class NpcSheetL5r5e extends BaseSheetL5r5e { static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["l5r5e", "sheet", "npc"], - template: CONFIG.L5r5e.paths.templates + "sheets/npc-sheet.html", + template: CONFIG.l5r5e.paths.templates + "sheets/npc-sheet.html", width: 600, height: 800, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }], diff --git a/system/scripts/sheets/twenty-questions-dialog.js b/system/scripts/sheets/twenty-questions-dialog.js index c9b852d..bfbdd3a 100644 --- a/system/scripts/sheets/twenty-questions-dialog.js +++ b/system/scripts/sheets/twenty-questions-dialog.js @@ -24,7 +24,7 @@ export class TwentyQuestionsDialog extends FormApplication { return mergeObject(super.defaultOptions, { id: "l5r5e-twenty-questions-dialog", classes: ["l5r5e", "twenty-questions-dialog"], - template: CONFIG.L5r5e.paths.templates + "sheets/twenty-questions-dialog.html", + template: CONFIG.l5r5e.paths.templates + "sheets/twenty-questions-dialog.html", title: game.i18n.localize("l5r5e.twenty_questions.title"), width: 600, height: 600, @@ -77,11 +77,12 @@ export class TwentyQuestionsDialog extends FormApplication { * @return {Object} */ getData(options = null) { + console.log(game.l5r5e.HelpersL5r5e.getRingsList()); return { ...super.getData(options), - elementsList: this._getElements(), - skillsList: this._getSkills(), - techniquesList: CONFIG.L5r5e.techniques, + ringsList: game.l5r5e.HelpersL5r5e.getRingsList(), + skillsList: game.l5r5e.HelpersL5r5e.getSkillsList(true), + techniquesList: CONFIG.l5r5e.techniques, datas: this.datas, }; } @@ -245,38 +246,6 @@ export class TwentyQuestionsDialog extends FormApplication { }, new Map()); } - /** - * Load elements list (id, label) - * @private - */ - _getElements() { - return CONFIG.L5r5e.stances.map((e) => { - return { - id: e, - label: game.i18n.localize(`l5r5e.rings.${e}`), - }; - }); - } - - /** - * Load Skills list (id, cat, label) - * @private - */ - _getSkills() { - const skills = {}; - Array.from(L5R5E.skills).forEach(([id, cat]) => { - if (!skills[cat]) { - skills[cat] = []; - } - skills[cat].push({ - id: id, - cat: cat, - label: game.i18n.localize(`l5r5e.skills.${cat}.${id}`), - }); - }); - return skills; - } - /** * Initialize form array * @private diff --git a/system/template.json b/system/template.json index 6b91568..38b4d43 100644 --- a/system/template.json +++ b/system/template.json @@ -140,7 +140,8 @@ "in_curriculum": false, "xp_used": 0, "rank": 1, - "bought_at_rank": 1 + "bought_at_rank": 1, + "ring": "void" }, "item": { "equipped": false, @@ -177,7 +178,6 @@ "technique": { "templates": ["advancement"], "technique_type": "", - "ring": "void", "effects": "", "description": "" }, @@ -187,13 +187,13 @@ "peculiarity": { "templates": ["advancement"], "peculiarity_type": "distinction", - "ring": "void", "types": "", "description": "" }, "advancement": { "templates": ["advancement"], "advancement_type": "", + "skill": "", "description": "" } } diff --git a/system/templates/dice/dice-picker-dialog.html b/system/templates/dice/dice-picker-dialog.html index 0fc28d3..87026d9 100644 --- a/system/templates/dice/dice-picker-dialog.html +++ b/system/templates/dice/dice-picker-dialog.html @@ -13,7 +13,7 @@