diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index b7a2be14..309e538f 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -108,7 +108,6 @@ export class RdDBaseActorSheet extends ActorSheet { this.html.find('.item-equip-armure').click(async event => this.actor.equiperObjet(this.getItem(event))) this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this.getItem(event), this.actor)); - this.html.find('.item-split').click(async event => RdDSheetUtility.splitItem(this.getItem(event), this.actor)) this.html.find('.item-quantite-plus').click(async event => this.actor.itemQuantiteIncDec(this.getItemId(event), 1)); this.html.find('.item-quantite-moins').click(async event => this.actor.itemQuantiteIncDec(this.getItemId(event), -1)); diff --git a/module/item-sheet.js b/module/item-sheet.js index 4cfb3985..fc953fcb 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -200,23 +200,19 @@ export class RdDItemSheet extends ItemSheet { this.html.find('.chat-roll-text').click(async event => await RdDTextEditor.chatRollText(event)) if (this.actor) { - // TODO this.html.find('.actionItem').click(event => ItemAction.onActionItem(event, this.actor, this.options)) - + + // TODO: utiliser un itemAction? this.html.find('.item-potion-consommer').click(event => this.itemActionConsommer(event)) - this.html.find('.item-split').click( event => this.itemActionSplit(event)) - this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)); - this.html.find('.item-delete').click(async event => this.itemActionDelete(event)); - this.html.find('.item-quantite-plus').click(async event => { await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), 1) - this.render(); - }); + this.render() + }) this.html.find('.item-quantite-moins').click(async event => { await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), -1) - this.render(); - }); + this.render() + }) } const updateItemTimestamp = (path, timestamp) => this.item.update({ [path]: foundry.utils.duplicate(timestamp) }) diff --git a/module/item/item-actions.js b/module/item/item-actions.js index 74e17268..a5085618 100644 --- a/module/item/item-actions.js +++ b/module/item/item-actions.js @@ -27,6 +27,12 @@ const _MONTRER = { code: 'item-montrer', label: 'Montrer', icon: it => 'fa-solid fa-comment', action: (item, actor) => item.postItemToChat() } +const _SPLIT = { + code: 'item-split', label: 'Séparer le goupe', icon: it => 'fa-solid fa-unlink', + filter: it => Misc.toInt(it.system.quantite) > 1, + action: (item, actor) => RdDSheetUtility.splitItem(item, actor) +} + const _EDIT = { code: 'item-edit', label: 'Editer', icon: it => 'fa-solid fa-edit', action: (item, actor) => item.sheet.render(true) @@ -89,19 +95,6 @@ const _REFOULER = { action: (item, actor) => actor.actionRefoulement(item) } -const _CONSOMMER_POTION = { - code: 'item-potion-consommer', label: 'Consommer', icon: it => 'fa-solid fa-vial', - optionsFilter: options => options.editable, - action: (item, actor) => actor.consommerPotion(item) -} - -const _ENCHANTER = { - code: 'item-enchanter', label: 'Enchanter', icon: it => 'fa-solid fa-sparkles', - filter: it => it.isEnchantable(), - optionsFilter: options => options.editable, - action: (item, actor) => item.enchanterPotion() -} - const _SORT_RESERVE = { code: 'item-sortreserve-add', label: 'Ajouter en réserve', icon: it => 'fa-solid fa-sparkles', filter: it => game.user.isGM && !it.system.isrituel, @@ -109,7 +102,7 @@ const _SORT_RESERVE = { } export const COMMON_ACTIONS = [_EQUIPER] -export const DEFAULT_ACTIONS = [_SPACEHOLDER, _VENDRE, _MONTRER, _EDIT, _DELETE] +export const DEFAULT_ACTIONS = [_SPACEHOLDER, _SPLIT, _VENDRE, _MONTRER, _EDIT, _DELETE] export const ITEM_ACTIONS = { faune: [_CUISINER, _MANGER_CRU], @@ -120,7 +113,6 @@ export const ITEM_ACTIONS = { nourritureboisson: [_MANGER, _BOIRE], ombre: [_REFOULER], plante: [_CUISINER, _MANGER_CRU], - potion: [_CONSOMMER_POTION, _ENCHANTER], queue: [_REFOULER], sort: [_SORT_RESERVE], service: [_ACHAT_SERVICE] @@ -130,7 +122,7 @@ export const ITEM_ACTIONS = { export class ItemAction { static applies(action, item, options) { - return action + return action && item && item.isActionAllowed(action.code) && (!action.filter || action.filter(item)) && (!action.optionsFilter || action.optionsFilter(options)) @@ -146,7 +138,7 @@ export class ItemAction { static onActionItem(event, actor, options) { const item = RdDSheetUtility.getItem(event, actor) const code = $(event.currentTarget).data('code') - const action = item.itemActions().find(it => it.code == code) + const action = item?.itemActions().find(it => it.code == code) if (action && (!action.optionsFilter || action.optionsFilter(options))) { action.action(item, actor) } diff --git a/module/item/potion.js b/module/item/potion.js index f0af84d4..d19a29f3 100644 --- a/module/item/potion.js +++ b/module/item/potion.js @@ -2,7 +2,6 @@ import { ITEM_TYPES } from "../constants.js"; import { Grammar } from "../grammar.js"; import { RdDItem } from "../item.js"; import { SystemCompendiums } from "../settings/system-compendiums.js"; -import { ITEM_ACTIONS } from "./item-actions.js"; import { DialogEnchanter } from "./potion/dialog-enchanter.js"; const POTION_MAGIQUE = ['AlchimieEnchante', 'ReposEnchante', 'SoinEnchante', 'AutreEnchante'] @@ -15,6 +14,19 @@ const MAP_CATEGORIE_ENCHANTEMENT = [ { basique: 'Soin', enchante: 'SoinEnchante' }, { basique: 'Autre', enchante: 'AutreEnchante' }] +const _CONSOMMER_POTION = { + code: 'item-potion-consommer', label: 'Consommer', icon: it => 'fa-solid fa-vial', + optionsFilter: options => options.editable, + action: (item, actor) => actor.consommerPotion(item) +} + +const _ENCHANTER = { + code: 'item-enchanter', label: 'Enchanter', icon: it => 'fa-solid fa-sparkles', + filter: it => game.user.isGM || it.isEnchantable(), + optionsFilter: options => options.editable, + action: (item, actor) => item.enchanterPotion() +} + export class RdDItemPotion extends RdDItem { static async herbesSoins() { @@ -43,7 +55,7 @@ export class RdDItemPotion extends RdDItem { isMagique() { return POTION_MAGIQUE.includes(this.system.categorie) } itemSpecificActions() { - return ITEM_ACTIONS[ITEM_TYPES.potion] + return [_CONSOMMER_POTION, _ENCHANTER] } getActions(options = { warnIfNot: true }) { @@ -94,8 +106,6 @@ export class RdDItemPotion extends RdDItem { const nouveauReve = Math.max(this.system.pr - 1, 0) return { _id: this.id, - name: this.name, - img: this.img, 'system.pr': nouveauReve, 'system.quantite': nouveauReve > 0 ? this.system.quantite : 0, 'system.magique': nouveauReve > 0 @@ -107,6 +117,7 @@ export class RdDItemPotion extends RdDItem { async $onEnchanterPotion(enchanter) { if (enchanter.nouveaupr == 0) { await this.update({ + name: this.name, // TODO: enlever "enchantée" ? 'system.pr': 0, 'system.purifie': false, 'system.magique': false, @@ -118,6 +129,7 @@ export class RdDItemPotion extends RdDItem { } else { await this.update({ + name: this.name, // TODO: ajout "enchantée" ? 'system.pr': enchanter.nouveaupr, 'system.purifie': enchanter.purifier, 'system.magique': true, diff --git a/module/rdd-sheet-utility.js b/module/rdd-sheet-utility.js index 8dbbf217..79b08cb6 100644 --- a/module/rdd-sheet-utility.js +++ b/module/rdd-sheet-utility.js @@ -66,10 +66,12 @@ export class RdDSheetUtility { } static async splitItem(item, actor, onSplit = () => { }) { - const dialog = await DialogSplitItem.create(item, async (item, split) => { + const _onSplit = async (item, split) => { await RdDSheetUtility._onSplitItem(item, split, actor); onSplit(); - }); + await RdDSheetUtility.renderItemBranch(actor, item) + } + const dialog = await DialogSplitItem.create(item, _onSplit) dialog.render(true) } diff --git a/styles/simple.css b/styles/simple.css index 38d4d89d..602cc813 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -467,7 +467,7 @@ table {border: 1px solid #7a7971;} text-align: left; } .equipement-nom { - flex-grow : 4; + flex-grow : 3; margin: 0; justify-content: center; text-align: left; diff --git a/templates/actor/inventaire-item.hbs b/templates/actor/inventaire-item.hbs index 26137e2d..e6a5bbc9 100644 --- a/templates/actor/inventaire-item.hbs +++ b/templates/actor/inventaire-item.hbs @@ -25,8 +25,8 @@ {{/if}} {{item.system.quantite}} - {{#if (gt item.system.quantite 1)}} - + {{#if @root.options.isGM}} + {{/if}} {{numberFormat item.system.encTotal decimals=2}} diff --git a/templates/actor/inventaire.html b/templates/actor/inventaire.html index feacdd3b..938738e6 100644 --- a/templates/actor/inventaire.html +++ b/templates/actor/inventaire.html @@ -18,7 +18,7 @@