refactor(engine): audit and rationalize platform cfg gates (closes #49)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -14,9 +14,8 @@ use std::collections::{HashMap, HashSet};
|
||||
|
||||
use bevy::color::Color;
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::WindowResized;
|
||||
#[cfg(target_os = "android")]
|
||||
use bevy::sprite::Anchor;
|
||||
use bevy::window::WindowResized;
|
||||
use solitaire_core::card::{Card, Rank, Suit};
|
||||
use solitaire_core::game_state::{DrawMode, GameState};
|
||||
use solitaire_core::pile::PileType;
|
||||
@@ -26,13 +25,14 @@ use solitaire_core::rules::{can_place_on_foundation, can_place_on_tableau};
|
||||
use crate::animation_plugin::{CardAnim, EffectiveSlideDuration, CARD_ANIM_Z_LIFT};
|
||||
use crate::card_animation::CardAnimation;
|
||||
use crate::events::{CardFaceRevealedEvent, CardFlippedEvent, StateChangedEvent};
|
||||
use crate::font_plugin::FontResource;
|
||||
use crate::game_plugin::GameMutation;
|
||||
use crate::layout::{Layout, LayoutResource, LayoutSystem};
|
||||
use crate::pause_plugin::PausedResource;
|
||||
use crate::platform::USE_TOUCH_UI_LAYOUT;
|
||||
use crate::resources::{DragState, GameStateResource};
|
||||
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource};
|
||||
use crate::table_plugin::{PileMarker, PILE_MARKER_DEFAULT_COLOUR};
|
||||
use crate::font_plugin::FontResource;
|
||||
use crate::ui_theme::{
|
||||
CARD_SHADOW_ALPHA_DRAG, CARD_SHADOW_ALPHA_IDLE, CARD_SHADOW_COLOR, CARD_SHADOW_LOCAL_Z,
|
||||
CARD_SHADOW_OFFSET_DRAG, CARD_SHADOW_OFFSET_IDLE, CARD_SHADOW_PADDING_DRAG,
|
||||
@@ -73,10 +73,9 @@ pub const STACK_FAN_FRAC: f32 = 0.025;
|
||||
/// Font size as a fraction of card width.
|
||||
const FONT_SIZE_FRAC: f32 = 0.28;
|
||||
|
||||
/// Font-size fraction for the large-print readability overlay on Android.
|
||||
/// Font-size fraction for the large-print readability overlay on touch HUD layouts.
|
||||
/// Spawned on top of PNG face cards to make the rank+suit legible at phone
|
||||
/// scale, where the baked-in PNG corner text is only ~10 px physical.
|
||||
#[cfg(target_os = "android")]
|
||||
const FONT_SIZE_FRAC_MOBILE: f32 = 0.35;
|
||||
|
||||
/// Card-face background — Terminal `#1a1a1a` (BG_ELEVATED).
|
||||
@@ -177,13 +176,12 @@ pub struct CardEntity {
|
||||
#[derive(Component, Debug)]
|
||||
pub struct CardLabel;
|
||||
|
||||
/// Marker for the large-print rank+suit corner overlay on Android.
|
||||
/// Marker for the large-print rank+suit corner overlay used by touch HUD layouts.
|
||||
///
|
||||
/// Spawned on top of PNG face cards (face-up only) at font size
|
||||
/// [`FONT_SIZE_FRAC_MOBILE`] so the rank and suit character are
|
||||
/// readable at phone scale. Only exists when `CardImageSet` is present
|
||||
/// (the fallback solid-colour path uses a plain `CardLabel` instead).
|
||||
#[cfg(target_os = "android")]
|
||||
#[derive(Component, Debug, Clone)]
|
||||
struct AndroidCornerLabel(pub String);
|
||||
|
||||
@@ -192,10 +190,11 @@ struct AndroidCornerLabel(pub String);
|
||||
/// Covers the card art's own small corner rank/suit text so only the
|
||||
/// large overlay is visible. Sized at [`FONT_SIZE_FRAC_MOBILE`]-derived
|
||||
/// dimensions and coloured [`CARD_FACE_COLOUR`] to match the card face.
|
||||
#[cfg(target_os = "android")]
|
||||
#[derive(Component, Debug, Clone, Copy)]
|
||||
struct AndroidCornerBg;
|
||||
|
||||
type AndroidCornerBgFilter = (With<AndroidCornerBg>, Without<AndroidCornerLabel>);
|
||||
|
||||
/// Marker component indicating the card is currently highlighted as a hint.
|
||||
/// `remaining` counts down in real seconds; the highlight is removed when it
|
||||
/// reaches zero and the card sprite colour is restored to its normal value.
|
||||
@@ -465,7 +464,6 @@ impl Plugin for CardPlugin {
|
||||
),
|
||||
);
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
app.add_systems(Update, resize_android_corner_labels);
|
||||
}
|
||||
}
|
||||
@@ -920,15 +918,11 @@ fn spawn_card_entity(
|
||||
));
|
||||
});
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
if card_images.is_some() {
|
||||
if USE_TOUCH_UI_LAYOUT && card_images.is_some() {
|
||||
entity.with_children(|b| {
|
||||
add_android_corner_label(b, card, layout.card_size, color_blind, high_contrast, font_handle);
|
||||
});
|
||||
}
|
||||
// Suppress unused-variable warning when not building for Android.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let _ = font_handle;
|
||||
entity_id
|
||||
}
|
||||
|
||||
@@ -1013,15 +1007,11 @@ fn update_card_entity(
|
||||
));
|
||||
});
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
if card_images.is_some() {
|
||||
if USE_TOUCH_UI_LAYOUT && card_images.is_some() {
|
||||
commands.entity(entity).with_children(|b| {
|
||||
add_android_corner_label(b, card, layout.card_size, color_blind, high_contrast, font_handle);
|
||||
});
|
||||
}
|
||||
// Suppress unused-variable warning when not building for Android.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let _ = font_handle;
|
||||
}
|
||||
|
||||
fn label_for(card: &Card) -> String {
|
||||
@@ -1094,9 +1084,8 @@ fn label_visibility(card: &Card) -> Visibility {
|
||||
}
|
||||
}
|
||||
|
||||
/// Rank+suit string for the Android readability overlay.
|
||||
/// Rank+suit string for the readability overlay on touch HUD layouts.
|
||||
/// Uses Unicode suit glyphs (♠♥♦♣ — U+2660–U+2666, covered by FiraMono).
|
||||
#[cfg(target_os = "android")]
|
||||
fn mobile_label_for(card: &Card) -> String {
|
||||
let rank = match card.rank {
|
||||
Rank::Ace => "A",
|
||||
@@ -1132,7 +1121,6 @@ fn mobile_label_for(card: &Card) -> String {
|
||||
/// those glyphs, causing a coloured missing-glyph rectangle to appear in
|
||||
/// the text colour — the root cause of the "red square on face-down cards"
|
||||
/// visual bug (the box bleeds through near the card edge at z=0.02).
|
||||
#[cfg(target_os = "android")]
|
||||
fn add_android_corner_label(
|
||||
parent: &mut ChildSpawnerCommands,
|
||||
card: &Card,
|
||||
@@ -2146,15 +2134,11 @@ fn resize_cards_in_place(
|
||||
/// change or any window resize). The full despawn/respawn path in
|
||||
/// `update_card_entity` already handles game-state changes; this system
|
||||
/// covers the resize-only path where children are mutated in place.
|
||||
#[cfg(target_os = "android")]
|
||||
fn resize_android_corner_labels(
|
||||
layout: Res<LayoutResource>,
|
||||
card_images: Option<Res<CardImageSet>>,
|
||||
mut text_query: Query<(&AndroidCornerLabel, &mut Text2d, &mut TextFont, &mut Transform)>,
|
||||
mut bg_query: Query<
|
||||
(&mut Sprite, &mut Transform),
|
||||
(With<AndroidCornerBg>, Without<AndroidCornerLabel>),
|
||||
>,
|
||||
mut bg_query: Query<(&mut Sprite, &mut Transform), AndroidCornerBgFilter>,
|
||||
) {
|
||||
if !layout.is_changed() || card_images.is_none() {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user