Add ability to sort inventories in player and party sheets

This commit is contained in:
Carlos Fernandez 2025-12-02 03:40:28 -05:00
parent 8f917c3640
commit 71ee9a0065
6 changed files with 86 additions and 143 deletions

View file

@ -214,34 +214,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
context.resources.stress.emptyPips =
context.resources.stress.max < maxResource ? maxResource - context.resources.stress.max : 0;
context.inventory = { currencies: {} };
const { title, ...currencies } = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Homebrew
).currency;
for (let key in currencies) {
context.inventory.currencies[key] = {
...currencies[key],
field: context.systemFields.gold.fields[key],
value: context.source.system.gold[key]
};
}
// context.inventory = {
// currency: {
// title: game.i18n.localize('DAGGERHEART.CONFIG.Gold.title'),
// coins: game.i18n.localize('DAGGERHEART.CONFIG.Gold.coins'),
// handfuls: game.i18n.localize('DAGGERHEART.CONFIG.Gold.handfuls'),
// bags: game.i18n.localize('DAGGERHEART.CONFIG.Gold.bags'),
// chests: game.i18n.localize('DAGGERHEART.CONFIG.Gold.chests')
// }
// };
context.beastformActive = this.document.effects.find(x => x.type === 'beastform');
// if (context.inventory.length === 0) {
// context.inventory = Array(1).fill(Array(5).fill([]));
// }
return context;
}
@ -918,20 +892,11 @@ export default class CharacterSheet extends DHBaseActorSheet {
super._onDragStart(event);
}
async _onDrop(event) {
// Prevent event bubbling to avoid duplicate handling
event.preventDefault();
event.stopPropagation();
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
async _onDropItem(event, item) {
if (this.document.uuid === item.parent?.uuid) {
return this._onSortItem(event, item);
}
const { cancel } = await super._onDrop(event);
if (cancel) return;
this._onDropItem(event, data);
}
async _onDropItem(event, data) {
const item = await Item.implementation.fromDropData(data);
const itemData = item.toObject();
if (item.type === 'domainCard' && !this.document.system.loadoutSlot.available) {
@ -963,10 +928,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
}
}
if (this.document.uuid === item.parent?.uuid) return this._onSortItem(event, itemData);
const createdItem = await this._onDropItemCreate(itemData);
return createdItem;
return await this._onDropItemCreate(itemData);
}
async _onDropItemCreate(itemData, event) {

View file

@ -93,25 +93,6 @@ export default class Party extends DHBaseActorSheet {
/* Prepare Context */
/* -------------------------------------------- */
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.inventory = { currencies: {} };
const { title, ...currencies } = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Homebrew
).currency;
for (let key in currencies) {
context.inventory.currencies[key] = {
...currencies[key],
field: context.systemFields.gold.fields[key],
value: context.source.system.gold[key]
};
}
return context;
}
async _preparePartContext(partId, context, options) {
context = await super._preparePartContext(partId, context, options);
switch (partId) {
@ -451,17 +432,8 @@ export default class Party extends DHBaseActorSheet {
super._onDragStart(event);
}
async _onDrop(event) {
// Prevent event bubbling to avoid duplicate handling
event.preventDefault();
event.stopPropagation();
async _onDropActor(event, document) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
const { cancel } = await super._onDrop(event);
if (cancel) return;
const document = await foundry.utils.fromUuid(data.uuid);
if (document instanceof DhpActor && Party.ALLOWED_ACTOR_TYPES.includes(document.type)) {
const currentMembers = this.document.system.partyMembers.map(x => x.uuid);
if (currentMembers.includes(data.uuid)) {
@ -469,11 +441,11 @@ export default class Party extends DHBaseActorSheet {
}
await this.document.update({ 'system.partyMembers': [...currentMembers, document.uuid] });
} else if (document instanceof DHItem) {
this.document.createEmbeddedDocuments('Item', [document.toObject()]);
} else {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.onlyCharactersInPartySheet'));
}
return null;
}
static async #deletePartyMember(event, target) {