Template
chore: formatting
This commit is contained in:
+12
-11
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { subscribe } from "~/netcode";
|
||||
import { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
||||
import type { ConceptEvent } from "~/netcode/events/events";
|
||||
import { handlers } from "~/netcode/handlers/game.handler";
|
||||
|
||||
export const useGameStore = defineStore("game", {
|
||||
@@ -10,18 +11,18 @@ export const useGameStore = defineStore("game", {
|
||||
eventSource: null as null | EventSource,
|
||||
}),
|
||||
actions: {
|
||||
async subscribe(id: number) {
|
||||
subscribe(id: number) {
|
||||
this.eventSource = subscribe(`/games/${id}/subscribe`);
|
||||
this.eventSource.addEventListener("message", async (message) => {
|
||||
const data = JSON.parse(message.data);
|
||||
const type = data.type as string;
|
||||
this.eventSource.addEventListener("message", (message) => {
|
||||
const data = JSON.parse(message.data as string) as ConceptEvent;
|
||||
const type = data.type;
|
||||
console.log(type);
|
||||
if (type in handlers) {
|
||||
handlers[type as keyof typeof handlers](data);
|
||||
}
|
||||
});
|
||||
},
|
||||
async close() {
|
||||
close() {
|
||||
this.eventSource?.close();
|
||||
},
|
||||
async fetchGame(id: number) {
|
||||
@@ -31,7 +32,7 @@ export const useGameStore = defineStore("game", {
|
||||
{
|
||||
credentials: "include",
|
||||
immediate: true,
|
||||
}
|
||||
},
|
||||
);
|
||||
if (data.data.value) {
|
||||
this.game = data.data.value;
|
||||
@@ -45,7 +46,7 @@ export const useGameStore = defineStore("game", {
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
async startGame(id: number) {
|
||||
@@ -55,7 +56,7 @@ export const useGameStore = defineStore("game", {
|
||||
{
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
async deleteGame(id: number) {
|
||||
@@ -65,7 +66,7 @@ export const useGameStore = defineStore("game", {
|
||||
{
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
async getCurrentWord(id: number) {
|
||||
@@ -74,7 +75,7 @@ export const useGameStore = defineStore("game", {
|
||||
config.public.endpoint + `/games/` + id + "/currentWord",
|
||||
{
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
if (data) {
|
||||
this.currentWord = data;
|
||||
@@ -92,7 +93,7 @@ export const useGameStore = defineStore("game", {
|
||||
value: message,
|
||||
},
|
||||
credentials: "include",
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user