From 3b159d7c0c959f3698f07c84700cba2411600b5f Mon Sep 17 00:00:00 2001 From: WBHarry Date: Tue, 1 Jul 2025 02:37:30 +0200 Subject: [PATCH] Experience settings update --- .../applications/adversary-settings.mjs | 272 +++++++++--------- templates/sheets/actors/adversary/sidebar.hbs | 4 +- .../adversary-settings/experiences.hbs | 10 +- 3 files changed, 142 insertions(+), 144 deletions(-) diff --git a/module/applications/sheets/applications/adversary-settings.mjs b/module/applications/sheets/applications/adversary-settings.mjs index 43ec593b..58b3ffdf 100644 --- a/module/applications/sheets/applications/adversary-settings.mjs +++ b/module/applications/sheets/applications/adversary-settings.mjs @@ -1,137 +1,135 @@ -import DHActionConfig from '../../config/Action.mjs'; -import DaggerheartSheet from '../daggerheart-sheet.mjs'; - -const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; - -export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) { - constructor(actor) { - super({}); - - this.actor = actor; - } - - get title() { - return `${game.i18n.localize('DAGGERHEART.Sheets.TABS.settings')}`; - } - - static DEFAULT_OPTIONS = { - tag: 'form', - id: 'daggerheart-action', - classes: ['daggerheart', 'dh-style', 'dialog', 'adversary-settings'], - window: { - icon: 'fa-solid fa-wrench', - resizable: false - }, - position: { width: 455, height: 'auto' }, - actions: { - addExperience: this.addExperience, - removeExperience: this.removeExperience - }, - form: { - handler: this.updateForm, - submitOnChange: true, - closeOnSubmit: false - } - }; - - static PARTS = { - header: { - id: 'header', - template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/header.hbs' - }, - tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' }, - details: { - id: 'details', - template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/details.hbs' - }, - attack: { - id: 'attack', - template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/attack.hbs' - }, - experiences: { - id: 'experiences', - template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/experiences.hbs' - }, - features: { - id: 'features', - template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/features.hbs' - } - }; - - static TABS = { - details: { - active: true, - cssClass: '', - group: 'primary', - id: 'details', - icon: null, - label: 'DAGGERHEART.General.tabs.details' - }, - attack: { - active: false, - cssClass: '', - group: 'primary', - id: 'attack', - icon: null, - label: 'DAGGERHEART.General.tabs.attack' - }, - experiences: { - active: false, - cssClass: '', - group: 'primary', - id: 'experiences', - icon: null, - label: 'DAGGERHEART.General.tabs.experiences' - }, - features: { - active: false, - cssClass: '', - group: 'primary', - id: 'features', - icon: null, - label: 'DAGGERHEART.General.tabs.features' - } - }; - - async _prepareContext(_options) { - const context = await super._prepareContext(_options); - context.document = this.actor; - context.tabs = this._getTabs(this.constructor.TABS); - context.systemFields = this.actor.system.schema.fields; - context.systemFields.attack.fields = this.actor.system.attack.schema.fields; - // context.getEffectDetails = this.getEffectDetails.bind(this); - // context.isNPC = true; - // console.log(context); - return context; - } - - _getTabs(tabs) { - for (const v of Object.values(tabs)) { - v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active; - v.cssClass = v.active ? 'active' : ''; - } - - return tabs; - } - - static async addExperience() { - const newExperience = { - name: 'Experience', - modifier: 0 - }; - await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience }); - } - - static async removeExperience() { - const newExperience = { - name: 'Experience', - modifier: 0 - }; - await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience }); - } - - static async updateForm(event, _, formData) { - await this.actor.update(formData.object); - this.render(); - } -} +import DHActionConfig from '../../config/Action.mjs'; +import DaggerheartSheet from '../daggerheart-sheet.mjs'; + +const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; + +export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) { + constructor(actor) { + super({}); + + this.actor = actor; + } + + get title() { + return `${game.i18n.localize('DAGGERHEART.Sheets.TABS.settings')}`; + } + + static DEFAULT_OPTIONS = { + tag: 'form', + id: 'daggerheart-action', + classes: ['daggerheart', 'dh-style', 'dialog', 'adversary-settings'], + window: { + icon: 'fa-solid fa-wrench', + resizable: false + }, + position: { width: 455, height: 'auto' }, + actions: { + addExperience: this.addExperience, + removeExperience: this.removeExperience + }, + form: { + handler: this.updateForm, + submitOnChange: true, + closeOnSubmit: false + } + }; + + static PARTS = { + header: { + id: 'header', + template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/header.hbs' + }, + tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' }, + details: { + id: 'details', + template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/details.hbs' + }, + attack: { + id: 'attack', + template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/attack.hbs' + }, + experiences: { + id: 'experiences', + template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/experiences.hbs' + }, + features: { + id: 'features', + template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/features.hbs' + } + }; + + static TABS = { + details: { + active: true, + cssClass: '', + group: 'primary', + id: 'details', + icon: null, + label: 'DAGGERHEART.General.tabs.details' + }, + attack: { + active: false, + cssClass: '', + group: 'primary', + id: 'attack', + icon: null, + label: 'DAGGERHEART.General.tabs.attack' + }, + experiences: { + active: false, + cssClass: '', + group: 'primary', + id: 'experiences', + icon: null, + label: 'DAGGERHEART.General.tabs.experiences' + }, + features: { + active: false, + cssClass: '', + group: 'primary', + id: 'features', + icon: null, + label: 'DAGGERHEART.General.tabs.features' + } + }; + + async _prepareContext(_options) { + const context = await super._prepareContext(_options); + context.document = this.actor; + context.tabs = this._getTabs(this.constructor.TABS); + context.systemFields = this.actor.system.schema.fields; + context.systemFields.attack.fields = this.actor.system.attack.schema.fields; + // context.getEffectDetails = this.getEffectDetails.bind(this); + // context.isNPC = true; + // console.log(context); + return context; + } + + _getTabs(tabs) { + for (const v of Object.values(tabs)) { + v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active; + v.cssClass = v.active ? 'active' : ''; + } + + return tabs; + } + + static async addExperience() { + const newExperience = { + name: 'Experience', + modifier: 0 + }; + await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience }); + this.render(); + } + + static async removeExperience(_, target) { + await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null }); + this.render(); + } + + static async updateForm(event, _, formData) { + await this.actor.update(formData.object); + this.render(); + } +} diff --git a/templates/sheets/actors/adversary/sidebar.hbs b/templates/sheets/actors/adversary/sidebar.hbs index 3a5ab718..a67a4e5c 100644 --- a/templates/sheets/actors/adversary/sidebar.hbs +++ b/templates/sheets/actors/adversary/sidebar.hbs @@ -94,9 +94,9 @@ {{#each source.system.experiences as |experience id|}}
- +{{experience.total}} + +{{experience.modifier}}
- {{experience.description}} + {{experience.name}}
diff --git a/templates/sheets/applications/adversary-settings/experiences.hbs b/templates/sheets/applications/adversary-settings/experiences.hbs index d54255d5..0e307929 100644 --- a/templates/sheets/applications/adversary-settings/experiences.hbs +++ b/templates/sheets/applications/adversary-settings/experiences.hbs @@ -3,15 +3,15 @@ data-tab='{{tabs.experiences.id}}' data-group='{{tabs.experiences.group}}' > - - {{#each document.system.experiences as |experience index|}} + {{#each document.system.experiences as |experience key|}}
- - - + + +
{{/each}} \ No newline at end of file