2021-12-05 01:48:26 +01:00
|
|
|
import { DialogSplitItem } from "./dialog-split-item.js";
|
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
|
|
|
export class RdDSheetUtility {
|
|
|
|
|
|
|
|
static getItem(event, actor) {
|
2022-06-12 08:17:59 +02:00
|
|
|
return actor.items.get(RdDSheetUtility.getItemId(event))
|
2021-12-05 01:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static getItemId(event) {
|
|
|
|
return RdDSheetUtility.getEventItemData(event, "item-id");
|
|
|
|
}
|
|
|
|
|
|
|
|
static getEventItemData(event, property) {
|
|
|
|
const node = RdDSheetUtility.getEventElement(event);
|
|
|
|
return node?.data(property);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getEventElement(event) {
|
|
|
|
return $(event.currentTarget)?.parents(".item");
|
|
|
|
}
|
|
|
|
|
2021-12-05 16:48:18 +01:00
|
|
|
static prepareItemDropParameters(destItemId, actorId, dragData, objetVersConteneur) {
|
2022-06-12 09:46:58 +02:00
|
|
|
console.log("ID", dragData)
|
|
|
|
const item = fromUuidSync(dragData.uuid)
|
|
|
|
let itemId = item.id
|
|
|
|
//const itemId = dragData.id || dragData.data._id
|
2021-12-05 01:48:26 +01:00
|
|
|
return {
|
|
|
|
destId: destItemId,
|
2021-12-05 16:48:18 +01:00
|
|
|
targetActorId: actorId,
|
|
|
|
itemId: itemId,
|
|
|
|
sourceActorId: dragData.actorId,
|
2021-12-05 01:48:26 +01:00
|
|
|
srcId: objetVersConteneur[itemId],
|
|
|
|
onEnleverConteneur: () => { delete objetVersConteneur[itemId]; },
|
2021-12-05 16:48:18 +01:00
|
|
|
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
|
2021-12-05 01:48:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 14:01:41 +01:00
|
|
|
static async splitItem(item, actor, onSplit = () => { }) {
|
2021-12-05 01:48:26 +01:00
|
|
|
const dialog = await DialogSplitItem.create(item, async (item, split) => {
|
|
|
|
await RdDSheetUtility._onSplitItem(item, split, actor);
|
|
|
|
onSplit();
|
|
|
|
});
|
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static async _onSplitItem(item, split, actor) {
|
2022-06-12 09:46:58 +02:00
|
|
|
if (split >= 1 && split < item.system.quantite) {
|
2021-12-05 01:48:26 +01:00
|
|
|
await item.diminuerQuantite(split);
|
2022-06-12 09:46:58 +02:00
|
|
|
const itemData = duplicate(item);
|
2021-12-05 01:48:26 +01:00
|
|
|
// todo: ajouter dans le même conteneur?
|
2022-06-12 09:46:58 +02:00
|
|
|
itemData.system.quantite = split;
|
2021-12-05 01:48:26 +01:00
|
|
|
await actor.createEmbeddedDocuments('Item', [itemData])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|