aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-04-24 13:41:46 +0200
committerpiernov <piernov@piernov.org>2016-04-24 13:41:46 +0200
commitf98b06a25d71cc02bf29d7c525da0095688ea872 (patch)
treef3302e9dc0f078cb5ca9b8806fa093f824ef8bb6
parent725c3529c3c2f63998578cfbcb070bdfa3a9ce19 (diff)
parent198eaff1fb3469e27318592c4b592e2f099f41a1 (diff)
downloadcandybox-f98b06a25d71cc02bf29d7c525da0095688ea872.tar.gz
candybox-f98b06a25d71cc02bf29d7c525da0095688ea872.tar.bz2
candybox-f98b06a25d71cc02bf29d7c525da0095688ea872.tar.xz
candybox-f98b06a25d71cc02bf29d7c525da0095688ea872.zip
Merge remote-tracking branch 'origin/master' into alexichi
-rw-r--r--inc/mine.inc9
-rw-r--r--js/craftmine.js27
2 files changed, 20 insertions, 16 deletions
diff --git a/inc/mine.inc b/inc/mine.inc
index 76c0055..aea04ad 100644
--- a/inc/mine.inc
+++ b/inc/mine.inc
@@ -5,13 +5,14 @@ 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() {
- if(empty($_SESSION["mine"])) initMine();
+ if(empty($_SESSION["mine"])) initCraftMine();
$mine = $_SESSION["mine"];
echo $mine["gold"];
}
diff --git a/js/craftmine.js b/js/craftmine.js
index 50d3a47..bbb1074 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,4 +1,4 @@
-datas = {
+data = {
gold: 0,
mine: 0,
miners: 1,
@@ -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 = 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() {