feat(engine): card-art thumbnails in the theme picker
Settings → Cosmetic's theme picker showed only the theme name. Now each chip carries a small Ace-of-Spades + back preview pair so the player can see what each theme looks like before switching. A new ThemeThumbnailCache resource keys per-theme by id and stores two Handle<Image>s (ace + back) rasterised at thumbnail resolution via the existing rasterize_svg path. Generation runs once per theme registration in theme_plugin; subsequent picker re-spawns just look up the cached handles. Themes that lack one of the preview SVGs (broken user theme) get a Handle::default() placeholder rather than crashing — the placeholder renders as a transparent rectangle the same size as the missing thumbnail. The picker chip spawn loop in settings_plugin reads the cache and renders the pair as two child sprites above the chip text. The selected-theme chip's existing STATE_SUCCESS tint sits behind the thumbnails; contrast stays readable. Asset-source plumbing in assets/sources.rs and assets/mod.rs picks up the new bytes-loading helper that the thumbnail generator uses for embedded:// theme assets at startup time (before AssetServer is fully initialised). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -194,6 +194,25 @@ impl Plugin for AssetSourcesPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the embedded SVG bytes for a single default-theme file
|
||||
/// (e.g. `"back.svg"` or `"spades_ace.svg"`), or `None` when the
|
||||
/// filename is not bundled.
|
||||
///
|
||||
/// The thumbnail generator in
|
||||
/// [`crate::theme::ThemeThumbnailCache`] uses this to rasterise
|
||||
/// preview-sized art for the picker UI without going through Bevy's
|
||||
/// async asset graph. Lookup is by the filename only — the
|
||||
/// `solitaire_engine/assets/themes/default/` prefix is stripped before
|
||||
/// comparison so callers don't need to know where the embedded files
|
||||
/// live in the binary.
|
||||
pub fn default_theme_svg_bytes(filename: &str) -> Option<&'static [u8]> {
|
||||
let suffix = format!("/{filename}");
|
||||
DEFAULT_THEME_SVGS
|
||||
.iter()
|
||||
.find(|(path, _)| path.ends_with(&suffix))
|
||||
.map(|(_, bytes)| *bytes)
|
||||
}
|
||||
|
||||
/// Pushes every bundled default-theme file into the
|
||||
/// [`EmbeddedAssetRegistry`] under its stable URL. Keeping this in a
|
||||
/// free function (and not inside the `Plugin::build` body) means the
|
||||
@@ -291,6 +310,29 @@ mod tests {
|
||||
assert_eq!(faces.len(), 52);
|
||||
}
|
||||
|
||||
/// `default_theme_svg_bytes` resolves the canonical preview pair
|
||||
/// the thumbnail cache rasterises: `back.svg` and `spades_ace.svg`.
|
||||
/// Both must exist in the embedded table or the picker's preview
|
||||
/// thumbnails would silently fall back to placeholders even for the
|
||||
/// always-present default theme.
|
||||
#[test]
|
||||
fn default_theme_svg_bytes_finds_back_and_ace_of_spades() {
|
||||
assert!(
|
||||
default_theme_svg_bytes("back.svg").is_some(),
|
||||
"default theme must bundle a back.svg"
|
||||
);
|
||||
assert!(
|
||||
default_theme_svg_bytes("spades_ace.svg").is_some(),
|
||||
"default theme must bundle a spades_ace.svg"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_theme_svg_bytes_returns_none_for_unknown_file() {
|
||||
assert!(default_theme_svg_bytes("nope.svg").is_none());
|
||||
assert!(default_theme_svg_bytes("").is_none());
|
||||
}
|
||||
|
||||
/// Belt-and-braces: if anyone edits `DEFAULT_THEME_MANIFEST_PATH`
|
||||
/// without updating `DEFAULT_THEME_MANIFEST_URL` (or vice versa)
|
||||
/// the asset would register at one path and be loaded from
|
||||
|
||||
Reference in New Issue
Block a user