Commit 5ba10c25 authored by Jyrki's avatar Jyrki 🐾

added basic load and save functionality

parent 55e29ff8
......@@ -361,10 +361,27 @@ marketSellItem = ->
updateCounters()
saveGame = ->
window.localStorage.gv = JSON.stringify window.gameVars
$('button#game-load').removeAttr "disabled"
$.growl.notice {
title: "Success!"
message: "Successfully saved game."
}
loadGame = ->
window.gameVars = JSON.parse window.localStorage.gv
$.growl.notice {
title: "Success!"
message: "Successfully loaded game."
}
$(document).on "change", "input[name=market-slider]", marketSliderChange
$(document).on "mousemove", "input[name=market-slider]", marketSliderChange
$(document).on "click", "button[name=market-buy]", marketBuyItem
$(document).on "click", "button[name=market-sell]", marketSellItem
$(document).on "click", "button#game-load", loadGame
$(document).on "click", "button#game-save", saveGame
evtim = window.setInterval eventTimer, 30000
fitim = window.setInterval fieldTimer, 100
......@@ -373,3 +390,6 @@ lstim = window.setInterval livestockTimer, 1000
cgtim = window.setInterval cattleGridTimer, 1000
$(document).ready -> updateCounters()
$(document).ready ->
unless window.localStorage.gv
$('button#game-load').attr "disabled", "disabled"
......@@ -53,8 +53,13 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">About</a></li>
<li><a href="#">Another Link</a></li>
<li><a href="#">About</a></li>
<li class="navbar-form">
<div class="btn-group">
<button type="button" class="btn btn-default" id="game-load"><i class="fa fa-folder-open-o"></i> Load</button>
<button type="button" class="btn btn-default" id="game-save"><i class="fa fa-floppy-o"></i> Save</button>
</div>
</li>
</ul>
</div><!--/.navbar-collapse -->
</div>
......
// Generated by CoffeeScript 1.7.1
(function() {
var cattleGridTimer, cgtim, cgtimEnabled, eventTimer, evtim, fieldTimer, fitim, getPrice, initItem, livestockTimer, lstim, lstimEnabled, marketBuyItem, marketSellItem, marketSliderChange, setPriceLabels, updateCounters, warTimer, wheatTimer, whtim;
var cattleGridTimer, cgtim, cgtimEnabled, eventTimer, evtim, fieldTimer, fitim, getPrice, initItem, livestockTimer, loadGame, lstim, lstimEnabled, marketBuyItem, marketSellItem, marketSliderChange, saveGame, setPriceLabels, updateCounters, warTimer, wheatTimer, whtim;
initItem = function(defaultCount, consumable) {
var retobj;
......@@ -396,6 +396,23 @@
return updateCounters();
};
saveGame = function() {
window.localStorage.gv = JSON.stringify(window.gameVars);
$('button#game-load').removeAttr("disabled");
return $.growl.notice({
title: "Success!",
message: "Successfully saved game."
});
};
loadGame = function() {
window.gameVars = JSON.parse(window.localStorage.gv);
return $.growl.notice({
title: "Success!",
message: "Successfully loaded game."
});
};
$(document).on("change", "input[name=market-slider]", marketSliderChange);
$(document).on("mousemove", "input[name=market-slider]", marketSliderChange);
......@@ -404,6 +421,10 @@
$(document).on("click", "button[name=market-sell]", marketSellItem);
$(document).on("click", "button#game-load", loadGame);
$(document).on("click", "button#game-save", saveGame);
evtim = window.setInterval(eventTimer, 30000);
fitim = window.setInterval(fieldTimer, 100);
......@@ -418,4 +439,10 @@
return updateCounters();
});
$(document).ready(function() {
if (!window.localStorage.gv) {
return $('button#game-load').attr("disabled", "disabled");
}
});
}).call(this);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment