diff --git a/design/data.md b/design/data.md new file mode 100644 index 0000000..97b827f --- /dev/null +++ b/design/data.md @@ -0,0 +1,10 @@ +## Saving + +The following records should be saved and loaded: + +* `ownedUpgrades` - boolean values for every upgrade + * Will need to have new upgrades inserted +* `resources` - values for every resource + * New resources should be inserted +* `belongings` - count of each building + * New buildings should be inserted diff --git a/gorge.css b/gorge.css index cf7706c..2cb549c 100644 --- a/gorge.css +++ b/gorge.css @@ -13,6 +13,11 @@ body.dark { display: none !important; } +button { + background-color: #444; + color: #eee; +} + #tasty-micro { color: #ddd; background-color: #211; diff --git a/gorge.html b/gorge.html index 53953c7..f6c2bb3 100644 --- a/gorge.html +++ b/gorge.html @@ -21,6 +21,8 @@
vidya gaem + +
Resources
diff --git a/gorge.js b/gorge.js index 162cda8..1a8553f 100644 --- a/gorge.js +++ b/gorge.js @@ -56,7 +56,6 @@ function productivityOf(type) { function costOfBuilding(type) { let baseCost = buildings[type].cost - let countCost = baseCost * Math.pow(1.15, belongings[type].count); return Math.round(countCost); @@ -204,6 +203,7 @@ function setup() { createButtons(); createDisplays(); registerListeners(); + load(); unlockAtStart(); } @@ -260,6 +260,10 @@ function initializeData() { function registerListeners() { document.querySelector("#tasty-micro").addEventListener("click", eatMicro); + + document.querySelector("#save").addEventListener("click", save); + + document.querySelector("#reset").addEventListener("click", reset); } function createButtons() { @@ -551,3 +555,33 @@ window.onload = function() { setTimeout(updateDisplay, 1000/updateRate); } + +function save() { + let storage = window.localStorage; + + storage.setItem("save-version", "0.0.1"); + + storage.setItem("ownedUpgrades", JSON.stringify(ownedUpgrades)); + + storage.setItem("resources", JSON.stringify(resources)); + + storage.setItem("belongings", JSON.stringify(belongings)); +} + +function load() { + let storage = window.localStorage; + + if (!storage.getItem("save-version")) { + return; + } + + ownedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); + + resources = JSON.parse(storage.getItem("resources")); + + belongings = JSON.parse(storage.getItem("belongings")); +} + +function reset() { + window.localStorage.clear(); +}