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() {
let typeObjets = RdDItem.getTypesOeuvres();
let types = RdDItem.getTypesOeuvres();
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 += '</select>';

View File

@ -50,16 +50,16 @@ export class RdDBaseActorSheet extends ActorSheet {
encTotal: await this.actor.computeEncTotal(),
}
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
this._appliquerRechercheObjets(formData.objets, formData.conteneurs);
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.inventaires);
this._appliquerRechercheObjets(formData.conteneurs, formData.inventaires);
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
return formData;
}
_appliquerRechercheObjets(objets, conteneurs) {
_appliquerRechercheObjets(conteneurs, inventaires) {
if (this.options.recherche?.text) {
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)
do {
allVisible.push(...addVisible)
@ -67,11 +67,11 @@ export class RdDBaseActorSheet extends ActorSheet {
addVisible = parentsIds.filter(id => !allVisible.includes(id))
}
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))
}
else {
objets.forEach(it => it.system.isHidden = false)
inventaires.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.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']);
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]))
.reduce((a, b) => a.concat(b), [])
.sort(Misc.ascending(it => it.name));
@ -230,9 +231,9 @@ export class RdDBaseActorSheet extends ActorSheet {
/* -------------------------------------------- */
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">`;
for (let typeName of typeObjets) {
for (let typeName of types) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
}
content += '</select>';

View File

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

View File

@ -29,7 +29,7 @@ export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
/* -------------------------------------------- */
prepareConteneurData(formData) {
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;
}

View File

@ -339,13 +339,13 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static buildArbreDeConteneurs(conteneurs, objets) {
static buildArbreDeConteneurs(conteneurs, inventaires) {
let objetVersConteneur = {};
// Attribution des objets aux conteneurs
for (let conteneur of conteneurs) {
conteneur.subItems = [];
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) {
objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template
objetVersConteneur[id] = conteneur._id;
@ -354,20 +354,20 @@ export class RdDUtility {
}
}
for (let conteneur of conteneurs) {
conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets);
conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, inventaires);
}
return objetVersConteneur;
}
/* -------------------------------------------- */
static calculEncContenu(conteneur, objets) {
static calculEncContenu(conteneur, inventaires) {
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);
let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1);
for (let contenu of contenus) {
if (contenu.type == 'conteneur') {
enc += RdDUtility.calculEncContenu(contenu, objets);
enc += RdDUtility.calculEncContenu(contenu, inventaires);
}
else {
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-actions">Actions</span>
</li>
{{#each (trier objets) as |item id|}}
{{#each (trier inventaires) as |item id|}}
{{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}}
{{buildLigneInventaire item ../options}}

View File

@ -1,7 +1,7 @@
{{#if @root.options.isObserver}}
<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">
{{#each monnaie as |piece id|}}
{{#each monnaies as |piece id|}}
<li class="item flexrow list-item" data-item-id="{{piece._id}}">
<img class="sheet-competence-img" src="{{piece.img}}" title="{{piece.name}}"/>
<span class="equipement-nom">{{piece.name}}</span>

View File

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