mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-19 00:19:03 +01:00
Fixed downtime config again
This commit is contained in:
parent
20dbd3804c
commit
b8786d981e
8 changed files with 105 additions and 45 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,10 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
|
||||
static async editItem(_, target) {
|
||||
const move = this.settings.restMoves[target.dataset.type].moves[target.dataset.id];
|
||||
const path = `restMoves.${target.dataset.type}.moves.${target.dataset.id}`;
|
||||
const editedMove = await game.system.api.applications.sheetConfigs.DowntimeConfig.configure(
|
||||
move,
|
||||
target.dataset.id,
|
||||
path,
|
||||
this.settings
|
||||
);
|
||||
if (!editedMove) return;
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
const submitData = this._prepareSubmitData(event, formData),
|
||||
data = foundry.utils.mergeObject(this.action.toObject(), submitData);
|
||||
this.action = await this.action.update(data);
|
||||
|
||||
this.sheetUpdate?.(this.action);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import DHActionConfig from './action-config.mjs';
|
|||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DhSettingsActionView extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(move, moveId, settings, options) {
|
||||
constructor(move, movePath, settings, options) {
|
||||
super(options);
|
||||
|
||||
this.move = move;
|
||||
|
||||
this.actionsPath = `restMoves.shortRest.moves.${moveId}.actions`;
|
||||
this.movePath = movePath;
|
||||
this.actionsPath = `${movePath}.actions`;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +112,6 @@ export default class DhSettingsActionView extends HandlebarsApplicationMixin(App
|
|||
const cls = actionsTypes[actionType] ?? actionsTypes.attack,
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
type: actionType,
|
||||
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
|
||||
img: 'icons/magic/life/cross-worn-green.webp',
|
||||
|
|
@ -123,26 +123,25 @@ export default class DhSettingsActionView extends HandlebarsApplicationMixin(App
|
|||
}
|
||||
);
|
||||
|
||||
this.move.actions.push(action);
|
||||
await this.settings.updateSource({ [this.actionsPath]: this.move.actions });
|
||||
await this.settings.updateSource({ [`${this.actionsPath}.${action.id}`]: action });
|
||||
this.move = foundry.utils.getProperty(this.settings, this.movePath);
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async editItem(_, target) {
|
||||
const editIndex = Number(target.dataset.id);
|
||||
const action = this.move.actions.find((_, index) => index === editIndex);
|
||||
const actionId = target.dataset.id;
|
||||
const action = this.move.actions.get(actionId);
|
||||
await new DHActionConfig(action, async updatedMove => {
|
||||
this.move.actions[editIndex] = updatedMove;
|
||||
await this.settings.updateSource({ [this.actionsPath]: this.move.actions });
|
||||
await this.settings.updateSource({ [`${this.actionsPath}.${actionId}`]: updatedMove });
|
||||
this.move = foundry.utils.getProperty(this.settings, this.movePath);
|
||||
this.render();
|
||||
}).render(true);
|
||||
}
|
||||
|
||||
static async removeItem(_, target) {
|
||||
this.move.actions = this.move.actions.filter((_, index) => index !== Number(target.dataset.id));
|
||||
await this.settings.updateSource({ [this.actionsPath]: this.move.actions });
|
||||
|
||||
await this.settings.updateSource({ [`${this.actionsPath}.-=${target.dataset.id}`]: null });
|
||||
this.move = foundry.utils.getProperty(this.settings, this.movePath);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
@ -153,9 +152,9 @@ export default class DhSettingsActionView extends HandlebarsApplicationMixin(App
|
|||
if (!options.submitted) this.move = null;
|
||||
}
|
||||
|
||||
static async configure(move, moveId, settings, options = {}) {
|
||||
static async configure(move, movePath, settings, options = {}) {
|
||||
return new Promise(resolve => {
|
||||
const app = new this(move, moveId, settings, options);
|
||||
const app = new this(move, movePath, settings, options);
|
||||
app.addEventListener('close', () => resolve(app.move), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue