Begin work on the fate path dropdown
This commit is contained in:
parent
edd4e49f62
commit
f6ca694dcc
10 changed files with 82 additions and 21 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { filePath } from "../../consts.mjs";
|
||||
import { gameTerms } from "../../gameTerms.mjs";
|
||||
import { Logger } from "../../utils/Logger.mjs";
|
||||
|
||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||
|
|
@ -43,10 +45,25 @@ export class HeroSummaryCardV1 extends HandlebarsApplicationMixin(ActorSheetV2)
|
|||
|
||||
ctx.actor = this.document;
|
||||
|
||||
ctx = await this._prepareFatePath(ctx);
|
||||
|
||||
partId = partId.slice(0,1).toUpperCase() + partId.slice(1);
|
||||
if (this[`_prepare${partId}Context`] != null) {
|
||||
ctx = await this[`_prepare${partId}Context`](ctx, opts);
|
||||
};
|
||||
|
||||
Logger.debug(`Context:`, ctx);
|
||||
return ctx;
|
||||
};
|
||||
|
||||
async _prepareFatePath(ctx) {
|
||||
ctx.fate = {};
|
||||
ctx.fate.selected = ctx.actor.system.fate;
|
||||
ctx.fate.options = [
|
||||
{ label: `RipCrypt.common.empty`, v: `` },
|
||||
...gameTerms.FatePath
|
||||
.map(v => ({ label: `RipCrypt.common.fate.${v}`, value: v })),
|
||||
];
|
||||
return ctx;
|
||||
};
|
||||
// #endregion
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { FatePath } from "../../gameTerms.mjs";
|
||||
import { gameTerms } from "../../gameTerms.mjs";
|
||||
|
||||
const { fields } = foundry.data;
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ export class HeroData extends foundry.abstract.TypeDataModel {
|
|||
trim: true,
|
||||
nullable: false,
|
||||
choices: () => {
|
||||
return Object.values(FatePath).concat(``);
|
||||
return gameTerms.FatePath.concat(``);
|
||||
},
|
||||
}),
|
||||
level: new fields.SchemaField({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
export const FatePath = {
|
||||
NORTH: `North`,
|
||||
EAST: `East`,
|
||||
SOUTH: `South`,
|
||||
WEST: `West`,
|
||||
};
|
||||
export const gameTerms = Object.preventExtensions({
|
||||
FatePath: [
|
||||
`North`,
|
||||
`East`,
|
||||
`South`,
|
||||
`West`,
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ import { localizer } from "../utils/Localizer.mjs";
|
|||
* @param {any} meta
|
||||
*/
|
||||
export function options(selected, opts, meta) {
|
||||
const { localize = false } = meta;
|
||||
const { localize = false } = meta.hash;
|
||||
selected = Handlebars.escapeExpression(selected);
|
||||
|
||||
const htmlOptions = [];
|
||||
|
||||
for (let opt of opts) {
|
||||
|
|
@ -33,4 +32,5 @@ export function options(selected, opts, meta) {
|
|||
</option>`,
|
||||
);
|
||||
};
|
||||
return new Handlebars.SafeString(htmlOptions.join(`\n`));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { registerDevSettings } from "../settings/devSettings.mjs";
|
|||
import { CryptDie } from "../dice/CryptDie.mjs";
|
||||
|
||||
// Misc
|
||||
import helpers from "../handlebarHelpers/_index.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
|
||||
Hooks.once(`init`, () => {
|
||||
|
|
@ -35,4 +36,6 @@ Hooks.once(`init`, () => {
|
|||
});
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
Handlebars.registerHelper(helpers);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { localizerConfig } from "../config.mjs";
|
||||
const config = Object.preventExtensions({
|
||||
subKeyPattern: /@(?<key>[a-zA-Z.]+)/gm,
|
||||
maxDepth: 10,
|
||||
});
|
||||
|
||||
export function handlebarsLocalizer(key, ...args) {
|
||||
let data = args[0];
|
||||
|
|
@ -11,10 +14,10 @@ export function handlebarsLocalizer(key, ...args) {
|
|||
export function localizer(key, args = {}, depth = 0) {
|
||||
/** @type {string} */
|
||||
let localized = game.i18n.format(key, args);
|
||||
const subkeys = localized.matchAll(localizerConfig.subKeyPattern);
|
||||
const subkeys = localized.matchAll(config.subKeyPattern);
|
||||
|
||||
// Short-cut to help prevent infinite recursion
|
||||
if (depth > localizerConfig.maxDepth) {
|
||||
if (depth > config.maxDepth) {
|
||||
return localized;
|
||||
};
|
||||
|
||||
|
|
@ -29,7 +32,7 @@ export function localizer(key, args = {}, depth = 0) {
|
|||
};
|
||||
|
||||
return localized.replace(
|
||||
localizerConfig.subKeyPattern,
|
||||
config.subKeyPattern,
|
||||
(_fullMatch, subkey) => {
|
||||
return localizedSubkeys.get(subkey);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue