Data fixes

This commit is contained in:
WBHarry 2025-07-03 10:37:33 +02:00
parent 502ac1cca5
commit ef2116db49
11 changed files with 183 additions and 136 deletions

View file

@ -1312,7 +1312,8 @@
} }
}, },
"Experiences": "Experiences", "Experiences": "Experiences",
"Level": "Level" "Level": "Level",
"noPartner": "No Partner selected"
}, },
"Adversary": { "Adversary": {
"FIELDS": { "FIELDS": {

View file

@ -1,5 +1,3 @@
import { GMUpdateEvent, socketEvent } from '../../../helpers/socket.mjs';
import DhCompanionlevelUp from '../../levelup/companionLevelup.mjs';
import DaggerheartSheet from '../daggerheart-sheet.mjs'; import DaggerheartSheet from '../daggerheart-sheet.mjs';
import DHCompanionSettings from '../applications/companion-settings.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'], classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'companion'],
position: { width: 300 }, position: { width: 300 },
actions: { actions: {
attackRoll: this.attackRoll, viewActor: this.viewActor,
levelUp: this.levelUp, openSettings: this.openSettings,
openSettings: this.openSettings useItem: this.useItem,
toChat: this.toChat
}, },
form: { form: {
handler: this.updateForm, 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) { async _prepareContext(_options) {
const context = await super._prepareContext(_options); const context = await super._prepareContext(_options);
context.document = this.document; context.document = this.document;
context.tabs = super._getTabs(this.constructor.TABS); 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; return context;
} }
@ -74,41 +58,51 @@ export default class DhCompanionSheet extends DaggerheartSheet(ActorSheetV2) {
this.render(); this.render();
} }
async onPartnerChange(event) { static async viewActor(_, button) {
const partnerDocument = event.target.value const target = button.closest('[data-item-uuid]');
? await foundry.utils.fromUuid(event.target.value) const actor = await foundry.utils.fromUuid(target.dataset.itemUuid);
: this.document.system.partner; if (!actor) return;
const partnerUpdate = { 'system.companion': event.target.value ? this.document.uuid : null };
if (!partnerDocument.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) { actor.sheet.render(true);
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);
}
} }
static async attackRoll(event) { getAction(element) {
this.actor.system.attack.use(event); 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() { static async openSettings() {
await new DHCompanionSettings(this.document).render(true); await new DHCompanionSettings(this.document).render(true);
} }
static async levelUp() {
new DhCompanionlevelUp(this.document).render(true);
}
} }

View file

@ -1,6 +1,5 @@
import DHActionConfig from '../../config/Action.mjs'; import { GMUpdateEvent, socketEvent } from '../../../helpers/socket.mjs';
import DHBaseItemSheet from '../api/base-item.mjs'; import DhCompanionlevelUp from '../../levelup/companionLevelup.mjs';
import { actionsTypes } from '../../../data/_module.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
@ -23,7 +22,9 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl
resizable: false resizable: false
}, },
position: { width: 455, height: 'auto' }, position: { width: 455, height: 'auto' },
actions: {}, actions: {
levelUp: this.levelUp
},
form: { form: {
handler: this.updateForm, handler: this.updateForm,
submitOnChange: true, 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) { async _prepareContext(_options) {
const context = await super._prepareContext(_options); const context = await super._prepareContext(_options);
context.document = this.actor; context.document = this.actor;
@ -89,8 +96,7 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl
.filter( .filter(
x => x =>
x.type === 'character' && x.type === 'character' &&
(x.ownership.default === 3 || (x.testUserPermission(game.user, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) ||
x.ownership[game.user.id] === 3 ||
this.document.system.partner?.uuid === x.uuid) this.document.system.partner?.uuid === x.uuid)
) )
.map(x => ({ key: x.uuid, name: x.name })); .map(x => ({ key: x.uuid, name: x.name }));
@ -107,6 +113,34 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl
return tabs; 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) { async viewActor(_, button) {
const target = button.closest('[data-item-uuid]'); const target = button.closest('[data-item-uuid]');
const actor = await foundry.utils.fromUuid(target.dataset.itemUuid); const actor = await foundry.utils.fromUuid(target.dataset.itemUuid);
@ -115,6 +149,10 @@ export default class DHCompanionSettings extends HandlebarsApplicationMixin(Appl
actor.sheet.render(true); actor.sheet.render(true);
} }
static async levelUp() {
new DhCompanionlevelUp(this.actor).render(true);
}
static async updateForm(event, _, formData) { static async updateForm(event, _, formData) {
await this.actor.update(formData.object); await this.actor.update(formData.object);
this.render(); this.render();

View file

@ -47,6 +47,7 @@ export default class DhCompanion extends BaseDataActor {
attack: new ActionField({ attack: new ActionField({
initial: { initial: {
name: 'Attack', name: 'Attack',
img: 'icons/creatures/claws/claw-bear-paw-swipe-brown.webp',
_id: foundry.utils.randomID(), _id: foundry.utils.randomID(),
systemPath: 'attack', systemPath: 'attack',
type: 'attack', type: 'attack',
@ -57,7 +58,8 @@ export default class DhCompanion extends BaseDataActor {
}, },
roll: { roll: {
type: 'weapon', type: 'weapon',
bonus: 0 bonus: 0,
trait: 'instinct'
}, },
damage: { damage: {
parts: [ parts: [
@ -77,8 +79,10 @@ export default class DhCompanion extends BaseDataActor {
}; };
} }
get attackBonus() { get traits() {
return this.attack.roll.bonus ?? 0; return {
instinct: { total: this.attack.roll.bonus }
};
} }
prepareBaseData() { prepareBaseData() {

View file

@ -338,7 +338,7 @@ export default class DhpActor extends Actor {
} }
get rollClass() { get rollClass() {
return CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll']; return CONFIG.Dice.daggerheart[['character', 'companion'].includes(this.type) ? 'DualityRoll' : 'D20Roll'];
} }
getRollData() { getRollData() {

View file

@ -21,8 +21,7 @@ export default class RegisterHandlebarsHelpers {
lte: this.lte, lte: this.lte,
gte: this.gte, gte: this.gte,
and: this.and, and: this.and,
or: this.or, or: this.or
getActor: this.getActor
}); });
} }
@ -138,8 +137,4 @@ export default class RegisterHandlebarsHelpers {
console.log(a); console.log(a);
return a; return a;
} }
static getActor(actorUuid) {
return fromUuid(actorUuid);
}
} }

View file

@ -5174,6 +5174,11 @@ div.daggerheart.views.multiclass {
gap: 10px; gap: 10px;
align-items: center; 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 { .application.sheet.daggerheart.actor.dh-style.companion .experience-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View file

@ -1,63 +1,69 @@
@import '../../utils/colors.less'; @import '../../utils/colors.less';
@import '../../utils/fonts.less'; @import '../../utils/fonts.less';
.application.sheet.daggerheart.actor.dh-style.companion { .application.sheet.daggerheart.actor.dh-style.companion {
.partner-section, .partner-section,
.attack-section { .attack-section {
.title { .title {
display: flex; display: flex;
gap: 15px; gap: 15px;
align-items: center; align-items: center;
h3 { h3 {
font-size: 20px; font-size: 20px;
} }
} }
.items-list { .items-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 10px; gap: 10px;
align-items: center; align-items: center;
} }
} }
.experience-list { .partner-placeholder {
display: flex; opacity: 0.6;
flex-direction: column; text-align: center;
gap: 5px; font-style: italic;
width: 100%; }
margin-top: 10px;
align-items: center; .experience-list {
display: flex;
.experience-row { flex-direction: column;
display: flex; gap: 5px;
gap: 5px; width: 100%;
width: 250px; margin-top: 10px;
align-items: center; align-items: center;
justify-content: space-between;
.experience-row {
.experience-name { display: flex;
width: 180px; gap: 5px;
text-align: start; width: 250px;
font-size: 14px; align-items: center;
font-family: @font-body; justify-content: space-between;
color: light-dark(@dark, @beige);
} .experience-name {
} width: 180px;
text-align: start;
.experience-value { font-size: 14px;
height: 25px; font-family: @font-body;
width: 35px; color: light-dark(@dark, @beige);
font-size: 14px; }
font-family: @font-body; }
color: light-dark(@dark, @beige);
align-content: center; .experience-value {
text-align: center; height: 25px;
background: url(../assets/svg/experience-shield.svg) no-repeat; width: 35px;
font-size: 14px;
.theme-light & { font-family: @font-body;
background: url('../assets/svg/experience-shield-light.svg') no-repeat; 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;
}
}
}
}

View file

@ -9,9 +9,13 @@
<h3>Partner</h3> <h3>Partner</h3>
<side-line-div></side-line-div> <side-line-div></side-line-div>
</div> </div>
<ul class="item-list"> {{#if document.system.partner}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=(getActor document.system.partner.uuid) type='actor' isSidebar=true isActor=true}} <ul class="item-list">
</ul> {{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=document.system.partner type='actor' isSidebar=true isActor=true noTooltip=true}}
</ul>
{{else}}
<div class="partner-placeholder">{{localize "DAGGERHEART.Sheets.Companion.noPartner"}}</div>
{{/if}}
</div> </div>
<div class="attack-section"> <div class="attack-section">
<div class="title"> <div class="title">
@ -20,7 +24,7 @@
<side-line-div></side-line-div> <side-line-div></side-line-div>
</div> </div>
<ul class="item-list"> <ul class="item-list">
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=source.system.attack type=source.system.attack.systemPath isSidebar=true isCompanion=true}} {{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=source.system.attack type=source.system.attack.systemPath isSidebar=true isCompanion=true noTooltip=true}}
</ul> </ul>
</div> </div>
<div class="experience-list"> <div class="experience-list">

View file

@ -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.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"}} {{formGroup systemFields.attack.fields.name value=document.system.attack.name label="Attack Name" name="system.attack.name"}}
</fieldset> </fieldset>
<fieldset class="flex"> {{!-- <fieldset class="flex">
<legend>{{localize "DAGGERHEART.Sheets.Adversary.Attack"}}</legend> <legend>{{localize "DAGGERHEART.Sheets.Adversary.Attack"}}</legend>
{{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.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}} {{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" }} {{ formField systemFields.attack.fields.target.fields.amount value=document.system.attack.target.amount label="Amount" name="system.attack.target.amount" }}
{{/if}} {{/if}}
{{/if}} {{/if}}
</fieldset> </fieldset> --}}
</section> </section>

View file

@ -1,4 +1,4 @@
<li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-companion="{{companion}}" data-tooltip="{{concat "#item#" item.uuid}}"> <li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-companion="{{companion}}" {{#if (not noTooltip)}}data-tooltip="{{concat "#item#" item.uuid}}"{{/if}}>
<img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem"/> <img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem"/>
<div class="item-label"> <div class="item-label">
{{#if isCompanion}} {{#if isCompanion}}