feat(engine): add platform abstraction trait skeleton (closes #47)

Adds solitaire_engine::platform::{StorageBackend, PlatformTime} traits.
No implementations yet — native and WASM impls follow in #48.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
funman300
2026-05-27 16:58:42 -07:00
parent 3885b334ec
commit 86bafdd679
4 changed files with 43 additions and 0 deletions
+2
View File
@@ -31,6 +31,7 @@ pub mod onboarding_plugin;
pub mod pause_plugin; pub mod pause_plugin;
pub mod pending_hint; pub mod pending_hint;
pub mod play_by_seed_plugin; pub mod play_by_seed_plugin;
pub mod platform;
pub mod profile_plugin; pub mod profile_plugin;
pub mod radial_menu; pub mod radial_menu;
pub mod replay_overlay; pub mod replay_overlay;
@@ -111,6 +112,7 @@ pub use events::{
}; };
pub use difficulty_plugin::{DifficultyIndexResource, DifficultyPlugin}; pub use difficulty_plugin::{DifficultyIndexResource, DifficultyPlugin};
pub use play_by_seed_plugin::{PlayBySeedPlugin, PlayBySeedScreen}; pub use play_by_seed_plugin::{PlayBySeedPlugin, PlayBySeedScreen};
pub use platform::{PlatformTime, StorageBackend};
pub use game_plugin::{ pub use game_plugin::{
ConfirmNewGameScreen, GameMutation, GameOverScreen, GamePlugin, GameStatePath, RecordingReplay, ConfirmNewGameScreen, GameMutation, GameOverScreen, GamePlugin, GameStatePath, RecordingReplay,
ReplayPath, ReplayPath,
+11
View File
@@ -0,0 +1,11 @@
//! Platform abstraction layer.
//!
//! Traits defined here are implemented by:
//! - `solitaire_data` for native targets (filesystem, `std::time`)
//! - future WASM-specific impls for browser targets (`localStorage`, `js_sys::Date`)
pub mod storage;
pub mod time;
pub use storage::StorageBackend;
pub use time::PlatformTime;
+19
View File
@@ -0,0 +1,19 @@
use std::io;
/// Abstracts platform-specific key-value / file storage.
///
/// Native: backed by the filesystem (via `solitaire_data`).
/// WASM: backed by `localStorage` / `sessionStorage`.
pub trait StorageBackend: Send + Sync + 'static {
/// Read bytes for the given key. Returns `None` if the key does not exist.
fn read(&self, key: &str) -> io::Result<Option<Vec<u8>>>;
/// Write bytes for the given key atomically.
fn write(&self, key: &str, data: &[u8]) -> io::Result<()>;
/// Delete a key. No-op if the key does not exist.
fn delete(&self, key: &str) -> io::Result<()>;
/// List all known keys (for migration / debug purposes).
fn keys(&self) -> io::Result<Vec<String>>;
}
+11
View File
@@ -0,0 +1,11 @@
/// Abstracts platform-specific wall-clock time.
///
/// Native: backed by `std::time::SystemTime`.
/// WASM: backed by `js_sys::Date::now()`.
pub trait PlatformTime: Send + Sync + 'static {
/// Returns the current Unix timestamp in seconds.
fn now_unix_secs(&self) -> u64;
/// Returns the current Unix timestamp in milliseconds.
fn now_unix_millis(&self) -> u128;
}