From 0fb48772666c832b81c5b1de405b5242ebcdb13d Mon Sep 17 00:00:00 2001 From: legonzaur Date: Tue, 27 Aug 2024 11:51:31 +0200 Subject: [PATCH] Feat : add Leave, kick and game configuration --- app.vue | 11 ++ components/game/modal/ConfigureDialog.vue | 144 ++++++++++++++++++ .../game/{overlay => modal}/ResultDialog.vue | 2 +- .../options/Dialog.client.vue | 0 components/game/player/Slot.vue | 21 --- netcode/events.ts | 29 ++-- netcode/index.ts | 26 ++++ netcode/interfaces.ts | 1 + pages/game.vue | 35 +++-- pages/lobby.vue | 20 ++- 10 files changed, 243 insertions(+), 46 deletions(-) create mode 100644 components/game/modal/ConfigureDialog.vue rename components/game/{overlay => modal}/ResultDialog.vue (97%) rename components/game/{overlay => modal}/options/Dialog.client.vue (100%) diff --git a/app.vue b/app.vue index bf1563f..05db36e 100644 --- a/app.vue +++ b/app.vue @@ -67,6 +67,17 @@ button:disabled { cursor: not-allowed; } +button.yellow { + background-color: rgba(255, 165, 0, 0.7); +} + +button:hover:enabled { + background-color: #45a049; +} +button.yellow:hover { + background-color: rgba(255, 165, 0, 0.8); +} + #__nuxt { height: 100%; user-select: none; diff --git a/components/game/modal/ConfigureDialog.vue b/components/game/modal/ConfigureDialog.vue new file mode 100644 index 0000000..09f7c1d --- /dev/null +++ b/components/game/modal/ConfigureDialog.vue @@ -0,0 +1,144 @@ + + + + + diff --git a/components/game/overlay/ResultDialog.vue b/components/game/modal/ResultDialog.vue similarity index 97% rename from components/game/overlay/ResultDialog.vue rename to components/game/modal/ResultDialog.vue index 98c18ef..de73ea5 100644 --- a/components/game/overlay/ResultDialog.vue +++ b/components/game/modal/ResultDialog.vue @@ -27,7 +27,7 @@ const close = () => {

Défaite!

- +

Vous avez gagné!

Vous avez perdu face à ce magnifique individu qui a très clairement diff --git a/components/game/overlay/options/Dialog.client.vue b/components/game/modal/options/Dialog.client.vue similarity index 100% rename from components/game/overlay/options/Dialog.client.vue rename to components/game/modal/options/Dialog.client.vue diff --git a/components/game/player/Slot.vue b/components/game/player/Slot.vue index 9f179f4..d9843fc 100644 --- a/components/game/player/Slot.vue +++ b/components/game/player/Slot.vue @@ -433,27 +433,6 @@ function discardCardClick(card: Card) { transform: translate(-50%, -50%); } -.end_turn_button { - background-color: #4caf50; - /* Green background color */ - color: white; - border: none; - border-radius: 8px; - padding: 13px 10px; - margin: 0 0 0 5px; - font-size: 16px; - font-weight: bold; - text-transform: uppercase; - cursor: pointer; - transition: background-color 0.3s ease; - box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.4); -} - -.end_turn_button:hover { - background-color: #45a049; - /* Darker green on hover */ -} - .end_turn_button:active { transform: translateY(2px); /* Add a slight press effect on click */ diff --git a/netcode/events.ts b/netcode/events.ts index 2b4f75c..e599f6d 100644 --- a/netcode/events.ts +++ b/netcode/events.ts @@ -1,6 +1,5 @@ import { playSound } from "~/helpers/audioHelpers"; import type { Container, Game, Player } from "./interfaces"; -import type { Store } from "pinia"; export function delay(delay: number) { return new Promise((resolve) => { @@ -8,16 +7,6 @@ export function delay(delay: number) { }); } -// export type ContainerHandler = { -// populateContainer: () => void; -// shuffleContainer: () => void; -// getCardsPosition: (cards: string) => any; -// startAnimation: () => void; -// endAnimation: () => void; -// }; - -// export const containerEvents = reactive(new Map()); - type handlerInput = { game: Game; containers: Ref>; @@ -102,6 +91,21 @@ export const handlers: { playSound("/sounds/teleport.mp3"); game.teams.push(data.team); }, + leaveTeam: async (data: any, { game }) => { + const team = game.teams.find((t) => t._id == data.team._id); + if (team == undefined) { + throw new Error("Cannot find team"); + } + const playerIndex = team.players.findIndex((p) => p._id == data.playerId); + if (playerIndex == -1) { + throw new Error("Cannot find player in team"); + } + team.players.splice(playerIndex, 1); + if (team.players.length === 0) { + const index = game.teams.findIndex((t) => t._id == data.team._id); + game.teams.splice(index, 1); + } + }, lockEffect: async (data: any, { game, settingsStore }) => { game.currentTurn.lockedEffects.push(data.effect); await delay(settingsStore.animationSpeed); @@ -187,4 +191,7 @@ export const handlers: { endGame: async () => { alert("game ended"); }, + delete: async () => { + alert("game deleted"); + }, }; diff --git a/netcode/index.ts b/netcode/index.ts index d60a7e3..aeefc14 100644 --- a/netcode/index.ts +++ b/netcode/index.ts @@ -50,6 +50,10 @@ export async function startGame(game: string) { ); } +export async function deleteGame(game: string) { + const config = useRuntimeConfig(); +} + export async function joinGame(game: string) { const config = useRuntimeConfig(); const res = await $fetch( @@ -61,6 +65,28 @@ export async function joinGame(game: string) { ); } +export async function leaveGame(game: string) { + const config = useRuntimeConfig(); + const res = await $fetch( + config.public.endpoint + `/games/${game}/leave`, + { + method: "POST", + credentials: "include", + } + ); +} + +export async function kickPlayer(game: string, playerId: string) { + const config = useRuntimeConfig(); + const res = await $fetch( + config.public.endpoint + `/games/${game}/kick/${playerId}`, + { + method: "POST", + credentials: "include", + } + ); +} + export async function endTurn(game: string) { const config = useRuntimeConfig(); await $fetch(config.public.endpoint + `/games/${game}/endTurn`, { diff --git a/netcode/interfaces.ts b/netcode/interfaces.ts index 420975d..26c80aa 100644 --- a/netcode/interfaces.ts +++ b/netcode/interfaces.ts @@ -72,6 +72,7 @@ export interface Game extends GameObject { currentTurn: PlayingTurn; started: boolean; owner: User; + packs: string[]; } export interface Team extends GameObject { diff --git a/pages/game.vue b/pages/game.vue index 29194a7..1fd0aa4 100644 --- a/pages/game.vue +++ b/pages/game.vue @@ -1,6 +1,14 @@