aboutsummaryrefslogtreecommitdiffstats
path: root/js/shop.js
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-08 14:43:34 +0200
committerpiernov <piernov@piernov.org>2016-05-08 14:43:34 +0200
commit44fea0c94df8f61ac1f31b8506cca0346e41bac9 (patch)
tree06b0d2ebb67bea8a3ecc5a25186d8ab1d031b743 /js/shop.js
parentcdba8c2fd7785b0a6506d1369d790bbd1d8542ad (diff)
downloadcandybox-44fea0c94df8f61ac1f31b8506cca0346e41bac9.tar.gz
candybox-44fea0c94df8f61ac1f31b8506cca0346e41bac9.tar.bz2
candybox-44fea0c94df8f61ac1f31b8506cca0346e41bac9.tar.xz
candybox-44fea0c94df8f61ac1f31b8506cca0346e41bac9.zip
Rewrite JS useItem() to be able to consume Item using properties from XML and to delete Item
Diffstat (limited to 'js/shop.js')
-rw-r--r--js/shop.js28
1 files changed, 11 insertions, 17 deletions
diff --git a/js/shop.js b/js/shop.js
index ce0ecd8..4c04572 100644
--- a/js/shop.js
+++ b/js/shop.js
@@ -41,7 +41,7 @@ function addItem(ret) {
else{ // si c'est une n-ième itération
itemtag.innerHTML=ret[1];
}
-
+
var invcontent = document.getElementById("tab3");
if(invcontent.children.length <= 1)
@@ -66,22 +66,16 @@ function buyItem(name) {
function useItem(name) {
sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) {
- if(parseInt(ret[1])>=0){
- var nb = parseInt(document.getElementById("nbItem").innerHTML);
- if(nb>0){
- nb--;
- switch(ret[0].name){
- case "Life Bottle": data.hp = parseInt(data.hp) + 3; break;
- case "Strength Bottle" : break; // to do
- case "Wooden Sword" : break; //to do
- case "Metal Sword" : break; //to do
- }
- }
- document.getElementById("nbItem").innerHTML = nb;
- sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){
- displayPerso(data.hp,data.xp,data.level);
- });
- }
+ if(!ret.item) return;
+ if(ret.perso) updatePerso(ret.perso);
+
+ var item = document.querySelector("[data-name=\""+ret.item[0].name+"\"]");
+ var nb = ret.item[1];
+
+ if(nb>=1)
+ item.innerHTML = nb;
+ else
+ item.parentNode.parentNode.parentNode.removeChild(item.parentNode.parentNode); // Remove <li> item from the <ul> list
});
}