feat : guess word

This commit is contained in:
2024-12-30 20:15:02 +01:00
parent 08daf733d1
commit 9eaf7009c6
12 changed files with 304 additions and 54 deletions
+50 -2
View File
@@ -5,7 +5,8 @@ import { handlers } from "~/netcode/handlers/game.handler";
export const useGameStore = defineStore("game", {
state: () => ({
game: null as null | GameResponseDTO,
game: {} as GameResponseDTO,
currentWord: null as null | string,
eventSource: null as null | EventSource,
}),
actions: {
@@ -14,6 +15,7 @@ export const useGameStore = defineStore("game", {
this.eventSource.addEventListener("message", async (message) => {
const data = JSON.parse(message.data);
const type = data.type as string;
console.log(type);
if (type in handlers) {
handlers[type as keyof typeof handlers](data);
}
@@ -34,8 +36,54 @@ export const useGameStore = defineStore("game", {
if (data.data.value) {
this.game = data.data.value;
}
return data.data;
},
async joinGame(id: number) {
const config = useRuntimeConfig();
const data = await $fetch<GameResponseDTO>(
config.public.endpoint + `/games/` + id + "/join",
{
method: "POST",
credentials: "include",
}
);
},
async startGame(id: number) {
const config = useRuntimeConfig();
const data = await $fetch<GameResponseDTO>(
config.public.endpoint + `/games/` + id + "/start",
{
method: "POST",
credentials: "include",
}
);
},
async getCurrentWord(id: number) {
const config = useRuntimeConfig();
const data = await $fetch<string>(
config.public.endpoint + `/games/` + id + "/currentWord",
{
credentials: "include",
}
);
if (data) {
this.currentWord = data;
}
return data;
},
async sendMessage(id: number, message: string) {
const config = useRuntimeConfig();
const data = await $fetch<string>(
config.public.endpoint + `/games/` + id + "/message",
{
method: "POST",
body: {
value: message,
},
credentials: "include",
}
);
},
},
});