From 9828e5ec623e5f45008723ac6e783e1f0f9117c6 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 9 Jul 2022 22:09:25 -0500 Subject: [PATCH] Document all the window augmentations --- src/game/layers.tsx | 7 +++++++ src/game/player.ts | 7 +++++++ src/game/settings.ts | 34 ++++++++++++++++++++++------------ src/game/state.ts | 6 ++++++ src/main.ts | 40 ++++++++++------------------------------ src/util/bignum.ts | 15 +++++++++++++++ src/util/save.ts | 11 +++++++++++ 7 files changed, 78 insertions(+), 42 deletions(-) diff --git a/src/game/layers.tsx b/src/game/layers.tsx index 5072ce9..351d1fc 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -48,6 +48,13 @@ export interface LayerEvents { } export const layers: Record | undefined> = shallowReactive({}); + +declare global { + /** Augment the window object so the layers can be accessed from the console */ + interface Window { + layers: Record | undefined>; + } +} window.layers = layers; declare module "@vue/runtime-dom" { diff --git a/src/game/player.ts b/src/game/player.ts index 506337d..8b4ceb0 100644 --- a/src/game/player.ts +++ b/src/game/player.ts @@ -126,6 +126,13 @@ const playerHandler: ProxyHandler> = { return Object.getOwnPropertyDescriptor(target[ProxyState], key); } }; + +declare global { + /** Augment the window object so the player can be accessed from the console */ + interface Window { + player: Player; + } +} export default window.player = new Proxy( { [ProxyState]: state, [ProxyPath]: ["player"] }, playerHandler diff --git a/src/game/settings.ts b/src/game/settings.ts index 4563008..5a94555 100644 --- a/src/game/settings.ts +++ b/src/game/settings.ts @@ -30,7 +30,29 @@ watch( }, { deep: true } ); + +declare global { + /** + * Augment the window object so the settings, and hard resetting the settings, + * can be accessed from the console + */ + interface Window { + settings: Settings; + hardResetSettings: VoidFunction; + } +} export default window.settings = state as Settings; +export const hardResetSettings = (window.hardResetSettings = () => { + const settings = { + active: "", + saves: [], + showTPS: true, + theme: Themes.Nordic + }; + globalBus.emit("loadSettings", settings); + Object.assign(state, settings); + hardReset(); +}); export function loadSettings(): void { try { @@ -59,18 +81,6 @@ export function loadSettings(): void { } catch {} } -export const hardResetSettings = (window.hardResetSettings = () => { - const settings = { - active: "", - saves: [], - showTPS: true, - theme: Themes.Nordic - }; - globalBus.emit("loadSettings", settings); - Object.assign(state, settings); - hardReset(); -}); - export const settingFields: CoercableComponent[] = reactive([]); export function registerSettingField(component: CoercableComponent) { settingFields.push(component); diff --git a/src/game/state.ts b/src/game/state.ts index e8d9da0..1154949 100644 --- a/src/game/state.ts +++ b/src/game/state.ts @@ -7,6 +7,12 @@ export interface Transient { NaNReceiver?: Record; } +declare global { + /** Augment the window object so the transient state can be accessed from the console */ + interface Window { + state: Transient; + } +} export default window.state = shallowReactive({ lastTenTicks: [], hasNaN: false, diff --git a/src/main.ts b/src/main.ts index 1540a1e..8db628b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,47 +1,29 @@ import App from "App.vue"; import projInfo from "data/projInfo.json"; -import type { GenericLayer } from "game/layers"; import "game/notifications"; -import type { PlayerData } from "game/player"; -import type { Settings } from "game/settings"; -import type { Transient } from "game/state"; -import type { DecimalSource } from "util/bignum"; -import Decimal from "util/bignum"; import { load } from "util/save"; import { useRegisterSW } from "virtual:pwa-register/vue"; import type { App as VueApp } from "vue"; import { createApp, nextTick } from "vue"; import { useToast } from "vue-toastification"; -document.title = projInfo.title; -if (projInfo.id === "") { - throw "Project ID is empty! Please select a unique ID for this project in /src/data/projInfo.json"; -} - declare global { + /** + * Augment the window object so + * the vue app and project info can be accessed from the console + */ interface Window { vue: VueApp; - save: VoidFunction; - hardReset: VoidFunction; - hardResetSettings: VoidFunction; - layers: Record | undefined>; - player: PlayerData; - state: Transient; - settings: Settings; - Decimal: typeof Decimal; - exponentialFormat: (num: DecimalSource, precision: number, mantissa: boolean) => string; - commaFormat: (num: DecimalSource, precision: number) => string; - regularFormat: (num: DecimalSource, precision: number) => string; - format: (num: DecimalSource, precision?: number, small?: boolean) => string; - formatWhole: (num: DecimalSource) => string; - formatTime: (s: number) => string; - toPlaces: (x: DecimalSource, precision: number, maxAccepted: DecimalSource) => string; - formatSmall: (x: DecimalSource, precision?: number) => string; - invertOOM: (x: DecimalSource) => Decimal; projInfo: typeof projInfo; } } +document.title = projInfo.title; +window.projInfo = projInfo; +if (projInfo.id === "") { + throw "Project ID is empty! Please select a unique ID for this project in /src/data/projInfo.json"; +} + requestAnimationFrame(async () => { console.log( "%cMade in Profectus%c\nLearn more at www.moddingtree.com", @@ -90,5 +72,3 @@ requestAnimationFrame(async () => { startGameLoop(); }); - -window.projInfo = projInfo; diff --git a/src/util/bignum.ts b/src/util/bignum.ts index ad7100f..2e047a2 100644 --- a/src/util/bignum.ts +++ b/src/util/bignum.ts @@ -17,6 +17,21 @@ export const { export type DecimalSource = RawDecimalSource; +declare global { + /** Augment the window object so the big num functions can be access from the console */ + interface Window { + Decimal: typeof Decimal; + exponentialFormat: (num: DecimalSource, precision: number, mantissa: boolean) => string; + commaFormat: (num: DecimalSource, precision: number) => string; + regularFormat: (num: DecimalSource, precision: number) => string; + format: (num: DecimalSource, precision?: number, small?: boolean) => string; + formatWhole: (num: DecimalSource) => string; + formatTime: (s: number) => string; + toPlaces: (x: DecimalSource, precision: number, maxAccepted: DecimalSource) => string; + formatSmall: (x: DecimalSource, precision?: number) => string; + invertOOM: (x: DecimalSource) => Decimal; + } +} window.Decimal = Decimal; window.exponentialFormat = exponentialFormat; window.commaFormat = commaFormat; diff --git a/src/util/save.ts b/src/util/save.ts index 122a2bd..c0f96ef 100644 --- a/src/util/save.ts +++ b/src/util/save.ts @@ -124,6 +124,17 @@ window.onbeforeunload = () => { save(); } }; + +declare global { + /** + * Augment the window object so the save function, + * and the hard reset function can be access from the console + */ + interface Window { + save: VoidFunction; + hardReset: VoidFunction; + } +} window.save = save; export const hardReset = (window.hardReset = async () => { await loadSave(newSave());