Experience settings update

This commit is contained in:
WBHarry 2025-07-01 02:37:30 +02:00
parent ca297b97b1
commit 3b159d7c0c
3 changed files with 142 additions and 144 deletions

View file

@ -1,137 +1,135 @@
import DHActionConfig from '../../config/Action.mjs'; import DHActionConfig from '../../config/Action.mjs';
import DaggerheartSheet from '../daggerheart-sheet.mjs'; import DaggerheartSheet from '../daggerheart-sheet.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) { export default class DHAdversarySettings extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(actor) { constructor(actor) {
super({}); super({});
this.actor = actor; this.actor = actor;
} }
get title() { get title() {
return `${game.i18n.localize('DAGGERHEART.Sheets.TABS.settings')}`; return `${game.i18n.localize('DAGGERHEART.Sheets.TABS.settings')}`;
} }
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
tag: 'form', tag: 'form',
id: 'daggerheart-action', id: 'daggerheart-action',
classes: ['daggerheart', 'dh-style', 'dialog', 'adversary-settings'], classes: ['daggerheart', 'dh-style', 'dialog', 'adversary-settings'],
window: { window: {
icon: 'fa-solid fa-wrench', icon: 'fa-solid fa-wrench',
resizable: false resizable: false
}, },
position: { width: 455, height: 'auto' }, position: { width: 455, height: 'auto' },
actions: { actions: {
addExperience: this.addExperience, addExperience: this.addExperience,
removeExperience: this.removeExperience removeExperience: this.removeExperience
}, },
form: { form: {
handler: this.updateForm, handler: this.updateForm,
submitOnChange: true, submitOnChange: true,
closeOnSubmit: false closeOnSubmit: false
} }
}; };
static PARTS = { static PARTS = {
header: { header: {
id: 'header', id: 'header',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/header.hbs' template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/header.hbs'
}, },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' }, tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
details: { details: {
id: 'details', id: 'details',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/details.hbs' template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/details.hbs'
}, },
attack: { attack: {
id: 'attack', id: 'attack',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/attack.hbs' template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/attack.hbs'
}, },
experiences: { experiences: {
id: 'experiences', id: 'experiences',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/experiences.hbs' template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/experiences.hbs'
}, },
features: { features: {
id: 'features', id: 'features',
template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/features.hbs' template: 'systems/daggerheart/templates/sheets/applications/adversary-settings/features.hbs'
} }
}; };
static TABS = { static TABS = {
details: { details: {
active: true, active: true,
cssClass: '', cssClass: '',
group: 'primary', group: 'primary',
id: 'details', id: 'details',
icon: null, icon: null,
label: 'DAGGERHEART.General.tabs.details' label: 'DAGGERHEART.General.tabs.details'
}, },
attack: { attack: {
active: false, active: false,
cssClass: '', cssClass: '',
group: 'primary', group: 'primary',
id: 'attack', id: 'attack',
icon: null, icon: null,
label: 'DAGGERHEART.General.tabs.attack' label: 'DAGGERHEART.General.tabs.attack'
}, },
experiences: { experiences: {
active: false, active: false,
cssClass: '', cssClass: '',
group: 'primary', group: 'primary',
id: 'experiences', id: 'experiences',
icon: null, icon: null,
label: 'DAGGERHEART.General.tabs.experiences' label: 'DAGGERHEART.General.tabs.experiences'
}, },
features: { features: {
active: false, active: false,
cssClass: '', cssClass: '',
group: 'primary', group: 'primary',
id: 'features', id: 'features',
icon: null, icon: null,
label: 'DAGGERHEART.General.tabs.features' label: 'DAGGERHEART.General.tabs.features'
} }
}; };
async _prepareContext(_options) { async _prepareContext(_options) {
const context = await super._prepareContext(_options); const context = await super._prepareContext(_options);
context.document = this.actor; context.document = this.actor;
context.tabs = this._getTabs(this.constructor.TABS); context.tabs = this._getTabs(this.constructor.TABS);
context.systemFields = this.actor.system.schema.fields; context.systemFields = this.actor.system.schema.fields;
context.systemFields.attack.fields = this.actor.system.attack.schema.fields; context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
// context.getEffectDetails = this.getEffectDetails.bind(this); // context.getEffectDetails = this.getEffectDetails.bind(this);
// context.isNPC = true; // context.isNPC = true;
// console.log(context); // console.log(context);
return context; return context;
} }
_getTabs(tabs) { _getTabs(tabs) {
for (const v of Object.values(tabs)) { for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active; v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
v.cssClass = v.active ? 'active' : ''; v.cssClass = v.active ? 'active' : '';
} }
return tabs; return tabs;
} }
static async addExperience() { static async addExperience() {
const newExperience = { const newExperience = {
name: 'Experience', name: 'Experience',
modifier: 0 modifier: 0
}; };
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience }); await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
} this.render();
}
static async removeExperience() {
const newExperience = { static async removeExperience(_, target) {
name: 'Experience', await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null });
modifier: 0 this.render();
}; }
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
} static async updateForm(event, _, formData) {
await this.actor.update(formData.object);
static async updateForm(event, _, formData) { this.render();
await this.actor.update(formData.object); }
this.render(); }
}
}

View file

@ -94,9 +94,9 @@
{{#each source.system.experiences as |experience id|}} {{#each source.system.experiences as |experience id|}}
<div class="experience-row"> <div class="experience-row">
<div class="experience-value"> <div class="experience-value">
+{{experience.total}} +{{experience.modifier}}
</div> </div>
<span>{{experience.description}}</span> <span>{{experience.name}}</span>
<div class="controls"> <div class="controls">
<a data-action="toChat" data-type="experience" data-uuid="{{id}}"><i class="fa-regular fa-message"></i></a> <a data-action="toChat" data-type="experience" data-uuid="{{id}}"><i class="fa-regular fa-message"></i></a>
</div> </div>

View file

@ -3,15 +3,15 @@
data-tab='{{tabs.experiences.id}}' data-tab='{{tabs.experiences.id}}'
data-group='{{tabs.experiences.group}}' data-group='{{tabs.experiences.group}}'
> >
<button data-action="addExperience"> <button type="button" data-action="addExperience">
New Experience New Experience
</button> </button>
{{#each document.system.experiences as |experience index|}} {{#each document.system.experiences as |experience key|}}
<div class="experience-chip"> <div class="experience-chip">
<input class="experience.value" type="text" name="system.experiences.{{index}}.name" value="{{experience.name}}" /> <input class="experience.value" type="text" name="system.experiences.{{key}}.name" value="{{experience.name}}" />
<input class="experience-value" type="text" name="system.experiences.{{index}}.value" value="{{experience.value}}" data-dtype="Number" /> <input class="experience-value" type="text" name="system.experiences.{{key}}.modifier" value="{{experience.modifier}}" data-dtype="Number" />
<button class="experience-button" data-action="removeExperience" data-experience="{{experience.id}}"><i class="fa-solid fa-x"></i></button> <button type="button" class="experience-button" data-action="removeExperience" data-experience="{{key}}"><i class="fa-solid fa-x"></i></button>
</div> </div>
{{/each}} {{/each}}
</section> </section>