Fixed Feature flow

This commit is contained in:
WBHarry 2025-07-01 03:27:05 +02:00
parent 71fec10788
commit c406974cb5
17 changed files with 100 additions and 427 deletions

View file

@ -1,5 +1,5 @@
import BaseLevelUp from './levelup.mjs';
import { defaultCompanionTier } from '../../data/levelTier.mjs';
import { defaultCompanionTier, LevelOptionType } from '../../data/levelTier.mjs';
import { DhLevelup } from '../../data/levelup.mjs';
import { diceTypes, range } from '../../config/generalConfig.mjs';
@ -108,6 +108,12 @@ export default class DhCompanionLevelUp extends BaseLevelUp {
: actorKey;
advancement[choiceKey][checkbox.data[0]] =
options[keys[Math.min(currentIndex + 1, keys.length - 1)]];
default:
if (!advancement.simple) advancement.simple = {};
advancement.simple[choiceKey] = game.i18n.localize(
LevelOptionType[checkbox.type].label
);
break;
}
}
}
@ -140,7 +146,8 @@ export default class DhCompanionLevelUp extends BaseLevelUp {
new: game.i18n.localize(advancement.vicious.range.label)
}
: null
}
},
simple: advancement.simple ?? {}
};
context.advancements.statistics.stress.shown =

View file

@ -6,8 +6,6 @@ import DaggerheartSheet from './daggerheart-sheet.mjs';
import { abilities } from '../../config/actorConfig.mjs';
import DhCharacterlevelUp from '../levelup/characterLevelup.mjs';
import DhCharacterCreation from '../characterCreation.mjs';
import DHActionConfig from '../config/Action.mjs';
import { DHBaseAction } from '../../data/action/action.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
const { TextEditor } = foundry.applications.ux;
@ -53,7 +51,6 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
levelManagement: this.levelManagement,
editImage: this._onEditImage,
triggerContextMenu: this.triggerContextMenu
// editAction: this.editAction,
},
window: {
resizable: true
@ -307,20 +304,13 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
getItem(element) {
const listElement = (element.target ?? element).closest('[data-item-id]');
if (listElement.dataset.isAction) return this.getAction(listElement);
const document = listElement.dataset.companion ? this.document.system.companion : this.document;
const itemId = listElement.dataset.itemId,
item = this.document.items.get(itemId);
item = document.items.get(itemId);
return item;
}
getAction(listElement) {
const target = listElement.dataset.partner === 'true' ? this.document.system.companion : this.document;
if (!target) return null;
return target.system.actions.find(x => x.id === listElement.dataset.itemId);
}
static triggerContextMenu(event, button) {
return CONFIG.ux.ContextMenu.triggerContextMenu(event);
}
@ -623,9 +613,15 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
static async useItem(event, button) {
const item = this.getItem(button);
if (!item) return;
const wasUsed = await item.use(event);
if (wasUsed && item.type === 'weapon') {
Hooks.callAll(SYSTEM.HOOKS.characterAttack, {});
// Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board
if (item.type === 'feature') {
item.toChat();
} else {
const wasUsed = await item.use(event);
if (wasUsed && item.type === 'weapon') {
Hooks.callAll(SYSTEM.HOOKS.characterAttack, {});
}
}
}
@ -633,11 +629,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
const item = this.getItem(event);
if (!item) return;
if (item instanceof DHBaseAction) {
new DHActionConfig(item).render({ force: true });
} else {
item.sheet.render(true);
}
item.sheet.render(true);
}
editItem(event) {
@ -694,12 +686,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
const item = this.getItem(event);
if (!item) return;
if (item instanceof DHBaseAction) {
const newActions = item.parent.actions.filter(x => x.id !== item.id);
await item.parent.parent.update({ ['system.actions']: newActions });
} else {
await item.delete();
}
await item.delete();
}
static async setItemQuantity(button, value) {
@ -735,30 +722,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
}
static async toChat(event, button) {
const item = event.dataset ? event : button.closest(['[data-item-id']);
if (item?.dataset.isAction) {
const action = this.getAction(item);
const cls = getDocumentClass('ChatMessage');
const systemData = {
title: action.name,
origin: this,
img: action.img,
name: action.name,
description: action.description,
actions: []
};
const msg = new cls({
type: 'abilityUse',
user: game.user.id,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
systemData
)
});
cls.create(msg.toObject());
} else if (button?.dataset?.type === 'experience') {
if (button?.dataset?.type === 'experience') {
const experience = this.document.system.experiences[button.dataset.uuid];
const cls = getDocumentClass('ChatMessage');
const systemData = {

View file

@ -6,11 +6,7 @@ export default class FeatureSheet extends DHBaseItemSheet {
id: 'daggerheart-feature',
classes: ['feature'],
position: { height: 600 },
window: { resizable: true },
actions: {
addEffect: this.addEffect,
removeEffect: this.removeEffect
}
window: { resizable: true }
};
/**@override */
@ -22,27 +18,16 @@ export default class FeatureSheet extends DHBaseItemSheet {
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs',
scrollable: ['.actions']
},
settings: {
template: 'systems/daggerheart/templates/sheets/items/feature/settings.hbs',
scrollable: ['.settings']
},
effects: {
template: 'systems/daggerheart/templates/sheets/items/feature/effects.hbs',
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-effects.hbs',
scrollable: ['.effects']
}
};
/**
* Internally tracks the selected effect type from the select.
* @type {String}
* @private
*/
_selectedEffectType;
/**@override */
static TABS = {
primary: {
tabs: [{ id: 'description' }, { id: 'actions' }, { id: 'settings' }, { id: 'effects' }],
tabs: [{ id: 'description' }, { id: 'actions' }, { id: 'effects' }],
initial: 'description',
labelPrefix: 'DAGGERHEART.Sheets.TABS'
}
@ -50,68 +35,10 @@ export default class FeatureSheet extends DHBaseItemSheet {
/* -------------------------------------------- */
/**@inheritdoc*/
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
if (partId === 'effects')
htmlElement.querySelector('.effect-select')?.addEventListener('change', this._effectSelect.bind(this));
}
/**
* Handles selection of a new effect type.
* @param {Event} event - Change Event
*/
_effectSelect(event) {
const value = event.currentTarget.value;
this._selectedEffectType = value;
this.render({ parts: ['effects'] });
}
/* -------------------------------------------- */
/**@inheritdoc */
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.properties = CONFIG.daggerheart.ACTOR.featureProperties;
context.dice = CONFIG.daggerheart.GENERAL.diceTypes;
context.effectConfig = CONFIG.daggerheart.EFFECTS;
context.selectedEffectType = this._selectedEffectType;
return context;
}
/* -------------------------------------------- */
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
* Adds a new effect to the item, based on the selected effect type.
* @param {PointerEvent} _event - The originating click event
* @param {HTMLElement} _target - The capturing HTML element which defines the [data-action]
* @returns
*/
static async addEffect(_event, _target) {
const type = this._selectedEffectType;
if (!type) return;
const { id, name, ...rest } = CONFIG.daggerheart.EFFECTS.effectTypes[type];
await this.item.update({
[`system.effects.${foundry.utils.randomID()}`]: {
type,
value: '',
...rest
}
});
}
/**
* Removes an effect from the item.
* @param {PointerEvent} _event - The originating click event
* @param {HTMLElement} target - The capturing HTML element which defines the [data-action]
* @returns
*/
static async removeEffect(_event, target) {
const path = `system.effects.-=${target.dataset.effect}`;
await this.item.update({ [path]: null });
}
}