Fixed downtime config again

This commit is contained in:
WBHarry 2025-07-25 18:22:56 +02:00
parent 20dbd3804c
commit b8786d981e
8 changed files with 105 additions and 45 deletions

View file

@ -64,8 +64,8 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
context.selectedActivity = this.selectedActivity; context.selectedActivity = this.selectedActivity;
context.moveData = this.moveData; context.moveData = this.moveData;
const shortRestMovesSelected = this.#nrSelectedMoves('shortRest'); const shortRestMovesSelected = this.nrSelectedMoves('shortRest');
const longRestMovesSelected = this.#nrSelectedMoves('longRest'); const longRestMovesSelected = this.nrSelectedMoves('longRest');
context.nrChoices = { context.nrChoices = {
...this.nrChoices, ...this.nrChoices,
shortRest: { shortRest: {
@ -89,7 +89,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
static selectMove(_, target) { static selectMove(_, target) {
const { category, move } = target.dataset; 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) { if (nrSelected + this.nrChoices[category].taken >= this.nrChoices[category].max) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noMoreMoves')); ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noMoreMoves'));
@ -176,7 +176,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
this.render(); this.render();
} }
#nrSelectedMoves(category) { nrSelectedMoves(category) {
return Object.values(this.moveData[category].moves).reduce((acc, x) => acc + (x.selected ?? 0), 0); return Object.values(this.moveData[category].moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
} }
} }

View file

@ -71,9 +71,10 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
static async editItem(_, target) { static async editItem(_, target) {
const move = this.settings.restMoves[target.dataset.type].moves[target.dataset.id]; 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( const editedMove = await game.system.api.applications.sheetConfigs.DowntimeConfig.configure(
move, move,
target.dataset.id, path,
this.settings this.settings
); );
if (!editedMove) return; if (!editedMove) return;

View file

@ -172,6 +172,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
const submitData = this._prepareSubmitData(event, formData), const submitData = this._prepareSubmitData(event, formData),
data = foundry.utils.mergeObject(this.action.toObject(), submitData); data = foundry.utils.mergeObject(this.action.toObject(), submitData);
this.action = await this.action.update(data); this.action = await this.action.update(data);
this.sheetUpdate?.(this.action);
this.render(); this.render();
} }

View file

@ -4,12 +4,13 @@ import DHActionConfig from './action-config.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DhSettingsActionView extends HandlebarsApplicationMixin(ApplicationV2) { export default class DhSettingsActionView extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(move, moveId, settings, options) { constructor(move, movePath, settings, options) {
super(options); super(options);
this.move = move; this.move = move;
this.actionsPath = `restMoves.shortRest.moves.${moveId}.actions`; this.movePath = movePath;
this.actionsPath = `${movePath}.actions`;
this.settings = settings; this.settings = settings;
} }
@ -111,7 +112,6 @@ export default class DhSettingsActionView extends HandlebarsApplicationMixin(App
const cls = actionsTypes[actionType] ?? actionsTypes.attack, const cls = actionsTypes[actionType] ?? actionsTypes.attack,
action = new cls( action = new cls(
{ {
_id: foundry.utils.randomID(),
type: actionType, type: actionType,
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name), name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
img: 'icons/magic/life/cross-worn-green.webp', 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}.${action.id}`]: action });
await this.settings.updateSource({ [this.actionsPath]: this.move.actions }); this.move = foundry.utils.getProperty(this.settings, this.movePath);
this.render(); this.render();
} }
static async editItem(_, target) { static async editItem(_, target) {
const editIndex = Number(target.dataset.id); const actionId = target.dataset.id;
const action = this.move.actions.find((_, index) => index === editIndex); const action = this.move.actions.get(actionId);
await new DHActionConfig(action, async updatedMove => { await new DHActionConfig(action, async updatedMove => {
this.move.actions[editIndex] = updatedMove; await this.settings.updateSource({ [`${this.actionsPath}.${actionId}`]: updatedMove });
await this.settings.updateSource({ [this.actionsPath]: this.move.actions }); this.move = foundry.utils.getProperty(this.settings, this.movePath);
this.render(); this.render();
}).render(true); }).render(true);
} }
static async removeItem(_, target) { static async removeItem(_, target) {
this.move.actions = this.move.actions.filter((_, index) => index !== Number(target.dataset.id)); await this.settings.updateSource({ [`${this.actionsPath}.-=${target.dataset.id}`]: null });
await this.settings.updateSource({ [this.actionsPath]: this.move.actions }); this.move = foundry.utils.getProperty(this.settings, this.movePath);
this.render(); this.render();
} }
@ -153,9 +152,9 @@ export default class DhSettingsActionView extends HandlebarsApplicationMixin(App
if (!options.submitted) this.move = null; if (!options.submitted) this.move = null;
} }
static async configure(move, moveId, settings, options = {}) { static async configure(move, movePath, settings, options = {}) {
return new Promise(resolve => { 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.addEventListener('close', () => resolve(app.move), { once: true });
app.render({ force: true }); app.render({ force: true });
}); });

View file

@ -138,9 +138,8 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-bandage', icon: 'fa-solid fa-bandage',
img: 'icons/magic/life/cross-worn-green.webp', img: 'icons/magic/life/cross-worn-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.description'),
actions: [ actions: {
{ tendToWounds: {
_id: foundry.utils.randomID(),
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions', systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing', type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.name'), name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.name'),
@ -156,7 +155,7 @@ export const defaultRestOptions = {
} }
} }
} }
] }
}, },
clearStress: { clearStress: {
id: 'clearStress', id: 'clearStress',
@ -164,9 +163,8 @@ export const defaultRestOptions = {
icon: 'fa-regular fa-face-surprise', icon: 'fa-regular fa-face-surprise',
img: 'icons/magic/perception/eye-ringed-green.webp', img: 'icons/magic/perception/eye-ringed-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.description'),
actions: [ actions: {
{ clearStress: {
_id: foundry.utils.randomID(),
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions', systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing', type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.name'), name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.name'),
@ -182,7 +180,7 @@ export const defaultRestOptions = {
} }
} }
} }
] }
}, },
repairArmor: { repairArmor: {
id: 'repairArmor', id: 'repairArmor',
@ -190,9 +188,8 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-hammer', icon: 'fa-solid fa-hammer',
img: 'icons/skills/trades/smithing-anvil-silver-red.webp', img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.description'),
actions: [ actions: {
{ repairArmor: {
_id: foundry.utils.randomID(),
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions', systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing', type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.name'), name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.name'),
@ -208,7 +205,7 @@ export const defaultRestOptions = {
} }
} }
} }
] }
}, },
prepare: { prepare: {
id: 'prepare', id: 'prepare',
@ -216,7 +213,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-dumbbell', icon: 'fa-solid fa-dumbbell',
img: 'icons/skills/trades/academics-merchant-scribe.webp', img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.prepare.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.prepare.description'),
actions: [] actions: {}
} }
}), }),
longRest: () => ({ longRest: () => ({
@ -226,7 +223,24 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-bandage', icon: 'fa-solid fa-bandage',
img: 'icons/magic/life/cross-worn-green.webp', img: 'icons/magic/life/cross-worn-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.tendToWounds.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.tendToWounds.description'),
actions: [] actions: {
tendToWounds: {
systemPath: 'restMoves.longRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.tendToWounds.name'),
img: 'icons/magic/life/cross-worn-green.webp',
actionType: 'action',
healing: {
applyTo: healingTypes.hitPoints.id,
value: {
custom: {
enabled: true,
formula: '@system.resources.hitPoints.max'
}
}
}
}
}
}, },
clearStress: { clearStress: {
id: 'clearStress', id: 'clearStress',
@ -234,7 +248,24 @@ export const defaultRestOptions = {
icon: 'fa-regular fa-face-surprise', icon: 'fa-regular fa-face-surprise',
img: 'icons/magic/perception/eye-ringed-green.webp', img: 'icons/magic/perception/eye-ringed-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.clearStress.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.clearStress.description'),
actions: [] actions: {
clearStress: {
systemPath: 'restMoves.longRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.clearStress.name'),
img: 'icons/magic/perception/eye-ringed-green.webp',
actionType: 'action',
healing: {
applyTo: healingTypes.stress.id,
value: {
custom: {
enabled: true,
formula: '@system.resources.stress.max'
}
}
}
}
}
}, },
repairArmor: { repairArmor: {
id: 'repairArmor', id: 'repairArmor',
@ -242,7 +273,24 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-hammer', icon: 'fa-solid fa-hammer',
img: 'icons/skills/trades/smithing-anvil-silver-red.webp', img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.repairArmor.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.repairArmor.description'),
actions: [] actions: {
repairArmor: {
systemPath: 'restMoves.longRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.repairArmor.name'),
img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
actionType: 'action',
healing: {
applyTo: healingTypes.armorStack.id,
value: {
custom: {
enabled: true,
formula: '@system.armorScore'
}
}
}
}
}
}, },
prepare: { prepare: {
id: 'prepare', id: 'prepare',
@ -250,7 +298,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-dumbbell', icon: 'fa-solid fa-dumbbell',
img: 'icons/skills/trades/academics-merchant-scribe.webp', img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.prepare.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.prepare.description'),
actions: [] actions: {}
}, },
workOnAProject: { workOnAProject: {
id: 'workOnAProject', id: 'workOnAProject',
@ -258,7 +306,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-diagram-project', icon: 'fa-solid fa-diagram-project',
img: 'icons/skills/social/thumbsup-approval-like.webp', img: 'icons/skills/social/thumbsup-approval-like.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.workOnAProject.description'), description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.workOnAProject.description'),
actions: [] actions: {}
} }
}) })
}; };

View file

@ -202,11 +202,21 @@ export function ActionMixin(Base) {
} }
async update(updates, options = {}) { async update(updates, options = {}) {
const path = this.inCollection ? `system.${this.systemPath}.${this.id}` : `system.${this.systemPath}`, const isSetting = !this.parent.parent;
const basePath = isSetting ? this.systemPath : `system.${this.systemPath}`;
const path = this.inCollection ? `${basePath}.${this.id}` : basePath;
let result = null;
if (isSetting) {
await this.parent.updateSource({ [path]: updates }, options);
result = this.parent;
} else {
result = await this.item.update({ [path]: updates }, options); result = await this.item.update({ [path]: updates }, options);
}
return this.inCollection return this.inCollection
? foundry.utils.getProperty(result, `system.${this.systemPath}`).get(this.id) ? foundry.utils.getProperty(result, basePath).get(this.id)
: foundry.utils.getProperty(result, `system.${this.systemPath}`); : foundry.utils.getProperty(result, basePath);
} }
delete() { delete() {

View file

@ -1,5 +1,5 @@
import { defaultRestOptions } from '../../config/generalConfig.mjs'; import { defaultRestOptions } from '../../config/generalConfig.mjs';
import ActionField from '../fields/actionField.mjs'; import { ActionsField } from '../fields/actionField.mjs';
export default class DhHomebrew extends foundry.abstract.DataModel { export default class DhHomebrew extends foundry.abstract.DataModel {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.SETTINGS.Homebrew']; // Doesn't work for some reason static LOCALIZATION_PREFIXES = ['DAGGERHEART.SETTINGS.Homebrew']; // Doesn't work for some reason
@ -62,7 +62,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
base64: false base64: false
}), }),
description: new fields.HTMLField(), description: new fields.HTMLField(),
actions: new fields.ArrayField(new ActionField()) actions: new ActionsField()
}), }),
{ initial: defaultRestOptions.longRest() } { initial: defaultRestOptions.longRest() }
) )
@ -79,7 +79,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
base64: false base64: false
}), }),
description: new fields.HTMLField(), description: new fields.HTMLField(),
actions: new fields.ArrayField(new ActionField()) actions: new ActionsField()
}), }),
{ initial: defaultRestOptions.shortRest() } { initial: defaultRestOptions.shortRest() }
) )

View file

@ -7,8 +7,8 @@
<legend>{{localize "DAGGERHEART.GENERAL.Action.plural"}} <a><i class="fa-solid fa-plus icon-button" data-action="addItem"></i></a></legend> <legend>{{localize "DAGGERHEART.GENERAL.Action.plural"}} <a><i class="fa-solid fa-plus icon-button" data-action="addItem"></i></a></legend>
<div class="settings-items"> <div class="settings-items">
{{#each move.actions as |action index|}} {{#each move.actions as |action|}}
{{> "systems/daggerheart/templates/settings/components/settings-item-line.hbs" id=index }} {{> "systems/daggerheart/templates/settings/components/settings-item-line.hbs" id=action.id }}
{{/each}} {{/each}}
</div> </div>
</fieldset> </fieldset>