diff --git a/client/src/lib/Websocket.ts b/client/src/lib/Websocket.ts index 516b009..4bf0d81 100644 --- a/client/src/lib/Websocket.ts +++ b/client/src/lib/Websocket.ts @@ -21,6 +21,7 @@ class ConnectedClient extends EventTarget { state: RTCDataChannelState | null = null; readyState: number = 0; pings: number[] = []; + score: number = 0; constructor(public ws: WebsocketConnection, public name: string) { super(); @@ -83,6 +84,9 @@ class ConnectedClient extends EventTarget { this.dispatchEvent(new FastEvent("message", msg.d)); messages.update(t => { t.push({ author: this.name, content: msg.d });return t}) break; + case "start": + gameData.set({ score: 0 }); + // break not on purpose default: console.log("MSG", msg); this.dispatchEvent(new FastEvent(msg.t, msg.d)); @@ -266,16 +270,28 @@ export class WebsocketConnection extends EventTarget { sendMessage(msg: string) { if (!this.roomName) return console.log("Not in a room"); - for(const [, client] of this.fast) { - client.send({ t: "msg", d: msg }); - } + this.broadcast({ t: "msg", d: msg }); messages.update(t => { t.push({ author: this.name, content: msg }); return t }); } + broadcast(data: any) { + if (!this.roomName) return console.log("Not in a room"); + for(const [, client] of this.fast) { + client.send(data); + } + } createGame(name: string) { this.ws.send(JSON.stringify({ t: "create", name: name })); } + startGame() { + if (!this.roomName) return console.log("Not in a room"); + this.broadcast({ t: "start" }); + for(const [, client] of this.fast) { + client.score = 0; + } + } + join(name: string) { this.ws.send(JSON.stringify({ t: "join", name: name })); } @@ -296,4 +312,5 @@ export const listLoading = writable(true); export const lastError: Writable = writable(""); export const room: Writable<{ name: string, host: string } | null> = writable(null); export const players: Writable> = writable(new Map); -export const messages: Writable<{ author: string, content: string }[]> = writable([]); \ No newline at end of file +export const messages: Writable<{ author: string, content: string }[]> = writable([]); +export const gameData: Writable<{ score: number }|null> = writable(null); \ No newline at end of file diff --git a/client/src/lib/view/components/button.svelte b/client/src/lib/view/components/button.svelte index 0d60859..13e68ce 100644 --- a/client/src/lib/view/components/button.svelte +++ b/client/src/lib/view/components/button.svelte @@ -1,5 +1,8 @@ + - + \ No newline at end of file diff --git a/client/src/lib/view/components/jump.svelte b/client/src/lib/view/components/jump.svelte new file mode 100644 index 0000000..3943a65 --- /dev/null +++ b/client/src/lib/view/components/jump.svelte @@ -0,0 +1,105 @@ + + +
+ + {#if showfaces} + + {/if} + + + {#if showfaces} + + + {/if} + + + {#if showfaces} + + + + {/if} + + + {#if showfaces} + + + + + + + {/if} + + + {#if showfaces} + + + + + {/if} + + + {#if showfaces} + + + + + + {/if} + +
+ + diff --git a/client/src/lib/view/components/prestartScreen.svelte b/client/src/lib/view/components/prestartScreen.svelte new file mode 100644 index 0000000..3d37df2 --- /dev/null +++ b/client/src/lib/view/components/prestartScreen.svelte @@ -0,0 +1,104 @@ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + diff --git a/client/src/lib/view/game/game.svelte b/client/src/lib/view/game/game.svelte index 8d1286b..2454751 100644 --- a/client/src/lib/view/game/game.svelte +++ b/client/src/lib/view/game/game.svelte @@ -1,5 +1,16 @@ - \ No newline at end of file +{#if !$gameData} + +{:else} + + + + +{/if} diff --git a/client/src/lib/view/game/gameOverlay.svelte b/client/src/lib/view/game/gameOverlay.svelte new file mode 100644 index 0000000..13e960c --- /dev/null +++ b/client/src/lib/view/game/gameOverlay.svelte @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/client/src/lib/view/game/scene.svelte b/client/src/lib/view/game/scene.svelte new file mode 100644 index 0000000..e69de29 diff --git a/client/src/lib/view/game/timedPrestartScreen.svelte b/client/src/lib/view/game/timedPrestartScreen.svelte new file mode 100644 index 0000000..361ebf5 --- /dev/null +++ b/client/src/lib/view/game/timedPrestartScreen.svelte @@ -0,0 +1,17 @@ + + +{#if visible} + +{/if} \ No newline at end of file diff --git a/client/src/lib/view/game/waiting.svelte b/client/src/lib/view/game/waiting.svelte index a6fcb44..2b83c0b 100644 --- a/client/src/lib/view/game/waiting.svelte +++ b/client/src/lib/view/game/waiting.svelte @@ -2,7 +2,9 @@ import { connection, messages, players, room } from '$lib/Websocket'; import Button from '../components/button.svelte'; - function startGame() {} + function startGame() { + + } let content = ""; function sendMessage() { if(!content.length || content.length > 512) return; @@ -61,7 +63,7 @@ {#if $room?.host === $connection?.name} {:else} - + {/if} diff --git a/client/src/routes/cube.svelte b/client/src/routes/cube.svelte deleted file mode 100644 index 3f63329..0000000 --- a/client/src/routes/cube.svelte +++ /dev/null @@ -1,41 +0,0 @@ - - -
- - - - - - - - - - - - -
- - \ No newline at end of file