#123 : Verification equipement
This commit is contained in:
parent
c4337e76a6
commit
7cb45afa13
@ -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)
|
||||
|
@ -200,3 +200,4 @@
|
||||
{"_id":"zQWlnUsd8bPySujd","name":"Aiguille à coudre","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"objet","data":{"description":"","quantite":1,"encombrement":0.01,"equipe":false,"resistance":0,"qualite":0,"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/aiguille.webp","effects":[]}
|
||||
{"_id":"zYI8mDiysWtmsSyy","name":"Carquois","permission":{"default":0,"jOzRscDxoXZWpGS6":3},"type":"conteneur","data":{"description":"","capacite":2,"encombrement":0.1,"equipe":false,"qualite":0,"cout":0.5},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/carquois.webp","effects":[]}
|
||||
{"_id":"zlDa1vwmls6Uf4pt","name":"Bourse de cuir","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"conteneur","data":{"description":"","capacite":0.5,"encombrement":0.01,"equipe":false,"qualite":0,"contenu":[],"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/bourse.webp","effects":[]}
|
||||
{"_id":"XlKp5BvZX8A03fUg","name":"Sac à dos de cuir","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"conteneur","data":{"description":"","capacite":25,"encombrement":0.4,"equipe":false,"qualite":0,"contenu":[],"cout":1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/sac_a_dos.webp","effects":[]}
|
||||
|
Loading…
Reference in New Issue
Block a user