mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 12:11:07 +01:00
122 lines
4.3 KiB
JavaScript
122 lines
4.3 KiB
JavaScript
import DHBaseActorSheet from '../api/base-actor.mjs';
|
|
|
|
export default class Party extends DHBaseActorSheet {
|
|
/**@inheritdoc */
|
|
static DEFAULT_OPTIONS = {
|
|
classes: ['party'],
|
|
position: {
|
|
width: 500
|
|
},
|
|
window: {
|
|
resizable: true
|
|
},
|
|
actions: {},
|
|
dragDrop: [{ dragSelector: '.actors-section .inventory-item', dropSelector: null }]
|
|
};
|
|
|
|
/**@override */
|
|
static PARTS = {
|
|
header: { template: 'systems/daggerheart/templates/sheets/actors/party/header.hbs' },
|
|
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
|
|
partyMembers: { template: 'systems/daggerheart/templates/sheets/actors/party/party-members.hbs' },
|
|
notes: { template: 'systems/daggerheart/templates/sheets/actors/party/notes.hbs' }
|
|
};
|
|
|
|
/** @inheritdoc */
|
|
static TABS = {
|
|
primary: {
|
|
tabs: [{ id: 'partyMembers' }, { id: 'notes' }],
|
|
initial: 'partyMembers',
|
|
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
|
|
}
|
|
};
|
|
|
|
async _preparePartContext(partId, context, options) {
|
|
context = await super._preparePartContext(partId, context, options);
|
|
switch (partId) {
|
|
case 'header':
|
|
await this._prepareHeaderContext(context, options);
|
|
break;
|
|
case 'notes':
|
|
await this._prepareNotesContext(context, options);
|
|
break;
|
|
}
|
|
return context;
|
|
}
|
|
|
|
/**
|
|
* Prepare render context for the Header part.
|
|
* @param {ApplicationRenderContext} context
|
|
* @param {ApplicationRenderOptions} options
|
|
* @returns {Promise<void>}
|
|
* @protected
|
|
*/
|
|
async _prepareHeaderContext(context, _options) {
|
|
const { system } = this.document;
|
|
const { TextEditor } = foundry.applications.ux;
|
|
|
|
context.description = await TextEditor.implementation.enrichHTML(system.description, {
|
|
secrets: this.document.isOwner,
|
|
relativeTo: this.document
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Prepare render context for the Biography part.
|
|
* @param {ApplicationRenderContext} context
|
|
* @param {ApplicationRenderOptions} options
|
|
* @returns {Promise<void>}
|
|
* @protected
|
|
*/
|
|
async _prepareNotesContext(context, _options) {
|
|
const { system } = this.document;
|
|
const { TextEditor } = foundry.applications.ux;
|
|
|
|
const paths = {
|
|
notes: 'notes'
|
|
};
|
|
|
|
for (const [key, path] of Object.entries(paths)) {
|
|
const value = foundry.utils.getProperty(system, path);
|
|
context[key] = {
|
|
field: system.schema.getField(path),
|
|
value,
|
|
enriched: await TextEditor.implementation.enrichHTML(value, {
|
|
secrets: this.document.isOwner,
|
|
relativeTo: this.document
|
|
})
|
|
};
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onDragStart(event) {
|
|
const item = event.currentTarget.closest('.inventory-item');
|
|
|
|
if (item) {
|
|
const adversaryData = { type: 'Actor', uuid: item.dataset.itemUuid };
|
|
event.dataTransfer.setData('text/plain', JSON.stringify(adversaryData));
|
|
event.dataTransfer.setDragImage(item, 60, 0);
|
|
}
|
|
}
|
|
|
|
async _onDrop(event) {
|
|
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
|
if (data.fromInternal) return;
|
|
|
|
const item = await fromUuid(data.uuid);
|
|
if (item.type === 'adversary' && event.target.closest('.category-container')) {
|
|
const target = event.target.closest('.category-container');
|
|
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
|
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
|
|
await this.actor.update({
|
|
[path]: [...current, item.uuid]
|
|
});
|
|
this.render();
|
|
} else if (item.type === 'feature' && event.target.closest('.tab.features')) {
|
|
await this.actor.createEmbeddedDocuments('Item', [item]);
|
|
this.render();
|
|
}
|
|
}
|
|
}
|