From e920b20fafe375eec15b24eb8cde4b1455dd01af Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 20:11:41 +0100 Subject: v4.1.1: pointer-first betting and visible payouts in the GUI The felt snaps the hover to the shared fine lattice: inner half of a cell is a straight, an edge a split, a crossing a corner. A translucent chip previews the target and the covered cells tint. Left click adds the selected chip, right or middle click takes one back through the new Bets::reduce; C or CLEAR empties the slip, and SPIN stays disabled with no chips. The result now pays out: the wheel leaves the winning pocket under the pointer, the winning cell and pocket get a gold outline, and the sidebar reports the amount returned and the net for the round (NO WIN on a loss). Placing a chip after a result starts the next round without losing the wheel position. The column row now spans the full width like a real table instead of hugging the left edge. Adds tests for lattice snapping, target naming and taking chips back. --- gui/tests/layout.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'gui/tests/layout.rs') diff --git a/gui/tests/layout.rs b/gui/tests/layout.rs index e0c0475..ab5a62e 100644 --- a/gui/tests/layout.rs +++ b/gui/tests/layout.rs @@ -4,8 +4,9 @@ use std::f32::consts::TAU; +use eframe::egui::{Pos2, Rect, pos2, vec2}; use zagan_bet::roulette::{BetTarget, Outside}; -use zagan_bet_gui::roulette::{number_under, size_for, target_name}; +use zagan_bet_gui::roulette::{Felt, number_under, size_for, target_name}; use zagan_bet_gui::theme::{group_digits, money}; #[test] @@ -49,6 +50,79 @@ fn table_size_keeps_the_felt_aspect_and_fits() { assert!((cell - (size.y - 12.0) / 4.89).abs() < 0.01); } +fn felt() -> Felt { + Felt::new(Rect::from_min_size( + Pos2::ZERO, + size_for(vec2(1300.0, 900.0)), + )) +} + +#[test] +fn the_pointer_snaps_to_straights_splits_and_corners() { + let felt = felt(); + let cell = felt.cell_size(); + let center = felt.number_rect(17).center(); + + // The inner half of a cell is a straight, even slightly off centre. + assert_eq!( + felt.target_at(center + vec2(cell * 0.2, 0.0)), + Some(BetTarget::Straight { number: 17 }) + ); + + // A quarter cell from the centre is the line: right of 17 is 20, above is 18. + assert_eq!( + felt.target_at(center + vec2(cell * 0.3, 0.0)), + Some(BetTarget::Split { a: 17, b: 20 }) + ); + assert_eq!( + felt.target_at(center + vec2(0.0, -cell * 0.3)), + Some(BetTarget::Split { a: 17, b: 18 }) + ); + + // Near both lines at once is the corner of the four cells. + assert_eq!( + felt.target_at(center + vec2(cell * 0.3, -cell * 0.3)), + Some(BetTarget::Corner { + numbers: [17, 18, 20, 21] + }) + ); + + // Zero is a straight and nothing else. + assert_eq!( + felt.target_at(felt.number_rect(0).center()), + Some(BetTarget::Straight { number: 0 }) + ); +} + +#[test] +fn the_pointer_finds_the_wide_bets_below_the_grid() { + let felt = felt(); + let cell = felt.cell_size(); + let x = felt.number_rect(17).center().x; + let grid_bottom = felt.number_rect(16).bottom(); + + // 17 sits in the second dozen (13-24). + assert_eq!( + felt.target_at(pos2(x, grid_bottom + cell * 0.3)), + Some(BetTarget::Dozen { index: 1 }) + ); + + // Below the dozens is the column row; 17 is in column 2 (2,5,...,17). + assert_eq!( + felt.target_at(pos2(x, grid_bottom + cell * (0.72 + 0.3))), + Some(BetTarget::Column { index: 1 }) + ); + + // And below that, the outside row: 17's column lands on RED. + assert_eq!( + felt.target_at(pos2(x, grid_bottom + cell * (0.72 + 0.55 + 0.3))), + Some(BetTarget::Outside { kind: Outside::Red }) + ); + + // Outside the board is not a bet. + assert_eq!(felt.target_at(pos2(-1.0, -1.0)), None); +} + #[test] fn targets_read_as_bet_slips() { assert_eq!( -- cgit v1.2.3