Add animations messages
This commit is contained in:
parent
70a9359c7f
commit
e7221390f3
|
@ -53,6 +53,7 @@
|
||||||
<script src="scripts/copy-game-link.js"></script>
|
<script src="scripts/copy-game-link.js"></script>
|
||||||
<script src="scripts/handle-redirects.js"></script>
|
<script src="scripts/handle-redirects.js"></script>
|
||||||
<script src="scripts/make-sounds.js"></script>
|
<script src="scripts/make-sounds.js"></script>
|
||||||
|
<script src="scripts/make-animations.js"></script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
|
@ -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,
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue