mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Initial
This commit is contained in:
parent
593105b163
commit
7bc5ea4910
12 changed files with 198 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ export { default as CompanionSettings } from './companion-settings.mjs';
|
|||
export { default as SettingActiveEffectConfig } from './setting-active-effect-config.mjs';
|
||||
export { default as SettingFeatureConfig } from './setting-feature-config.mjs';
|
||||
export { default as EnvironmentSettings } from './environment-settings.mjs';
|
||||
export { default as ArmorActiveEffectConfig } from './armorActiveEffectConfig.mjs';
|
||||
export { default as ActiveEffectConfig } from './activeEffectConfig.mjs';
|
||||
export { default as DhTokenConfig } from './token-config.mjs';
|
||||
export { default as DhPrototypeTokenConfig } from './prototype-token-config.mjs';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
const { HandlebarsApplicationMixin, DocumentSheetV2 } = foundry.applications.api;
|
||||
|
||||
export default class ArmorActiveEffectConfig extends HandlebarsApplicationMixin(DocumentSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['daggerheart', 'sheet', 'dh-style', 'active-effect-config', 'armor-effect-config'],
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
actions: {
|
||||
addEffect: ArmorActiveEffectConfig.#addEffect
|
||||
}
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
header: { template: 'systems/daggerheart/templates/sheets/activeEffect/header.hbs' },
|
||||
tabs: { template: 'templates/generic/tab-navigation.hbs' },
|
||||
details: { template: 'systems/daggerheart/templates/sheets/activeEffect/armor/details.hbs' },
|
||||
settings: { template: 'systems/daggerheart/templates/sheets/activeEffect/armor/settings.hbs' },
|
||||
footer: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-form-footer.hbs' }
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
sheet: {
|
||||
tabs: [
|
||||
{ id: 'details', icon: 'fa-solid fa-book' },
|
||||
{ id: 'settings', icon: 'fa-solid fa-bars', label: 'DAGGERHEART.GENERAL.Tabs.settings' }
|
||||
],
|
||||
initial: 'details',
|
||||
labelPrefix: 'EFFECT.TABS'
|
||||
}
|
||||
};
|
||||
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
context.systemFields = context.document.system.schema.fields;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async _preparePartContext(partId, context) {
|
||||
const partContext = await super._preparePartContext(partId, context);
|
||||
if (partId in partContext.tabs) partContext.tab = partContext.tabs[partId];
|
||||
|
||||
return partContext;
|
||||
}
|
||||
|
||||
async updateForm(_event, _form, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static #addEffect() {
|
||||
this.document.update({ 'system.changes': [...this.document.system.changes, {}] });
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
import BaseEffect from './baseEffect.mjs';
|
||||
import BeastformEffect from './beastformEffect.mjs';
|
||||
import HordeEffect from './hordeEffect.mjs';
|
||||
import ArmorEffect from './armorEffect.mjs';
|
||||
|
||||
export { BaseEffect, BeastformEffect, HordeEffect };
|
||||
export { BaseEffect, BeastformEffect, HordeEffect, ArmorEffect };
|
||||
|
||||
export const config = {
|
||||
base: BaseEffect,
|
||||
beastform: BeastformEffect,
|
||||
horde: HordeEffect
|
||||
horde: HordeEffect,
|
||||
armor: ArmorEffect
|
||||
};
|
||||
|
|
|
|||
64
module/data/activeEffect/armorEffect.mjs
Normal file
64
module/data/activeEffect/armorEffect.mjs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
export default class ArmorEffect extends foundry.data.ActiveEffectTypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
changes: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
blank: false,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectModes,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectModes.add.id,
|
||||
validate: ArmorEffect.#validateType
|
||||
}),
|
||||
phase: new fields.StringField({ required: true, blank: false, initial: 'initial' }),
|
||||
priority: new fields.NumberField(),
|
||||
marked: new fields.NumberField({
|
||||
required: true,
|
||||
integer: true,
|
||||
initial: 0,
|
||||
min: 0,
|
||||
label: 'DAGGERHEART.GENERAL.value'
|
||||
}),
|
||||
max: new fields.NumberField({
|
||||
required: true,
|
||||
integer: true,
|
||||
initial: 1,
|
||||
min: 1,
|
||||
label: 'DAGGERHEART.GENERAL.max'
|
||||
})
|
||||
})
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
static applyChangeField(model, change, field) {
|
||||
return [model, change, field];
|
||||
}
|
||||
|
||||
prepareBaseData() {
|
||||
for (const change of this.changes) {
|
||||
change.key = 'system.armorTest';
|
||||
change.value = Math.max(change.max - change.marked, change.max);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that an {@link EffectChangeData#type} string is well-formed.
|
||||
* @param {string} type The string to be validated
|
||||
* @returns {true}
|
||||
* @throws {Error} An error if the type string is malformed
|
||||
*/
|
||||
static #validateType(type) {
|
||||
if (type.length < 3) throw new Error('must be at least three characters long');
|
||||
if (!/^custom\.-?\d+$/.test(type) && !type.split('.').every(s => /^[a-z0-9]+$/i.test(s))) {
|
||||
throw new Error(
|
||||
'A change type must either be a sequence of dot-delimited, alpha-numeric substrings or of the form' +
|
||||
' "custom.{number}"'
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
throw new Error('The array of sub-types to restrict to must not be empty.');
|
||||
}
|
||||
|
||||
const creatableEffects = ['base'];
|
||||
const creatableEffects = ['base', 'armor'];
|
||||
const documentTypes = this.TYPES.filter(type => creatableEffects.includes(type)).map(type => {
|
||||
const labelKey = `TYPES.ActiveEffect.${type}`;
|
||||
const label = game.i18n.has(labelKey) ? game.i18n.localize(labelKey) : type;
|
||||
|
|
@ -140,6 +140,9 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
|||
|
||||
/**@inheritdoc*/
|
||||
static applyChangeField(model, change, field) {
|
||||
if (this.system?.applyChangeField)
|
||||
super.applyChangeField(...this.system.applyChangeField(model, change, field));
|
||||
|
||||
change.value = Number.isNumeric(change.value)
|
||||
? change.value
|
||||
: DhActiveEffect.getChangeValue(model, change, change.effect);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue