Prune missing party members

This commit is contained in:
Carlos Fernandez 2025-11-14 17:30:43 -05:00
parent fbf1ee2046
commit a647b1ea41
2 changed files with 5 additions and 3 deletions

View file

@ -7,7 +7,7 @@ export default class DhParty extends BaseDataActor {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }),
partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }, { prune: true }),
notes: new fields.HTMLField(),
gold: new fields.SchemaField({
coins: new fields.NumberField({ initial: 0, integer: true }),
@ -27,7 +27,6 @@ export default class DhParty extends BaseDataActor {
prepareBaseData() {
super.prepareBaseData();
this.partyMembers = this.partyMembers.filter(p => !!p);
// Register this party to all members
if (game.actors.get(this.parent.id) === this.parent) {

View file

@ -15,6 +15,9 @@ export default class ForeignDocumentUUIDArrayField extends foundry.data.fields.A
/** @inheritdoc */
initialize(value, model, options = {}) {
const v = super.initialize(value, model, options);
return () => v.map(entry => (typeof entry === 'function' ? entry() : entry));
return () => {
const data = v.map(entry => (typeof entry === 'function' ? entry() : entry));
return this.options.prune ? data.filter((d) => !!d) : d;
};
}
}