mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
[Feature] ArmorEffect reworked into ChangeType on BaseEffect (#1739)
* Initial * . * Single armor rework start * More fixes * Fixed DamageReductionDialog * Removed last traces of ArmorEffect * .
This commit is contained in:
parent
0b5de79ca8
commit
b5e0bb7c27
26 changed files with 339 additions and 416 deletions
|
|
@ -21,13 +21,12 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
this.rulesDefault
|
||||
);
|
||||
|
||||
const allArmorEffects = Array.from(actor.allApplicableEffects()).filter(x => x.type === 'armor');
|
||||
const orderedArmorEffects = game.system.api.data.activeEffects.ArmorEffect.orderEffectsForAutoChange(
|
||||
const allArmorEffects = Array.from(actor.allApplicableEffects()).filter(x => x.system.armorData);
|
||||
const orderedArmorEffects = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
||||
allArmorEffects,
|
||||
true
|
||||
);
|
||||
const armor = orderedArmorEffects.reduce((acc, effect) => {
|
||||
if (effect.type !== 'armor') return acc;
|
||||
const { value, max } = effect.system.armorData;
|
||||
acc.push({
|
||||
effect: effect,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ 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';
|
||||
|
|
|
|||
|
|
@ -150,6 +150,10 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
minLength: 0
|
||||
});
|
||||
});
|
||||
|
||||
htmlElement
|
||||
.querySelector('.armor-change-checkbox')
|
||||
?.addEventListener('change', this.armorChangeToggle.bind(this));
|
||||
}
|
||||
|
||||
async _prepareContext(options) {
|
||||
|
|
@ -187,38 +191,74 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
break;
|
||||
case 'changes':
|
||||
const fields = this.document.system.schema.fields.changes.element.fields;
|
||||
|
||||
const singleTypes = ['armor'];
|
||||
const { base, ...typedChanges } = context.source.changes.reduce((acc, change, index) => {
|
||||
const type = CONFIG.DH.GENERAL.baseActiveEffectModes[change.type] ? 'base' : change.type;
|
||||
if (singleTypes.includes(type)) {
|
||||
acc[type] = { ...change, index };
|
||||
} else {
|
||||
if (!acc[type]) acc[type] = [];
|
||||
acc[type].push({ ...change, index });
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
partContext.changes = await Promise.all(
|
||||
foundry.utils
|
||||
.deepClone(context.source.changes)
|
||||
.map((c, i) => this._prepareChangeContext(c, i, fields))
|
||||
foundry.utils.deepClone(base ?? []).map(c => this._prepareChangeContext(c, fields))
|
||||
);
|
||||
partContext.typedChanges = typedChanges;
|
||||
break;
|
||||
}
|
||||
|
||||
return partContext;
|
||||
}
|
||||
|
||||
_prepareChangeContext(change, index, fields) {
|
||||
armorChangeToggle(event) {
|
||||
if (event.target.checked) {
|
||||
this.addArmorChange();
|
||||
} else {
|
||||
this.removeTypedChange(event.target.dataset.index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Could be generalised if needed later */
|
||||
addArmorChange() {
|
||||
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
||||
const changes = Object.values(submitData.system?.changes ?? {});
|
||||
changes.push(game.system.api.data.activeEffects.changeTypes.armor.getInitialValue());
|
||||
return this.submit({ updateData: { system: { changes } } });
|
||||
}
|
||||
|
||||
removeTypedChange(indexString) {
|
||||
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
||||
const changes = Object.values(submitData.system.changes);
|
||||
const index = Number(indexString);
|
||||
changes.splice(index, 1);
|
||||
return this.submit({ updateData: { system: { changes } } });
|
||||
}
|
||||
|
||||
_prepareChangeContext(change, fields) {
|
||||
if (typeof change.value !== 'string') change.value = JSON.stringify(change.value);
|
||||
const defaultPriority = game.system.api.documents.DhActiveEffect.CHANGE_TYPES[change.type]?.defaultPriority;
|
||||
Object.assign(
|
||||
change,
|
||||
['key', 'type', 'value', 'priority'].reduce((paths, fieldName) => {
|
||||
paths[`${fieldName}Path`] = `system.changes.${index}.${fieldName}`;
|
||||
paths[`${fieldName}Path`] = `system.changes.${change.index}.${fieldName}`;
|
||||
return paths;
|
||||
}, {})
|
||||
);
|
||||
return (
|
||||
game.system.api.documents.DhActiveEffect.CHANGE_TYPES[change.type].render?.(
|
||||
change,
|
||||
index,
|
||||
change.index,
|
||||
defaultPriority
|
||||
) ??
|
||||
foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/sheets/activeEffect/change.hbs',
|
||||
{
|
||||
change,
|
||||
index,
|
||||
index: change.index,
|
||||
defaultPriority,
|
||||
fields
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
const { HandlebarsApplicationMixin, DocumentSheetV2 } = foundry.applications.api;
|
||||
|
||||
export default class ArmorActiveEffectConfig extends HandlebarsApplicationMixin(DocumentSheetV2) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'dh-style', 'active-effect-config', 'armor-effect-config'],
|
||||
form: {
|
||||
handler: this.updateForm,
|
||||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
position: { width: 560 },
|
||||
actions: {
|
||||
finish: ArmorActiveEffectConfig.#finish
|
||||
}
|
||||
};
|
||||
|
||||
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/activeEffect/armor/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];
|
||||
|
||||
switch (partId) {
|
||||
case 'details':
|
||||
partContext.isActorEffect = this.document.parent?.documentName === 'Actor';
|
||||
partContext.isItemEffect = this.document.parent?.documentName === 'Item';
|
||||
break;
|
||||
}
|
||||
|
||||
return partContext;
|
||||
}
|
||||
|
||||
static async updateForm(_event, _form, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
}
|
||||
|
||||
static #finish() {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -966,10 +966,13 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const armorSources = [];
|
||||
for (var effect of Array.from(this.document.allApplicableEffects())) {
|
||||
const origin = effect.origin ? await foundry.utils.fromUuid(effect.origin) : effect.parent;
|
||||
if (effect.type !== 'armor' || effect.disabled || effect.isSuppressed) continue;
|
||||
if (!effect.system.armorData || effect.disabled || effect.isSuppressed) continue;
|
||||
|
||||
const originIsActor = origin instanceof Actor;
|
||||
const name = originIsActor ? effect.name : origin.name;
|
||||
armorSources.push({
|
||||
uuid: effect.uuid,
|
||||
name: origin.name,
|
||||
name,
|
||||
...effect.system.armorData
|
||||
});
|
||||
}
|
||||
|
|
@ -1018,15 +1021,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
/** Update specific armor source */
|
||||
static async armorSourceUpdate(event) {
|
||||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
||||
if (effect.system.changes.length !== 1) return;
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
const value = Math.max(Math.min(Number.parseInt(event.target.value), effect.system.armorData.max), 0);
|
||||
|
||||
const newChanges = [
|
||||
{
|
||||
...effect.system.changes[0],
|
||||
value
|
||||
}
|
||||
];
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? value : change.value
|
||||
}));
|
||||
|
||||
event.target.value = value;
|
||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
||||
|
|
@ -1038,19 +1040,19 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
static async armorSourcePipUpdate(event) {
|
||||
const target = event.target.closest('.armor-slot');
|
||||
const effect = await foundry.utils.fromUuid(target.dataset.uuid);
|
||||
if (effect.system.changes.length !== 1) return;
|
||||
const { value, max } = effect.system.armorData;
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
|
||||
const { value } = effect.system.armorData;
|
||||
|
||||
const inputValue = Number.parseInt(target.dataset.value);
|
||||
const decreasing = value >= inputValue;
|
||||
const newValue = decreasing ? inputValue - 1 : inputValue;
|
||||
|
||||
const newChanges = [
|
||||
{
|
||||
...effect.system.changes[0],
|
||||
value: newValue
|
||||
}
|
||||
];
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? newValue : change.value
|
||||
}));
|
||||
|
||||
const container = target.closest('.slot-bar');
|
||||
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
||||
|
|
|
|||
|
|
@ -762,10 +762,6 @@ export default function DHApplicationMixin(Base) {
|
|||
data.system.domain = parent.system.domains[0];
|
||||
}
|
||||
|
||||
if (documentClass === 'ActiveEffect') {
|
||||
return cls.createDialog(data, { parent: this.document });
|
||||
}
|
||||
|
||||
const doc = await cls.create(data, { parent, renderSheet: !event.shiftKey });
|
||||
if (parentIsItem && type === 'feature') {
|
||||
await this.document.update({
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
|||
const armorEffect = this.document.system.armorEffect;
|
||||
if (Number.isNaN(value) || !armorEffect) return;
|
||||
|
||||
await armorEffect.system.updateArmorMax(value);
|
||||
await armorEffect.system.armorChange.typeData.updateArmorMax(value);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue