mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 04:01:06 +01:00
Added countdown actions
This commit is contained in:
parent
a146132171
commit
dccb0bfa2d
16 changed files with 159 additions and 7 deletions
|
|
@ -46,6 +46,10 @@
|
|||
"name": "Beastform",
|
||||
"tooltip": "Shapeshift the user into another form."
|
||||
},
|
||||
"countdown": {
|
||||
"name": "Countdown",
|
||||
"tooltip": "Start a countdown"
|
||||
},
|
||||
"damage": {
|
||||
"name": "Damage",
|
||||
"tooltip": "Direct damage without a roll."
|
||||
|
|
@ -73,6 +77,9 @@
|
|||
"exactHint": "The Character's Tier is used if empty",
|
||||
"label": "Beastform"
|
||||
},
|
||||
"countdown": {
|
||||
"defaultOwnership": "Default Ownership"
|
||||
},
|
||||
"damage": {
|
||||
"multiplier": "Multiplier",
|
||||
"flatMultiplier": "Flat Multiplier"
|
||||
|
|
|
|||
|
|
@ -200,7 +200,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
const data = this.action.toObject(),
|
||||
key = event.target.closest('[data-key]').dataset.key;
|
||||
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) });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
|
|||
const countdown = this.data.countdowns[key];
|
||||
acc[key] = {
|
||||
...countdown,
|
||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].name),
|
||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
|
||||
progress: {
|
||||
...countdown.progress,
|
||||
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownTypes[countdown.progress.type].label)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@ export const actionTypes = {
|
|||
icon: 'fa-khanda',
|
||||
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: {
|
||||
id: 'healing',
|
||||
name: 'DAGGERHEART.ACTIONS.TYPES.healing.name',
|
||||
|
|
|
|||
|
|
@ -673,11 +673,11 @@ export const simpleOwnershiplevels = {
|
|||
export const countdownBaseTypes = {
|
||||
narrative: {
|
||||
id: 'narrative',
|
||||
name: 'DAGGERHEART.APPLICATIONS.Countdown.types.narrative'
|
||||
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.narrative'
|
||||
},
|
||||
encounter: {
|
||||
id: 'encounter',
|
||||
name: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter'
|
||||
label: 'DAGGERHEART.APPLICATIONS.Countdown.types.encounter'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ export { default as DhCombat } from './combat.mjs';
|
|||
export { default as DhCombatant } from './combatant.mjs';
|
||||
export { default as DhTagTeamRoll } from './tagTeamRoll.mjs';
|
||||
|
||||
export * as countdowns from './countdowns.mjs';
|
||||
export * as actions from './action/_module.mjs';
|
||||
export * as activeEffects from './activeEffect/_module.mjs';
|
||||
export * as actors from './actor/_module.mjs';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import AttackAction from './attackAction.mjs';
|
||||
import BaseAction from './baseAction.mjs';
|
||||
import BeastformAction from './beastformAction.mjs';
|
||||
import CountdownAction from './countdownAction.mjs';
|
||||
import DamageAction from './damageAction.mjs';
|
||||
import EffectAction from './effectAction.mjs';
|
||||
import HealingAction from './healingAction.mjs';
|
||||
|
|
@ -10,6 +11,7 @@ import SummonAction from './summonAction.mjs';
|
|||
export const actionsTypes = {
|
||||
base: BaseAction,
|
||||
attack: AttackAction,
|
||||
countdown: CountdownAction,
|
||||
damage: DamageAction,
|
||||
healing: HealingAction,
|
||||
summon: SummonAction,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,13 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
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.
|
||||
*
|
||||
|
|
|
|||
15
module/data/action/countdownAction.mjs
Normal file
15
module/data/action/countdownAction.mjs
Normal 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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
export { default as CostField } from './costField.mjs';
|
||||
export { default as CountdownField } from './countdownField.mjs';
|
||||
export { default as UsesField } from './usesField.mjs';
|
||||
export { default as RangeField } from './rangeField.mjs';
|
||||
export { default as TargetField } from './targetField.mjs';
|
||||
|
|
|
|||
89
module/data/fields/action/countdownField.mjs
Normal file
89
module/data/fields/action/countdownField.mjs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ export const preloadHandlebarsTemplates = async function () {
|
|||
'systems/daggerheart/templates/actionTypes/range-target.hbs',
|
||||
'systems/daggerheart/templates/actionTypes/effect.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/ui/tooltip/parts/tooltipChips.hbs',
|
||||
'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs',
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
.countdown-edit-container {
|
||||
display: grid;
|
||||
grid-template-columns: 48px 1fr 64px;
|
||||
grid-template-columns: 48px 1fr 72px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
|
|
|
|||
21
templates/actionTypes/countdown.hbs
Normal file
21
templates/actionTypes/countdown.hbs
Normal 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>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<section
|
||||
<section
|
||||
class="tab {{this.tabs.effect.cssClass}}"
|
||||
data-group="primary"
|
||||
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.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.countdown}}{{> 'systems/daggerheart/templates/actionTypes/countdown.hbs' fields=fields.countdown.element.fields source=source.countdown}}{{/if}}
|
||||
</section>
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
<div class="countdown-edit-input">
|
||||
<label>{{localize "DAGGERHEART.APPLICATIONS.CountdownEdit.category"}}</label>
|
||||
<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>
|
||||
</div>
|
||||
<div class="countdown-edit-input">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue