Beastform Improvements (#294)

* BeastformEffect is editable. Added SubjectTexture field.

* Using handlebars disabled helper
This commit is contained in:
WBHarry 2025-07-08 21:01:28 +02:00 committed by GitHub
parent 61f04df765
commit 861dfd977d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 81 additions and 32 deletions

View file

@ -1129,6 +1129,7 @@
"examples": { "label": "Examples" },
"advantageOn": { "label": "Gain Advantage On" },
"tokenImg": { "label": "Token Image" },
"tokenRingImg": { "label": "Subject Texture" },
"tokenSize": {
"placeholder": "Using character dimensions",
"height": { "label": "Height" },

View file

@ -188,7 +188,17 @@ export default class CharacterSheet extends DHBaseActorSheet {
* @param {HTMLElement} el
* @returns {foundry.documents.Item?}
*/
const getItem = el => this.actor.items.get(el.closest('[data-item-id]')?.dataset.itemId);
const getItem = element => {
const listElement = (element.target ?? element).closest('[data-item-id]');
const itemId = listElement.dataset.itemId;
switch (listElement.dataset.type) {
case 'effect':
return this.document.effects.get(itemId);
default:
return this.document.items.get(itemId);
}
};
return [
{

View file

@ -30,8 +30,17 @@ export default class BeastformSheet extends DHBaseItemSheet {
};
/**@inheritdoc */
async _preparePartContext(partId, context) {
await super._preparePartContext(partId, context);
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.document = context.document.toObject();
context.document.effects = this.document.effects.map(effect => {
const data = effect.toObject();
data.id = effect.id;
if (effect.type === 'beastform') data.mandatory = true;
return data;
});
return context;
}

View file

@ -10,6 +10,11 @@ export default class BeastformEffect extends foundry.abstract.TypeDataModel {
base64: false,
nullable: true
}),
tokenRingImg: new fields.FilePathField({
initial: 'icons/svg/mystery-man.svg',
categories: ['IMAGE'],
base64: false
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, nullable: true }),
width: new fields.NumberField({ integer: true, nullable: true })
@ -28,6 +33,11 @@ export default class BeastformEffect extends foundry.abstract.TypeDataModel {
width: this.characterTokenData.tokenSize.width,
texture: {
src: this.characterTokenData.tokenImg
},
ring: {
subject: {
texture: this.characterTokenData.tokenRingImg
}
}
};

View file

@ -3,7 +3,7 @@ import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayFie
import BaseDataItem from './base.mjs';
export default class DHBeastform extends BaseDataItem {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Sheets.Beastform'];
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ITEMS.Beastform'];
/** @inheritDoc */
static get metadata() {
@ -29,12 +29,17 @@ export default class DHBeastform extends BaseDataItem {
categories: ['IMAGE'],
base64: false
}),
tokenRingImg: new fields.FilePathField({
initial: 'icons/svg/mystery-man.svg',
categories: ['IMAGE'],
base64: false
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
}),
examples: new fields.StringField(),
advantageOn: new fields.ArrayField(new fields.StringField()),
advantageOn: new fields.StringField(),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
@ -56,40 +61,54 @@ export default class DHBeastform extends BaseDataItem {
'Item',
this.features.map(x => x.toObject())
);
const effects = await this.parent.parent.createEmbeddedDocuments(
const extraEffects = await this.parent.parent.createEmbeddedDocuments(
'ActiveEffect',
this.parent.effects.map(x => x.toObject())
this.parent.effects.filter(x => x.type !== 'beastform').map(x => x.toObject())
);
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
{
type: 'beastform',
name: game.i18n.localize('DAGGERHEART.ITEMS.Beastform.beastformEffect'),
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
system: {
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)
}
const beastformEffect = this.parent.effects.find(x => x.type === 'beastform');
await beastformEffect.updateSource({
system: {
characterTokenData: {
tokenImg: this.parent.parent.prototypeToken.texture.src,
tokenRingImg: this.parent.parent.prototypeToken.ring.subject.texture,
tokenSize: {
height: this.parent.parent.prototypeToken.height,
width: this.parent.parent.prototypeToken.width
}
},
advantageOn: this.advantageOn,
featureIds: features.map(x => x.id),
effectIds: extraEffects.map(x => x.id)
}
]);
});
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [beastformEffect.toObject()]);
await updateActorTokens(this.parent.parent, {
height: this.tokenSize.height,
width: this.tokenSize.width,
texture: {
src: this.tokenImg
},
ring: {
subject: {
texture: this.tokenRingImg
}
}
});
return false;
}
_onCreate() {
this.parent.createEmbeddedDocuments('ActiveEffect', [
{
type: 'beastform',
name: game.i18n.localize('DAGGERHEART.ITEMS.Beastform.beastformEffect'),
img: 'icons/creatures/abilities/paw-print-pair-purple.webp'
}
]);
}
}

View file

@ -17,7 +17,7 @@
<span>{{effect.name}}</span>
<div class="controls">
<a data-action="editDoc" data-type="ActiveEffect" data-doc-id="{{effect.id}}"><i class="fa-solid fa-pen-to-square"></i></a>
<a data-action="deleteDoc" data-type="ActiveEffect" data-doc-id="{{effect.id}}"><i class="fa-solid fa-trash"></i></a>
<a data-action="deleteDoc" data-type="ActiveEffect" data-doc-id="{{effect.id}}" {{disabled effect.mandatory}}><i class="fa-solid fa-trash icon-button {{disabled effect.mandatory}}"></i></a>
</div>
</div>
{{/each}}

View file

@ -8,11 +8,7 @@
{{formGroup systemFields.examples value=source.system.examples localize=true}}
</div>
<fieldset class="two-columns">
<legend>{{localize "DAGGERHEART.ITEMS.Beastform.FIELDS.advantageOn.label"}}</legend>
{{!-- {{formGroup systemFields.examples value=source.system.examples localize=true}} --}}
</fieldset>
{{formGroup systemFields.advantageOn value=source.system.advantageOn localize=true}}
<fieldset class="two-columns even">
<legend>{{localize "DAGGERHEART.ITEMS.Beastform.tokenTitle"}}</legend>
@ -21,6 +17,10 @@
{{formGroup systemFields.tokenImg value=source.system.tokenImg localize=true}}
</div>
<div class="full-width">
{{formGroup systemFields.tokenRingImg value=source.system.tokenRingImg localize=true}}
</div>
{{formGroup systemFields.tokenSize.fields.height value=source.system.tokenSize.height localize=true placeholder=(localize "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder") }}
{{formGroup systemFields.tokenSize.fields.width value=source.system.tokenSize.width localize=true placeholder=(localize "DAGGERHEART.ITEMS.Beastform.FIELDS.tokenSize.placeholder")}}
</fieldset>