mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Single armor rework start
This commit is contained in:
parent
6e75b81806
commit
caea55ade4
7 changed files with 53 additions and 32 deletions
|
|
@ -281,7 +281,6 @@ Hooks.on('setup', () => {
|
||||||
...damageThresholds,
|
...damageThresholds,
|
||||||
'proficiency',
|
'proficiency',
|
||||||
'evasion',
|
'evasion',
|
||||||
'armorScore',
|
|
||||||
'scars',
|
'scars',
|
||||||
'levelData.level.current'
|
'levelData.level.current'
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,10 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
minLength: 0
|
minLength: 0
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
htmlElement
|
||||||
|
.querySelector('.armor-change-checkbox')
|
||||||
|
?.addEventListener('change', this.armorChangeToggle.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _prepareContext(options) {
|
async _prepareContext(options) {
|
||||||
|
|
@ -190,10 +194,17 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
break;
|
break;
|
||||||
case 'changes':
|
case 'changes':
|
||||||
const fields = this.document.system.schema.fields.changes.element.fields;
|
const fields = this.document.system.schema.fields.changes.element.fields;
|
||||||
|
|
||||||
|
const singleTypes = ['armor'];
|
||||||
const { base, ...typedChanges } = context.source.changes.reduce((acc, change, index) => {
|
const { base, ...typedChanges } = context.source.changes.reduce((acc, change, index) => {
|
||||||
const type = CONFIG.DH.GENERAL.baseActiveEffectModes[change.type] ? 'base' : change.type;
|
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] = [];
|
if (!acc[type]) acc[type] = [];
|
||||||
acc[type].push({ ...change, index });
|
acc[type].push({ ...change, index });
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
partContext.changes = await Promise.all(
|
partContext.changes = await Promise.all(
|
||||||
|
|
@ -206,14 +217,30 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
return partContext;
|
return partContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
armorChangeToggle(event) {
|
||||||
|
if (event.target.checked) {
|
||||||
|
this.addArmorChange();
|
||||||
|
} else {
|
||||||
|
this.removeTypedChange(event.target.dataset.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Could be generalised if needed later */
|
/* Could be generalised if needed later */
|
||||||
static #addTypedChange() {
|
addArmorChange() {
|
||||||
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form));
|
||||||
const changes = Object.values(submitData.system?.changes ?? {});
|
const changes = Object.values(submitData.system?.changes ?? {});
|
||||||
changes.push(game.system.api.data.activeEffects.changeTypes.armor.getInitialValue());
|
changes.push(game.system.api.data.activeEffects.changeTypes.armor.getInitialValue());
|
||||||
return this.submit({ updateData: { system: { changes } } });
|
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) {
|
_prepareChangeContext(change, fields) {
|
||||||
if (typeof change.value !== 'string') change.value = JSON.stringify(change.value);
|
if (typeof change.value !== 'string') change.value = JSON.stringify(change.value);
|
||||||
const defaultPriority = game.system.api.documents.DhActiveEffect.CHANGE_TYPES[change.type]?.defaultPriority;
|
const defaultPriority = game.system.api.documents.DhActiveEffect.CHANGE_TYPES[change.type]?.defaultPriority;
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,13 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get armorData() {
|
||||||
|
const armorChange = this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id);
|
||||||
|
if (!armorChange) return null;
|
||||||
|
|
||||||
|
return armorChange.armorData;
|
||||||
|
}
|
||||||
|
|
||||||
static getDefaultObject() {
|
static getDefaultObject() {
|
||||||
return {
|
return {
|
||||||
name: 'New Effect',
|
name: 'New Effect',
|
||||||
|
|
|
||||||
|
|
@ -76,36 +76,27 @@ export default class Armor extends foundry.abstract.DataModel {
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
|
|
||||||
get armorChange() {
|
get armorData() {
|
||||||
if (this.changes.length !== 1)
|
const actor = this.parent.parent?.actor?.type === 'character' ? this.parent.parent.actor : null;
|
||||||
throw new Error('Unexpected error. An armor effect should have a changes field of length 1.');
|
const maxParse = actor ? itemAbleRollParse(this.max, actor, this.parent.parent.parent) : null;
|
||||||
|
|
||||||
const actor = this.parent.actor?.type === 'character' ? this.parent.actor : null;
|
|
||||||
const changeData = this.changes[0];
|
|
||||||
const maxParse = actor ? itemAbleRollParse(changeData.max, actor, this.parent.parent) : null;
|
|
||||||
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
|
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
|
||||||
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
|
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...changeData,
|
value: this.value,
|
||||||
max: maxEvaluated ?? changeData.max
|
max: maxEvaluated ?? this.max
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get armorData() {
|
|
||||||
return { value: this.armorChange.value, max: this.armorChange.max };
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateArmorMax(newMax) {
|
async updateArmorMax(newMax) {
|
||||||
const { effect, ...baseChange } = this.armorChange;
|
|
||||||
const newChanges = [
|
const newChanges = [
|
||||||
{
|
...this.parent.changes.map(change => ({
|
||||||
...baseChange,
|
...change,
|
||||||
max: newMax,
|
value: change.type === 'armor' ? Math.min(this.parent.value, newMax) : change.value,
|
||||||
value: Math.min(this.armorChange.value, newMax)
|
typeData: change.type === 'armor' ? { ...change.typeData, max: newMax } : change.typeData
|
||||||
}
|
}))
|
||||||
];
|
];
|
||||||
await this.parent.update({ 'system.changes': newChanges });
|
await this.parent.parent.update({ 'system.changes': newChanges });
|
||||||
}
|
}
|
||||||
|
|
||||||
static orderEffectsForAutoChange(armorEffects, increasing) {
|
static orderEffectsForAutoChange(armorEffects, increasing) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
.armor-change-container {
|
.armor-change-container {
|
||||||
header,
|
header,
|
||||||
ol {
|
ol {
|
||||||
grid-template-columns: 6rem 6rem 12rem 4rem 1rem;
|
grid-template-columns: 6rem 6rem 12rem 4rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<fieldset class="armor-change-container">
|
<fieldset class="armor-change-container">
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.armor"}} <a data-action="addTypedChange"><i class="fa-solid fa-plus"></i></a></legend>
|
<legend>{{localize "DAGGERHEART.GENERAL.armor"}} <input type="checkbox" class="armor-change-checkbox" data-index="{{typedChanges.armor.index}}" {{checked typedChanges.armor}} /></legend>
|
||||||
|
{{#if typedChanges.armor}}
|
||||||
<header>
|
<header>
|
||||||
<div>{{localize "EFFECT.FIELDS.changes.element.value.label"}}</div>
|
<div>{{localize "EFFECT.FIELDS.changes.element.value.label"}}</div>
|
||||||
<div>{{localize "DAGGERHEART.GENERAL.max"}}</div>
|
<div>{{localize "DAGGERHEART.GENERAL.max"}}</div>
|
||||||
|
|
@ -24,10 +24,8 @@
|
||||||
<div>{{localize "EFFECT.FIELDS.changes.element.priority.label"}}</div>
|
<div>{{localize "EFFECT.FIELDS.changes.element.priority.label"}}</div>
|
||||||
</header>
|
</header>
|
||||||
<ol class="scrollable">
|
<ol class="scrollable">
|
||||||
{{#each typedChanges.armor as |armor|}}
|
{{> "systems/daggerheart/templates/sheets/activeEffect/typeChanges/armorChange.hbs" typedChanges.armor fields=@root.systemFields.changes.element.fields}}
|
||||||
{{> "systems/daggerheart/templates/sheets/activeEffect/typeChanges/armorChange.hbs" armor fields=@root.systemFields.changes.element.fields}}
|
|
||||||
{{/each}}
|
|
||||||
</ol>
|
</ol>
|
||||||
|
{{/if}}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,4 @@
|
||||||
{{formInput fields.typeData.types.armor.fields.max name=(concat "system.changes." index ".typeData.max") value=typeData.max data-dtype="Number"}}
|
{{formInput fields.typeData.types.armor.fields.max name=(concat "system.changes." index ".typeData.max") value=typeData.max data-dtype="Number"}}
|
||||||
{{formInput fields.typeData.types.armor.fields.armorInteraction name=(concat "system.changes." index ".typeData.armorInteraction") value=typeData.armorInteraction localize=true}}
|
{{formInput fields.typeData.types.armor.fields.armorInteraction name=(concat "system.changes." index ".typeData.armorInteraction") value=typeData.armorInteraction localize=true}}
|
||||||
{{formInput fields.priority name=(concat "system.changes." index ".priority") value=priority}}
|
{{formInput fields.priority name=(concat "system.changes." index ".priority") value=priority}}
|
||||||
<a data-action="deleteChange"><i class="fa-solid fa-trash"></i></a>
|
|
||||||
</li>
|
</li>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue