diff --git a/module/actor-creature-sheet.js b/module/actor-creature-sheet.js index c13b6d38..f6f91d02 100644 --- a/module/actor-creature-sheet.js +++ b/module/actor-creature-sheet.js @@ -21,13 +21,6 @@ export class RdDActorCreatureSheet extends ActorSheet { }); } - /* -------------------------------------------- */ - _checkNull(items) { - if (items && items.length) { - return items; - } - return []; - } /* -------------------------------------------- */ getData() { @@ -54,11 +47,19 @@ export class RdDActorCreatureSheet extends ActorSheet { data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); data.data.competencecreature = data.itemsByType["competencecreature"]; - - console.log("DATA:", data); + + RdDUtility.filterItemsPerTypeForSheet(data ); + RdDUtility.buildArbreDeConteneur( this, data ); + return data; } + /* -------------------------------------------- */ + async _onDrop(event) { + RdDUtility.processItemDropEvent(this, event); + super._onDrop(event); + } + /* -------------------------------------------- */ /** @override */ activateListeners(html) { diff --git a/module/actor-humanoide-sheet.js b/module/actor-humanoide-sheet.js index d3e5a600..f41fd603 100644 --- a/module/actor-humanoide-sheet.js +++ b/module/actor-humanoide-sheet.js @@ -21,14 +21,6 @@ export class RdDActorHumanoideSheet extends ActorSheet { }); } - /* -------------------------------------------- */ - _checkNull(items) { - if (items && items.length) { - return items; - } - return []; - } - /* -------------------------------------------- */ getData() { let data = super.getData(); @@ -52,12 +44,19 @@ export class RdDActorHumanoideSheet extends ActorSheet { data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste ); data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste ); data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); - data.data.competencecreature = data.itemsByType["competencecreature"]; + + RdDUtility.filterItemsPerTypeForSheet(data ); + RdDUtility.buildArbreDeConteneur( this, data ); - console.log("DATA:", data); return data; } + + /* -------------------------------------------- */ + async _onDrop(event) { + RdDUtility.processItemDropEvent(this, event); + super._onDrop(event); + } /* -------------------------------------------- */ /** @override */ diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 798b4884..8d1c4e76 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -21,14 +21,6 @@ export class RdDActorSheet extends ActorSheet { }); } - /* -------------------------------------------- */ - _checkNull(items) { - if (items && items.length) { - return items; - } - return []; - } - /* -------------------------------------------- */ getData() { let data = super.getData(); @@ -86,7 +78,7 @@ export class RdDActorSheet extends ActorSheet { } // To avoid armour and so on... - data.data.combat = duplicate( this._checkNull(data.itemsByType['arme'])); + data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme'])); if (data.competenceByCategory && data.competenceByCategory.melee) { //Specific case for Esquive and Corps à Corps @@ -115,43 +107,10 @@ export class RdDActorSheet extends ActorSheet { // low is normal, this the base used to compute the grid. data.data.fatigueHTML = "" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "
"; - data.data.materiel = this._checkNull(data.itemsByType['objet']); - data.data.conteneurs = this._checkNull(data.itemsByType['conteneur']); - data.data.armes = this._checkNull(data.itemsByType['arme']); - data.data.armures = this._checkNull(data.itemsByType['armure']); - data.data.livres = this._checkNull(data.itemsByType['livre']); - data.data.potions = this._checkNull(data.itemsByType['potions']); - data.data.ingredients = this._checkNull(data.itemsByType['ingredient']); - data.data.munitions = this._checkNull(data.itemsByType['munition']); - data.data.herbes = this._checkNull(data.itemsByType['herbe']); - data.data.sorts = this._checkNull(data.itemsByType['sort']); - data.data.queues = this._checkNull(data.itemsByType['queue']); - data.data.souffles = this._checkNull(data.itemsByType['souffle']); - data.data.ombres = this._checkNull(data.itemsByType['ombre']); - data.data.tetes = this._checkNull(data.itemsByType['tete']); - 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); + RdDUtility.filterItemsPerTypeForSheet(data ); data.data.sortReserve = data.data.reve.reserve.list; - - this.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant) - // Attribution des objets aux conteneurs - for (let conteneur of data.data.conteneurs) { - conteneur.subItems = []; - conteneur.encTotal = 0; - if (conteneur.data.contenu) { - for (let id of conteneur.data.contenu) { - let objet = data.data.objets.find( objet => (id == objet._id) ); - if (objet) { - objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template - this.objetVersConteneur[id] = conteneur._id; - conteneur.encTotal += objet.data.encombrement * ((objet.data.quantite)?objet.data.quantite:1); - conteneur.subItems.push( objet ); - } - } - } - } - // Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur) - let newConteneurs = data.data.conteneurs.filter(function(conteneur, index, arr) { return !conteneur.estContenu } ); - data.data.conteneurs = newConteneurs; + + RdDUtility.buildArbreDeConteneur( this, data ); return data; } @@ -165,22 +124,8 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async _onDrop(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 ) { - if ( this.actor.testConteneurCapacite(objetId, dropID) ) { - this.actor.enleverDeConteneur(objetId, this.objetVersConteneur[objetId]); - this.actor.ajouterAConteneur(objetId, dropID); - } else { - ui.notifications.info("Capacité d'encombrement insuffisante dans le conteneur !"); - } - } - } - console.log("DATA !!!!", dragData, dropID ); - super._onDrop(event) - this.actor.computeEncombrementTotal(); + RdDUtility.processItemDropEvent(this, event); + super._onDrop(event); } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 6adb1d16..cbd21a60 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -135,7 +135,76 @@ export class RdDUtility { return loadTemplates(templatePaths); } - + + /* -------------------------------------------- */ + static checkNull(items) { + if (items && items.length) { + return items; + } + return []; + } + + /* -------------------------------------------- */ + static filterItemsPerTypeForSheet( data ) { + data.data.materiel = this.checkNull(data.itemsByType['objet']); + data.data.conteneurs = this.checkNull(data.itemsByType['conteneur']); + data.data.armes = this.checkNull(data.itemsByType['arme']); + data.data.armures = this.checkNull(data.itemsByType['armure']); + data.data.livres = this.checkNull(data.itemsByType['livre']); + data.data.potions = this.checkNull(data.itemsByType['potions']); + data.data.ingredients = this.checkNull(data.itemsByType['ingredient']); + data.data.munitions = this.checkNull(data.itemsByType['munition']); + data.data.herbes = this.checkNull(data.itemsByType['herbe']); + data.data.sorts = this.checkNull(data.itemsByType['sort']); + data.data.queues = this.checkNull(data.itemsByType['queue']); + data.data.souffles = this.checkNull(data.itemsByType['souffle']); + data.data.ombres = this.checkNull(data.itemsByType['ombre']); + data.data.tetes = this.checkNull(data.itemsByType['tete']); + 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 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 ) { + if ( actorSheet.actor.testConteneurCapacite(objetId, dropID) ) { + actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]); + actorSheet.actor.ajouterAConteneur(objetId, dropID); + } else { + ui.notifications.info("Capacité d'encombrement insuffisante dans le conteneur !"); + } + } + } + actorSheet.actor.computeEncombrementTotal(); + } + + /* -------------------------------------------- */ + static buildArbreDeConteneur( actorSheet, data ) { + actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant) + // Attribution des objets aux conteneurs + for (let conteneur of data.data.conteneurs) { + conteneur.subItems = []; + conteneur.encTotal = 0; + if (conteneur.data.contenu) { + for (let id of conteneur.data.contenu) { + let objet = data.data.objets.find( objet => (id == objet._id) ); + if (objet) { + objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template + actorSheet.objetVersConteneur[id] = conteneur._id; + conteneur.encTotal += objet.data.encombrement * ((objet.data.quantite)?objet.data.quantite:1); + conteneur.subItems.push( objet ); + } + } + } + } + // Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur) + let newConteneurs = data.data.conteneurs.filter(function(conteneur, index, arr) { return !conteneur.estContenu } ); + data.data.conteneurs = newConteneurs; + } + /* -------------------------------------------- */ /** Construit la structure récursive des conteneurs, avec imbrication potentielle * diff --git a/system.json b/system.json index ea874bde..13b9f218 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "0.9.59", + "version": "0.9.61", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.6", "templateVersion": 47, diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index 4295abfb..ebb858fa 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -20,6 +20,7 @@ Caractéristiques Compétences Blessures + Équipement Description @@ -174,7 +175,36 @@ {{/each}} - + + {{!-- Equipment Tab --}} +
+ Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} +
+ Porté sur soi +
    + {{#each data.objets as |item id|}} + {{#unless item.estContenu}} + {{#if (ne item.type 'conteneur')}} +
  1. + +

    {{item.name}}

    + {{#if item.data.quantite}} +

    {{item.data.quantite}}

    + {{/if}} + +
  2. + {{/if}} + {{/unless}} + {{/each}} + {{#each data.conteneurs as |conteneur id|}} + {{buildConteneur this}} + {{/each}} +
+ {{!-- Biography Tab --}}
diff --git a/templates/actor-humanoide-sheet.html b/templates/actor-humanoide-sheet.html index 4295abfb..b79622e7 100644 --- a/templates/actor-humanoide-sheet.html +++ b/templates/actor-humanoide-sheet.html @@ -20,6 +20,7 @@ Caractéristiques Compétences Blessures + Équipement Description @@ -174,7 +175,36 @@ {{/each}}
- + + {{!-- Equipment Tab --}} +
+ Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} +
+ Porté sur soi +
    + {{#each data.objets as |item id|}} + {{#unless item.estContenu}} + {{#if (ne item.type 'conteneur')}} +
  1. + +

    {{item.name}}

    + {{#if item.data.quantite}} +

    {{item.data.quantite}}

    + {{/if}} + +
  2. + {{/if}} + {{/unless}} + {{/each}} + {{#each data.conteneurs as |conteneur id|}} + {{buildConteneur this}} + {{/each}} +
+ {{!-- Biography Tab --}}