aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-04-25 10:00:20 +0200
committeralexichi <alexbankai96@gmail.com>2016-04-25 10:08:29 +0200
commitd013e0e873277dd1bf29f51a83bbd9e467cad23b (patch)
tree85bc045e1e46c000376b9e033f7b7e1faa2dfaf0
parenta6768cc97e3b418e0df08bcc2b09d8ffb1c9daa2 (diff)
parent198eaff1fb3469e27318592c4b592e2f099f41a1 (diff)
downloadcandybox-d013e0e873277dd1bf29f51a83bbd9e467cad23b.tar.gz
candybox-d013e0e873277dd1bf29f51a83bbd9e467cad23b.tar.bz2
candybox-d013e0e873277dd1bf29f51a83bbd9e467cad23b.tar.xz
candybox-d013e0e873277dd1bf29f51a83bbd9e467cad23b.zip
Merge branch 'master' of piernov.org:candybox into alexichi
Conflicts: js/craftmine.js
-rw-r--r--inc/mine.inc7
-rw-r--r--js/craftmine.js27
2 files changed, 19 insertions, 15 deletions
diff --git a/inc/mine.inc b/inc/mine.inc
index 7a68237..a2ecd09 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -5,9 +5,10 @@ function initCraftMine() {
}
function withdrawMine() {
- $mine = $_SESSION["mine"];
- $_SESSION["mine"]["gold"] += $mine["mine"];
- $_SESSION["mine"]["mine"] = 0;
+ $amount = intval($_POST["amount"]);
+ if($amount == 0) return;
+ $_SESSION["mine"]["gold"] += $amount;
+ echo $_SESSION["mine"]["gold"];
}
function sendMine() {
diff --git a/js/craftmine.js b/js/craftmine.js
index 4ccdf2f..9aaae5c 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,4 +1,4 @@
-datas = {
+data = {
gold: 0,
mine: 0,
miners: 0,
@@ -18,31 +18,34 @@ function sendRequest(url, params, callback) {
}
-function updateDatas(t) {
- document.getElementById(t).innerHTML = datas[t];
+function updateData() {
+ for (var i = 0; i < arguments.length; i++) {
+ document.getElementById(arguments[i]).innerHTML = data[arguments[i]];
+ }
}
function withdrawMine() {
- sendRequest("craftmine.php", "op=withdrawMine", function() {
- datas.gold += parseInt(datas.mine);
- datas.mine = 0;
- updateDatas("gold");
- updateDatas("mine");
+ sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) {
+ var gold = parseInt(xhr.responseText); // Server's response is a string
+ if(isNaN(gold)) return;
+ data.gold = gold;
+ data.mine = 0;
+ updateData("gold", "mine");
})
}
function initCraftMine() {
sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
var ret = xhr.responseText;
- datas.gold = parseInt(ret);
- updateDatas("gold");
+ data.gold = parseInt(ret); // Server's response is a string
+ updateData("gold");
})
}
function updateMine() {
- datas.mine += (datas.miners+1);
- updateDatas("mine");
+ data.mine += (data.miners+1);
+ updateData("mine");
}
function init() {