This commit is contained in:
WBHarry 2025-07-04 01:22:18 +02:00
parent 72dfc54705
commit 266a2806ab
13 changed files with 102 additions and 52 deletions

View file

@ -38,7 +38,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
}
};
static CLEAN_ARRAYS = ["damage.parts", "cost", "effects"];
static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects'];
_getTabs() {
const tabs = {
@ -69,7 +69,13 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
context.disableOption = this.disableOption.bind(this);
context.isNPC = this.action.actor && this.action.actor.type !== 'character';
context.hasRoll = this.action.hasRoll;
console.log(context)
const settingsTiers = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers;
context.tierOptions = [
{ key: 1, label: game.i18n.localize('DAGGERHEART.Tiers.tier1') },
...Object.values(settingsTiers).map(x => ({ key: x.tier, label: x.name }))
];
return context;
}
@ -97,9 +103,9 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
_prepareSubmitData(event, formData) {
const submitData = foundry.utils.expandObject(formData.object);
for ( const keyPath of this.constructor.CLEAN_ARRAYS ) {
for (const keyPath of this.constructor.CLEAN_ARRAYS) {
const data = foundry.utils.getProperty(submitData, keyPath);
if ( data ) foundry.utils.setProperty(submitData, keyPath, Object.values(data));
if (data) foundry.utils.setProperty(submitData, keyPath, Object.values(data));
}
return submitData;
}

View file

@ -103,7 +103,6 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
context.systemFields = this.actor.system.schema.fields;
context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
context.isNPC = true;
console.log(context);
return context;
}

View file

@ -44,7 +44,7 @@ export default class BeastformSheet extends DHBaseItemSheet {
static editFeature(event) {
const target = event.target.closest('[data-action="editFeature"]');
const feature = this.document.system.features[target.dataset.index];
feature.sheet.render(true);
feature.sheet.render({ force: true });
}
static async removeFeature(_, target) {
@ -52,7 +52,6 @@ export default class BeastformSheet extends DHBaseItemSheet {
await this.document.update({
'system.features': current.filter((_, index) => index !== Number(target.dataset.index))
});
this.render();
}
async _onDrop(event) {

View file

@ -275,18 +275,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}) */
}
if (this instanceof DhBeastformAction) {
config.beastform = this.prepareBeastformConfig();
const abort = await this.handleActiveTransformations();
if (abort) return;
const beastformUuid = await BeastformDialog.configure(config);
if (!beastformUuid) return;
await this.transform(beastformUuid);
}
if (this.doFollowUp()) {
if (this.rollDamage) await this.rollDamage(event, config);
if (this.rollHealing) await this.rollHealing(event, config);
@ -779,11 +767,23 @@ export class DHMacroAction extends DHBaseAction {
export class DhBeastformAction extends DHBaseAction {
static extraSchemas = ['beastform'];
async use(event, ...args) {
const beastformConfig = this.prepareBeastformConfig();
const abort = await this.handleActiveTransformations();
if (abort) return;
const beastformUuid = await BeastformDialog.configure(beastformConfig);
if (!beastformUuid) return;
await this.transform(beastformUuid);
}
prepareBeastformConfig(config) {
const settingsTier = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers;
const settingsTiers = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers;
const actorLevel = this.actor.system.levelData.level.current;
const actorTier =
Object.values(settingsTier).find(
Object.values(settingsTiers).find(
tier => actorLevel >= tier.levels.start && actorLevel <= tier.levels.end
) ?? 1;

View file

@ -4,7 +4,6 @@ export default class BeastformEffect extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
isBeastform: new fields.BooleanField({ initial: false }),
characterTokenData: new fields.SchemaField({
tokenImg: new fields.FilePathField({
categories: ['IMAGE'],
@ -34,13 +33,8 @@ export default class BeastformEffect extends foundry.abstract.TypeDataModel {
await updateActorTokens(this.parent.parent, update);
for (var feature of this.parent.parent.items.filter(x => this.featureIds.includes(x.id))) {
await feature.delete();
}
for (var effect of this.parent.parent.effects.filter(x => this.effectIds.includes(x.id))) {
await effect.delete();
}
await this.parent.parent.deleteEmbeddedDocuments('Item', this.featureIds);
await this.parent.parent.deleteEmbeddedDocuments('ActiveEffect', this.effectIds);
}
}
}

View file

@ -43,14 +43,16 @@ export default class DHBeastform extends BaseDataItem {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (this.actor?.type !== 'character') {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.beastformInapplicable'));
return;
if (!this.actor) return;
if (this.actor.type !== 'character') {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.notifications.beastformInapplicable'));
return false;
}
if (this.actor.items.find(x => x.type === 'beastform')) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.beastformAlreadyApplied'));
return;
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.notifications.beastformAlreadyApplied'));
return false;
}
const features = await this.parent.parent.createEmbeddedDocuments(

View file

@ -12,7 +12,6 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
static DEFAULT_OPTIONS = {
tag: 'form',
id: 'beastform-selection',
classes: ['daggerheart', 'views', 'dh-style', 'beastform-selection'],
position: {
width: 600,
@ -42,11 +41,10 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.configData = this.configData;
context.beastformTiers = game.items.reduce((acc, x) => {
const tier = tiers[x.system.tier];
if (x.type !== 'beastform' || tier.value > context.configData.beastform.tierLimit) return acc;
if (x.type !== 'beastform' || tier.value > this.configData.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 };

View file

@ -51,7 +51,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
};
async _prepareContext(_options) {
console.log(this.config, this.roll);
const context = await super._prepareContext(_options);
context.hasRoll = !!this.config.roll;
context.roll = this.roll;

View file

@ -299,12 +299,10 @@ export const updateActorTokens = async (actor, update) => {
await actor.prototypeToken.update(update);
/* Update the tokens in all scenes belonging to Actor */
for (let scene of game.scenes) {
for (let token of scene.tokens) {
const tokenActor = token.baseActor ?? token.actor;
if (tokenActor?.id === actor.id) {
await token.update(update);
}
for (let token of actor.getDependentTokens()) {
const tokenActor = token.baseActor ?? token.actor;
if (tokenActor?.id === actor.id) {
await token.update(update);
}
}
};