Corrected back to actions for right items

This commit is contained in:
WBHarry 2025-07-05 21:34:15 +02:00
parent 3d735e6a09
commit eb96e8b813
17 changed files with 148 additions and 58 deletions

View file

@ -1478,7 +1478,7 @@
"Features": "Features",
"Effects": "Effects",
"activeEffects": "Active Effects",
"inativeEffects": "Inative Effects"
"inactiveEffects": "Inactive Effects"
},
"DomainCard": {
"Type": "Type",

View file

@ -307,9 +307,13 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
getItem(element) {
const listElement = (element.target ?? element).closest('[data-item-id]');
const itemId = listElement.dataset.itemId;
return listElement.dataset.type === 'effect'
? this.document.effects.get(itemId)
: this.document.items.get(itemId);
switch (listElement.dataset.type) {
case 'effect':
return this.document.effects.get(itemId);
default:
return this.document.items.get(itemId);
}
}
static triggerContextMenu(event, button) {

View file

@ -1,3 +1,4 @@
import DHActionConfig from '../../sheets-configs/action-config.mjs';
import DHApplicationMixin from './application-mixin.mjs';
const { ItemSheetV2 } = foundry.applications.sheets;
@ -16,6 +17,9 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
submitOnChange: true
},
actions: {
addAction: DHBaseItemSheet.#addAction,
editAction: DHBaseItemSheet.#editAction,
removeAction: DHBaseItemSheet.#removeAction,
addFeature: DHBaseItemSheet.#addFeature,
editFeature: DHBaseItemSheet.#editFeature,
removeFeature: DHBaseItemSheet.#removeFeature
@ -31,7 +35,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
/** @inheritdoc */
static TABS = {
primary: {
tabs: [{ id: 'description' }, { id: 'features' }, { id: 'settings' }],
tabs: [{ id: 'description' }, { id: 'actions' }, { id: 'settings' }],
initial: 'description',
labelPrefix: 'DAGGERHEART.Sheets.TABS'
}
@ -64,6 +68,83 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
* Render a dialog prompting the user to select an action type.
*
* @returns {Promise<object>} An object containing the selected action type.
*/
static async selectActionType() {
const content = await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/actionTypes/actionType.hbs',
{ types: CONFIG.DH.ACTIONS.actionTypes }
),
title = 'Select Action Type';
return foundry.applications.api.DialogV2.prompt({
window: { title },
content,
ok: {
label: title,
callback: (event, button, dialog) => button.form.elements.type.value
}
});
}
/**
* Add a new action to the item, prompting the user for its type.
* @param {PointerEvent} _event - The originating click event
* @param {HTMLElement} _button - The capturing HTML element which defines the [data-action="addAction"]
*/
static async #addAction(_event, _button) {
const actionType = await DHBaseItemSheet.selectActionType();
if (!actionType) return;
try {
const cls =
game.system.api.models.actions.actionsTypes[actionType] ??
game.system.api.models.actions.actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.document)
},
{
parent: this.document
}
);
await this.document.update({ 'system.actions': [...this.document.system.actions, action] });
await new DHActionConfig(this.document.system.actions[this.document.system.actions.length - 1]).render({
force: true
});
} catch (error) {
console.log(error);
}
}
/**
* Edit an existing action on the item
* @param {PointerEvent} _event - The originating click event
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="editAction"]
*/
static async #editAction(_event, button) {
const action = this.document.system.actions[button.dataset.index];
await new DHActionConfig(action).render({ force: true });
}
/**
* Remove an action from the item.
* @param {PointerEvent} event - The originating click event
* @param {HTMLElement} button - The capturing HTML element which defines the [data-action="removeAction"]
*/
static async #removeAction(event, button) {
event.stopPropagation();
const actionIndex = button.closest('[data-index]').dataset.index;
await this.document.update({
'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex))
});
}
/**
* Add a new feature to the item, prompting the user for its type.
* @param {PointerEvent} _event - The originating click event

View file

@ -9,7 +9,7 @@ export default class ArmorSheet extends DHBaseItemSheet {
{
selector: '.features-input',
options: () => CONFIG.DH.ITEM.armorFeatures,
callback: ArmorSheet.#onArmorFeatureSelect
callback: ArmorSheet.#onFeatureSelect
}
]
};
@ -19,9 +19,9 @@ export default class ArmorSheet extends DHBaseItemSheet {
header: { template: 'systems/daggerheart/templates/sheets/items/armor/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
actions: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/armor/settings.hbs',
@ -35,7 +35,7 @@ export default class ArmorSheet extends DHBaseItemSheet {
switch (partId) {
case 'settings':
context.armorFeatures = this.document.system.armorFeatures.map(x => x.value);
context.features = this.document.system.features.map(x => x.value);
break;
}
@ -46,7 +46,7 @@ export default class ArmorSheet extends DHBaseItemSheet {
* Callback function used by `tagifyElement`.
* @param {Array<Object>} selectedOptions - The currently selected tag objects.
*/
static async #onArmorFeatureSelect(selectedOptions) {
await this.document.update({ 'system.armorFeatures': selectedOptions.map(x => ({ value: x.value })) });
static async #onFeatureSelect(selectedOptions) {
await this.document.update({ 'system.features': selectedOptions.map(x => ({ value: x.value })) });
}
}

View file

@ -12,9 +12,9 @@ export default class ConsumableSheet extends DHBaseItemSheet {
header: { template: 'systems/daggerheart/templates/sheets/items/consumable/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
actions: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/consumable/settings.hbs',

View file

@ -10,7 +10,7 @@ export default class DomainCardSheet extends DHBaseItemSheet {
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'description' }, { id: 'features' }, { id: 'settings' }, { id: 'effects' }],
tabs: [{ id: 'description' }, { id: 'actions' }, { id: 'settings' }, { id: 'effects' }],
initial: 'description',
labelPrefix: 'DAGGERHEART.Sheets.TABS'
}
@ -21,9 +21,9 @@ export default class DomainCardSheet extends DHBaseItemSheet {
header: { template: 'systems/daggerheart/templates/sheets/items/domainCard/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
actions: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/domainCard/settings.hbs',

View file

@ -12,9 +12,9 @@ export default class MiscellaneousSheet extends DHBaseItemSheet {
header: { template: 'systems/daggerheart/templates/sheets/items/miscellaneous/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
actions: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/miscellaneous/settings.hbs',

View file

@ -8,7 +8,7 @@ export default class WeaponSheet extends DHBaseItemSheet {
{
selector: '.features-input',
options: () => CONFIG.DH.ITEM.weaponFeatures,
callback: WeaponSheet.#onWeaponFeatureSelect
callback: WeaponSheet.#onFeatureSelect
}
]
};
@ -18,9 +18,9 @@ export default class WeaponSheet extends DHBaseItemSheet {
header: { template: 'systems/daggerheart/templates/sheets/items/weapon/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
scrollable: ['.features']
actions: {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/weapon/settings.hbs',
@ -34,7 +34,7 @@ export default class WeaponSheet extends DHBaseItemSheet {
switch (partId) {
case 'settings':
context.weaponFeatures = this.document.system.weaponFeatures.map(x => x.value);
context.features = this.document.system.features.map(x => x.value);
break;
}
@ -45,7 +45,7 @@ export default class WeaponSheet extends DHBaseItemSheet {
* Callback function used by `tagifyElement`.
* @param {Array<Object>} selectedOptions - The currently selected tag objects.
*/
static async #onWeaponFeatureSelect(selectedOptions) {
await this.document.update({ 'system.weaponFeatures': selectedOptions.map(x => ({ value: x.value })) });
static async #onFeatureSelect(selectedOptions) {
await this.document.update({ 'system.features': selectedOptions.map(x => ({ value: x.value })) });
}
}

View file

@ -1,6 +1,6 @@
import BaseDataItem from './base.mjs';
import ActionField from '../fields/actionField.mjs';
import { armorFeatures } from '../../config/itemConfig.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
export default class DHArmor extends BaseDataItem {
/** @inheritDoc */
@ -22,7 +22,7 @@ export default class DHArmor extends BaseDataItem {
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
equipped: new fields.BooleanField({ initial: false }),
baseScore: new fields.NumberField({ integer: true, initial: 0 }),
armorFeatures: new fields.ArrayField(
features: new fields.ArrayField(
new fields.SchemaField({
value: new fields.StringField({
required: true,
@ -40,28 +40,32 @@ export default class DHArmor extends BaseDataItem {
major: new fields.NumberField({ integer: true, initial: 0 }),
severe: new fields.NumberField({ integer: true, initial: 0 })
}),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
actions: new fields.ArrayField(new ActionField())
};
}
get featureInfo() {
return this.feature ? CONFIG.DH.ITEM.armorFeatures[this.feature] : null;
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;
if (changes.system?.armorFeatures) {
const removed = this.armorFeatures.filter(x => !changes.system.armorFeatures.includes(x));
const added = changes.system.armorFeatures.filter(x => !this.armorFeatures.includes(x));
if (changes.system.features) {
const removed = this.features.filter(x => !changes.system.features.includes(x));
const added = changes.system.features.filter(x => !this.features.includes(x));
for (var armorFeature of removed) {
for (var effectId of armorFeature.effectIds) {
for (var feature of removed) {
for (var effectId of feature.effectIds) {
await this.parent.effects.get(effectId).delete();
}
changes.system.actions = this.actions.filter(x => !armorFeature.actionIds.includes(x._id));
changes.system.actions = this.actions.filter(x => !feature.actionIds.includes(x._id));
}
for (var armorFeature of added) {
const featureData = armorFeatures[armorFeature.value];
for (var feature of added) {
const featureData = armorFeatures[feature.value];
if (featureData.effects?.length > 0) {
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
{
@ -70,7 +74,7 @@ export default class DHArmor extends BaseDataItem {
changes: featureData.effects.flatMap(x => x.changes)
}
]);
armorFeature.effectIds = embeddedItems.map(x => x.id);
feature.effectIds = embeddedItems.map(x => x.id);
}
if (featureData.actions?.length > 0) {
const newActions = featureData.actions.map(action => {
@ -81,7 +85,7 @@ export default class DHArmor extends BaseDataItem {
);
});
changes.system.actions = [...this.actions, ...newActions];
armorFeature.actionIds = newActions.map(x => x._id);
feature.actionIds = newActions.map(x => x._id);
}
}
}

View file

@ -1,5 +1,5 @@
import BaseDataItem from './base.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHConsumable extends BaseDataItem {
/** @inheritDoc */
@ -19,7 +19,7 @@ export default class DHConsumable extends BaseDataItem {
return {
...super.defineSchema(),
consumeOnUse: new fields.BooleanField({ initial: false }),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
actions: new fields.ArrayField(new ActionField())
};
}
}

View file

@ -1,5 +1,5 @@
import BaseDataItem from './base.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHDomainCard extends BaseDataItem {
/** @inheritDoc */
@ -30,7 +30,7 @@ export default class DHDomainCard extends BaseDataItem {
}),
foundation: new fields.BooleanField({ initial: false }),
inVault: new fields.BooleanField({ initial: false }),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
actions: new fields.ArrayField(new ActionField())
};
}

View file

@ -1,5 +1,5 @@
import BaseDataItem from './base.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHMiscellaneous extends BaseDataItem {
/** @inheritDoc */
@ -15,9 +15,10 @@ export default class DHMiscellaneous extends BaseDataItem {
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
actions: new fields.ArrayField(new ActionField())
};
}
}

View file

@ -1,6 +1,6 @@
import BaseDataItem from './base.mjs';
import { actionsTypes } from '../action/_module.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import ActionField from '../fields/actionField.mjs';
export default class DHWeapon extends BaseDataItem {
/** @inheritDoc */
@ -38,7 +38,7 @@ export default class DHWeapon extends BaseDataItem {
initial: 'physical'
})
}),
weaponFeatures: new fields.ArrayField(
features: new fields.ArrayField(
new fields.SchemaField({
value: new fields.StringField({
required: true,
@ -49,7 +49,7 @@ export default class DHWeapon extends BaseDataItem {
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
})
),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
actions: new fields.ArrayField(new ActionField())
};
}
@ -57,9 +57,9 @@ export default class DHWeapon extends BaseDataItem {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;
if (changes.system?.weaponFeatures) {
const removed = this.weaponFeatures.filter(x => !changes.system.weaponFeatures.includes(x));
const added = changes.system.weaponFeatures.filter(x => !this.weaponFeatures.includes(x));
if (changes.system?.features) {
const removed = this.features.filter(x => !changes.system.features.includes(x));
const added = changes.system.features.filter(x => !this.features.includes(x));
for (var weaponFeature of removed) {
for (var effectId of weaponFeature.effectIds) {

View file

@ -4,5 +4,5 @@
data-group='{{tabs.effects.group}}'
>
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.activeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inativeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inactiveEffects') type='effect'}}
</section>

View file

@ -4,5 +4,5 @@
data-group='{{tabs.effects.group}}'
>
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.activeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inativeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inactiveEffects') type='effect'}}
</section>

View file

@ -4,5 +4,5 @@
data-group='{{tabs.effects.group}}'
>
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.activeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inativeEffects') type='effect'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize 'DAGGERHEART.Sheets.Global.inactiveEffects') type='effect'}}
</section>

View file

@ -2,7 +2,7 @@
<legend>{{title}}</legend>
<ul class="items-list">
{{#unless (eq cardView 'card') }}
{{#if (eq type 'domainCard')}}
{{#if (or (eq type 'domainCard') (eq type 'armor') (eq type 'consumable') (eq type 'miscellaneous') (eq type 'weapon'))}}
{{#each document.items as |item|}}
{{#if (eq item.type ../type)}}
{{#unless (and (eq ../type 'domainCard') (or (and item.system.inVault (not ../isVault)) (and (not item.system.inVault) ../isVault)))}}