aboutsummaryrefslogtreecommitdiffstats
path: root/js/shop.js
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-04-25 10:43:56 +0200
committeralexichi <alexbankai96@gmail.com>2016-04-25 10:43:56 +0200
commit1ffba62faae83e18597270b68580a90ac3032a31 (patch)
tree603d33ed48a9dd3690aeef379eeb7fd8ce3a257f /js/shop.js
parent3ece645cc83e36aaa36c0258afa0f1b36eb13ca2 (diff)
parentdc28807625b9f53e621ec0d7063d99c2527cfa02 (diff)
downloadcandybox-1ffba62faae83e18597270b68580a90ac3032a31.tar.gz
candybox-1ffba62faae83e18597270b68580a90ac3032a31.tar.bz2
candybox-1ffba62faae83e18597270b68580a90ac3032a31.tar.xz
candybox-1ffba62faae83e18597270b68580a90ac3032a31.zip
Merge remote-tracking branch 'origin/piernov' into alexichi
Conflicts: craftmine.php index.xhtml
Diffstat (limited to 'js/shop.js')
-rw-r--r--js/shop.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/js/shop.js b/js/shop.js
new file mode 100644
index 0000000..00636e1
--- /dev/null
+++ b/js/shop.js
@@ -0,0 +1,57 @@
+function displayShop(ret) {
+ var tmphtml = "<h4> Select an item to buy it:</h4>";
+ tmphtml += "<ul class=\"list-inline\">";
+ for(var i=0; i < ret.items.length; i++) {
+ tmphtml += "<li>";
+ tmphtml += "<button type=\"submit\" class=\"btn btn-primary\" onclick=\"buyItem('" + ret.items[i].name + "')\"><span class=\"item-icon\">" + ret.items[i].icon + "</span><br />" + ret.items[i].name + "</button>";
+ tmphtml += "</li>";
+ }
+ tmphtml += "</ul>"
+ document.getElementById("tab2").innerHTML = tmphtml;
+}
+
+function displayInventory(items) {
+ for(var i=0; i < items.length; i++) {
+ addItem(items[i]);
+ }
+}
+
+function buildShop() {
+ sendRequest("craftmine.php", "op=buildShop", function(ret) {
+ displayShop(ret);
+ debitAccount(ret.cost);
+ });
+}
+
+function addItem(ret) {
+ var itemhtml = "<li>";
+ itemhtml += "<button type=\"submit\" class=\"btn btn-primary\" onclick=\"useItem('" + ret.name + "')\"><span class=\"item-icon\">" + ret.icon + "</span><br />" + ret.name + "</button>";
+ itemhtml += "</li>";
+
+ var invcontent = document.getElementById("tab3");
+
+ if(invcontent.children.length <= 1)
+ {
+ var tmphtml = "<h4>Your bag contains the following items:</h4>";
+ tmphtml += "<ul class=\"list-inline\">";
+ tmphtml += itemhtml;
+ tmphtml += "</ul>"
+ invcontent.innerHTML = tmphtml;
+ } else
+ invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml;
+
+ showInfo(ret.desc);
+}
+
+function buyItem(name) {
+ sendRequest("craftmine.php", "op=buyItem&item="+name, function(ret) {
+ addItem(ret);
+ debitAccount(ret.cost);
+ });
+}
+
+function useItem(name) {
+ sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) {
+ });
+}
+