Add functionality for randomly picking a difficulty

This commit is contained in:
Oliver-Akins 2025-02-02 17:11:57 -07:00
parent 31033017f7
commit 39ba3fd547
3 changed files with 37 additions and 11 deletions

View file

@ -4,6 +4,13 @@ import { Logger } from "../utils/Logger.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
const conditions = [
{ 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 },
];
export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(ApplicationV2)) { export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(ApplicationV2)) {
// #region Options // #region Options
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
@ -18,9 +25,11 @@ export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(Applica
minimizable: false, minimizable: false,
}, },
position: { position: {
width: 100, width: `auto`,
},
actions: {
randomCondition: this.#randomCondition,
}, },
actions: {},
}; };
static PARTS = { static PARTS = {
@ -79,17 +88,17 @@ export class CryptApp extends GenericAppMixin(HandlebarsApplicationMixin(Applica
}; };
_prepareDifficulty(ctx) { _prepareDifficulty(ctx) {
ctx.options = [ ctx.options = conditions;
{ 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`); ctx.difficulty = game.settings.get(`ripcrypt`, `dc`);
return ctx; return ctx;
}; };
// #endregion // #endregion
// #region Actions // #region Actions
static async #randomCondition() {
const dc = conditions[Math.floor(Math.random() * conditions.length)];
await game.settings.set(`ripcrypt`, `dc`, dc.value);
await this.render({ parts: [`delveConditions`] });
};
// #endregion // #endregion
}; };

View file

@ -8,9 +8,21 @@
<div slot="content"> <div slot="content">
<span>{{ difficulty }}</span> <span>{{ difficulty }}</span>
{{#if meta.editable}} {{#if meta.editable}}
<select id="{{meta.idp}}-difficulty"> <div class="row">
{{ rc-options difficulty options localize=true }} <select id="{{meta.idp}}-difficulty">
</select> {{ rc-options difficulty options localize=true }}
</select>
<button
type="button"
data-action="randomCondition"
>
<rc-icon
name="icons/roll"
var:size="20px"
var:fill="var(--accent-3)"
></rc-icon>
</button>
</div>
{{/if}} {{/if}}
</div> </div>
</rc-border> </rc-border>

View file

@ -10,4 +10,9 @@
background: var(--base-background); background: var(--base-background);
padding: 4px; padding: 4px;
}; };
.row {
display: flex;
flex-direction: row;
}
} }