partial sync

This commit is contained in:
sladecraven 2021-01-09 09:54:08 +01:00
parent 06618746f9
commit 9f8db50a1d
3 changed files with 30 additions and 7 deletions

View File

@ -141,8 +141,10 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onDrop(event) { async _onDrop(event) {
await RdDUtility.processItemDropEvent(this, event); let toSuper = await RdDUtility.processItemDropEvent(this, event);
super._onDrop(event); if ( toSuper) {
super._onDrop(event);
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -709,13 +709,14 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
buildSubConteneurObjetList( conteneurId, deleteList ) { buildSubConteneurObjetList( conteneurId, deleteList ) {
let conteneur = this.items.find( conteneur => conteneurId == conteneur._id); // recup conteneur 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 ) { for ( let subId of conteneur.data.data.contenu ) {
let subObj = this.items.find( subobjet => subId == subobjet._id); // recup conteneur let subObj = this.items.find( subobjet => subId == subobjet._id); // recup conteneur
if ( subObj.type == 'conteneur') { if ( subObj && subObj.type == 'conteneur') {
this.buildSubConteneurObjetList( subId, deleteList ); this.buildSubConteneurObjetList( subId, deleteList );
} }
deleteList.push( subId ); if ( subObj) // Robust...
deleteList.push( subId );
} }
} }
deleteList.push( conteneurId ); deleteList.push( conteneurId );
@ -777,6 +778,20 @@ export class RdDActor extends Actor {
await this.updateOwnedItem( conteneurFixedList ) ; 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( ) { detectSurEncombrement( ) {
let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value); 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 // Mise à jour valeur totale et états
this.encTotal = encTotal; this.encTotal = encTotal;
console.log("Enco total : ", this.encTotal); //console.log("Enco total : ", this.encTotal);
this.detectSurEncombrement(); this.detectSurEncombrement();
// Mise à jour éventuelle du malus armure // Mise à jour éventuelle du malus armure
if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) { if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) {

View File

@ -281,8 +281,8 @@ export class RdDUtility {
let dragData = JSON.parse(event.dataTransfer.getData("text/plain")); let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
console.log(dragData, actorSheet.actor._id); console.log(dragData, actorSheet.actor._id);
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop 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 !!! if ( dropID ) { // Dropped over an item !!!
let objetId = dragData.id || dragData.data._id;
if ( actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) { if ( actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) {
if ( actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID) ) { if ( actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID) ) {
await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]); 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(); actorSheet.actor.computeEncombrementTotalEtMalusArmure();
return true;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */