2022-12-03 18:29:29 +01:00
|
|
|
import { RdDItemSheet } from "./item-sheet.js";
|
|
|
|
import { RdDSheetUtility } from "./rdd-sheet-utility.js";
|
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
|
|
|
|
export class RdDConteneurItemSheet extends RdDItemSheet {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
RdDUtility.filterEquipementParType(formData, this.actor.itemTypes);
|
|
|
|
|
|
|
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
|
|
|
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",
|
|
|
|
data: item.system
|
|
|
|
};
|
|
|
|
|
|
|
|
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onDropItem(event, dragData) {
|
|
|
|
if (this.actor) {
|
|
|
|
const dropParams = RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur);
|
|
|
|
await this.actor.processDropItem(dropParams);
|
|
|
|
await this.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|