From 2b0a84a41eeb90094d42c3c516bf99837d08a745 Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 27 Apr 2016 19:47:34 +0200 Subject: Automatically show received info --- js/craftmine.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/craftmine.js') diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..28583dd 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -12,6 +12,8 @@ function sendRequest(url, params, callback) { xhr.onreadystatechange = function() { if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") { var data = JSON.parse(xhr.responseText); + if(data.info) + showInfo(data.info); if(data.error) { showError(data.error); return; -- cgit v1.2.3-54-g00ecf From 0133251e523b1c984b2b5cdb60c7392c18e6bd73 Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 27 Apr 2016 19:51:32 +0200 Subject: Add button for saving on server/downloading the game --- index.xhtml | 2 ++ js/craftmine.js | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'js/craftmine.js') diff --git a/index.xhtml b/index.xhtml index aa29615..d12585f 100644 --- a/index.xhtml +++ b/index.xhtml @@ -32,6 +32,8 @@
+ +
diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..13dd0a2 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -60,6 +60,14 @@ function updateMine() { updateData("mine"); } +function saveGame() { + sendRequest("craftmine.php", "op=saveGame"); +} + +function downGame() { + window.open("craftmine.php?op=downGame", "_blank"); +} + function init() { initCraftMine(); changeTab(); -- cgit v1.2.3-54-g00ecf From b60d56327a1b8531d15348034889e67f8b49444d Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:44:28 +0200 Subject: Allow empty data from server --- js/craftmine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/craftmine.js') diff --git a/js/craftmine.js b/js/craftmine.js index 8af8296..608efb7 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -11,7 +11,8 @@ 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) { -- cgit v1.2.3-54-g00ecf From 6bff76321ab05d6193bc1d35327cb44128f9ed66 Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:45:44 +0200 Subject: Force reset mine on game reload --- js/craftmine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/craftmine.js') diff --git a/js/craftmine.js b/js/craftmine.js index 608efb7..d649305 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -50,10 +50,11 @@ 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); data.miners = parseInt(ret.miners); - updateData("gold","miners"); + updateData("gold", "mine", "miners"); }) } -- cgit v1.2.3-54-g00ecf From f53549e4c2668ca268c8e31ef4c7cf3718fe08b5 Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 2 May 2016 15:50:14 +0200 Subject: Move saveGame()/downGame() to its own JS file --- index.xhtml | 1 + js/craftmine.js | 8 -------- js/savegame.js | 7 +++++++ 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 js/savegame.js (limited to 'js/craftmine.js') diff --git a/index.xhtml b/index.xhtml index d12585f..e879cf1 100644 --- a/index.xhtml +++ b/index.xhtml @@ -15,6 +15,7 @@ +
diff --git a/js/craftmine.js b/js/craftmine.js index 13dd0a2..92fa45a 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -60,14 +60,6 @@ function updateMine() { updateData("mine"); } -function saveGame() { - sendRequest("craftmine.php", "op=saveGame"); -} - -function downGame() { - window.open("craftmine.php?op=downGame", "_blank"); -} - function init() { initCraftMine(); changeTab(); diff --git a/js/savegame.js b/js/savegame.js new file mode 100644 index 0000000..2a83f77 --- /dev/null +++ b/js/savegame.js @@ -0,0 +1,7 @@ +function saveGame() { + sendRequest("craftmine.php", "op=saveGame"); +} + +function downGame() { + window.open("craftmine.php?op=downSave", "_blank"); +} -- cgit v1.2.3-54-g00ecf