Template
chore: formatting
This commit is contained in:
@@ -1,15 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useUserStore } from "~/store/user.store";
|
import { useUserStore } from "~/store/user.store";
|
||||||
import { useLobbyStore } from "./store/lobby.store";
|
import { useLobbyStore } from "./store/lobby.store";
|
||||||
import { useConceptStore } from "./store/concepts.store";
|
|
||||||
import PageHeader from "./components/pageHeader.vue";
|
import PageHeader from "./components/pageHeader.vue";
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const lobbyStore = useLobbyStore();
|
const lobbyStore = useLobbyStore();
|
||||||
const conceptStore = useConceptStore()
|
|
||||||
|
|
||||||
void userStore.whoami();
|
void userStore.whoami();
|
||||||
void conceptStore.fetchConceptTypes();
|
|
||||||
void conceptStore.fetchConceptList()
|
|
||||||
void lobbyStore.fetchGames();
|
void lobbyStore.fetchGames();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
Submodule netcode/events updated: 24c39d23d6...913c82994a
@@ -25,18 +25,18 @@ export const handlers = {
|
|||||||
void gameStore.getCurrentWord(gameStore.game.id);
|
void gameStore.getCurrentWord(gameStore.game.id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
delete: (event: GameDeleteEvent) => {
|
delete: async (event: GameDeleteEvent) => {
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
gameStore.game = {} as GameResponseDTO;
|
gameStore.game = {} as GameResponseDTO;
|
||||||
alert("Game deleted");
|
alert("Game deleted");
|
||||||
navigateTo("/");
|
await navigateTo("/");
|
||||||
},
|
},
|
||||||
message: (event: GameMessageEvent) => {
|
message: (event: GameMessageEvent) => {
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
gameStore.game.messages.push(event.message);
|
gameStore.game.messages.push(event.message);
|
||||||
if (!event.message.authorId) {
|
if (!event.message.authorId) {
|
||||||
const player = gameStore.game.players.find(
|
const player = gameStore.game.players.find(
|
||||||
(p) => p.userId == event.message.value
|
(p) => p.userId == event.message.value,
|
||||||
);
|
);
|
||||||
if (player) {
|
if (player) {
|
||||||
player.score++;
|
player.score++;
|
||||||
@@ -46,7 +46,7 @@ export const handlers = {
|
|||||||
deleteMessage: (event: GameMessageDeleteEvent) => {
|
deleteMessage: (event: GameMessageDeleteEvent) => {
|
||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
const index = gameStore.game.messages.findIndex(
|
const index = gameStore.game.messages.findIndex(
|
||||||
(m) => m.id == event.messageId
|
(m) => m.id == event.messageId,
|
||||||
);
|
);
|
||||||
gameStore.game.messages.splice(index, 1);
|
gameStore.game.messages.splice(index, 1);
|
||||||
},
|
},
|
||||||
@@ -54,7 +54,6 @@ export const handlers = {
|
|||||||
const gameStore = useGameStore();
|
const gameStore = useGameStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
gameStore.game.players.forEach((p) => (p.hasGuessed = false));
|
gameStore.game.players.forEach((p) => (p.hasGuessed = false));
|
||||||
gameStore.game.currentConcepts = [];
|
|
||||||
gameStore.game.messages = [];
|
gameStore.game.messages = [];
|
||||||
gameStore.game.currentPlayer = event.currentPlayer;
|
gameStore.game.currentPlayer = event.currentPlayer;
|
||||||
if (userStore.self && userStore.self.id == event.currentPlayer.userId) {
|
if (userStore.self && userStore.self.id == event.currentPlayer.userId) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const handlers = {
|
|||||||
leavegame: (event: LobbyLeaveEvent) => {
|
leavegame: (event: LobbyLeaveEvent) => {
|
||||||
const lobbyStore = useLobbyStore();
|
const lobbyStore = useLobbyStore();
|
||||||
const playerIndex = lobbyStore.games[event.game.id].players.findIndex(
|
const playerIndex = lobbyStore.games[event.game.id].players.findIndex(
|
||||||
(p) => p.userId == event.player.userId
|
(p) => p.userId == event.player.userId,
|
||||||
);
|
);
|
||||||
lobbyStore.games[event.game.id].players.splice(playerIndex, 1);
|
lobbyStore.games[event.game.id].players.splice(playerIndex, 1);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,27 +7,25 @@ import {
|
|||||||
WordEnableEvent,
|
WordEnableEvent,
|
||||||
} from "../events/word.events";
|
} from "../events/word.events";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const handlers = {
|
export const handlers = {
|
||||||
create: (event: WordCreateEvent) => {
|
create: (event: WordCreateEvent) => {
|
||||||
const wordStore = useWordStore();
|
const wordStore = useWordStore();
|
||||||
wordStore.words[event.word.id] = event.word
|
wordStore.words[event.word.id] = event.word;
|
||||||
},
|
},
|
||||||
edit: (event: WordEditEvent) => {
|
edit: (event: WordEditEvent) => {
|
||||||
const wordStore = useWordStore();
|
const wordStore = useWordStore();
|
||||||
wordStore.words[event.word.id].value = event.word.value
|
wordStore.words[event.word.id].value = event.word.value;
|
||||||
},
|
},
|
||||||
delete: (event: WordDeleteEvent) => {
|
delete: (event: WordDeleteEvent) => {
|
||||||
const wordStore = useWordStore();
|
const wordStore = useWordStore();
|
||||||
delete wordStore.words[event.id]
|
delete wordStore.words[event.id];
|
||||||
},
|
},
|
||||||
enable: (event: WordEnableEvent) => {
|
enable: (event: WordEnableEvent) => {
|
||||||
const wordStore = useWordStore();
|
const wordStore = useWordStore();
|
||||||
wordStore.words[event.id].enabled = true
|
wordStore.words[event.id].enabled = true;
|
||||||
},
|
},
|
||||||
disable: (event: WordDisableEvent) => {
|
disable: (event: WordDisableEvent) => {
|
||||||
const wordStore = useWordStore();
|
const wordStore = useWordStore();
|
||||||
wordStore.words[event.id].enabled = false
|
wordStore.words[event.id].enabled = false;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+12
-11
@@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { subscribe } from "~/netcode";
|
import { subscribe } from "~/netcode";
|
||||||
import { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
import { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
||||||
|
import type { ConceptEvent } from "~/netcode/events/events";
|
||||||
import { handlers } from "~/netcode/handlers/game.handler";
|
import { handlers } from "~/netcode/handlers/game.handler";
|
||||||
|
|
||||||
export const useGameStore = defineStore("game", {
|
export const useGameStore = defineStore("game", {
|
||||||
@@ -10,18 +11,18 @@ export const useGameStore = defineStore("game", {
|
|||||||
eventSource: null as null | EventSource,
|
eventSource: null as null | EventSource,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async subscribe(id: number) {
|
subscribe(id: number) {
|
||||||
this.eventSource = subscribe(`/games/${id}/subscribe`);
|
this.eventSource = subscribe(`/games/${id}/subscribe`);
|
||||||
this.eventSource.addEventListener("message", async (message) => {
|
this.eventSource.addEventListener("message", (message) => {
|
||||||
const data = JSON.parse(message.data);
|
const data = JSON.parse(message.data as string) as ConceptEvent;
|
||||||
const type = data.type as string;
|
const type = data.type;
|
||||||
console.log(type);
|
console.log(type);
|
||||||
if (type in handlers) {
|
if (type in handlers) {
|
||||||
handlers[type as keyof typeof handlers](data);
|
handlers[type as keyof typeof handlers](data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async close() {
|
close() {
|
||||||
this.eventSource?.close();
|
this.eventSource?.close();
|
||||||
},
|
},
|
||||||
async fetchGame(id: number) {
|
async fetchGame(id: number) {
|
||||||
@@ -31,7 +32,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
immediate: true,
|
immediate: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (data.data.value) {
|
if (data.data.value) {
|
||||||
this.game = data.data.value;
|
this.game = data.data.value;
|
||||||
@@ -45,7 +46,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
async startGame(id: number) {
|
async startGame(id: number) {
|
||||||
@@ -55,7 +56,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
async deleteGame(id: number) {
|
async deleteGame(id: number) {
|
||||||
@@ -65,7 +66,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
async getCurrentWord(id: number) {
|
async getCurrentWord(id: number) {
|
||||||
@@ -74,7 +75,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
config.public.endpoint + `/games/` + id + "/currentWord",
|
config.public.endpoint + `/games/` + id + "/currentWord",
|
||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (data) {
|
if (data) {
|
||||||
this.currentWord = data;
|
this.currentWord = data;
|
||||||
@@ -92,7 +93,7 @@ export const useGameStore = defineStore("game", {
|
|||||||
value: message,
|
value: message,
|
||||||
},
|
},
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { subscribe } from "~/netcode";
|
import { subscribe } from "~/netcode";
|
||||||
import type { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
import type { GameResponseDTO } from "~/netcode/events/dto/gameresponse.dto";
|
||||||
|
import type { ConceptEvent } from "~/netcode/events/events";
|
||||||
import { handlers } from "~/netcode/handlers/lobby.handler";
|
import { handlers } from "~/netcode/handlers/lobby.handler";
|
||||||
|
|
||||||
export const useLobbyStore = defineStore("lobby", {
|
export const useLobbyStore = defineStore("lobby", {
|
||||||
@@ -9,17 +10,17 @@ export const useLobbyStore = defineStore("lobby", {
|
|||||||
eventSource: null as null | EventSource,
|
eventSource: null as null | EventSource,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async subscribe() {
|
subscribe() {
|
||||||
this.eventSource = subscribe(`/games/subscribe`);
|
this.eventSource = subscribe(`/games/subscribe`);
|
||||||
this.eventSource.addEventListener("message", async (message) => {
|
this.eventSource.addEventListener("message", (message) => {
|
||||||
const data = JSON.parse(message.data);
|
const data = JSON.parse(message.data as string) as ConceptEvent;
|
||||||
const type = data.type as string;
|
const type = data.type;
|
||||||
if (type in handlers) {
|
if (type in handlers) {
|
||||||
handlers[type as keyof typeof handlers](data);
|
handlers[type as keyof typeof handlers](data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async close() {
|
close() {
|
||||||
this.eventSource?.close();
|
this.eventSource?.close();
|
||||||
},
|
},
|
||||||
async fetchGames() {
|
async fetchGames() {
|
||||||
@@ -29,7 +30,7 @@ export const useLobbyStore = defineStore("lobby", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
immediate: true,
|
immediate: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (data.data.value) {
|
if (data.data.value) {
|
||||||
for (const game of data.data.value) {
|
for (const game of data.data.value) {
|
||||||
@@ -46,7 +47,7 @@ export const useLobbyStore = defineStore("lobby", {
|
|||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
// this.games[data.id] = data;
|
// this.games[data.id] = data;
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
+5
-4
@@ -1,5 +1,6 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto";
|
import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto";
|
||||||
|
import { type FetchContext } from "ofetch";
|
||||||
|
|
||||||
export const useUserStore = defineStore("user", {
|
export const useUserStore = defineStore("user", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -18,7 +19,7 @@ export const useUserStore = defineStore("user", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
immediate: true,
|
immediate: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (data.data.value) {
|
if (data.data.value) {
|
||||||
this.users[data.data.value.id] = data.data.value;
|
this.users[data.data.value.id] = data.data.value;
|
||||||
@@ -33,15 +34,15 @@ export const useUserStore = defineStore("user", {
|
|||||||
credentials: "include",
|
credentials: "include",
|
||||||
server: false,
|
server: false,
|
||||||
immediate: true,
|
immediate: true,
|
||||||
onResponse: (data) => {
|
onResponse: (data: FetchContext<UserResponseDTO>) => {
|
||||||
if (data.response.ok) {
|
if (data.response && data.response.ok && data.response._data) {
|
||||||
this.self = data.response._data;
|
this.self = data.response._data;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.has_contacted = true;
|
this.has_contacted = true;
|
||||||
},
|
},
|
||||||
lazy: true,
|
lazy: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
return req;
|
return req;
|
||||||
},
|
},
|
||||||
|
|||||||
+11
-10
@@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { subscribe } from "~/netcode";
|
import { subscribe } from "~/netcode";
|
||||||
import { WordResponseDTO } from "~/netcode/events/dto/wordresponse.dto";
|
import { WordResponseDTO } from "~/netcode/events/dto/wordresponse.dto";
|
||||||
|
import type { ConceptEvent } from "~/netcode/events/events";
|
||||||
import { handlers } from "~/netcode/handlers/word.handler";
|
import { handlers } from "~/netcode/handlers/word.handler";
|
||||||
|
|
||||||
export const useWordStore = defineStore("word", {
|
export const useWordStore = defineStore("word", {
|
||||||
@@ -9,17 +10,17 @@ export const useWordStore = defineStore("word", {
|
|||||||
eventSource: null as null | EventSource,
|
eventSource: null as null | EventSource,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async subscribe() {
|
subscribe() {
|
||||||
this.eventSource = subscribe(`/words/subscribe`);
|
this.eventSource = subscribe(`/words/subscribe`);
|
||||||
this.eventSource.addEventListener("message", async (message) => {
|
this.eventSource.addEventListener("message", (message) => {
|
||||||
const data = JSON.parse(message.data);
|
const data = JSON.parse(message.data as string) as ConceptEvent;
|
||||||
const type = data.type as string;
|
const type = data.type;
|
||||||
if (type in handlers) {
|
if (type in handlers) {
|
||||||
handlers[type as keyof typeof handlers](data);
|
handlers[type as keyof typeof handlers](data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async close() {
|
close() {
|
||||||
this.eventSource?.close();
|
this.eventSource?.close();
|
||||||
},
|
},
|
||||||
async fetchWordList() {
|
async fetchWordList() {
|
||||||
@@ -28,7 +29,7 @@ export const useWordStore = defineStore("word", {
|
|||||||
config.public.endpoint + `/words/all`,
|
config.public.endpoint + `/words/all`,
|
||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (data.data.value && !data.error.value) {
|
if (data.data.value && !data.error.value) {
|
||||||
for (const word of data.data.value) {
|
for (const word of data.data.value) {
|
||||||
@@ -44,7 +45,7 @@ export const useWordStore = defineStore("word", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
// word.enabled = true;
|
// word.enabled = true;
|
||||||
// return data;
|
// return data;
|
||||||
@@ -56,7 +57,7 @@ export const useWordStore = defineStore("word", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
// word.enabled = false;
|
// word.enabled = false;
|
||||||
// return data;
|
// return data;
|
||||||
@@ -70,7 +71,7 @@ export const useWordStore = defineStore("word", {
|
|||||||
credentials: "include",
|
credentials: "include",
|
||||||
body: { value },
|
body: { value },
|
||||||
method: "POST",
|
method: "POST",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
// this.words[data.id] = data;
|
// this.words[data.id] = data;
|
||||||
// return data;
|
// return data;
|
||||||
@@ -82,7 +83,7 @@ export const useWordStore = defineStore("word", {
|
|||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
// delete this.words[word.id];
|
// delete this.words[word.id];
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user