Explorar el Código

Added a way to save your character

tags/v0.7.0
Fen Dweller hace 8 años
padre
commit
1b6c5cfdbe
Se han modificado 2 ficheros con 50 adiciones y 2 borrados
  1. +46
    -0
      game.js
  2. +4
    -2
      stroll.html

+ 46
- 0
game.js Ver fichero

@@ -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) { function startGame(e) {


form = document.forms.namedItem("custom-species-form"); 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-50").addEventListener("click",function() { grow_pick(50); });
document.getElementById("button-amount-100").addEventListener("click",function() { grow_pick(100); }); 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); document.getElementById("button-start").addEventListener("click",startGame);
setTimeout(pick_move, 2000); setTimeout(pick_move, 2000);
}); });

+ 4
- 2
stroll.html Ver fichero

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




<div class=option-container id=option-panel> <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> <p><b>This game features 18+ content</b></p>
<a href="https://chemicalcrux.org/stroll">Changelog</a> <a href="https://chemicalcrux.org/stroll">Changelog</a>
<br> <br>
@@ -204,6 +204,8 @@
</div> </div>
</ul> </ul>
</form> </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> <button class=option-button id=button-start>Start Game</button>
</div> </div>
</div> </div>


Cargando…
Cancelar
Guardar