mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
[V14] Refactor ArmorChange schema and fix some bugs (#1742)
* Refactor ArmorChange schema and fix some bugs * Add current back to schema * Fixed so changing armor values and taking damage works again * Fixed so that scrolltexts for armor changes work again * Removed old marks on armor.system * Restored damageReductionDialog armorScore.value * Use toggle for css class addition/removal * Fix armor change type choices * Added ArmorChange DamageThresholds --------- Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
6193153596
commit
50dcbf4396
68 changed files with 356 additions and 428 deletions
|
|
@ -27,11 +27,11 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
true
|
||||
);
|
||||
const armor = orderedArmorEffects.reduce((acc, effect) => {
|
||||
const { value, max } = effect.system.armorData;
|
||||
const { current, max } = effect.system.armorData;
|
||||
acc.push({
|
||||
effect: effect,
|
||||
marks: [...Array(max).keys()].reduce((acc, _, index) => {
|
||||
const spent = index < value;
|
||||
const spent = index < current;
|
||||
acc[foundry.utils.randomID()] = { selected: false, disabled: spent, spent };
|
||||
return acc;
|
||||
}, {})
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
htmlElement
|
||||
.querySelector('.armor-change-checkbox')
|
||||
?.addEventListener('change', this.armorChangeToggle.bind(this));
|
||||
|
||||
htmlElement
|
||||
.querySelector('.armor-damage-thresholds-checkbox')
|
||||
?.addEventListener('change', this.armorDamageThresholdToggle.bind(this));
|
||||
}
|
||||
|
||||
async _prepareContext(options) {
|
||||
|
|
@ -190,23 +194,14 @@ 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 });
|
||||
const typedChanges = context.source.changes.reduce((acc, change, index) => {
|
||||
if (singleTypes.includes(change.type)) {
|
||||
acc[change.type] = { ...change, index };
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
partContext.changes = await Promise.all(
|
||||
foundry.utils.deepClone(base ?? []).map(c => this._prepareChangeContext(c, fields))
|
||||
);
|
||||
partContext.changes = partContext.changes.filter(c => !!c);
|
||||
partContext.typedChanges = typedChanges;
|
||||
break;
|
||||
}
|
||||
|
|
@ -238,29 +233,51 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
|||
return this.submit({ updateData: { system: { changes } } });
|
||||
}
|
||||
|
||||
_prepareChangeContext(change, fields) {
|
||||
armorDamageThresholdToggle(event) {
|
||||
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
||||
const changes = Object.values(submitData.system?.changes ?? {});
|
||||
const index = Number(event.target.dataset.index);
|
||||
if (event.target.checked) {
|
||||
changes[index].value.damageThresholds = { major: 0, severe: 0 };
|
||||
} else {
|
||||
changes[index].value.damageThresholds = null;
|
||||
}
|
||||
|
||||
return this.submit({ updateData: { system: { changes } } });
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
_renderChange(context) {
|
||||
const { change, index, defaultPriority } = context;
|
||||
if (!(change.type in CONFIG.DH.GENERAL.baseActiveEffectModes)) return null;
|
||||
|
||||
const changeTypesSchema = this.document.system.schema.fields.changes.element.types;
|
||||
const fields = context.fields ?? (changeTypesSchema[change.type] ?? changeTypesSchema.add).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.${change.index}.${fieldName}`;
|
||||
paths[`${fieldName}Path`] = `system.changes.${index}.${fieldName}`;
|
||||
return paths;
|
||||
}, {})
|
||||
);
|
||||
return (
|
||||
game.system.api.documents.DhActiveEffect.CHANGE_TYPES[change.type].render?.(
|
||||
change,
|
||||
change.index,
|
||||
index,
|
||||
defaultPriority
|
||||
) ??
|
||||
foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/sheets/activeEffect/change.hbs',
|
||||
{
|
||||
change,
|
||||
index: change.index,
|
||||
index,
|
||||
defaultPriority,
|
||||
fields
|
||||
fields,
|
||||
types: Object.keys(CONFIG.DH.GENERAL.baseActiveEffectModes).reduce((r, key) => {
|
||||
r[key] = CONFIG.DH.GENERAL.baseActiveEffectModes[key].label;
|
||||
return r;
|
||||
}, {})
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1003,16 +1003,16 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
||||
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 current = Math.max(Math.min(Number.parseInt(event.target.value), effect.system.armorData.max), 0);
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? value : change.value
|
||||
value: change.type === 'armor' ? { ...change.value, current } : change.value
|
||||
}));
|
||||
|
||||
event.target.value = value;
|
||||
event.target.value = current;
|
||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
||||
progressBar.value = value;
|
||||
progressBar.value = current;
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
}
|
||||
|
|
@ -1023,27 +1023,22 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
|
||||
const { value } = effect.system.armorData;
|
||||
const { current } = effect.system.armorData;
|
||||
|
||||
const inputValue = Number.parseInt(target.dataset.value);
|
||||
const decreasing = value >= inputValue;
|
||||
const newValue = decreasing ? inputValue - 1 : inputValue;
|
||||
const decreasing = current >= inputValue;
|
||||
const newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? newValue : change.value
|
||||
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
||||
}));
|
||||
|
||||
const container = target.closest('.slot-bar');
|
||||
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
||||
const index = Number.parseInt(armorSlot.dataset.index);
|
||||
if (decreasing && index >= newValue) {
|
||||
armorSlot.classList.remove('fa-shield');
|
||||
armorSlot.classList.add('fa-shield-halved');
|
||||
} else if (!decreasing && index < newValue) {
|
||||
armorSlot.classList.add('fa-shield');
|
||||
armorSlot.classList.remove('fa-shield-halved');
|
||||
}
|
||||
const marked = !decreasing && Number.parseInt(armorSlot.dataset.index) < newCurrent;
|
||||
armorSlot.classList.toggle('fa-shield', marked);
|
||||
armorSlot.classList.toggle('fa-shield-halved', !marked);
|
||||
}
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
|||
context.armorScore = this.document.system.armorData.max;
|
||||
break;
|
||||
case 'effects':
|
||||
context.effects.actives = context.effects.actives.filter(x => x.type !== 'armor');
|
||||
context.effects.inactives = context.effects.actives.filter(x => x.type !== 'armor');
|
||||
context.effects.actives = context.effects.actives.filter(x => !x.system.armorData);
|
||||
context.effects.inactives = context.effects.inactives.filter(x => !x.system.armorData);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -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.armorChange.typeData.updateArmorMax(value);
|
||||
await armorEffect.system.armorChange.updateArmorMax(value);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue