fixes groupsheet dragging and dropping
parent
6f1bad0b67
commit
f74bb38f3a
|
|
@ -901,33 +901,33 @@ export class CharacterSheet extends foundry.appv1.sheets.ActorSheet {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
/*
|
||||||
html.on('dragstart', '.equipment', (evt) => {
|
html.on('dragstart', '.equipment', (evt) => {
|
||||||
evt.originalEvent.dataTransfer.setData("application/json", JSON.stringify({
|
evt.originalEvent.dataTransfer.setData("application/json", JSON.stringify({
|
||||||
documentId: evt.currentTarget.dataset.id
|
documentId: evt.currentTarget.dataset.id
|
||||||
}));
|
}));
|
||||||
})
|
})*/
|
||||||
|
/*
|
||||||
html.on('drop', '.equipped', async (evt) => {
|
html.on('drop', '.equipped', async (evt) => {
|
||||||
const {actor, target, setId} = evt.currentTarget.dataset;
|
const {actor, target, setId} = evt.currentTarget.dataset;
|
||||||
try {
|
try {
|
||||||
const {documentId} = JSON.parse(evt.originalEvent.dataTransfer.getData("application/json"));
|
const {documentId} = JSON.parse(evt.originalEvent.dataTransfer.getData("application/json"));
|
||||||
|
|
||||||
|
|
||||||
if (actor === this.object._id && documentId) { // managing equipped items
|
if (actor === this.object._id && documentId) { // managing equipped items
|
||||||
//const slot = this.#isWorn(documentId, setId)
|
//const slot = this.#isWorn(documentId, setId)
|
||||||
//const updateObject = await this.#getEquipmentset(Number(setId))
|
//const updateObject = await this.#getEquipmentset(Number(setId))
|
||||||
const updateObject = this.#mapAllSets()
|
const updateObject = this.#mapAllSets()
|
||||||
updateObject[`system.heldenausruestung.${setId}.${target}`] = documentId;
|
updateObject[`system.heldenausruestung.${setId}.${target}`] = documentId;
|
||||||
console.log(updateObject);
|
console.log(updateObject);
|
||||||
|
|
||||||
await this.object.update(updateObject);
|
await this.object.update(updateObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
})
|
})*/
|
||||||
|
|
||||||
new foundry.applications.ux.ContextMenu(html[0], '.talent.rollable', [
|
new foundry.applications.ux.ContextMenu(html[0], '.talent.rollable', [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -219,11 +219,11 @@ export class GroupSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.equipments = [];
|
context.inventoryItems = [];
|
||||||
const actorData = context.document;
|
const actorData = context.document;
|
||||||
Object.values(actorData.items).forEach((item, index) => {
|
actorData.items.forEach((item, index) => {
|
||||||
if (item.type === "Equipment") {
|
if (item.type === "Equipment") {
|
||||||
context.equipments.push({
|
context.inventoryItems.push({
|
||||||
index: index,
|
index: index,
|
||||||
id: item._id,
|
id: item._id,
|
||||||
quantity: item.system.quantity,
|
quantity: item.system.quantity,
|
||||||
|
|
@ -255,6 +255,7 @@ export class GroupSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
|
|
||||||
// Drag-drop
|
// Drag-drop
|
||||||
new foundry.applications.ux.DragDrop.implementation({
|
new foundry.applications.ux.DragDrop.implementation({
|
||||||
|
dragSelector: ".inventory-table .equipment",
|
||||||
dropSelector: ".inventory-table",
|
dropSelector: ".inventory-table",
|
||||||
permissions: {
|
permissions: {
|
||||||
dragstart: this._canDragStart.bind(this),
|
dragstart: this._canDragStart.bind(this),
|
||||||
|
|
@ -280,13 +281,53 @@ export class GroupSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO needs to be fixed once Character Sheet is migrated to ActorSheetV2
|
/**
|
||||||
_onDrop(event) {
|
* An event that occurs when a drag workflow begins for a draggable item on the sheet.
|
||||||
const data = event.dataTransfer.getData("application/json")
|
* @param {DragEvent} event The initiating drag start event
|
||||||
if (!data) return false
|
* @returns {Promise<void>}
|
||||||
console.log(data)
|
* @protected
|
||||||
|
*/
|
||||||
|
async _onDragStart(event) {
|
||||||
|
const target = event.currentTarget;
|
||||||
|
if ("link" in event.target.dataset) return;
|
||||||
|
let dragData;
|
||||||
|
|
||||||
|
// Owned Items
|
||||||
|
if (target.dataset.itemId) {
|
||||||
|
const item = this.actor.items.get(target.dataset.itemId);
|
||||||
|
dragData = item.toDragData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active Effect
|
||||||
|
if (target.dataset.effectId) {
|
||||||
|
const effect = this.actor.effects.get(target.dataset.effectId);
|
||||||
|
dragData = effect.toDragData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set data transfer
|
||||||
|
if (!dragData) return;
|
||||||
|
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO needs to be fixed once Character Sheet is migrated to ActorSheetV2
|
||||||
|
async _onDrop(event) {
|
||||||
|
const data = TextEditor.implementation.getDragEventData(event);
|
||||||
|
const actor = this.actor;
|
||||||
|
const allowed = Hooks.call("dropActorSheetData", actor, this, data);
|
||||||
|
if (allowed === false) return;
|
||||||
|
|
||||||
|
// Dropped Documents
|
||||||
|
const documentClass = foundry.utils.getDocumentClass(data.type);
|
||||||
|
if (documentClass) {
|
||||||
|
const document = await documentClass.fromDropData(data);
|
||||||
|
await this._onDropDocument(event, document);
|
||||||
|
|
||||||
|
// No duplication by moving items from one actor to another
|
||||||
|
if (document.parent) {
|
||||||
|
document.parent.items.get(document._id).delete()
|
||||||
|
}
|
||||||
|
await this._onDropDocument(event, document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
{{#each inventoryItems}}
|
{{#each inventoryItems}}
|
||||||
<tr class="equipment" data-id="{{this.id}}" draggable="true">
|
<tr class="equipment" data-item-id="{{this.id}}" draggable="true">
|
||||||
<td class="icon"><img alt="" src="{{this.icon}}" width="16" height="16"></td>
|
<td class="icon"><img alt="" src="{{this.icon}}" width="16" height="16"></td>
|
||||||
<td class="name">{{this.name}}</td>
|
<td class="name">{{this.name}}</td>
|
||||||
<td class="quantity">{{this.quantity}}</td>
|
<td class="quantity">{{this.quantity}}</td>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue