aboutsummaryrefslogtreecommitdiff
path: root/time/granularity.ts
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-04-22 07:51:18 +0530
committerBobby <[email protected]>2026-04-22 07:51:18 +0530
commit6e8adbaabedba12e81bf0fdfe3dc42108255bd11 (patch)
tree6d0cb2f5d6d029ea93432a1f906ab74bcdfb7917 /time/granularity.ts
parent22912c4af19b9055ed95779c4d16020fe3a449eb (diff)
downloadhollowdark-6e8adbaabedba12e81bf0fdfe3dc42108255bd11.tar.xz
hollowdark-6e8adbaabedba12e81bf0fdfe3dc42108255bd11.zip
Migrate remaining relative imports to @hollowdark/*; strip //-comments and doc references, JSDoc-only
Diffstat (limited to 'time/granularity.ts')
-rw-r--r--time/granularity.ts20
1 files changed, 13 insertions, 7 deletions
diff --git a/time/granularity.ts b/time/granularity.ts
index 0643c47..1acb122 100644
--- a/time/granularity.ts
+++ b/time/granularity.ts
@@ -1,12 +1,7 @@
/**
- * Tick granularity by life stage.
- *
- * One tick represents a different span of time depending on the character's
- * age — infancy advances in years because there isn't weekly texture worth
- * resolving, adulthood in weeks because that's the rhythm the design lives
- * at. See docs/05-time-system.md and ARCHITECTURE.md §5.
+ * The eight life stages a character moves through. Used to pick how much
+ * wall-clock time one simulation tick represents at a given age.
*/
-
export type LifeStage =
| 'infancy'
| 'early_childhood'
@@ -17,8 +12,15 @@ export type LifeStage =
| 'late_adult'
| 'elderly'
+/** How much game time one tick advances. */
export type TickUnit = 'year' | 'season' | 'month' | 'week'
+/**
+ * Tick granularity per life stage. Infancy advances in years because
+ * there isn't weekly texture worth resolving; adulthood in weeks because
+ * that's the rhythm the design lives at; elderly in months as the pace
+ * slows again.
+ */
export const TICK_UNIT_BY_LIFE_STAGE: Readonly<Record<LifeStage, TickUnit>> = {
infancy: 'year',
early_childhood: 'season',
@@ -30,6 +32,9 @@ export const TICK_UNIT_BY_LIFE_STAGE: Readonly<Record<LifeStage, TickUnit>> = {
elderly: 'month'
}
+/**
+ * Bucket an age in whole years into its life stage. Throws on negative age.
+ */
export function lifeStageForAge(ageYears: number): LifeStage {
if (ageYears < 0) throw new Error(`Invalid age: ${ageYears}`)
if (ageYears < 3) return 'infancy'
@@ -42,6 +47,7 @@ export function lifeStageForAge(ageYears: number): LifeStage {
return 'elderly'
}
+/** Shortcut: map an age directly to its tick unit. */
export function tickUnitForAge(ageYears: number): TickUnit {
return TICK_UNIT_BY_LIFE_STAGE[lifeStageForAge(ageYears)]
}