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, + }); +}