Reprise de l'arbre d'inventaire
Soucis lors de l'affichage dans la fenêtre d'un conteneur
This commit is contained in:
parent
61474172a7
commit
4d5651c2d3
@ -29,7 +29,6 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
||||
/* -------------------------------------------- */
|
||||
prepareConteneurData(formData) {
|
||||
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
||||
|
||||
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
||||
}
|
||||
@ -44,7 +43,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
||||
const dragData = {
|
||||
actorId: this.actor.id,
|
||||
type: "Item",
|
||||
data: item.system
|
||||
data: item.system,
|
||||
uuid: item.uuid
|
||||
};
|
||||
|
||||
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
||||
@ -52,7 +52,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
||||
|
||||
async _onDropItem(event, dragData) {
|
||||
if (this.actor) {
|
||||
const dropParams = await RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur);
|
||||
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') ?? this.item.id
|
||||
const dropParams = await RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur);
|
||||
await this.actor.processDropItem(dropParams);
|
||||
await this.render(true);
|
||||
}
|
||||
|
@ -278,8 +278,9 @@ export class RdDUtility {
|
||||
Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str));
|
||||
Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str));
|
||||
Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args));
|
||||
Handlebars.registerHelper('buildConteneur', (objet, templateItem, options) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet, 1, templateItem, options)); });
|
||||
Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); });
|
||||
Handlebars.registerHelper('buildLigneInventaire', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildLigneInventaire(item, options)); });
|
||||
Handlebars.registerHelper('buildInventaireConteneur', (actorId, itemId, options) => { return new Handlebars.SafeString(RdDUtility.buildInventaireConteneur(actorId, itemId, options)); });
|
||||
Handlebars.registerHelper('buildContenuConteneur', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildContenuConteneur(item, options)); });
|
||||
Handlebars.registerHelper('calculerPrixCommercant', item => item.calculerPrixCommercant());
|
||||
Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord));
|
||||
Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord));
|
||||
@ -394,38 +395,58 @@ export class RdDUtility {
|
||||
return conteneurs.filter((conteneur, index, arr) => !conteneur.estContenu);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Construit la structure récursive des conteneurs, avec imbrication potentielle
|
||||
*
|
||||
*/
|
||||
static buildConteneur(objet, profondeur, templateItem, options) {
|
||||
if (!profondeur) profondeur = 1;
|
||||
if (!templateItem) templateItem = 'actor/inventaire-item.html'
|
||||
objet.niveau = profondeur;
|
||||
|
||||
const isConteneur = objet.type == 'conteneur';
|
||||
const isOuvert = isConteneur && this.getAfficheContenu(objet._id);
|
||||
const isVide = isConteneur && objet.system.contenu.length == 0;
|
||||
const conteneur = Handlebars.partials[`systems/foundryvtt-reve-de-dragon/templates/${templateItem}`]({
|
||||
item: objet,
|
||||
vide: isVide,
|
||||
ouvert: isOuvert,
|
||||
options: options
|
||||
});
|
||||
const contenu = isConteneur ? RdDUtility.buildContenu(objet, profondeur, isOuvert, templateItem, options) : '';
|
||||
return conteneur + contenu;
|
||||
static prepareOptionsArbreInventaire(item, optionsArbre) {
|
||||
if (!optionsArbre.profondeur) {
|
||||
optionsArbre.profondeur = 1
|
||||
};
|
||||
if (!optionsArbre.templateItem) {
|
||||
optionsArbre.templateItem = item.parent?.type == 'commerce'
|
||||
? "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html"
|
||||
: "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html";
|
||||
}
|
||||
item.niveau = optionsArbre.profondeur;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildContenu(objet, profondeur, afficherContenu, templateItem, options) {
|
||||
if (!profondeur) profondeur = 1;
|
||||
if (!templateItem) templateItem = 'actor/inventaire-item.html'
|
||||
objet.niveau = profondeur;
|
||||
|
||||
const display = afficherContenu ? 'item-display-show' : 'item-display-hide';
|
||||
let strContenu = `<ul class='item-list alterne-list ${display} list-item-margin${Math.min(profondeur, 6)}'>`;
|
||||
for (let subItem of objet.subItems) {
|
||||
strContenu += this.buildConteneur(subItem, profondeur + 1, templateItem, options);
|
||||
/**
|
||||
* Construit la structure récursive des conteneurs, avec imbrication potentielle
|
||||
*/
|
||||
static buildLigneInventaire(item, options = {}, optionsArbre = { ouvert: false, profondeur: 1 }) {
|
||||
RdDUtility.prepareOptionsArbreInventaire(item, optionsArbre);
|
||||
|
||||
const isConteneur = item.type == 'conteneur';
|
||||
const inventaire = {
|
||||
item: item,
|
||||
vide: isConteneur && item.system.contenu.length == 0,
|
||||
ouvert: isConteneur && RdDUtility.getAfficheContenu(item._id),
|
||||
options: options
|
||||
};
|
||||
optionsArbre.ouvert = inventaire.ouvert
|
||||
const ligneObjet = Handlebars.partials[optionsArbre.templateItem](inventaire);
|
||||
if (isConteneur) {
|
||||
return ligneObjet + RdDUtility.buildContenuConteneur(item, options, optionsArbre);
|
||||
}
|
||||
return ligneObjet;
|
||||
}
|
||||
|
||||
static buildInventaireConteneur(actorId, itemId, options) {
|
||||
const actor = game.actors.get(actorId)
|
||||
const item = actor?.items.get(itemId)
|
||||
if (item) {
|
||||
return RdDUtility.buildContenuConteneur(item, options, { ouvert: true, profondeur: 1 });
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildContenuConteneur(conteneur, options = {}, optionsArbre = {}) {
|
||||
RdDUtility.prepareOptionsArbreInventaire(conteneur, optionsArbre);
|
||||
const display = optionsArbre.ouvert ? 'item-display-show' : 'item-display-hide';
|
||||
let strContenu = `<ul class='item-list alterne-list ${display} list-item-margin${Math.min(optionsArbre.profondeur, 6)}'>`;
|
||||
optionsArbre.profondeur++;
|
||||
for (let contenu of conteneur.subItems) {
|
||||
strContenu += this.buildLigneInventaire(contenu, options, optionsArbre);
|
||||
}
|
||||
return strContenu + "</ul>";
|
||||
}
|
||||
|
@ -24,13 +24,12 @@
|
||||
</li>
|
||||
{{#each objets as |item id|}}
|
||||
{{#unless item.estContenu}}
|
||||
{{#if (ne item.type 'conteneur')}}
|
||||
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html"
|
||||
item=item vide=true ouvert=true options=../options}}
|
||||
{{/if}}
|
||||
{{#if (ne item.type 'conteneur')}}
|
||||
{{buildLigneInventaire item ../options}}
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
{{/each}}
|
||||
{{#each conteneurs as |conteneur id|}}
|
||||
{{buildConteneur conteneur 'actor/commerce-inventaire-item.html' ../options}}
|
||||
{{buildLigneInventaire conteneur ../options}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{#if (or @root.options.isObserver (ne item.type 'monnaie'))}}
|
||||
{{#if (or options.isObserver (ne item.type 'monnaie'))}}
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
|
||||
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
@ -21,7 +21,7 @@
|
||||
</span>
|
||||
<span class="equipement-detail">{{numberFormat item.system.encTotal decimals=2}}</span>
|
||||
<span class="equipement-actions item-controls">
|
||||
{{#if @root.options.isOwner}}
|
||||
{{#if options.isOwner}}
|
||||
{{#unless item.estContenu}}
|
||||
{{#if (or (eq item.type 'arme') (eq item.type 'armure') )}}
|
||||
<a class="item-equip" title="Equiper">{{#if item.system.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="far fa-hand-paper"></i>{{/if}}</a>
|
||||
@ -35,7 +35,7 @@
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<a class="item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
|
||||
{{#if @root.options.isOwner}}
|
||||
{{#if options.isOwner}}
|
||||
{{#if item.system.actionPrincipale}}
|
||||
<a class="item-action">{{item.system.actionPrincipale}}</a>
|
||||
{{/if}}
|
||||
|
@ -20,11 +20,11 @@
|
||||
{{#each objets as |item id|}}
|
||||
{{#unless item.estContenu}}
|
||||
{{#if (ne item.type 'conteneur')}}
|
||||
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html" item=item vide=true ouvert=true options=@root.options}}
|
||||
{{buildLigneInventaire item @root.options}}
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
{{/each}}
|
||||
{{#each conteneurs as |conteneur id|}}
|
||||
{{buildConteneur this 'actor/inventaire-item.html' @root.options}}
|
||||
{{buildLigneInventaire conteneur @root.options}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
|
@ -13,10 +13,8 @@
|
||||
<input class="attribute-value" type="text" name="system.capacite" value="{{system.capacite}}" data-dtype="Number"/>
|
||||
</div>
|
||||
{{>"systems/foundryvtt-reve-de-dragon/templates/item/partial-inventaire.html"}}
|
||||
|
||||
{{#if isOwned}}
|
||||
<div class="flexcol">
|
||||
<span><label>Contenu : </label></span>
|
||||
<ul class="item-list alterne-list">
|
||||
<li class="competence-header flexrow">
|
||||
<span class="equipement-nom">Nom</span>
|
||||
@ -24,7 +22,8 @@
|
||||
<span class="equipement-detail">Enc.</span>
|
||||
<span class="equipement-actions">Actions</span>
|
||||
</li>
|
||||
{{buildContenu this}}
|
||||
{{log 'contenu conteneur-sheet' this}}
|
||||
{{buildInventaireConteneur actorId id @root.options}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user