mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Fixed the rest
This commit is contained in:
parent
ee89d5cb9e
commit
b1f2bdbee5
4 changed files with 31 additions and 32 deletions
|
|
@ -754,8 +754,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
await config.resourceUpdates.updateResources();
|
||||
}
|
||||
|
||||
//TODO: redo toggleEquipItem method
|
||||
|
||||
/**
|
||||
* Toggles the equipped state of an item (armor or weapon).
|
||||
* @type {ApplicationClickAction}
|
||||
|
|
@ -830,12 +828,13 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
*/
|
||||
static async #toggleVault(_event, button) {
|
||||
const doc = await getDocFromElement(button);
|
||||
const { available } = this.document.system.loadoutSlot;
|
||||
if (doc.system.inVault && !available && !doc.system.loadoutIgnore) {
|
||||
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.loadoutMaxReached'));
|
||||
}
|
||||
|
||||
await doc?.update({ 'system.inVault': !doc.system.inVault });
|
||||
const changedData = await this.document.toggleDomainCardVault(doc);
|
||||
const removedData = changedData.filter(x => !x.add);
|
||||
this.document.update({
|
||||
'system.sidebarFavorites': [
|
||||
...this.document.system.sidebarFavorites.filter(x => removedData.every(r => r.item.id !== x.id))
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -554,6 +554,7 @@ export default function DHApplicationMixin(Base) {
|
|||
callback: async (target, _event) => {
|
||||
const doc = await getDocFromElement(target);
|
||||
if (doc.type === 'domainCard') {
|
||||
this.document.setFavoriteItem(doc, false);
|
||||
} else {
|
||||
this.document.update({
|
||||
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(
|
||||
|
|
|
|||
|
|
@ -72,26 +72,6 @@ export default class DHDomainCard extends BaseDataItem {
|
|||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preUpdate(data, options, user) {
|
||||
const allowed = await super._preUpdate(data, options, user);
|
||||
if (allowed === false) return;
|
||||
|
||||
if (this.parent.parent?.type === 'character') {
|
||||
if (
|
||||
data.system?.inVault &&
|
||||
!this.inVault &&
|
||||
this.parent.parent.system.sidebarFavorites.find(x => x?.id === this.parent.id)
|
||||
) {
|
||||
this.parent.parent.update({
|
||||
'system.sidebarFavorites': this.parent.parent.system.sidebarFavorites.filter(
|
||||
x => x.id !== this.parent.id
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preCreate(data, options, user) {
|
||||
const allowed = await super._preCreate(data, options, user);
|
||||
|
|
|
|||
|
|
@ -993,6 +993,18 @@ export default class DhpActor extends Actor {
|
|||
return allTokens;
|
||||
}
|
||||
|
||||
async toggleDomainCardVault(card, options = { render: true }) {
|
||||
const { render } = options;
|
||||
const { available } = this.system.loadoutSlot;
|
||||
|
||||
if (card.system.inVault && !available && !card.system.loadoutIgnore) {
|
||||
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.loadoutMaxReached'));
|
||||
}
|
||||
|
||||
await card?.update({ 'system.inVault': !card.system.inVault }, { render });
|
||||
return [{ item: card, add: !card.system.inVault }];
|
||||
}
|
||||
|
||||
async unequipBeforeEquip(itemToEquip, options = { render: true }) {
|
||||
const { render } = options;
|
||||
|
||||
|
|
@ -1030,7 +1042,7 @@ export default class DhpActor extends Actor {
|
|||
await item.update({ 'system.equipped': equip }, { render });
|
||||
};
|
||||
|
||||
if (item.system.equipped) {
|
||||
if (item.system.equipped && [undefined, false].includes(options.equip)) {
|
||||
await updateAndAddChangedItem(item, false);
|
||||
return changedItems;
|
||||
}
|
||||
|
|
@ -1051,7 +1063,7 @@ export default class DhpActor extends Actor {
|
|||
);
|
||||
}
|
||||
|
||||
const unequippedItems = await this.unequipBeforeEquip(item, { render });
|
||||
const unequippedItems = await this.unequipBeforeEquip(item, { render: false });
|
||||
changedItems.push(...unequippedItems.map(x => ({ item: x, add: false })));
|
||||
await updateAndAddChangedItem(item, true);
|
||||
break;
|
||||
|
|
@ -1060,11 +1072,18 @@ export default class DhpActor extends Actor {
|
|||
return changedItems;
|
||||
}
|
||||
|
||||
/* This is very convoluted, and there is almost certainly a better way to do it. I couldn't get it working any better way atm though. */
|
||||
async setFavoriteItem(item, setFavorited) {
|
||||
const favoritesToRemove = [];
|
||||
const favoritesToAdd = [];
|
||||
if (item.type === 'weapon') {
|
||||
const changedData = await this.toggleEquipItem(item, { render: false });
|
||||
if (['weapon', 'armor'].includes(item.type)) {
|
||||
const changedData = await this.toggleEquipItem(item, { render: false, equip: setFavorited });
|
||||
for (const data of changedData) {
|
||||
if (data.add) favoritesToAdd.push(data.item);
|
||||
else favoritesToRemove.push(data.item);
|
||||
}
|
||||
} else if (item.type === 'domainCard') {
|
||||
const changedData = await this.toggleDomainCardVault(item, { render: false });
|
||||
for (const data of changedData) {
|
||||
if (data.add) favoritesToAdd.push(data.item);
|
||||
else favoritesToRemove.push(data.item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue