2022-03-04 03:39:48 +00:00
|
|
|
import projInfo from "data/projInfo.json";
|
2022-06-27 00:17:22 +00:00
|
|
|
import type { Player, PlayerData } from "game/player";
|
|
|
|
import player, { stringifySave } from "game/player";
|
2022-03-04 03:39:48 +00:00
|
|
|
import settings, { loadSettings } from "game/settings";
|
2022-04-18 02:15:38 +00:00
|
|
|
import LZString from "lz-string";
|
2022-06-27 00:17:22 +00:00
|
|
|
import { ProxyState } from "util/proxies";
|
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-25 04:25:34 +00:00
|
|
|
export function setupInitialStore(player: Partial<PlayerData> = {}): Player {
|
|
|
|
return Object.assign(
|
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-03-03 02:12:56 +00:00
|
|
|
id: `${projInfo.id}-0`,
|
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: "Default Save",
|
2022-03-03 02:12:56 +00:00
|
|
|
tabs: projInfo.initialTabs.slice(),
|
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
|
|
|
time: Date.now(),
|
|
|
|
autosave: true,
|
|
|
|
offlineProd: true,
|
2022-03-11 20:02:41 +00:00
|
|
|
offlineTime: 0,
|
|
|
|
timePlayed: 0,
|
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
|
|
|
keepGoing: false,
|
2022-03-03 02:12:56 +00:00
|
|
|
modID: projInfo.id,
|
|
|
|
modVersion: projInfo.versionNumber,
|
2022-01-14 04:25:47 +00:00
|
|
|
layers: {}
|
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
|
|
|
player
|
2022-01-25 04:25:34 +00:00
|
|
|
) as 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
|
|
|
}
|
|
|
|
|
2022-04-18 02:15:38 +00:00
|
|
|
export function save(playerData?: PlayerData): string {
|
2022-05-11 01:58:13 +00:00
|
|
|
const stringifiedSave = LZString.compressToUTF16(
|
|
|
|
stringifySave(playerData ?? player[ProxyState])
|
|
|
|
);
|
2022-04-18 02:15:38 +00:00
|
|
|
localStorage.setItem((playerData ?? player[ProxyState]).id, stringifiedSave);
|
2022-01-14 04:25:47 +00:00
|
|
|
return stringifiedSave;
|
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 async function load(): Promise<void> {
|
2021-09-05 23:53:04 +00:00
|
|
|
// Load global settings
|
|
|
|
loadSettings();
|
|
|
|
|
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
|
|
|
try {
|
2022-04-18 02:15:38 +00:00
|
|
|
let save = localStorage.getItem(settings.active);
|
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 (save == null) {
|
|
|
|
await loadSave(newSave());
|
|
|
|
return;
|
|
|
|
}
|
2022-04-18 02:15:38 +00:00
|
|
|
if (save[0] === "{") {
|
|
|
|
// plaintext. No processing needed
|
|
|
|
} else if (save[0] === "e") {
|
|
|
|
// Assumed to be base64, which starts with e
|
|
|
|
save = decodeURIComponent(escape(atob(save)));
|
|
|
|
} else if (save[0] === "ᯡ") {
|
|
|
|
// Assumed to be lz, which starts with ᯡ
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
save = LZString.decompressFromUTF16(save)!;
|
|
|
|
} else {
|
|
|
|
throw `Unable to determine save encoding`;
|
|
|
|
}
|
|
|
|
const player = JSON.parse(save);
|
2022-03-03 02:12:56 +00:00
|
|
|
if (player.modID !== projInfo.id) {
|
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
|
|
|
await loadSave(newSave());
|
|
|
|
return;
|
|
|
|
}
|
2022-01-14 04:25:47 +00:00
|
|
|
player.id = settings.active;
|
|
|
|
await loadSave(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
|
|
|
} catch (e) {
|
2022-01-25 04:23:30 +00:00
|
|
|
console.error("Failed to load save. Falling back to new save.\n", e);
|
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
|
|
|
await loadSave(newSave());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function newSave(): PlayerData {
|
|
|
|
const id = getUniqueID();
|
2022-01-25 04:25:34 +00:00
|
|
|
const player = setupInitialStore({ id });
|
2022-04-18 02:15:38 +00:00
|
|
|
save(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
|
|
|
|
2021-09-05 23:53:04 +00:00
|
|
|
settings.saves.push(id);
|
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
|
|
|
return 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
|
|
|
}
|
|
|
|
|
|
|
|
export function getUniqueID(): string {
|
|
|
|
let id,
|
|
|
|
i = 0;
|
|
|
|
do {
|
2022-03-03 02:12:56 +00:00
|
|
|
id = `${projInfo.id}-${i++}`;
|
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
|
|
|
} while (localStorage.getItem(id));
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
export async function loadSave(playerObj: Partial<PlayerData>): Promise<void> {
|
2022-01-25 04:23:30 +00:00
|
|
|
console.info("Loading save", playerObj);
|
2022-03-04 03:39:48 +00:00
|
|
|
const { layers, removeLayer, addLayer } = await import("game/layers");
|
|
|
|
const { fixOldSave, getInitialLayers } = await import("data/projEntry");
|
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
|
|
|
|
|
|
|
for (const layer in layers) {
|
2022-05-03 01:50:05 +00:00
|
|
|
const l = layers[layer];
|
|
|
|
if (l) {
|
|
|
|
removeLayer(l);
|
|
|
|
}
|
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
|
|
|
getInitialLayers(playerObj).forEach(layer => addLayer(layer, playerObj));
|
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-25 04:25:34 +00:00
|
|
|
playerObj = setupInitialStore(playerObj);
|
2022-01-14 04:25:47 +00:00
|
|
|
if (playerObj.offlineProd && playerObj.time) {
|
2022-03-11 20:02:41 +00:00
|
|
|
if (playerObj.offlineTime == undefined) playerObj.offlineTime = 0;
|
|
|
|
playerObj.offlineTime += (Date.now() - playerObj.time) / 1000;
|
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
|
|
|
playerObj.time = Date.now();
|
2022-03-03 02:12:56 +00:00
|
|
|
if (playerObj.modVersion !== projInfo.versionNumber) {
|
2022-01-14 04:25:47 +00:00
|
|
|
fixOldSave(playerObj.modVersion, playerObj);
|
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
|
|
|
Object.assign(player, playerObj);
|
2022-01-25 04:25:34 +00:00
|
|
|
settings.active = player.id;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
if (player.autosave) {
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
window.onbeforeunload = () => {
|
|
|
|
if (player.autosave) {
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
};
|
2022-07-10 03:09:25 +00:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
/**
|
2022-07-10 05:43:52 +00:00
|
|
|
* Augment the window object so the save function, and the hard reset function can be access from the console.
|
2022-07-10 03:09:25 +00:00
|
|
|
*/
|
|
|
|
interface Window {
|
|
|
|
save: VoidFunction;
|
|
|
|
hardReset: VoidFunction;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
window.save = save;
|
2021-08-28 16:35:25 +00:00
|
|
|
export const hardReset = (window.hardReset = async () => {
|
2021-08-22 07:00:38 +00:00
|
|
|
await loadSave(newSave());
|
2021-08-28 16:35:25 +00:00
|
|
|
});
|