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:
Vincent Vandemeulebrouck 2025-01-19 17:56:55 +01:00
parent 8969d5e0ed
commit 6083dd41fa
8 changed files with 39 additions and 38 deletions

View File

@ -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));

View File

@ -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) })

View File

@ -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)
}

View File

@ -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,

View File

@ -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)
}

View File

@ -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;

View File

@ -25,8 +25,8 @@
<a class="item-quantite-moins" data-tooltip="Diminuer la quantité de {{item.name}}"><i class="fa-solid fa-square-minus"></i></a>
{{/if}}
{{item.system.quantite}}
{{#if (gt item.system.quantite 1)}}
<a class="item-split" data-tooltip="Séparer le groupe de {{item.name}}"><i class="fas fa-unlink"></i></a>
{{#if @root.options.isGM}}
<a class="item-quantite-plus" data-tooltip="Augmenter la quantité de {{item.name}}"><i class="fa-solid fa-square-plus"></i></a>
{{/if}}
</span>
<span class="equipement-detail">{{numberFormat item.system.encTotal decimals=2}}</span>

View File

@ -18,7 +18,7 @@
<ul class="item-list alterne-list">
<li class="competence-header flexrow">
<span class="equipement-nom">Nom</span>
<span class="equipement-detail">Q.</span>
<span class="equipement-detail-buttons">Q.</span>
<span class="equipement-detail">Enc.</span>
<span class="equipement-actions">Actions</span>
</li>