Browse Source

* Chat: invite user to game

master
vvandenb 2 years ago
parent
commit
e62f8160a4
  1. 14
      front/volume/src/App.svelte
  2. 4
      front/volume/src/components/Chat2.svelte
  3. 8
      front/volume/src/components/Pong/GameCreation.svelte
  4. 13
      front/volume/src/components/Pong/Pong.svelte

14
front/volume/src/App.svelte

@ -18,7 +18,6 @@
import FakeLogin from "./FakeLogin.svelte"; import FakeLogin from "./FakeLogin.svelte";
// PROFILE // PROFILE
onMount(() => { onMount(() => {
getUser(); getUser();
}); });
@ -33,7 +32,7 @@
let userProfile; let userProfile;
let isIdProfileOpen = false; let isIdProfileOpen = false;
async function openIdProfile(event) { async function openIdProfile(event: CustomEvent<string>) {
console.log("Opening profile: " + event.detail); console.log("Opening profile: " + event.detail);
isIdProfileOpen = true; isIdProfileOpen = true;
const res = await fetch(API_URL + "/user/" + event.detail, { const res = await fetch(API_URL + "/user/" + event.detail, {
@ -47,7 +46,6 @@
} }
// HISTORY // HISTORY
let matches: Array<Match>; let matches: Array<Match>;
let isHistoryOpen = false; let isHistoryOpen = false;
function clickHistory() { function clickHistory() {
@ -55,7 +53,7 @@
getHistory(); getHistory();
} }
export async function getHistory(): Promise<Match[]> { export async function getHistory(): Promise<void> {
let response = await fetch(API_URL + "/history/" + $store.ftId, { let response = await fetch(API_URL + "/history/" + $store.ftId, {
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
@ -64,7 +62,6 @@
} }
// FRIENDS // FRIENDS
let friends: Friend[] = []; let friends: Friend[] = [];
let invits: Friend[] = []; let invits: Friend[] = [];
let friendsInterval: ReturnType<typeof setInterval>; let friendsInterval: ReturnType<typeof setInterval>;
@ -146,6 +143,10 @@
leaderboard = await getLeader(); leaderboard = await getLeader();
} }
// GAME
let pong: Pong;
// FAKE LOGIN
let usernameFake = "test"; let usernameFake = "test";
let ftIdFake = "42"; let ftIdFake = "42";
let fakemenu = true; let fakemenu = true;
@ -184,6 +185,7 @@
chatMessages={selectedChannel.messages} chatMessages={selectedChannel.messages}
on:view-profile={openIdProfile} on:view-profile={openIdProfile}
on:add-friend={addFriend} on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame}
/> />
</div> </div>
{/if} {/if}
@ -256,7 +258,7 @@
<button on:click={impersonate}>Impersonate</button> <button on:click={impersonate}>Impersonate</button>
<button on:click={() => fakemenu = false}>No impersonate</button> <button on:click={() => fakemenu = false}>No impersonate</button>
{:else} {:else}
<Pong {fakeUser} /> <Pong bind:this={pong} {fakeUser} />
{/if} {/if}
{/if} {/if}
</div> </div>

4
front/volume/src/components/Chat2.svelte

@ -50,8 +50,8 @@
<p class="message"> <p class="message">
<span <span
class="message-name" class="message-name"
on:click={openProfile(message.author)} on:click={() => openProfile(message.author)}
on:keydown={openProfile(message.author)} on:keydown={() => openProfile(message.author)}
style="cursor: pointer;" style="cursor: pointer;"
> >
{message.author} {message.author}

8
front/volume/src/components/Pong/GameCreation.svelte

@ -7,13 +7,13 @@
import { store } from "../../Auth"; import { store } from "../../Auth";
export let socket: WebSocket; export let socket: WebSocket;
export let invitedUsername: string;
let map: Map = new Map(DEFAULT_MAP_SIZE.clone(), []); let map: Map = new Map(DEFAULT_MAP_SIZE.clone(), []);
let otherUsername: string = "Garfield";
function createGame() { function createGame() {
const data: GameCreationDto = { const data: GameCreationDto = {
playerNames: [$store.username, otherUsername], playerNames: [$store.username, invitedUsername],
map, map,
}; };
socket.send(formatWebsocketData(GAME_EVENTS.CREATE_GAME, data)); socket.send(formatWebsocketData(GAME_EVENTS.CREATE_GAME, data));
@ -23,9 +23,9 @@
<div class="overlay"> <div class="overlay">
<div class="window" on:click|stopPropagation on:keydown|stopPropagation> <div class="window" on:click|stopPropagation on:keydown|stopPropagation>
Friend: Friend:
<input bind:value={otherUsername} /> <input bind:value={invitedUsername} />
<button on:click={createGame}> <button on:click={createGame}>
Create game vs {otherUsername} Create game vs {invitedUsername}
</button> </button>
<MapCustomization {map} /> <MapCustomization {map} />
</div> </div>

13
front/volume/src/components/Pong/Pong.svelte

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

Loading…
Cancel
Save