Fix affichage des "objets" dans les commerces

La confusion entre les Item "objets" et le champ formData.objets
rendait les Item "objets" indisponibles (par exemple, les vêtements)
This commit is contained in:
Vincent Vandemeulebrouck 2023-06-04 01:58:02 +02:00
parent 49fc2c9b0a
commit 1bf247db33
8 changed files with 28 additions and 23 deletions

View File

@ -456,9 +456,9 @@ export class RdDActorSheet extends RdDBaseActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async selectTypeOeuvreToCreate() { async selectTypeOeuvreToCreate() {
let typeObjets = RdDItem.getTypesOeuvres(); let types = RdDItem.getTypesOeuvres();
let content = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`; let content = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
for (let typeName of typeObjets) { for (let typeName of types) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>` content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
} }
content += '</select>'; content += '</select>';

View File

@ -50,16 +50,16 @@ export class RdDBaseActorSheet extends ActorSheet {
encTotal: await this.actor.computeEncTotal(), encTotal: await this.actor.computeEncTotal(),
} }
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets); this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.inventaires);
this._appliquerRechercheObjets(formData.objets, formData.conteneurs); this._appliquerRechercheObjets(formData.conteneurs, formData.inventaires);
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs); formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
return formData; return formData;
} }
_appliquerRechercheObjets(objets, conteneurs) { _appliquerRechercheObjets(conteneurs, inventaires) {
if (this.options.recherche?.text) { if (this.options.recherche?.text) {
const recherche = this.options.recherche; const recherche = this.options.recherche;
const allVisible = objets.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id); const allVisible = inventaires.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id);
let addVisible = conteneurs.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id) let addVisible = conteneurs.filter(it => it.isNomTypeLike(recherche.text)).map(it => it.id)
do { do {
allVisible.push(...addVisible) allVisible.push(...addVisible)
@ -67,11 +67,11 @@ export class RdDBaseActorSheet extends ActorSheet {
addVisible = parentsIds.filter(id => !allVisible.includes(id)) addVisible = parentsIds.filter(id => !allVisible.includes(id))
} }
while (addVisible.length > 0) while (addVisible.length > 0)
objets.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) inventaires.forEach(it => it.system.isHidden = !allVisible.includes(it.id))
conteneurs.forEach(it => it.system.isHidden = !allVisible.includes(it.id)) conteneurs.forEach(it => it.system.isHidden = !allVisible.includes(it.id))
} }
else { else {
objets.forEach(it => it.system.isHidden = false) inventaires.forEach(it => it.system.isHidden = false)
conteneurs.forEach(it => it.system.isHidden = false) conteneurs.forEach(it => it.system.isHidden = false)
} }
} }
@ -118,9 +118,10 @@ export class RdDBaseActorSheet extends ActorSheet {
formData.herbes = Misc.arrayOrEmpty(itemTypes['herbe']); formData.herbes = Misc.arrayOrEmpty(itemTypes['herbe']);
formData.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']); formData.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']);
formData.gemmes = Misc.arrayOrEmpty(itemTypes['gemme']); formData.gemmes = Misc.arrayOrEmpty(itemTypes['gemme']);
formData.monnaie = Misc.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere()); formData.monnaies = Misc.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere());
formData.objets = Misc.arrayOrEmpty(itemTypes['objet'])
formData.objets = RdDItem.getItemTypesInventaire('all') formData.inventaires = RdDItem.getItemTypesInventaire('all')
.map(t => Misc.arrayOrEmpty(itemTypes[t])) .map(t => Misc.arrayOrEmpty(itemTypes[t]))
.reduce((a, b) => a.concat(b), []) .reduce((a, b) => a.concat(b), [])
.sort(Misc.ascending(it => it.name)); .sort(Misc.ascending(it => it.name));
@ -230,9 +231,9 @@ export class RdDBaseActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async selectObjetTypeToCreate() { async selectObjetTypeToCreate() {
let typeObjets = this.getTypesInventaire().sort(Misc.ascending(type => Misc.typeName('Item', type))); let types = this.getTypesInventaire().sort(Misc.ascending(type => Misc.typeName('Item', type)));
let content = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`; let content = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
for (let typeName of typeObjets) { for (let typeName of types) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>` content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
} }
content += '</select>'; content += '</select>';

View File

@ -15,6 +15,7 @@ export const TYPES = {
conteneur: 'conteneur', conteneur: 'conteneur',
sort: 'sort', sort: 'sort',
herbe: 'herbe', herbe: 'herbe',
plante: 'plante',
faune: 'faune', faune: 'faune',
ingredient: 'ingredient', ingredient: 'ingredient',
livre: 'livre', livre: 'livre',
@ -34,6 +35,8 @@ export const TYPES = {
maladie: 'maladie', maladie: 'maladie',
poison: 'poison', poison: 'poison',
oeuvre: 'oeuvre', oeuvre: 'oeuvre',
monnaie: 'monnaie',
munition: 'munition',
nourritureboisson: 'nourritureboisson', nourritureboisson: 'nourritureboisson',
service: 'service', service: 'service',
signedraconique: 'signedraconique', signedraconique: 'signedraconique',
@ -42,7 +45,8 @@ export const TYPES = {
sortreserve: 'sortreserve', sortreserve: 'sortreserve',
extraitpoetique: 'extraitpoetique', extraitpoetique: 'extraitpoetique',
tarot: 'tarot', tarot: 'tarot',
empoignade: 'empoignade' empoignade: 'empoignade',
objet: 'objet'
} }
const typesInventaireMateriel = [ const typesInventaireMateriel = [
TYPES.arme, TYPES.arme,

View File

@ -29,7 +29,7 @@ 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.inventaires);
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems; formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
} }

View File

@ -339,13 +339,13 @@ export class RdDUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildArbreDeConteneurs(conteneurs, objets) { static buildArbreDeConteneurs(conteneurs, inventaires) {
let objetVersConteneur = {}; let objetVersConteneur = {};
// Attribution des objets aux conteneurs // Attribution des objets aux conteneurs
for (let conteneur of conteneurs) { for (let conteneur of conteneurs) {
conteneur.subItems = []; conteneur.subItems = [];
for (let id of conteneur.system.contenu ?? []) { for (let id of conteneur.system.contenu ?? []) {
let objet = objets.find(objet => (id == objet._id)); let objet = inventaires.find(objet => (id == objet._id));
if (objet) { if (objet) {
objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template
objetVersConteneur[id] = conteneur._id; objetVersConteneur[id] = conteneur._id;
@ -354,20 +354,20 @@ export class RdDUtility {
} }
} }
for (let conteneur of conteneurs) { for (let conteneur of conteneurs) {
conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets); conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, inventaires);
} }
return objetVersConteneur; return objetVersConteneur;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static calculEncContenu(conteneur, objets) { static calculEncContenu(conteneur, inventaires) {
const contenus = (conteneur.system.contenu ?? []).filter(id => id != undefined) const contenus = (conteneur.system.contenu ?? []).filter(id => id != undefined)
.map(id => objets.find(it => (id == it.id))) .map(id => inventaires.find(it => (id == it.id)))
.filter(it => it); .filter(it => it);
let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1); let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1);
for (let contenu of contenus) { for (let contenu of contenus) {
if (contenu.type == 'conteneur') { if (contenu.type == 'conteneur') {
enc += RdDUtility.calculEncContenu(contenu, objets); enc += RdDUtility.calculEncContenu(contenu, inventaires);
} }
else { else {
enc += Number(contenu.system.encombrement ?? 0) * Number(contenu.system.quantite ?? 1) enc += Number(contenu.system.encombrement ?? 0) * Number(contenu.system.quantite ?? 1)

View File

@ -25,7 +25,7 @@
<span class="equipement-detail">Prix (sols)</span> <span class="equipement-detail">Prix (sols)</span>
<span class="equipement-actions">Actions</span> <span class="equipement-actions">Actions</span>
</li> </li>
{{#each (trier objets) as |item id|}} {{#each (trier inventaires) as |item id|}}
{{#unless item.estContenu}} {{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}} {{#if (ne item.type 'conteneur')}}
{{buildLigneInventaire item ../options}} {{buildLigneInventaire item ../options}}

View File

@ -1,7 +1,7 @@
{{#if @root.options.isObserver}} {{#if @root.options.isObserver}}
<span class="item-name"><h4>Argent et Monnaies (fortune: {{calc.fortune.sols}} sols {{calc.fortune.deniers}} deniers)</h4></span> <span class="item-name"><h4>Argent et Monnaies (fortune: {{calc.fortune.sols}} sols {{calc.fortune.deniers}} deniers)</h4></span>
<ul class="item-list alterne-list"> <ul class="item-list alterne-list">
{{#each monnaie as |piece id|}} {{#each monnaies as |piece id|}}
<li class="item flexrow list-item" data-item-id="{{piece._id}}"> <li class="item flexrow list-item" data-item-id="{{piece._id}}">
<img class="sheet-competence-img" src="{{piece.img}}" title="{{piece.name}}"/> <img class="sheet-competence-img" src="{{piece.img}}" title="{{piece.name}}"/>
<span class="equipement-nom">{{piece.name}}</span> <span class="equipement-nom">{{piece.name}}</span>

View File

@ -22,7 +22,7 @@
<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>
{{#each objets as |item id|}} {{#each inventaires as |item id|}}
{{#unless item.estContenu}} {{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}} {{#if (ne item.type 'conteneur')}}
{{buildLigneInventaire item @root.options}} {{buildLigneInventaire item @root.options}}