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) {
|
prepareConteneurData(formData) {
|
||||||
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
||||||
|
|
||||||
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||||
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
||||||
}
|
}
|
||||||
@ -44,7 +43,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
|||||||
const dragData = {
|
const dragData = {
|
||||||
actorId: this.actor.id,
|
actorId: this.actor.id,
|
||||||
type: "Item",
|
type: "Item",
|
||||||
data: item.system
|
data: item.system,
|
||||||
|
uuid: item.uuid
|
||||||
};
|
};
|
||||||
|
|
||||||
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
||||||
@ -52,7 +52,8 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
|||||||
|
|
||||||
async _onDropItem(event, dragData) {
|
async _onDropItem(event, dragData) {
|
||||||
if (this.actor) {
|
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.actor.processDropItem(dropParams);
|
||||||
await this.render(true);
|
await this.render(true);
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,9 @@ export class RdDUtility {
|
|||||||
Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str));
|
Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str));
|
||||||
Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str));
|
Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str));
|
||||||
Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args));
|
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('buildLigneInventaire', (item, options) => { return new Handlebars.SafeString(RdDUtility.buildLigneInventaire(item, options)); });
|
||||||
Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); });
|
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('calculerPrixCommercant', item => item.calculerPrixCommercant());
|
||||||
Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord));
|
Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord));
|
||||||
Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord));
|
Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord));
|
||||||
@ -394,38 +395,58 @@ export class RdDUtility {
|
|||||||
return conteneurs.filter((conteneur, index, arr) => !conteneur.estContenu);
|
return conteneurs.filter((conteneur, index, arr) => !conteneur.estContenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
static prepareOptionsArbreInventaire(item, optionsArbre) {
|
||||||
/** Construit la structure récursive des conteneurs, avec imbrication potentielle
|
if (!optionsArbre.profondeur) {
|
||||||
*
|
optionsArbre.profondeur = 1
|
||||||
*/
|
};
|
||||||
static buildConteneur(objet, profondeur, templateItem, options) {
|
if (!optionsArbre.templateItem) {
|
||||||
if (!profondeur) profondeur = 1;
|
optionsArbre.templateItem = item.parent?.type == 'commerce'
|
||||||
if (!templateItem) templateItem = 'actor/inventaire-item.html'
|
? "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html"
|
||||||
objet.niveau = profondeur;
|
: "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html";
|
||||||
|
}
|
||||||
const isConteneur = objet.type == 'conteneur';
|
item.niveau = optionsArbre.profondeur;
|
||||||
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 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)}'>`;
|
* Construit la structure récursive des conteneurs, avec imbrication potentielle
|
||||||
for (let subItem of objet.subItems) {
|
*/
|
||||||
strContenu += this.buildConteneur(subItem, profondeur + 1, templateItem, options);
|
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>";
|
return strContenu + "</ul>";
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,12 @@
|
|||||||
</li>
|
</li>
|
||||||
{{#each objets as |item id|}}
|
{{#each objets as |item id|}}
|
||||||
{{#unless item.estContenu}}
|
{{#unless item.estContenu}}
|
||||||
{{#if (ne item.type 'conteneur')}}
|
{{#if (ne item.type 'conteneur')}}
|
||||||
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html"
|
{{buildLigneInventaire item ../options}}
|
||||||
item=item vide=true ouvert=true options=../options}}
|
{{/if}}
|
||||||
{{/if}}
|
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#each conteneurs as |conteneur id|}}
|
{{#each conteneurs as |conteneur id|}}
|
||||||
{{buildConteneur conteneur 'actor/commerce-inventaire-item.html' ../options}}
|
{{buildLigneInventaire conteneur ../options}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</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">
|
<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}} ">
|
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
|
||||||
{{#if (eq item.type 'conteneur')}}
|
{{#if (eq item.type 'conteneur')}}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<span class="equipement-detail">{{numberFormat item.system.encTotal decimals=2}}</span>
|
<span class="equipement-detail">{{numberFormat item.system.encTotal decimals=2}}</span>
|
||||||
<span class="equipement-actions item-controls">
|
<span class="equipement-actions item-controls">
|
||||||
{{#if @root.options.isOwner}}
|
{{#if options.isOwner}}
|
||||||
{{#unless item.estContenu}}
|
{{#unless item.estContenu}}
|
||||||
{{#if (or (eq item.type 'arme') (eq item.type 'armure') )}}
|
{{#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>
|
<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}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<a class="item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
|
<a class="item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
|
||||||
{{#if @root.options.isOwner}}
|
{{#if options.isOwner}}
|
||||||
{{#if item.system.actionPrincipale}}
|
{{#if item.system.actionPrincipale}}
|
||||||
<a class="item-action">{{item.system.actionPrincipale}}</a>
|
<a class="item-action">{{item.system.actionPrincipale}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
{{#each objets as |item id|}}
|
{{#each objets as |item id|}}
|
||||||
{{#unless item.estContenu}}
|
{{#unless item.estContenu}}
|
||||||
{{#if (ne item.type 'conteneur')}}
|
{{#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}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#each conteneurs as |conteneur id|}}
|
{{#each conteneurs as |conteneur id|}}
|
||||||
{{buildConteneur this 'actor/inventaire-item.html' @root.options}}
|
{{buildLigneInventaire conteneur @root.options}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -13,10 +13,8 @@
|
|||||||
<input class="attribute-value" type="text" name="system.capacite" value="{{system.capacite}}" data-dtype="Number"/>
|
<input class="attribute-value" type="text" name="system.capacite" value="{{system.capacite}}" data-dtype="Number"/>
|
||||||
</div>
|
</div>
|
||||||
{{>"systems/foundryvtt-reve-de-dragon/templates/item/partial-inventaire.html"}}
|
{{>"systems/foundryvtt-reve-de-dragon/templates/item/partial-inventaire.html"}}
|
||||||
|
|
||||||
{{#if isOwned}}
|
{{#if isOwned}}
|
||||||
<div class="flexcol">
|
<div class="flexcol">
|
||||||
<span><label>Contenu : </label></span>
|
|
||||||
<ul class="item-list alterne-list">
|
<ul class="item-list alterne-list">
|
||||||
<li class="competence-header flexrow">
|
<li class="competence-header flexrow">
|
||||||
<span class="equipement-nom">Nom</span>
|
<span class="equipement-nom">Nom</span>
|
||||||
@ -24,7 +22,8 @@
|
|||||||
<span class="equipement-detail">Enc.</span>
|
<span class="equipement-detail">Enc.</span>
|
||||||
<span class="equipement-actions">Actions</span>
|
<span class="equipement-actions">Actions</span>
|
||||||
</li>
|
</li>
|
||||||
{{buildContenu this}}
|
{{log 'contenu conteneur-sheet' this}}
|
||||||
|
{{buildInventaireConteneur actorId id @root.options}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Loading…
Reference in New Issue
Block a user