mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Merged with main
This commit is contained in:
commit
a5b656f533
51 changed files with 650 additions and 1032 deletions
|
|
@ -7,3 +7,4 @@ export { default as DeathMove } from './deathMove.mjs';
|
|||
export { default as Downtime } from './downtime.mjs';
|
||||
export { default as OwnershipSelection } from './ownershipSelection.mjs';
|
||||
export { default as ResourceDiceDialog } from './resourceDiceDialog.mjs';
|
||||
export { default as ActionSelectionDialog } from './actionSelectionDialog.mjs';
|
||||
|
|
|
|||
87
module/applications/dialogs/actionSelectionDialog.mjs
Normal file
87
module/applications/dialogs/actionSelectionDialog.mjs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class ActionSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(item, event, options = {}) {
|
||||
super(options);
|
||||
this.#item = item;
|
||||
this.#event = event;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart', 'dh-style', 'dialog'],
|
||||
actions: {
|
||||
choose: ActionSelectionDialog.#onChooseAction
|
||||
},
|
||||
position: {
|
||||
width: 400
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static PARTS = {
|
||||
actions: {
|
||||
template: 'systems/daggerheart/templates/dialogs/actionSelect.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
#item;
|
||||
|
||||
get item() {
|
||||
return this.#item;
|
||||
}
|
||||
|
||||
#event;
|
||||
|
||||
get event() {
|
||||
return this.#event;
|
||||
}
|
||||
|
||||
#action;
|
||||
|
||||
get action() {
|
||||
return this.#action ?? null;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
get title() {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.SelectAction.selectAction');
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @inheritDoc */
|
||||
async _prepareContext(options) {
|
||||
const actions = this.#item.system.actionsList,
|
||||
itemName = this.#item.name;
|
||||
return {
|
||||
...(await super._prepareContext(options)),
|
||||
actions,
|
||||
itemName
|
||||
};
|
||||
}
|
||||
|
||||
static async #onChooseAction(event, button) {
|
||||
const { actionId } = button.dataset;
|
||||
this.#action = this.#item.system.actionsList.find(a => a._id === actionId);
|
||||
Object.defineProperty(this.#event, 'shiftKey', {
|
||||
get() {
|
||||
return event.shiftKey;
|
||||
}
|
||||
});
|
||||
this.close();
|
||||
}
|
||||
|
||||
static create(item, event, options) {
|
||||
return new Promise(resolve => {
|
||||
const dialog = new this(item, event, options);
|
||||
dialog.addEventListener('close', () => resolve(dialog.action), { once: true });
|
||||
dialog.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -64,8 +64,8 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
context.selectedActivity = this.selectedActivity;
|
||||
context.moveData = this.moveData;
|
||||
|
||||
const shortRestMovesSelected = this.#nrSelectedMoves('shortRest');
|
||||
const longRestMovesSelected = this.#nrSelectedMoves('longRest');
|
||||
const shortRestMovesSelected = this.nrSelectedMoves('shortRest');
|
||||
const longRestMovesSelected = this.nrSelectedMoves('longRest');
|
||||
context.nrChoices = {
|
||||
...this.nrChoices,
|
||||
shortRest: {
|
||||
|
|
@ -89,7 +89,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
static selectMove(_, target) {
|
||||
const { category, move } = target.dataset;
|
||||
|
||||
const nrSelected = this.#nrSelectedMoves(category);
|
||||
const nrSelected = this.nrSelectedMoves(category);
|
||||
|
||||
if (nrSelected + this.nrChoices[category].taken >= this.nrChoices[category].max) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noMoreMoves'));
|
||||
|
|
@ -176,7 +176,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
this.render();
|
||||
}
|
||||
|
||||
#nrSelectedMoves(category) {
|
||||
nrSelectedMoves(category) {
|
||||
return Object.values(this.moveData[category].moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue