#11 Gestion des conteneurs
This commit is contained in:
parent
021948bf6e
commit
1d6768aff0
@ -106,10 +106,16 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
// Mise à jour de l'encombrement total
|
// Mise à jour de l'encombrement total
|
||||||
this.actor.computeEncombrementTotal();
|
this.actor.computeEncombrementTotal();
|
||||||
|
|
||||||
|
// 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.
|
// 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.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.materiel = this._checkNull(data.itemsByType['objet']);
|
||||||
data.data.conteneur = this._checkNull(data.itemsByType['conteneur']);
|
data.data.conteneurs = this._checkNull(data.itemsByType['conteneur']);
|
||||||
data.data.armes = this._checkNull(data.itemsByType['arme']);
|
data.data.armes = this._checkNull(data.itemsByType['arme']);
|
||||||
data.data.armures = this._checkNull(data.itemsByType['armure']);
|
data.data.armures = this._checkNull(data.itemsByType['armure']);
|
||||||
data.data.livres = this._checkNull(data.itemsByType['livre']);
|
data.data.livres = this._checkNull(data.itemsByType['livre']);
|
||||||
@ -122,11 +128,28 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
data.data.souffles = this._checkNull(data.itemsByType['souffle']);
|
data.data.souffles = this._checkNull(data.itemsByType['souffle']);
|
||||||
data.data.ombres = this._checkNull(data.itemsByType['ombre']);
|
data.data.ombres = this._checkNull(data.itemsByType['ombre']);
|
||||||
data.data.tetes = this._checkNull(data.itemsByType['tete']);
|
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);
|
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);
|
||||||
data.data.competenceByCategory = data.competenceByCategory;
|
|
||||||
data.data.encombrementTotal = this.actor.encombrementTotal;
|
this.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
||||||
data.data.isGM = game.user.isGM;
|
// Attribution des objets aux conteneurs
|
||||||
data.bonusmalusTable = CONFIG.RDD.bonusmalus;
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
@ -140,10 +163,18 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
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)
|
super._onDrop(event)
|
||||||
this.actor.computeEncombrementTotal();
|
this.actor.computeEncombrementTotal();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
/** @override */
|
/** @override */
|
||||||
activateListeners(html) {
|
activateListeners(html) {
|
||||||
|
@ -371,14 +371,40 @@ export class RdDActor extends Actor {
|
|||||||
await this.update( {"data.compteurs": compteurs } );
|
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( ) {
|
detectSurEncombrement( ) {
|
||||||
let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value);
|
let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value);
|
||||||
console.log("Sur enc", this.encombrementTotal, diffEnc);
|
|
||||||
if ( diffEnc > 0 ) { // Sur-encombrement
|
if ( diffEnc > 0 ) { // Sur-encombrement
|
||||||
let malus = Math.round( diffEnc);
|
let malus = Math.round( diffEnc);
|
||||||
malus = (malus == 0) ? 1 : malus; // Always 1 at least
|
malus = (malus == 0) ? 1 : malus; // Always 1 at least
|
||||||
console.log("Sur enc malus", malus);
|
//console.log("Sur enc malus", malus);
|
||||||
return malus;
|
return malus;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -136,6 +136,9 @@ Hooks.once("init", async function() {
|
|||||||
Items.unregisterSheet("core", ItemSheet);
|
Items.unregisterSheet("core", ItemSheet);
|
||||||
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
|
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 the initiative formula
|
||||||
_patch_initiative();
|
_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-roll-encaisser.html',
|
||||||
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html',
|
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html',
|
||||||
// Calendrier
|
// 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);
|
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( ) {
|
static buildResolutionTable( ) {
|
||||||
let tableRes = []
|
let tableRes = []
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"version": "0.9.32",
|
"version": "0.9.32",
|
||||||
"minimumCoreVersion": "0.7.5",
|
"minimumCoreVersion": "0.7.5",
|
||||||
"compatibleCoreVersion": "0.7.6",
|
"compatibleCoreVersion": "0.7.6",
|
||||||
"templateVersion": 41,
|
"templateVersion": 43,
|
||||||
"author": "LeRatierBretonnien",
|
"author": "LeRatierBretonnien",
|
||||||
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
|
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
|
||||||
"styles": ["styles/simple.css"],
|
"styles": ["styles/simple.css"],
|
||||||
|
@ -467,6 +467,7 @@
|
|||||||
"encombrement": 0,
|
"encombrement": 0,
|
||||||
"equipe": false,
|
"equipe": false,
|
||||||
"qualite": 0,
|
"qualite": 0,
|
||||||
|
"contenu": [],
|
||||||
"cout": 0
|
"cout": 0
|
||||||
},
|
},
|
||||||
"arme": {
|
"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 --}}
|
{{!-- Equipment Tab --}}
|
||||||
<div class="tab items" data-group="primary" data-tab="items">
|
<div class="tab items" data-group="primary" data-tab="items">
|
||||||
<span cass=item-name>Encombrement total/max : {{data.encombrementTotal}} / {{data.attributs.encombrement.value}}</span>
|
<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">
|
<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}}">
|
<li class="item flexrow" data-item-id="{{item._id}}">
|
||||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||||
<h4 class="item-name">{{item.name}}</h4>
|
<h4 class="item-name">{{item.name}}</h4>
|
||||||
@ -433,58 +437,12 @@
|
|||||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ol>
|
|
||||||
<ol class="item-list">
|
<ol class="item-list">
|
||||||
{{#each data.armures as |item id|}}
|
{{#each data.conteneurs as |conteneur id|}}
|
||||||
<li class="item flexrow" data-item-id="{{item._id}}">
|
{{buildConteneur this}}
|
||||||
<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}}
|
|
||||||
</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}}
|
{{/each}}
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user