diff --git a/js/main.js b/js/main.js index d278528..f249d8e 100644 --- a/js/main.js +++ b/js/main.js @@ -1,6 +1,6 @@ function remplirMagasin(){ - + const table= document.getElementById("table_magasin_body") @@ -19,10 +19,27 @@ function remplirMagasin(){ const cout = document.createElement("td") cout.innerText = el.cout + const test = document.createElement("td") + const btn_acheter = document.createElement("button") + let tmp = key + btn_acheter.addEventListener("click", (event) =>{ + console.log("clé : ",tmp) + let t = new Technologie(tmp) + t.chargerDepuisBdd(true) + }) + + btn_acheter.innerText = "Acheter" + + test.appendChild(btn_acheter) + + tr.appendChild(nom) tr.appendChild(boost) tr.appendChild(cout) + tr.appendChild(test) + table.appendChild(tr) + }); }) @@ -30,4 +47,4 @@ function remplirMagasin(){ -} \ No newline at end of file +} diff --git a/js/technologie.js b/js/technologie.js index 15040b3..d007127 100644 --- a/js/technologie.js +++ b/js/technologie.js @@ -3,15 +3,20 @@ class Technologie{ this.nom = nom } - chargerDepuisBdd(){ + chargerDepuisBdd( style){ fetch("../bdd/arbre.json").then((data)=>{ data.json().then((data)=>{ - console.log(data) + console.log("clé dans technologie :",this.nom) this.props = data["technologies"][this.nom] this.cout = this.props.cout this.boost = this.props.boost + if(style){ + this.appliquerAmeliorationStyle() + } }) + + }) }