explodorama / files / src / channel.ts
channel.ts
| 1 | /** |
| 2 | * Which copy of the game this is (user request, 2026-10-31). `stable` is the released one, built |
| 3 | * from a git tag, at /explodorama/; `next` is built from `main` at /explodorama-next/ for anyone |
| 4 | * who wants to try what is coming (vite.config.ts sets VITE_CHANNEL from the deploy's app name); |
| 5 | * `local` is `npm run dev`. The two deployed copies share an origin, so they share localStorage: |
| 6 | * `storageKey` keeps their saves, options and scores apart. |
| 7 | */ |
| 8 | export type Channel = 'stable' | 'next' | 'local' |
| 9 | |
| 10 | export const CHANNEL: Channel = import.meta.env.DEV ? 'local' : import.meta.env.VITE_CHANNEL === 'next' ? 'next' : 'stable' |
| 11 | |
| 12 | /** The page title, which says which copy it is. */ |
| 13 | export const TITLE = CHANNEL === 'local' ? 'EXPLODORAMA! (local)' : CHANNEL === 'next' ? 'EXPLODORAMA! (next)' : 'EXPLODORAMA!' |
| 14 | |
| 15 | /** A localStorage key of this copy's own: `explodorama.run`, or `explodorama-next.run` on the next copy. */ |
| 16 | export function storageKey(name: string): string { |
| 17 | return `${CHANNEL === 'next' ? 'explodorama-next' : 'explodorama'}.${name}` |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * The one key both copies share: how many runs have been finished on the next copy, so the |
| 22 | * released one can say so (early adopters). |
| 23 | */ |
| 24 | export const EARLY_RUNS_KEY = 'explodorama.earlyRuns' |
| 25 | |
| 26 | /** |
| 27 | * Where each copy lives: the full addresses come from package.json (`homepage`, `nextHomepage`, |
| 28 | * through vite.config.ts), the menu shows them; the paths are for the links and for next.json. |
| 29 | */ |
| 30 | export const HOME_URL: string = import.meta.env.VITE_HOME_URL || 'https://apps.fuzzyworld.net/explodorama/' |
| 31 | export const NEXT_URL: string = import.meta.env.VITE_NEXT_URL || 'https://apps.fuzzyworld.net/explodorama-next/' |
| 32 | export const STABLE_PATH = new URL(HOME_URL).pathname |
| 33 | export const NEXT_PATH = new URL(NEXT_URL).pathname |
| 34 | |
| 35 | /** Runs finished on the next copy, from either copy. */ |
| 36 | export function earlyRuns(): number { |
| 37 | try { |
| 38 | const n = Number(localStorage.getItem(EARLY_RUNS_KEY)) |
| 39 | return Number.isInteger(n) && n > 0 ? n : 0 |
| 40 | } catch { |
| 41 | return 0 |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | export function countEarlyRun(): void { |
| 46 | try { |
| 47 | localStorage.setItem(EARLY_RUNS_KEY, String(earlyRuns() + 1)) |
| 48 | } catch { |
| 49 | // No storage: not counted. |
| 50 | } |
| 51 | } |