const for skills map, and raw 20 questions template

This commit is contained in:
Vlyan
2020-12-14 18:22:49 +01:00
parent 4870ad2302
commit 45ca9d1071
6 changed files with 597 additions and 19 deletions

View File

@@ -2,6 +2,7 @@
* L5R Dice picker dialog
* @extends {FormApplication}
*/
import { L5R5E } from "../l5r5e-config.js";
import { RollL5r5e } from "./roll.js";
export class DicePickerDialog extends FormApplication {
@@ -138,7 +139,7 @@ export class DicePickerDialog extends FormApplication {
name: "",
};
const cat = RollL5r5e.getCategoryForSkillId(skillId);
const cat = L5R5E.skills.get(skillId);
if (!cat) {
return;
}

View File

@@ -1,3 +1,4 @@
import { L5R5E } from "../l5r5e-config.js";
import { L5rBaseDie } from "./dietype/l5r-base-die.js";
/**
@@ -197,9 +198,7 @@ export class RollL5r5e extends Roll {
}
const skillName =
game.i18n.translations.l5r5e.skills?.[RollL5r5e.getCategoryForSkillId(this.l5r5e.skillId)]?.[
this.l5r5e.skillId
] || "";
game.i18n.translations.l5r5e.skills?.[L5R5E.skills.get(this.l5r5e.skillId)]?.[this.l5r5e.skillId] || "";
// Define chat data
const chatData = {
@@ -275,17 +274,6 @@ export class RollL5r5e extends Roll {
return create ? CONFIG.ChatMessage.entityClass.create(messageData, messageOptions) : messageData;
}
/**
* Return the categoryId for the skillId
* TODO in proper category helper ?
* @param skillId
*/
static getCategoryForSkillId(skillId) {
return Object.keys(game.i18n.translations.l5r5e.skills).find((e) => {
return !!game.i18n.translations.l5r5e.skills?.[e]?.[skillId];
});
}
/** @override */
static fromData(data) {
const roll = super.fromData(data);

View File

@@ -1,8 +1,39 @@
export const L5R5E = {};
L5R5E.stances = ["earth", "air", "water", "fire", "void"];
L5R5E.paths = {
assets: `systems/l5r5e/assets/`,
templates: `systems/l5r5e/templates/`,
};
L5R5E.stances = ["earth", "air", "water", "fire", "void"];
// Map SkillId - CategoryId
L5R5E.skills = new Map();
L5R5E.skills.set("aesthetics", "artisan");
L5R5E.skills.set("composition", "artisan");
L5R5E.skills.set("design", "artisan");
L5R5E.skills.set("smithing", "artisan");
L5R5E.skills.set("fitness", "martial");
L5R5E.skills.set("melee", "martial");
L5R5E.skills.set("ranged", "martial");
L5R5E.skills.set("unarmed", "martial");
L5R5E.skills.set("meditation", "martial");
L5R5E.skills.set("tactics", "martial");
L5R5E.skills.set("culture", "scholar");
L5R5E.skills.set("government", "scholar");
L5R5E.skills.set("medicine", "scholar");
L5R5E.skills.set("sentiment", "scholar");
L5R5E.skills.set("theology", "scholar");
L5R5E.skills.set("command", "social");
L5R5E.skills.set("courtesy", "social");
L5R5E.skills.set("games", "social");
L5R5E.skills.set("performance", "social");
L5R5E.skills.set("commerce", "trade");
L5R5E.skills.set("labor", "trade");
L5R5E.skills.set("seafaring", "trade");
L5R5E.skills.set("skulduggery", "trade");
L5R5E.skills.set("survival", "trade");

View File

@@ -10,6 +10,7 @@ import { ItemL5r5e } from "./items/item.js";
import { ItemSheetL5r5e } from "./items/item-sheet.js";
import { WeaponSheetL5r5e } from "./items/weapon-sheet.js";
import { FeatSheetL5r5e } from "./items/feat-sheet.js";
import { TwentyQuestionsDialog } from "./sheets/twenty-questions-dialog.js";
// Import Dice Types
@@ -46,6 +47,7 @@ Hooks.once("init", async function () {
// Add some helper classes in game
game.l5r5e = {
DicePickerDialog,
TwentyQuestionsDialog,
};
// Register custom system settings
@@ -88,8 +90,7 @@ Hooks.once("init", async function () {
});
Handlebars.registerHelper("localizeSkillId", function (skillName) {
const key =
"l5r5e.skills." + RollL5r5e.getCategoryForSkillId(skillName.toLowerCase()) + "." + skillName.toLowerCase();
const key = "l5r5e.skills." + L5R5E.skills.get(skillName.toLowerCase()) + "." + skillName.toLowerCase();
return game.i18n.localize(key);
});

View File

@@ -0,0 +1,120 @@
import { L5R5E } from "../l5r5e-config.js";
/**
* L5R Twenty Questions form
* @extends {FormApplication}
*/
export class TwentyQuestionsDialog extends FormApplication {
/**
* Assign the default options
* @override
*/
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id: "l5r5e-twenty-questions-dialog",
classes: ["l5r5e", "twenty-questions-dialog"],
template: CONFIG.L5r5e.paths.templates + "sheets/twenty-questions-dialog.html",
title: "L5R Twenty Questions", // TODO Localize
width: 600,
height: 600,
resizable: true,
});
}
/**
* Create dialog
*/
constructor(options = null) {
super(options);
}
/**
* Construct and return the data object used to render the HTML template for this form application.
* @param options
* @return {Object}
*/
getData(options = null) {
return {
...super.getData(options),
elementsList: this._getElements(),
skillsList: this._getSkills(),
};
}
/**
* Render the dialog
* @param force
* @param options
* @returns {Application}
*/
render(force, options) {
options = {
...options,
};
if (force === undefined) {
force = true;
}
return super.render(force, options);
}
/**
* Listen to html elements
* @override
*/
activateListeners(html) {
super.activateListeners(html);
// html.find('input[name="approach"]').on("click", async (event) => {});
}
/**
* This method is called upon form submission after form data is validated
* @param event The initial triggering submission event
* @param formData The object of validated form data with which to update the object
* @returns A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
// const ring = formData.ring || null;
// TODO
console.log(formData);
return;
// return this.close();
}
/**
* 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}`),
});
});
console.log(skills);
return skills;
}
}