This repository was archived by the owner on Jul 1, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbotsEpStateFromPersisted.ts
More file actions
70 lines (64 loc) · 2.29 KB
/
Copy pathbotsEpStateFromPersisted.ts
File metadata and controls
70 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { workshopBotIsOwned } from '../data/workshopBots'
import {
WORKSHOP_BOT_ORDER,
WORKSHOP_BOT_SPECIAL_LEVEL_LOCKED,
WORKSHOP_BOT_SPECIAL_LEVEL_ORDER,
WORKSHOP_BOT_UPGRADE_ORDER,
type WorkshopBotId,
} from '../data/workshopBotsData'
import type { WorkshopPersistedV1 } from '../labPresetsStorage'
import type { ResearchData } from '../types/research'
export type BotsEpSyncState = {
levels: Record<string, number>
ownedByBotId: Record<WorkshopBotId, boolean>
labLevels: Record<string, number>
}
/** Medal + Bot+ levels and owned flags from workshop state. */
export function botsEpLevelsAndOwnedFromPersisted(ws: WorkshopPersistedV1): {
levels: Record<string, number>
ownedByBotId: Record<WorkshopBotId, boolean>
} {
const levels: Record<string, number> = {}
for (const key of WORKSHOP_BOT_UPGRADE_ORDER) {
levels[key] = Math.max(0, Math.round(ws[key] ?? 0))
}
for (const key of WORKSHOP_BOT_SPECIAL_LEVEL_ORDER) {
const raw = ws[key] ?? WORKSHOP_BOT_SPECIAL_LEVEL_LOCKED
levels[key] = raw < 0 ? 0 : Math.max(0, Math.round(raw))
}
const ownedByBotId = {} as Record<WorkshopBotId, boolean>
for (const botId of WORKSHOP_BOT_ORDER) {
ownedByBotId[botId] = workshopBotIsOwned(ws, botId)
}
return { levels, ownedByBotId }
}
/** BOTS lab levels keyed by lab display name (e.g. "Flame Bot - Cooldown"). */
export function botLabLevelsFromOverrides(
data: ResearchData,
levelOverrides: Readonly<Record<string, number>>,
): Record<string, number> {
const si = data.sections.findIndex((section) => section.sectionSlug === 'bots')
if (si < 0) return {}
const section = data.sections[si]!
const out: Record<string, number> = {}
section.items.forEach((item, ii) => {
const level = levelOverrides[`${si}-${ii}`]
if (typeof level === 'number' && Number.isFinite(level)) {
out[item.name] = Math.max(0, Math.trunc(level))
}
})
return out
}
/** Full Bots workbook sync payload from TowerSmith workspace state. */
export function botsEpStateFromPersisted(
ws: WorkshopPersistedV1,
data: ResearchData,
levelOverrides: Readonly<Record<string, number>>,
): BotsEpSyncState {
const { levels, ownedByBotId } = botsEpLevelsAndOwnedFromPersisted(ws)
return {
levels,
ownedByBotId,
labLevels: botLabLevelsFromOverrides(data, levelOverrides),
}
}