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({});
|
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;
|
window.layers = layers;
|
||||||
|
|
||||||
declare module "@vue/runtime-dom" {
|
declare module "@vue/runtime-dom" {
|
||||||
|
|
|
@ -126,6 +126,13 @@ const playerHandler: ProxyHandler<Record<PropertyKey, any>> = {
|
||||||
return Object.getOwnPropertyDescriptor(target[ProxyState], key);
|
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(
|
export default window.player = new Proxy(
|
||||||
{ [ProxyState]: state, [ProxyPath]: ["player"] },
|
{ [ProxyState]: state, [ProxyPath]: ["player"] },
|
||||||
playerHandler
|
playerHandler
|
||||||
|
|
|
@ -30,7 +30,29 @@ watch(
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ 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 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 {
|
export function loadSettings(): void {
|
||||||
try {
|
try {
|
||||||
|
@ -59,18 +81,6 @@ export function loadSettings(): void {
|
||||||
} catch {}
|
} 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 const settingFields: CoercableComponent[] = reactive([]);
|
||||||
export function registerSettingField(component: CoercableComponent) {
|
export function registerSettingField(component: CoercableComponent) {
|
||||||
settingFields.push(component);
|
settingFields.push(component);
|
||||||
|
|
|
@ -7,6 +7,12 @@ export interface Transient {
|
||||||
NaNReceiver?: Record<string, unknown>;
|
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>({
|
export default window.state = shallowReactive<Transient>({
|
||||||
lastTenTicks: [],
|
lastTenTicks: [],
|
||||||
hasNaN: false,
|
hasNaN: false,
|
||||||
|
|
40
src/main.ts
40
src/main.ts
|
@ -1,47 +1,29 @@
|
||||||
import App from "App.vue";
|
import App from "App.vue";
|
||||||
import projInfo from "data/projInfo.json";
|
import projInfo from "data/projInfo.json";
|
||||||
import type { GenericLayer } from "game/layers";
|
|
||||||
import "game/notifications";
|
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 { load } from "util/save";
|
||||||
import { useRegisterSW } from "virtual:pwa-register/vue";
|
import { useRegisterSW } from "virtual:pwa-register/vue";
|
||||||
import type { App as VueApp } from "vue";
|
import type { App as VueApp } from "vue";
|
||||||
import { createApp, nextTick } from "vue";
|
import { createApp, nextTick } from "vue";
|
||||||
import { useToast } from "vue-toastification";
|
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 {
|
declare global {
|
||||||
|
/**
|
||||||
|
* Augment the window object so
|
||||||
|
* the vue app and project info can be accessed from the console
|
||||||
|
*/
|
||||||
interface Window {
|
interface Window {
|
||||||
vue: VueApp;
|
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;
|
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 () => {
|
requestAnimationFrame(async () => {
|
||||||
console.log(
|
console.log(
|
||||||
"%cMade in Profectus%c\nLearn more at www.moddingtree.com",
|
"%cMade in Profectus%c\nLearn more at www.moddingtree.com",
|
||||||
|
@ -90,5 +72,3 @@ requestAnimationFrame(async () => {
|
||||||
|
|
||||||
startGameLoop();
|
startGameLoop();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.projInfo = projInfo;
|
|
||||||
|
|
|
@ -17,6 +17,21 @@ export const {
|
||||||
|
|
||||||
export type DecimalSource = RawDecimalSource;
|
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.Decimal = Decimal;
|
||||||
window.exponentialFormat = exponentialFormat;
|
window.exponentialFormat = exponentialFormat;
|
||||||
window.commaFormat = commaFormat;
|
window.commaFormat = commaFormat;
|
||||||
|
|
|
@ -124,6 +124,17 @@ window.onbeforeunload = () => {
|
||||||
save();
|
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;
|
window.save = save;
|
||||||
export const hardReset = (window.hardReset = async () => {
|
export const hardReset = (window.hardReset = async () => {
|
||||||
await loadSave(newSave());
|
await loadSave(newSave());
|
||||||
|
|
Loading…
Reference in a new issue