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 { PlayerData } from "@/typings/player";
|
|
|
|
import Decimal from "@/util/bignum";
|
|
|
|
import { isPlainObject } from "@/util/common";
|
|
|
|
import { reactive } 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
|
|
|
|
|
|
|
const state = reactive<PlayerData>({
|
|
|
|
id: "",
|
|
|
|
points: new Decimal(0),
|
|
|
|
name: "",
|
|
|
|
tabs: [],
|
|
|
|
time: -1,
|
|
|
|
autosave: true,
|
|
|
|
offlineProd: true,
|
|
|
|
offlineTime: null,
|
|
|
|
timePlayed: new Decimal(0),
|
|
|
|
keepGoing: false,
|
|
|
|
subtabs: {},
|
|
|
|
minimized: {},
|
|
|
|
modID: "",
|
|
|
|
modVersion: "",
|
2021-08-28 16:35:25 +00:00
|
|
|
justLoaded: false,
|
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
|
|
|
layers: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
const playerHandler: ProxyHandler<Record<string, any>> = {
|
|
|
|
get(target: Record<string, any>, key: string): any {
|
|
|
|
if (key === "__state" || key === "__path") {
|
|
|
|
return target[key];
|
|
|
|
}
|
|
|
|
if (target.__state[key] == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isPlainObject(target.__state[key]) && !(target.__state[key] instanceof Decimal)) {
|
|
|
|
if (target.__state[key] !== target[key]?.__state) {
|
|
|
|
const path = [...target.__path, key];
|
|
|
|
target[key] = new Proxy(
|
|
|
|
{ __state: target.__state[key], __path: path },
|
|
|
|
playerHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return target[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return target.__state[key];
|
|
|
|
},
|
|
|
|
set(
|
|
|
|
target: Record<string, any>,
|
|
|
|
property: string,
|
|
|
|
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))))
|
|
|
|
) {
|
|
|
|
const currentValue = target.__state[property];
|
|
|
|
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;
|
|
|
|
transientState.NaNPath = [...target.__path, property];
|
|
|
|
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`,
|
|
|
|
[...target.__path, property],
|
|
|
|
target.__state
|
|
|
|
);
|
|
|
|
throw "Attempted to set NaN value. See above for details";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
target.__state[property] = value;
|
|
|
|
if (property === "points") {
|
|
|
|
if (target.__state.best != undefined) {
|
|
|
|
target.__state.best = Decimal.max(target.__state.best, value);
|
|
|
|
}
|
|
|
|
if (target.__state.total != undefined) {
|
|
|
|
const diff = Decimal.sub(value, target.__state.points);
|
|
|
|
if (diff.gt(0)) {
|
|
|
|
target.__state.total = target.__state.total.add(diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2021-08-20 05:47:56 +00:00
|
|
|
},
|
|
|
|
ownKeys(target: Record<string, any>) {
|
|
|
|
return Reflect.ownKeys(target.__state);
|
|
|
|
},
|
|
|
|
has(target: Record<string, any>, key: string) {
|
|
|
|
return Reflect.has(target.__state, 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(
|
|
|
|
{ __state: state, __path: ["player"] },
|
|
|
|
playerHandler
|
|
|
|
) as PlayerData;
|