Dialog setup

This commit is contained in:
WBHarry 2025-07-02 23:27:43 +02:00
parent 97f8da69cd
commit 80c347471b
19 changed files with 473 additions and 14 deletions

View file

@ -15,5 +15,6 @@ export { default as DhpChatMessage } from './chatMessage.mjs';
export { default as DhpEnvironment } from './sheets/actors/environment.mjs';
export { default as DhActiveEffectConfig } from './sheets/activeEffectConfig.mjs';
export { default as DhContextMenu } from './contextMenu.mjs';
export { default as DhBeastform } from './sheets/items/beastform.mjs';
export * as api from './sheets/api/_modules.mjs';

View file

@ -0,0 +1,62 @@
import DHBaseItemSheet from '../api/base-item.mjs';
export default class BeastformSheet extends DHBaseItemSheet {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['beastform'],
dragDrop: [{ dragSelector: null, dropSelector: '.drop-section' }],
actions: {
editFeature: this.editFeature,
removeFeature: this.removeFeature
}
};
/**@override */
static PARTS = {
header: { template: 'systems/daggerheart/templates/sheets/items/beastform/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
settings: { template: 'systems/daggerheart/templates/sheets/items/beastform/settings.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
}
};
static TABS = {
primary: {
tabs: [{ id: 'settings' }, { id: 'features' }],
initial: 'settings',
labelPrefix: 'DAGGERHEART.Sheets.TABS'
}
};
/**@inheritdoc */
async _preparePartContext(partId, context) {
await super._preparePartContext(partId, context);
return context;
}
static editFeature(event) {
const target = event.target.closest('[data-action="editFeature"]');
const feature = this.document.system.features[target.dataset.index];
feature.sheet.render(true);
}
static async removeFeature(_, target) {
const current = this.document.system.features.map(x => x.uuid);
await this.document.update({
'system.features': current.filter((_, index) => index !== Number(target.dataset.index))
});
this.render();
}
async _onDrop(event) {
const data = TextEditor.getDragEventData(event);
const item = await fromUuid(data.uuid);
if (item.type === 'feature') {
const current = this.document.system.features.map(x => x.uuid);
await this.document.update({ 'system.features': [...current, item.uuid] });
}
}
}

View file

@ -245,19 +245,23 @@ export const deathMoves = {
export const tiers = {
tier1: {
id: 'tier1',
label: 'DAGGERHEART.Tiers.tier1'
label: 'DAGGERHEART.Tiers.tier1',
value: 1
},
tier2: {
id: 'tier2',
label: 'DAGGERHEART.Tiers.tier2'
label: 'DAGGERHEART.Tiers.tier2',
value: 2
},
tier3: {
id: 'tier3',
label: 'DAGGERHEART.Tiers.tier3'
label: 'DAGGERHEART.Tiers.tier3',
value: 3
},
tier4: {
id: 'tier4',
label: 'DAGGERHEART.Tiers.tier4'
label: 'DAGGERHEART.Tiers.tier4',
value: 4
}
};

View file

@ -2,6 +2,7 @@ import CostSelectionDialog from '../../applications/costSelectionDialog.mjs';
import { DHActionDiceData, DHActionRollData, DHDamageData, DHDamageField } from './actionDice.mjs';
import DhpActor from '../../documents/actor.mjs';
import D20RollDialog from '../../dialogs/d20RollDialog.mjs';
import BeastformDialog from '../../dialogs/beastformDialog.mjs';
const fields = foundry.data.fields;
@ -271,7 +272,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}
if (this instanceof DhBeastformAction) {
console.log('Test');
config = await BeastformDialog.configure(config);
if (!config) return;
}
if (this.doFollowUp()) {

View file

@ -8,6 +8,7 @@ import DHFeature from './feature.mjs';
import DHMiscellaneous from './miscellaneous.mjs';
import DHSubclass from './subclass.mjs';
import DHWeapon from './weapon.mjs';
import DHBeastform from './beastform.mjs';
export {
DHAncestry,
@ -19,7 +20,8 @@ export {
DHFeature,
DHMiscellaneous,
DHSubclass,
DHWeapon
DHWeapon,
DHBeastform
};
export const config = {
@ -32,5 +34,6 @@ export const config = {
feature: DHFeature,
miscellaneous: DHMiscellaneous,
subclass: DHSubclass,
weapon: DHWeapon
weapon: DHWeapon,
beastform: DHBeastform
};

View file

@ -0,0 +1,32 @@
import ActionField from '../fields/actionField.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import BaseDataItem from './base.mjs';
export default class DHBeastform extends BaseDataItem {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Sheets.Beastform'];
/** @inheritDoc */
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Item.beastform',
type: 'beastform',
hasDescription: false
});
}
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
tier: new fields.StringField({
required: true,
choices: SYSTEM.GENERAL.tiers,
initial: SYSTEM.GENERAL.tiers.tier1.id
}),
examples: new fields.StringField(),
advantageOn: new fields.ArrayField(new fields.StringField()),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
}

View file

@ -0,0 +1,83 @@
import { tiers } from '../config/generalConfig.mjs';
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class BeastformDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(configData) {
super();
this.configData = configData;
this.selected = null;
}
static DEFAULT_OPTIONS = {
tag: 'form',
id: 'beastform-selection',
classes: ['daggerheart', 'views', 'dh-style', 'beastform-selection'],
position: {
width: 600,
height: 'auto'
},
actions: {
submitBeastform: this.submitBeastform
},
form: {
handler: this.updateBeastform,
submitOnChange: true,
submitOnClose: false
}
};
get title() {
return game.i18n.localize('DAGGERHEART.Sheets.Beastform.DialogTitle');
}
/** @override */
static PARTS = {
beastform: {
template: 'systems/daggerheart/templates/views/beastformDialog.hbs'
}
};
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.configData = this.configData;
const tierLimit = 2;
context.beastformTiers = game.items.reduce((acc, x) => {
const tier = tiers[x.system.tier];
if (x.type !== 'beastform' || tier.value > tierLimit) return acc;
if (!acc[tier.value]) acc[tier.value] = { label: game.i18n.localize(tier.label), values: {} };
acc[tier.value].values[x.uuid] = { selected: this.selected == x.uuid, value: x };
return acc;
}, {}); // Also get from compendium when added
context.canSubmit = this.selected;
return context;
}
static updateBeastform(event, _, formData) {
this.selected = foundry.utils.mergeObject(this.selected, formData.object);
this.render();
}
static async submitBeastform() {
await this.close({ submitted: true });
}
/** @override */
_onClose(options = {}) {
if (!options.submitted) this.config = false;
}
static async configure(configData) {
return new Promise(resolve => {
const app = new this(configData);
app.addEventListener('close', () => resolve(app.config), { once: true });
app.render({ force: true });
});
}
}