2022-06-05 22:30:40 +00:00
|
|
|
import type { Ref } from "vue";
|
2022-12-28 15:03:51 +00:00
|
|
|
import { reactive, unref } from "vue";
|
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-07-15 05:55:36 +00:00
|
|
|
/** The player save data object. */
|
2022-12-28 15:03:51 +00:00
|
|
|
export interface Player {
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The ID of this save. */
|
2022-01-14 04:25:47 +00:00
|
|
|
id: string;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** A multiplier for time passing. Set to 0 when the game is paused. */
|
2022-03-11 20:02:41 +00:00
|
|
|
devSpeed: number | null;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The display name of this save. */
|
2022-01-14 04:25:47 +00:00
|
|
|
name: string;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The open tabs. */
|
2022-01-14 04:25:47 +00:00
|
|
|
tabs: Array<string>;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The current time this save was last opened at, in ms since the unix epoch. */
|
2022-01-14 04:25:47 +00:00
|
|
|
time: number;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** Whether or not to automatically save every couple of seconds and on tab close. */
|
2022-01-14 04:25:47 +00:00
|
|
|
autosave: boolean;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** Whether or not to apply offline time when loading this save. */
|
2022-01-14 04:25:47 +00:00
|
|
|
offlineProd: boolean;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** How much offline time has been accumulated and not yet processed. */
|
2022-03-11 20:02:41 +00:00
|
|
|
offlineTime: number | null;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** How long, in ms, this game has been played. */
|
2022-03-11 20:02:41 +00:00
|
|
|
timePlayed: number;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** Whether or not to continue playing after {@link data/projEntry.hasWon} is true. */
|
2022-01-14 04:25:47 +00:00
|
|
|
keepGoing: boolean;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The ID of this project, to make sure saves aren't imported into the wrong project. */
|
2022-01-14 04:25:47 +00:00
|
|
|
modID: string;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** The version of the project this save was created by. Used for upgrading saves for new versions. */
|
2022-01-14 04:25:47 +00:00
|
|
|
modVersion: string;
|
2022-07-15 05:55:36 +00:00
|
|
|
/** A dictionary of layer save data. */
|
2022-06-05 22:30:40 +00:00
|
|
|
layers: Record<string, LayerData<unknown>>;
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 05:55:36 +00:00
|
|
|
/** A layer's save data. Automatically unwraps refs. */
|
2022-06-05 22:30:40 +00:00
|
|
|
export type LayerData<T> = {
|
|
|
|
[P in keyof T]?: T[P] extends (infer U)[]
|
2022-07-18 01:21:03 +00:00
|
|
|
? Record<string, LayerData<U>>
|
2022-06-05 22:30:40 +00:00
|
|
|
: T[P] extends Record<string, never>
|
|
|
|
? never
|
|
|
|
: T[P] extends Ref<infer S>
|
|
|
|
? S
|
|
|
|
: T[P] extends object
|
|
|
|
? LayerData<T[P]>
|
|
|
|
: T[P];
|
|
|
|
};
|
|
|
|
|
2022-12-28 15:03:51 +00:00
|
|
|
const player = reactive<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
|
|
|
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,
|
2022-03-11 20:02:41 +00:00
|
|
|
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,
|
|
|
|
modID: "",
|
|
|
|
modVersion: "",
|
|
|
|
layers: {}
|
|
|
|
});
|
|
|
|
|
2022-12-28 15:03:51 +00:00
|
|
|
export default window.player = player;
|
|
|
|
|
2022-07-15 05:55:36 +00:00
|
|
|
/** Convert a player save data object into a JSON string. Unwraps refs. */
|
2022-12-28 15:03:51 +00:00
|
|
|
export function stringifySave(player: Player): string {
|
2022-02-27 19:49:34 +00:00
|
|
|
return JSON.stringify(player, (key, value) => unref(value));
|
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 player can be accessed from the console. */
|
2022-07-10 03:09:25 +00:00
|
|
|
interface Window {
|
|
|
|
player: Player;
|
|
|
|
}
|
|
|
|
}
|