Added size to Beastform tokenData

This commit is contained in:
WBHarry 2025-12-21 01:31:25 +01:00
parent 0f52eb0492
commit 989a6e3a2a
5 changed files with 79 additions and 28 deletions

View file

@ -2236,6 +2236,7 @@
"tokenRingImg": { "label": "Subject Texture" }, "tokenRingImg": { "label": "Subject Texture" },
"tokenSize": { "tokenSize": {
"placeholder": "Using character dimensions", "placeholder": "Using character dimensions",
"disabledPlaceholder": "Set by character size",
"height": { "label": "Height" }, "height": { "label": "Height" },
"width": { "label": "Width" } "width": { "label": "Width" }
}, },

View file

@ -77,6 +77,7 @@ export default class BeastformSheet extends DHBaseItemSheet {
name: context.document.system.advantageOn[key].value name: context.document.system.advantageOn[key].value
})) }))
); );
context.dimensionsDisabled = context.document.system.tokenSize.size === 'custom';
break; break;
case 'effects': case 'effects':
context.effects.actives = context.effects.actives.map(effect => { context.effects.actives = context.effects.actives.map(effect => {

View file

@ -65,20 +65,30 @@ export default class BeastformEffect extends BaseEffect {
} }
}; };
const updateToken = token => ({ const updateToken = token => {
...baseUpdate, const { x, y } = game.system.api.documents.DhToken.getSnappedPositionInSquareGrid(
'texture': { token.object.scene.grid,
enabled: this.characterTokenData.usesDynamicToken, { x: token.x, y: token.y, elevation: token.elevation },
src: token.flags.daggerheart?.beastformTokenImg ?? this.characterTokenData.tokenImg baseUpdate.width,
}, baseUpdate.height
'ring': { );
subject: { return {
texture: ...baseUpdate,
token.flags.daggerheart?.beastformSubjectTexture ?? this.characterTokenData.tokenRingImg x,
} y,
}, 'texture': {
'flags.daggerheart': { '-=beastformTokenImg': null, '-=beastformSubjectTexture': null } enabled: this.characterTokenData.usesDynamicToken,
}); src: token.flags.daggerheart?.beastformTokenImg ?? this.characterTokenData.tokenImg
},
'ring': {
subject: {
texture:
token.flags.daggerheart?.beastformSubjectTexture ?? this.characterTokenData.tokenRingImg
}
},
'flags.daggerheart': { '-=beastformTokenImg': null, '-=beastformSubjectTexture': null }
};
};
await updateActorTokens(this.parent.parent, update, updateToken); await updateActorTokens(this.parent.parent, update, updateToken);

View file

@ -43,6 +43,12 @@ export default class DHBeastform extends BaseDataItem {
base64: false base64: false
}), }),
tokenSize: new fields.SchemaField({ tokenSize: new fields.SchemaField({
size: new fields.StringField({
required: true,
nullable: false,
choices: CONFIG.DH.ACTOR.tokenSize,
initial: CONFIG.DH.ACTOR.tokenSize.custom.id
}),
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }), height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }) width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
}), }),
@ -190,9 +196,18 @@ export default class DHBeastform extends BaseDataItem {
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [beastformEffect.toObject()]); await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [beastformEffect.toObject()]);
let width = this.tokenSize.width;
let height = this.tokenSize.height;
if (this.tokenSize.size !== 'custom') {
const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes;
const tokenSize = tokenSizes[this.tokenSize.size];
width = tokenSize;
height = tokenSize;
}
const prototypeTokenUpdate = { const prototypeTokenUpdate = {
height: this.tokenSize.height, height,
width: this.tokenSize.width, width,
texture: { texture: {
src: this.tokenImg src: this.tokenImg
}, },
@ -202,16 +217,25 @@ export default class DHBeastform extends BaseDataItem {
} }
} }
}; };
const tokenUpdate = token => {
const tokenUpdate = token => ({ const { x, y } = game.system.api.documents.DhToken.getSnappedPositionInSquareGrid(
...prototypeTokenUpdate, token.object.scene.grid,
flags: { { x: token.x, y: token.y, elevation: token.elevation },
daggerheart: { width,
beastformTokenImg: token.texture.src, height
beastformSubjectTexture: token.ring.subject.texture );
return {
...prototypeTokenUpdate,
x,
y,
flags: {
daggerheart: {
beastformTokenImg: token.texture.src,
beastformSubjectTexture: token.ring.subject.texture
}
} }
} };
}); };
await updateActorTokens(this.parent.parent, prototypeTokenUpdate, tokenUpdate); await updateActorTokens(this.parent.parent, prototypeTokenUpdate, tokenUpdate);

View file

@ -20,7 +20,7 @@
{{/unless}} {{/unless}}
{{/if}} {{/if}}
<fieldset class="two-columns even"> <fieldset>
<legend>{{localize "DAGGERHEART.ITEMS.Beastform.tokenTitle"}}</legend> <legend>{{localize "DAGGERHEART.ITEMS.Beastform.tokenTitle"}}</legend>
<div class="full-width"> <div class="full-width">
@ -31,7 +31,22 @@
{{formGroup systemFields.tokenRingImg value=source.system.tokenRingImg localize=true}} {{formGroup systemFields.tokenRingImg value=source.system.tokenRingImg localize=true}}
</div> </div>
{{formGroup systemFields.tokenSize.fields.height value=source.system.tokenSize.height localize=true placeholder=(localize "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder") }} <div class="nest-inputs">
{{formGroup systemFields.tokenSize.fields.width value=source.system.tokenSize.width localize=true placeholder=(localize "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder")}} {{formGroup systemFields.tokenSize.fields.size value=source.system.tokenSize.size label=(localize "DAGGERHEART.GENERAL.tokenSize") localize=true }}
{{formGroup
systemFields.tokenSize.fields.height
value=source.system.tokenSize.height
localize=true
placeholder=(localize (ifThen dimensionsDisabled "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.disabledPlaceholder" "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder"))
disabled=dimensionsDisabled
}}
{{formGroup
systemFields.tokenSize.fields.width
value=source.system.tokenSize.width
localize=true
placeholder=(localize (ifThen dimensionsDisabled "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.disabledPlaceholder" "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder"))
disabled=dimensionsDisabled
}}
</div>
</fieldset> </fieldset>
</section> </section>