using helpers for selects

This commit is contained in:
Vlyan
2020-12-18 13:55:28 +01:00
parent 1ad9d639f2
commit 97060b5666
22 changed files with 138 additions and 102 deletions

View File

@@ -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}

View File

@@ -27,7 +27,7 @@ export class L5rBaseDie extends DiceTerm {
* @override
*/
static getResultLabel(result) {
return `<img src="${CONFIG.L5r5e.paths.assets}dices/default/${this.FACES[result].image}.svg" alt="${result}" />`;
return `<img src="${CONFIG.l5r5e.paths.assets}dices/default/${this.FACES[result].image}.svg" alt="${result}" />`;
}
/**

View File

@@ -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

View File

@@ -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}`),
};
});
}
}

View File

@@ -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;
}

View File

@@ -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" }],

View File

@@ -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;
}

View File

@@ -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" }],

View File

@@ -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.
}

View File

@@ -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" }],

View File

@@ -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" }],

View File

@@ -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",

View File

@@ -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" }],

View File

@@ -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;
}

View File

@@ -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" }],

View File

@@ -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