mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 05:01:08 +01:00
Added homebrew settings without action handling for now
This commit is contained in:
parent
e38ebfab29
commit
a65719b314
11 changed files with 478 additions and 5 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { DhHomebrew } from '../../data/settings/_module.mjs';
|
||||
import DhSettingsActionView from './components/settingsActionsView.mjs';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DhAutomationSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
export default class DhHomebrewSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor() {
|
||||
super({});
|
||||
|
||||
|
|
@ -19,7 +20,10 @@ export default class DhAutomationSettings extends HandlebarsApplicationMixin(App
|
|||
classes: ['daggerheart', 'setting', 'dh-style'],
|
||||
position: { width: '600', height: 'auto' },
|
||||
actions: {
|
||||
reset: this.reset,
|
||||
addItem: this.addItem,
|
||||
editItem: this.editItem,
|
||||
removeItem: this.removeItem,
|
||||
resetMoves: this.resetMoves,
|
||||
save: this.save
|
||||
},
|
||||
form: { handler: this.updateData, submitOnChange: true }
|
||||
|
|
@ -48,8 +52,101 @@ export default class DhAutomationSettings extends HandlebarsApplicationMixin(App
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async reset() {
|
||||
this.settings = new DhHomebrew();
|
||||
static async addItem(_, target) {
|
||||
await this.settings.updateSource({
|
||||
[`restMoves.${target.dataset.type}.moves.${foundry.utils.randomID()}`]: {
|
||||
name: game.i18n.localize('DAGGERHEART.Settings.Homebrew.NewDowntimeMove'),
|
||||
img: 'icons/magic/life/cross-worn-green.webp',
|
||||
description: '',
|
||||
actions: []
|
||||
}
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async editItem(_, target) {
|
||||
const move = this.settings.restMoves[target.dataset.type].moves[target.dataset.id];
|
||||
new Promise((resolve, reject) => {
|
||||
new DhSettingsActionView(
|
||||
resolve,
|
||||
reject,
|
||||
game.i18n.localize('DAGGERHEART.Settings.Homebrew.DowntimeMoves'),
|
||||
move.name,
|
||||
move.img,
|
||||
move.description,
|
||||
move.actions
|
||||
).render(true);
|
||||
}).then(data => this.updateAction.bind(this)(data, target.dataset.type, target.dataset.id));
|
||||
}
|
||||
|
||||
async updateAction(data, type, id) {
|
||||
await this.settings.updateSource({
|
||||
[`restMoves.${type}.moves.${id}`]: {
|
||||
name: data.name,
|
||||
img: data.img,
|
||||
description: data.description
|
||||
}
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async removeItem(_, target) {
|
||||
await this.settings.updateSource({
|
||||
[`restMoves.${target.dataset.type}.moves.-=${target.dataset.id}`]: null
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async resetMoves(_, target) {
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.format('DAGGERHEART.Settings.Homebrew.ResetMovesTitle', {
|
||||
type: game.i18n.localize(
|
||||
`DAGGERHEART.Downtime.${target.dataset.type === 'shortRest' ? 'ShortRest' : 'LongRest'}.title`
|
||||
)
|
||||
})
|
||||
},
|
||||
content: game.i18n.localize('DAGGERHEART.Settings.Homebrew.ResetMovesText')
|
||||
});
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
const fields = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Homebrew).schema.fields;
|
||||
|
||||
const removeUpdate = Object.keys(this.settings.restMoves[target.dataset.type].moves).reduce((acc, key) => {
|
||||
acc[`-=${key}`] = null;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const updateBase =
|
||||
target.dataset.type === 'shortRest'
|
||||
? fields.restMoves.fields.shortRest.fields
|
||||
: fields.restMoves.fields.longRest.fields;
|
||||
const update = {
|
||||
nrChoices: updateBase.nrChoices.initial,
|
||||
moves: Object.keys(updateBase.moves.initial).reduce((acc, key) => {
|
||||
const move = updateBase.moves.initial[key];
|
||||
acc[key] = {
|
||||
...move,
|
||||
name: game.i18n.localize(move.name),
|
||||
description: game.i18n.localize(move.description)
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {})
|
||||
};
|
||||
|
||||
await this.settings.updateSource({
|
||||
[`restMoves.${target.dataset.type}`]: {
|
||||
...update,
|
||||
moves: {
|
||||
...removeUpdate,
|
||||
...update.moves
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue