Browse Source

Autosave every 60 seconds

tags/v0.0.2
Fen Dweller 5 years ago
parent
commit
89b93b5bb7
2 changed files with 18 additions and 5 deletions
  1. +2
    -2
      gorge.css
  2. +16
    -3
      gorge.js

+ 2
- 2
gorge.css View File

@@ -341,10 +341,10 @@ button {

.click-popup-info {
pointer-events: none;
transform-origin: -50% 50%;
text-align: center;
position: fixed;
animation: click-popup-upgrade 2s linear;
transform-origin: 0% 0%;
animation: click-popup-info 2s linear;
animation-fill-mode: both;
font-size: 36px;
--target: -200px;


+ 16
- 3
gorge.js View File

@@ -570,7 +570,7 @@ function clickPopup(text, type, location) {
} else if (type == "upgrade") {
direction = -50;
} else if (type == "info") {
direction = 50;
direction = 0;
}

direction *= Math.random() * 0.5 + 1;
@@ -684,9 +684,24 @@ window.onload = function() {
lastTime = performance.now();

setTimeout(updateDisplay, 1000/updateRate);

setTimeout(autosave, 60000);
}

function autosave() {
saveGame();
let x = window.innerWidth / 2;
let y = window.innerHeight * 9 / 10;
clickPopup("Autosaving...", "info", [x, y]);
setTimeout(autosave, 60000);
}

function save(e) {
saveGame();
clickPopup("Saved!", "info", [e.clientX, e.clientY]);
}

function saveGame() {
let storage = window.localStorage;

storage.setItem("save-version", "0.0.1");
@@ -696,8 +711,6 @@ function save(e) {
storage.setItem("resources", JSON.stringify(resources));

storage.setItem("belongings", JSON.stringify(belongings));

clickPopup("Saved!", "upgrade", [e.clientX, e.clientY]);
}

function load() {


Loading…
Cancel
Save