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.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);
}
}

View file

@ -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;

View file

@ -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();
}

View file

@ -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 });
});

View file

@ -138,9 +138,8 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-bandage',
img: 'icons/magic/life/cross-worn-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.description'),
actions: [
{
_id: foundry.utils.randomID(),
actions: {
tendToWounds: {
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.tendToWounds.name'),
@ -156,7 +155,7 @@ export const defaultRestOptions = {
}
}
}
]
}
},
clearStress: {
id: 'clearStress',
@ -164,9 +163,8 @@ export const defaultRestOptions = {
icon: 'fa-regular fa-face-surprise',
img: 'icons/magic/perception/eye-ringed-green.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.description'),
actions: [
{
_id: foundry.utils.randomID(),
actions: {
clearStress: {
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.clearStress.name'),
@ -182,7 +180,7 @@ export const defaultRestOptions = {
}
}
}
]
}
},
repairArmor: {
id: 'repairArmor',
@ -190,9 +188,8 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-hammer',
img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.description'),
actions: [
{
_id: foundry.utils.randomID(),
actions: {
repairArmor: {
systemPath: 'restMoves.shortRest.moves.tendToWounds.actions',
type: 'healing',
name: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.repairArmor.name'),
@ -208,7 +205,7 @@ export const defaultRestOptions = {
}
}
}
]
}
},
prepare: {
id: 'prepare',
@ -216,7 +213,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-dumbbell',
img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.shortRest.prepare.description'),
actions: []
actions: {}
}
}),
longRest: () => ({
@ -226,7 +223,24 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-bandage',
img: 'icons/magic/life/cross-worn-green.webp',
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: {
id: 'clearStress',
@ -234,7 +248,24 @@ export const defaultRestOptions = {
icon: 'fa-regular fa-face-surprise',
img: 'icons/magic/perception/eye-ringed-green.webp',
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: {
id: 'repairArmor',
@ -242,7 +273,24 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-hammer',
img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
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: {
id: 'prepare',
@ -250,7 +298,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-dumbbell',
img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: game.i18n.localize('DAGGERHEART.APPLICATIONS.Downtime.longRest.prepare.description'),
actions: []
actions: {}
},
workOnAProject: {
id: 'workOnAProject',
@ -258,7 +306,7 @@ export const defaultRestOptions = {
icon: 'fa-solid fa-diagram-project',
img: 'icons/skills/social/thumbsup-approval-like.webp',
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 = {}) {
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);
}
return this.inCollection
? foundry.utils.getProperty(result, `system.${this.systemPath}`).get(this.id)
: foundry.utils.getProperty(result, `system.${this.systemPath}`);
? foundry.utils.getProperty(result, basePath).get(this.id)
: foundry.utils.getProperty(result, basePath);
}
delete() {

View file

@ -1,5 +1,5 @@
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 {
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
}),
description: new fields.HTMLField(),
actions: new fields.ArrayField(new ActionField())
actions: new ActionsField()
}),
{ initial: defaultRestOptions.longRest() }
)
@ -79,7 +79,7 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
base64: false
}),
description: new fields.HTMLField(),
actions: new fields.ArrayField(new ActionField())
actions: new ActionsField()
}),
{ 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>
<div class="settings-items">
{{#each move.actions as |action index|}}
{{> "systems/daggerheart/templates/settings/components/settings-item-line.hbs" id=index }}
{{#each move.actions as |action|}}
{{> "systems/daggerheart/templates/settings/components/settings-item-line.hbs" id=action.id }}
{{/each}}
</div>
</fieldset>