mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Refactor resources selection and data prep (#1721)
* Move resources select to scrolly text and accept actor object * Convert isReversed to prepared data and add label * Removed unused imports --------- Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
a4a7b8e7ca
commit
cb0f63208e
9 changed files with 25 additions and 24 deletions
|
|
@ -140,18 +140,6 @@ export const companionResources = {
|
||||||
...companionBaseResources
|
...companionBaseResources
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getScrollingTextResources = actorType => ({
|
|
||||||
armor: {
|
|
||||||
label: 'DAGGERHEART.GENERAL.armor',
|
|
||||||
reverse: true
|
|
||||||
},
|
|
||||||
...(actorType === 'character'
|
|
||||||
? characterResources
|
|
||||||
: actorType === 'adversary'
|
|
||||||
? adversaryResources
|
|
||||||
: companionResources)
|
|
||||||
});
|
|
||||||
|
|
||||||
export const featureProperties = {
|
export const featureProperties = {
|
||||||
agility: {
|
agility: {
|
||||||
name: 'DAGGERHEART.CONFIG.Traits.agility.name',
|
name: 'DAGGERHEART.CONFIG.Traits.agility.name',
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ export default class DhpAdversary extends DhCreature {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDerivedData() {
|
prepareDerivedData() {
|
||||||
|
super.prepareDerivedData();
|
||||||
this.attack.roll.isStandardAttack = true;
|
this.attack.roll.isStandardAttack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel {
|
||||||
const textData = Object.keys(changes.system.resources).reduce((acc, key) => {
|
const textData = Object.keys(changes.system.resources).reduce((acc, key) => {
|
||||||
const resource = changes.system.resources[key];
|
const resource = changes.system.resources[key];
|
||||||
if (resource.value !== undefined && resource.value !== this.resources[key].value) {
|
if (resource.value !== undefined && resource.value !== this.resources[key].value) {
|
||||||
acc.push(getScrollTextData(this.resources, resource, key, this.parent.type));
|
acc.push(getScrollTextData(this.parent, resource, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
|
|
|
||||||
|
|
@ -658,6 +658,7 @@ export default class DhCharacter extends DhCreature {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDerivedData() {
|
prepareDerivedData() {
|
||||||
|
super.prepareDerivedData();
|
||||||
let baseHope = this.resources.hope.value;
|
let baseHope = this.resources.hope.value;
|
||||||
if (this.companion) {
|
if (this.companion) {
|
||||||
for (let levelKey in this.companion.system.levelData.levelups) {
|
for (let levelKey in this.companion.system.levelData.levelups) {
|
||||||
|
|
@ -677,6 +678,7 @@ export default class DhCharacter extends DhCreature {
|
||||||
this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait;
|
this.attack.roll.trait = this.rules.attack.roll.trait ?? this.attack.roll.trait;
|
||||||
|
|
||||||
this.resources.armor = {
|
this.resources.armor = {
|
||||||
|
label: 'DAGGERHEART.GENERAL.armor',
|
||||||
value: this.armor?.system?.marks?.value ?? 0,
|
value: this.armor?.system?.marks?.value ?? 0,
|
||||||
max: this.armorScore,
|
max: this.armorScore,
|
||||||
isReversed: true
|
isReversed: true
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,7 @@ export default class DhCompanion extends DhCreature {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDerivedData() {
|
prepareDerivedData() {
|
||||||
|
super.prepareDerivedData();
|
||||||
/* Partner Related Setup */
|
/* Partner Related Setup */
|
||||||
if (this.partner) {
|
if (this.partner) {
|
||||||
this.levelData.level.changed = this.partner.system.levelData.level.current;
|
this.levelData.level.changed = this.partner.system.levelData.level.current;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ export default class DhCreature extends BaseDataActor {
|
||||||
resource.max,
|
resource.max,
|
||||||
resource.initial,
|
resource.initial,
|
||||||
resource.label,
|
resource.label,
|
||||||
resource.reverse,
|
|
||||||
resource.maxLabel
|
resource.maxLabel
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -54,6 +53,17 @@ export default class DhCreature extends BaseDataActor {
|
||||||
return !vulnerableAppliedByOther;
|
return !vulnerableAppliedByOther;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareDerivedData() {
|
||||||
|
super.prepareDerivedData();
|
||||||
|
const resources = CONFIG.DH.ACTOR[`${this.parent.type}Resources`];
|
||||||
|
if (resources) {
|
||||||
|
for (const [key, value] of Object.entries(this.resources)) {
|
||||||
|
value.label = resources[key]?.label;
|
||||||
|
value.isReversed = resources[key]?.reverse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _preUpdate(changes, options, userId) {
|
async _preUpdate(changes, options, userId) {
|
||||||
const allowed = await super._preUpdate(changes, options, userId);
|
const allowed = await super._preUpdate(changes, options, userId);
|
||||||
if (allowed === false) return;
|
if (allowed === false) return;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const attributeField = label =>
|
||||||
tierMarked: new fields.BooleanField({ initial: false })
|
tierMarked: new fields.BooleanField({ initial: false })
|
||||||
});
|
});
|
||||||
|
|
||||||
const resourceField = (max = 0, initial = 0, label, reverse = false, maxLabel) =>
|
const resourceField = (max = 0, initial = 0, label, maxLabel) =>
|
||||||
new fields.SchemaField(
|
new fields.SchemaField(
|
||||||
{
|
{
|
||||||
value: new fields.NumberField({ initial: initial, min: 0, integer: true, label }),
|
value: new fields.NumberField({ initial: initial, min: 0, integer: true, label }),
|
||||||
|
|
@ -17,7 +17,6 @@ const resourceField = (max = 0, initial = 0, label, reverse = false, maxLabel) =
|
||||||
maxLabel ??
|
maxLabel ??
|
||||||
game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
|
game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
|
||||||
}),
|
}),
|
||||||
isReversed: new fields.BooleanField({ initial: reverse })
|
|
||||||
},
|
},
|
||||||
{ label }
|
{ label }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -225,10 +225,9 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
changed.system?.marks?.value !== undefined && changed.system.marks.value !== this.marks.value;
|
changed.system?.marks?.value !== undefined && changed.system.marks.value !== this.marks.value;
|
||||||
if (armorChanged && autoSettings.resourceScrollTexts && this.parent.parent?.type === 'character') {
|
if (armorChanged && autoSettings.resourceScrollTexts && this.parent.parent?.type === 'character') {
|
||||||
const armorData = getScrollTextData(
|
const armorData = getScrollTextData(
|
||||||
this.parent.parent.system.resources,
|
this.parent.parent,
|
||||||
changed.system.marks,
|
changed.system.marks,
|
||||||
'armor',
|
'armor',
|
||||||
this.parent.parent.type
|
|
||||||
);
|
);
|
||||||
options.scrollingTextData = [armorData];
|
options.scrollingTextData = [armorData];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -378,17 +378,18 @@ export const arraysEqual = (a, b) =>
|
||||||
|
|
||||||
export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value));
|
export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value));
|
||||||
|
|
||||||
export function getScrollTextData(resources, resource, key, actorType) {
|
export function getScrollTextData(actor, resource, key) {
|
||||||
const { reverse, label } = CONFIG.DH.ACTOR.getScrollingTextResources(actorType)[key];
|
|
||||||
const { BOTTOM, TOP } = CONST.TEXT_ANCHOR_POINTS;
|
const { BOTTOM, TOP } = CONST.TEXT_ANCHOR_POINTS;
|
||||||
|
|
||||||
|
const resources = actor.system.resources;
|
||||||
const increased = resources[key].value < resource.value;
|
const increased = resources[key].value < resource.value;
|
||||||
const value = -1 * (resources[key].value - resource.value);
|
const value = -1 * (resources[key].value - resource.value);
|
||||||
|
const { label, isReversed } = resources[key];
|
||||||
|
|
||||||
const text = `${game.i18n.localize(label)} ${value.signedString()}`;
|
const text = `${game.i18n.localize(label)} ${value.signedString()}`;
|
||||||
|
const stroke = increased ? (isReversed ? 0xffffff : 0x000000) : isReversed ? 0x000000 : 0xffffff;
|
||||||
const stroke = increased ? (reverse ? 0xffffff : 0x000000) : reverse ? 0x000000 : 0xffffff;
|
const fill = increased ? (isReversed ? 0x0032b1 : 0xffe760) : isReversed ? 0xffe760 : 0x0032b1;
|
||||||
const fill = increased ? (reverse ? 0x0032b1 : 0xffe760) : reverse ? 0xffe760 : 0x0032b1;
|
const direction = increased ? (isReversed ? BOTTOM : TOP) : isReversed ? TOP : BOTTOM;
|
||||||
const direction = increased ? (reverse ? BOTTOM : TOP) : reverse ? TOP : BOTTOM;
|
|
||||||
|
|
||||||
return { text, stroke, fill, direction };
|
return { text, stroke, fill, direction };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue