Fixed MixedAncestry name setting

This commit is contained in:
WBHarry 2025-08-11 23:50:28 +02:00
parent 5da20e36c0
commit b3dd981d28
2 changed files with 12 additions and 5 deletions

View file

@ -13,7 +13,10 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
this.setup = { this.setup = {
traits: this.character.system.traits, traits: this.character.system.traits,
ancestryName: '', ancestryName: {
primary: '',
secondary: ''
},
mixedAncestry: false, mixedAncestry: false,
primaryAncestry: this.character.system.ancestry ?? {}, primaryAncestry: this.character.system.ancestry ?? {},
secondaryAncestry: {}, secondaryAncestry: {},
@ -240,7 +243,9 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
}; };
context.mixedAncestry = Number(this.setup.mixedAncestry); context.mixedAncestry = Number(this.setup.mixedAncestry);
context.ancestryName = this.setup.ancestryName;
const { primary, secondary, overwrite } = this.setup.ancestryName;
context.ancestryName = overwrite ?? (primary && secondary ? `${primary}/${secondary}` : primary);
context.primaryAncestry = { ...this.setup.primaryAncestry, compendium: 'ancestries' }; context.primaryAncestry = { ...this.setup.primaryAncestry, compendium: 'ancestries' };
context.secondaryAncestry = { ...this.setup.secondaryAncestry, compendium: 'ancestries' }; context.secondaryAncestry = { ...this.setup.secondaryAncestry, compendium: 'ancestries' };
context.community = { ...this.setup.community, compendium: 'communities' }; context.community = { ...this.setup.community, compendium: 'communities' };
@ -498,9 +503,10 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
? this.setup.secondaryAncestry.system.secondaryFeature ? this.setup.secondaryAncestry.system.secondaryFeature
: this.setup.primaryAncestry.system.secondaryFeature; : this.setup.primaryAncestry.system.secondaryFeature;
const { primary, secondary, overwrite } = this.setup.ancestryName;
const ancestry = { const ancestry = {
...this.setup.primaryAncestry, ...this.setup.primaryAncestry,
name: this.setup.ancestryName ?? this.setup.primaryAncestry.name, name: overwrite ?? (primary && secondary ? `${primary}/${secondary}` : primary),
system: { system: {
...this.setup.primaryAncestry.system, ...this.setup.primaryAncestry.system,
features: [ features: [
@ -572,13 +578,14 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
const item = await foundry.utils.fromUuid(data.uuid); const item = await foundry.utils.fromUuid(data.uuid);
if (item.type === 'ancestry' && event.target.closest('.primary-ancestry-card')) { if (item.type === 'ancestry' && event.target.closest('.primary-ancestry-card')) {
this.setup.ancestryName = item.name; this.setup.ancestryName.primary = item.name;
this.setup.primaryAncestry = { this.setup.primaryAncestry = {
...item, ...item,
effects: Array.from(item.effects).map(x => x.toObject()), effects: Array.from(item.effects).map(x => x.toObject()),
uuid: item.uuid uuid: item.uuid
}; };
} else if (item.type === 'ancestry' && event.target.closest('.secondary-ancestry-card')) { } else if (item.type === 'ancestry' && event.target.closest('.secondary-ancestry-card')) {
this.setup.ancestryName.secondary = item.name;
this.setup.secondaryAncestry = { this.setup.secondaryAncestry = {
...item, ...item,
effects: Array.from(item.effects).map(x => x.toObject()), effects: Array.from(item.effects).map(x => x.toObject()),

View file

@ -8,7 +8,7 @@
<legend>{{localize "TYPES.Item.ancestry"}}</legend> <legend>{{localize "TYPES.Item.ancestry"}}</legend>
<div class="ancestry-name"> <div class="ancestry-name">
<input type="text" name="ancestryName" value="{{ancestryName}}" placeholder="{{localize "DAGGERHEART.APPLICATIONS.CharacterCreation.ancestryNamePlaceholder"}}" {{disabled (not primaryAncestry.uuid)}} /> <input type="text" name="ancestryName.overwrite" value="{{ancestryName}}" placeholder="{{localize "DAGGERHEART.APPLICATIONS.CharacterCreation.ancestryNamePlaceholder"}}" {{disabled (not primaryAncestry.uuid)}} />
</div> </div>
<div class="ancestry-mixed-controller {{#if mixedAncestry}}active{{/if}}"> <div class="ancestry-mixed-controller {{#if mixedAncestry}}active{{/if}}">