mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
Potential Adversaries can be dragged out of the sheet onto canvas
This commit is contained in:
parent
4a53adf857
commit
1506f46efb
11 changed files with 54 additions and 66 deletions
|
|
@ -11,7 +11,6 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
|
|||
},
|
||||
actions: {
|
||||
addAdversary: this.addAdversary,
|
||||
addFeature: this.addFeature,
|
||||
deleteProperty: this.deleteProperty,
|
||||
viewAdversary: this.viewAdversary,
|
||||
openSettings: this.openSettings
|
||||
|
|
@ -21,7 +20,7 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
|
|||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '.category-container' }]
|
||||
dragDrop: [{ dragSelector: '.action-section .inventory-item', dropSelector: null }]
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
|
|
@ -91,32 +90,24 @@ export default class DhpEnvironment extends DaggerheartSheet(ActorSheetV2) {
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async addFeature() {
|
||||
ui.notifications.error('Not Implemented yet. Awaiting datamodel rework');
|
||||
}
|
||||
|
||||
static async deleteProperty(_, target) {
|
||||
await this.document.update({ [`${target.dataset.path}.-=${target.id}`]: null });
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async viewAdversary(_, button) {
|
||||
const adversary = foundry.utils.getProperty(
|
||||
this.document.system.potentialAdversaries,
|
||||
`${button.dataset.potentialAdversary}.adversaries.${button.dataset.adversary}`
|
||||
);
|
||||
const adversary = await foundry.utils.fromUuid(button.dataset.adversary);
|
||||
adversary.sheet.render(true);
|
||||
}
|
||||
|
||||
async _onDrop(event) {
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'adversary') {
|
||||
const target = event.target.closest('.category-container');
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries.${item.id}`;
|
||||
await this.document.update({
|
||||
[path]: item.uuid
|
||||
});
|
||||
async _onDragStart(event) {
|
||||
const item = event.currentTarget.closest('.inventory-item');
|
||||
|
||||
if (item) {
|
||||
const adversary = game.actors.find(x => x.type === 'adversary' && x.id === item.dataset.itemId);
|
||||
const adversaryData = { type: 'Actor', uuid: adversary.uuid };
|
||||
event.dataTransfer.setData('text/plain', JSON.stringify(adversaryData));
|
||||
event.dataTransfer.setDragImage(item, 60, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,17 +180,15 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
}
|
||||
|
||||
static async #viewAdversary(_, button) {
|
||||
const adversary = foundry.utils.getProperty(
|
||||
this.actor.system.potentialAdversaries,
|
||||
`${button.dataset.potentialAdversary}.adversaries.${button.dataset.adversary}`
|
||||
);
|
||||
adversary.uuid.sheet.render(true);
|
||||
const adversary = await foundry.utils.fromUuid(button.dataset.adversary);
|
||||
adversary.sheet.render(true);
|
||||
}
|
||||
|
||||
static async #deleteAdversary(event, target) {
|
||||
const adversaryKey = target.dataset.adversary;
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||
await this.actor.update({ [`${path}.-=${adversaryKey}`]: null });
|
||||
const newAdversaries = foundry.utils.getProperty(this.actor, path).filter(x => x.uuid !== adversaryKey);
|
||||
await this.actor.update({ [path]: newAdversaries });
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
@ -199,11 +197,10 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
|||
const item = await fromUuid(data.uuid);
|
||||
if (item.type === 'adversary') {
|
||||
const target = event.target.closest('.category-container');
|
||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries.${item.id}`;
|
||||
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]: {
|
||||
uuid: item.uuid
|
||||
}
|
||||
[path]: [...current, item.uuid]
|
||||
});
|
||||
this.render();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ export default function DhpApplicationMixin(Base) {
|
|||
// drop: this._canDragDrop.bind(this)
|
||||
// };
|
||||
d.callbacks = {
|
||||
// dragstart: this._onDragStart.bind(this),
|
||||
dragstart: this._onDragStart.bind(this),
|
||||
// dragover: this._onDragOver.bind(this),
|
||||
drop: this._onDrop.bind(this)
|
||||
};
|
||||
|
|
@ -68,6 +68,7 @@ export default function DhpApplicationMixin(Base) {
|
|||
});
|
||||
}
|
||||
|
||||
async _onDragStart(event) {}
|
||||
_onDrop(event) {}
|
||||
|
||||
_getTabs(tabs) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { environmentTypes } from '../../config/actorConfig.mjs';
|
|||
import BaseDataActor from './base.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DhEnvironment extends BaseDataActor {
|
||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Sheets.Environment'];
|
||||
|
|
@ -28,11 +29,7 @@ export default class DhEnvironment extends BaseDataActor {
|
|||
potentialAdversaries: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
label: new fields.StringField(),
|
||||
adversaries: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
uuid: new ForeignDocumentUUIDField({ type: 'Actor' })
|
||||
})
|
||||
)
|
||||
adversaries: new ForeignDocumentUUIDArrayField({ type: 'Actor' })
|
||||
})
|
||||
),
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue