mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Fixes links upon being embedded
This commit is contained in:
parent
df8b96e9bc
commit
b1aca218c2
3 changed files with 64 additions and 14 deletions
|
|
@ -205,7 +205,11 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
|
|
||||||
_getSetupTabs(tabs) {
|
_getSetupTabs(tabs) {
|
||||||
for (const v of Object.values(tabs)) {
|
for (const v of Object.values(tabs)) {
|
||||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
v.active = this.tabGroups[v.group]
|
||||||
|
? this.tabGroups[v.group] === v.id
|
||||||
|
: this.tabGroups.primary !== 'equipment'
|
||||||
|
? v.active
|
||||||
|
: false;
|
||||||
v.cssClass = v.active ? 'active' : '';
|
v.cssClass = v.active ? 'active' : '';
|
||||||
|
|
||||||
switch (v.id) {
|
switch (v.id) {
|
||||||
|
|
@ -242,6 +246,16 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
marker.classList.remove('active');
|
marker.classList.remove('active');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tab === 'equipment') {
|
||||||
|
this.tabGroups.setup = null;
|
||||||
|
this.element.querySelector('section[data-group="setup"].active')?.classList?.remove?.('active');
|
||||||
|
} else {
|
||||||
|
this.tabGroups.setup = 'domainCards';
|
||||||
|
this.element
|
||||||
|
.querySelector('section[data-group="setup"][data-tab="domainCards"]')
|
||||||
|
?.classList?.add?.('active');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +280,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
async _preparePartContext(partId, context) {
|
async _preparePartContext(partId, context) {
|
||||||
switch (partId) {
|
switch (partId) {
|
||||||
case 'footer':
|
case 'footer':
|
||||||
context.isLastTab = this.tabGroups.setup === 'domainCards';
|
context.isLastTab = this.tabGroups.setup === 'domainCards' || this.tabGroups.primary !== 'setup';
|
||||||
switch (this.tabGroups.setup) {
|
switch (this.tabGroups.setup) {
|
||||||
case null:
|
case null:
|
||||||
case 'ancestry':
|
case 'ancestry':
|
||||||
|
|
@ -353,13 +367,18 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
);
|
);
|
||||||
context.armor = {
|
context.armor = {
|
||||||
...this.equipment.armor,
|
...this.equipment.armor,
|
||||||
suggestion: { ...suggestions.armor, taken: suggestions.armor?.uuid === this.equipment.armor?.uuid },
|
suggestion: {
|
||||||
|
...suggestions.armor,
|
||||||
|
uuid: suggestions.armor?.uuid,
|
||||||
|
taken: suggestions.armor?.uuid === this.equipment.armor?.uuid
|
||||||
|
},
|
||||||
compendium: 'armors'
|
compendium: 'armors'
|
||||||
};
|
};
|
||||||
context.primaryWeapon = {
|
context.primaryWeapon = {
|
||||||
...this.equipment.primaryWeapon,
|
...this.equipment.primaryWeapon,
|
||||||
suggestion: {
|
suggestion: {
|
||||||
...suggestions.primaryWeapon,
|
...suggestions.primaryWeapon,
|
||||||
|
uuid: suggestions.primaryWeapon?.uuid,
|
||||||
taken: suggestions.primaryWeapon?.uuid === this.equipment.primaryWeapon?.uuid
|
taken: suggestions.primaryWeapon?.uuid === this.equipment.primaryWeapon?.uuid
|
||||||
},
|
},
|
||||||
compendium: 'weapons'
|
compendium: 'weapons'
|
||||||
|
|
@ -368,6 +387,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
...this.equipment.secondaryWeapon,
|
...this.equipment.secondaryWeapon,
|
||||||
suggestion: {
|
suggestion: {
|
||||||
...suggestions.secondaryWeapon,
|
...suggestions.secondaryWeapon,
|
||||||
|
uuid: suggestions.secondaryWeapon?.uuid,
|
||||||
taken: suggestions.secondaryWeapon?.uuid === this.equipment.secondaryWeapon?.uuid
|
taken: suggestions.secondaryWeapon?.uuid === this.equipment.secondaryWeapon?.uuid
|
||||||
},
|
},
|
||||||
disabled: this.equipment.primaryWeapon?.system?.burden === burden.twoHanded.value,
|
disabled: this.equipment.primaryWeapon?.system?.burden === burden.twoHanded.value,
|
||||||
|
|
@ -421,18 +441,29 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
async getEquipmentSuggestions(choiceA, choiceB) {
|
async getEquipmentSuggestions(choiceA, choiceB) {
|
||||||
if (!this.setup.class.uuid) return { inventory: { take: [] } };
|
if (!this.setup.class.uuid) return { inventory: { take: [] } };
|
||||||
|
|
||||||
const { inventory, characterGuide } = this.setup.class.system;
|
|
||||||
return {
|
return {
|
||||||
armor: characterGuide.suggestedArmor ?? null,
|
armor: this.setup.class.system.suggestedArmor ?? null,
|
||||||
primaryWeapon: characterGuide.suggestedPrimaryWeapon ?? null,
|
primaryWeapon: this.setup.class.system.suggestedPrimaryWeapon ?? null,
|
||||||
secondaryWeapon: characterGuide.suggestedSecondaryWeapon
|
secondaryWeapon: this.setup.class.system.suggestedSecondaryWeapon
|
||||||
? { ...characterGuide.suggestedSecondaryWeapon, uuid: characterGuide.suggestedSecondaryWeapon.uuid }
|
? {
|
||||||
|
...this.setup.class.system.suggestedSecondaryWeapon,
|
||||||
|
uuid: this.setup.class.system.suggestedSecondaryWeapon.uuid
|
||||||
|
}
|
||||||
: null,
|
: null,
|
||||||
inventory: {
|
inventory: {
|
||||||
take: inventory.take ?? [],
|
take: this.setup.class.system.take ?? [],
|
||||||
choiceA:
|
choiceA:
|
||||||
inventory.choiceA?.map(x => ({ ...x, uuid: x.uuid, selected: x.uuid === choiceA?.uuid })) ?? [],
|
this.setup.class.system.choiceA?.map(x => ({
|
||||||
choiceB: inventory.choiceB?.map(x => ({ ...x, uuid: x.uuid, selected: x.uuid === choiceB?.uuid })) ?? []
|
...x,
|
||||||
|
uuid: x.uuid,
|
||||||
|
selected: x.uuid === choiceA?.uuid
|
||||||
|
})) ?? [],
|
||||||
|
choiceB:
|
||||||
|
this.setup.class.system.choiceB?.map(x => ({
|
||||||
|
...x,
|
||||||
|
uuid: x.uuid,
|
||||||
|
selected: x.uuid === choiceB?.uuid
|
||||||
|
})) ?? []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -535,7 +566,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
|
||||||
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceA]);
|
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceA]);
|
||||||
if (this.equipment.inventory.choiceB.uuid)
|
if (this.equipment.inventory.choiceB.uuid)
|
||||||
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceB]);
|
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceB]);
|
||||||
await this.character.createEmbeddedDocuments('Item', this.setup.class.system.inventory.take);
|
await this.character.createEmbeddedDocuments('Item', this.setup.class.system.take);
|
||||||
|
|
||||||
await this.character.update({
|
await this.character.update({
|
||||||
system: {
|
system: {
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
classFeatures.push(item);
|
classFeatures.push(item);
|
||||||
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
|
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
|
||||||
const subclassState = this.class.subclass.system.featureState;
|
const subclassState = this.class.subclass.system.featureState;
|
||||||
const subType = item.system.subType;
|
const subType = item.system.itemLinks[this.class.subclass.uuid];
|
||||||
if (
|
if (
|
||||||
subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation ||
|
subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation ||
|
||||||
(subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization && subclassState >= 2) ||
|
(subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization && subclassState >= 2) ||
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
* @property {boolean} hasDescription - Indicates whether items of this type have description field
|
* @property {boolean} hasDescription - Indicates whether items of this type have description field
|
||||||
* @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field
|
* @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field
|
||||||
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
|
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
|
||||||
|
* @property {boolean} isItemLinkable - Indicates whether items of this type can have links to other items.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ItemLinksField from '../fields/itemLinksField.mjs';
|
import ItemLinksField from '../fields/itemLinksField.mjs';
|
||||||
|
|
@ -123,9 +124,11 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
this.updateSource({ actions: [action] });
|
this.updateSource({ actions: [action] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.origUuid = data.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCreate(data) {
|
_onCreate(data, options) {
|
||||||
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
|
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
|
||||||
|
|
||||||
this.actor.createEmbeddedDocuments(
|
this.actor.createEmbeddedDocuments(
|
||||||
|
|
@ -134,12 +137,28 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
...feature,
|
...feature,
|
||||||
system: {
|
system: {
|
||||||
...feature.system,
|
...feature.system,
|
||||||
|
itemLinks: Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
||||||
|
const type = feature.system.itemLinks[uuid];
|
||||||
|
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
originItemType: this.parent.type,
|
originItemType: this.parent.type,
|
||||||
originId: data._id,
|
originId: data._id,
|
||||||
identifier: feature.identifier
|
identifier: feature.identifier
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (let feature of this.features) {
|
||||||
|
feature.update({
|
||||||
|
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
||||||
|
const type = feature.system.itemLinks[uuid];
|
||||||
|
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _preDelete() {
|
async _preDelete() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue