Profectus-Demo/src/game/state.ts

29 lines
969 B
TypeScript
Raw Normal View History

import type { DecimalSource } from "util/bignum";
2022-01-25 04:25:34 +00:00
import { shallowReactive } from "vue";
import type { Persistent } from "./persistence";
2022-07-15 05:55:36 +00:00
/** An object of global data that is not persistent. */
2022-01-14 04:25:47 +00:00
export interface Transient {
2022-07-15 05:55:36 +00:00
/** A list of the duration, in ms, of the last 10 game ticks. Used for calculating TPS. */
2022-01-14 04:25:47 +00:00
lastTenTicks: number[];
2022-07-15 05:55:36 +00:00
/** Whether or not a NaN value has been detected and undealt with. */
2022-01-14 04:25:47 +00:00
hasNaN: boolean;
2022-07-15 05:55:36 +00:00
/** The location within the player save data object of the NaN value. */
2022-01-14 04:25:47 +00:00
NaNPath?: string[];
/** The ref that was being set to NaN. */
NaNPersistent?: Persistent<DecimalSource>;
2022-01-14 04:25:47 +00:00
}
2022-07-10 03:09:25 +00:00
declare global {
2022-07-10 05:43:52 +00:00
/** Augment the window object so the transient state can be accessed from the console. */
2022-07-10 03:09:25 +00:00
interface Window {
state: Transient;
}
}
2022-07-15 05:55:36 +00:00
/** The global transient state object. */
2022-01-25 04:25:34 +00:00
export default window.state = shallowReactive<Transient>({
lastTenTicks: [],
hasNaN: false,
2022-01-14 04:25:47 +00:00
NaNPath: []
});