Skip to main content

cuqueclicker_lib/platform/
mod.rs

1//! Platform abstraction layer.
2//!
3//! Two impls are kept in lockstep: `native` (filesystem + std::fs locking)
4//! and `web` (localStorage + no-op locking, added when the wasm port lands).
5//! Both expose **the same set of types and methods** — code outside this
6//! module doesn't know which one it's compiled against. Drift is caught at
7//! compile time because both impls have to satisfy the same callers.
8//!
9//! See `tracking issue #13` for the discovery rationale and gotchas.
10
11#[cfg(not(target_arch = "wasm32"))]
12mod native;
13#[cfg(not(target_arch = "wasm32"))]
14pub use native::{CAPABILITIES, InstanceLock, Persistence};
15
16#[cfg(target_arch = "wasm32")]
17mod web;
18#[cfg(target_arch = "wasm32")]
19pub use web::{CAPABILITIES, InstanceLock, Persistence};
20
21/// Static feature-flag struct describing what the host environment
22/// supports. Each platform impl exposes a `CAPABILITIES` constant of
23/// this type. UI / input code reads it to gate affordances that have
24/// no meaning on a given platform — e.g. the `[q] quit` help-bar hint
25/// is hidden in the browser, where the wasm bundle has no authority
26/// to close the tab.
27///
28/// Add new fields here when a feature genuinely diverges between
29/// surfaces (and add the matching value to *both* `native::CAPABILITIES`
30/// and `web::CAPABILITIES`); don't reach for `cfg(target_arch)` deeper
31/// in the tree if a capability flag fits the seam.
32#[derive(Clone, Copy, Debug)]
33pub struct Capabilities {
34    /// Whether the player can quit the running instance from inside
35    /// the game. True on native (terminal close = process exit).
36    /// False on web — the wasm has no authority over the tab; the
37    /// player closes the page or navigates away themselves.
38    pub can_quit: bool,
39}