This commit is contained in:
WBHarry 2026-04-19 20:58:34 +02:00
parent 1fea8438ba
commit 7af3f07a26
14 changed files with 260 additions and 16 deletions

View file

@ -17,3 +17,4 @@ export { default as TagTeamDialog } from './tagTeamDialog.mjs';
export { default as GroupRollDialog } from './groupRollDialog.mjs';
export { default as RiskItAllDialog } from './riskItAllDialog.mjs';
export { default as CompendiumBrowserSettingsDialog } from './CompendiumBrowserSettings.mjs';
export { default as LevelupOptionsDialog } from './levelupOptionsDialog.mjs';

View file

@ -0,0 +1,92 @@
import { LevelOptionType } from "../../data/levelTier.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class LevelupOptionsDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(item) {
super({});
this.item = item;
this.selectedOption = null;
}
get title() {
return game.i18n.format('DAGGERHEART.APPLICATIONS.LevelupOptionsDialog.title', { name: this.item.name });
}
static DEFAULT_OPTIONS = {
tag: 'form',
classes: ['daggerheart', 'dh-style', 'dialog', 'views', 'levelup-options-dialog'],
position: { width: 480, height: 'auto' },
window: { icon: 'fa-solid fa-angles-up fa-fw' },
actions: {
addTierOption: LevelupOptionsDialog.#addTierOption,
removeTierOption: LevelupOptionsDialog.#removeTierOption,
},
form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false }
};
static PARTS = {
header: { template: 'systems/daggerheart/templates/dialogs/levelupOptionsDialog/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
tiers: { template: 'systems/daggerheart/templates/dialogs/levelupOptionsDialog/tiers.hbs' },
};
/** @inheritdoc */
static TABS = {
primary: {
tabs: [
{ id: 'tier2', label: 'DAGGERHEART.GENERAL.Tiers.2', tier: 2 },
{ id: 'tier3', label: 'DAGGERHEART.GENERAL.Tiers.3', tier: 3 },
{ id: 'tier4', label: 'DAGGERHEART.GENERAL.Tiers.4', tier: 4 }
],
initial: 'tier2',
}
};
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
for(const element of htmlElement.querySelectorAll('.option-type-select'))
element.addEventListener('change', this.updateSelectedOption.bind(this));
}
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.item = this.item;
context.fields = this.item.system.schema.fields.levelupOptionTiers.element.element.fields;
context.optionTypes = LevelOptionType;
context.selectedOption = this.selectedOption;
return context;
}
static async updateData(_event, _element, formData) {
const data = foundry.utils.expandObject(formData.object);
this.render();
}
updateSelectedOption(event) {
this.selectedOption = event.target.value;
this.render();
}
static async #addTierOption(_event, button) {
const { tier } = button.dataset;
await this.item.update({ [`system.levelupOptionTiers.${tier}.${foundry.utils.randomID()}`]: {
label: LevelOptionType[this.selectedOption].label,
type: this.selectedOption
}});
this.selectedOption = null;
this.render();
}
static async #removeTierOption(_event, button) {
const { tier, key } = button.dataset;
await this.item.update({ [`system.levelupOptionTiers.${tier}.${key}`]: _del });
this.render();
}
}

View file

@ -6,9 +6,7 @@ export default class DhCharacterLevelUp extends LevelUpBase {
constructor(actor) {
super(actor);
this.levelTiers = this.addBonusChoices(
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers)
);
this.levelTiers = this.addBonusChoices(actor.system.levelupTiers);
const playerLevelupData = actor.system.levelData;
this.levelup = new DhLevelup(DhLevelup.initializeData(this.levelTiers, playerLevelupData));
}
@ -366,7 +364,7 @@ export default class DhCharacterLevelUp extends LevelUpBase {
advancement.experience?.flatMap(x => x.data.map(data => ({ name: data, modifier: x.value }))) ??
[],
multiclass: advancement.multiclass,
subclass: advancement.subclass
subclass: advancement.subclass,
};
context.advancements.statistics.proficiency.shown =

View file

@ -99,7 +99,8 @@ export default function DHApplicationMixin(Base) {
toggleExtended: DHSheetV2.#toggleExtended,
addNewItem: DHSheetV2.#addNewItem,
browseItem: DHSheetV2.#browseItem,
editAttribution: DHSheetV2.#editAttribution
editAttribution: DHSheetV2.#editAttribution,
configureLevelUpOptions: DHSheetV2.#configureLevelUpOptions,
},
contextMenus: [
{
@ -119,6 +120,16 @@ export default function DHApplicationMixin(Base) {
}
}
],
window: {
controls: [
{
icon: 'fa-solid fa-angles-up fa-fw',
label: 'DAGGERHEART.UI.Tooltip.configureLevelupOptions',
action: 'configureLevelUpOptions',
visible: DHSheetV2.#hasLevelUpOptions,
}
],
},
dragDrop: [{ dragSelector: '.inventory-item[data-type="effect"]', dropSelector: null }],
tagifyConfigs: []
};
@ -142,6 +153,10 @@ export default function DHApplicationMixin(Base) {
return frame;
}
static #hasLevelUpOptions() {
return this.document.system.metadata.hasLevelUpOptions;
};
/**
* Refresh the custom parts of the application frame
*/
@ -708,6 +723,10 @@ export default function DHApplicationMixin(Base) {
new game.system.api.applications.dialogs.AttributionDialog(this.document).render({ force: true });
}
static async #configureLevelUpOptions() {
new game.system.api.applications.dialogs.LevelupOptionsDialog(this.document).render({ force: true });
}
/**
* Create an embedded document.
* @type {ApplicationClickAction}