From 7b58407634de75be99d901e409b5873b10f04808 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 5 Dec 2022 15:29:00 +0100 Subject: [PATCH] Cleanup --- module/actor-sheet.js | 27 +---- module/actor.js | 130 ++++++++++----------- module/dialog-item-consommer.js | 10 +- module/item-competence.js | 32 +++++ module/item-sheet.js | 60 +++------- module/item.js | 1 - module/rdd-utility.js | 45 ++----- templates/actor/dragon-queue.html | 2 +- templates/actor/dragon-souffles.html | 2 +- templates/actor/dragon-tetes.html | 2 +- templates/actor/hr-casestmr.html | 2 +- templates/actor/hr-rencontres.html | 2 +- templates/actor/hr-signes-draconiques.html | 2 +- templates/actor/hr-sorts-reserve.html | 2 +- templates/actor/hr-sorts.html | 2 +- 15 files changed, 142 insertions(+), 179 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 8dc97a16..4003a99c 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -133,7 +133,7 @@ export class RdDActorSheet extends ActorSheet { async _onDropItem(event, dragData) { const destItemId = $(event.target)?.closest('.item').attr('data-item-id') const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur) - if (dropParams){ + if (dropParams) { const callSuper = await this.actor.processDropItem(dropParams) if (callSuper) { await super._onDropItem(event, dragData) @@ -164,31 +164,14 @@ export class RdDActorSheet extends ActorSheet { const item = RdDSheetUtility.getItem(event, this.actor); RdDSheetUtility.splitItem(item, this.actor); }); - html.find('.item-edit').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor) - item.sheet.render(true) - }) - html.find('.display-label a').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item.sheet.render(true); - }); - html.find('.item-delete').click(async event => { - const li = RdDSheetUtility.getEventElement(event); - const item = this.actor.getObjet(li.data("item-id")); - RdDUtility.confirmerSuppressionItem(this, item, li); - }); - html.find('.item-vendre').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item?.proposerVente(); - }); - html.find('.item-montrer').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item?.postItem(); - }); html.find('.item-action').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor) this.actor.actionItem(item); }); + html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)) + html.find('.item-delete').click(async event => RdDUtility.confirmerSuppressionItem(this, RdDSheetUtility.getItem(event, this.actor))); + html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); + html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem()); html.find('.subacteur-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); const actorId = li.data("actor-id"); diff --git a/module/actor.js b/module/actor.js index c38d9124..f9c5c3bf 100644 --- a/module/actor.js +++ b/module/actor.js @@ -250,7 +250,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ getReveActuel() { - switch(this.type) { + switch (this.type) { case 'personnage': return Misc.toInt(this.system.reve?.reve?.value ?? this.carac.reve.value); case 'creature': @@ -258,7 +258,7 @@ export class RdDActor extends Actor { return Misc.toInt(this.system.carac.reve?.value) case 'vehicule': default: - return 0; + return 0; } } @@ -400,8 +400,8 @@ export class RdDActor extends Actor { return duplicate(possessions[0]); } const draconics = [...this.getDraconicList().filter(it => it.system.niveau >= 0), - POSSESSION_SANS_DRACONIC] - .sort(Misc.descending(it => it.system.niveau)); + POSSESSION_SANS_DRACONIC] + .sort(Misc.descending(it => it.system.niveau)); return duplicate(draconics[0]); } @@ -620,18 +620,18 @@ export class RdDActor extends Actor { content: 'Remise à neuf de ' + this.name }); const updates = { - 'system.sante.endurance.value' : this.system.sante.endurance.max + 'system.sante.endurance.value': this.system.sante.endurance.max }; if (!this.isEntite([ENTITE_INCARNE, ENTITE_BLURETTE])) { if (this.system.blessures) { updates['system.blessures.legeres.liste'] = [PAS_DE_BLESSURE, PAS_DE_BLESSURE, PAS_DE_BLESSURE, PAS_DE_BLESSURE, PAS_DE_BLESSURE]; - updates['system.blessures.graves.liste'] = [PAS_DE_BLESSURE, PAS_DE_BLESSURE]; + updates['system.blessures.graves.liste'] = [PAS_DE_BLESSURE, PAS_DE_BLESSURE]; updates['system.blessures.critiques.liste'] = [PAS_DE_BLESSURE]; } updates['system.sante.vie.value'] = this.system.sante.vie.max; updates['system.sante.fatigue.value'] = 0; if (this.isPersonnage()) { - updates['system.compteurs.ethylisme'] = { value:1, nb_doses: 0, jet_moral: false}; + updates['system.compteurs.ethylisme'] = { value: 1, nb_doses: 0, jet_moral: false }; } } await this.update(updates); @@ -809,8 +809,7 @@ export class RdDActor extends Actor { name: 'maitrise', label: 'Maîtriser le Rêve de Dragon', callbacks: [ - { action: async r => - this.resultCombatReveDeDragon(r) } + { action: async r => this.resultCombatReveDeDragon(r) } ] } ); @@ -829,11 +828,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async sortMisEnReserve(sort, draconic, coord, ptreve) { await this.createEmbeddedDocuments("Item", [{ - type: 'sortreserve', - name: sort.name, - img: sort.img, - system: { sortid: sort._id, draconic: (draconic?.name ?? sort.system.draconic), ptreve: ptreve, coord: coord, heurecible: 'Vaisseau' } }], - { renderSheet: false}); + type: 'sortreserve', + name: sort.name, + img: sort.img, + system: { sortid: sort._id, draconic: (draconic?.name ?? sort.system.draconic), ptreve: ptreve, coord: coord, heurecible: 'Vaisseau' } + }], + { renderSheet: false }); this.currentTMR.updateTokens(); } @@ -923,7 +923,7 @@ export class RdDActor extends Actor { return; } const xpUtilise = Math.max(0, Math.min(stress, xpRequis)); - const gainNiveau = (xpUtilise >= xpRequis || xpRequis <=0) ? 1 : 0; + const gainNiveau = (xpUtilise >= xpRequis || xpRequis <= 0) ? 1 : 0; const nouveauNiveau = niveau + gainNiveau; const nouveauXp = gainNiveau > 0 ? Math.max(competence.system.xp - xpSuivant, 0) : (competence.system.xp + xpUtilise); await competence.update({ @@ -1028,7 +1028,7 @@ export class RdDActor extends Actor { }); await this.update({ [`system.experiencelog`]: expLog }); } - + async deleteExperienceLog(from, count) { if (from >= 0 && count > 0) { let expLog = duplicate(this.system.experiencelog); @@ -1144,7 +1144,7 @@ export class RdDActor extends Actor { onEnleverDeConteneur(); } } - + /* -------------------------------------------- */ /** Ajoute un item dans un conteneur, sur la base * de leurs ID */ @@ -1158,7 +1158,7 @@ export class RdDActor extends Actor { await this.updateEmbeddedDocuments('Item', [{ _id: conteneur.id, 'system.contenu': [...conteneur.system.contenu, item.id] - }]); + }]); onAjouterDansConteneur(item.id, conteneur.id); } } @@ -1374,8 +1374,8 @@ export class RdDActor extends Actor { async computeMalusArmure() { if (this.isPersonnage()) { const malusArmure = this.filterItems(it => it.type == 'armure' && it.system.equipe) - .map(it => it.system.malus ?? 0) - .reduce(Misc.sum(), 0); + .map(it => it.system.malus ?? 0) + .reduce(Misc.sum(), 0); // Mise à jour éventuelle du malus armure if (this.system.attributs?.malusarmure?.value != malusArmure) { await this.updateAttributeValue("malusarmure", malusArmure); @@ -1460,7 +1460,7 @@ export class RdDActor extends Actor { }); } } - + /* -------------------------------------------- */ async ajouterRefoulement(value = 1, refouler) { const refoulement = this.system.reve.refoulement.value + value; @@ -1568,7 +1568,7 @@ export class RdDActor extends Actor { async deleteTMRRencontreAtPosition() { const demiReve = this.getDemiReve() let rencontreIds = this.items.filter(it => it.type == 'rencontre' && it.system.coord == demiReve).map(it => it.id); - if (rencontreIds.length>0) { + if (rencontreIds.length > 0) { await this.deleteEmbeddedDocuments('Item', rencontreIds); } } @@ -1576,7 +1576,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async addTMRRencontre(currentRencontre) { const toCreate = currentRencontre.toObject(); - console.log('actor.addTMRRencontre(', toCreate,')'); + console.log('actor.addTMRRencontre(', toCreate, ')'); this.createEmbeddedDocuments('Item', [toCreate]); } @@ -1805,7 +1805,7 @@ export class RdDActor extends Actor { } return result; } - + async vehicleIncDec(name, inc) { if (!this.isVehicule() || !['resistance', 'structure'].includes(name)) { return @@ -1813,7 +1813,7 @@ export class RdDActor extends Actor { const value = this.system.etat[name].value; const max = this.system.etat[name].max; const newValue = value + inc; - if (0 <= newValue && newValue <=max) { + if (0 <= newValue && newValue <= max) { await this.update({ [`system.etat.${name}.value`]: newValue }) } } @@ -1965,9 +1965,9 @@ export class RdDActor extends Actor { } } - async actionNourritureboisson(item, onActionItem) { - const dialog = await DialogConsommer.create(this, item, onActionItem); - dialog.render(true); + + async mangerNourriture(item, onActionItem) { + return (await DialogConsommer.create(this, item, onActionItem)).render(true); } async actionLire(item) { @@ -1988,14 +1988,14 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false}, userId = undefined) { + async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }, userId = undefined) { if (userId != undefined && userId != game.user.id) { RdDActor.remoteActorCall({ actorId: this.id, method: 'consommerNourritureboisson', args: [itemId, choix, userId] }, - userId) + userId) return; } const item = this.getObjet(itemId) @@ -2297,9 +2297,9 @@ export class RdDActor extends Actor { if (xpData) { const content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-gain-xp.html`, xpData); if (hideChatMessage) { - ChatUtility.blindMessageToGM({ content: content}); + ChatUtility.blindMessageToGM({ content: content }); } - else{ + else { ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name), content: content @@ -2583,7 +2583,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async rollCompetence(idOrName, options = {tryTarget: true}) { + async rollCompetence(idOrName, options = { tryTarget: true }) { let rollData = { carac: this.system.carac, competence: this.getCompetence(idOrName) @@ -2591,14 +2591,14 @@ export class RdDActor extends Actor { if (rollData.competence.type == 'competencecreature') { if (rollData.competence.system.iscombat && options.tryTarget && Targets.hasTargets()) { Targets.selectOneToken(target => { - if (rollData.competence.system.ispossession) { - RdDPossession.onAttaquePossession(target, this, rollData.competence) - } - else { - const arme = RdDItemCompetenceCreature.armeNaturelle(rollData.competence) - RdDCombat.rddCombatTarget(target, this).attaque(competence, arme) - } - }); + if (rollData.competence.system.ispossession) { + RdDPossession.onAttaquePossession(target, this, rollData.competence) + } + else { + const arme = RdDItemCompetenceCreature.armeNaturelle(rollData.competence) + RdDCombat.rddCombatTarget(target, this).attaque(competence, arme) + } + }); return; } // Transformer la competence de créature @@ -2705,12 +2705,13 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) { + oeuvre.system.niveau = oeuvre.system.niveau ?? 0; mergeObject(artData, { oeuvre: oeuvre, art: oeuvre.type, competence: duplicate(this.getCompetence(artData.compName ?? oeuvre.system.competence ?? artData.art)), - diffLibre: - (oeuvre.system.niveau ?? 0), + diffLibre: - oeuvre.system.niveau, diffConditions: 0, use: { libre: false, conditions: true, surenc: false }, selectedCarac: duplicate(this.system.carac[selected]) @@ -2803,13 +2804,13 @@ export class RdDActor extends Actor { type: 'nourritureboisson', img: 'systems/foundryvtt-reve-de-dragon/icons/objets/provision_cuite.webp', system: { - "description": artData.oeuvre.system.description, - "sust": Math.min(sust, 1), - "qualite": artData.qualiteFinale, - "exotisme": artData.exotismeFinal, - "encombrement": 0.1, - "quantite": Math.max(1, Math.floor(sust)), - "cout": Math.max(artData.qualiteFinale) * 0.01 + description: cuisine.oeuvre.system.description, + sust: 1, + qualite: cuisine.qualiteFinale, + exotisme: cuisine.exotismeFinal, + encombrement: 0.1, + quantite: Math.max(1, Math.floor(cuisine.sust)), + cout: Math.max(cuisine.qualiteFinale, 0) * 0.01 } }; if (artData.ajouterEquipement) { @@ -3169,7 +3170,7 @@ export class RdDActor extends Actor { const caracList = Object.entries(carac); let entry = Misc.findFirstLike(name, caracList, { mapper: it => it[0], description: 'caractéristique' }); - if (!entry || entry.length ==0) { + if (!entry || entry.length == 0) { entry = Misc.findFirstLike(name, caracList, { mapper: it => it[1].label, description: 'caractéristique' }); } return entry && entry.length > 0 ? carac[entry[0]] : undefined; @@ -3205,7 +3206,7 @@ export class RdDActor extends Actor { ui.notifications.warn("Vous êtes déja dans les TMR...."); return } - if (mode != 'visu' && this.getEffect(STATUSES.StatusDemiReve)) { + if (mode != 'visu' && this.getEffect(STATUSES.StatusDemiReve)) { ui.notifications.warn("Le joueur ou le MJ est déja dans les Terres Médianes avec ce personnage ! Visualisation uniquement"); mode = "visu"; // bascule le mode en visu automatiquement } @@ -3263,18 +3264,18 @@ export class RdDActor extends Actor { title: 'Ne pas utiliser les automatisation de combat', buttonLabel: "Pas d'automatisation", onAction: async () => { - this.rollCompetence(arme.system.competence, {tryTarget: false}) + this.rollCompetence(arme.system.competence, { tryTarget: false }) } }); return; } Targets.selectOneToken(target => { - if (Targets.isTargetEntite(target)){ + if (Targets.isTargetEntite(target)) { ui.notifications.warn(`Vous ne pouvez pas attaquer une entité non incarnée avec votre ${arme.name}!!!!`); return; } - - + + const competence = this.getCompetence(arme.system.competence) if (competence.system.ispossession) { return RdDPossession.onAttaquePossession(target, this, competence); @@ -3393,12 +3394,12 @@ export class RdDActor extends Actor { async validerEncaissement(rollData, show) { if (ReglesOptionelles.isUsing('validation-encaissement-gr') && !game.user.isGM) { - RdDActor.remoteActorCall({ - actorId: this.id, - method: 'validerEncaissement', - args: [rollData, show] - }); - return; + RdDActor.remoteActorCall({ + actorId: this.id, + method: 'validerEncaissement', + args: [rollData, show] + }); + return; } const armure = await this.computeArmure(rollData); if (ReglesOptionelles.isUsing('validation-encaissement-gr')) { @@ -3878,7 +3879,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ addSubActeur(subActor) { - if(subActor?.id == this.id){ + if (subActor?.id == this.id) { ui.notifications.warn("Vous ne pouvez pas attacher un acteur à lui même") } else if (!subActor?.isOwner) { @@ -4105,10 +4106,10 @@ export class RdDActor extends Actor { } console.log("setEffect", statusId, status) const effect = this.getEffect(statusId); - if (!status && effect){ + if (!status && effect) { await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]); } - if (status && !effect ) { + if (status && !effect) { await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.status(statusId)]); } } @@ -4134,7 +4135,6 @@ export class RdDActor extends Actor { await this.checkCompetenceXP(item.name, item.system.xp); } } - /* -------------------------------------------- */ async onCreateItem(item, options, id) { switch (item.type) { diff --git a/module/dialog-item-consommer.js b/module/dialog-item-consommer.js index 81ef25d9..d74a704c 100644 --- a/module/dialog-item-consommer.js +++ b/module/dialog-item-consommer.js @@ -2,13 +2,13 @@ import { Misc } from "./misc.js"; export class DialogConsommer extends Dialog { - static async create(actor, item, onActionItem = async ()=>{}) { + static async create(actor, item, onActionItem = async () => { }) { const consommerData = DialogConsommer.prepareData(actor, item); const html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-item-consommer.html', consommerData); return new DialogConsommer(actor, item, consommerData, html, onActionItem) } - constructor(actor, item, consommerData, html, onActionItem = async ()=>{}) { + constructor(actor, item, consommerData, html, onActionItem = async () => { }) { const options = { classes: ["dialogconsommer"], width: 350, height: 'fit-content', 'z-index': 99999 }; let conf = { title: consommerData.title, @@ -18,7 +18,8 @@ export class DialogConsommer extends Dialog { [consommerData.buttonName]: { label: consommerData.buttonName, callback: async it => { await this.onConsommer(it); - await onActionItem();} + await onActionItem(); + } } } }; @@ -38,9 +39,8 @@ export class DialogConsommer extends Dialog { /* -------------------------------------------- */ static prepareData(actor, item) { - item = duplicate(item); let consommerData = { - item: item, + item: duplicate(item), cuisine: actor.getCompetence('cuisine'), choix: { doses: 1, diff --git a/module/item-competence.js b/module/item-competence.js index e5fbfab9..13b7de41 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -281,4 +281,36 @@ export class RdDItemCompetence extends Item { return duplicate(limitesArchetypes); } + static triVisible(competences) { + return competences.filter(it => it.system.isVisible) + .sort((a, b) => RdDItemCompetence.compare(a,b)) + } + + static $positionTri(comp) { + if (comp.name.startsWith("Survie")) { + if (comp.name.includes("Cité")) return 0; + if (comp.name.includes("Extérieur")) return 1; + return 2; + } + if (comp.system.categorie.startsWith("melee")) { + if (comp.name.includes("Corps")) return 0; + if (comp.name.includes("Dague")) return 1; + if (comp.name.includes("Esquive")) return 2; + return 3; + } + if (comp.system.categorie.startsWith("draconic")) { + if (comp.name.includes("Oniros")) return 0; + if (comp.name.includes("Hypnos")) return 1; + if (comp.name.includes("Narcos")) return 2; + if (comp.name.includes("Thanatos")) return 3; + return 4; + } + return 0; + } + + static compare(a,b) { + const diff = RdDItemCompetence.$positionTri(a) - RdDItemCompetence.$positionTri(b); + return diff ? diff : a.name.localeCompare(b.name); + } + } \ No newline at end of file diff --git a/module/item-sheet.js b/module/item-sheet.js index 2e6c91c2..b08d6a8d 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -166,7 +166,6 @@ export class RdDItemSheet extends ItemSheet { this.form.ondragstart = (event) => this._onDragStart(event); this.form.ondrop = (event) => this._onDrop(event); - // Select competence categorie html.find(".categorie").change(event => this._onSelectCategorie(event)); @@ -182,60 +181,37 @@ export class RdDItemSheet extends ItemSheet { this.dateUpdated = game.system.rdd.calendrier.getIndexFromDate(jour, mois); }); - html.find('.creer-tache-livre').click((event) => { - let actorId = event.currentTarget.attributes['data-actor-id'].value; - let actor = game.actors.get(actorId); - actor.creerTacheDepuisLivre(this.item); - }); - html.find('.consommer-potion').click((event) => { - let actorId = event.currentTarget.attributes['data-actor-id'].value; - let actor = game.actors.get(actorId); - actor.consommerPotion(this.item); - }); - html.find('.creer-potion-base').click((event) => { - let actorId = event.currentTarget.attributes['data-actor-id'].value; - let actor = game.actors.get(actorId); - actor.dialogFabriquerPotion(this.item); - }); + html.find('.creer-tache-livre').click((event) => this._getEventActor(event).creerTacheDepuisLivre(this.item)); + html.find('.consommer-potion').click((event) => this._getEventActor(event).consommerPotion(this.item)); + html.find('.creer-potion-base').click((event) => this._getEventActor(event).dialogFabriquerPotion(this.item)); html.find('.alchimie-tache a').click((event) => { - let actorId = event.currentTarget.attributes['data-actor-id'].value; - let recetteId = event.currentTarget.attributes['data-recette-id'].value; - let tacheName = event.currentTarget.attributes['data-alchimie-tache'].value; - let tacheData = event.currentTarget.attributes['data-alchimie-data'].value; - let actor = game.actors.get(actorId); + let actor = this._getEventActor(event); if (actor) { + let recetteId = event.currentTarget.attributes['data-recette-id'].value; + let tacheName = event.currentTarget.attributes['data-alchimie-tache'].value; + let tacheData = event.currentTarget.attributes['data-alchimie-data'].value; actor.effectuerTacheAlchimie(recetteId, tacheName, tacheData); } else { ui.notifications.info("Impossible trouver un acteur pour réaliser cette tache Alchimique."); } }); - html.find('.item-split').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - await RdDSheetUtility.splitItem(item, this.actor, async () => itemSheetDialog.render(true)); - }); - html.find('.item-edit').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item.sheet.render(true); - }); - html.find('.item-delete').click(async event => { - const li = RdDSheetUtility.getEventElement(event); - const item = this.actor.getObjet(li.data("item-id")); - RdDUtility.confirmerSuppressionItem(this, item, li); - }); - html.find('.item-vendre').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item?.proposerVente(); - }); - html.find('.item-montrer').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item?.postItem(); - }); html.find('.item-action').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); this.actor.actionItem(item, async () => itemSheetDialog.render(true)); }); + html.find('.item-split').click(async event => RdDSheetUtility.splitItem(RdDSheetUtility.getItem(event, this.actor), this.actor, async () => itemSheetDialog.render(true))); + html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)); + html.find('.item-delete').click(async event => RdDUtility.confirmerSuppressionItem(this, RdDSheetUtility.getItem(event, this.actor))); + html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); + html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem()); + } + + _getEventActor(event) { + let actorId = event.currentTarget.attributes['data-actor-id'].value; + let actor = game.actors.get(actorId); + return actor; } /* -------------------------------------------- */ diff --git a/module/item.js b/module/item.js index 6182bd0f..650540b9 100644 --- a/module/item.js +++ b/module/item.js @@ -287,7 +287,6 @@ export class RdDItem extends Item { if (!other || !this.isInventaire()) { return [false, undefined]; } - if (this.system.quantite == undefined) { return [false, `Impossible de regrouper des ${this.type}, ils ne sont pas empilables`]; } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 0b7f21d3..8625e267 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -279,6 +279,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html' ]; + Handlebars.registerHelper('either', (a, b) => a ?? b); Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null')); Handlebars.registerHelper('lowerFirst', str => Misc.lowerFirst(str ?? 'Null')); Handlebars.registerHelper('upper', str => str?.toUpperCase() ?? 'NULL'); @@ -296,46 +297,18 @@ export class RdDUtility { Handlebars.registerHelper('min', (...args) => Math.min(...args.slice(0, -1))); Handlebars.registerHelper('regle-optionnelle', (option) => ReglesOptionelles.isUsing(option)); Handlebars.registerHelper('trier', list => list.sort((a, b) => a.name.localeCompare(b.name))); - Handlebars.registerHelper('filtreTriCompetences', competences => competences.filter(it => it.system.isVisible) - .sort((a, b) => { - if (a.name.startsWith("Survie") && b.name.startsWith("Survie")) { - if (a.name.includes("Cité")) return -1; - if (b.name.includes("Cité")) return 1; - if (a.name.includes("Extérieur")) return -1; - if (b.name.includes("Extérieur")) return 1; - return a.name.localeCompare(b.name); - } - if (a.system.categorie.startsWith("melee") && b.system.categorie.startsWith("melee")) { - if (a.name.includes("Corps")) return -1; - if (b.name.includes("Corps")) return 1; - if (a.name.includes("Dague")) return -1; - if (b.name.includes("Dague")) return 1; - if (a.name.includes("Esquive")) return -1; - if (b.name.includes("Esquive")) return 1; - return a.name.localeCompare(b.name); - } - if (a.name.startsWith("Voie") && b.name.startsWith("Voie")) { - if (a.name.includes("Oniros")) return -1; - if (b.name.includes("Oniros")) return 1; - if (a.name.includes("Hypnos")) return -1; - if (b.name.includes("Hypnos")) return 1; - if (a.name.includes("Narcos")) return -1; - if (b.name.includes("Narcos")) return 1; - if (a.name.includes("Thanatos")) return -1; - if (b.name.includes("Thanatos")) return 1; - return a.name.localeCompare(b.name); - } - return a.name.localeCompare(b.name); - }) - ); - Handlebars.registerHelper('linkCompendium', (pack, id, name)=> RdDUtility.linkCompendium(pack, id, name)); - Handlebars.registerHelper('uniteQuantite', (type) => RdDItem.getUniteQuantite(type)); + Handlebars.registerHelper('filtreTriCompetences', competences => RdDItemCompetence.triVisible(competences)); + Handlebars.registerHelper('linkCompendium', (pack, id, name) => RdDUtility.linkCompendium(pack, id, name)); + Handlebars.registerHelper('uniteQuantite', (itemId, actorId) => RdDUtility.getItem(itemId, actorId)?.getUniteQuantite()); Handlebars.registerHelper('isFieldInventaireModifiable', (type, field) => RdDItem.isFieldInventaireModifiable(type, field)); Handlebars.registerHelper('getFrequenceRarete', (rarete, field) => Environnement.getFrequenceRarete(rarete, field)); - Handlebars.registerHelper('either', (a, b) => a ?? b); return loadTemplates(templatePaths); } + static getItem(itemId, actorId = undefined) { + return actorId ? game.actors.get(actorId)?.getObjet(itemId) : game.items.get(itemId); + } + static linkCompendium(pack, id, name) { return `@Compendium[${pack}.${id}]{${name}}`; } @@ -1001,7 +974,7 @@ export class RdDUtility { } static slideOnDelete(sheet, htmlToDelete) { - return htmlToDelete.slideUp(200, () => sheet.render(false)); + return htmlToDelete?.slideUp(200, () => sheet.render(false)); } /* -------------------------------------------- */ diff --git a/templates/actor/dragon-queue.html b/templates/actor/dragon-queue.html index 057dc09e..889a752e 100644 --- a/templates/actor/dragon-queue.html +++ b/templates/actor/dragon-queue.html @@ -1,6 +1,6 @@
  • - + {{#if (eq queue.type 'ombre')}} {{/if}} diff --git a/templates/actor/dragon-souffles.html b/templates/actor/dragon-souffles.html index aa28abab..4671b429 100644 --- a/templates/actor/dragon-souffles.html +++ b/templates/actor/dragon-souffles.html @@ -4,7 +4,7 @@ {{#each souffles as |souffle key|}}
  • - {{souffle.name}} + {{souffle.name}}
    diff --git a/templates/actor/dragon-tetes.html b/templates/actor/dragon-tetes.html index fc65ed54..28785008 100644 --- a/templates/actor/dragon-tetes.html +++ b/templates/actor/dragon-tetes.html @@ -4,7 +4,7 @@ {{#each tetes as |tete key|}}
  • - {{tete.name}} + {{tete.name}}
    diff --git a/templates/actor/hr-casestmr.html b/templates/actor/hr-casestmr.html index 1c1f3fd8..0ec1decf 100644 --- a/templates/actor/hr-casestmr.html +++ b/templates/actor/hr-casestmr.html @@ -4,7 +4,7 @@ {{#each casestmr as |casetmr key|}}
  • - {{casetmr.name}} + {{casetmr.name}} {{casetmr.system.coord}} - {{caseTmr-label casetmr.system.coord}}
    diff --git a/templates/actor/hr-rencontres.html b/templates/actor/hr-rencontres.html index 7d9a2a7e..bdd432ff 100644 --- a/templates/actor/hr-rencontres.html +++ b/templates/actor/hr-rencontres.html @@ -4,7 +4,7 @@ {{#each rencontres as |rencontre key|}}
  • - + {{rencontre.name}} r{{rencontre.system.force}} ({{rencontre.system.coord}} - {{caseTmr-label rencontre.system.coord}}) {{#if rencontre.system.date}} diff --git a/templates/actor/hr-signes-draconiques.html b/templates/actor/hr-signes-draconiques.html index 1edb8f1c..4a45ad21 100644 --- a/templates/actor/hr-signes-draconiques.html +++ b/templates/actor/hr-signes-draconiques.html @@ -4,7 +4,7 @@ {{#each signesdraconiques as |signe key|}}
  • - {{signe.name}} + {{signe.name}} {{signe.system.difficulte}}
    diff --git a/templates/actor/hr-sorts-reserve.html b/templates/actor/hr-sorts-reserve.html index 3214bceb..8976e6ff 100644 --- a/templates/actor/hr-sorts-reserve.html +++ b/templates/actor/hr-sorts-reserve.html @@ -4,7 +4,7 @@ {{#each sortsReserve as |sort key|}}
  • - {{#if sort.system.echectotal}}Echec total: {{/if}}{{sort.name}} r{{sort.system.ptreve}} + {{#if sort.system.echectotal}}Echec total: {{/if}}{{sort.name}} r{{sort.system.ptreve}} {{sort.system.coord}} - {{caseTmr-label sort.system.coord}}
    diff --git a/templates/actor/hr-sorts.html b/templates/actor/hr-sorts.html index 09d92cff..80c20740 100644 --- a/templates/actor/hr-sorts.html +++ b/templates/actor/hr-sorts.html @@ -4,7 +4,7 @@ {{#each sorts as |sort key|}}
  • - + {{sort.name}} - {{#if sort.system.caseTMRspeciale}}{{sort.system.caseTMRspeciale}}{{else}}{{upperFirst sort.system.caseTMR}}{{/if}}