Fixed the rest

This commit is contained in:
WBHarry 2026-01-27 17:08:36 +01:00
parent ee89d5cb9e
commit b1f2bdbee5
4 changed files with 31 additions and 32 deletions

View file

@ -754,8 +754,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
await config.resourceUpdates.updateResources(); await config.resourceUpdates.updateResources();
} }
//TODO: redo toggleEquipItem method
/** /**
* Toggles the equipped state of an item (armor or weapon). * Toggles the equipped state of an item (armor or weapon).
* @type {ApplicationClickAction} * @type {ApplicationClickAction}
@ -830,12 +828,13 @@ export default class CharacterSheet extends DHBaseActorSheet {
*/ */
static async #toggleVault(_event, button) { static async #toggleVault(_event, button) {
const doc = await getDocFromElement(button); const doc = await getDocFromElement(button);
const { available } = this.document.system.loadoutSlot; const changedData = await this.document.toggleDomainCardVault(doc);
if (doc.system.inVault && !available && !doc.system.loadoutIgnore) { const removedData = changedData.filter(x => !x.add);
return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.loadoutMaxReached')); this.document.update({
} 'system.sidebarFavorites': [
...this.document.system.sidebarFavorites.filter(x => removedData.every(r => r.item.id !== x.id))
await doc?.update({ 'system.inVault': !doc.system.inVault }); ]
});
} }
/** /**

View file

@ -554,6 +554,7 @@ export default function DHApplicationMixin(Base) {
callback: async (target, _event) => { callback: async (target, _event) => {
const doc = await getDocFromElement(target); const doc = await getDocFromElement(target);
if (doc.type === 'domainCard') { if (doc.type === 'domainCard') {
this.document.setFavoriteItem(doc, false);
} else { } else {
this.document.update({ this.document.update({
'system.sidebarFavorites': this.document.system.sidebarFavorites.filter( 'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(

View file

@ -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 */ /**@inheritdoc */
async _preCreate(data, options, user) { async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user); const allowed = await super._preCreate(data, options, user);

View file

@ -993,6 +993,18 @@ export default class DhpActor extends Actor {
return allTokens; 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 }) { async unequipBeforeEquip(itemToEquip, options = { render: true }) {
const { render } = options; const { render } = options;
@ -1030,7 +1042,7 @@ export default class DhpActor extends Actor {
await item.update({ 'system.equipped': equip }, { render }); await item.update({ 'system.equipped': equip }, { render });
}; };
if (item.system.equipped) { if (item.system.equipped && [undefined, false].includes(options.equip)) {
await updateAndAddChangedItem(item, false); await updateAndAddChangedItem(item, false);
return changedItems; 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 }))); changedItems.push(...unequippedItems.map(x => ({ item: x, add: false })));
await updateAndAddChangedItem(item, true); await updateAndAddChangedItem(item, true);
break; break;
@ -1060,11 +1072,18 @@ export default class DhpActor extends Actor {
return changedItems; 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) { async setFavoriteItem(item, setFavorited) {
const favoritesToRemove = []; const favoritesToRemove = [];
const favoritesToAdd = []; const favoritesToAdd = [];
if (item.type === 'weapon') { if (['weapon', 'armor'].includes(item.type)) {
const changedData = await this.toggleEquipItem(item, { render: false }); 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) { for (const data of changedData) {
if (data.add) favoritesToAdd.push(data.item); if (data.add) favoritesToAdd.push(data.item);
else favoritesToRemove.push(data.item); else favoritesToRemove.push(data.item);