Amélioration du split
Bouton split géré avec itemActions Ajout d'un bouton pour augmenter les piles (pour le MJ)
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user