2023-01-18 01:37:22 +01:00
|
|
|
import { RdDBaseActorSheet } from "../actor/base-actor-sheet.js";
|
|
|
|
import { RdDSheetUtility } from "../rdd-sheet-utility.js";
|
|
|
|
import { RdDUtility } from "../rdd-utility.js";
|
|
|
|
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
2022-12-03 18:29:29 +01:00
|
|
|
|
2023-01-18 01:37:22 +01:00
|
|
|
export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
2022-12-03 18:29:29 +01:00
|
|
|
|
|
|
|
static get ITEM_TYPE() { return "conteneur" };
|
|
|
|
|
|
|
|
async getData() {
|
|
|
|
const formData = await super.getData();
|
|
|
|
if (this.actor) {
|
|
|
|
this.prepareConteneurData(formData);
|
|
|
|
}
|
2022-12-05 16:23:12 +01:00
|
|
|
return formData;
|
2022-12-03 18:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2022-12-03 18:29:29 +01:00
|
|
|
if (!this.options.editable) return;
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.conteneur-name a').click(async event => {
|
2022-12-03 18:29:29 +01:00
|
|
|
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
|
|
|
|
this.render(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareConteneurData(formData) {
|
2023-01-13 01:51:26 +01:00
|
|
|
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
2023-06-04 01:58:02 +02:00
|
|
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.inventaires);
|
2022-12-03 18:29:29 +01:00
|
|
|
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onDragStart(event) {
|
|
|
|
console.log("_onDragStart", event);
|
|
|
|
if (event.target.classList.contains("entity-link")) return;
|
|
|
|
|
|
|
|
const itemId = event.srcElement?.attributes["data-item-id"].value;
|
|
|
|
const item = this.actor.items.get(itemId);
|
|
|
|
// Create drag data
|
|
|
|
const dragData = {
|
|
|
|
actorId: this.actor.id,
|
|
|
|
type: "Item",
|
2023-01-28 15:43:31 +01:00
|
|
|
data: item.system,
|
|
|
|
uuid: item.uuid
|
2022-12-03 18:29:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onDropItem(event, dragData) {
|
|
|
|
if (this.actor) {
|
2023-01-28 15:43:31 +01:00
|
|
|
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') ?? this.item.id
|
|
|
|
const dropParams = await RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur);
|
2022-12-03 18:29:29 +01:00
|
|
|
await this.actor.processDropItem(dropParams);
|
|
|
|
await this.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|