mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
Merge 2123ae1965 into 17aa0680d2
This commit is contained in:
commit
374ef6040f
12 changed files with 335 additions and 181 deletions
|
|
@ -55,6 +55,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: [
|
||||
|
|
@ -260,6 +264,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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,7 +316,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);
|
||||
|
|
@ -323,7 +332,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);
|
||||
|
|
@ -362,7 +373,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 })
|
||||
}
|
||||
|
|
@ -741,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}
|
||||
|
|
@ -750,32 +761,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))
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -835,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))
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -962,6 +956,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({
|
||||
|
|
@ -1012,4 +1011,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue