From ef2116db4932b5413549523bfda74a67e9ec6f9d Mon Sep 17 00:00:00 2001 From: WBHarry Date: Thu, 3 Jul 2025 10:37:33 +0200 Subject: [PATCH] Data fixes --- lang/en.json | 3 +- .../applications/sheets/actors/companion.mjs | 92 ++++++------ .../applications/companion-settings.mjs | 50 ++++++- module/data/actor/companion.mjs | 10 +- module/documents/actor.mjs | 2 +- module/helpers/handlebarsHelper.mjs | 7 +- styles/daggerheart.css | 5 + styles/less/actors/companion/details.less | 132 +++++++++--------- templates/sheets/actors/companion/details.hbs | 12 +- .../companion-settings/attack.hbs | 4 +- .../sheets/global/partials/inventory-item.hbs | 2 +- 11 files changed, 183 insertions(+), 136 deletions(-) diff --git a/lang/en.json b/lang/en.json index 7867265d..d466b0fc 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1312,7 +1312,8 @@ } }, "Experiences": "Experiences", - "Level": "Level" + "Level": "Level", + "noPartner": "No Partner selected" }, "Adversary": { "FIELDS": { diff --git a/module/applications/sheets/actors/companion.mjs b/module/applications/sheets/actors/companion.mjs index 35e9a103..89939e9a 100644 --- a/module/applications/sheets/actors/companion.mjs +++ b/module/applications/sheets/actors/companion.mjs @@ -1,5 +1,3 @@ -import { GMUpdateEvent, socketEvent } from '../../../helpers/socket.mjs'; -import DhCompanionlevelUp from '../../levelup/companionLevelup.mjs'; import DaggerheartSheet from '../daggerheart-sheet.mjs'; import DHCompanionSettings from '../applications/companion-settings.mjs'; @@ -10,9 +8,10 @@ export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) { classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'companion'], position: { width: 300 }, actions: { - attackRoll: this.attackRoll, - levelUp: this.levelUp, - openSettings: this.openSettings + viewActor: this.viewActor, + openSettings: this.openSettings, + useItem: this.useItem, + toChat: this.toChat }, form: { handler: this.updateForm, @@ -46,25 +45,10 @@ export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) { } }; - _attachPartListeners(partId, htmlElement, options) { - super._attachPartListeners(partId, htmlElement, options); - - htmlElement.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this)); - } - async _prepareContext(_options) { const context = await super._prepareContext(_options); context.document = this.document; context.tabs = super._getTabs(this.constructor.TABS); - context.playerCharacters = game.actors - .filter( - x => - x.type === 'character' && - (x.ownership.default === 3 || - x.ownership[game.user.id] === 3 || - this.document.system.partner?.uuid === x.uuid) - ) - .map(x => ({ key: x.uuid, name: x.name })); return context; } @@ -74,41 +58,51 @@ export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) { this.render(); } - async onPartnerChange(event) { - const partnerDocument = event.target.value - ? await foundry.utils.fromUuid(event.target.value) - : this.document.system.partner; - const partnerUpdate = { 'system.companion': event.target.value ? this.document.uuid : null }; + static async viewActor(_, button) { + const target = button.closest('[data-item-uuid]'); + const actor = await foundry.utils.fromUuid(target.dataset.itemUuid); + if (!actor) return; - if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) { - await game.socket.emit(`system.${SYSTEM.id}`, { - action: socketEvent.GMUpdate, - data: { - action: GMUpdateEvent.UpdateDocument, - uuid: partnerDocument.uuid, - update: update - } - }); - } else { - await partnerDocument.update(partnerUpdate); - } - - await this.document.update({ 'system.partner': event.target.value }); - - if (!event.target.value) { - await this.document.updateLevel(1); - } + actor.sheet.render(true); } - static async attackRoll(event) { - this.actor.system.attack.use(event); + getAction(element) { + const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId, + item = this.document.system.actions.find(x => x.id === itemId); + return item; + } + + static async useItem(event) { + const action = this.getAction(event) ?? this.actor.system.attack; + action.use(event); + } + + static async toChat(event, button) { + if (button?.dataset?.type === 'experience') { + const experience = this.document.system.experiences[button.dataset.uuid]; + const cls = getDocumentClass('ChatMessage'); + const systemData = { + name: game.i18n.localize('DAGGERHEART.General.Experience.Single'), + description: `${experience.name} ${experience.total < 0 ? experience.total : `+${experience.total}`}` + }; + 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 { + const item = this.getAction(event) ?? this.document.system.attack; + item.toChat(this.document.id); + } } static async openSettings() { await new DHCompanionSettings(this.document).render(true); } - - static async levelUp() { - new DhCompanionlevelUp(this.document).render(true); - } } diff --git a/module/applications/sheets/applications/companion-settings.mjs b/module/applications/sheets/applications/companion-settings.mjs index 053dfbb0..89d20a07 100644 --- a/module/applications/sheets/applications/companion-settings.mjs +++ b/module/applications/sheets/applications/companion-settings.mjs @@ -1,6 +1,5 @@ -import DHActionConfig from '../../config/Action.mjs'; -import DHBaseItemSheet from '../api/base-item.mjs'; -import { actionsTypes } from '../../../data/_module.mjs'; +import { GMUpdateEvent, socketEvent } from '../../../helpers/socket.mjs'; +import DhCompanionlevelUp from '../../levelup/companionLevelup.mjs'; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; @@ -23,7 +22,9 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl resizable: false }, position: { width: 455, height: 'auto' }, - actions: {}, + actions: { + levelUp: this.levelUp + }, form: { handler: this.updateForm, submitOnChange: true, @@ -78,6 +79,12 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl } }; + _attachPartListeners(partId, htmlElement, options) { + super._attachPartListeners(partId, htmlElement, options); + + htmlElement.querySelector('.partner-value')?.addEventListener('change', this.onPartnerChange.bind(this)); + } + async _prepareContext(_options) { const context = await super._prepareContext(_options); context.document = this.actor; @@ -89,8 +96,7 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl .filter( x => x.type === 'character' && - (x.ownership.default === 3 || - x.ownership[game.user.id] === 3 || + (x.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) || this.document.system.partner?.uuid === x.uuid) ) .map(x => ({ key: x.uuid, name: x.name })); @@ -107,6 +113,34 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl return tabs; } + async onPartnerChange(event) { + const partnerDocument = event.target.value + ? await foundry.utils.fromUuid(event.target.value) + : this.actor.system.partner; + const partnerUpdate = { 'system.companion': event.target.value ? this.actor.uuid : null }; + + if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) { + await game.socket.emit(`system.${SYSTEM.id}`, { + action: socketEvent.GMUpdate, + data: { + action: GMUpdateEvent.UpdateDocument, + uuid: partnerDocument.uuid, + update: update + } + }); + } else { + await partnerDocument.update(partnerUpdate); + } + + await this.actor.update({ 'system.partner': event.target.value }); + + if (!event.target.value) { + await this.actor.updateLevel(1); + } + + this.render(); + } + async viewActor(_, button) { const target = button.closest('[data-item-uuid]'); const actor = await foundry.utils.fromUuid(target.dataset.itemUuid); @@ -115,6 +149,10 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl actor.sheet.render(true); } + static async levelUp() { + new DhCompanionlevelUp(this.actor).render(true); + } + static async updateForm(event, _, formData) { await this.actor.update(formData.object); this.render(); diff --git a/module/data/actor/companion.mjs b/module/data/actor/companion.mjs index abc38e93..b1254f87 100644 --- a/module/data/actor/companion.mjs +++ b/module/data/actor/companion.mjs @@ -47,6 +47,7 @@ export default class DhCompanion extends BaseDataActor { attack: new ActionField({ initial: { name: 'Attack', + img: 'icons/creatures/claws/claw-bear-paw-swipe-brown.webp', _id: foundry.utils.randomID(), systemPath: 'attack', type: 'attack', @@ -57,7 +58,8 @@ export default class DhCompanion extends BaseDataActor { }, roll: { type: 'weapon', - bonus: 0 + bonus: 0, + trait: 'instinct' }, damage: { parts: [ @@ -77,8 +79,10 @@ export default class DhCompanion extends BaseDataActor { }; } - get attackBonus() { - return this.attack.roll.bonus ?? 0; + get traits() { + return { + instinct: { total: this.attack.roll.bonus } + }; } prepareBaseData() { diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 541b76d0..1779ca8d 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -338,7 +338,7 @@ export default class DhpActor extends Actor { } get rollClass() { - return CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll']; + return CONFIG.Dice.daggerheart[['character', 'companion'].includes(this.type) ? 'DualityRoll' : 'D20Roll']; } getRollData() { diff --git a/module/helpers/handlebarsHelper.mjs b/module/helpers/handlebarsHelper.mjs index 4c0800f2..6200b690 100644 --- a/module/helpers/handlebarsHelper.mjs +++ b/module/helpers/handlebarsHelper.mjs @@ -21,8 +21,7 @@ export default class RegisterHandlebarsHelpers { lte: this.lte, gte: this.gte, and: this.and, - or: this.or, - getActor: this.getActor + or: this.or }); } @@ -138,8 +137,4 @@ export default class RegisterHandlebarsHelpers { console.log(a); return a; } - - static getActor(actorUuid) { - return fromUuid(actorUuid); - } } diff --git a/styles/daggerheart.css b/styles/daggerheart.css index 28666a18..7efa8f7b 100755 --- a/styles/daggerheart.css +++ b/styles/daggerheart.css @@ -5174,6 +5174,11 @@ div.daggerheart.views.multiclass { gap: 10px; align-items: center; } +.application.sheet.daggerheart.actor.dh-style.companion .partner-placeholder { + opacity: 0.6; + text-align: center; + font-style: italic; +} .application.sheet.daggerheart.actor.dh-style.companion .experience-list { display: flex; flex-direction: column; diff --git a/styles/less/actors/companion/details.less b/styles/less/actors/companion/details.less index 33551d9b..ae65fe33 100644 --- a/styles/less/actors/companion/details.less +++ b/styles/less/actors/companion/details.less @@ -1,63 +1,69 @@ -@import '../../utils/colors.less'; -@import '../../utils/fonts.less'; - -.application.sheet.daggerheart.actor.dh-style.companion { - .partner-section, - .attack-section { - .title { - display: flex; - gap: 15px; - align-items: center; - - h3 { - font-size: 20px; - } - } - .items-list { - display: flex; - flex-direction: column; - gap: 10px; - align-items: center; - } - } - - .experience-list { - display: flex; - flex-direction: column; - gap: 5px; - width: 100%; - margin-top: 10px; - align-items: center; - - .experience-row { - display: flex; - gap: 5px; - width: 250px; - align-items: center; - justify-content: space-between; - - .experience-name { - width: 180px; - text-align: start; - font-size: 14px; - font-family: @font-body; - color: light-dark(@dark, @beige); - } - } - - .experience-value { - height: 25px; - width: 35px; - font-size: 14px; - font-family: @font-body; - color: light-dark(@dark, @beige); - align-content: center; - text-align: center; - background: url(../assets/svg/experience-shield.svg) no-repeat; - - .theme-light & { - background: url('../assets/svg/experience-shield-light.svg') no-repeat; - } - } - } -} +@import '../../utils/colors.less'; +@import '../../utils/fonts.less'; + +.application.sheet.daggerheart.actor.dh-style.companion { + .partner-section, + .attack-section { + .title { + display: flex; + gap: 15px; + align-items: center; + + h3 { + font-size: 20px; + } + } + .items-list { + display: flex; + flex-direction: column; + gap: 10px; + align-items: center; + } + } + + .partner-placeholder { + opacity: 0.6; + text-align: center; + font-style: italic; + } + + .experience-list { + display: flex; + flex-direction: column; + gap: 5px; + width: 100%; + margin-top: 10px; + align-items: center; + + .experience-row { + display: flex; + gap: 5px; + width: 250px; + align-items: center; + justify-content: space-between; + + .experience-name { + width: 180px; + text-align: start; + font-size: 14px; + font-family: @font-body; + color: light-dark(@dark, @beige); + } + } + + .experience-value { + height: 25px; + width: 35px; + font-size: 14px; + font-family: @font-body; + color: light-dark(@dark, @beige); + align-content: center; + text-align: center; + background: url(../assets/svg/experience-shield.svg) no-repeat; + + .theme-light & { + background: url('../assets/svg/experience-shield-light.svg') no-repeat; + } + } + } +} diff --git a/templates/sheets/actors/companion/details.hbs b/templates/sheets/actors/companion/details.hbs index 8f8c4b4f..f7479bef 100644 --- a/templates/sheets/actors/companion/details.hbs +++ b/templates/sheets/actors/companion/details.hbs @@ -9,9 +9,13 @@

Partner

- + {{#if document.system.partner}} + + {{else}} +
{{localize "DAGGERHEART.Sheets.Companion.noPartner"}}
+ {{/if}}
@@ -20,7 +24,7 @@
diff --git a/templates/sheets/applications/companion-settings/attack.hbs b/templates/sheets/applications/companion-settings/attack.hbs index e3e0d16c..d0fd571a 100644 --- a/templates/sheets/applications/companion-settings/attack.hbs +++ b/templates/sheets/applications/companion-settings/attack.hbs @@ -8,7 +8,7 @@ {{formGroup systemFields.attack.fields.img value=document.system.attack.img label="Image Path" name="system.attack.img"}} {{formGroup systemFields.attack.fields.name value=document.system.attack.name label="Attack Name" name="system.attack.name"}} -
+ {{!--
{{localize "DAGGERHEART.Sheets.Adversary.Attack"}} {{formField systemFields.attack.fields.roll.fields.bonus value=document.system.attack.roll.bonus label="Attack Bonus" name="system.attack.roll.bonus"}} {{formField systemFields.attack.fields.range value=document.system.attack.range label="Range" name="system.attack.range" localize=true}} @@ -18,5 +18,5 @@ {{ formField systemFields.attack.fields.target.fields.amount value=document.system.attack.target.amount label="Amount" name="system.attack.target.amount" }} {{/if}} {{/if}} -
+
--}} \ No newline at end of file diff --git a/templates/sheets/global/partials/inventory-item.hbs b/templates/sheets/global/partials/inventory-item.hbs index e1840a76..9b1c392b 100644 --- a/templates/sheets/global/partials/inventory-item.hbs +++ b/templates/sheets/global/partials/inventory-item.hbs @@ -1,4 +1,4 @@ -
  • +
  • {{#if isCompanion}}