Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar-shaped resource meter attributes #798

Merged
merged 11 commits into from
Jun 9, 2023
15 changes: 12 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@ module.exports = {
// FIXME: part of standard-ts. not an awful idea, but it's not doable via autofix, so it's disabled for now
'@typescript-eslint/explicit-function-return-type': 'off',

// prefer lodash-es to regular lodash
// prefer lodash-es to regular lodash, and FVTT-provided utilities to lodash utilities
'no-restricted-imports': [
'error',
{
name: 'lodash',
message: 'Please use `lodash-es` instead.'
paths: [
{
name: 'lodash',
message: 'Please use lodash-es instead.'
},
{
name: 'lodash-es',
importNames: ['clamp'],
message: "Please use FVTT's Math.clamped instead."
}
]
}
]
},
Expand Down
90 changes: 44 additions & 46 deletions src/module/actor/subtypes/character.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { StatField } from '../../fields/StatField'
import { MeterValueField } from '../../fields/MeterValueField'
import { ImpactField } from '../../fields/ImpactField'
import type { IronswornActor } from '../actor'
import { ProgressTicksField } from '../../fields/ProgressTicksField'
import { clamp } from 'lodash-es'
import type { DataSchema } from '../../fields/utils'
import type {
ConditionMeterSource,
MomentumSource
} from '../../fields/MeterField'
import { ConditionMeterField, MomentumField } from '../../fields/MeterField'

export class CharacterData extends foundry.abstract.TypeDataModel<
CharacterDataSourceData,
Expand All @@ -24,37 +27,39 @@ export class CharacterData extends foundry.abstract.TypeDataModel<

static _enableV10Validation = true

static readonly MOMENTUM_MAX = 10
static readonly MOMENTUM_MIN = -6
static readonly MOMENTUM_INITIAL = 2
static readonly MOMENTUM_RESET_MIN = 0

async burnMomentum(this: CharacterData) {
if (this.parent.system.momentum > this.parent.system.momentumReset) {
if (this.canBurnMomentum) {
await this.parent.update({
system: { momentum: this.parent.system.momentumReset }
system: { 'momentum.value': this.parent.system.momentum.resetValue }
})
}
}

get canBurnMomentum() {
return (
this.parent.system.momentum.value > this.parent.system.momentum.resetValue
)
}

get #impactCount() {
return Object.values(this.debility as any).filter((value) => value === true)
.length
}

// FIXME: These won't be required when impacts are represented as ActiveEffects
get momentumReset() {
return clamp(
CharacterData.MOMENTUM_INITIAL - this.#impactCount,
CharacterData.MOMENTUM_RESET_MIN,
CharacterData.MOMENTUM_MAX
return Math.clamped(
this.momentum.resetValue - this.#impactCount,
MomentumField.RESET_MIN,
this.momentum.max
)
}

get momentumMax() {
return clamp(
CharacterData.MOMENTUM_MAX - this.#impactCount,
CharacterData.MOMENTUM_MIN,
CharacterData.MOMENTUM_MAX
return Math.clamped(
this.momentum.max - this.#impactCount,
MomentumField.MIN,
MomentumField.MAX
)
}

Expand All @@ -70,23 +75,13 @@ export class CharacterData extends foundry.abstract.TypeDataModel<
shadow: new StatField({ label: 'IRONSWORN.Shadow' }),
wits: new StatField({ label: 'IRONSWORN.Wits' }),

health: new MeterValueField({ label: 'IRONSWORN.Health' }),
spirit: new MeterValueField({ label: 'IRONSWORN.Spirit' }),
supply: new MeterValueField({ label: 'IRONSWORN.Supply' }),
// TODO: add a localized `hint` property, and have the vue sheet automatically pull these in as tooltips
health: new ConditionMeterField({ label: 'IRONSWORN.Health' }),
spirit: new ConditionMeterField({ label: 'IRONSWORN.Spirit' }),
supply: new ConditionMeterField({ label: 'IRONSWORN.Supply' }),

momentum: new MeterValueField({
label: 'IRONSWORN.Momentum',
initial: (source) => (source as any).momentumReset,
max: this.MOMENTUM_MAX,
min: this.MOMENTUM_MIN
}),
momentum: new MomentumField(),

experience: new fields.NumberField({
integer: true,
required: true,
initial: 0,
min: 0
}),
xp: new fields.NumberField({
integer: true,
required: true,
Expand Down Expand Up @@ -142,16 +137,28 @@ export interface CharacterData extends CharacterDataSourceData {}
export interface CharacterDataSourceData {
biography: string
notes: string

edge: number
heart: number
iron: number
shadow: number
wits: number
health: number
spirit: number
supply: number
experience: number
momentum: number

health: ConditionMeterSource
spirit: ConditionMeterSource
supply: ConditionMeterSource
momentum: MomentumSource

xp: number
legacies: {
quests: number
questsXpSpent: number
bonds: number
bondsXpSpent: number
discoveries: number
discoveriesXpSpent: number
}

debility: {
corrupted: boolean
cursed: boolean
Expand All @@ -171,15 +178,6 @@ export interface CharacterDataSourceData {
custom2: boolean
custom2name: string
}
legacies: {
quests: number
questsXpSpent: number
bonds: number
bondsXpSpent: number
discoveries: number
discoveriesXpSpent: number
}
xp: number
}

export interface CharacterDataSource {
Expand Down
8 changes: 6 additions & 2 deletions src/module/actor/subtypes/shared.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
ConditionMeterField,
ConditionMeterSource
} from '../../fields/MeterField'
import { MeterValueField } from '../../fields/MeterValueField'
import type { DataSchema } from '../../fields/utils'
import type { IronswornActor } from '../actor'
Expand All @@ -11,15 +15,15 @@ export class SharedData extends foundry.abstract.TypeDataModel<
static override defineSchema(): DataSchema<SharedDataSourceData> {
return {
biography: new foundry.data.fields.HTMLField(),
supply: new MeterValueField({ label: 'IRONSWORN.Supply' })
supply: new ConditionMeterField({ label: 'IRONSWORN.Supply' })
}
}
}
export interface SharedData extends SharedDataSourceData {}

interface SharedDataSourceData {
biography: string
supply: number
supply: ConditionMeterSource
}

export interface SharedDataSource {
Expand Down
Loading