Compare commits
No commits in common. "692fc9aeb6410bc7e8a2cf3e8794c25d0c37a6dd" and "7373b6481335a8f178be5c0536a5417734452520" have entirely different histories.
692fc9aeb6
...
7373b64813
4 changed files with 57 additions and 89 deletions
|
@ -4,14 +4,16 @@ class Element{
|
||||||
this.techno = techno
|
this.techno = techno
|
||||||
}
|
}
|
||||||
|
|
||||||
async chargerDepuisBdd(){
|
chargerDepuisBdd(){
|
||||||
let data = await fetch("../bdd/arbre.json")
|
fetch("../bdd/arbre.json").then((data)=>{
|
||||||
data = await data.json()
|
data.json().then((data)=>{
|
||||||
|
this.props = data["technologies"][this.techno]["elements"][this.tag]
|
||||||
|
this.cout = this.props.cout
|
||||||
|
this.nom = this.props.nom
|
||||||
|
this.boost = this.props.boost
|
||||||
|
})
|
||||||
|
|
||||||
this.props = data["technologies"][this.techno]["elements"][this.tag]
|
})
|
||||||
this.cout = this.props.cout
|
|
||||||
this.nom = this.props.nom
|
|
||||||
this.boost = this.props.boost
|
|
||||||
}
|
}
|
||||||
|
|
||||||
afficherDropsDansHtml(){
|
afficherDropsDansHtml(){
|
||||||
|
|
|
@ -32,7 +32,4 @@ function scoreCount(){
|
||||||
const score_aff = document.getElementById("score_affichage")
|
const score_aff = document.getElementById("score_affichage")
|
||||||
score += 1
|
score += 1
|
||||||
score_aff.innerText="SCORE : " + score
|
score_aff.innerText="SCORE : " + score
|
||||||
|
|
||||||
// check refresh la table magasin pour afficher une amélioration si un palier est atteint
|
|
||||||
remplirMagasin()
|
|
||||||
}
|
}
|
||||||
|
|
92
js/main.js
92
js/main.js
|
@ -1,72 +1,34 @@
|
||||||
|
function remplirMagasin(){
|
||||||
// stoque les ameliorations deja disponibles dans le magasin pour ne pas le faire clignoter
|
|
||||||
let magasin = {}
|
|
||||||
|
|
||||||
// stoquer les ameliorations deja achetees pour ne pas les afficher dans le magasin
|
|
||||||
let sacado = {}
|
|
||||||
|
|
||||||
async function remplirMagasin(){
|
|
||||||
|
|
||||||
|
|
||||||
const table= document.getElementById("table_magasin_body")
|
const table= document.getElementById("table_magasin_body")
|
||||||
|
|
||||||
let data = await fetch("../bdd/arbre.json")
|
|
||||||
data = await data.json()
|
|
||||||
|
|
||||||
let tech = data["technologies"]
|
fetch("../bdd/arbre.json").then((data)=>{
|
||||||
|
data.json().then((data)=>{
|
||||||
|
console.log(data)
|
||||||
|
let tech = data["technologies"]
|
||||||
|
|
||||||
for(const key in tech){
|
Object.keys(tech).forEach(key => {
|
||||||
console.log(sacado)
|
el = tech[key]
|
||||||
console.log(magasin)
|
const tr = document.createElement("tr")
|
||||||
// ne va pas s'embeter à proecess si on a deja acheté l'amelioration
|
const nom = document.createElement("td")
|
||||||
if(!sacado[key] && !magasin[key]){
|
nom.innerText = el.nom
|
||||||
el = tech[key]
|
const boost = document.createElement("td")
|
||||||
|
boost.innerText = el.boost
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
const tr = document.createElement("tr")
|
btn_acheter.innerText = "Acheter"
|
||||||
const nom = document.createElement("td")
|
|
||||||
nom.innerText = el.nom
|
|
||||||
const boost = document.createElement("td")
|
|
||||||
boost.innerText = el.boost
|
|
||||||
const cout = document.createElement("td")
|
|
||||||
cout.innerText = el.cout
|
|
||||||
|
|
||||||
const test = document.createElement("td")
|
|
||||||
const btn_acheter = document.createElement("button")
|
|
||||||
|
|
||||||
// stoquage temporaire de la clé JSON correspondant à la technologie à débloquer
|
|
||||||
// pour éviter de référencer key, qui va sauter sur sa valeur finale
|
|
||||||
let tmp = key
|
|
||||||
|
|
||||||
|
|
||||||
let t = new Technologie(tmp)
|
|
||||||
// charge les propriétés de la technologie depuis la bdd sans mettre à jour le style directement après
|
|
||||||
await t.chargerDepuisBdd(false)
|
|
||||||
|
|
||||||
/* fonction qui va s'activer lorsqu'on achète l'objet*/
|
|
||||||
btn_acheter.addEventListener("click", (event) =>{
|
|
||||||
// on améliore le style de la page :)
|
|
||||||
t.appliquerAmeliorationStyle()
|
|
||||||
|
|
||||||
// et on ajouter l'amélioration dans l'abre des compétences débloquées
|
|
||||||
sacado[key] = true
|
|
||||||
|
|
||||||
// on refresh le magasin pour enlever l'amelioration de la liste
|
|
||||||
// vide le ventre du magasin
|
|
||||||
table.innerHTML = ""
|
|
||||||
magasin = {}
|
|
||||||
remplirMagasin()
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
btn_acheter.innerText = "Acheter"
|
|
||||||
|
|
||||||
// n'afficher l'amélioration que si le score est assez élevé
|
|
||||||
if(t.props.borne <= score){
|
|
||||||
|
|
||||||
// met à jour le contenu du magasin
|
|
||||||
// pour ne pas re-afficher cette ligne et éviter un clignotement
|
|
||||||
magasin[key] = true
|
|
||||||
|
|
||||||
test.appendChild(btn_acheter)
|
test.appendChild(btn_acheter)
|
||||||
|
|
||||||
|
@ -77,10 +39,12 @@ async function remplirMagasin(){
|
||||||
tr.appendChild(test)
|
tr.appendChild(test)
|
||||||
|
|
||||||
table.appendChild(tr)
|
table.appendChild(tr)
|
||||||
}
|
|
||||||
}
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,21 @@ class Technologie{
|
||||||
this.nom = nom
|
this.nom = nom
|
||||||
}
|
}
|
||||||
|
|
||||||
async chargerDepuisBdd(style) {
|
chargerDepuisBdd( style){
|
||||||
let data = await fetch("../bdd/arbre.json")
|
fetch("../bdd/arbre.json").then((data)=>{
|
||||||
data = await data.json()
|
data.json().then((data)=>{
|
||||||
console.log("clé dans technologie :", this.nom);
|
console.log("clé dans technologie :",this.nom)
|
||||||
this.props = data["technologies"][this.nom];
|
this.props = data["technologies"][this.nom]
|
||||||
this.cout = this.props.cout;
|
this.cout = this.props.cout
|
||||||
this.boost = this.props.boost;
|
this.boost = this.props.boost
|
||||||
if (style) {
|
if(style){
|
||||||
this.appliquerAmeliorationStyle();
|
this.appliquerAmeliorationStyle()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
appliquerAmeliorationStyle(){
|
appliquerAmeliorationStyle(){
|
||||||
|
|
Loading…
Reference in a new issue