2022-01-14 04:25:47 +00:00
|
|
|
import Decimal, { DecimalSource } from "@/util/bignum";
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
import { isPlainObject } from "@/util/common";
|
2022-01-14 04:25:47 +00:00
|
|
|
import { ProxiedWithState, ProxyPath, ProxyState } from "@/util/proxies";
|
2022-01-25 04:25:34 +00:00
|
|
|
import { shallowReactive, unref } from "vue";
|
2021-09-05 23:53:04 +00:00
|
|
|
import transientState from "./state";
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface PlayerData {
|
|
|
|
id: string;
|
|
|
|
devSpeed: DecimalSource | null;
|
|
|
|
name: string;
|
|
|
|
tabs: Array<string>;
|
|
|
|
time: number;
|
|
|
|
autosave: boolean;
|
|
|
|
offlineProd: boolean;
|
2022-01-25 04:25:34 +00:00
|
|
|
offlineTime: DecimalSource | null;
|
|
|
|
timePlayed: DecimalSource;
|
2022-01-14 04:25:47 +00:00
|
|
|
keepGoing: boolean;
|
|
|
|
minimized: Record<string, boolean>;
|
|
|
|
modID: string;
|
|
|
|
modVersion: string;
|
|
|
|
layers: Record<string, Record<string, unknown>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type Player = ProxiedWithState<PlayerData>;
|
|
|
|
|
2022-01-25 04:25:34 +00:00
|
|
|
const state = shallowReactive<PlayerData>({
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
id: "",
|
2022-01-14 04:25:47 +00:00
|
|
|
devSpeed: null,
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
name: "",
|
|
|
|
tabs: [],
|
|
|
|
time: -1,
|
|
|
|
autosave: true,
|
|
|
|
offlineProd: true,
|
|
|
|
offlineTime: null,
|
|
|
|
timePlayed: new Decimal(0),
|
|
|
|
keepGoing: false,
|
|
|
|
minimized: {},
|
|
|
|
modID: "",
|
|
|
|
modVersion: "",
|
|
|
|
layers: {}
|
|
|
|
});
|
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
export function stringifySave(player: PlayerData): string {
|
|
|
|
return JSON.stringify((player as Player)[ProxyState], (key, value) => unref(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const playerHandler: ProxyHandler<Record<PropertyKey, any>> = {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
get(target: Record<PropertyKey, any>, key: PropertyKey): any {
|
|
|
|
if (key === ProxyState || key === ProxyPath) {
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
return target[key];
|
|
|
|
}
|
2022-01-25 04:25:34 +00:00
|
|
|
|
|
|
|
const value = target[ProxyState][key];
|
|
|
|
if (isPlainObject(value) && !(value instanceof Decimal)) {
|
|
|
|
if (value !== target[key]?.[ProxyState]) {
|
2022-01-14 04:25:47 +00:00
|
|
|
const path = [...target[ProxyPath], key];
|
2022-01-25 04:25:34 +00:00
|
|
|
target[key] = new Proxy({ [ProxyState]: value, [ProxyPath]: path }, playerHandler);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
return target[key];
|
|
|
|
}
|
|
|
|
|
2022-01-25 04:25:34 +00:00
|
|
|
return value;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
},
|
|
|
|
set(
|
2022-01-14 04:25:47 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
target: Record<PropertyKey, any>,
|
|
|
|
property: PropertyKey,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
value: any,
|
|
|
|
receiver: ProxyConstructor
|
|
|
|
): boolean {
|
|
|
|
if (
|
2021-09-05 23:53:04 +00:00
|
|
|
!transientState.hasNaN &&
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
((typeof value === "number" && isNaN(value)) ||
|
|
|
|
(value instanceof Decimal &&
|
|
|
|
(isNaN(value.sign) || isNaN(value.layer) || isNaN(value.mag))))
|
|
|
|
) {
|
2022-01-14 04:25:47 +00:00
|
|
|
const currentValue = target[ProxyState][property];
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
if (
|
|
|
|
!(
|
|
|
|
(typeof currentValue === "number" && isNaN(currentValue)) ||
|
|
|
|
(currentValue instanceof Decimal &&
|
|
|
|
(isNaN(currentValue.sign) ||
|
|
|
|
isNaN(currentValue.layer) ||
|
|
|
|
isNaN(currentValue.mag)))
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
state.autosave = false;
|
2021-09-05 23:53:04 +00:00
|
|
|
transientState.hasNaN = true;
|
2022-01-14 04:25:47 +00:00
|
|
|
transientState.NaNPath = [...target[ProxyPath], property];
|
2022-01-25 04:23:30 +00:00
|
|
|
transientState.NaNReceiver = receiver as unknown as Record<string, unknown>;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
console.error(
|
|
|
|
`Attempted to set NaN value`,
|
2022-01-14 04:25:47 +00:00
|
|
|
[...target[ProxyPath], property],
|
|
|
|
target[ProxyState]
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
);
|
|
|
|
throw "Attempted to set NaN value. See above for details";
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 04:25:47 +00:00
|
|
|
target[ProxyState][property] = value;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
return true;
|
2021-08-20 05:47:56 +00:00
|
|
|
},
|
2022-01-14 04:25:47 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
ownKeys(target: Record<PropertyKey, any>) {
|
|
|
|
return Reflect.ownKeys(target[ProxyState]);
|
2021-08-20 05:47:56 +00:00
|
|
|
},
|
2022-01-14 04:25:47 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
has(target: Record<PropertyKey, any>, key: string) {
|
|
|
|
return Reflect.has(target[ProxyState], key);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
export default window.player = new Proxy(
|
2022-01-14 04:25:47 +00:00
|
|
|
{ [ProxyState]: state, [ProxyPath]: ["player"] },
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
playerHandler
|
|
|
|
) as PlayerData;
|