From bf4cf78ab26896faf457273e37d30fc96381c4a4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 21:09:56 +0100 Subject: v4.2.0: wire the GUI to the core, transport and all four games Phase 4. The egui frontend now shares ClientCore and the client database with the terminal: one background worker owns TLS, trust answers go through a channel, and a 10 s request deadline mirrors the terminal socket timeout. First contact, a changed key and a version mismatch are explicit screens; login can remember the credential and auto-login signs in before the login form appears. Adds the lobby with an update notice, a full-width scrollable history table, and the four games painted from View: slots with reel animation and win lines that stop at the last matching reel, roulette with the hover lattice and wheel spin, blackjack with vector-drawn suits, and a smooth crash curve. Sidebars pin their action block; leaving a live hand or round asks before forfeiting. The header balance holds the staked amount while the reels or wheel turn and only shows the payout when they stop. Refused spins cancel the animation. Live crash multipliers keep full precision for the chart; the terminal still displays two decimals. Verified live against a 4.2.0 server: register, login, auto-login, trust, all four games settling, history (50 rows), logout, disconnect, forfeit confirmation, and the version-mismatch screen. Release: 8.3 MB Linux, 6.8 MB Windows, 61 ms to window, 131 MB idle RSS. --- src/client/core.rs | 39 +++++++++++++++++++++++++++++++-------- src/client/games/manager.rs | 6 ++++-- src/client/view.rs | 2 ++ 3 files changed, 37 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/client/core.rs b/src/client/core.rs index 21c1cb2..6d8294c 100644 --- a/src/client/core.rs +++ b/src/client/core.rs @@ -62,6 +62,8 @@ pub struct ClientCore { logged_in: Option, pending: Option, balance: Option, + /// Account number from the last `INFO`, shown by both frontends. + account: Option, host: Option, fingerprint: Option, /// Local anchor for the crash multiplier, set when a round starts. @@ -82,6 +84,7 @@ impl ClientCore { logged_in: None, pending: None, balance: None, + account: None, host: None, fingerprint: None, crash_started: None, @@ -275,15 +278,18 @@ impl ClientCore { } Some(Pending::Echo) => print_line(format!("Echo: {}", reply.trim())), Some(Pending::Info) => { + // The same reply feeds the balance and the account number. + let balance = info_balance(reply); + if let Some(account) = info_account(reply) { + self.account = Some(account); + } + if let Some(balance) = balance { + self.balance = Some(balance); + self.game.set_balance(balance); + } if self.game.is_in_game() { - // Balance fetch while entering a game. A failure is not - // fatal: the board keeps showing `?`. - if let Some(balance) = info_balance(reply) { - self.balance = Some(balance); - self.game.set_balance(balance); - return self.board_effects(); - } - Vec::new() + // A failure is not fatal: the board keeps showing `?`. + self.board_effects() } else { vec![Effect::Print(info_lines(reply))] } @@ -405,6 +411,7 @@ impl ClientCore { None => Vec::new(), }, Command::PlaceBetAt(target) => self.place_roulette_chip_on(target), + Command::RemoveBetAt(target) => self.remove_roulette_chip_on(target), Command::ClearBets => { self.game.set_roulette_bets(&Bets::default()); self.game.set_roulette_status("place"); @@ -489,6 +496,12 @@ impl ClientCore { self.place_roulette_bets(bets) } + fn remove_roulette_chip_on(&mut self, target: BetTarget) -> Vec { + let mut bets = self.game.roulette_bets(); + bets.reduce(&target, self.game.roulette_chip()); + self.place_roulette_bets(bets) + } + fn place_roulette_bets(&mut self, bets: Bets) -> Vec { if let Some(balance) = self.balance { if bets.total() > balance.max(0) as u64 { @@ -782,6 +795,7 @@ impl ClientCore { Screen::Lobby => View::Lobby(LobbyView { connected: self.connected, user: self.logged_in.clone(), + account: self.account.clone(), balance: self.balance, games: self.games(), login_error: self.login_error.clone(), @@ -824,6 +838,15 @@ fn print_line(message: impl Into) -> Vec { vec![Effect::Print(vec![message.into()])] } +fn info_account(reply: &str) -> Option { + let parts: Vec<&str> = reply.split_whitespace().collect(); + if parts.first() == Some(&"INFO") && parts.len() == 4 { + Some(parts[2].to_string()).filter(|account| account != "-") + } else { + None + } +} + fn info_balance(reply: &str) -> Option { let parts: Vec<&str> = reply.split_whitespace().collect(); if parts.first() == Some(&"INFO") && parts.len() == 4 { diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index bb2a8b5..24ceeaa 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs @@ -353,7 +353,7 @@ impl GameManager { .insert("balance".to_string(), state.balance.to_string()); session .data - .insert("multiplier".to_string(), format!("{:.2}", state.multiplier)); + .insert("multiplier".to_string(), state.multiplier.to_string()); session .data .insert("potential".to_string(), state.potential.to_string()); @@ -373,9 +373,11 @@ impl GameManager { return; }; let bet = session.bet_amount; + // Keep the full value: the terminal rounds for display, but the GUI + // charts it and must not draw a staircase. session .data - .insert("multiplier".to_string(), format!("{multiplier:.2}")); + .insert("multiplier".to_string(), multiplier.to_string()); session .data .insert("potential".to_string(), payout(bet, multiplier).to_string()); diff --git a/src/client/view.rs b/src/client/view.rs index d2ccadb..4615720 100644 --- a/src/client/view.rs +++ b/src/client/view.rs @@ -246,6 +246,7 @@ impl CrashView { pub struct LobbyView { pub connected: bool, pub user: Option, + pub account: Option, pub balance: Option, pub games: Vec<(String, String)>, /// Why the last login or registration attempt failed. @@ -297,6 +298,7 @@ pub enum Command { MoveCursor(Direction), PlaceBet, PlaceBetAt(BetTarget), + RemoveBetAt(BetTarget), ClearBets, SetChip(u64), AdjustChip(i64), -- cgit v1.2.3