Sfoglia il codice sorgente

Added a way to save your character

tags/v0.7.0
Fen Dweller 7 anni fa
parent
commit
1b6c5cfdbe
2 ha cambiato i file con 50 aggiunte e 2 eliminazioni
  1. +46
    -0
      game.js
  2. +4
    -2
      stroll.html

+ 46
- 0
game.js Vedi File

@@ -1317,6 +1317,50 @@ function preset(name) {
}
}

function saveSettings() {
storage = window.localStorage;

settings = {};

form = document.forms.namedItem("custom-species-form");

for (var i=0; i<form.length; i++) {
if (form[i].value != "") {
if (form[i].type == "text")
settings[form[i].name] = form[i].value;
else if (form[i].type == "number")
settings[form[i].name] = parseFloat(form[i].value);
else if (form[i].type == "checkbox") {
settings[form[i].name] = form[i].checked;
}
}
}

storage.setItem('settings',JSON.stringify(settings));
}

function loadSettings() {
if (window.localStorage.getItem('settings') == null)
return;

storage = window.localStorage;

settings = JSON.parse(storage.getItem('settings'));
form = document.forms.namedItem("custom-species-form");

for (var i=0; i<form.length; i++) {
if (settings[form[i].name] != undefined) {
if (form[i].type == "text")
form[i].value = settings[form[i].name];
else if (form[i].type == "number")
form[i].value = settings[form[i].name];
else if (form[i].type == "checkbox") {
form[i].checked = settings[form[i].name];
}
}
}
}

function startGame(e) {

form = document.forms.namedItem("custom-species-form");
@@ -1457,6 +1501,8 @@ window.addEventListener('load', function(event) {
document.getElementById("button-amount-50").addEventListener("click",function() { grow_pick(50); });
document.getElementById("button-amount-100").addEventListener("click",function() { grow_pick(100); });

document.getElementById("button-load-custom").addEventListener("click",loadSettings);
document.getElementById("button-save-custom").addEventListener("click",saveSettings);
document.getElementById("button-start").addEventListener("click",startGame);
setTimeout(pick_move, 2000);
});

+ 4
- 2
stroll.html Vedi File

@@ -60,7 +60,7 @@
</div>
<div id=log-area>
<div id=log>
<div>Welcome to Stroll 0.3.5</div>
<div>Welcome to Stroll 0.3.6</div>
<div><b>This game features 18+ content</b></div>
<div><a href="https://chemicalcrux.org/stroll">Changelog</a></div>
<div>It's a nice day for a walk</div>
@@ -88,7 +88,7 @@


<div class=option-container id=option-panel>
<p>Welcome to Stroll 0.3.5</p>
<p>Welcome to Stroll 0.3.6</p>
<p><b>This game features 18+ content</b></p>
<a href="https://chemicalcrux.org/stroll">Changelog</a>
<br>
@@ -204,6 +204,8 @@
</div>
</ul>
</form>
<button class=option-button id=button-load-custom>Load Custom Character</button>
<button class=option-button id=button-save-custom>Save Custom Character</button>
<button class=option-button id=button-start>Start Game</button>
</div>
</div>


Loading…
Annulla
Salva