2021-09-05 23:53:04 +00:00
|
|
|
import modInfo from "@/data/modInfo.json";
|
|
|
|
import { Themes } from "@/data/themes";
|
2022-01-14 04:25:47 +00:00
|
|
|
import { globalBus } from "@/game/events";
|
2021-09-05 23:53:04 +00:00
|
|
|
import { hardReset } from "@/util/save";
|
2022-01-14 04:25:47 +00:00
|
|
|
import { reactive, watch } from "vue";
|
2021-09-05 23:53:04 +00:00
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface Settings {
|
|
|
|
active: string;
|
|
|
|
saves: string[];
|
|
|
|
showTPS: boolean;
|
|
|
|
theme: Themes;
|
|
|
|
unthrottled: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = reactive<Partial<Settings>>({
|
2021-09-05 23:53:04 +00:00
|
|
|
active: "",
|
|
|
|
saves: [],
|
|
|
|
showTPS: true,
|
2021-09-06 00:13:56 +00:00
|
|
|
theme: Themes.Nordic,
|
|
|
|
unthrottled: false
|
2021-09-05 23:53:04 +00:00
|
|
|
});
|
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
watch(
|
|
|
|
() => state,
|
|
|
|
state =>
|
|
|
|
localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(state))))),
|
|
|
|
{ deep: true }
|
|
|
|
);
|
|
|
|
export default window.settings = state as Settings;
|
2021-09-05 23:53:04 +00:00
|
|
|
|
|
|
|
export function loadSettings(): void {
|
|
|
|
try {
|
|
|
|
const item: string | null = localStorage.getItem(modInfo.id);
|
|
|
|
if (item != null && item !== "") {
|
|
|
|
const settings = JSON.parse(decodeURIComponent(escape(atob(item))));
|
|
|
|
if (typeof settings === "object") {
|
|
|
|
Object.assign(state, settings);
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 04:25:47 +00:00
|
|
|
globalBus.emit("loadSettings", state);
|
2021-09-05 23:53:04 +00:00
|
|
|
// eslint-disable-next-line no-empty
|
|
|
|
} catch {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const hardResetSettings = (window.hardResetSettings = () => {
|
2022-01-14 04:25:47 +00:00
|
|
|
const settings = {
|
2021-09-05 23:53:04 +00:00
|
|
|
active: "",
|
|
|
|
saves: [],
|
|
|
|
showTPS: true,
|
|
|
|
theme: Themes.Nordic
|
2022-01-14 04:25:47 +00:00
|
|
|
};
|
|
|
|
globalBus.emit("loadSettings", settings);
|
|
|
|
Object.assign(state, settings);
|
2021-09-05 23:53:04 +00:00
|
|
|
hardReset();
|
|
|
|
});
|