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

Unified models for progress tracks and clocks #820

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
89d722d
copy from `progress-model-dirty`
rsek Jun 23, 2023
eaa4acc
copy from `progress-model-dirty`
rsek Jun 23, 2023
8069d9b
copy from `progress-model-dirty`
rsek Jun 23, 2023
88c1953
rm some unused methods
rsek Jun 23, 2023
9e03c14
clean up imports + references
rsek Jun 23, 2023
501a0e7
add item class to IRONSWORN. clean up imports
rsek Jun 23, 2023
3b7e1b1
some toolset detection logic
rsek Jun 23, 2023
769448b
provide statics on class as constants
rsek Jun 23, 2023
16f8988
as const for stricter typing
rsek Jun 23, 2023
a6bb047
copy from `progress-model-dirty`
rsek Jun 23, 2023
e6dc233
copy form `progress-model-dirty`
rsek Jun 23, 2023
ce0a3b2
update jsdoc
rsek Jun 23, 2023
12d72c6
copy from `progress-model-dirty`
rsek Jun 23, 2023
4236d78
copy from `progress-model-dirty`
rsek Jun 23, 2023
d7b8ded
copy from `progress-model-dirty`
rsek Jun 23, 2023
92db5e6
use field statics
rsek Jun 24, 2023
f57e9d2
just use the object directly
rsek Jun 24, 2023
2208c23
copy from `progress-model-dirty`
rsek Jun 24, 2023
732416a
update utility types
rsek Jun 24, 2023
4e63e37
update typings
rsek Jun 24, 2023
05b0b57
more specific typings
rsek Jun 24, 2023
0a5981e
rm ts-expect-error
rsek Jun 24, 2023
0d41c3d
type adjustments
rsek Jun 24, 2023
8c161b7
add JEP progress track model
rsek Jun 24, 2023
dc03258
add JEP truth model
rsek Jun 24, 2023
e797046
copy from `progress-model-dirty`
rsek Jun 24, 2023
930c7ea
revert class name
rsek Jun 24, 2023
50db360
add missing import
rsek Jun 24, 2023
e4a910f
copy from `progress-model-dirty`
rsek Jun 24, 2023
c723d3a
add `starred` to item flags
rsek Jun 24, 2023
31f8c0b
update initializers + methods
rsek Jun 24, 2023
102f076
shuffle some method names
rsek Jun 24, 2023
ecd5334
adjust description
rsek Jun 24, 2023
f142cca
type adjustments, file renames
rsek Jun 24, 2023
fd13dec
rename file
rsek Jun 24, 2023
dd20e09
organize imports
rsek Jun 24, 2023
74d5864
retire ProgressTicksField
rsek Jun 24, 2023
302d8b2
retire MeterValueField
rsek Jun 24, 2023
f95a5b3
retire ProgressBase
rsek Jun 24, 2023
80edd23
prune and update code for new progress schema
rsek Jun 25, 2023
2dbf7fa
DRY delete dialog
rsek Jun 25, 2023
833bc9d
adjust comment
rsek Jun 25, 2023
a472f5a
update model names
rsek Jun 25, 2023
a47a9d1
Merge branch 'main' into progress-model
rsek Jun 25, 2023
02b02be
rm duplicate method
rsek Jun 25, 2023
f6f2f61
Merge branch 'main' into progress-model
rsek Sep 18, 2023
41a4631
stdize keys/types for progress vs progressTrack
rsek Sep 18, 2023
9c6a500
wip - can uuids live in a field?
rsek Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
registerOracleTree
} from './module/features/customoracles'
import { OracleTable } from './module/roll-table/oracle-table'
import { IronswornItem } from './module/item/item'

export interface EmitterEvents extends Record<EventType, unknown> {
highlightMove: string // Foundry UUID
Expand All @@ -33,6 +34,7 @@ export type IronswornEmitter = Emitter<EmitterEvents>
export interface IronswornConfig {
actorClass: typeof IronswornActor
OracleTable: typeof OracleTable
IronswornItem: typeof IronswornItem

showdown: showdown.Converter

Expand Down Expand Up @@ -67,6 +69,7 @@ export interface IronswornConfig {
export const IRONSWORN: IronswornConfig = {
actorClass: IronswornActor,
OracleTable,
IronswornItem,

// TODO: if we wanted to implement enrichMarkdown as a showdown plugin, we could use our own instance instead.
get showdown() {
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import type {
} from '@league-of-foundry-developers/foundry-vtt-types/src/types/helperTypes'
import ActorConfig from './module/actor/config'
import ItemConfig from './module/item/config'
import { ProgressTrackModel } from './module/journal/subtypes/progress'
import { TruthModel } from './module/journal/subtypes/truth'

declare global {
interface LenientGlobalVariableTypes {
Expand Down Expand Up @@ -83,6 +85,10 @@ Hooks.once('init', async () => {

CONFIG.JournalEntry.documentClass = IronswornJournalEntry
CONFIG.JournalEntryPage.documentClass = IronswornJournalPage
;(CONFIG.JournalEntryPage as any).dataModels = {
progress: ProgressTrackModel,
truth: TruthModel
}

CONFIG.RollTable.documentClass = OracleTable
CONFIG.RollTable.resultIcon = 'icons/dice/d10black.svg'
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/sheets/sitesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Fetch the item. We only want to override denizens (progress-type items)
const item = await Item.fromDropData(data)
if (item == null) return false
if (!item.assert('progress')) {
if (!item.assert('progressTrack')) {

Check failure on line 21 in src/module/actor/sheets/sitesheet.ts

View workflow job for this annotation

GitHub Actions / static-check

Argument of type '"progressTrack"' is not assignable to parameter of type '"asset" | "progress" | "bondset" | "sfmove" | "delve-theme" | "delve-domain"'.
return await super._onDropItem(event, data)
}

Expand Down
73 changes: 45 additions & 28 deletions src/module/actor/subtypes/character.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { StatField } from '../../fields/StatField'
import { ImpactField } from '../../fields/ImpactField'
import type { IronswornActor } from '../actor'
import { ProgressTicksField } from '../../fields/ProgressTicksField'
import type { DataSchema } from '../../fields/utils'
import type {
ConditionMeterSource,
MomentumSource
} from '../../fields/MeterField'
import { ConditionMeterField, MomentumField } from '../../fields/MeterField'
import { StatField } from '../../fields/StatField'
import type { LegacyTrackSource } from '../../model/LegacyTrack'
import { LegacyTrack } from '../../model/LegacyTrack'
import type { IronswornActor } from '../actor'

export class CharacterModel extends foundry.abstract.TypeDataModel<
CharacterDataSourceData,
CharacterDataSourceData,
CharacterDataPropertiesData,
IronswornActor<'character'>
> {
constructor(
Expand Down Expand Up @@ -112,30 +112,49 @@ export class CharacterModel extends foundry.abstract.TypeDataModel<
custom2name: new fields.StringField({})
}),

legacies: new fields.SchemaField<CharacterDataSourceData['legacies']>({
quests: new ProgressTicksField({
max: undefined
legacies: new fields.SchemaField({
quests: new fields.EmbeddedDataField(LegacyTrack, {
label: 'IRONSWORN.LEGACY.Quests'
}),
questsXpSpent: new fields.NumberField({
initial: 0
bonds: new fields.EmbeddedDataField(LegacyTrack, {
label: 'IRONSWORN.LEGACY.Bonds'
}),
bonds: new ProgressTicksField({
max: undefined
}),
bondsXpSpent: new fields.NumberField({
initial: 0
}),
discoveries: new ProgressTicksField({
max: undefined
}),
discoveriesXpSpent: new fields.NumberField({
initial: 0
discoveries: new fields.EmbeddedDataField(LegacyTrack, {
label: 'IRONSWORN.LEGACY.Discoveries'
})
})
}
}

static migrateData(source: Record<string, unknown>) {
// @ts-expect-error
super.migrateData(source)
const migrate = foundry.abstract.Document._addDataFieldMigration

const legacies = ['quests', 'bonds', 'discoveries']

for (const legacy of legacies) {
if (typeof source[legacy] === 'number')
source[legacy] = { ticks: source[legacy] }
migrate(source, `legacies.${legacy}XpSpent`, `legacies.${legacy}.xpSpent`)
}

return source
}
}
export interface CharacterModel extends CharacterDataPropertiesData {}
export interface CharacterDataPropertiesData extends CharacterDataSourceData {
health: ConditionMeterField
spirit: ConditionMeterField
supply: ConditionMeterField
momentum: MomentumField

legacies: {
quests: LegacyTrack
bonds: LegacyTrack
discoveries: LegacyTrack
}
}
export interface CharacterModel extends CharacterDataSourceData {}
export interface CharacterDataSourceData {
biography: string
notes: string
Expand All @@ -154,13 +173,11 @@ export interface CharacterDataSourceData {
momentum: MomentumSource

xp: number

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

debility: {
Expand Down
59 changes: 48 additions & 11 deletions src/module/actor/subtypes/site.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import type { TableResultDataConstructorData } from '@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/data/data.mjs/tableResultData'
import { ChallengeRank } from '../../fields/ChallengeRank'
import { ProgressTicksField } from '../../fields/ProgressTicksField'
import type { TableResultStub } from '../../fields/TableResultField'
import { TableResultField } from '../../fields/TableResultField'
import type { DataSchema } from '../../fields/utils'
import type {
ProgressTrackProperties,
ProgressTrackSource
} from '../../model/ProgressTrack'
import { ProgressTrack } from '../../model/ProgressTrack'
import { OracleTable } from '../../roll-table/oracle-table'
import type { IronswornActor } from '../actor'

export class SiteModel extends foundry.abstract.TypeDataModel<
SiteDataSourceData,
SiteDataSourceData,
SiteDataPropertiesData,
IronswornActor<'site'>
> {
static _enableV10Validation = true

get denizenTable() {
return new OracleTable({
name: game.i18n.localize('IRONSWORN.DELVESITE.Denizens'),
Expand Down Expand Up @@ -110,11 +111,34 @@ export class SiteModel extends foundry.abstract.TypeDataModel<
return this.theme != null && this.domain != null
}

static override defineSchema(): DataSchema<SiteDataSourceData> {
async markProgress(times = 1) {
return await this.parent.update({
system: { progressTrack: this.progressTrack.getMarkData(times) }
})
}

/** Make the Reveal a Danger move and roll a random danger from this delve site. */
async revealADanger() {
return await (await this.getDangers())?.draw()
}

/** Make a progress roll with the Locate Your Objective move. */
async locateYourObjective() {
return await this.progressTrack.roll({
actor: this.parent,
objective: this.objective
})
}

static override defineSchema(): DataSchema<
SiteDataSourceData,
SiteDataPropertiesData
> {
const fields = foundry.data.fields
return {
rank: new ChallengeRank(),
current: new ProgressTicksField(),
progressTrack: new fields.EmbeddedDataField(ProgressTrack, {
initial: { enabled: true, subtype: 'delve' } as any
}) as any,
objective: new fields.HTMLField(),
description: new fields.HTMLField(),
notes: new fields.HTMLField(),
Expand Down Expand Up @@ -172,17 +196,30 @@ export class SiteModel extends foundry.abstract.TypeDataModel<
})
}
}

static migrateData(source) {
const migrate = foundry.abstract.Document._addDataFieldMigration
migrate(source, 'rank', 'progressTrack.rank')
migrate(source, 'current', 'progressTrack.ticks')

return source
}
}

export interface SiteModel extends SiteDataSourceData {}
export interface SiteModel extends SiteDataPropertiesData {
progressTrack: ProgressTrack
}

interface SiteDataSourceData {
objective: string
description: string
notes: string
rank: ChallengeRank.Value
current: number
denizens: TableResultStub[]
progressTrack: ProgressTrackSource
}
interface SiteDataPropertiesData
extends Omit<SiteDataSourceData, 'progressTrack'> {
progressTrack: ProgressTrackProperties
}

export interface SiteDataSource {
Expand Down
31 changes: 0 additions & 31 deletions src/module/constants.ts

This file was deleted.

Loading
Loading