Document all the window augmentations
This commit is contained in:
parent
3ee1cdb384
commit
9828e5ec62
7 changed files with 78 additions and 42 deletions
|
@ -48,6 +48,13 @@ export interface LayerEvents {
|
|||
}
|
||||
|
||||
export const layers: Record<string, Readonly<GenericLayer> | undefined> = shallowReactive({});
|
||||
|
||||
declare global {
|
||||
/** Augment the window object so the layers can be accessed from the console */
|
||||
interface Window {
|
||||
layers: Record<string, Readonly<GenericLayer> | undefined>;
|
||||
}
|
||||
}
|
||||
window.layers = layers;
|
||||
|
||||
declare module "@vue/runtime-dom" {
|
||||
|
|
|
@ -126,6 +126,13 @@ const playerHandler: ProxyHandler<Record<PropertyKey, any>> = {
|
|||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,6 +7,12 @@ export interface Transient {
|
|||
NaNReceiver?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
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<Transient>({
|
||||
lastTenTicks: [],
|
||||
hasNaN: false,
|
||||
|
|
40
src/main.ts
40
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<string, Readonly<GenericLayer> | 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue