Ajout des entites de Cauchemar

This commit is contained in:
sladecraven 2020-11-18 16:57:58 +01:00
parent 5068964e05
commit a5adacc5b9
7 changed files with 158 additions and 84 deletions

View File

@ -21,13 +21,6 @@ export class RdDActorCreatureSheet extends ActorSheet {
});
}
/* -------------------------------------------- */
_checkNull(items) {
if (items && items.length) {
return items;
}
return [];
}
/* -------------------------------------------- */
getData() {
@ -55,10 +48,18 @@ export class RdDActorCreatureSheet extends ActorSheet {
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) {

View File

@ -21,14 +21,6 @@ export class RdDActorHumanoideSheet extends ActorSheet {
});
}
/* -------------------------------------------- */
_checkNull(items) {
if (items && items.length) {
return items;
}
return [];
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
@ -52,13 +44,20 @@ 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"];
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) {

View File

@ -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 = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>";
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);
}
/* -------------------------------------------- */

View File

@ -136,6 +136,75 @@ 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
*

View File

@ -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,

View File

@ -20,6 +20,7 @@
<a class="item" data-tab="carac">Caractéristiques</a>
<a class="item" data-tab="competences">Compétences</a>
<a class="item" data-tab="blessures">Blessures</a>
<a class="item" data-tab="items">Équipement</a>
<a class="item" data-tab="description">Description</a>
</nav>
@ -175,6 +176,35 @@
</div>
</div>
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span cass=item-name>Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<hr>
<span cass=item-name>Porté sur soi</span>
<ol class="item-list">
{{#each data.objets as |item id|}}
{{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}}
<li class="item flexrow" data-item-id="{{item._id}}">
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
<h4 class="item-name">{{item.name}}</h4>
{{#if item.data.quantite}}
<h4 class="item-quantite">{{item.data.quantite}}</h4>
{{/if}}
<div class="item-controls">
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/if}}
{{/unless}}
{{/each}}
{{#each data.conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</div>
{{!-- Biography Tab --}}
<div class="tab description" data-group="primary" data-tab="description">
<div class="form-group editor">

View File

@ -20,6 +20,7 @@
<a class="item" data-tab="carac">Caractéristiques</a>
<a class="item" data-tab="competences">Compétences</a>
<a class="item" data-tab="blessures">Blessures</a>
<a class="item" data-tab="items">Équipement</a>
<a class="item" data-tab="description">Description</a>
</nav>
@ -175,6 +176,35 @@
</div>
</div>
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span cass=item-name>Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<hr>
<span cass=item-name>Porté sur soi</span>
<ol class="item-list">
{{#each data.objets as |item id|}}
{{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}}
<li class="item flexrow" data-item-id="{{item._id}}">
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
<h4 class="item-name">{{item.name}}</h4>
{{#if item.data.quantite}}
<h4 class="item-quantite">{{item.data.quantite}}</h4>
{{/if}}
<div class="item-controls">
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/if}}
{{/unless}}
{{/each}}
{{#each data.conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</div>
{{!-- Biography Tab --}}
<div class="tab description" data-group="primary" data-tab="description">
<div class="form-group editor">