From e7221390f3e11cffbe52fb1448dd5986898095af Mon Sep 17 00:00:00 2001 From: sepia Date: Tue, 29 Jul 2025 17:56:07 -0500 Subject: [PATCH] Add animations messages --- public/index.html | 1 + public/scripts/make-animations.js | 18 ++++++++++++++++++ src/view/animation-renderer.tsx | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100755 public/scripts/make-animations.js create mode 100755 src/view/animation-renderer.tsx diff --git a/public/index.html b/public/index.html index ab05535..be5e2de 100755 --- a/public/index.html +++ b/public/index.html @@ -53,6 +53,7 @@ + diff --git a/public/scripts/make-animations.js b/public/scripts/make-animations.js new file mode 100755 index 0000000..b7c4833 --- /dev/null +++ b/public/scripts/make-animations.js @@ -0,0 +1,18 @@ +const animations = {}; +// animations['victory'] = TODO: implement victory animation +// animations['defeat'] = TODO: implement defeat animation +// animations['draw'] = TODO: implement draw animation + +document.addEventListener('htmx:wsAfterMessage', function (e) { + let msg; + try { + msg = JSON.parse(e.detail.message); + } catch (_) { + return; + } + if (msg.type !== 'animation') { + return; + } + // TODO: implement animation playback + console.log('Animation requested:', msg.animation); +}); diff --git a/src/view/animation-renderer.tsx b/src/view/animation-renderer.tsx new file mode 100755 index 0000000..5a8387f --- /dev/null +++ b/src/view/animation-renderer.tsx @@ -0,0 +1,18 @@ +import { PlayerConnection } from '../player-connection'; +import { GameServer } from '../game-server'; + +export function broadcastAnimation(server: GameServer, animation: string) { + server.connections.forEach((conn: PlayerConnection) => + broadcastAnimationToPlayer(conn, animation), + ); +} + +export function broadcastAnimationToPlayer( + conn: PlayerConnection, + animation: string, +) { + conn.ws.send({ + type: 'animation', + animation: animation, + }); +}