Gestion des signes draconiques #455
@ -161,7 +161,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
let toSuper = await RdDUtility.processItemDropEvent(this, event);
|
||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
||||
if (toSuper) {
|
||||
super._onDrop(event);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
let toSuper = await RdDUtility.processItemDropEvent(this, event);
|
||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
||||
if ( toSuper) {
|
||||
super._onDrop(event);
|
||||
}
|
||||
|
@ -828,11 +828,12 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
validateConteneur(itemId, conteneurId) {
|
||||
const dest = this.getObjet(conteneurId);
|
||||
if (dest?.type != 'conteneur') {
|
||||
ui.notifications.warn(`Impossible de déplacer un objet (${item.name}) vers un ${dest.type} qui n'est pas un conteneur (${dest.name}) !`);
|
||||
const item = this.getObjet(itemId);
|
||||
const destData = Misc.data(dest);
|
||||
if (destData?.type != 'conteneur') {
|
||||
ui.notifications.warn(`Impossible de déplacer un objet (${item.name}) vers un ${destData.type} qui n'est pas un conteneur (${dest.name}) !`);
|
||||
return false;
|
||||
}
|
||||
const item = this.getObjet(itemId);
|
||||
if (this._isConteneurContenu(item, conteneurId)) {
|
||||
ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${dest.name} !`);
|
||||
return false; // Loop detected !
|
||||
@ -841,7 +842,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
_isConteneurContenu(item, conteneurId) {
|
||||
if (item?.type == 'conteneur') { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant
|
||||
if (Misc.data(item)?.type == 'conteneur') { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant
|
||||
for (let id of Misc.templateData(item).contenu) {
|
||||
let subObjet = this.getObjet(id);
|
||||
if (subObjet?.id == conteneurId) {
|
||||
@ -972,6 +973,42 @@ export class RdDActor extends Actor {
|
||||
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processItemDropEvent(event, objetVersConteneur) {
|
||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
console.log(dragData, this.id);
|
||||
let objetId = dragData.id || dragData.data._id;
|
||||
console.log("DRAG", dragData);
|
||||
if (dragData.type == 'Item') {
|
||||
if (dragData.actorId) {
|
||||
if (dragData.actorId != this.id) {
|
||||
console.log("Moving objects", dragData);
|
||||
this.moveItemsBetweenActors(objetId, dragData.actorId);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// rangement
|
||||
const destId = $(event.target).parents(".item").attr("data-item-id");
|
||||
const srcId = objetVersConteneur[objetId];
|
||||
|
||||
if (srcId != destId && objetId != destId && this.isConteneurSuffisant(objetId, destId)) {
|
||||
if (srcId) {
|
||||
await this.enleverDeConteneur(objetId, srcId);
|
||||
}
|
||||
if (destId) { // Dropped over an item !!!
|
||||
await this.ajouterAConteneur(objetId, destId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.computeEncombrementTotalEtMalusArmure();
|
||||
}
|
||||
if (dragData.type == "Actor") {
|
||||
this.addSubacteur(objetId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async moveItemsBetweenActors(itemId, sourceActorId) {
|
||||
let itemsList = []
|
||||
|
@ -281,41 +281,6 @@ export class RdDUtility {
|
||||
formData.competences = (formData.itemsByType.competence ?? []).concat(formData.itemsByType.competencecreature ?? []);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async processItemDropEvent(actorSheet, event) {
|
||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
console.log(dragData, actorSheet.actor.id);
|
||||
let objetId = dragData.id || dragData.data._id;
|
||||
console.log("DRAG", dragData);
|
||||
if (dragData.type == 'Item') {
|
||||
if (dragData.actorId) {
|
||||
if (dragData.actorId != actorSheet.actor.id) {
|
||||
console.log("Moving objects", dragData);
|
||||
actorSheet.actor.moveItemsBetweenActors(objetId, dragData.actorId);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// rangement
|
||||
const destId = $(event.target).parents(".item").attr("data-item-id");
|
||||
const srcId = actorSheet.objetVersConteneur[objetId];
|
||||
|
||||
if (srcId != destId && objetId != destId && actorSheet.actor.isConteneurSuffisant(objetId, destId)) {
|
||||
if (srcId) {
|
||||
await actorSheet.actor.enleverDeConteneur(objetId, srcId);
|
||||
}
|
||||
if (destId) { // Dropped over an item !!!
|
||||
await actorSheet.actor.ajouterAConteneur(objetId, destId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
|
||||
} else if (dragData.type == "Actor") {
|
||||
actorSheet.actor.addSubacteur(objetId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildArbreDeConteneur(actorSheet, formData) {
|
||||
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
||||
|
Loading…
Reference in New Issue
Block a user