From 9f8db50a1d2f96481040bacd3b9ce9ad936f2a17 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sat, 9 Jan 2021 09:54:08 +0100 Subject: [PATCH] partial sync --- module/actor-sheet.js | 6 ++++-- module/actor.js | 23 +++++++++++++++++++---- module/rdd-utility.js | 8 +++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index b4a03b81..ea8519f2 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -141,8 +141,10 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async _onDrop(event) { - await RdDUtility.processItemDropEvent(this, event); - super._onDrop(event); + let toSuper = await RdDUtility.processItemDropEvent(this, event); + if ( toSuper) { + super._onDrop(event); + } } /* -------------------------------------------- */ diff --git a/module/actor.js b/module/actor.js index 5e050f90..80c1e369 100644 --- a/module/actor.js +++ b/module/actor.js @@ -709,13 +709,14 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ buildSubConteneurObjetList( conteneurId, deleteList ) { let conteneur = this.items.find( conteneur => conteneurId == conteneur._id); // recup conteneur - if ( conteneur ) { // Si présent + if ( conteneur && conteneur.type =='conteneur' ) { // Si présent for ( let subId of conteneur.data.data.contenu ) { let subObj = this.items.find( subobjet => subId == subobjet._id); // recup conteneur - if ( subObj.type == 'conteneur') { + if ( subObj && subObj.type == 'conteneur') { this.buildSubConteneurObjetList( subId, deleteList ); } - deleteList.push( subId ); + if ( subObj) // Robust... + deleteList.push( subId ); } } deleteList.push( conteneurId ); @@ -777,6 +778,20 @@ export class RdDActor extends Actor { await this.updateOwnedItem( conteneurFixedList ) ; } + /* -------------------------------------------- */ + async moveItemsBetweenActors( itemId, sourceActorId ) { + let itemsList = [] + let sourceActor = game.actors.get( sourceActorId ); + sourceActor.buildSubConteneurObjetList( itemId, itemsList ); // Get itemId list + for (let srcItemId of itemsList) { + let copyItem = sourceActor.data.items.find( item => item._id == srcItemId ); + await this.createOwnedItem( duplicate(copyItem) ); + } + for( let srcItemId of itemsList) { + await sourceActor.deleteOwnedItem( srcItemId ); + } + } + /* -------------------------------------------- */ detectSurEncombrement( ) { let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value); @@ -806,7 +821,7 @@ export class RdDActor extends Actor { } // Mise à jour valeur totale et états this.encTotal = encTotal; - console.log("Enco total : ", this.encTotal); + //console.log("Enco total : ", this.encTotal); this.detectSurEncombrement(); // Mise à jour éventuelle du malus armure if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 76236912..5706bef7 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -281,8 +281,8 @@ export class RdDUtility { let dragData = JSON.parse(event.dataTransfer.getData("text/plain")); console.log(dragData, actorSheet.actor._id); let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop + let objetId = dragData.id || dragData.data._id; if ( dropID ) { // Dropped over an item !!! - let objetId = dragData.id || dragData.data._id; if ( actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) { if ( actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID) ) { await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]); @@ -290,7 +290,13 @@ export class RdDUtility { } } } + if (dragData.actorId && dragData.actorId != actorSheet.actor._id ) { // Un acteur est à l'origine de l'item -> deplacement + console.log("Moving objects"); + actorSheet.actor.moveItemsBetweenActors( objetId, dragData.actorId); + return false; + } actorSheet.actor.computeEncombrementTotalEtMalusArmure(); + return true; } /* -------------------------------------------- */