mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Improved
This commit is contained in:
parent
f0a809266d
commit
e8343de4e4
4 changed files with 52 additions and 52 deletions
|
|
@ -63,6 +63,26 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
return this.document.system.features.map(x => x.item);
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _onFirstRender(context, options) {
|
||||
await super._onFirstRender(context, options);
|
||||
|
||||
const paths = [
|
||||
'subclasses',
|
||||
'characterGuide.suggestedPrimaryWeapon',
|
||||
'characterGuide.suggestedSecondaryWeapon',
|
||||
'characterGuide.suggestedArmor',
|
||||
'inventory.take',
|
||||
'inventory.choiceA',
|
||||
'inventory.choiceB'
|
||||
];
|
||||
|
||||
paths.forEach(path => {
|
||||
const docs = [].concat(foundry.utils.getProperty(this.document, `system.${path}`) ?? []);
|
||||
docs.forEach(doc => (doc.apps[this.id] = this));
|
||||
});
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
|
|
|
|||
|
|
@ -159,12 +159,12 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
const allowed = await super._preUpdate(changed, options, userId);
|
||||
if (allowed === false) return false;
|
||||
|
||||
addLinkedItemsDiff(changed.system?.features, this.features, options, 'changedFeatures');
|
||||
addLinkedItemsDiff(changed.system?.features, this.features, options);
|
||||
}
|
||||
|
||||
_onUpdate(changed, options, userId) {
|
||||
super._onUpdate(changed, options, userId);
|
||||
|
||||
updateLinkedItemApps(options, 'changedFeatures', this.parent.sheet);
|
||||
updateLinkedItemApps(options, this.parent.sheet);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,44 +102,28 @@ export default class DHClass extends BaseDataItem {
|
|||
const allowed = await super._preUpdate(changed, options, userId);
|
||||
if (allowed === false) return false;
|
||||
|
||||
addLinkedItemsDiff(changed.system?.subclasses, this.subclasses, options, 'changedSubclasses');
|
||||
const paths = [
|
||||
'subclasses',
|
||||
'characterGuide.suggestedPrimaryWeapon',
|
||||
'characterGuide.suggestedSecondaryWeapon',
|
||||
'characterGuide.suggestedArmor',
|
||||
'inventory.take',
|
||||
'inventory.choiceA',
|
||||
'inventory.choiceB'
|
||||
];
|
||||
|
||||
const guide = changed.system?.characterGuide;
|
||||
addLinkedItemsDiff(
|
||||
guide?.suggestedPrimaryWeapon ? [guide.suggestedPrimaryWeapon] : null,
|
||||
this.characterGuide.suggestedPrimaryWeapon ? [this.characterGuide.suggestedPrimaryWeapon] : [],
|
||||
options,
|
||||
'primaryWeapon'
|
||||
);
|
||||
addLinkedItemsDiff(
|
||||
guide?.suggestedSecondaryWeapon ? [guide.suggestedSecondaryWeapon] : null,
|
||||
this.characterGuide.suggestedSecondaryWeapon ? [this.characterGuide.suggestedSecondaryWeapon] : [],
|
||||
options,
|
||||
'secondaryWeapon'
|
||||
);
|
||||
addLinkedItemsDiff(
|
||||
guide?.suggestedArmor ? [guide.suggestedArmor] : null,
|
||||
this.characterGuide.suggestedArmor ? [this.characterGuide.suggestedArmor] : [],
|
||||
options,
|
||||
'armor'
|
||||
);
|
||||
for (let path of paths) {
|
||||
const currentItems = [].concat(foundry.utils.getProperty(this, path) ?? []);
|
||||
const changedItems = [].concat(foundry.utils.getProperty(changed, `system.${path}`) ?? []);
|
||||
if (!changedItems.length) continue;
|
||||
|
||||
addLinkedItemsDiff(changed.system?.inventory?.take, this.inventory.take, options, 'changedTake');
|
||||
addLinkedItemsDiff(changed.system?.inventory?.choiceA, this.inventory.choiceA, options, 'changedChoiceA');
|
||||
addLinkedItemsDiff(changed.system?.inventory?.choiceB, this.inventory.choiceB, options, 'changedChoiceB');
|
||||
addLinkedItemsDiff(changedItems, currentItems, options);
|
||||
}
|
||||
}
|
||||
|
||||
_onUpdate(changed, options, userId) {
|
||||
super._onUpdate(changed, options, userId);
|
||||
|
||||
updateLinkedItemApps(options, 'changedSubclasses', this.parent.sheet);
|
||||
|
||||
updateLinkedItemApps(options, 'primaryWeapon', this.parent.sheet);
|
||||
updateLinkedItemApps(options, 'secondaryWeapon', this.parent.sheet);
|
||||
updateLinkedItemApps(options, 'armor', this.parent.sheet);
|
||||
|
||||
updateLinkedItemApps(options, 'changedTake', this.parent.sheet);
|
||||
updateLinkedItemApps(options, 'changedChoiceA', this.parent.sheet);
|
||||
updateLinkedItemApps(options, 'changedChoiceB', this.parent.sheet);
|
||||
updateLinkedItemApps(options, this.parent.sheet);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,16 +247,15 @@ export function getDocFromElement(element) {
|
|||
* @param {Array} changedItems The candidate changed list
|
||||
* @param {Array} currentItems The current list
|
||||
* @param {object} options Additional options which modify the update request
|
||||
* @param {string} optionsName The name of the options property holding the diff
|
||||
*/
|
||||
export function addLinkedItemsDiff(changedItems, currentItems, options, optionsName) {
|
||||
export function addLinkedItemsDiff(changedItems, currentItems, options) {
|
||||
if (changedItems) {
|
||||
const prevItems = new Set(currentItems);
|
||||
const newItems = new Set(changedItems);
|
||||
options[optionsName] = {
|
||||
toLink: Array.from(newItems.difference(prevItems).map(item => item?.item ?? item)),
|
||||
toUnlink: Array.from(prevItems.difference(newItems).map(item => item?.item?.uuid ?? item?.uuid ?? item))
|
||||
};
|
||||
options.toLink = Array.from(newItems.difference(prevItems).map(item => item?.item ?? item));
|
||||
options.toUnlink = Array.from(
|
||||
prevItems.difference(newItems).map(item => item?.item?.uuid ?? item?.uuid ?? item)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -264,20 +263,17 @@ export function addLinkedItemsDiff(changedItems, currentItems, options, optionsN
|
|||
* Adds or removes the current Application from linked document apps
|
||||
* depending on an update diff in the linked item list.
|
||||
* @param {object} options Additional options which modify the update requests
|
||||
* @param {string} optionName The prop name on options of the update diff
|
||||
* @param {object} sheet The application to add or remove from document apps
|
||||
*/
|
||||
export function updateLinkedItemApps(options, optionName, sheet) {
|
||||
if (options[optionName]) {
|
||||
options[optionName].toLink.forEach(featureUuid => {
|
||||
const doc = foundry.utils.fromUuidSync(featureUuid);
|
||||
doc.apps[sheet.id] = sheet;
|
||||
});
|
||||
options[optionName].toUnlink.forEach(featureUuid => {
|
||||
const doc = foundry.utils.fromUuidSync(featureUuid);
|
||||
delete doc.apps[sheet.id];
|
||||
});
|
||||
}
|
||||
export function updateLinkedItemApps(options, sheet) {
|
||||
options.toLink?.forEach(featureUuid => {
|
||||
const doc = foundry.utils.fromUuidSync(featureUuid);
|
||||
doc.apps[sheet.id] = sheet;
|
||||
});
|
||||
options.toUnlink?.forEach(featureUuid => {
|
||||
const doc = foundry.utils.fromUuidSync(featureUuid);
|
||||
delete doc.apps[sheet.id];
|
||||
});
|
||||
}
|
||||
|
||||
export const itemAbleRollParse = (value, actor, item) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue