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. --- tests/client_core.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/client_core.rs b/tests/client_core.rs index 49abca2..2f43d47 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs @@ -17,7 +17,7 @@ use zagan_bet::client::games::roulette::{Cursor, Direction}; use zagan_bet::client::ui::command_names; use zagan_bet::client::view::{Command, RoulettePhase, SlotsPhase, View}; use zagan_bet::roulette::BetTarget; -use zagan_bet::crash::CrashState; +use zagan_bet::crash::{CrashState, multiplier_at}; const WIN3: &str = "CCCCLLCLODGSDGS"; const LOSS: &str = "CLOOGDSLCDCOGLS"; @@ -538,6 +538,45 @@ fn info_shows_the_host_and_the_server_fields() { assert!(h.screen.lines.iter().any(|line| line == "User: alice")); assert!(h.screen.lines.iter().any(|line| line == "Account: 42")); assert!(h.screen.lines.iter().any(|line| line == "Balance: 1234 Kr")); + + let Some(View::Lobby(lobby)) = h.core.view() else { + panic!("the lobby view is always available"); + }; + assert_eq!(lobby.account.as_deref(), Some("42")); + assert_eq!(lobby.balance, Some(1234)); +} + +#[test] +fn a_roulette_chip_can_be_taken_back_through_a_command() { + let mut h = Harness::new(); + h.enter_roulette(); + h.core.command(Command::SetChip(25)); + + h.core + .command(Command::PlaceBetAt(BetTarget::Straight { number: 17 })); + h.core + .command(Command::PlaceBetAt(BetTarget::Straight { number: 17 })); + let Some(View::Roulette(view)) = h.core.view() else { + panic!("roulette is open"); + }; + assert_eq!(view.bets.total(), 50); + + h.core + .command(Command::RemoveBetAt(BetTarget::Straight { number: 17 })); + let Some(View::Roulette(view)) = h.core.view() else { + panic!("roulette is open"); + }; + assert_eq!(view.bets.total(), 25); + assert_eq!(view.phase, RoulettePhase::Placing); + + h.core + .command(Command::RemoveBetAt(BetTarget::Straight { number: 17 })); + h.core + .command(Command::RemoveBetAt(BetTarget::Straight { number: 17 })); + let Some(View::Roulette(view)) = h.core.view() else { + panic!("roulette is open"); + }; + assert_eq!(view.bets.total(), 0); } #[test] @@ -1581,3 +1620,29 @@ fn login_requires_a_connection() { assert!(!h.sent.iter().any(|line| line.starts_with("AUTH"))); } + +#[test] +fn the_crash_multiplier_is_not_rounded_for_the_chart() { + let mut h = Harness::new(); + h.enter_crash(); + h.key(Key::Char(' ')); + h.reply(&crash_line( + "CRASH_START", + &crash_state("running", 1.0, None, 0, 990), + )); + + h.tick(Duration::from_millis(1234)); + let expected = multiplier_at(Duration::from_millis(1234)); + let Some(View::Crash(view)) = h.core.view() else { + panic!("expected a crash view"); + }; + assert!( + (view.multiplier - expected).abs() < 1e-9, + "the GUI chart needs the full precision value" + ); + let rounded = (expected * 100.0).round() / 100.0; + assert!( + (view.multiplier - rounded).abs() > 1e-6, + "a two-decimal store would flatten the curve into steps" + ); +} -- cgit v1.2.3