1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-21 08:12:39 +00:00

feat: Improved Mod IDs

This commit is contained in:
Braeden 2024-10-27 17:12:54 -04:00
parent 8cf14c49c0
commit 12a1ccf66b
2 changed files with 11 additions and 10 deletions

View file

@ -1,6 +1,5 @@
let modInfo = { let modInfo = {
name: "The ??? Tree", name: "The ??? Tree",
id: "mymod",
author: "nobody", author: "nobody",
pointsName: "points", pointsName: "points",
modFiles: ["layers.js", "tree.js"], modFiles: ["layers.js", "tree.js"],

View file

@ -1,9 +1,11 @@
// ************ Save stuff ************ // ************ Save stuff ************
let getModID = () => modInfo.id ?? `${modInfo.name.replace(/\s+/g, '-')}-${modInfo.author.replace(/\s+/g, '-')}`;
function save(force) { function save(force) {
NaNcheck(player) NaNcheck(player)
if (NaNalert && !force) return if (NaNalert && !force) return
localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(player))))); localStorage.setItem(getModID(), btoa(unescape(encodeURIComponent(JSON.stringify(player)))));
localStorage.setItem(modInfo.id+"_options", btoa(unescape(encodeURIComponent(JSON.stringify(options))))); localStorage.setItem(getModID()+"_options", btoa(unescape(encodeURIComponent(JSON.stringify(options)))));
} }
function startPlayerBase() { function startPlayerBase() {
@ -12,7 +14,7 @@ function startPlayerBase() {
navTab: (layoutInfo.showTree ? layoutInfo.startNavTab : "none"), navTab: (layoutInfo.showTree ? layoutInfo.startNavTab : "none"),
time: Date.now(), time: Date.now(),
notify: {}, notify: {},
versionType: modInfo.id, versionType: getModID(),
version: VERSION.num, version: VERSION.num,
beta: VERSION.beta, beta: VERSION.beta,
timePlayed: 0, timePlayed: 0,
@ -185,7 +187,7 @@ function fixData(defaultData, newData) {
} }
} }
function load() { function load() {
let get = localStorage.getItem(modInfo.id); let get = localStorage.getItem(getModID());
if (get === null || get === undefined) { if (get === null || get === undefined) {
player = getStartPlayer(); player = getStartPlayer();
@ -217,7 +219,7 @@ function load() {
} }
function loadOptions() { function loadOptions() {
let get2 = localStorage.getItem(modInfo.id+"_options"); let get2 = localStorage.getItem(getModID()+"_options");
if (get2) if (get2)
options = Object.assign(getStartOptions(), JSON.parse(decodeURIComponent(escape(atob(get2))))); options = Object.assign(getStartOptions(), JSON.parse(decodeURIComponent(escape(atob(get2)))));
else else
@ -274,10 +276,10 @@ function importSave(imported = undefined, forced = false) {
imported = prompt("Paste your save here"); imported = prompt("Paste your save here");
try { try {
tempPlr = Object.assign(getStartPlayer(), JSON.parse(atob(imported))); tempPlr = Object.assign(getStartPlayer(), JSON.parse(atob(imported)));
if (tempPlr.versionType != modInfo.id && !forced && !confirm("This save appears to be for a different mod! Are you sure you want to import?")) // Wrong save (use "Forced" to force it to accept.) if (tempPlr.versionType != getModID() && !forced && !confirm("This save appears to be for a different mod! Are you sure you want to import?")) // Wrong save (use "Forced" to force it to accept.)
return; return;
player = tempPlr; player = tempPlr;
player.versionType = modInfo.id; player.versionType = getModID();
fixSave(); fixSave();
versionCheck(); versionCheck();
NaNcheck(save) NaNcheck(save)
@ -291,12 +293,12 @@ function versionCheck() {
let setVersion = true; let setVersion = true;
if (player.versionType === undefined || player.version === undefined) { if (player.versionType === undefined || player.version === undefined) {
player.versionType = modInfo.id; player.versionType = getModID();
player.version = 0; player.version = 0;
} }
if (setVersion) { if (setVersion) {
if (player.versionType == modInfo.id && VERSION.num > player.version) { if (player.versionType == getModID() && VERSION.num > player.version) {
player.keepGoing = false; player.keepGoing = false;
if (fixOldSave) if (fixOldSave)
fixOldSave(player.version); fixOldSave(player.version);