creer dataobject kahoot.js et y mettre les stubs

front
Gwenael PLANCHON 1 year ago
parent 9e9b83cb90
commit 5ed13a011c

@ -1,5 +1,6 @@
<script> <script>
import { KAHOOT_NB_APRES_LA_VIRGULE_COMPTE_A_REBOURS} from "@/assets/const" import { KAHOOT_NB_APRES_LA_VIRGULE_COMPTE_A_REBOURS} from "@/assets/const"
import { Kahoot } from "@/data/kahoot"
export default { export default {
data() { data() {
@ -61,7 +62,7 @@ export default {
}, },
obtenirQuestion(){ obtenirQuestion(){
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
this.DEBUG_obtenirQuestion().then(response=>{ Kahoot.obtenirQuestion().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
//afficher cet etat //afficher cet etat
this.etats.question=true this.etats.question=true
@ -79,7 +80,7 @@ export default {
}, },
obtenirScores(){ obtenirScores(){
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
this.DEBUG_obtenirScore().then(response=>{ Kahoot.obtenirScore().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
//afficher cet etat //afficher cet etat
this.etats.score=true this.etats.score=true
@ -98,7 +99,7 @@ export default {
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
//afficher cet etat //afficher cet etat
this.etats.salleAttente=true this.etats.salleAttente=true
this.DEBUG_obtenirSalleAttente().then(response=>{ Kahoot.obtenirSalleAttente().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
this.salleAttente=response this.salleAttente=response
@ -128,36 +129,7 @@ export default {
resetEtats(){ resetEtats(){
Object.keys(this.etats).forEach(nomEtat=>this.etats[nomEtat]=0) Object.keys(this.etats).forEach(nomEtat=>this.etats[nomEtat]=0)
}, }
//simuler l'api avec des stubs
async DEBUG_obtenirQuestion(){
return JSON.parse(`
{
"question":"Qui a reçu le prix Nobel de chimie en 1911, pour avoir réussi à isoler un gramme de radium ?",
"reponses":["Marie Curie","Einstein","Sophie Germain","Ada Lovelace"],
"tempsLimite":${Date.now()+this.DEBUG_temps /* maintenant + 10 secondes pour repondre*/}
}
`)
},
async DEBUG_obtenirScore(){
return JSON.parse(`
{
"score":1337,
"pointsGagne":100,
"leaderboard":{"Moi":1337, "Titouan":320},
"tempsLimite":${Date.now()+this.DEBUG_temps /* maintenant + 10 secondes le temps de regarder les scores*/}
}
`)
},
async DEBUG_obtenirSalleAttente(){
return JSON.parse(`
{
"joueurs":["Moi","Titouan"],
"partieDemarree":true,
"tempsLimite":${Date.now()+this.DEBUG_temps /* maintenant + 1 seconde*/}
}
`)
},
} }
} }

@ -0,0 +1,59 @@
import { REST_API } from "@/assets/const"
import { DataObject, PagedDataObject } from "./dataObject"
export class Kahoot extends DataObject{
constructor(parsedJSON){
super(parsedJSON)
}
static async obtenirQuestion(){
return JSON.parse(`
{
"question":"Qui a reçu le prix Nobel de chimie en 1911, pour avoir réussi à isoler un gramme de radium ?",
"reponses":["Marie Curie","Einstein","Sophie Germain","Ada Lovelace"],
"tempsLimite":${Date.now()+10000 /* maintenant + 10 secondes pour repondre*/}
}
`)
}
static async obtenirScore(){
return JSON.parse(`
{
"score":1337,
"pointsGagne":100,
"leaderboard":{"Moi":1337, "Titouan":320},
"tempsLimite":${Date.now()+10000 /* maintenant + 10 secondes le temps de regarder les scores*/}
}
`)
}
static async obtenirSalleAttente(){
return JSON.parse(`
{
"joueurs":["Moi","Titouan"],
"partieDemarree":true,
"tempsLimite":${Date.now()+10000 /* maintenant + 1 seconde*/}
}
`)
}
}
/* JSON de reference (question)
{
"question":"Qui a reçu le prix Nobel de chimie en 1911, pour avoir réussi à isoler un gramme de radium ?",
"reponses":["Marie Curie","Einstein","Sophie Germain","Ada Lovelace"],
"tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes pour repondre}
}
*/
/* JSON de reference (score)
{
"score":1337,
"pointsGagne":100,
"leaderboard":{"Moi":1337, "Titouan":320},
"tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes le temps de regarder les scores}
}
*/
/* JSON de reference (salleAttente)
{
"joueurs":["Moi","Titouan"],
"partieDemarree":true,
"tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 1 seconde}
}
*/
Loading…
Cancel
Save