debut d'adaptation de l'api vers le kahoot

front
Gwenael PLANCHON 1 year ago
parent 9a7040d88c
commit 62f68905ba

@ -6,6 +6,7 @@ export default {
data() {
return {
codePartie: this.$route.params.code ?? -1,
kahootAPI:null,
//unix timestamp pour indiquer la date limite pour repondre a la question, -1 indiquera la fin de la partie
tempsLimite:0,
compteARebours:0,
@ -39,6 +40,8 @@ export default {
}
},
mounted(){
//TODO : s'ajouter a la partie
this.kahootAPI=new Kahoot(this.codePartie)
this.obtenirSalleAttente()
},
unmounted(){
@ -102,7 +105,7 @@ export default {
this.resetEtats() //cacher l'etat precedent
//afficher cet etat
this.etats.salleAttente=true
Kahoot.obtenirSalleAttente().then(response=>{
this.kahootAPI.obtenirSalleAttente().then(response=>{
this.tempsLimite=response.tempsLimite
this.salleAttente=response

@ -1,38 +1,31 @@
import { REST_API } from "@/assets/const"
import { DataObject, PagedDataObject } from "./dataObject"
export class Kahoot extends DataObject{
constructor(parsedJSON){
export class Kahoot{
constructor(codeInvitation){
this.codeInvitation=codeInvitation
}
async obtenirSalleAttente(){
const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/status`)
return new KahootSalleAttente(await response.json())
}
}
/* JSON de reference (salleAttente)
{
"joueurs":["Moi","Titouan"],
"partieDemarree":true,
"tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 1 seconde}
}
*/
export class KahootSalleAttente extends DataObject{
constructor(parsedJSON){
super(parsedJSON)
this.partieDemarree=this.status!="Pending"
this.joueurs=this.scores.map(score=>score.joueur.pseudo)
this.tempsLimite=Date.now()+1000
}
static async obtenirQuestion(){
return new this(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 new this(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 new this(JSON.parse(`
{
"joueurs":["Moi","Titouan"],
"partieDemarree":true,
"tempsLimite":${Date.now()+10000 /* maintenant + 1 seconde*/}
}
`))
}
}
/* JSON de reference (question)
@ -49,11 +42,4 @@ export class Kahoot extends DataObject{
"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