diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 19526161..b823162a 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -15,6 +15,7 @@ import { DialogSplitItem } from "./dialog-split-item.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; import { DialogRepos } from "./dialog-repos.js"; import { RdDSheetUtility } from "./rdd-sheet-utility.js"; +import { TMRUtility } from "./tmr-utility.js"; /* -------------------------------------------- */ export class RdDActorSheet extends ActorSheet { @@ -180,7 +181,21 @@ export class RdDActorSheet extends ActorSheet { }); html.find('.item-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); - RdDUtility.confirmerSuppression(this, li); + const item = this.actor.getObjet(li.data("item-id")); + RdDUtility.confirmerSuppressionItem(this, item, li); + }); + html.find('.sort-reserve-delete').click(async event => { + const li = RdDSheetUtility.getEventElement(event); + const index = li.data('index'); + const sortReserve = this.actor.system.reve.reserve.list[index]; + RdDUtility.confirmerSuppression(this, li, { + supprimer: `le sort en réserve ${sortReserve.sort.name} en ${TMRUtility.getTMR(sortReserve.coord).label}`, + deleteLabel: "Supprimer le sort en réserve", + onDelete: () => { + console.log("Delete : ", sortReserve.name); + this.actor.deleteSortReserveKey(index); + } + }); }); html.find('.item-vendre').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); @@ -197,7 +212,11 @@ export class RdDActorSheet extends ActorSheet { }); html.find('.subacteur-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); - RdDUtility.confirmerSuppressionSubacteur(this, li); + const actorId = li.data("actor-id"); + if (actorId) { + const subActor = game.actors.get(actorId); + RdDUtility.confirmerSuppressionSubacteur(this, subActor, li); + } }); html.find('.encaisser-direct').click(async event => { diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 56ab0aee..7d0691af 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -104,7 +104,8 @@ export class RdDActorVehiculeSheet extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); - RdDUtility.confirmerSuppression(this, li); + 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); diff --git a/module/actor.js b/module/actor.js index b4bfe9c4..ee9307a8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -432,6 +432,14 @@ export class RdDActor extends Actor { } } + async deleteSortReserveKey(index) { + let reserve = duplicate(this.system.reve.reserve); + if (index >= 0) { + reserve.list.splice(index, 1); + await this.update({ "system.reve.reserve": reserve }, { renderSheet: false }); + } + } + /* -------------------------------------------- */ getSurprise(isCombat = undefined) { let niveauSurprise = this.getActiveEffects() @@ -1424,6 +1432,15 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + async actionRefoulement(item) { + const refoulement = item?.system.refoulement ?? 0; + if (refoulement>0){ + await this.ajouterRefoulement(refoulement); + await item.delete(); + } + } + /* -------------------------------------------- */ async ajouterRefoulement(value = 1) { let refoulement = this.system.reve.refoulement.value + value; @@ -1924,6 +1941,7 @@ export class RdDActor extends Actor { } return; } + case 'queue': case 'ombre': return await this.actionRefoulement(item); } } @@ -3916,9 +3934,9 @@ export class RdDActor extends Actor { let newVehicules = this.system.subacteurs.vehicules.filter(function (obj, index, arr) { return obj.id != actorId }); let newSuivants = this.system.subacteurs.suivants.filter(function (obj, index, arr) { return obj.id != actorId }); let newMontures = this.system.subacteurs.montures.filter(function (obj, index, arr) { return obj.id != actorId }); - await this.update({ 'system.subacteurs.vehicules': newVehicules }); - await this.update({ 'system.subacteurs.suivants': newSuivants }); - await this.update({ 'system.subacteurs.montures': newMontures }); + await this.update({ 'system.subacteurs.vehicules': newVehicules }, { renderSheet: false }); + await this.update({ 'system.subacteurs.suivants': newSuivants }, { renderSheet: false }); + await this.update({ 'system.subacteurs.montures': newMontures }, { renderSheet: false }); } /* -------------------------------------------- */ diff --git a/module/item-sheet.js b/module/item-sheet.js index ea1804be..933b4642 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -197,7 +197,8 @@ export class RdDItemSheet extends ItemSheet { }); html.find('.item-delete').click(async event => { const li = RdDSheetUtility.getEventElement(event); - RdDUtility.confirmerSuppression(this, li); + 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); diff --git a/module/item.js b/module/item.js index f83cf913..7f9003d8 100644 --- a/module/item.js +++ b/module/item.js @@ -145,24 +145,28 @@ export class RdDItem extends Item { } getActionPrincipale(options = { warnIfNot: true }) { - if (!this.isConteneur() && (this.system.quantite ?? 0) <= 0) { - if (options.warnIfNot) { + const warn = options.warnIfNot; + switch (this.type) { + case 'nourritureboisson': return this._actionOrWarnQuantiteZero(this.boisson ? 'Boire' : 'Manger', warn); + case 'potion': return this._actionOrWarnQuantiteZero('Boire', warn); + case 'livre': return this._actionOrWarnQuantiteZero('Lire', warn); + case 'conteneur': return this._actionOrWarnQuantiteZero('Ouvrir', warn); + case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined; + case 'queue': case 'ombre': return this.system.refoulement>0 ? 'Refouler' : undefined; + } + return undefined; + } + + _actionOrWarnQuantiteZero(actionName, warn){ + if ((this.system.quantite ?? 0) <= 0) { + if (warn) { ui.notifications.warn(`Vous n'avez plus de ${this.name}.`); } return undefined; } - switch (this.type) { - case 'nourritureboisson': return this.boisson ? 'Boire' : 'Manger'; - case 'potion': return 'Boire'; - case 'livre': return 'Lire'; - case 'conteneur': return 'Ouvrir'; + else { + return actionName; } - if (this.isHerbeAPotion()) { return 'Décoction'; } - if (options.warnIfNot) { - ui.notifications.warn(`Impossible d'utiliser un ${this.name}, aucune action associée définie.`); - } - - return undefined; } async diminuerQuantite(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 04bcb0c9..ae808838 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -121,8 +121,10 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-liste-blessures-partial.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-blessure-partial.html', + 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-queues.html', // Conteneur/item in Actor sheet 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire.html', + 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-item-queue.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-item.html', "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-monnaie.html", 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-liens-animaux.html', @@ -829,21 +831,17 @@ export class RdDUtility { } /* -------------------------------------------- */ - static confirmerSuppressionSubacteur(actorSheet, li) { - let actorId = li.data("actor-id"); - let actor = game.actors.get(actorId); - let msgTxt = "

Etes vous certain de vouloir supprimer le lien vers ce véhicule/monture/suivant : " + actor.name + " ?

"; - let d = new Dialog({ - title: "Confirmer la suppression du lien", - content: msgTxt, + static confirmerSuppression(sheet, htmlToDelete, options) { + const d = new Dialog({ + title: options.title ?? 'Confirmer la suppression', + content: `

Etes vous certain de vouloir supprimer ${options.supprimer ?? 'cet objet'} ?

`, buttons: { delete: { icon: '', - label: "Supprimer le lien", + label: options.deleteLabel ?? 'Supprimer', callback: () => { - console.log("Delete : ", actorId); - actorSheet.actor.removeSubacteur(actorId); - li.slideUp(200, () => actorSheet.render(false)); + options.onDelete(); + RdDUtility.slideOnDelete(sheet, htmlToDelete); } }, cancel: { @@ -857,11 +855,21 @@ export class RdDUtility { } /* -------------------------------------------- */ - static async confirmerSuppression(actorSheet, li) { - let itemId = li.data("item-id"); - let objet = actorSheet.actor.getObjet(itemId); + static confirmerSuppressionSubacteur(sheet, subActor, htmlToDelete) { + RdDUtility.confirmerSuppression(sheet, htmlToDelete,{ + supprimer: "le lien vers le véhicule/monture/suivant : " + subActor.name, + deleteLabel: "Supprimer le lien", + onDelete: () => { + console.log("Delete : ", subActor.id); + sheet.actor.removeSubacteur(subActor.id); + } + }) + } - if (Monnaie.isSystemMonnaie(objet, actorSheet.actor.items)) { + /* -------------------------------------------- */ + static async confirmerSuppressionItem(sheet, item, htmlToDelete) { + const itemId = item.id; + if (Monnaie.isSystemMonnaie(item, sheet.actor.items)) { ui.notifications.warn("Suppression des monnaies de base impossible"); return; } @@ -873,8 +881,8 @@ export class RdDUtility { label: "Supprimer l'objet", callback: () => { console.log("Delete : ", itemId); - actorSheet.actor.deleteEmbeddedDocuments('Item', [itemId]); - li.slideUp(200, () => actorSheet.render(false)); + sheet.actor.deleteEmbeddedDocuments('Item', [itemId]); + RdDUtility.slideOnDelete(sheet, htmlToDelete); } }, cancel: { @@ -882,15 +890,15 @@ export class RdDUtility { label: "Annuler" } } - if (objet.type == 'conteneur' && objet.system.contenu.length > 0) { + if (item.type == 'conteneur' && item.system.contenu.length > 0) { msgTxt += "
Ce conteneur n'est pas vide. Choisissez l'option de suppression"; buttons['deleteall'] = { icon: '', label: "Supprimer le conteneur et tout son contenu", callback: () => { console.log("Delete : ", itemId); - actorSheet.actor.deleteAllConteneur(itemId); - li.slideUp(200, () => actorSheet.render(false)); + sheet.actor.deleteAllConteneur(itemId); + RdDUtility.slideOnDelete(sheet, htmlToDelete); } } } @@ -904,6 +912,10 @@ export class RdDUtility { d.render(true); } + static slideOnDelete(sheet, htmlToDelete) { + return htmlToDelete.slideUp(200, () => sheet.render(false)); + } + /* -------------------------------------------- */ static afficherHeuresChanceMalchance(heureNaissance) { if (game.user.isGM) { diff --git a/templates/actor-sheet-item-queue.html b/templates/actor-sheet-item-queue.html new file mode 100644 index 00000000..bd4fdf74 --- /dev/null +++ b/templates/actor-sheet-item-queue.html @@ -0,0 +1,9 @@ +
  • + {{queue.name}} +
    + + {{#if queue.system.refoulement}} + Refouler + {{/if}} +
    +
  • diff --git a/templates/actor-sheet-queues.html b/templates/actor-sheet-queues.html new file mode 100644 index 00000000..a91a3388 --- /dev/null +++ b/templates/actor-sheet-queues.html @@ -0,0 +1,15 @@ +{{#if (or queues.length ombres.length)}} +

    + {{#if queues.length}}Queues de Dragon{{/if}} + {{#if (and queues.length ombres.length)}} et {{/if}} + {{#if ombres.length}}Ombres de Thanatos{{/if}} + :

    + +{{/if}} diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 1b060de6..5592aae4 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -510,32 +510,7 @@
    {{!-- Queues, Souffles, Tetes, Ombre --}} - {{#if queues.length}} -

    Queues:

    - - {{/if}} - {{#if ombres.length}} -

    Ombres de Thanatos:

    - - {{/if}} + {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-queues.html"}} {{#if souffles.length}}

    Souffles: