Fixed up downtime dialogs and data model

This commit is contained in:
WBHarry 2025-06-19 17:11:01 +02:00
parent f6e077b290
commit e38ebfab29
10 changed files with 284 additions and 118 deletions

View file

@ -499,29 +499,51 @@
}
},
"Downtime": {
"TendToWounds": {
"Name": "Tend to Wounds",
"Description": "Describe how you patch yourself up and remove all marked Hit Points. You may also do this on an ally instead."
"DowntimeHeader": "Downtime Moves ({current}/{max})",
"ShortRest": {
"title": "Short Rest",
"TendToWounds": {
"Name": "Tend to Wounds",
"Description": "Describe how you hastily patch yourself up, then clear a number of Hit Points equal to 1d4 + your tier. You can do this to an ally instead."
},
"ClearStress": {
"Name": "Clear Stress",
"Description": "Describe how you blow off steam or pull yourself together, then clear a number of Stress equal to 1d4 + your tier."
},
"RepairArmor": {
"Name": "Repair Armor",
"Description": "Describe how you quickly repair your armor, then clear a number of Armor Slots equal to 1d4 + your tier. You can do this to an ally's armor instead."
},
"Prepare": {
"Name": "Prepare",
"Description": "Describe how you prepare yourself for the path ahead, then gain a Hope. If you choose to Prepare with one or more members of your party, you each gain 2 Hope."
}
},
"ClearStress": {
"Name": "Clear Stress",
"Description": "Describe how you blow off steam or pull yourself together, and clear all marked Stress."
"LongRest": {
"title": "Long Rest",
"TendToWounds": {
"Name": "Tend to Wounds",
"Description": "Describe how you patch yourself up and remove all marked Hit Points. You may also do this on an ally instead."
},
"ClearStress": {
"Name": "Clear Stress",
"Description": "Describe how you blow off steam or pull yourself together, and clear all marked Stress."
},
"RepairArmor": {
"Name": "Repair Armor",
"Description": "Describe how you spend time repairing your armor and clear all of its Armor Slots. You may also do this to an ally's armor instead."
},
"Prepare": {
"Name": "Prepare",
"Description": "Describe how you are preparing for the next day's adventure, then gain a Hope. If you choose to Prepare with one or more members of your party, you may each take two Hope."
},
"WorkOnAProject": {
"Name": "Work on a Project",
"Description": "Establish or continue work on a project."
}
},
"RepairArmor": {
"Name": "Repair Armor",
"Description": "Describe how you spend time repairing your armor and clear all of its Armor Slots. You may also do this to an allys armor instead."
},
"Prepare": {
"Name": "Prepare",
"Description": "Describe how you are preparing for the next days adventure, then gain a Hope. If you choose to Prepare with one or more members of your party, you may each take two Hope."
},
"WorkOnAProject": {
"Name": "Work on a Project",
"Description": "Establish or continue work on a project. The GM might ask for a roll to determine how much to tick down on the completion track."
},
"Custom": {
"NamePlaceholder": "Custom Activity...",
"Placeholder": "A custom downtime activity description..."
"Notifications": {
"NoMoreMoves": "You cannot select any more downtime moves"
}
},
"DeathMoves": {

View file

@ -1,3 +1,5 @@
import { actionsTypes } from '../data/_module.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV2) {
@ -5,25 +7,25 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
super({});
this.actor = actor;
this.selectedActivity = null;
this.shortrest = shortrest;
this.customActivity = SYSTEM.GENERAL.downtime.custom;
const options = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Homebrew).restMoves;
this.moveData = shortrest ? options.shortRest : options.longRest;
}
get title() {
return `${this.actor.name} - ${this.shortrest ? 'Short Rest' : 'Long Rest'}`;
return '';
}
static DEFAULT_OPTIONS = {
tag: 'form',
classes: ['daggerheart', 'views', 'downtime'],
position: { width: 800, height: 'auto' },
position: { width: 680, height: 'auto' },
actions: {
selectActivity: this.selectActivity,
selectMove: this.selectMove,
takeDowntime: this.takeDowntime
},
form: { handler: this.updateData, submitOnChange: true }
form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false }
};
static PARTS = {
@ -33,51 +35,63 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
}
};
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
htmlElement
.querySelectorAll('.activity-image')
.forEach(element => element.addEventListener('contextmenu', this.deselectMove.bind(this)));
}
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.selectedActivity = this.selectedActivity;
context.options = this.shortrest ? SYSTEM.GENERAL.downtime.shortRest : SYSTEM.GENERAL.downtime.longRest;
context.customActivity = this.customActivity;
context.disabledDowntime =
!this.selectedActivity ||
(this.selectedActivity.id === this.customActivity.id &&
(!this.customActivity.name || !this.customActivity.description));
context.moveData = this.moveData;
context.nrCurrentChoices = Object.values(this.moveData.moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
context.disabledDowntime = context.nrCurrentChoices < context.moveData.nrChoices;
return context;
}
static selectActivity(_, button) {
const activity = button.dataset.activity;
this.selectedActivity =
activity === this.customActivity.id
? this.customActivity
: this.shortrest
? SYSTEM.GENERAL.downtime.shortRest[activity]
: SYSTEM.GENERAL.downtime.longRest[activity];
static selectMove(_, button) {
const nrSelected = Object.values(this.moveData.moves).reduce((acc, x) => acc + (x.selected ?? 0), 0);
if (nrSelected === this.moveData.nrChoices) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Downtime.Notifications.NoMoreMoves'));
return;
}
const move = button.dataset.move;
this.moveData.moves[move].selected = this.moveData.moves[move].selected
? this.moveData.moves[move].selected + 1
: 1;
this.render();
}
deselectMove(event) {
const move = event.currentTarget.dataset.move;
this.moveData.moves[move].selected = this.moveData.moves[move].selected
? this.moveData.moves[move].selected - 1
: 0;
this.render();
}
static async takeDowntime() {
const refreshedFeatures = this.shortrest
? this.actor.system.refreshableFeatures.shortRest
: [...this.actor.system.refreshableFeatures.shortRest, ...this.actor.system.refreshableFeatures.longRest];
for (var feature of refreshedFeatures) {
await feature.system.refresh();
}
const moves = Object.values(this.moveData.moves).filter(x => x.selected);
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
system: {
moves: moves,
actor: this.actor.uuid
},
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/downtime.hbs',
{
player: this.actor.name,
title: game.i18n.localize(this.selectedActivity.name),
img: this.selectedActivity.img,
description: game.i18n.localize(this.selectedActivity.description),
refreshedFeatures: refreshedFeatures
title: `${this.actor.name} - ${game.i18n.localize(`DAGGERHEART.Downtime.${this.shortRest ? 'ShortRest' : 'LongRest'}.title`)}`,
moves: moves
}
)
});

View file

@ -101,65 +101,99 @@ export const conditions = {
}
};
export const downtime = {
shortRest: {
export const defaultRestOptions = {
shortRest: () => ({
tendToWounds: {
id: 'tendToWounds',
name: 'DAGGERHEART.Downtime.TendToWounds.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.TendToWounds.Name'),
img: 'icons/magic/life/cross-worn-green.webp',
description: 'DAGGERHEART.Downtime.TendToWounds.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.TendToWounds.Description'),
actions: [
{
type: 'healing',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.TendToWounds.Name'),
img: 'icons/magic/life/cross-worn-green.webp',
actionType: 'action',
healing: {
type: 'health',
value: {
custom: {
enabled: true,
formula: '1d4 + 1' // should be 1d4 + {tier}. How to use the roll param?
}
}
}
}
]
},
clearStress: {
id: 'clearStress',
name: 'DAGGERHEART.Downtime.ClearStress.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.ClearStress.Name'),
img: 'icons/magic/perception/eye-ringed-green.webp',
description: 'DAGGERHEART.Downtime.ClearStress.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.ClearStress.Description'),
actions: [
{
type: 'healing',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.ClearStress.Name'),
img: 'icons/magic/perception/eye-ringed-green.webp',
actionType: 'action',
healing: {
type: 'stress',
value: {
custom: {
enabled: true,
formula: '1d4 + 1' // should be 1d4 + {tier}. How to use the roll param?
}
}
}
}
]
},
repairArmor: {
id: 'repairArmor',
name: 'DAGGERHEART.Downtime.RepairArmor.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.RepairArmor.Name'),
img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
description: 'DAGGERHEART.Downtime.RepairArmor.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.RepairArmor.Description')
},
prepare: {
id: 'prepare',
name: 'DAGGERHEART.Downtime.Prepare.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.Prepare.Name'),
img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: 'DAGGERHEART.Downtime.Prepare.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.ShortRest.Prepare.Description')
}
},
longRest: {
}),
longRest: () => ({
tendToWounds: {
id: 'tendToWounds',
name: 'DAGGERHEART.Downtime.TendToWounds.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.LongRest.TendToWounds.Name'),
img: 'icons/magic/life/cross-worn-green.webp',
description: 'DAGGERHEART.Downtime.TendToWounds.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.LongRest.TendToWounds.Description')
},
clearStress: {
id: 'clearStress',
name: 'DAGGERHEART.Downtime.ClearStress.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.LongRest.ClearStress.Name'),
img: 'icons/magic/perception/eye-ringed-green.webp',
description: 'DAGGERHEART.Downtime.ClearStress.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.LongRest.ClearStress.Description')
},
repairArmor: {
id: 'repairArmor',
name: 'DAGGERHEART.Downtime.RepairArmor.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.LongRest.RepairArmor.Name'),
img: 'icons/skills/trades/smithing-anvil-silver-red.webp',
description: 'DAGGERHEART.Downtime.RepairArmor.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.LongRest.RepairArmor.Description')
},
prepare: {
id: 'prepare',
name: 'DAGGERHEART.Downtime.Prepare.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.LongRest.Prepare.Name'),
img: 'icons/skills/trades/academics-merchant-scribe.webp',
description: 'DAGGERHEART.Downtime.Prepare.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.LongRest.Prepare.Description')
},
workOnAProject: {
id: 'workOnAProject',
name: 'DAGGERHEART.Downtime.WorkOnAProject.Name',
name: game.i18n.localize('DAGGERHEART.Downtime.LongRest.WorkOnAProject.Name'),
img: 'icons/skills/social/thumbsup-approval-like.webp',
description: 'DAGGERHEART.Downtime.WorkOnAProject.Description'
description: game.i18n.localize('DAGGERHEART.Downtime.LongRest.WorkOnAProject.Description')
}
},
}),
custom: {
id: 'customActivity',
name: '',

View file

@ -87,6 +87,14 @@ export default class DhCharacter extends BaseDataActor {
};
}
get tier() {
return this.levelData.level.current === 1
? 1
: Object.values(game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers).find(
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
).tier;
}
get ancestry() {
return this.parent.items.find(x => x.type === 'ancestry') ?? null;
}
@ -134,19 +142,6 @@ export default class DhCharacter extends BaseDataActor {
: null;
}
get refreshableFeatures() {
return this.parent.items.reduce(
(acc, x) => {
if (x.type === 'feature' && x.system.refreshData?.type === 'feature' && x.system.refreshData?.type) {
acc[x.system.refreshData.type].push(x);
}
return acc;
},
{ shortRest: [], longRest: [] }
);
}
static async unequipBeforeEquip(itemToEquip) {
const primary = this.primaryWeapon,
secondary = this.secondaryWeapon;
@ -242,6 +237,14 @@ export default class DhCharacter extends BaseDataActor {
this.evasion.total = (this.class?.evasion ?? 0) + this.evasion.bonus;
this.proficiency.total = this.proficiency.value + this.proficiency.bonus;
}
getRollData() {
const data = super.getRollData();
return {
...data,
tier: this.tier
};
}
}
class DhPCLevelData extends foundry.abstract.DataModel {

View file

@ -1,3 +1,5 @@
import { defaultRestOptions } from '../../config/generalConfig.mjs';
export default class DhHomebrew extends foundry.abstract.DataModel {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Settings.Homebrew']; // Doesn't work for some reason
@ -13,6 +15,40 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
}),
traitArray: new fields.ArrayField(new fields.NumberField({ required: true, integer: true }), {
initial: () => [2, 1, 1, 0, 0, -1]
}),
restMoves: new fields.SchemaField({
longRest: new fields.SchemaField({
nrChoices: new fields.NumberField({ required: true, integer: true, min: 1, initial: 2 }),
moves: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField({ required: true }),
img: new fields.FilePathField({
initial: 'icons/magic/life/cross-worn-green.webp',
categories: ['IMAGE'],
base64: false
}),
description: new fields.HTMLField(),
actions: new fields.ArrayField(new fields.ObjectField())
}),
{ initial: defaultRestOptions.longRest() }
)
}),
shortRest: new fields.SchemaField({
nrChoices: new fields.NumberField({ required: true, integer: true, min: 1, initial: 2 }),
moves: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField({ required: true }),
img: new fields.FilePathField({
initial: 'icons/magic/life/cross-worn-green.webp',
categories: ['IMAGE'],
base64: false
}),
description: new fields.HTMLField(),
actions: new fields.ArrayField(new fields.ObjectField())
}),
{ initial: defaultRestOptions.shortRest() }
)
})
})
};
}

View file

@ -1,3 +1,5 @@
import { actionsTypes } from '../data/_module.mjs';
export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog {
constructor() {
super();
@ -38,6 +40,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
html.querySelectorAll('.ability-use-button').forEach(element =>
element.addEventListener('click', event => this.abilityUseButton.bind(this)(event, data.message))
);
html.querySelectorAll('.action-use-button').forEach(element =>
element.addEventListener('click', event => this.actionUseButton.bind(this)(event, data.message))
);
};
setupHooks() {
@ -137,4 +142,16 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
const actor = game.actors.get(message.system.origin);
await actor.useAction(action);
};
actionUseButton = async (_, message) => {
const parent = await foundry.utils.fromUuid(message.system.actor);
const testAction = Object.values(message.system.moves)[0].actions[0];
const cls = actionsTypes[testAction.type];
const action = new cls(
{ ...testAction, _id: foundry.utils.randomID(), name: game.i18n.localize(testAction.name) },
{ parent: parent }
);
action.use();
};
}

View file

@ -134,6 +134,12 @@ div.daggerheart.views.multiclass {
}
.downtime-container {
.downtime-header {
margin: 0;
color: light-dark(@dark-blue, @golden);
text-align: center;
}
.activity-container {
display: flex;
align-items: center;
@ -150,12 +156,32 @@ div.daggerheart.views.multiclass {
}
.activity-image {
width: 120px;
width: 80px;
position: relative;
display: flex;
justify-content: center;
margin-right: 8px;
border: 2px solid black;
border-radius: 50%;
margin-right: 8px;
cursor: pointer;
.activity-select-label {
position: absolute;
top: -9px;
font-size: 14px;
border: 1px solid light-dark(@dark-blue, @golden);
border-radius: 6px;
color: light-dark(@beige, @dark);
background-image: url(../assets/parchments/dh-parchment-light.png);
padding: 0 8px;
line-height: 1;
font-weight: bold;
}
img {
border-radius: 50%;
}
&:hover,
&.selected {
filter: drop-shadow(0 0 6px gold);

View file

@ -1887,6 +1887,11 @@ div.daggerheart.views.multiclass {
.daggerheart.views.levelup .levelup-section .levelup-container .levelup-inner-container .levelup-posttext {
padding: 8px 0;
}
.daggerheart.views .downtime-container .downtime-header {
margin: 0;
color: light-dark(#18162e, #f3c267);
text-align: center;
}
.daggerheart.views .downtime-container .activity-container {
display: flex;
align-items: center;
@ -1902,12 +1907,30 @@ div.daggerheart.views.multiclass {
font-weight: bold;
}
.daggerheart.views .downtime-container .activity-container .activity-title .activity-image {
width: 120px;
width: 80px;
position: relative;
display: flex;
justify-content: center;
margin-right: 8px;
border: 2px solid black;
border-radius: 50%;
margin-right: 8px;
cursor: pointer;
}
.daggerheart.views .downtime-container .activity-container .activity-title .activity-image .activity-select-label {
position: absolute;
top: -9px;
font-size: 14px;
border: 1px solid light-dark(#18162e, #f3c267);
border-radius: 6px;
color: light-dark(#efe6d8, #222);
background-image: url(../assets/parchments/dh-parchment-light.png);
padding: 0 8px;
line-height: 1;
font-weight: bold;
}
.daggerheart.views .downtime-container .activity-container .activity-title .activity-image img {
border-radius: 50%;
}
.daggerheart.views .downtime-container .activity-container .activity-title .activity-image:hover,
.daggerheart.views .downtime-container .activity-container .activity-title .activity-image.selected {
filter: drop-shadow(0 0 6px gold);

View file

@ -1,16 +1,11 @@
<div class="daggerheart chat downtime">
<h2 class="downtime-title-container">
<div>{{this.player}} {{localize "DAGGERHEART.Chat.Downtime.Title"}}</div>
<div class="downtime-subtitle">{{this.title}}</div>
<div>{{title}}</div>
</h2>
<img class="downtime-image" src="{{this.img}}" />
<div>{{{this.description}}}</div>
<div class="downtime-refresh-container">
<div class="refresh-title">Refreshed Features</div>
{{#each this.refreshedFeatures}}
<div class="refresh-inner-container">
<div>{{this.name}}</div>
</div>
{{/each}}
</div>
{{#each moves}}
<strong>{{this.name}}</strong>
<img class="downtime-image" src="{{this.img}}" />
<div>{{{this.description}}}</div>
{{#if (gt this.actions.length 0)}}<button class="action-use-button">{{localize "Action"}}</button>{{/if}}
{{/each}}
</div>

View file

@ -1,9 +1,14 @@
<div>
<div class="downtime-container">
{{#each this.options as |option key|}}
<h2 class="downtime-header">{{localize "DAGGERHEART.Downtime.DowntimeHeader" current=nrCurrentChoices max=moveData.nrChoices}}</h2>
{{#each moveData.moves as |move key|}}
<div class="activity-container">
<div class="activity-title">
<img class="activity-image {{#if (eq ../selectedActivity.id key)}}selected{{/if}}" src="{{option.img}}" data-action="selectActivity" data-activity="{{key}}" />
<div class="activity-image {{#if this.selected}}selected{{/if}}" data-action="selectMove" data-move="{{key}}">
{{#if this.selected}}<div class="activity-select-label">{{move.selected}}</div>{{/if}}
<img src="{{move.img}}" />
</div>
<span class="activity-title-text">{{localize this.name}}</span>
</div>
<div class="activity-body">
@ -11,18 +16,9 @@
</div>
</div>
{{/each}}
<div class="activity-container">
<div class="activity-title">
<img class="activity-image {{#if (eq selectedActivity this.customActivity)}}selected{{/if}}" src="{{this.customActivity.img}}" data-action="selectActivity" data-activity="{{this.customActivity.id}}" />
<input class="custom-name-input" type="text" name="name" value="{{this.customActivity.name}}" placeholder="{{localize this.customActivity.namePlaceholder}}" />
</div>
<div class="activity-body">
<textarea class="activity-text-area" name="description" placeholder="{{localize this.customActivity.placeholder}}">{{this.customActivity.description}}</textarea>
</div>
</div>
</div>
<footer class="flexrow">
<button data-action="takeDowntime" {{#if this.disabledDowntime}}disabled{{/if}}>{{localize "DAGGERHEART.Application.Downtime.TakeDowntime"}}</button>
<button data-action="close">{{localize "DAGGERHEART.Application.Cancel"}}</button>
<button type="button" data-action="close">{{localize "DAGGERHEART.Application.Cancel"}}</button>
<button type="button" data-action="takeDowntime" {{#if this.disabledDowntime}}disabled{{/if}}>{{localize "DAGGERHEART.Application.Downtime.TakeDowntime"}}</button>
</footer>
</div>