Add functionality to the CryptApp to make it update/display the current difficulty, and rerender when it changes.
This commit is contained in:
parent
495dafaf12
commit
31033017f7
11 changed files with 125 additions and 11 deletions
|
|
@ -7,19 +7,31 @@ const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
|||
export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(ApplicationV2)) {
|
||||
// #region Options
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: [
|
||||
`ripcrypt--CryptApp`,
|
||||
],
|
||||
window: {
|
||||
title: `Crypt Overview`,
|
||||
title: `Crypt`,
|
||||
frame: true,
|
||||
positioned: true,
|
||||
resizable: false,
|
||||
minimizable: true,
|
||||
minimizable: false,
|
||||
},
|
||||
position: {
|
||||
width: 100,
|
||||
},
|
||||
actions: {},
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: filePath(`templates/Apps/CryptApp/main.hbs`),
|
||||
turnCount: {
|
||||
template: filePath(`templates/Apps/CryptApp/turnCount.hbs`),
|
||||
},
|
||||
delveConditions: {
|
||||
template: filePath(`templates/Apps/CryptApp/delveConditions.hbs`),
|
||||
},
|
||||
fate: {
|
||||
template: filePath(`templates/Apps/CryptApp/fate.hbs`),
|
||||
},
|
||||
};
|
||||
// #endregion
|
||||
|
|
@ -31,9 +43,49 @@ export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(Applica
|
|||
return frame;
|
||||
};
|
||||
|
||||
async _onRender(context, options) {
|
||||
await super._onRender(context, options);
|
||||
|
||||
// Shortcut because users can't edit
|
||||
if (!game.user.isGM) { return };
|
||||
|
||||
// Add event listener for the dropdown
|
||||
if (options.parts.includes(`delveConditions`)) {
|
||||
const select = this.element.querySelector(`#${this.id}-difficulty`);
|
||||
select.addEventListener(`change`, async (ev) => {
|
||||
const newDifficulty = parseInt(ev.target.value);
|
||||
if (!Number.isNaN(newDifficulty)) {
|
||||
await game.settings.set(`ripcrypt`, `dc`, newDifficulty);
|
||||
};
|
||||
this.render({ parts: [`delveConditions`] });
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
async _preparePartContext(partId, ctx, opts) {
|
||||
ctx = await super._preparePartContext(partId, ctx, opts);
|
||||
Logger.log(`Context`, ctx);
|
||||
|
||||
ctx.meta.editable = game.user.isGM;
|
||||
|
||||
switch (partId) {
|
||||
case `delveConditions`: {
|
||||
ctx = this._prepareDifficulty(ctx);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
Logger.log(`${partId} Context`, ctx);
|
||||
return ctx;
|
||||
};
|
||||
|
||||
_prepareDifficulty(ctx) {
|
||||
ctx.options = [
|
||||
{ label: `RipCrypt.common.difficulties.easy`, value: 4 },
|
||||
{ label: `RipCrypt.common.difficulties.normal`, value: 5 },
|
||||
{ label: `RipCrypt.common.difficulties.tough`, value: 6 },
|
||||
{ label: `RipCrypt.common.difficulties.hard`, value: 7 },
|
||||
];
|
||||
ctx.difficulty = game.settings.get(`ripcrypt`, `dc`);
|
||||
return ctx;
|
||||
};
|
||||
// #endregion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue