67b0555b11
Il y en avait partout dans des dialogues, des options, le drag&drop d'acteur sur acteur, l'empilage d'objet...
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
import { DialogSplitItem } from "./dialog-split-item.js";
|
|
import { Misc } from "./misc.js";
|
|
|
|
export class RdDSheetUtility {
|
|
|
|
static getItem(event, actor) {
|
|
return actor.items.get(RdDSheetUtility.getItemId(event))
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
static prepareItemDropParameters(destItemId, actorId, dragData, objetVersConteneur) {
|
|
console.log("ID", dragData)
|
|
const item = fromUuidSync(dragData.uuid)
|
|
let itemId = item.id
|
|
//const itemId = dragData.id || dragData.data._id
|
|
return {
|
|
destId: destItemId,
|
|
targetActorId: actorId,
|
|
itemId: itemId,
|
|
sourceActorId: item.actor.id,
|
|
srcId: objetVersConteneur[itemId],
|
|
onEnleverConteneur: () => { delete objetVersConteneur[itemId]; },
|
|
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
|
|
}
|
|
}
|
|
|
|
static async splitItem(item, actor, onSplit = () => { }) {
|
|
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) {
|
|
if (split >= 1 && split < item.system.quantite) {
|
|
await item.diminuerQuantite(split);
|
|
const itemData = duplicate(item);
|
|
// todo: ajouter dans le même conteneur?
|
|
itemData.system.quantite = split;
|
|
await actor.createEmbeddedDocuments('Item', [itemData])
|
|
}
|
|
}
|
|
} |