#11 Gestion des conteneurs
This commit is contained in:
parent
021948bf6e
commit
1d6768aff0
@ -106,28 +106,51 @@ export class RdDActorSheet extends ActorSheet {
|
||||
// Mise à jour de l'encombrement total
|
||||
this.actor.computeEncombrementTotal();
|
||||
|
||||
// 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.conteneur = 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['herbes']);
|
||||
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.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);
|
||||
// Common data
|
||||
data.data.competenceByCategory = data.competenceByCategory;
|
||||
data.data.encombrementTotal = this.actor.encombrementTotal;
|
||||
data.data.isGM = game.user.isGM;
|
||||
data.bonusmalusTable = CONFIG.RDD.bonusmalus;
|
||||
|
||||
// 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['herbes']);
|
||||
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);
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -140,10 +163,18 @@ 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;
|
||||
this.actor.enleverDeConteneur(objetId, this.objetVersConteneur[objetId]);
|
||||
this.actor.ajouterAConteneur(objetId, dropID);
|
||||
}
|
||||
console.log("DATA !!!!", dragData, dropID );
|
||||
super._onDrop(event)
|
||||
this.actor.computeEncombrementTotal();
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
|
@ -371,14 +371,40 @@ export class RdDActor extends Actor {
|
||||
await this.update( {"data.compteurs": compteurs } );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Supprime un item d'un conteneur, sur la base
|
||||
* de leurs ID */
|
||||
async enleverDeConteneur( itemId, conteneurId ) {
|
||||
if ( !conteneurId ) return; // pas de conteneur (porté sur soi)
|
||||
let conteneur = this.items.find( conteneur => conteneurId == conteneur._id); // recup conteneur
|
||||
if ( conteneur ) { // Si présent
|
||||
//console.log("Suppression du conteneur1", conteneurId, itemId, conteneur.data.data.contenu);
|
||||
let newContenu = conteneur.data.data.contenu.filter( function(value, index, arr) { return value != itemId } );
|
||||
//console.log("Suppression du conteneur2", conteneurId, itemId, newContenu);
|
||||
let update = {_id: conteneurId, "data.contenu": newContenu };
|
||||
await this.updateEmbeddedEntity("OwnedItem", update);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Ajoute un item dans un conteneur, sur la base
|
||||
* de leurs ID */
|
||||
async ajouterAConteneur( itemId, conteneurId ) {
|
||||
if ( !conteneurId ) return; // pas de conteneur (porté sur soi)
|
||||
let conteneur = this.items.find( conteneur => conteneurId == conteneur._id);
|
||||
if ( conteneur && conteneur.type == 'conteneur' ) {
|
||||
conteneur.data.data.contenu.push( itemId );
|
||||
await this.updateEmbeddedEntity("OwnedItem", conteneur.data );
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
detectSurEncombrement( ) {
|
||||
let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value);
|
||||
console.log("Sur enc", this.encombrementTotal, diffEnc);
|
||||
if ( diffEnc > 0 ) { // Sur-encombrement
|
||||
let malus = Math.round( diffEnc);
|
||||
malus = (malus == 0) ? 1 : malus; // Always 1 at least
|
||||
console.log("Sur enc malus", malus);
|
||||
//console.log("Sur enc malus", malus);
|
||||
return malus;
|
||||
}
|
||||
return 0;
|
||||
|
@ -136,6 +136,9 @@ Hooks.once("init", async function() {
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
|
||||
|
||||
// Handlebar function pour container
|
||||
Handlebars.registerHelper('buildConteneur', (objet) => { return RdDUtility.buildConteneur(objet); });
|
||||
|
||||
// Patch the initiative formula
|
||||
_patch_initiative();
|
||||
});
|
||||
|
@ -155,12 +155,30 @@ export class RdDUtility {
|
||||
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html',
|
||||
// Calendrier
|
||||
'systems/foundryvtt-reve-de-dragon/templates/calendar_template.html'
|
||||
'systems/foundryvtt-reve-de-dragon/templates/calendar_template.html',
|
||||
// Conteneur/item in Actor sheet
|
||||
'systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html'
|
||||
];
|
||||
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
static buildConteneur( objet, niveau ) {
|
||||
if (!niveau) niveau = 1;
|
||||
let prefix = "";
|
||||
for (let i = 0; i < niveau; i++) prefix += " ";
|
||||
let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']( { item: objet} );
|
||||
if (objet.type == 'conteneur') {
|
||||
str = str + "<ol class='item-list'>";
|
||||
for (let subItem of objet.subItems) {
|
||||
str = str + this.buildConteneur(subItem, niveau+1);
|
||||
}
|
||||
str = str + "</ol>";
|
||||
}
|
||||
return new Handlebars.SafeString(str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildResolutionTable( ) {
|
||||
let tableRes = []
|
||||
|
@ -5,7 +5,7 @@
|
||||
"version": "0.9.32",
|
||||
"minimumCoreVersion": "0.7.5",
|
||||
"compatibleCoreVersion": "0.7.6",
|
||||
"templateVersion": 41,
|
||||
"templateVersion": 43,
|
||||
"author": "LeRatierBretonnien",
|
||||
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
|
||||
"styles": ["styles/simple.css"],
|
||||
|
@ -467,6 +467,7 @@
|
||||
"encombrement": 0,
|
||||
"equipe": false,
|
||||
"qualite": 0,
|
||||
"contenu": [],
|
||||
"cout": 0
|
||||
},
|
||||
"arme": {
|
||||
|
8
templates/actor-inventaire-conteneur.html
Normal file
8
templates/actor-inventaire-conteneur.html
Normal file
@ -0,0 +1,8 @@
|
||||
<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>
|
||||
<div class="item-controls">
|
||||
<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>
|
@ -422,8 +422,12 @@
|
||||
{{!-- Equipment Tab --}}
|
||||
<div class="tab items" data-group="primary" data-tab="items">
|
||||
<span cass=item-name>Encombrement total/max : {{data.encombrementTotal}} / {{data.attributs.encombrement.value}}</span>
|
||||
<hr>
|
||||
<span cass=item-name>Porté sur soi</span>
|
||||
<ol class="item-list">
|
||||
{{#each data.armes_seules as |item id|}}
|
||||
{{#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>
|
||||
@ -433,61 +437,15 @@
|
||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
</div>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
{{/each}}
|
||||
</ol>
|
||||
<ol class="item-list">
|
||||
{{#each data.armures as |item id|}}
|
||||
<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>
|
||||
<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>
|
||||
{{/each}}
|
||||
</ol>
|
||||
<ol class="item-list">
|
||||
{{#each data.conteneur as |item id|}}
|
||||
<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>
|
||||
<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>
|
||||
{{#each data.conteneurs as |conteneur id|}}
|
||||
{{buildConteneur this}}
|
||||
{{/each}}
|
||||
</ol>
|
||||
<ol class="item-list">
|
||||
{{#each data.materiel as |item id|}}
|
||||
<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>
|
||||
<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>
|
||||
{{/each}}
|
||||
</ol>
|
||||
<ol class="item-list">
|
||||
{{#each data.livres as |item id|}}
|
||||
<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>
|
||||
<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>
|
||||
{{/each}}
|
||||
</ol>
|
||||
</div>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
{{!-- Biography Tab --}}
|
||||
<div class="tab biography" data-group="primary" data-tab="description">
|
||||
|
Loading…
Reference in New Issue
Block a user