aboutsummaryrefslogtreecommitdiffstats
path: root/js/craftmine.js
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-04-25 22:36:33 +0200
committerpiernov <piernov@piernov.org>2016-04-25 22:36:33 +0200
commit54635d17eef27eb2546d69599e4107b242509ced (patch)
tree86d18cbb6e021b78ba1ce87307447d71d1802ad3 /js/craftmine.js
parentf98b06a25d71cc02bf29d7c525da0095688ea872 (diff)
parent8140617aeb2f32f7095a443ca743c6d6915739c6 (diff)
downloadcandybox-54635d17eef27eb2546d69599e4107b242509ced.tar.gz
candybox-54635d17eef27eb2546d69599e4107b242509ced.tar.bz2
candybox-54635d17eef27eb2546d69599e4107b242509ced.tar.xz
candybox-54635d17eef27eb2546d69599e4107b242509ced.zip
Merge branch 'alexichi' of ssh://piernov.org/srv/git/candybox into alexichi
Diffstat (limited to 'js/craftmine.js')
-rw-r--r--js/craftmine.js27
1 files changed, 20 insertions, 7 deletions
diff --git a/js/craftmine.js b/js/craftmine.js
index bbb1074..92fa45a 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -1,7 +1,7 @@
data = {
gold: 0,
mine: 0,
- miners: 1,
+ miners: 0,
level: 1
}
@@ -11,7 +11,12 @@ 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") {
- callback(xhr);
+ var data = JSON.parse(xhr.responseText);
+ if(data.error) {
+ showError(data.error);
+ return;
+ }
+ if(callback) callback(data);
}
}
xhr.send(params);
@@ -24,9 +29,14 @@ function updateData() {
}
}
+function debitAccount(amount) {
+ data.gold -= amount;
+ updateData("gold");
+}
+
function withdrawMine() {
sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) {
- var gold = parseInt(xhr.responseText); // Server's response is a string
+ var gold = parseInt(xhr); // Server's response is a string
if(isNaN(gold)) return;
data.gold = gold;
data.mine = 0;
@@ -35,10 +45,12 @@ function withdrawMine() {
}
function initCraftMine() {
- sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
- var ret = xhr.responseText;
- data.gold = parseInt(ret); // Server's response is a string
- updateData("gold");
+ sendRequest("craftmine.php", "op=getCraftMine", function(ret) {
+ data.gold = parseInt(ret.gold); // Server's response is a string
+ if(ret.shop) displayShop(ret.shop);
+ displayInventory(ret.inventory);
+ data.miners = parseInt(ret.miners);
+ updateData("gold","miners");
})
}
@@ -50,5 +62,6 @@ function updateMine() {
function init() {
initCraftMine();
+ changeTab();
window.setInterval(updateMine, 1000);
}