#123 : Verification equipement
This commit is contained in:
@ -137,9 +137,25 @@ export class RdDActorSheet extends ActorSheet {
|
||||
return data;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processItemDropEvent( event) {
|
||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
|
||||
if ( dropID ) { // Dropped over an item !!!
|
||||
let objetId = dragData.id || dragData.data._id;
|
||||
if ( this.objetVersConteneur[objetId] != dropID && objetId != dropID) {
|
||||
if ( this.actor.validateConteneur(objetId, dropID) && this.actor.testConteneurCapacite(objetId, dropID) ) {
|
||||
await this.actor.enleverDeConteneur(objetId, this.objetVersConteneur[objetId]);
|
||||
await this.actor.ajouterAConteneur(objetId, dropID);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.actor.computeEncombrementTotalEtMalusArmure();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
await RdDUtility.processItemDropEvent(this, event);
|
||||
await this.processItemDropEvent(event);
|
||||
super._onDrop(event);
|
||||
}
|
||||
|
||||
|
@ -657,6 +657,25 @@ export class RdDActor extends Actor {
|
||||
await this.update( {"data.attributs": attributs } );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
validateConteneur( itemId, conteneurId ) {
|
||||
let conteneurDest = this.items.find( conteneur => conteneurId == conteneur._id); // recup conteneur
|
||||
let conteneurSrc = this.items.find( conteneur => itemId == conteneur._id && conteneur.type == 'conteneur');
|
||||
if ( conteneurSrc ) { // 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 conteneurSrc.data.data.contenu) {
|
||||
let subObjet = this.items.find( subobj => id == subobj._id);
|
||||
if ( subObjet && subObjet._id == conteneurDest._id ) {
|
||||
ui.notifications.warn("Impossible de déplacer un conteneur parent dans son fils !");
|
||||
return false; // Loop detected !
|
||||
}
|
||||
if ( subObjet && subObjet.type == 'conteneur') {
|
||||
return this.validateConteneur( subObjet._id, conteneurId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Teste si le conteneur de destination a suffisament de capacité
|
||||
* pour recevoir le nouvel objet
|
||||
@ -673,8 +692,10 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
// Et gérer le nouvel objet
|
||||
let nouvelObjet = this.items.find( objet => (itemId == objet._id) );
|
||||
if ( currentEnc + nouvelObjet.data.data.encombrement > Number(conteneur.data.data.capacite) )
|
||||
if ( currentEnc + nouvelObjet.data.data.encombrement > Number(conteneur.data.data.capacite) ) {
|
||||
ui.notifications.warn("Capacité d'encombrement insuffisante dans le conteneur !");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -276,24 +276,6 @@ export class RdDUtility {
|
||||
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async processItemDropEvent( actorSheet, event) {
|
||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
|
||||
if ( dropID ) { // Dropped over an item !!!
|
||||
let objetId = dragData.id || dragData.data._id;
|
||||
if ( actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) {
|
||||
if ( actorSheet.actor.testConteneurCapacite(objetId, dropID) ) {
|
||||
await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]);
|
||||
await actorSheet.actor.ajouterAConteneur(objetId, dropID);
|
||||
} else {
|
||||
ui.notifications.info("Capacité d'encombrement insuffisante dans le conteneur !");
|
||||
}
|
||||
}
|
||||
}
|
||||
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildArbreDeConteneur( actorSheet, data ) {
|
||||
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
||||
|
Reference in New Issue
Block a user