print version on startup, and whether the game has loaded

This commit is contained in:
2023-02-27 17:12:27 -08:00
parent fbf8830b31
commit e3d022df68
2 changed files with 13 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
const ver_numeric = 0;
const ver_string = "pre alpha";
const sleep = ms => new Promise(r => setTimeout(r, ms)); // sleep(int ms)
var page_elements = {};
@@ -16,8 +19,14 @@ const gamestate_default = {
function prepare_gamestate() {
var gamestate_loaded = window.localStorage.getItem("gamestate");
if (gamestate_loaded == null) { gamestate = structuredClone(gamestate_default); }
else { gamestate = JSON.parse(gamestate_loaded); }
if (gamestate_loaded == null) {
record_log("Welcome to Seagull Game! We haven't found a save in your browser storage, so we're starting a new game!");
gamestate = structuredClone(gamestate_default);
}
else {
gamestate = JSON.parse(gamestate_loaded);
record_log("Welcome back! Game loaded.")
}
}
function record_log(text) {
@@ -95,7 +104,7 @@ document.addEventListener("DOMContentLoaded", function (ev) {
prepare_gamestate();
record_log("It works!");
record_log("seagull game ver. " + ver_string);
page_elements["lbl_name"].innerHTML = gamestate["name"];
page_elements["lbl_tick"].innerHTML = gamestate["tick"];