Fixed game sending player stats when not logged in

This commit is contained in:
dhain 2023-01-31 08:31:40 +01:00
parent 3befee6fdd
commit c2bb6c104a
3 changed files with 142 additions and 126 deletions

View file

@ -153,6 +153,9 @@ function collisionCheck(o) {
}
function die(){
if(localStorage.getItem("frontend-ready") == "false")
return;
ready = false;
hasDied = true;
playTime = Date.now() - startTime;
@ -205,14 +208,15 @@ function checkRaspberryScore() {
}
function resetScore(){
if (hasDied) {
if(!hasDied || localStorage.getItem("frontend-ready") == "false")
return;
hasDied = false;
score = 0;
hasAlreadyScored = false;
startTime = Date.now();
exportToLocalStorage();
}
}
function keyPressed(){
if(!ready)

View file

@ -13,7 +13,7 @@
<Login v-if="!user" @userChange="(event) => {this.updateUser(event);}">
</Login>
<div v-if="user" class="logout-wrapper offset-10 col-2">
<RRButton @click="this.user = null; this.userId = -1;" text="Logout"></RRButton>
<RRButton @click="logOut()" text="Logout"></RRButton>
</div>
</div>
<div class="row">
@ -59,7 +59,9 @@ export default defineComponent({
leaderboardEvent: new Event('reloadLeaderboard')
}
},
created() {
localStorage.setItem("frontend-ready", "false");
},
methods: {
async fetchFromApi(path: string, method: "GET" | "POST") {
@ -80,6 +82,11 @@ export default defineComponent({
await this.updateUserScores();
}
window.dispatchEvent(this.leaderboardEvent);
},
logOut(){
this.user = null;
this.userId = -1;
localStorage.setItem('frontend-ready', 'false');
}
},
});
@ -99,9 +106,11 @@ export default defineComponent({
.everything {
margin-bottom: 4em;
}
.hidden {
visibility: hidden;
}
.logout-wrapper {
display: flex;
justify-content: right;

View file

@ -19,7 +19,7 @@ export default {
data(){
return {
username: '',
user: null,
_user: null,
}
},
emits: ['userChange'],
@ -33,14 +33,17 @@ export default {
if(user.errors){
console.error("Something when wrong when logging in, please contact admin!")
return;
}
if(user){
this.user = user;
this.$emit('userChange', this.user);
this.user(user);
}
},
user(user){
this._user = user;
localStorage.setItem("frontend-ready", "true");
this.$emit('userChange', this._user);
}
}
}
</script>