From e62f8160a4beed6035418bb891f8a39c4323ff52 Mon Sep 17 00:00:00 2001 From: vvandenb Date: Sat, 11 Mar 2023 10:51:01 +0100 Subject: [PATCH] * Chat: invite user to game --- front/volume/src/App.svelte | 14 ++++++++------ front/volume/src/components/Chat2.svelte | 4 ++-- .../volume/src/components/Pong/GameCreation.svelte | 8 ++++---- front/volume/src/components/Pong/Pong.svelte | 13 ++++++++++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index f52486c..26f3ce8 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -18,7 +18,6 @@ import FakeLogin from "./FakeLogin.svelte"; // PROFILE - onMount(() => { getUser(); }); @@ -33,7 +32,7 @@ let userProfile; let isIdProfileOpen = false; - async function openIdProfile(event) { + async function openIdProfile(event: CustomEvent) { console.log("Opening profile: " + event.detail); isIdProfileOpen = true; const res = await fetch(API_URL + "/user/" + event.detail, { @@ -47,7 +46,6 @@ } // HISTORY - let matches: Array; let isHistoryOpen = false; function clickHistory() { @@ -55,7 +53,7 @@ getHistory(); } - export async function getHistory(): Promise { + export async function getHistory(): Promise { let response = await fetch(API_URL + "/history/" + $store.ftId, { credentials: "include", mode: "cors", @@ -64,7 +62,6 @@ } // FRIENDS - let friends: Friend[] = []; let invits: Friend[] = []; let friendsInterval: ReturnType; @@ -146,6 +143,10 @@ leaderboard = await getLeader(); } + // GAME + let pong: Pong; + + // FAKE LOGIN let usernameFake = "test"; let ftIdFake = "42"; let fakemenu = true; @@ -184,6 +185,7 @@ chatMessages={selectedChannel.messages} on:view-profile={openIdProfile} on:add-friend={addFriend} + on:invite-to-game={pong.inviteToGame} /> {/if} @@ -256,7 +258,7 @@ {:else} - + {/if} {/if} diff --git a/front/volume/src/components/Chat2.svelte b/front/volume/src/components/Chat2.svelte index 7d77810..3bb305f 100644 --- a/front/volume/src/components/Chat2.svelte +++ b/front/volume/src/components/Chat2.svelte @@ -50,8 +50,8 @@

openProfile(message.author)} + on:keydown={() => openProfile(message.author)} style="cursor: pointer;" > {message.author} diff --git a/front/volume/src/components/Pong/GameCreation.svelte b/front/volume/src/components/Pong/GameCreation.svelte index 4f970d6..8c598d0 100644 --- a/front/volume/src/components/Pong/GameCreation.svelte +++ b/front/volume/src/components/Pong/GameCreation.svelte @@ -7,13 +7,13 @@ import { store } from "../../Auth"; export let socket: WebSocket; + export let invitedUsername: string; let map: Map = new Map(DEFAULT_MAP_SIZE.clone(), []); - let otherUsername: string = "Garfield"; function createGame() { const data: GameCreationDto = { - playerNames: [$store.username, otherUsername], + playerNames: [$store.username, invitedUsername], map, }; socket.send(formatWebsocketData(GAME_EVENTS.CREATE_GAME, data)); @@ -23,9 +23,9 @@

Friend: - +
diff --git a/front/volume/src/components/Pong/Pong.svelte b/front/volume/src/components/Pong/Pong.svelte index fdc744c..51131d6 100644 --- a/front/volume/src/components/Pong/Pong.svelte +++ b/front/volume/src/components/Pong/Pong.svelte @@ -11,7 +11,12 @@ import { getUser, store } from "../../Auth"; import ColorPicker from "./ColorPicker.svelte"; - export let fakeUser; + export function inviteToGame(event: CustomEvent) { + createMatchWindow = true; + invitedUsername = event.detail; + } + + export let fakeUser: boolean; const SERVER_URL = `ws://${import.meta.env.VITE_HOST}:${ import.meta.env.VITE_BACK_PORT @@ -31,6 +36,7 @@ let renderCanvas: HTMLCanvasElement; let canvas: HTMLCanvasElement; let context: CanvasRenderingContext2D; + let invitedUsername: string = ""; function setupSocket( _renderCanvas: HTMLCanvasElement, @@ -102,7 +108,8 @@ } async function onSocketOpen() { - await getUser(); + if (!fakeUser) + await getUser(); void logIn(); connected = true; } @@ -173,7 +180,7 @@ on:click={() => (createMatchWindow = false)} on:keydown={() => (createMatchWindow = false)} > - +
{:else if spectateWindow}