mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 19:51:08 +01:00
Added countdown actions
This commit is contained in:
parent
a146132171
commit
dccb0bfa2d
16 changed files with 159 additions and 7 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue