diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/craftmine.js | 8 | ||||
-rw-r--r-- | js/gui.js | 6 | ||||
-rw-r--r-- | js/savegame.js | 42 |
3 files changed, 50 insertions, 6 deletions
diff --git a/js/craftmine.js b/js/craftmine.js index 7c37e59..ffc9b5e 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -14,7 +14,10 @@ function sendRequest(url, params, callback) { xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { - var data = JSON.parse(xhr.responseText); + var data = ""; + if(xhr.responseText) data = JSON.parse(xhr.responseText); + if(data.info) + showInfo(data.info); if(data.error) { showError(data.error); return; @@ -50,11 +53,12 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { data.gold = parseInt(ret.gold); // Server's response is a string + data.mine = 0; // Reset mine if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); if(ret.dungeon) displayDungeon(); data.miners = parseInt(ret.miners); - updateData("gold","miners"); + updateData("gold", "mine", "miners"); }) } @@ -6,10 +6,8 @@ function changeTab() { var id = window.location.hash.substr(4); var tabs = document.querySelectorAll("#tabs-panel > ul > li"); for(var i=0; i < tabs.length; i++) { - if(i == id-1) - tabs[i].className = "active"; - else - tabs[i].className = ""; + if(i == id-1) tabs[i].classList.add("active"); // Doesn't work with IE < 10 (and Opera Mini), but who cares? + else tabs[i].classList.remove("active"); } } diff --git a/js/savegame.js b/js/savegame.js new file mode 100644 index 0000000..4a08f91 --- /dev/null +++ b/js/savegame.js @@ -0,0 +1,42 @@ +function listSaves() { + sendRequest("craftmine.php", "op=listSaves", function(ret) { + var tmphtml="" + for(var i=0; i<ret.length; i++) { + tmphtml += "<label class=\"radio\"><input name=\"saveRadio\" value=\"" + i + "\" type=\"radio\" />" + ret[i] + "</label>\n"; + } + console.log(tmphtml); + document.getElementById("listsaves").innerHTML = tmphtml; + }); +} + +function getCheckedSave() { + var radios = document.getElementsByName('saveRadio'); + for (var i = 0, length = radios.length; i < length; i++) { + if (radios[i].checked) return radios[i].parentNode.textContent; + } + return -1; +} + +function loadSave() { + sendRequest("craftmine.php", "op=loadSave&filename="+getCheckedSave(), function(ret) { + initCraftMine(); + }); +} + +function downloadSave() { + window.open("craftmine.php?op=downSave&filename="+getCheckedSave(), "_blank"); +} + +function deleteSave() { + sendRequest("craftmine.php", "op=deleteSave&filename="+getCheckedSave(), function(ret) { + listSaves(); + }); +} + +function saveGame() { + sendRequest("craftmine.php", "op=saveGame"); +} + +function downGame() { + window.open("craftmine.php?op=downSave", "_blank"); +} |