feat(engine): per-platform user-theme directory (Card theme phase 5)
Implements Phase 5 of CARD_PLAN.md. Phase 3 (asset sources) and
Phase 7 (zip importer) both depend on this so it goes first.
solitaire_engine/src/assets/user_dir.rs
user_theme_dir() -> PathBuf
Desktop (Linux/macOS/Windows): joins dirs::data_dir() with
"solitaire_quest/themes" — same parent as the rest of the
project's per-user files (settings.json, stats.json, etc.)
Mobile (Android/iOS): reads a process-wide OnceLock populated
by set_user_theme_dir() at entry-point bootstrap. Panics with a
targeted message if the override is missing — there is no
platform default we can guess that won't be wrong inside iOS
sandboxing or the Android storage model.
set_user_theme_dir(PathBuf) -> Result<(), PathBuf>
First-write-wins. Mobile entry points call this before App::run().
The plan suggested the `directories` crate; reused the existing `dirs`
workspace dep instead to keep the dependency surface minimal — both
crates share an author and the platform behaviour we need is identical.
3 new tests covering pure path composition (desktop nesting + empty
root) and a desktop-target-gated check that the detected data dir is
absolute. The OnceLock override is intentionally not unit-tested
because asserting its semantics would pollute global state for any
sibling test that calls `user_theme_dir()`.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
//! Asset-loading infrastructure for runtime SVG rasterisation.
|
||||
//! Asset-loading infrastructure for runtime SVG rasterisation and the
|
||||
//! per-platform user-themes directory.
|
||||
//!
|
||||
//! See `CARD_PLAN.md` for the multi-phase implementation plan. This module
|
||||
//! is the entry point for Phase 1 (the SVG → `Image` asset loader). Later
|
||||
//! phases extend it with custom asset sources for embedded and user
|
||||
//! themes, and a `CardTheme` asset that aggregates 53 image handles.
|
||||
//! See `CARD_PLAN.md` for the full multi-phase implementation plan.
|
||||
//! This module is the entry point for Phases 1 (SVG → `Image`) and 5
|
||||
//! (user-themes directory). Phase 3 will extend it further with custom
|
||||
//! `AssetSource` implementations for `embedded://` and `themes://`.
|
||||
|
||||
pub mod svg_loader;
|
||||
pub mod user_dir;
|
||||
|
||||
pub use svg_loader::{rasterize_svg, SvgLoader, SvgLoaderError, SvgLoaderSettings};
|
||||
pub use user_dir::{set_user_theme_dir, user_theme_dir};
|
||||
|
||||
Reference in New Issue
Block a user