mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 23:43:37 +02:00
Readded so that armor items have their system defined armor instead of using an ActiveEffect
This commit is contained in:
parent
50dcbf4396
commit
1cdabf15a5
11 changed files with 198 additions and 161 deletions
|
|
@ -948,8 +948,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const origin = effect.origin ? await foundry.utils.fromUuid(effect.origin) : effect.parent;
|
||||
if (!effect.system.armorData || effect.disabled || effect.isSuppressed) continue;
|
||||
|
||||
const originIsActor = origin instanceof Actor;
|
||||
const name = originIsActor ? effect.name : origin.name;
|
||||
const useEffectName = origin.type === 'armor' || origin instanceof Actor;
|
||||
const name = useEffectName ? effect.name : origin.name;
|
||||
armorSources.push({
|
||||
uuid: effect.uuid,
|
||||
name,
|
||||
|
|
@ -957,6 +957,15 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
});
|
||||
}
|
||||
|
||||
if (this.document.system.armor) {
|
||||
armorSources.push({
|
||||
...this.document.system.armor.system.armor,
|
||||
uuid: this.document.system.armor.uuid,
|
||||
name: this.document.system.armor.name,
|
||||
isArmorItem: true
|
||||
});
|
||||
}
|
||||
|
||||
if (!armorSources.length) return;
|
||||
|
||||
const useResourcePips = game.settings.get(
|
||||
|
|
@ -980,11 +989,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
direction: 'DOWN'
|
||||
});
|
||||
|
||||
html.querySelectorAll('.armor-marks-input').forEach(element => {
|
||||
element.addEventListener('blur', CharacterSheet.armorSourceUpdate);
|
||||
element.addEventListener('input', CharacterSheet.armorSourceInput);
|
||||
});
|
||||
|
||||
html.querySelectorAll('.armor-slot').forEach(element => {
|
||||
element.addEventListener('click', CharacterSheet.armorSourcePipUpdate);
|
||||
});
|
||||
|
|
@ -999,49 +1003,49 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
}
|
||||
|
||||
/** Update specific armor source */
|
||||
static async armorSourceUpdate(event) {
|
||||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
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' ? { ...change.value, current } : change.value
|
||||
}));
|
||||
|
||||
event.target.value = current;
|
||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
||||
progressBar.value = current;
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
}
|
||||
|
||||
static async armorSourcePipUpdate(event) {
|
||||
const target = event.target.closest('.armor-slot');
|
||||
const effect = await foundry.utils.fromUuid(target.dataset.uuid);
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
const { uuid, value, isArmorItem: isArmorItemString } = target.dataset;
|
||||
const isArmorItem = Boolean(isArmorItemString);
|
||||
|
||||
const { current } = effect.system.armorData;
|
||||
let inputValue = Number.parseInt(value);
|
||||
let decreasing = false;
|
||||
let newCurrent = 0;
|
||||
|
||||
const inputValue = Number.parseInt(target.dataset.value);
|
||||
const decreasing = current >= inputValue;
|
||||
const newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||
if (isArmorItem) {
|
||||
const armor = await foundry.utils.fromUuid(uuid);
|
||||
decreasing = armor.system.armor.current >= inputValue;
|
||||
newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
||||
}));
|
||||
await armor.update({ 'system.armor.current': newCurrent });
|
||||
} else {
|
||||
const effect = await foundry.utils.fromUuid(uuid);
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
|
||||
const { current } = effect.system.armorData;
|
||||
decreasing = current >= inputValue;
|
||||
newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
||||
}));
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
}
|
||||
|
||||
const container = target.closest('.slot-bar');
|
||||
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
||||
const marked = !decreasing && Number.parseInt(armorSlot.dataset.index) < newCurrent;
|
||||
armorSlot.classList.toggle('fa-shield', marked);
|
||||
armorSlot.classList.toggle('fa-shield-halved', !marked);
|
||||
const index = Number.parseInt(armorSlot.dataset.index);
|
||||
if (decreasing && index >= newCurrent) {
|
||||
armorSlot.classList.remove('fa-shield');
|
||||
armorSlot.classList.add('fa-shield-halved');
|
||||
} else if (!decreasing && index < newCurrent) {
|
||||
armorSlot.classList.add('fa-shield');
|
||||
armorSlot.classList.remove('fa-shield-halved');
|
||||
}
|
||||
}
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
}
|
||||
|
||||
static async #toggleResourceManagement(event, button) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue