diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 46f829e..f2c7126 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -1,3 +1,19 @@ + + @@ -29,11 +28,6 @@ {/if} - {#if link.text === "Spectate"} -
  • - -
  • - {/if} {#if link.text === "Channels"}
  • diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte index 75470df..74c81a9 100644 --- a/front/volume/src/components/Pong/Pong.svelte +++ b/front/volume/src/components/Pong/Pong.svelte @@ -10,22 +10,22 @@ import type { MatchmakingDto } from "./dtos/MatchmakingDto"; import { getUser, store } from "../../Auth"; import ColorPicker from "./ColorPicker.svelte"; + import { APPSTATE } from "../../App.svelte"; export function inviteToGame(event: CustomEvent) { - createMatchWindow = true; + setAppState(APPSTATE.CREATE_GAME); invitedUsername = event.detail; } export let fakeUser: boolean; + export let appState: string; + export let setAppState: (newState: APPSTATE | string) => void; const SERVER_URL = `ws://${import.meta.env.VITE_HOST}:${ import.meta.env.VITE_BACK_PORT }`; - let createMatchWindow: boolean = false; - let spectateWindow: boolean = false; let gamePlaying: boolean = false; - let matchmaking: boolean = false; let connected: boolean = false; let loggedIn: boolean = false; let failedLogIn: boolean = false; @@ -87,7 +87,11 @@ } else if (event == GAME_EVENTS.CREATE_GAME) { if (data) gamePlaying = true; } else if (event == GAME_EVENTS.MATCHMAKING) { - matchmaking = data.matchmaking; + if (data.matchmaking && appState !== APPSTATE.MATCHMAKING) { + setAppState(APPSTATE.MATCHMAKING); + } else if (!data.matchmaking && appState === APPSTATE.MATCHMAKING) { + setAppState(APPSTATE.HOME); + } } else if (event == GAME_EVENTS.SPECTATE) { if (data) { gamePlaying = true; @@ -141,9 +145,7 @@ } function resetMenus() { - createMatchWindow = false; - spectateWindow = false; - matchmaking = false; + setAppState(APPSTATE.HOME); game.youAreReady = false; } @@ -152,6 +154,16 @@ game.updateColors(elementsColor, backgroundColor); } } + + $: { + if (socket && socket.readyState) { + if (appState === APPSTATE.MATCHMAKING) { + startMatchmaking(); + } else if (appState !== APPSTATE.MATCHMAKING) { + stopMatchmaking(); + } + } + }
    @@ -161,30 +173,32 @@ {:else if loggedIn}

    Choose a gamemode

    - - + - {#if matchmaking} + {#if appState === APPSTATE.MATCHMAKING}
    - {:else if createMatchWindow} + {:else if appState === APPSTATE.CREATE_GAME}
    (createMatchWindow = false)} - on:keydown={() => (createMatchWindow = false)} + on:click={() => setAppState(APPSTATE.HOME)} + on:keydown={() => setAppState(APPSTATE.HOME)} >
    - {:else if spectateWindow} + {:else if appState === APPSTATE.SPECTATE_GAME}
    (spectateWindow = false)} - on:keydown={() => (spectateWindow = false)} + on:click={() => setAppState(APPSTATE.HOME)} + on:keydown={() => setAppState(APPSTATE.HOME)} >
    diff --git a/front/volume/src/components/Spectate.svelte b/front/volume/src/components/Spectate.svelte deleted file mode 100644 index f0d1806..0000000 --- a/front/volume/src/components/Spectate.svelte +++ /dev/null @@ -1,55 +0,0 @@ - - - - -
    -
    -
    - {#if spectate.length > 0} -

    Monkey spectating

    - {#each spectate.slice(0, 10) as _spectate} -
  • - {_spectate.player1} VS {_spectate.player2} - -
  • - {/each} - {:else} -

    No matches to spectate

    - {/if} -
    -
    -
    - -