From 616e7bc792d636a22811bc4e711b51a313453888 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sat, 4 Jan 2025 20:08:28 -0500 Subject: [PATCH] debug: Split up debug page / golf some JS Tempted by the idea of making this more polished for real use.. --- public/debug.css | 3 +++ public/debug.html | 107 +++-------------------------------------------------------------------------------------------------------- public/debug.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 104 deletions(-) create mode 100644 public/debug.css create mode 100644 public/debug.js diff --git a/public/debug.css b/public/debug.css new file mode 100644 index 0000000..382e61b --- /dev/null +++ b/public/debug.css @@ -0,0 +1,3 @@ +img.card { + width: 100px; +} diff --git a/public/debug.html b/public/debug.html index 3b6d449..3e562de 100644 --- a/public/debug.html +++ b/public/debug.html @@ -3,114 +3,13 @@ Euchre Live!! - +
- -

Hello, World

+ +

Euchre

diff --git a/public/debug.js b/public/debug.js new file mode 100644 index 0000000..39f1ce8 --- /dev/null +++ b/public/debug.js @@ -0,0 +1,96 @@ +const ws = new WebSocket(`ws://${window.location.host}/play`); +let GAME_PHASE = ''; +const send = (payload) => ws.send(JSON.stringify(payload)); +const getel = (id) => document.getElementById(id); +ws.onmessage = (event) => { + msg = JSON.parse(event.data); + if (msg.msg_type !== 'pong') { console.log(msg) } + + if (msg.msg_type === 'game_state') { + GAME_PHASE = msg.game.phase; + gameState = '
Game: ' + msg.table_id + '
' + + 'Players: ' + msg.game.players + '
' + + 'Spectators: ' + msg.game.spectators + '
' + + 'Game Phase: ' + msg.game.phase + '
' + + 'Player Turn: ' + msg.game.turn + '
' + + 'Dealer: ' + msg.game.dealer + '
' + + 'Trump: ' + msg.game.trump + '
' + + 'Tricks: ' + msg.game.tricks + '
' + + 'Hand Lengths: ' + msg.game.hand_lengths + '
' + + 'Score: ' + msg.game.score + '
' + + if (typeof msg.game.trump_nominee !== 'undefined') { + gameState += 'Trump Nominee: ' + '
' + } + + getel('hand').innerHTML = 'HAND:
' + if (msg.hand) { + for (let i = 0; i < msg.hand.length; i++) { + const c = msg.hand[i] + getel('hand').innerHTML += '' + } + } + + if (msg.game.table) { + getel('table').innerHTML = '' + for (let i = 0; i < msg.game.table.length; i++) { + let c = msg.game.table[i] + if (c === null) { + c = '2B' // show back + } + getel('table').innerHTML += '' + } + } else { + getel('table').innerHTML = 'No cards on table' + } + getel('game').innerHTML = gameState + } else if (msg.msg_type === 'error') { + getel('error').innerHTML += msg.msg + '
' + } else if (msg.msg_type === 'chat') { + getel('chat_box').innerHTML += msg.msg + '
' + } +}; + +function joinGame() { + uname = getel('username').value; + gname = getel('gamename').value; + pass = getel('password').value; + console.log('U: ' + uname + ' G: ' + gname); + send({action:'join_table', player_name: uname, table: gname, password: pass}) +} +function sit() { + seat = getel('seat_no').value; + send({action:'take_seat', seat: seat}) +} +function stand() { + send({action:'stand_up'}) +} +function start_game() { + seat = getel('start_seat').value; + send({action:'start_game', start_seat: seat}) +} +function vote(a) { + order_suit = getel('order_suit').value; + console.log(order_suit); + send({action:'order', vote: order_suit, loner: a}) +} +function pass_kitty() { + send({action:'order', vote: 'pass'}) +} +function play(card) { + if (GAME_PHASE === 'dealer_swap') { + send({action:'dealer_swap', card: card}) + } else { + send({action:'play_card', card: card}) + } +} +function chat() { + send({action:'chat', msg: getel('chat').value }) + getel('chat').value = ''; +} +function leaveGame() { + send({action:'leave_table'}) +} + +window.setInterval(() => { send({action:'ping'}) }, 5000); + -- libgit2 1.8.1