Reworked beastform to hold it's data entirely in the beastformEffect

This commit is contained in:
WBHarry 2025-07-03 16:18:54 +02:00
parent 3186468f28
commit 51bd7c18af
7 changed files with 76 additions and 60 deletions

View file

@ -786,14 +786,12 @@ export class DhBeastformAction extends DHBaseAction {
}
async handleActiveTransformations() {
const activeBeastforms = this.actor.items.filter(x => x.type === 'beastform');
if (activeBeastforms.length > 0) {
for (let form of activeBeastforms) {
await form.delete();
const beastformEffects = this.actor.effects.filter(x => x.type === 'beastform');
if (beastformEffects.length > 0) {
for (let effect of beastformEffects) {
await effect.delete();
}
this.actor.effects.filter(x => x.type === 'beastform').forEach(x => x.delete());
return true;
}

View file

@ -1,17 +1,45 @@
import { updateActorTokens } from '../../helpers/utils.mjs';
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
isBeastform: new fields.BooleanField({ initial: false })
isBeastform: new fields.BooleanField({ initial: false }),
characterTokenData: new fields.SchemaField({
tokenImg: new fields.FilePathField({
categories: ['IMAGE'],
base64: false,
nullable: true
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, nullable: true }),
width: new fields.NumberField({ integer: true, nullable: true })
})
}),
advantageOn: new fields.ArrayField(new fields.StringField()),
featureIds: new fields.ArrayField(new fields.StringField()),
effectIds: new fields.ArrayField(new fields.StringField())
};
}
async _preDelete() {
if (this.parent.parent.type === 'character') {
for (let item of this.parent.parent.items) {
if (item.type === 'beastform') {
await item.delete();
const update = {
height: this.characterTokenData.tokenSize.height,
width: this.characterTokenData.tokenSize.width,
texture: {
src: this.characterTokenData.tokenImg
}
};
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();
}
}
}

View file

@ -33,18 +33,6 @@ export default class DHBeastform extends BaseDataItem {
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
}),
characterTokenData: new fields.SchemaField({
tokenImg: new fields.FilePathField({
categories: ['IMAGE'],
base64: false,
nullable: true,
initial: null
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, initial: null, nullable: true })
})
}),
examples: new fields.StringField(),
advantageOn: new fields.ArrayField(new fields.StringField()),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
@ -65,49 +53,44 @@ export default class DHBeastform extends BaseDataItem {
return;
}
await this.updateSource({
characterTokenData: {
tokenImg: this.parent.parent.prototypeToken.texture.src,
tokenSize: {
height: this.parent.parent.prototypeToken.height,
width: this.parent.parent.prototypeToken.width
}
}
});
}
const features = await this.parent.parent.createEmbeddedDocuments(
'Item',
this.features.map(x => x.toObject())
);
const effects = await this.parent.parent.createEmbeddedDocuments(
'ActiveEffect',
this.parent.effects.map(x => x.toObject())
);
_onCreate(data, options, userId) {
super._onCreate(data, options, userId);
const update = {
height: this.tokenSize.height,
width: this.tokenSize.width,
texture: {
src: this.tokenImg
}
};
updateActorTokens(this.parent.parent, update);
this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
{
type: 'beastform',
name: game.i18n.localize('DAGGERHEART.Sheets.Beastform.beastformEffect'),
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
system: {
isBeastform: true
isBeastform: true,
characterTokenData: {
tokenImg: this.parent.parent.prototypeToken.texture.src,
tokenSize: {
height: this.parent.parent.prototypeToken.height,
width: this.parent.parent.prototypeToken.width
}
},
advantageOn: this.advantageOn,
featureIds: features.map(x => x.id),
effectIds: effects.map(x => x.id)
}
}
]);
}
async _preDelete() {
const update = {
height: this.characterTokenData.tokenSize.height,
width: this.characterTokenData.tokenSize.width,
await updateActorTokens(this.parent.parent, {
height: this.tokenSize.height,
width: this.tokenSize.width,
texture: {
src: this.characterTokenData.tokenImg
src: this.tokenImg
}
};
await updateActorTokens(this.parent.parent, update);
});
return false;
}
}