summaryrefslogtreecommitdiffstats
path: root/gui/tests
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 20:11:41 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 20:11:41 +0100
commite920b20fafe375eec15b24eb8cde4b1455dd01af (patch)
tree308d2f7999177a753528779f6ec7926f3fa50818 /gui/tests
parentv4.1.0: add the egui workspace member and the roulette style spike (diff)
downloadzagan-bet-e920b20fafe375eec15b24eb8cde4b1455dd01af.tar.gz
zagan-bet-e920b20fafe375eec15b24eb8cde4b1455dd01af.zip
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.
Diffstat (limited to '')
-rw-r--r--gui/tests/layout.rs76
1 files changed, 75 insertions, 1 deletions
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 @@
4 4
5use std::f32::consts::TAU; 5use std::f32::consts::TAU;
6 6
7use eframe::egui::{Pos2, Rect, pos2, vec2};
7use zagan_bet::roulette::{BetTarget, Outside}; 8use zagan_bet::roulette::{BetTarget, Outside};
8use zagan_bet_gui::roulette::{number_under, size_for, target_name}; 9use zagan_bet_gui::roulette::{Felt, number_under, size_for, target_name};
9use zagan_bet_gui::theme::{group_digits, money}; 10use zagan_bet_gui::theme::{group_digits, money};
10 11
11#[test] 12#[test]
@@ -49,6 +50,79 @@ fn table_size_keeps_the_felt_aspect_and_fits() {
49 assert!((cell - (size.y - 12.0) / 4.89).abs() < 0.01); 50 assert!((cell - (size.y - 12.0) / 4.89).abs() < 0.01);
50} 51}
51 52
53fn felt() -> Felt {
54 Felt::new(Rect::from_min_size(
55 Pos2::ZERO,
56 size_for(vec2(1300.0, 900.0)),
57 ))
58}
59
60#[test]
61fn the_pointer_snaps_to_straights_splits_and_corners() {
62 let felt = felt();
63 let cell = felt.cell_size();
64 let center = felt.number_rect(17).center();
65
66 // The inner half of a cell is a straight, even slightly off centre.
67 assert_eq!(
68 felt.target_at(center + vec2(cell * 0.2, 0.0)),
69 Some(BetTarget::Straight { number: 17 })
70 );
71
72 // A quarter cell from the centre is the line: right of 17 is 20, above is 18.
73 assert_eq!(
74 felt.target_at(center + vec2(cell * 0.3, 0.0)),
75 Some(BetTarget::Split { a: 17, b: 20 })
76 );
77 assert_eq!(
78 felt.target_at(center + vec2(0.0, -cell * 0.3)),
79 Some(BetTarget::Split { a: 17, b: 18 })
80 );
81
82 // Near both lines at once is the corner of the four cells.
83 assert_eq!(
84 felt.target_at(center + vec2(cell * 0.3, -cell * 0.3)),
85 Some(BetTarget::Corner {
86 numbers: [17, 18, 20, 21]
87 })
88 );
89
90 // Zero is a straight and nothing else.
91 assert_eq!(
92 felt.target_at(felt.number_rect(0).center()),
93 Some(BetTarget::Straight { number: 0 })
94 );
95}
96
97#[test]
98fn the_pointer_finds_the_wide_bets_below_the_grid() {
99 let felt = felt();
100 let cell = felt.cell_size();
101 let x = felt.number_rect(17).center().x;
102 let grid_bottom = felt.number_rect(16).bottom();
103
104 // 17 sits in the second dozen (13-24).
105 assert_eq!(
106 felt.target_at(pos2(x, grid_bottom + cell * 0.3)),
107 Some(BetTarget::Dozen { index: 1 })
108 );
109
110 // Below the dozens is the column row; 17 is in column 2 (2,5,...,17).
111 assert_eq!(
112 felt.target_at(pos2(x, grid_bottom + cell * (0.72 + 0.3))),
113 Some(BetTarget::Column { index: 1 })
114 );
115
116 // And below that, the outside row: 17's column lands on RED.
117 assert_eq!(
118 felt.target_at(pos2(x, grid_bottom + cell * (0.72 + 0.55 + 0.3))),
119 Some(BetTarget::Outside { kind: Outside::Red })
120 );
121
122 // Outside the board is not a bet.
123 assert_eq!(felt.target_at(pos2(-1.0, -1.0)), None);
124}
125
52#[test] 126#[test]
53fn targets_read_as_bet_slips() { 127fn targets_read_as_bet_slips() {
54 assert_eq!( 128 assert_eq!(