Added countdown actions

This commit is contained in:
WBHarry 2025-11-17 23:02:22 +01:00
parent a146132171
commit dccb0bfa2d
16 changed files with 159 additions and 7 deletions

View file

@ -46,6 +46,10 @@
"name": "Beastform", "name": "Beastform",
"tooltip": "Shapeshift the user into another form." "tooltip": "Shapeshift the user into another form."
}, },
"countdown": {
"name": "Countdown",
"tooltip": "Start a countdown"
},
"damage": { "damage": {
"name": "Damage", "name": "Damage",
"tooltip": "Direct damage without a roll." "tooltip": "Direct damage without a roll."
@ -73,6 +77,9 @@
"exactHint": "The Character's Tier is used if empty", "exactHint": "The Character's Tier is used if empty",
"label": "Beastform" "label": "Beastform"
}, },
"countdown": {
"defaultOwnership": "Default Ownership"
},
"damage": { "damage": {
"multiplier": "Multiplier", "multiplier": "Multiplier",
"flatMultiplier": "Flat Multiplier" "flatMultiplier": "Flat Multiplier"

View file

@ -200,7 +200,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
const data = this.action.toObject(), const data = this.action.toObject(),
key = event.target.closest('[data-key]').dataset.key; key = event.target.closest('[data-key]').dataset.key;
if (!this.action[key]) return; if (!this.action[key]) return;
data[key].push({});
data[key].push(this.action.defaultValues[key] ?? {});
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
} }

View file

@ -50,7 +50,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
const countdown = this.data.countdowns[key]; const countdown = this.data.countdowns[key];
acc[key] = { acc[key] = {
...countdown, ...countdown,
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].name), typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
progress: { progress: {
...countdown.progress, ...countdown.progress,
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownTypes[countdown.progress.type].label) typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownTypes[countdown.progress.type].label)

View file

@ -5,6 +5,12 @@ export const actionTypes = {
icon: 'fa-khanda', icon: 'fa-khanda',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.attack.tooltip' tooltip: 'DAGGERHEART.ACTIONS.TYPES.attack.tooltip'
}, },
countdown: {
id: 'countdown',
name: 'DAGGERHEART.ACTIONS.TYPES.countdown.name',
icon: 'fa-hourglass-half',
tooltip: 'DAGGERHEART.ACTIONS.TYPES.countdown.tooltip'
},
healing: { healing: {
id: 'healing', id: 'healing',
name: 'DAGGERHEART.ACTIONS.TYPES.healing.name', name: 'DAGGERHEART.ACTIONS.TYPES.healing.name',

View file

@ -673,11 +673,11 @@ export const simpleOwnershiplevels = {
export const countdownBaseTypes = { export const countdownBaseTypes = {
narrative: { narrative: {
id: 'narrative', id: 'narrative',
name: 'DAGGERHEART.APPLICATIONS.Countdown.types.narrative' label: 'DAGGERHEART.APPLICATIONS.Countdown.types.narrative'
}, },
encounter: { encounter: {
id: 'encounter', id: 'encounter',
name: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter' label: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter'
} }
}; };

View file

@ -2,6 +2,7 @@ export { default as DhCombat } from './combat.mjs';
export { default as DhCombatant } from './combatant.mjs'; export { default as DhCombatant } from './combatant.mjs';
export { default as DhTagTeamRoll } from './tagTeamRoll.mjs'; export { default as DhTagTeamRoll } from './tagTeamRoll.mjs';
export * as countdowns from './countdowns.mjs';
export * as actions from './action/_module.mjs'; export * as actions from './action/_module.mjs';
export * as activeEffects from './activeEffect/_module.mjs'; export * as activeEffects from './activeEffect/_module.mjs';
export * as actors from './actor/_module.mjs'; export * as actors from './actor/_module.mjs';

View file

@ -1,6 +1,7 @@
import AttackAction from './attackAction.mjs'; import AttackAction from './attackAction.mjs';
import BaseAction from './baseAction.mjs'; import BaseAction from './baseAction.mjs';
import BeastformAction from './beastformAction.mjs'; import BeastformAction from './beastformAction.mjs';
import CountdownAction from './countdownAction.mjs';
import DamageAction from './damageAction.mjs'; import DamageAction from './damageAction.mjs';
import EffectAction from './effectAction.mjs'; import EffectAction from './effectAction.mjs';
import HealingAction from './healingAction.mjs'; import HealingAction from './healingAction.mjs';
@ -10,6 +11,7 @@ import SummonAction from './summonAction.mjs';
export const actionsTypes = { export const actionsTypes = {
base: BaseAction, base: BaseAction,
attack: AttackAction, attack: AttackAction,
countdown: CountdownAction,
damage: DamageAction, damage: DamageAction,
healing: HealingAction, healing: HealingAction,
summon: SummonAction, summon: SummonAction,

View file

@ -43,6 +43,13 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
return schemaFields; return schemaFields;
} }
/**
* The default values to supply to schema fields when they are created in the actionConfig. Defined by implementing classes.
*/
get defaultValues() {
return {};
}
/** /**
* Create a Map containing each Action step based on fields define in schema. Ordered by Fields order property. * Create a Map containing each Action step based on fields define in schema. Ordered by Fields order property.
* *

View file

@ -0,0 +1,15 @@
import DHBaseAction from './baseAction.mjs';
export default class DhCountdownAction extends DHBaseAction {
static extraSchemas = [...super.extraSchemas, 'countdown'];
get defaultValues() {
return {
...super.defaultValues,
countdown: {
name: this.parent.parent.name,
img: this.img
}
};
}
}

View file

@ -1,4 +1,5 @@
export { default as CostField } from './costField.mjs'; export { default as CostField } from './costField.mjs';
export { default as CountdownField } from './countdownField.mjs';
export { default as UsesField } from './usesField.mjs'; export { default as UsesField } from './usesField.mjs';
export { default as RangeField } from './rangeField.mjs'; export { default as RangeField } from './rangeField.mjs';
export { default as TargetField } from './targetField.mjs'; export { default as TargetField } from './targetField.mjs';

View file

@ -0,0 +1,89 @@
import { emitAsGM, GMUpdateEvent, RefreshType, socketEvent } from '../../../systemRegistration/socket.mjs';
const fields = foundry.data.fields;
export default class CountdownField extends fields.ArrayField {
constructor(options = {}, context = {}) {
const element = new fields.SchemaField({
...game.system.api.data.countdowns.DhCountdown.defineSchema(),
type: new fields.StringField({
required: true,
choices: CONFIG.DH.GENERAL.countdownBaseTypes,
initial: CONFIG.DH.GENERAL.countdownBaseTypes.encounter.id,
label: 'DAGGERHEART.GENERAL.type'
}),
name: new fields.StringField({
required: true,
initial: game.i18n.localize('DAGGERHEART.APPLICATIONS.Countdown.newCountdown'),
label: 'DAGGERHEART.APPLICATIONS.Countdown.FIELDS.countdowns.element.name.label'
}),
defaultOwnership: new fields.NumberField({
required: true,
choices: CONFIG.DH.GENERAL.simpleOwnershiplevels,
initial: CONST.DOCUMENT_OWNERSHIP_LEVELS.INHERIT,
label: 'DAGGERHEART.ACTIONS.Config.countdown.defaultOwnership'
})
});
super(element, options, context);
}
/**
* Countdown Action Workflow part.
* Must be called within Action context or similar. Requires a GM online to edit the game setting for countdowns.
* @param {object} config Object that contains workflow datas. Usually made from Action Fields prepareConfig methods.
*/
static async execute(config) {
const noGM = !game.users.find(x => x.isGM && x.active);
if (noGM) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.gmRequired'));
return;
}
const data = config.countdowns.reduce(
(acc, curr) => {
acc.countdowns[foundry.utils.randomID()] = {
...curr,
progress: {
...curr.progress,
current: curr.progress.max
}
};
return acc;
},
{ countdowns: {} }
);
await emitAsGM(
GMUpdateEvent.UpdateCountdowns,
async () => {
const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
await countdownSetting.updateSource(data);
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Countdowns,
countdownSetting.toObject()
),
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.Refresh,
data: { refreshType: RefreshType.Countdown }
});
Hooks.callAll(socketEvent.Refresh, { refreshType: RefreshType.Countdown });
},
data,
null,
{
refreshType: RefreshType.Countdown
}
);
}
/**
* Update Action Workflow config object.
* Must be called within Action context.
* @param {object} config Object that contains workflow datas. Usually made from Action Fields prepareConfig methods.
*/
prepareConfig(config) {
config.countdowns = this.countdown;
return config;
}
}

View file

@ -28,6 +28,7 @@ export const preloadHandlebarsTemplates = async function () {
'systems/daggerheart/templates/actionTypes/range-target.hbs', 'systems/daggerheart/templates/actionTypes/range-target.hbs',
'systems/daggerheart/templates/actionTypes/effect.hbs', 'systems/daggerheart/templates/actionTypes/effect.hbs',
'systems/daggerheart/templates/actionTypes/beastform.hbs', 'systems/daggerheart/templates/actionTypes/beastform.hbs',
'systems/daggerheart/templates/actionTypes/countdown.hbs',
'systems/daggerheart/templates/settings/components/settings-item-line.hbs', 'systems/daggerheart/templates/settings/components/settings-item-line.hbs',
'systems/daggerheart/templates/ui/tooltip/parts/tooltipChips.hbs', 'systems/daggerheart/templates/ui/tooltip/parts/tooltipChips.hbs',
'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs', 'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs',

View file

@ -65,7 +65,7 @@
.countdown-edit-container { .countdown-edit-container {
display: grid; display: grid;
grid-template-columns: 48px 1fr 64px; grid-template-columns: 48px 1fr 72px;
align-items: center; align-items: center;
gap: 8px; gap: 8px;

View file

@ -0,0 +1,21 @@
<fieldset class="one-column" data-key="countdown">
<legend>
{{localize "DAGGERHEART.ACTIONS.TYPES.countdown.name"}}
<a><i class="fa-solid fa-plus icon-button" data-action="addElement"></i></a>
</legend>
{{#each source as |countdown index|}}
<div class="nest-inputs">
{{formField ../fields.name value=countdown.name name=(concat "countdown." index ".name") localize=true}}
<a class="btn" data-tooltip="{{localize "CONTROLS.CommonDelete"}}" data-action="removeElement" data-index="{{index}}"><i class="fas fa-trash"></i></a>
</div>
<div class="nest-inputs">
{{formField ../fields.type value=countdown.type name=(concat "countdown." index ".type") localize=true}}
{{formField ../fields.defaultOwnership value=countdown.defaultOwnership name=(concat "countdown." index ".defaultOwnership") localize=true}}
</div>
{{formField ../fields.img value=countdown.img name=(concat "countdown." index ".img") label="DAGGERHEART.GENERAL.imagePath" localize=true}}
<div class="nest-inputs">
{{formField ../fields.progress.fields.type value=countdown.progress.type name=(concat "countdown." index ".progress.type") localize=true}}
{{formField ../fields.progress.fields.max value=countdown.progress.max name=(concat "countdown." index ".progress.max") localize=true}}
</div>
{{/each}}
</fieldset>

View file

@ -1,4 +1,4 @@
<section <section
class="tab {{this.tabs.effect.cssClass}}" class="tab {{this.tabs.effect.cssClass}}"
data-group="primary" data-group="primary"
data-tab="effect" data-tab="effect"
@ -9,4 +9,5 @@
{{#if fields.macro}}{{> 'systems/daggerheart/templates/actionTypes/macro.hbs' fields=fields.macro source=source.macro}}{{/if}} {{#if fields.macro}}{{> 'systems/daggerheart/templates/actionTypes/macro.hbs' fields=fields.macro source=source.macro}}{{/if}}
{{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}} {{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}}
{{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}} {{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}}
{{#if fields.countdown}}{{> 'systems/daggerheart/templates/actionTypes/countdown.hbs' fields=fields.countdown.element.fields source=source.countdown}}{{/if}}
</section> </section>

View file

@ -59,7 +59,7 @@
<div class="countdown-edit-input"> <div class="countdown-edit-input">
<label>{{localize "DAGGERHEART.APPLICATIONS.CountdownEdit.category"}}</label> <label>{{localize "DAGGERHEART.APPLICATIONS.CountdownEdit.category"}}</label>
<select name="{{concat "countdowns." id ".type"}}"> <select name="{{concat "countdowns." id ".type"}}">
{{selectOptions ../countdownBaseTypes selected=countdown.type valueAttr="id" labelAttr="name" localize=true}} {{selectOptions ../countdownBaseTypes selected=countdown.type localize=true}}
</select> </select>
</div> </div>
<div class="countdown-edit-input"> <div class="countdown-edit-input">