mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Iss4 - create a way to attach attach items to armor and weapons (#310)
* add basic drag drop window * add better field * make effects copy onto actor on attachment * make items from inventory draggable * working drop from inventory * remove duplication issue * add attachment only flag and logic * add weapons to attachables * remove debug logs * try to make it drier * remove unecessary try catch * remove extra configs * remove superfluous comments * remove spurious defenses * make drier * remove unecessary code * deduplicate and simplify * its a desert * standardize to be more similar to class item code * fix bug of duplicate effects being created * fix localization string * fix bug of item equiping and un equiping * remove this since were not going to be using attachmentonly * update attachment tab with comments * remove attachment only logic in favor of just transfer * change flags * change armor and weapon to be attachableItem * change armor and weapon to be attachableItem * change weapon to use mixin * add mixin to armor * move everything to mixin sheet * refactor code for review comments * cleanup and somehow git is ignoring some changes * see if this picks up the changes now * Import/Export updates --------- Co-authored-by: psitacus <walther.johnson@ucalgary.ca> Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
812a5e8dd7
commit
687500f191
18 changed files with 357 additions and 18 deletions
|
|
@ -1,5 +1,6 @@
|
|||
export { default as DHApplicationMixin } from './application-mixin.mjs';
|
||||
export { default as DHBaseItemSheet } from './base-item.mjs';
|
||||
export { default as DHHeritageSheet } from './heritage-sheet.mjs';
|
||||
export { default as DHItemAttachmentSheet } from './item-attachment-sheet.mjs';
|
||||
export { default as DHBaseActorSheet } from './base-actor.mjs';
|
||||
export { default as DHBaseActorSettings } from './actor-setting.mjs';
|
||||
|
|
|
|||
90
module/applications/sheets/api/item-attachment-sheet.mjs
Normal file
90
module/applications/sheets/api/item-attachment-sheet.mjs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
export default function ItemAttachmentSheet(Base) {
|
||||
return class extends Base {
|
||||
static DEFAULT_OPTIONS = {
|
||||
...super.DEFAULT_OPTIONS,
|
||||
dragDrop: [
|
||||
...(super.DEFAULT_OPTIONS.dragDrop || []),
|
||||
{ dragSelector: null, dropSelector: '.attachments-section' }
|
||||
],
|
||||
actions: {
|
||||
...super.DEFAULT_OPTIONS.actions,
|
||||
removeAttachment: this.#removeAttachment
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
...super.PARTS,
|
||||
attachments: {
|
||||
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-attachments.hbs',
|
||||
scrollable: ['.attachments']
|
||||
}
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
...super.TABS,
|
||||
primary: {
|
||||
...super.TABS?.primary,
|
||||
tabs: [
|
||||
...(super.TABS?.primary?.tabs || []),
|
||||
{ id: 'attachments' }
|
||||
],
|
||||
initial: super.TABS?.primary?.initial || 'description',
|
||||
labelPrefix: super.TABS?.primary?.labelPrefix || 'DAGGERHEART.GENERAL.Tabs'
|
||||
}
|
||||
};
|
||||
|
||||
async _preparePartContext(partId, context) {
|
||||
await super._preparePartContext(partId, context);
|
||||
|
||||
if (partId === 'attachments') {
|
||||
context.attachedItems = await prepareAttachmentContext(this.document);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
|
||||
const attachmentsSection = event.target.closest('.attachments-section');
|
||||
if (!attachmentsSection) return super._onDrop(event);
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const item = await Item.implementation.fromDropData(data);
|
||||
if (!item) return;
|
||||
|
||||
// Call the data model's public method
|
||||
await this.document.system.addAttachment(item);
|
||||
}
|
||||
|
||||
|
||||
static async #removeAttachment(event, target) {
|
||||
// Call the data model's public method
|
||||
await this.document.system.removeAttachment(target.dataset.uuid);
|
||||
}
|
||||
|
||||
async _preparePartContext(partId, context) {
|
||||
await super._preparePartContext(partId, context);
|
||||
|
||||
if (partId === 'attachments') {
|
||||
// Keep this simple UI preparation in the mixin
|
||||
const attachedUUIDs = this.document.system.attached;
|
||||
context.attachedItems = await Promise.all(
|
||||
attachedUUIDs.map(async uuid => {
|
||||
const item = await fromUuid(uuid);
|
||||
return {
|
||||
uuid: uuid,
|
||||
name: item?.name || 'Unknown Item',
|
||||
img: item?.img || 'icons/svg/item-bag.svg'
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue