aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexichi <alexbankai96@gmail.com>2016-05-02 14:51:37 +0200
committeralexichi <alexbankai96@gmail.com>2016-05-02 14:51:37 +0200
commit556adda68fe99e3a88f59803aa9bd8892e4d34cf (patch)
tree2de7c76ad8c4c0cdfde7086c3cb179f44a665fbc
parent64b1663e55544e1ed0e072c4f624688625691c9f (diff)
downloadcandybox-556adda68fe99e3a88f59803aa9bd8892e4d34cf.tar.gz
candybox-556adda68fe99e3a88f59803aa9bd8892e4d34cf.tar.bz2
candybox-556adda68fe99e3a88f59803aa9bd8892e4d34cf.tar.xz
candybox-556adda68fe99e3a88f59803aa9bd8892e4d34cf.zip
fix shop item count
-rw-r--r--inc/Inventory.inc8
-rw-r--r--js/shop.js9
2 files changed, 9 insertions, 8 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 3396eb9..20c63bf 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -20,13 +20,13 @@ class Inventory {
}
private function _addItem($item) {
- $counter = 0;
- foreach($this->items as $object){
+ foreach($this->items as $k => $object){
if($object[0] == $item){
- $counter++;
+ $this->items[$k][1]++;
+ return $this->items[$k];
}
}
- $tab = array($item,$counter+1);
+ $tab = array($item,1);
$this->items[] = $tab;
return $tab;
}
diff --git a/js/shop.js b/js/shop.js
index 00f13af..bda3885 100644
--- a/js/shop.js
+++ b/js/shop.js
@@ -34,13 +34,14 @@ function buildShop() {
function addItem(ret) {
var itemhtml = "";
- if(ret[1]==1){ //si c'est la première itération de l'objet
+ var itemtag = document.querySelector("[data-name=\""+ret[0].name+"\"]");
+ if(!itemtag){ //si c'est la première itération de l'objet
itemhtml += "<li>";
- itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret[0].name + "')\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "(<span id=\"nbObjet\">"+ret[1]+"</span>)</button>";
+ itemhtml += "<button type=\"button\" class=\"btn btn-primary\" onclick=\"useItem('" + ret[0].name + "')\"><span class=\"item-icon\">" + ret[0].icon + "</span><br />" + ret[0].name + "(<span data-name=\""+ ret[0].name + "\">"+ret[1]+"</span>)</button>";
itemhtml += "</li>";
}
- else if(ret[1]>1){ // si c'est une n-ième itération
- document.getElementById("nbObjet").innerHTML=ret[1];
+ else{ // si c'est une n-ième itération
+ itemtag.innerHTML=ret[1];
}
var invcontent = document.getElementById("tab3");