fix(engine): share Draw-Three waste fan step between renderer and hit-test
The waste fan x-offset was computed two ways: the renderer used tableau_col_step * 0.224 while the hit-test hard-coded card_size.x * 0.28. These coincide on desktop (col_step = 1.25*cw) but drift on Android, where tighter column spacing (H_GAP_DIVISOR=32, col_step ~= 1.03*cw) makes the renderer fan at ~0.231*cw. The top fanned waste card's sprite then sits ~14px left of its click target, so dragging the visible top card grabs the card beneath it. Extract waste_fan_step() and tableau_col_step() as the single source for both the renderer (card_plugin::card_positions) and the hit-test (input_plugin::card_position) so they can no longer diverge. Add a regression test that simulates Android-tight spacing and asserts the hit target tracks the renderer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,36 @@ pub const TABLEAU_FACEDOWN_FAN_FRAC: f32 = 0.14;
|
||||
// foundation piles bleeding through when a 2 sits on an Ace.
|
||||
pub const STACK_FAN_FRAC: f32 = 0.025;
|
||||
|
||||
/// Per-card horizontal fan step for the Draw-Three waste, in logical pixels.
|
||||
///
|
||||
/// Derived from the actual tableau column spacing (`Tableau2.x − Tableau1.x`)
|
||||
/// rather than a fixed fraction of card width, so the fan scales with the
|
||||
/// platform's `H_GAP_DIVISOR` (desktop ≈ 1.25×cw spacing, Android ≈ 1.03×cw).
|
||||
/// Public so `input_plugin` can hit-test the fanned waste cards at the exact
|
||||
/// x-offsets the renderer uses; any drift makes a click on the top fanned card
|
||||
/// land on the card beneath it.
|
||||
pub fn waste_fan_step(layout: &Layout) -> f32 {
|
||||
tableau_col_step(layout) * 0.224
|
||||
}
|
||||
|
||||
/// Horizontal distance between adjacent tableau columns (`Tableau2.x −
|
||||
/// Tableau1.x`), in logical pixels. The face-down stock is rendered one column
|
||||
/// step left of the waste, and the Draw-Three waste fan ([`waste_fan_step`]) is
|
||||
/// a fraction of it. Public so hit-testing mirrors the renderer exactly.
|
||||
pub fn tableau_col_step(layout: &Layout) -> f32 {
|
||||
let t1 = layout
|
||||
.pile_positions
|
||||
.get(&KlondikePile::Tableau(Tableau::Tableau1))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
let t2 = layout
|
||||
.pile_positions
|
||||
.get(&KlondikePile::Tableau(Tableau::Tableau2))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
(t2.x - t1.x).abs()
|
||||
}
|
||||
|
||||
/// Font size as a fraction of card width.
|
||||
const FONT_SIZE_FRAC: f32 = 0.28;
|
||||
|
||||
@@ -908,34 +938,18 @@ fn card_positions(game: &GameState, layout: &Layout) -> Vec<((Card, bool), Vec2,
|
||||
(KlondikePile::Tableau(Tableau::Tableau7), false),
|
||||
];
|
||||
|
||||
// Compute the Draw-Three waste fan step proportional to the column spacing
|
||||
// (waste_x − stock_x = card_width + h_gap) rather than a fixed fraction of
|
||||
// card_width. On desktop (H_GAP_DIVISOR=4) col_step = 1.25×cw and
|
||||
// 0.224 × 1.25 = 0.28 — identical to the previous constant. On Android
|
||||
// (H_GAP_DIVISOR=32) col_step ≈ 1.031×cw so fan_step ≈ 0.231×cw, keeping
|
||||
// the top fanned card's centre within the waste column's own horizontal
|
||||
// footprint instead of spilling into the adjacent gap.
|
||||
let tableau_col_step = {
|
||||
let t1 = layout
|
||||
.pile_positions
|
||||
.get(&KlondikePile::Tableau(Tableau::Tableau1))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
let t2 = layout
|
||||
.pile_positions
|
||||
.get(&KlondikePile::Tableau(Tableau::Tableau2))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
(t2.x - t1.x).abs()
|
||||
};
|
||||
let waste_fan_step = tableau_col_step * 0.224;
|
||||
// Draw-Three waste fan step, proportional to the column spacing so it scales
|
||||
// with the platform's H_GAP_DIVISOR. Shared with input_plugin's hit-test via
|
||||
// `waste_fan_step` so the two never drift (a drift puts the top fanned card's
|
||||
// click target on the card beneath it).
|
||||
let waste_fan_step = waste_fan_step(layout);
|
||||
|
||||
for (pile_type, is_stock_area) in piles {
|
||||
let Some(mut base) = layout.pile_positions.get(&pile_type).copied() else {
|
||||
continue;
|
||||
};
|
||||
if matches!(pile_type, KlondikePile::Stock) && is_stock_area {
|
||||
base.x -= tableau_col_step;
|
||||
base.x -= tableau_col_step(layout);
|
||||
}
|
||||
let is_tableau = matches!(pile_type, KlondikePile::Tableau(_));
|
||||
let is_waste = matches!(pile_type, KlondikePile::Stock) && !is_stock_area;
|
||||
|
||||
Reference in New Issue
Block a user