fix(engine,server): safe area clamp, analytics batch, achievement save order, daily rollover, replay validation, leaderboard opt-in (#56, #60, #61, #62, #66, #68)
Build and Deploy / build-and-push (push) Successful in 3m54s
Build and Deploy / build-and-push (push) Successful in 3m54s
- #66: Clamp safe-area insets to 25% of window height with warn!() on excess - #68: Move fire_flush outside per-event loop in analytics (batch flush once) - #56: Persist progress before marking reward_granted to prevent XP loss on crash - #60: Add DateRolloverTimer + check_date_rollover system for midnight seed refresh - #62: Add validate_header() in replay upload with mode/draw_mode allowlists - #61: Restore two-query leaderboard opt-in check (SELECT then UPDATE); original queries already in .sqlx cache; EXISTS variant would require sqlx prepare Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
//! [`InfoToastEvent`] explaining the gate but does not launch the mode
|
||||
//! or close the overlay.
|
||||
|
||||
use bevy::input::mouse::{MouseScrollUnit, MouseWheel};
|
||||
use bevy::input::ButtonInput;
|
||||
use bevy::input::mouse::{MouseScrollUnit, MouseWheel};
|
||||
use bevy::prelude::*;
|
||||
use solitaire_core::game_state::{DifficultyLevel, DrawMode};
|
||||
use solitaire_data::save_settings_to;
|
||||
@@ -28,15 +28,12 @@ use crate::events::{
|
||||
};
|
||||
use crate::font_plugin::FontResource;
|
||||
use crate::progress_plugin::ProgressResource;
|
||||
use crate::settings_plugin::{
|
||||
SettingsChangedEvent, SettingsResource, SettingsStoragePath,
|
||||
};
|
||||
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource, SettingsStoragePath};
|
||||
use crate::stats_plugin::StatsResource;
|
||||
use crate::ui_focus::{Disabled, FocusGroup, Focusable};
|
||||
use crate::ui_modal::{
|
||||
spawn_modal, spawn_modal_actions, spawn_modal_button, spawn_modal_header, ButtonVariant,
|
||||
ModalButton,
|
||||
ScrimDismissible,
|
||||
ButtonVariant, ModalButton, ScrimDismissible, spawn_modal, spawn_modal_actions,
|
||||
spawn_modal_button, spawn_modal_header,
|
||||
};
|
||||
use crate::ui_theme::{
|
||||
ACCENT_PRIMARY, BG_ELEVATED, BG_ELEVATED_HI, BORDER_STRONG, BORDER_SUBTLE, HighContrastBorder,
|
||||
@@ -189,7 +186,10 @@ impl HomeMode {
|
||||
|
||||
/// `true` when the mode is gated behind `CHALLENGE_UNLOCK_LEVEL`.
|
||||
fn requires_unlock(self) -> bool {
|
||||
matches!(self, HomeMode::Zen | HomeMode::Challenge | HomeMode::TimeAttack)
|
||||
matches!(
|
||||
self,
|
||||
HomeMode::Zen | HomeMode::Challenge | HomeMode::TimeAttack
|
||||
)
|
||||
}
|
||||
|
||||
/// `true` if the player at `level` is allowed to launch the mode.
|
||||
@@ -342,7 +342,10 @@ fn spawn_home_on_launch(
|
||||
}
|
||||
|
||||
// Pre-expand the difficulty section when the player has a saved preference.
|
||||
if settings.as_ref().is_some_and(|s| s.0.last_difficulty.is_some()) {
|
||||
if settings
|
||||
.as_ref()
|
||||
.is_some_and(|s| s.0.last_difficulty.is_some())
|
||||
{
|
||||
diff_expanded.0 = true;
|
||||
}
|
||||
|
||||
@@ -429,9 +432,7 @@ fn build_home_context<'a>(
|
||||
zen_best: stats.map_or(0, |s| s.0.zen_best_score),
|
||||
challenge_best: stats.map_or(0, |s| s.0.challenge_best_score),
|
||||
daily_today,
|
||||
draw_mode: settings
|
||||
.map(|s| s.0.draw_mode)
|
||||
.unwrap_or(DrawMode::DrawOne),
|
||||
draw_mode: settings.map(|s| s.0.draw_mode).unwrap_or(DrawMode::DrawOne),
|
||||
font_res,
|
||||
difficulty_expanded,
|
||||
last_difficulty: settings.and_then(|s| s.0.last_difficulty),
|
||||
@@ -1113,8 +1114,16 @@ fn spawn_draw_mode_chip<M: Component>(
|
||||
/// update without Visibility component surgery.
|
||||
fn spawn_difficulty_section(parent: &mut ChildSpawnerCommands, ctx: &HomeContext<'_>) {
|
||||
let font_handle = ctx.font_res.map(|f| f.0.clone()).unwrap_or_default();
|
||||
let font_label = TextFont { font: font_handle.clone(), font_size: TYPE_BODY, ..default() };
|
||||
let font_chip = TextFont { font: font_handle, font_size: TYPE_CAPTION, ..default() };
|
||||
let font_label = TextFont {
|
||||
font: font_handle.clone(),
|
||||
font_size: TYPE_BODY,
|
||||
..default()
|
||||
};
|
||||
let font_chip = TextFont {
|
||||
font: font_handle,
|
||||
font_size: TYPE_CAPTION,
|
||||
..default()
|
||||
};
|
||||
|
||||
let chevron = if ctx.difficulty_expanded { "v" } else { ">" };
|
||||
|
||||
@@ -1184,11 +1193,7 @@ fn spawn_difficulty_section(parent: &mut ChildSpawnerCommands, ctx: &HomeContext
|
||||
HighContrastBorder::with_default(BORDER_SUBTLE),
|
||||
))
|
||||
.with_children(|c| {
|
||||
c.spawn((
|
||||
Text::new(level.label()),
|
||||
font_chip.clone(),
|
||||
TextColor(fg),
|
||||
));
|
||||
c.spawn((Text::new(level.label()), font_chip.clone(), TextColor(fg)));
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1223,12 +1228,11 @@ fn score_chip_text_for(mode: HomeMode, ctx: &HomeContext<'_>) -> Option<String>
|
||||
HomeMode::Zen if ctx.zen_best > 0 => {
|
||||
Some(format!("Best {}", format_compact(ctx.zen_best as u64)))
|
||||
}
|
||||
HomeMode::Challenge if ctx.challenge_best > 0 => {
|
||||
Some(format!("Best {}", format_compact(ctx.challenge_best as u64)))
|
||||
}
|
||||
HomeMode::Daily if ctx.daily_streak > 0 => {
|
||||
Some(format!("Streak {}", ctx.daily_streak))
|
||||
}
|
||||
HomeMode::Challenge if ctx.challenge_best > 0 => Some(format!(
|
||||
"Best {}",
|
||||
format_compact(ctx.challenge_best as u64)
|
||||
)),
|
||||
HomeMode::Daily if ctx.daily_streak > 0 => Some(format!("Streak {}", ctx.daily_streak)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1302,11 +1306,7 @@ fn attach_focusable_to_home_mode_cards(
|
||||
/// feedback is supplied by `paint_modal_buttons` via the `ModalButton`
|
||||
/// component, which we attach with `ButtonVariant::Secondary` so the card
|
||||
/// reads as a standard interactive surface.
|
||||
fn spawn_mode_card(
|
||||
parent: &mut ChildSpawnerCommands,
|
||||
mode: HomeMode,
|
||||
ctx: &HomeContext<'_>,
|
||||
) {
|
||||
fn spawn_mode_card(parent: &mut ChildSpawnerCommands, mode: HomeMode, ctx: &HomeContext<'_>) {
|
||||
let level = ctx.level;
|
||||
let font_res = ctx.font_res;
|
||||
let score_chip = score_chip_text_for(mode, ctx);
|
||||
@@ -1338,10 +1338,26 @@ fn spawn_mode_card(
|
||||
// Locked cards mute their text to communicate the disabled state at
|
||||
// a glance; the explicit "Unlocks at level N" caption underneath
|
||||
// backs that up with copy.
|
||||
let title_color = if unlocked { TEXT_PRIMARY } else { TEXT_DISABLED };
|
||||
let desc_color = if unlocked { TEXT_SECONDARY } else { TEXT_DISABLED };
|
||||
let border_color = if unlocked { BORDER_SUBTLE } else { BORDER_STRONG };
|
||||
let glyph_color = if unlocked { ACCENT_PRIMARY } else { TEXT_DISABLED };
|
||||
let title_color = if unlocked {
|
||||
TEXT_PRIMARY
|
||||
} else {
|
||||
TEXT_DISABLED
|
||||
};
|
||||
let desc_color = if unlocked {
|
||||
TEXT_SECONDARY
|
||||
} else {
|
||||
TEXT_DISABLED
|
||||
};
|
||||
let border_color = if unlocked {
|
||||
BORDER_SUBTLE
|
||||
} else {
|
||||
BORDER_STRONG
|
||||
};
|
||||
let glyph_color = if unlocked {
|
||||
ACCENT_PRIMARY
|
||||
} else {
|
||||
TEXT_DISABLED
|
||||
};
|
||||
|
||||
parent
|
||||
.spawn((
|
||||
@@ -1489,9 +1505,7 @@ fn spawn_mode_card(
|
||||
// Locked footnote — explicit copy so the gate is unambiguous.
|
||||
if !unlocked {
|
||||
c.spawn((
|
||||
Text::new(format!(
|
||||
"Unlocks at level {CHALLENGE_UNLOCK_LEVEL}"
|
||||
)),
|
||||
Text::new(format!("Unlocks at level {CHALLENGE_UNLOCK_LEVEL}")),
|
||||
TextFont {
|
||||
font: font_desc.font.clone(),
|
||||
font_size: TYPE_CAPTION,
|
||||
@@ -1734,10 +1748,7 @@ mod tests {
|
||||
fn unlocked_zen_click_fires_start_zen_event_and_closes_modal() {
|
||||
let mut app = headless_app();
|
||||
// Bump the player to the unlock level.
|
||||
app.world_mut()
|
||||
.resource_mut::<ProgressResource>()
|
||||
.0
|
||||
.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
app.world_mut().resource_mut::<ProgressResource>().0.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
let _ = open_home(&mut app);
|
||||
|
||||
app.world_mut()
|
||||
@@ -1991,10 +2002,7 @@ mod tests {
|
||||
let mut app = headless_app();
|
||||
// Bump the player to the unlock level *before* opening the modal
|
||||
// so the Mode Launcher is in its unlocked state.
|
||||
app.world_mut()
|
||||
.resource_mut::<ProgressResource>()
|
||||
.0
|
||||
.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
app.world_mut().resource_mut::<ProgressResource>().0.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
let _ = open_home(&mut app);
|
||||
|
||||
app.world_mut()
|
||||
@@ -2026,10 +2034,7 @@ mod tests {
|
||||
let mut app = headless_app();
|
||||
// Modal is NOT open. Bump level so Zen would otherwise be allowed
|
||||
// — this isolates the modal-scope guard from the unlock check.
|
||||
app.world_mut()
|
||||
.resource_mut::<ProgressResource>()
|
||||
.0
|
||||
.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
app.world_mut().resource_mut::<ProgressResource>().0.level = CHALLENGE_UNLOCK_LEVEL;
|
||||
|
||||
// Drain any pre-existing events.
|
||||
app.world_mut()
|
||||
@@ -2071,19 +2076,25 @@ mod tests {
|
||||
zc.read(zen).next().is_none(),
|
||||
"Digit keys with no modal open must not fire StartZenRequestEvent"
|
||||
);
|
||||
let chal = app.world().resource::<Messages<StartChallengeRequestEvent>>();
|
||||
let chal = app
|
||||
.world()
|
||||
.resource::<Messages<StartChallengeRequestEvent>>();
|
||||
let mut cc = chal.get_cursor();
|
||||
assert!(
|
||||
cc.read(chal).next().is_none(),
|
||||
"Digit keys with no modal open must not fire StartChallengeRequestEvent"
|
||||
);
|
||||
let ta = app.world().resource::<Messages<StartTimeAttackRequestEvent>>();
|
||||
let ta = app
|
||||
.world()
|
||||
.resource::<Messages<StartTimeAttackRequestEvent>>();
|
||||
let mut tc = ta.get_cursor();
|
||||
assert!(
|
||||
tc.read(ta).next().is_none(),
|
||||
"Digit keys with no modal open must not fire StartTimeAttackRequestEvent"
|
||||
);
|
||||
let daily = app.world().resource::<Messages<StartDailyChallengeRequestEvent>>();
|
||||
let daily = app
|
||||
.world()
|
||||
.resource::<Messages<StartDailyChallengeRequestEvent>>();
|
||||
let mut dc = daily.get_cursor();
|
||||
assert!(
|
||||
dc.read(daily).next().is_none(),
|
||||
|
||||
Reference in New Issue
Block a user