mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 07:36:26 +01:00
deduplicate and simplify
This commit is contained in:
parent
598bf733f8
commit
b269e58585
4 changed files with 37 additions and 44 deletions
|
|
@ -656,31 +656,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
const target = event.target || event.currentTarget;
|
||||
const itemElement = target.closest('[data-item-id]');
|
||||
const item = this.getItem(event);
|
||||
|
||||
if (itemElement) {
|
||||
const itemId = itemElement.dataset.itemId;
|
||||
const itemType = itemElement.dataset.type;
|
||||
|
||||
let item;
|
||||
if (itemType === 'effect') {
|
||||
item = this.document.effects.get(itemId);
|
||||
} else {
|
||||
item = this.document.items.get(itemId);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
const dragData = {
|
||||
type: item.documentName,
|
||||
uuid: item.uuid
|
||||
};
|
||||
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
const dragData = {
|
||||
type: item.documentName,
|
||||
uuid: item.uuid
|
||||
};
|
||||
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
|
||||
|
||||
super._onDragStart(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import { copyAttachmentEffectsToActor, removeAttachmentEffectsFromActor } from '../../../helpers/attachmentHelper.mjs';
|
||||
import { copyAttachmentEffectsToActor, removeAttachmentFromItem } from '../../../helpers/attachmentHelper.mjs';
|
||||
|
||||
export default class ArmorSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
|
|
@ -129,16 +129,9 @@ export default class ArmorSheet extends DHBaseItemSheet {
|
|||
* @param {HTMLElement} target - The clicked element
|
||||
*/
|
||||
static async #removeAttachment(event, target) {
|
||||
const uuid = target.dataset.uuid;
|
||||
const currentAttached = this.document.system.attached;
|
||||
|
||||
await this.document.update({
|
||||
'system.attached': currentAttached.filter(attachedUuid => attachedUuid !== uuid)
|
||||
});
|
||||
|
||||
await removeAttachmentEffectsFromActor({
|
||||
await removeAttachmentFromItem({
|
||||
parentItem: this.document,
|
||||
attachedUuid: uuid,
|
||||
attachedUuid: target.dataset.uuid,
|
||||
parentType: 'armor'
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||
import { copyAttachmentEffectsToActor, removeAttachmentEffectsFromActor } from '../../../helpers/attachmentHelper.mjs';
|
||||
import { copyAttachmentEffectsToActor, removeAttachmentFromItem } from '../../../helpers/attachmentHelper.mjs';
|
||||
|
||||
export default class WeaponSheet extends DHBaseItemSheet {
|
||||
/**@inheritdoc */
|
||||
|
|
@ -130,16 +130,9 @@ export default class WeaponSheet extends DHBaseItemSheet {
|
|||
* @param {HTMLElement} target - The clicked element
|
||||
*/
|
||||
static async #removeAttachment(event, target) {
|
||||
const uuid = target.dataset.uuid;
|
||||
const currentAttached = this.document.system.attached;
|
||||
|
||||
await this.document.update({
|
||||
'system.attached': currentAttached.filter(attachedUuid => attachedUuid !== uuid)
|
||||
});
|
||||
|
||||
await removeAttachmentEffectsFromActor({
|
||||
await removeAttachmentFromItem({
|
||||
parentItem: this.document,
|
||||
attachedUuid: uuid,
|
||||
attachedUuid: target.dataset.uuid,
|
||||
parentType: 'weapon'
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,30 @@ export async function removeAttachmentEffectsFromActor({ parentItem, attachedUui
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an attachment from an item and clean up its effects
|
||||
* @param {Object} options - Configuration options
|
||||
* @param {Item} options.parentItem - The item (armor/weapon) that the item is attached to
|
||||
* @param {string} options.attachedUuid - UUID of the attached item being removed
|
||||
* @param {string} options.parentType - Type of parent item ("armor" or "weapon")
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function removeAttachmentFromItem({ parentItem, attachedUuid, parentType }) {
|
||||
const currentAttached = parentItem.system.attached;
|
||||
|
||||
// Remove the attachment from the parent item's attached array
|
||||
await parentItem.update({
|
||||
'system.attached': currentAttached.filter(uuid => uuid !== attachedUuid)
|
||||
});
|
||||
|
||||
// Remove any effects that came from this attachment
|
||||
await removeAttachmentEffectsFromActor({
|
||||
parentItem,
|
||||
attachedUuid,
|
||||
parentType
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle adding/removing attachment effects when a parent item is equipped/unequipped
|
||||
* @param {Object} options - Configuration options
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue