Browse Source

Some basic saving and loading

tags/v0.0.1
Fen Dweller 7 years ago
parent
commit
7f1f35040c
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
4 changed files with 52 additions and 1 deletions
  1. +10
    -0
      design/data.md
  2. +5
    -0
      gorge.css
  3. +2
    -0
      gorge.html
  4. +35
    -1
      gorge.js

+ 10
- 0
design/data.md View File

@@ -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

+ 5
- 0
gorge.css View File

@@ -13,6 +13,11 @@ body.dark {
display: none !important; display: none !important;
} }


button {
background-color: #444;
color: #eee;
}

#tasty-micro { #tasty-micro {
color: #ddd; color: #ddd;
background-color: #211; background-color: #211;


+ 2
- 0
gorge.html View File

@@ -21,6 +21,8 @@
<body class="dark"> <body class="dark">
<div id="top-bar"> <div id="top-bar">
vidya gaem vidya gaem
<button id="save">Save</button>
<button id="reset">Reset saved data</button>
</div> </div>
<div id="resources-area"> <div id="resources-area">
<div id="resources" class="title">Resources</div> <div id="resources" class="title">Resources</div>


+ 35
- 1
gorge.js View File

@@ -56,7 +56,6 @@ function productivityOf(type) {


function costOfBuilding(type) { function costOfBuilding(type) {
let baseCost = buildings[type].cost let baseCost = buildings[type].cost

let countCost = baseCost * Math.pow(1.15, belongings[type].count); let countCost = baseCost * Math.pow(1.15, belongings[type].count);


return Math.round(countCost); return Math.round(countCost);
@@ -204,6 +203,7 @@ function setup() {
createButtons(); createButtons();
createDisplays(); createDisplays();
registerListeners(); registerListeners();
load();
unlockAtStart(); unlockAtStart();


} }
@@ -260,6 +260,10 @@ function initializeData() {


function registerListeners() { function registerListeners() {
document.querySelector("#tasty-micro").addEventListener("click", eatMicro); document.querySelector("#tasty-micro").addEventListener("click", eatMicro);

document.querySelector("#save").addEventListener("click", save);

document.querySelector("#reset").addEventListener("click", reset);
} }


function createButtons() { function createButtons() {
@@ -551,3 +555,33 @@ window.onload = function() {


setTimeout(updateDisplay, 1000/updateRate); 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();
}

Loading…
Cancel
Save