unseen-mods.ts
Purpose
Tracks post-mission mod drops that the player has not yet viewed in the inventory UI. Powers the NEW badge rendered on mods in the inventory until the player opens the inventory screen, which clears the flag set.
Storage
- Backed by
localStorageunder keyss_unseen_mod_uids. - Persisted as a JSON array of mod instance uids (strings).
- Survives page reloads. NOT synced to server.
- In-memory shape:
Set<string>of mod instance uids.
Module shape
Module-scope constant:
UNSEEN_KEY = 'ss_unseen_mod_uids'— localStorage key.
Private helpers:
read(): Set<string>— reads + parses the localStorage value. Returns emptySeton missing key, parse error, non-array payload, or any thrown exception. Filters payload to strings only via type-narrowing predicate.write(set: Set<string>): void— serializes the set as a JSON array and writes to localStorage. Swallows all exceptions (no-throw on storage quota / disabled storage).
Public API
markModsUnseen(uids: string[]): void— adds each uid to the unseen set. No-op on empty array. Reads the current set, unions in the new uids, writes back.getUnseenModUids(): Set<string>— returns a freshSetof the currently-unseen uids. Each call re-reads localStorage; the returned set is a new instance and is safe to mutate locally (mutations do NOT propagate back to storage).clearAllUnseenMods(): void— overwrites storage with an empty set. Used by the inventory screen on mount to clear all NEW badges.
Behavior notes
- All localStorage access is wrapped in
try/catch; the module never throws. - Non-string entries in a corrupted payload are silently dropped on read.
- There is no per-uid clear API — the inventory clears everything at once on mount.
- Set semantics dedupe: calling
markModsUnseenwith a uid already present is a no-op.
Consumers
- Mission/run-end flow calls
markModsUnseen(uids)with the freshly-dropped mod instance uids. - Inventory
UpgradesTabcallsgetUnseenModUids()on render to decide which mods get the NEW badge, and callsclearAllUnseenMods()on mount to consume the flag.
EXTRACT-CANDIDATE
UNSEEN_KEY— localStorage namespace for unseen-mod tracking.- Public function signatures:
markModsUnseen(uids: string[]),getUnseenModUids(): Set<string>,clearAllUnseenMods().