diff --git a/lang/en.json b/lang/en.json index feeb65b2..e58cf4e2 100755 --- a/lang/en.json +++ b/lang/en.json @@ -266,6 +266,7 @@ "InvalidOldCharacterImportTitle": "Old Character Import", "InvalidOldCharacterImportText": "Character data exported prior to system version 1.1 will not generate a complete character. Do you wish to continue?", "cancelBeastform": "Cancel Beastform", + "sidebarFavoritesHint": "Drag items, features and domain cards from the sheet to here", "resetCharacterConfirmationTitle": "Reset Character", "resetCharacterConfirmationContent": "You are reseting all character data except name and portrait. Are you sure?" }, @@ -2260,6 +2261,10 @@ "plural": "Experiences" }, "failure": "Failure", + "favorite": { + "single": "Favorite", + "plural": "Favorites" + }, "fate": "Fate", "fateRoll": "Fate Roll", "fear": "Fear", diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index 14dd1ae7..8d6abdbb 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -56,6 +56,10 @@ export default class CharacterSheet extends DHBaseActorSheet { { dragSelector: '[data-item-id][draggable="true"], [data-item-id] [draggable="true"]', dropSelector: null + }, + { + dragSelector: null, + dropSelector: '.character-sidebar-sheet' } ], contextMenus: [ @@ -270,6 +274,9 @@ export default class CharacterSheet extends DHBaseActorSheet { */ async _prepareSidebarContext(context, _options) { context.isDeath = this.document.system.deathMoveViable; + context.sidebarFavoritesEmpty = this.document.system.sidebarFavorites.length === 0; + context.showfavorites = !context.sidebarFavoritesEmpty || this.document.system.usedUnarmed; + context.sidebarFavorites = this.document.system.sidebarFavorites.sort((a, b) => a.name.localeCompare(b.name)); } /** @@ -319,7 +326,9 @@ export default class CharacterSheet extends DHBaseActorSheet { icon: 'fa-solid fa-arrow-up', condition: target => { const doc = getDocFromElementSync(target); - return doc && doc.system.inVault; + const inCharacterSidebar = + this.document.type === 'character' && target.closest('.items-sidebar-list'); + return doc && doc.system.inVault && !inCharacterSidebar; }, callback: async target => { const doc = await getDocFromElement(target); @@ -333,7 +342,9 @@ export default class CharacterSheet extends DHBaseActorSheet { icon: 'fa-solid fa-bolt-lightning', condition: target => { const doc = getDocFromElementSync(target); - return doc && doc.system.inVault; + const inCharacterSidebar = + this.document.type === 'character' && target.closest('.items-sidebar-list'); + return doc && doc.system.inVault && !inCharacterSidebar; }, callback: async (target, event) => { const doc = await getDocFromElement(target); @@ -372,7 +383,9 @@ export default class CharacterSheet extends DHBaseActorSheet { icon: 'fa-solid fa-arrow-down', condition: target => { const doc = getDocFromElementSync(target); - return doc && !doc.system.inVault; + const inCharacterSidebar = + this.document.type === 'character' && target.closest('.items-sidebar-list'); + return doc && !doc.system.inVault && !inCharacterSidebar; }, callback: async target => (await getDocFromElement(target)).update({ 'system.inVault': true }) } @@ -751,8 +764,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} @@ -760,32 +771,14 @@ export default class CharacterSheet extends DHBaseActorSheet { static async #toggleEquipItem(_event, button) { const item = await getDocFromElement(button); if (!item) return; - if (item.system.equipped) { - await item.update({ 'system.equipped': false }); - return; - } - switch (item.type) { - case 'armor': - const currentArmor = this.document.system.armor; - if (currentArmor) { - await currentArmor.update({ 'system.equipped': false }); - } - - await item.update({ 'system.equipped': true }); - break; - case 'weapon': - if (this.document.effects.find(x => !x.disabled && x.type === 'beastform')) { - return ui.notifications.warn( - game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon') - ); - } - - await this.document.system.constructor.unequipBeforeEquip.bind(this.document.system)(item); - - await item.update({ 'system.equipped': true }); - break; - } + const changedData = await this.document.toggleEquipItem(item); + 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)) + ] + }); } /** @@ -845,12 +838,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)) + ] + }); } /** @@ -1044,6 +1038,11 @@ export default class CharacterSheet extends DHBaseActorSheet { } async _onDropItem(event, item) { + const sidebarDrop = event.target.closest('.character-sidebar-sheet'); + if (sidebarDrop) { + return this._onSidebarDrop(event, item); + } + const setupCriticalItemTypes = ['class', 'subclass', 'ancestry', 'community']; if (this.document.system.needsCharacterSetup && setupCriticalItemTypes.includes(item.type)) { const confirmed = await foundry.applications.api.DialogV2.confirm({ @@ -1094,4 +1093,18 @@ export default class CharacterSheet extends DHBaseActorSheet { itemData = itemData instanceof Array ? itemData : [itemData]; return this.document.createEmbeddedDocuments('Item', itemData); } + + async _onSidebarDrop(event, item) { + if (!item.testUserPermission(game.user, 'OWNER')) return; + + if (!(item instanceof game.system.api.documents.DHItem)) return; + if (!this.document.items.get(item.id)) return; + + const allowedItemTypes = ['domainCard', 'feature', 'weapon', 'armor', 'loot', 'consumable']; + if (!allowedItemTypes.includes(item.type)) return; + + if (this.document.system.sidebarFavorites.some(x => x.id === item.id)) return; + + this.document.setFavoriteItem(item, true); + } } diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index b18176ec..3423aed0 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -532,6 +532,40 @@ export default function DHApplicationMixin(Base) { callback: async target => (await getDocFromElement(target)).toChat(this.document.uuid) }); + options.push({ + name: 'Unfavorite', + icon: 'fa-regular fa-star', + condition: target => { + const doc = getDocFromElementSync(target); + const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id); + return this.document.type === 'character' && isFavorited; + }, + callback: async (target, _event) => { + const doc = await getDocFromElement(target); + this.document.update({ + 'system.sidebarFavorites': this.document.system.sidebarFavorites.filter(x => x.id !== doc.id) + }); + } + }); + + options.push({ + name: 'Favorite', + icon: 'fa-solid fa-star', + condition: target => { + const doc = getDocFromElementSync(target); + const isFavorited = this.document.system.sidebarFavorites.some(x => x.id === doc.id); + return ( + !(doc instanceof game.system.api.documents.DhActiveEffect) && + this.document.type === 'character' && + !isFavorited + ); + }, + callback: async (target, _event) => { + const doc = await getDocFromElement(target); + this.document.setFavoriteItem(doc, true); + } + }); + if (deletable) options.push({ name: 'CONTROLS.CommonDelete', diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index cde7d280..0d540552 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -6,6 +6,7 @@ import DhCreature from './creature.mjs'; import { attributeField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs'; import { ActionField } from '../fields/actionField.mjs'; import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs'; +import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs'; export default class DhCharacter extends DhCreature { /**@override */ @@ -295,7 +296,8 @@ export default class DhCharacter extends DhCreature { hint: 'DAGGERHEART.ACTORS.Character.roll.guaranteedCritical.hint' }) }) - }) + }), + sidebarFavorites: new ForeignDocumentUUIDArrayField({ type: 'Item' }) }; } @@ -564,28 +566,6 @@ export default class DhCharacter extends DhCreature { return diceTypes[attackDiceIndex]; } - static async unequipBeforeEquip(itemToEquip) { - const primary = this.primaryWeapon, - secondary = this.secondaryWeapon; - if (itemToEquip.system.secondary) { - if (primary && primary.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) { - await primary.update({ 'system.equipped': false }); - } - - if (secondary) { - await secondary.update({ 'system.equipped': false }); - } - } else { - if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) { - await secondary.update({ 'system.equipped': false }); - } - - if (primary) { - await primary.update({ 'system.equipped': false }); - } - } - } - prepareBaseData() { super.prepareBaseData(); this.evasion += this.class.value?.system?.evasion ?? 0; diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index eea2e212..62c281d9 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -1007,4 +1007,111 @@ 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')); + } + + const toVault = options.toVault ?? !card.system.inVault; + await card?.update({ 'system.inVault': toVault }, { render }); + return [{ item: card, add: !toVault }]; + } + + async unequipBeforeEquip(itemToEquip, options = { render: true }) { + const { render } = options; + + const primary = this.system.primaryWeapon, + secondary = this.system.secondaryWeapon; + let unequippedItems = []; + if (itemToEquip.system.secondary) { + if (primary && primary.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) { + unequippedItems.push(primary); + } + + if (secondary) { + unequippedItems.push(secondary); + } + } else { + if (secondary && itemToEquip.system.burden === CONFIG.DH.GENERAL.burden.twoHanded.value) { + unequippedItems.push(secondary); + } + + if (primary) { + unequippedItems.push(primary); + } + } + + for (const item of unequippedItems) await item?.update({ 'system.equipped': false }, { render }); + + return unequippedItems; + } + + async toggleEquipItem(item, options = { render: true }) { + const { render } = options; + const changedItems = []; + const updateAndAddChangedItem = async (item, equip) => { + changedItems.push({ item, add: equip }); + await item.update({ 'system.equipped': equip }, { render }); + }; + + if (item.system.equipped && [undefined, false].includes(options.equip)) { + await updateAndAddChangedItem(item, false); + return changedItems; + } + + switch (item.type) { + case 'armor': + const currentArmor = this.system.armor; + if (currentArmor) { + await updateAndAddChangedItem(currentArmor, false); + } + + await updateAndAddChangedItem(item, true); + break; + case 'weapon': + if (this.effects.find(x => !x.disabled && x.type === 'beastform')) { + return ui.notifications.warn( + game.i18n.localize('DAGGERHEART.UI.Notifications.beastformEquipWeapon') + ); + } + + const unequippedItems = await this.unequipBeforeEquip(item, { render: false }); + changedItems.push(...unequippedItems.map(x => ({ item: x, add: false }))); + await updateAndAddChangedItem(item, true); + break; + } + + 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 (['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, toVault: !setFavorited }); + for (const data of changedData) { + if (data.add) favoritesToAdd.push(data.item); + else favoritesToRemove.push(data.item); + } + } else if (setFavorited) favoritesToAdd.push(item); + else favoritesToRemove.push(item); + + this.update({ + 'system.sidebarFavorites': [ + ...this.system.sidebarFavorites.filter(x => favoritesToRemove.every(r => r.id !== x.id)), + ...favoritesToAdd + ] + }); + } } diff --git a/module/documents/item.mjs b/module/documents/item.mjs index 67f7d253..b658e0df 100644 --- a/module/documents/item.mjs +++ b/module/documents/item.mjs @@ -229,5 +229,11 @@ export default class DHItem extends foundry.documents.Item { async _preDelete() { this.deleteTriggers(); + + if (this.parent?.type === 'character') { + const filteredFavorites = this.parent.system.sidebarFavorites.filter(x => x.id !== this.id); + if (this.parent.system.sidebarFavorites.length !== filteredFavorites.length) + this.parent.update({ 'system.sidebarFavorites': filteredFavorites }); + } } } diff --git a/styles/less/sheets/actors/character/sidebar.less b/styles/less/sheets/actors/character/sidebar.less index 04baf2b9..0f710055 100644 --- a/styles/less/sheets/actors/character/sidebar.less +++ b/styles/less/sheets/actors/character/sidebar.less @@ -552,7 +552,6 @@ .shortcut-items-section { overflow-y: hidden; padding-top: 10px; - padding-bottom: 20px; mask-image: linear-gradient(0deg, transparent 0%, black 5%); scrollbar-gutter: stable; scrollbar-width: thin; @@ -561,6 +560,26 @@ overflow-y: auto; scrollbar-color: light-dark(@dark-blue, @golden) transparent; } + + .empty-favorites { + width: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + box-sizing: border-box; + border: 1px dashed light-dark(@dark-blue-50, @beige-50); + border-radius: 3px; + color: light-dark(@dark-blue-50, @beige-50); + text-align: center; + margin-bottom: 10px; + margin-left: 4px; + padding: 4px 0; + + span { + width: 250px; + } + } } .equipment-section, diff --git a/styles/less/ui/chat/deathmoves.less b/styles/less/ui/chat/deathmoves.less index 175b8753..4cfe1b13 100644 --- a/styles/less/ui/chat/deathmoves.less +++ b/styles/less/ui/chat/deathmoves.less @@ -143,10 +143,10 @@ } .risk-it-all-button { - width: -webkit-fill-available; - margin: 0 8px; - font-weight: 600; - height: 40px; + width: -webkit-fill-available; + margin: 0 8px; + font-weight: 600; + height: 40px; } } } diff --git a/templates/sheets/actors/character/sidebar.hbs b/templates/sheets/actors/character/sidebar.hbs index b2757b55..36244c35 100644 --- a/templates/sheets/actors/character/sidebar.hbs +++ b/templates/sheets/actors/character/sidebar.hbs @@ -99,63 +99,51 @@