Compare commits
147 Commits
v0.20.0
...
08f74d1e25
| Author | SHA1 | Date | |
|---|---|---|---|
| 08f74d1e25 | |||
| 6e6f3ef1ff | |||
| 549a817bb1 | |||
| 613bbf8799 | |||
| b129664344 | |||
| 7d7c83ab28 | |||
| bd388fef26 | |||
| 272d31f851 | |||
| 6ce55646d8 | |||
| 432061c3ec | |||
| 22303c62ff | |||
| b1731fe68a | |||
| 2b01f741b4 | |||
| 3110702c74 | |||
| 33fb9627a8 | |||
| 4398403418 | |||
| 002d96f2c8 | |||
| cc161cc37f | |||
| 8a3e30bd16 | |||
| 2a206b994c | |||
| ae7c6c97f1 | |||
| 016fb7214d | |||
| 948864e653 | |||
| 76a754d8e5 | |||
| 9fb59c7d47 | |||
| d714a11cfb | |||
| e107f5e218 | |||
| 463b7465ed | |||
| 92a5ebb15e | |||
| 89a21c0587 | |||
| 304cb050a7 | |||
| fcc7337c97 | |||
| 16ce2b88d2 | |||
| b9aa2620b8 | |||
| 47f02a60ae | |||
| a5c3188686 | |||
| 6a289b7b50 | |||
| bee712c5ab | |||
| 0db5e9dac4 | |||
| 681a54d9bb | |||
| 7894559ca7 | |||
| ab803c07af | |||
| e43b329fc1 | |||
| 7c07f71f02 | |||
| c1329bbb21 | |||
| 4303ef3f5b | |||
| 4df962ee07 | |||
| f281425b45 | |||
| 2c822ba2d7 | |||
| 7ddf2733c9 | |||
| 585570559c | |||
| 45436d0eda | |||
| 2062bd06f3 | |||
| 0cb15872b1 | |||
| 395a322adc | |||
| 5199a5e499 | |||
| 16242e6d77 | |||
| 202a64db45 | |||
| c0415eb0ee | |||
| a449f60bc5 | |||
| ad5f613277 | |||
| c50eaf81f7 | |||
| b44d2777ec | |||
| 52407e7256 | |||
| da3e5423dc | |||
| a1864271de | |||
| f63db769ae | |||
| 4437a1aaf9 | |||
| e7345aed6c | |||
| 140251beae | |||
| d6f32d3154 | |||
| 8fdc41f36f | |||
| 2e25476d0a | |||
| d3cb1a51d4 | |||
| c8358f4275 | |||
| a2432dfe7a | |||
| 511550232c | |||
| e5c4f51a6e | |||
| 23902cdc44 | |||
| 3cc8eacafa | |||
| 90e24d9711 | |||
| decbe0bbd9 | |||
| 1873b3f9be | |||
| d11d97e677 | |||
| d322abf67b | |||
| c9e4c0b4cd | |||
| fe68861e10 | |||
| c33b39cf11 | |||
| 23ff62c397 | |||
| 0b2ffca016 | |||
| fbe48acef6 | |||
| cd79877933 | |||
| 52befa6199 | |||
| e63046700c | |||
| ab857bbb6e | |||
| 886e0cf8a1 | |||
| 3d92a91e3b | |||
| 9113cdb483 | |||
| c153363626 | |||
| 93b67f1d0b | |||
| 279e23d0af | |||
| 12fba2157a | |||
| f23df3b805 | |||
| 68d50b5021 | |||
| ec804d54c6 | |||
| d87761d451 | |||
| 2fb2d638bf | |||
| c9af1ead22 | |||
| ed152e2d8f | |||
| 279a834f9d | |||
| daa655a0af | |||
| 4d48cad4e3 | |||
| dd970215cc | |||
| ddb65403c2 | |||
| 62b61cc786 | |||
| 31139ae455 | |||
| 07e035771c | |||
| c5787c6953 | |||
| 716a025352 | |||
| 3eb3a26789 | |||
| 0c1cc40266 | |||
| 04f9bf9be3 | |||
| a292a7ead0 | |||
| d109c32b75 | |||
| dd101b3d54 | |||
| af414b6aed | |||
| ae84dc1504 | |||
| 8719f77ec2 | |||
| a14200ac2f | |||
| e8bf9d79da | |||
| 48b28d29f8 | |||
| babe5cc9c8 | |||
| 3a4bb63a6f | |||
| 56233687b0 | |||
| 73ac67d76b | |||
| a27cf5a020 | |||
| 29136d815d | |||
| ef54cdeb65 | |||
| e080b49914 | |||
| 54005d5494 | |||
| 44f5972edd | |||
| 13ae16051d | |||
| a65e5b8c7b | |||
| 6204db8bb1 | |||
| c84d9f445c | |||
| cacb19c03f | |||
| 39b84965b6 |
@@ -1,88 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
pull_request:
|
|
||||||
branches: [master]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
RUSTFLAGS: "-D warnings"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Test & Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
with:
|
|
||||||
components: clippy
|
|
||||||
|
|
||||||
- name: Install Linux audio/display dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y --no-install-recommends \
|
|
||||||
libasound2-dev \
|
|
||||||
libudev-dev \
|
|
||||||
libwayland-dev \
|
|
||||||
libxkbcommon-dev
|
|
||||||
|
|
||||||
- name: Cache cargo registry and build artifacts
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
target
|
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cargo-
|
|
||||||
|
|
||||||
- name: Clippy (all crates, zero warnings)
|
|
||||||
run: cargo clippy --workspace -- -D warnings
|
|
||||||
|
|
||||||
- name: Test (headless crates only — no display required)
|
|
||||||
run: |
|
|
||||||
cargo test -p solitaire_core
|
|
||||||
cargo test -p solitaire_sync
|
|
||||||
cargo test -p solitaire_data
|
|
||||||
cargo test -p solitaire_server
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Release Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: test
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Install Linux audio/display dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y --no-install-recommends \
|
|
||||||
libasound2-dev \
|
|
||||||
libudev-dev \
|
|
||||||
libwayland-dev \
|
|
||||||
libxkbcommon-dev
|
|
||||||
|
|
||||||
- name: Cache cargo registry and build artifacts
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/registry
|
|
||||||
~/.cargo/git
|
|
||||||
target
|
|
||||||
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cargo-release-
|
|
||||||
|
|
||||||
- name: Build release binaries
|
|
||||||
run: cargo build --workspace --release
|
|
||||||
@@ -7,3 +7,11 @@
|
|||||||
*.tmp
|
*.tmp
|
||||||
data/
|
data/
|
||||||
.claude/
|
.claude/
|
||||||
|
|
||||||
|
# IDE project files
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Android signing keystores — never commit
|
||||||
|
*.jks
|
||||||
|
*.jks.bak
|
||||||
|
*.keystore
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "DELETE FROM refresh_tokens WHERE jti = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "168e205e3eb832b78d085b48281a1bae74d5a0e64c4c793c18a6400605bacf76"
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "SELECT jti FROM refresh_tokens WHERE jti = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "jti",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
true
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "893c45c27854ba15ea611e8254ef980ced21dc64e6ca95fde56af513f86ffa46"
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "INSERT INTO refresh_tokens (jti, user_id, expires_at) VALUES (?, ?, ?)",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 3
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "c9ee5c64ca547f0c730379919a642bd649cbf81fc1804159101a70efabf08b33"
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "DELETE FROM refresh_tokens WHERE expires_at < ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "ef7af925a8715c329dcafca5257c691e6bca31755eb5f54be47114f21fc04c8c"
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
# Solitaire Quest — Architecture Document
|
# Solitaire Quest — Architecture Document
|
||||||
|
|
||||||
> **Version:** 1.1
|
> **Version:** 1.3
|
||||||
> **Language:** Rust (Edition 2024)
|
> **Language:** Rust (Edition 2024)
|
||||||
> **Engine:** Bevy (latest stable)
|
> **Engine:** Bevy (latest stable)
|
||||||
> **Last Updated:** 2026-04-29
|
> **Last Updated:** 2026-05-12
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ solitaire_quest/
|
|||||||
├── solitaire_data/ # Persistence, sync client, settings
|
├── solitaire_data/ # Persistence, sync client, settings
|
||||||
├── solitaire_engine/ # Bevy ECS systems, components, plugins
|
├── solitaire_engine/ # Bevy ECS systems, components, plugins
|
||||||
├── solitaire_server/ # Self-hosted sync server (Axum + SQLite)
|
├── solitaire_server/ # Self-hosted sync server (Axum + SQLite)
|
||||||
|
├── solitaire_wasm/ # WebAssembly bindings — browser-side replay player
|
||||||
└── solitaire_app/ # Main binary entry point
|
└── solitaire_app/ # Main binary entry point
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -160,6 +161,20 @@ Owns:
|
|||||||
- Daily challenge seed generation
|
- Daily challenge seed generation
|
||||||
- Leaderboard management
|
- Leaderboard management
|
||||||
|
|
||||||
|
### `solitaire_wasm`
|
||||||
|
**Dependencies:** `solitaire_core`, `serde`, `serde_json`, `chrono`, `wasm-bindgen`, `serde-wasm-bindgen`.
|
||||||
|
|
||||||
|
WebAssembly bindings for browser-side replay playback. Compiled to `cdylib` via `wasm-pack build`; the output lives in `solitaire_server/web/pkg/` and is served statically by the server.
|
||||||
|
|
||||||
|
Intentionally **does not** depend on `solitaire_data` (which pulls in `dirs`, `keyring`, `reqwest`, and other non-WASM crates). Instead it defines a minimal `Replay` mirror with the same serde shape as `solitaire_data::Replay` — the JSON wire format is the compatibility contract.
|
||||||
|
|
||||||
|
Owns:
|
||||||
|
- `ReplayPlayer` — WASM-exported state machine; steps through a replay's `Vec<ReplayMove>` against a live `GameState`
|
||||||
|
- `StateSnapshot` — JS-facing pile snapshot returned by each `step()` call
|
||||||
|
- `ReplayMove` / `Replay` mirrors — same serde shape as `solitaire_data` v2 equivalents
|
||||||
|
|
||||||
|
Because `ReplayPlayer` uses the same `solitaire_core::GameState` as the desktop client, the two implementations cannot drift: the same seed + move list produces identical pile state at every step on both platforms.
|
||||||
|
|
||||||
### `solitaire_app`
|
### `solitaire_app`
|
||||||
**Dependencies:** `bevy`, `solitaire_engine`.
|
**Dependencies:** `bevy`, `solitaire_engine`.
|
||||||
|
|
||||||
@@ -261,6 +276,8 @@ The "Shortcut" column lists optional keyboard accelerators. Every action in this
|
|||||||
| `HomePlugin` | M | Main-menu overlay with keyboard shortcut reference |
|
| `HomePlugin` | M | Main-menu overlay with keyboard shortcut reference |
|
||||||
| `ProfilePlugin` | P | Player profile overlay: level, XP, achievements, sync status |
|
| `ProfilePlugin` | P | Player profile overlay: level, XP, achievements, sync status |
|
||||||
| `SettingsPlugin` | O | Settings panel: audio, draw mode, theme, sync, cosmetics |
|
| `SettingsPlugin` | O | Settings panel: audio, draw mode, theme, sync, cosmetics |
|
||||||
|
| `ThemePlugin` | — | Owns `ActiveTheme` resource; registers the `CardTheme` SVG asset loader; rasterises themes once per (theme, target size) at load time and caches the resulting `Image`; handles the embedded default theme and user themes from `user_theme_dir()` |
|
||||||
|
| `SyncSetupPlugin` | — | Sync setup modal (URL / username / password fields, "Log In" / "Register" buttons); account deletion confirm modal; re-auth trigger when `SyncError::Auth` is returned by a pull |
|
||||||
| `LeaderboardPlugin` | L | Leaderboard overlay |
|
| `LeaderboardPlugin` | L | Leaderboard overlay |
|
||||||
| `HelpPlugin` | H | Help / controls overlay |
|
| `HelpPlugin` | H | Help / controls overlay |
|
||||||
| `PausePlugin` | Esc | Pause and resume |
|
| `PausePlugin` | Esc | Pause and resume |
|
||||||
@@ -365,10 +382,22 @@ All sync backends implement a single trait in `solitaire_data`. The `SyncPlugin`
|
|||||||
```rust
|
```rust
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait SyncProvider: Send + Sync {
|
pub trait SyncProvider: Send + Sync {
|
||||||
|
// Required — must be implemented by every backend:
|
||||||
async fn pull(&self) -> Result<SyncPayload, SyncError>;
|
async fn pull(&self) -> Result<SyncPayload, SyncError>;
|
||||||
async fn push(&self, payload: &SyncPayload) -> Result<SyncResponse, SyncError>;
|
async fn push(&self, payload: &SyncPayload) -> Result<SyncResponse, SyncError>;
|
||||||
fn backend_name(&self) -> &'static str;
|
fn backend_name(&self) -> &'static str;
|
||||||
fn is_authenticated(&self) -> bool;
|
fn is_authenticated(&self) -> bool;
|
||||||
|
|
||||||
|
// Optional — all have default no-op / empty implementations:
|
||||||
|
async fn mirror_achievement(&self, _id: &str) -> Result<(), SyncError>;
|
||||||
|
async fn fetch_leaderboard(&self) -> Result<Vec<LeaderboardEntry>, SyncError>;
|
||||||
|
async fn fetch_daily_challenge(&self) -> Result<Option<ChallengeGoal>, SyncError>;
|
||||||
|
async fn opt_in_leaderboard(&self, _display_name: &str) -> Result<(), SyncError>;
|
||||||
|
async fn opt_out_leaderboard(&self) -> Result<(), SyncError>;
|
||||||
|
async fn delete_account(&self) -> Result<(), SyncError>;
|
||||||
|
// Returns the shareable web URL on success; defaults to Err(UnsupportedPlatform)
|
||||||
|
// so LocalOnlyProvider silently no-ops the push-on-win path.
|
||||||
|
async fn push_replay(&self, _replay: &Replay) -> Result<String, SyncError>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -454,6 +483,24 @@ CREATE TABLE leaderboard (
|
|||||||
recorded_at TEXT NOT NULL,
|
recorded_at TEXT NOT NULL,
|
||||||
PRIMARY KEY (user_id)
|
PRIMARY KEY (user_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- migrations/002_replays.sql
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS replays (
|
||||||
|
id TEXT PRIMARY KEY, -- UUID v4 minted server-side
|
||||||
|
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
seed INTEGER NOT NULL,
|
||||||
|
draw_mode TEXT NOT NULL, -- "DrawOne" | "DrawThree"
|
||||||
|
mode TEXT NOT NULL, -- "Classic" | "Zen" | "Challenge" | "TimeAttack"
|
||||||
|
time_seconds INTEGER NOT NULL,
|
||||||
|
final_score INTEGER NOT NULL,
|
||||||
|
recorded_at TEXT NOT NULL, -- replay-side date (YYYY-MM-DD)
|
||||||
|
received_at TEXT NOT NULL, -- server insert timestamp (ISO 8601)
|
||||||
|
replay_json TEXT NOT NULL -- full Replay serialisation
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS replays_received_at_idx ON replays(received_at DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS replays_user_id_idx ON replays(user_id);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Request Lifecycle
|
### Request Lifecycle
|
||||||
@@ -584,7 +631,20 @@ pub struct Settings {
|
|||||||
pub animation_speed: AnimSpeed,
|
pub animation_speed: AnimSpeed,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
pub sync_backend: SyncBackend, // Local | SolitaireServer
|
pub sync_backend: SyncBackend, // Local | SolitaireServer
|
||||||
|
pub selected_card_back: usize, // index into PlayerProgress::unlocked_card_backs
|
||||||
|
pub selected_background: usize, // index into PlayerProgress::unlocked_backgrounds
|
||||||
pub first_run_complete: bool,
|
pub first_run_complete: bool,
|
||||||
|
pub color_blind_mode: bool, // blue tint on red suits
|
||||||
|
pub high_contrast_mode: bool, // boosted luminance for low-vision users
|
||||||
|
pub reduce_motion_mode: bool, // WCAG reduce-motion — snaps instead of slides
|
||||||
|
pub window_geometry: Option<WindowGeometry>, // persisted size + position; None on first run
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WindowGeometry {
|
||||||
|
pub width: u32, // logical pixels
|
||||||
|
pub height: u32,
|
||||||
|
pub x: i32, // physical pixels, top-left corner
|
||||||
|
pub y: i32,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -600,7 +660,7 @@ All endpoints are under the base URL configured by the user (e.g., `https://soli
|
|||||||
|---|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
| POST | `/api/auth/register` | None | `{username, password}` | `{access_token, refresh_token}` |
|
| POST | `/api/auth/register` | None | `{username, password}` | `{access_token, refresh_token}` |
|
||||||
| POST | `/api/auth/login` | None | `{username, password}` | `{access_token, refresh_token}` |
|
| POST | `/api/auth/login` | None | `{username, password}` | `{access_token, refresh_token}` |
|
||||||
| POST | `/api/auth/refresh` | None | `{refresh_token}` | `{access_token}` |
|
| POST | `/api/auth/refresh` | None | `{refresh_token}` | `{access_token, refresh_token}` (rotated) |
|
||||||
|
|
||||||
### Sync
|
### Sync
|
||||||
|
|
||||||
@@ -617,6 +677,21 @@ All endpoints are under the base URL configured by the user (e.g., `https://soli
|
|||||||
| GET | `/api/leaderboard` | Bearer JWT | — | `Vec<LeaderboardEntry>` |
|
| GET | `/api/leaderboard` | Bearer JWT | — | `Vec<LeaderboardEntry>` |
|
||||||
| POST | `/api/leaderboard/opt-in` | Bearer JWT | — | `{ok: true}` |
|
| POST | `/api/leaderboard/opt-in` | Bearer JWT | — | `{ok: true}` |
|
||||||
|
|
||||||
|
### Replays
|
||||||
|
|
||||||
|
| Method | Path | Auth | Body | Response |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| POST | `/api/replays` | Bearer JWT | Replay JSON | `{id, share_url}` |
|
||||||
|
| GET | `/api/replays/recent` | None | — (`?limit=N`) | `Vec<ReplaySummary>` |
|
||||||
|
| GET | `/api/replays/:id` | None | — | Full Replay JSON |
|
||||||
|
|
||||||
|
### Web Replay Player
|
||||||
|
|
||||||
|
| Method | Path | Auth | Notes |
|
||||||
|
|---|---|---|---|
|
||||||
|
| GET | `/replays/:id` | None | Serves `web/index.html`; JS fetches `/api/replays/:id` and steps through via the `solitaire_wasm` WASM module |
|
||||||
|
| GET | `/web/*` | None | Static assets served via `ServeDir` from `solitaire_server/web/` (includes `web/pkg/` with wasm-bindgen output) |
|
||||||
|
|
||||||
### Account Management
|
### Account Management
|
||||||
|
|
||||||
| Method | Path | Auth | Body | Response |
|
| Method | Path | Auth | Body | Response |
|
||||||
@@ -945,6 +1020,7 @@ Migrations run automatically on startup via `sqlx::migrate!()`.
|
|||||||
| Password storage | bcrypt, cost factor 12 — never stored in plaintext |
|
| Password storage | bcrypt, cost factor 12 — never stored in plaintext |
|
||||||
| Token security | JWTs signed with HS256, stored in OS keychain via `keyring` crate |
|
| Token security | JWTs signed with HS256, stored in OS keychain via `keyring` crate |
|
||||||
| Token expiry | Access: 24h, Refresh: 30d |
|
| Token expiry | Access: 24h, Refresh: 30d |
|
||||||
|
| Refresh token rotation | Each `/api/auth/refresh` call consumes the incoming refresh token (deletes its jti row) and issues a new one. Reuse of a consumed token returns 401. Expired rows are pruned inline. |
|
||||||
| Brute force | `tower-governor`: 10 req/min per IP on `/api/auth/*` |
|
| Brute force | `tower-governor`: 10 req/min per IP on `/api/auth/*` |
|
||||||
| Payload abuse | 1MB max request body, enforced by Axum middleware |
|
| Payload abuse | 1MB max request body, enforced by Axum middleware |
|
||||||
| Data deletion | `DELETE /api/account` removes all rows via `ON DELETE CASCADE` |
|
| Data deletion | `DELETE /api/account` removes all rows via `ON DELETE CASCADE` |
|
||||||
|
|||||||
@@ -6957,6 +6957,8 @@ dependencies = [
|
|||||||
"keyring",
|
"keyring",
|
||||||
"solitaire_data",
|
"solitaire_data",
|
||||||
"solitaire_engine",
|
"solitaire_engine",
|
||||||
|
"tiny-skia 0.12.0",
|
||||||
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6965,6 +6967,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"png 0.17.16",
|
"png 0.17.16",
|
||||||
|
"solitaire_core",
|
||||||
|
"solitaire_data",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6982,8 +6986,10 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
|
"bevy",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"jni 0.21.1",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"keyring-core",
|
"keyring-core",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
@@ -7007,6 +7013,7 @@ dependencies = [
|
|||||||
"bevy",
|
"bevy",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"jni 0.21.1",
|
||||||
"kira",
|
"kira",
|
||||||
"resvg",
|
"resvg",
|
||||||
"ron",
|
"ron",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ keyring = "4"
|
|||||||
keyring-core = "1"
|
keyring-core = "1"
|
||||||
reqwest = { version = "0.13", features = ["json", "rustls", "rustls-native-certs"], default-features = false }
|
reqwest = { version = "0.13", features = ["json", "rustls", "rustls-native-certs"], default-features = false }
|
||||||
arboard = { version = "3", default-features = false }
|
arboard = { version = "3", default-features = false }
|
||||||
|
jni = { version = "0.21", default-features = false }
|
||||||
|
|
||||||
solitaire_core = { path = "solitaire_core" }
|
solitaire_core = { path = "solitaire_core" }
|
||||||
solitaire_sync = { path = "solitaire_sync" }
|
solitaire_sync = { path = "solitaire_sync" }
|
||||||
|
|||||||
@@ -1,282 +1,158 @@
|
|||||||
# Solitaire Quest — Session Handoff
|
# Solitaire Quest — Session Handoff
|
||||||
|
|
||||||
**Last updated:** 2026-05-07 — v0.20.0 cut. Two through-lines closed
|
**Last updated:** 2026-05-12 — Sync rate limiting + mirror_achievement removal + theme import scan shipped (`6e6f3ef`). HEAD locally: `6e6f3ef`. Push pending.
|
||||||
in this cycle: a full **Terminal visual-identity port** (token system
|
|
||||||
in `ui_theme` plus downstream chrome migrations across modal scaffold,
|
|
||||||
gameplay-feedback, toasts, and the table / card / splash surfaces)
|
|
||||||
and the **Android persistence shim** that closes the
|
|
||||||
`dirs::data_dir() = None` pitfall flagged in CLAUDE.md §10. The
|
|
||||||
Android *build* target landed earlier in the cycle (`fb8b2ac`); this
|
|
||||||
session paid down the persistence half so a real APK can survive a
|
|
||||||
cold start. The 24 Stitch-rendered mockups are now in-tree under
|
|
||||||
`docs/ui-mockups/`; future plugin work diffs against the matching
|
|
||||||
mockup before touching pixels.
|
|
||||||
|
|
||||||
## Status at pause
|
Phase 8 closes the self-hosted-server connection arc end-to-end: login/register
|
||||||
|
modal, re-auth on token expiry, account deletion flow, server deployment
|
||||||
|
artifacts (Dockerfile + docker-compose), replay upload on win, web replay
|
||||||
|
player (WASM + HTML/CSS/JS served by the server), leaderboard opt-in/out,
|
||||||
|
and full server integration tests.
|
||||||
|
|
||||||
- **HEAD on origin:** the v0.20.0 docs commit (the one that lands
|
---
|
||||||
this file + CHANGELOG cut). Tag not yet pushed; cut whenever
|
|
||||||
feels right.
|
|
||||||
- **Working tree:** clean apart from the still-untracked `artwork/`
|
|
||||||
directory (intentional — the card PNGs there are mid-flight for
|
|
||||||
the Terminal aesthetic and committing now would freeze a
|
|
||||||
transitional state).
|
|
||||||
- **Build:** `cargo clippy --workspace --all-targets -- -D warnings`
|
|
||||||
clean.
|
|
||||||
- **Tests:** **1176 passing / 0 failing** across the workspace.
|
|
||||||
Six new tests this cycle: four `ui_theme` invariant guards
|
|
||||||
(type / spacing / z-index scales + `scaled_duration`), one
|
|
||||||
toast-variant-border-mapping pair, and four palette-tracking
|
|
||||||
guards on `MARKER_VALID` / `HINT_PILE_HIGHLIGHT_COLOUR` /
|
|
||||||
`RIGHT_CLICK_HIGHLIGHT_COLOUR` / toast-border distinctness. No
|
|
||||||
known flakes.
|
|
||||||
- **Tags on origin:** `v0.9.0` through `v0.19.0`. v0.20.0 not yet
|
|
||||||
tagged.
|
|
||||||
|
|
||||||
## What shipped in v0.20.0
|
## Current state
|
||||||
|
|
||||||
### Terminal visual-identity port
|
- **HEAD locally:** `6e6f3ef` (feat: sync rate limiting).
|
||||||
|
- **HEAD on origin:** `b129664` (pushed — 4 commits ahead).
|
||||||
|
- **Working tree:** `SESSION_HANDOFF.md` modified, uncommitted.
|
||||||
|
- **Build:** `cargo clippy --workspace --all-targets -- -D warnings` clean.
|
||||||
|
- **Tests:** **1300+ passing / 0 failing** across the workspace.
|
||||||
|
- **Tags on origin:** `v0.9.0` through `v0.22.0`.
|
||||||
|
|
||||||
Top-down stack — every commit downstream of the token system
|
---
|
||||||
reads from it, so swapping the palette is now a one-file edit:
|
|
||||||
|
|
||||||
- **`ui_theme` token system** (`0d477ac`). base16-eighties
|
## What shipped in Phase 8 (432061c – bd388fe)
|
||||||
palette, 5-rung type scale, 7-rung 4-multiple spacing scale,
|
|
||||||
3-step radius, 14-rung z-index hierarchy, full motion budget,
|
|
||||||
4 invariant-pinning unit tests. Card-shadow alphas pinned to 0
|
|
||||||
(Terminal achieves depth via 1px borders + tonal layering).
|
|
||||||
- **Modal scaffold already on tokens** — `ui_modal` was ported
|
|
||||||
in the same commit's wake; three stale "loud yellow" /
|
|
||||||
"magenta secondary" doc comments fixed.
|
|
||||||
- **Gameplay feedback → semantic state tokens** (`ceec4fc`).
|
|
||||||
Selection / valid-drop tints route through `ACCENT_PRIMARY` /
|
|
||||||
`STATE_WARNING` / `STATE_SUCCESS`.
|
|
||||||
- **Toasts** (`a137607`). New `ToastVariant` enum
|
|
||||||
(Info / Warning / Error / Celebration); opaque `BG_ELEVATED`
|
|
||||||
+ 1px accent border + bottom-anchor. All ten call sites pass
|
|
||||||
their semantic variant.
|
|
||||||
- **`table_plugin` chrome** (`651f406`).
|
|
||||||
`PILE_MARKER_DEFAULT_COLOUR` promoted; `cursor_plugin` imports
|
|
||||||
it, replacing a "kept in sync" doc comment with a compile-
|
|
||||||
enforced invariant. `HINT_PILE_HIGHLIGHT_COLOUR` →
|
|
||||||
`STATE_WARNING`.
|
|
||||||
- **`card_plugin` chrome** (`d752870`). Drag-elevation shadow
|
|
||||||
routes through `CARD_SHADOW_*` tokens. `RIGHT_CLICK_HIGHLIGHT_COLOUR`
|
|
||||||
→ `STATE_SUCCESS`. Stock recycle "↺" text → `TEXT_PRIMARY @ 0.7α`.
|
|
||||||
Card-face / suit / card-back palette intentionally NOT migrated
|
|
||||||
(artwork dependency — see open-list item below).
|
|
||||||
- **Splash cursor** (`cdcadda`). The signature `▌` cyan glyph
|
|
||||||
(96 px) added above the wordmark, matching the spec.
|
|
||||||
- **Hint-source / dest pairing** (`9891ae4`). `input_plugin`'s
|
|
||||||
source-card tint now matches the destination pile's
|
|
||||||
`STATE_WARNING`.
|
|
||||||
- **Design system + 24-mockup library** (`fa7f98a`).
|
|
||||||
`docs/ui-mockups/design-system.md` + 24 Stitch mockups (HTML +
|
|
||||||
PNG) covering every screen plus 9 missing-plugin surfaces.
|
|
||||||
- **`card_shadow_params` test aligned** (`1d1543e`). Drag-vs-
|
|
||||||
idle shadow assertion loosened to `>=` to accept the Terminal
|
|
||||||
"no shadow" intent without losing the regression-guard.
|
|
||||||
|
|
||||||
### Android persistence
|
| Commit | Summary |
|
||||||
|
|--------|---------|
|
||||||
|
| `432061c` | Sync setup modal (login/register/connect/disconnect) |
|
||||||
|
| `6ce5564` | Re-auth on expired session + server deployment artifacts |
|
||||||
|
| `272d31f` | Account deletion flow + `handle_sync_buttons` refactor |
|
||||||
|
| `bd388fe` | CHANGELOG v0.23.0 documentation |
|
||||||
|
|
||||||
- **`solitaire_data::data_dir` shim** (`4b51e50`). New
|
Also shipped (pre-Phase 8 but post-v0.22.0, already in CHANGELOG):
|
||||||
`solitaire_data::platform::data_dir()` falls through to
|
- `solitaire_wasm` crate: WASM ReplayPlayer bindings for browser-side replay playback
|
||||||
`dirs::data_dir()` on desktop and returns the per-app sandbox
|
- Server replay API: `POST /api/replays`, `GET /api/replays/recent`, `GET /api/replays/:id`
|
||||||
at `/data/data/com.solitairequest.app/files` on Android — no
|
- Server web UI: `/replays/:id` HTML route + `ServeDir /web` static assets
|
||||||
JNI needed (package id pinned in `[package.metadata.android]`).
|
- DB migration 002: `replays` table + two indexes
|
||||||
Six `solitaire_data` callsites + `solitaire_engine/assets/user_dir.rs`
|
- Full server integration tests for replay endpoints
|
||||||
migrated. Settings, stats, achievements, replays, game-state,
|
- `push_replay` in `sync_plugin` (uploads on win, writes share URL into replay history)
|
||||||
time-attack sessions, and user themes now persist on Android.
|
- Stats panel "Copy Share Link" button reads `share_url` from replay history
|
||||||
|
|
||||||
### Inherited from earlier in the cycle (pre-session)
|
---
|
||||||
|
|
||||||
- Android build target + APK (`fb8b2ac`), runbook (`59424a3`),
|
## Open punch list (ordered by priority)
|
||||||
F3 FPS overlay (`690e1d2`), Smart Window Size opt-out
|
|
||||||
(`e1b8766`), Shareable badge (`9b065e5`), Help cheat-sheet
|
|
||||||
M/P/Enter rows (`35516d3`), `pull_failure_sets_error_status`
|
|
||||||
flake fix (`67c150b`).
|
|
||||||
|
|
||||||
## Open punch list
|
### 1. Documentation debt (no code)
|
||||||
|
- [x] CHANGELOG [Unreleased] → v0.23.0 — done this session
|
||||||
|
- [x] ARCHITECTURE.md update — all 8 gaps closed, bumped to v1.3
|
||||||
|
- [x] SESSION_HANDOFF.md update — this file
|
||||||
|
|
||||||
### Phase Android (build + persistence shipped; runtime gaps remain)
|
### 2. Leaderboard wiring gaps
|
||||||
|
- **Best-score auto-post missing.** `POST /api/sync/push` merges stats/achievements/
|
||||||
|
progress but never touches the `leaderboard` table. Players who opt in never
|
||||||
|
have their `best_time_secs` / `best_score` updated automatically. Fix: update
|
||||||
|
the leaderboard row inside the server's sync push handler (or on `GameWonEvent`
|
||||||
|
via a new async task in `sync_plugin`).
|
||||||
|
- **Display name = username.** `handle_opt_in_button` uses the `SyncBackend`
|
||||||
|
username as the leaderboard display name. Consider adding
|
||||||
|
`leaderboard_display_name: Option<String>` to `Settings` for players who
|
||||||
|
want a different public identity.
|
||||||
|
|
||||||
- **APK launch verification on AVD / device.** `adb install` then
|
### 3. Security hardening
|
||||||
`adb logcat` against the `bevy_test` AVD or an x86_64 device.
|
- [x] **Refresh token rotation.** Done (`b129664`): `refresh_tokens` table
|
||||||
The build works and persistence is wired, but no end-to-end
|
(migration 003); jti embedded in JWT; rotate-on-use pattern; 3 integration
|
||||||
device run has been logged. Shakes out runtime bugs the build +
|
tests.
|
||||||
unit tests can't catch.
|
- [x] **Sync endpoint rate limiting.** Done (`6e6f3ef`): `UserIdKeyExtractor`
|
||||||
- **JNI ClipboardManager bridge.** Replaces the Android stub for
|
decodes JWT for per-user identity; falls back to IP; burst 10 / 6 min
|
||||||
the Stats "Copy share link" toast. `arboard` doesn't ship an
|
steady-state; integration test passes.
|
||||||
Android backend; small custom JNI call.
|
|
||||||
- **Android Keystore for credentials.** `keyring` is target-gated
|
|
||||||
to a stub returning `KeychainUnavailable`; replace with Android
|
|
||||||
Keystore via JNI when sync auth ships on mobile.
|
|
||||||
- **Google Play Games (gpgs) integration.** Listed as a
|
|
||||||
Phase-Android target since Phase 1; now unblocked by the build
|
|
||||||
target.
|
|
||||||
- **Cosmetic `cargo apk build --lib` workaround.** Post-sign
|
|
||||||
panic doesn't affect the APK on disk but produces noisy stderr.
|
|
||||||
Either upstream a cargo-apk fix or document `--lib` as
|
|
||||||
canonical in the runbook.
|
|
||||||
|
|
||||||
### Visual-identity follow-ups (opened by v0.20.0's port)
|
### 4. Android validation
|
||||||
|
- **Android Keystore functional test** — JNI AES-GCM code ships (`f281425`) but
|
||||||
|
no AVD round-trip test has been run. Required before Phase 8 sync goes live on
|
||||||
|
Android.
|
||||||
|
- **JNI clipboard functional test** — same status (`2c822ba`). Note: `adb tap`
|
||||||
|
doesn't work in headless AVD (see memory); requires a touch-gesture path.
|
||||||
|
- **`cargo apk build --lib` noisy stderr** — post-sign panic doesn't affect the
|
||||||
|
APK but pollutes CI output. Document `--lib` as canonical or upstream a fix.
|
||||||
|
|
||||||
- **Card-face / suit / card-back artwork regeneration.** The
|
### 5. Feature completeness
|
||||||
Terminal spec calls for dark `#1a1a1a` cards with light suit
|
- [x] **Theme importer UI.** Done (`613bbf8`): "Scan for new themes" button in
|
||||||
pips (pink for hearts/diamonds, foreground gray for spades/
|
Settings Appearance section. Shows import path label, scans user_theme_dir()
|
||||||
clubs); the runtime path still renders the legacy white-card
|
for .zip archives, fires InfoToastEvent per file, refreshes ThemeRegistry.
|
||||||
PNG artwork. The fallback constants in `card_plugin`
|
- [x] **`mirror_achievement` removed.** Done (`549a817`): method was a no-op
|
||||||
(`CARD_FACE_COLOUR`, `RED_SUIT_COLOUR`, `BLACK_SUIT_COLOUR`,
|
default never overridden and never called; achievements already sync via
|
||||||
`CARD_FACE_COLOUR_RED_CBM`, `card_back_colour` palette) are
|
`SyncPayload` push. Deleted from trait and blanket impl.
|
||||||
intentionally unmigrated and should swap in lockstep with the
|
- **WASM build script.** `web/pkg/` contains compiled WASM committed to git.
|
||||||
artwork. Largest visible payoff remaining in the visual-
|
Need a `build_wasm.sh` or Makefile target documenting the `wasm-pack build`
|
||||||
identity arc.
|
invocation to regenerate it.
|
||||||
- **Splash boot-loader richness.** The mockup
|
- **Server password reset.** No admin endpoint or CLI tool for resetting a
|
||||||
(`docs/ui-mockups/splash-mobile.html`) calls for a scanline
|
user's password. Self-hosters have no recovery path short of direct SQLite
|
||||||
overlay, ✓ lime check log lines, pulsing cursor, ROOT@SOLITAIRE
|
edits.
|
||||||
prompt, and a loading bar — none of which v0.20.0's
|
|
||||||
cursor-glyph-only port pulled in. Aesthetic feature, its own
|
|
||||||
commit.
|
|
||||||
- **Replay-overlay redesign.** The mockup
|
|
||||||
(`docs/ui-mockups/replay-overlay-mobile.html`) envisions a
|
|
||||||
much richer surface (terminal `▌replay.tsx` header, move log
|
|
||||||
scroll, MOVE 47/87 chip, WIN MOVE callout, status bar) versus
|
|
||||||
the current top banner. Aesthetic feature.
|
|
||||||
- **Toast Warning / Error variants.** The new `ToastVariant`
|
|
||||||
enum has slots for `Warning` (gold) and `Error` (pink) but no
|
|
||||||
in-engine event uses them yet (the four current toast events
|
|
||||||
all map to Info or Celebration). Wire when a warning- or
|
|
||||||
error-flavoured toast event materialises.
|
|
||||||
|
|
||||||
### Carried forward from v0.19.0
|
### 6. Testing gaps
|
||||||
|
- **Server 401 → refresh → retry path** — the `pull`/`push` retry logic in
|
||||||
|
`SolitaireServerClient` has no integration test.
|
||||||
|
- **WASM winning-replay step-through** — current tests cover 2 stock clicks;
|
||||||
|
a test stepping through a full winning sequence would catch
|
||||||
|
`GameState`/`ReplayMove` compatibility regressions.
|
||||||
|
|
||||||
- **App icon round.** `Window::icon` not yet wired; no
|
---
|
||||||
`.icns` / `.ico` / Linux hicolor PNG hierarchy. The 11-size
|
|
||||||
icon export the v0.19 handoff referenced is *not* currently
|
|
||||||
in `artwork/` (current `artwork/` holds the reverted Rusty
|
|
||||||
Pixel card PNGs and is intentionally untracked); icon-export
|
|
||||||
needs to be re-run before this item can be picked up.
|
|
||||||
Half-day task once the PNGs are back in place. No cert
|
|
||||||
dependency.
|
|
||||||
|
|
||||||
### Other small candidates
|
## ARCHITECTURE.md gaps (for the update pass)
|
||||||
|
|
||||||
- **Prev/Next selector chips spawn site.** v0.19.0's `9b065e5`
|
Items missing from the doc:
|
||||||
noted Prev/Next markers exist in `stats_plugin` but no spawn
|
1. `solitaire_wasm` crate (§2 workspace + §3 responsibilities)
|
||||||
site renders them today — the Shareable badge therefore lands
|
2. Replay API endpoints (§9 API Reference — 3 new routes)
|
||||||
on the single-replay caption. If/when Prev/Next is plumbed,
|
3. Web replay player route (`/replays/:id` + `ServeDir /web`)
|
||||||
the badge will need to follow.
|
4. `SyncProvider` trait: 6 added methods
|
||||||
- **Toast queue / immediate unification.** The two toast paths
|
5. Theme system in Bevy plugin table (§5)
|
||||||
(`spawn_queued_toast` for `InfoToastEvent` queue; `spawn_toast`
|
6. `Settings` new fields: `color_blind_mode`, `high_contrast_mode`,
|
||||||
for fire-and-forget) now share visual treatment but remain
|
`reduce_motion_mode`, `window_geometry`, `selected_card_back`,
|
||||||
separate functions because they serve different temporal
|
`selected_background`
|
||||||
needs (sequential vs. parallel). If overlap becomes a UX
|
7. DB migration 002 (§7)
|
||||||
issue, merge into one queue with priority lanes.
|
8. Update "Last Updated" date
|
||||||
|
|
||||||
### Process notes
|
---
|
||||||
|
|
||||||
- **Token-port pattern.** v0.20.0's chrome-migration commits
|
## Process notes
|
||||||
set a reusable shape for "centralized design system applied
|
|
||||||
across N plugins":
|
|
||||||
1. Constants module (`ui_theme.rs`) is the source of truth.
|
|
||||||
2. Const sites that can't call `Alpha::with_alpha` (not yet
|
|
||||||
`const` on stable) use a literal RGB matching the token,
|
|
||||||
with a unit test pinning the RGB to the token (e.g.
|
|
||||||
`MARKER_VALID`, `HINT_PILE_HIGHLIGHT_COLOUR`,
|
|
||||||
`RIGHT_CLICK_HIGHLIGHT_COLOUR`).
|
|
||||||
3. Cross-plugin duplication (e.g. `MARKER_DEFAULT` ↔
|
|
||||||
`PILE_MARKER_DEFAULT_COLOUR`) collapses to a single
|
|
||||||
promoted const re-exported from one plugin and imported
|
|
||||||
by the other — replaces "kept in sync" doc comments with a
|
|
||||||
compile-time invariant.
|
|
||||||
4. Domain colours (suit pips, card faces, lerp helpers) stay
|
|
||||||
as literals with a comment naming the rationale; only UI
|
|
||||||
chrome routes through tokens.
|
|
||||||
- **Audit before migrating wide.** Before touching any plugin,
|
|
||||||
grep for the literal pattern (`Color::srgb\(|Color::srgba\(|
|
|
||||||
Color::WHITE|Color::BLACK`) and classify each hit as domain
|
|
||||||
vs. chrome. Most plugins after the modal scaffold port turned
|
|
||||||
out to be 100 % token-correct already; the audit prevents
|
|
||||||
wasted churn.
|
|
||||||
|
|
||||||
### Canonical remote
|
- **Commit attribution:** use `funman300` as git user. Co-author line:
|
||||||
|
`Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>`.
|
||||||
|
- **Commit format:** `type(scope): description` per CLAUDE.md §7.
|
||||||
|
- **Never commit without:** `cargo test --workspace` passing + clippy clean.
|
||||||
|
- **Sub-agents** stage/verify only; orchestrator commits.
|
||||||
|
- **`CARD_PLAN.md`** referenced in `theme/` module comments but not present in
|
||||||
|
repo. Clean up references or commit the file.
|
||||||
|
- **Token-port pattern** (v0.20.0): when migrating tokens, walk every concrete
|
||||||
|
artifact downstream — PNGs, SVGs, literals, comments. Three "walked past this"
|
||||||
|
follow-ups in v0.21.0 all had this shape.
|
||||||
|
|
||||||
`github.com/funman300/Rusty_Solitaire` is the canonical repo.
|
---
|
||||||
Always push there.
|
|
||||||
|
|
||||||
### Design direction (now Terminal — base16-eighties)
|
|
||||||
|
|
||||||
- **Tone:** retro-terminal / synthwave — flat depth (no box-shadows),
|
|
||||||
monospaced-forward typography (JetBrains Mono / FiraMono), tight
|
|
||||||
16 px edge margins, 8 px card radius.
|
|
||||||
- **Palette:** near-black surface ramp (`#151515` / `#202020` / `#2a2a2a`
|
|
||||||
/ `#353535`), cyan primary CTA (`#6fc2ef`), lime success
|
|
||||||
(`#acc267`), gold warning (`#ddb26f`), pink error / suit-red
|
|
||||||
(`#fb9fb1`), lavender celebration (`#e1a3ee`), teal info
|
|
||||||
(`#12cfc0`).
|
|
||||||
- **Two-color suits.** Red = `#fb9fb1`, black = `#d0d0d0`. Outlined
|
|
||||||
glyphs for diamonds & clubs are *always on*; the Settings
|
|
||||||
"color-blind mode" toggle only swaps red → cyan.
|
|
||||||
|
|
||||||
(Was: Midnight Purple base + Balatro yellow primary + warm magenta.
|
|
||||||
Replaced this cycle.)
|
|
||||||
|
|
||||||
## Resume prompt
|
## Resume prompt
|
||||||
|
|
||||||
```
|
```
|
||||||
You are a senior Rust + Bevy developer working on Solitaire Quest.
|
You are a senior Rust + Bevy developer working on Solitaire Quest.
|
||||||
Working directory: <Rusty_Solitaire clone path on this machine>.
|
Working directory: <Rusty_Solitaire clone path>.
|
||||||
Branch: master. v0.20.0 just cut on 2026-05-07; CHANGELOG's new
|
Branch: master. v0.23.0 is the current version (HEAD locally: bd388fe).
|
||||||
[Unreleased] section is empty pending the next cycle's threads.
|
Phase 8 sync is fully shipped. ARCHITECTURE.md is now v1.3 (all Phase 8 gaps closed).
|
||||||
|
Push to origin pending (bd388fe + ARCHITECTURE.md + SESSION_HANDOFF.md commits).
|
||||||
|
|
||||||
State: HEAD on the v0.20.0 docs commit. Tag not pushed yet — last
|
READ FIRST (in order):
|
||||||
pushed tag is v0.19.0. Working tree clean apart from the
|
|
||||||
intentionally-untracked `artwork/`.
|
|
||||||
|
|
||||||
READ FIRST (in order, before doing anything):
|
|
||||||
1. SESSION_HANDOFF.md — this file
|
1. SESSION_HANDOFF.md — this file
|
||||||
2. CHANGELOG.md — [0.20.0] section is the most recent cut
|
2. CHANGELOG.md — [0.23.0] section has the full Phase 8 detail
|
||||||
3. CLAUDE.md — unified-3.0 rule set
|
3. CLAUDE.md — unified-3.0 rule set
|
||||||
4. CLAUDE_SPEC.md — formal architecture spec
|
4. ARCHITECTURE.md — v1.3, fully up to date
|
||||||
5. ARCHITECTURE.md — crate responsibilities + data flow
|
5. docs/ui-mockups/ — design system + mockup library
|
||||||
6. docs/ui-mockups/ — design system + 24-mockup library
|
6. docs/android/ — Android setup + build runbook
|
||||||
(Terminal aesthetic — landed in fa7f98a)
|
7. ~/.claude/projects/<this-project>/memory/MEMORY.md
|
||||||
7. docs/android/* — Android setup + build runbook
|
|
||||||
8. ~/.claude/projects/<this-project>/memory/MEMORY.md
|
|
||||||
— saved feedback / project context
|
|
||||||
(machine-local; may be missing on a
|
|
||||||
fresh machine)
|
|
||||||
|
|
||||||
DECISION TO ASK THE PLAYER FIRST:
|
OPEN WORK (in priority order):
|
||||||
A. Push v0.20.0 tag — `git tag v0.20.0 && git push --tags`. If
|
D. Android AVD functional tests (Keystore + clipboard)
|
||||||
the player wants the cut formalised before any new work.
|
E. Theme importer UI button in Settings
|
||||||
B. APK launch verification — `adb install` + `adb logcat` on
|
F. mirror_achievement: decide + implement or remove from trait
|
||||||
bevy_test AVD or an x86_64 device. Now that persistence is
|
G. Sync endpoint rate limiting (POST /api/sync/push has no per-user throttle)
|
||||||
wired (4b51e50), shake out remaining runtime bugs.
|
|
||||||
C. Card-face artwork regeneration — generate Terminal-aesthetic
|
|
||||||
card PNGs (dark face, light suit pips), then migrate
|
|
||||||
CARD_FACE_COLOUR / RED_SUIT_COLOUR / BLACK_SUIT_COLOUR /
|
|
||||||
CARD_FACE_COLOUR_RED_CBM in lockstep. Largest visible
|
|
||||||
payoff remaining in the visual-identity arc.
|
|
||||||
D. Splash boot-loader richness — port the scanline overlay,
|
|
||||||
✓ check log, pulsing cursor, ROOT@SOLITAIRE prompt, and
|
|
||||||
loading bar from docs/ui-mockups/splash-mobile.html. Pure
|
|
||||||
polish; no behavioural change.
|
|
||||||
E. App icon round — re-run artwork/Icon Export.html (the
|
|
||||||
export PNGs are not currently in `artwork/`), then wire
|
|
||||||
Window::icon + generate .icns / .ico. Half-day task. No
|
|
||||||
cert dependency.
|
|
||||||
F. JNI ClipboardManager / Keystore bridge — replaces the
|
|
||||||
Android stubs for Stats clipboard share + sync auth.
|
|
||||||
|
|
||||||
WORKFLOW NOTES:
|
Ask which to start. All are independent; any is a valid next arc.
|
||||||
- Use the system git config (already correct).
|
|
||||||
- When attributing playtester feedback in commits/docs, use
|
|
||||||
"Quat" not "Rhys" (saved feedback memory).
|
|
||||||
- Sub-agents stage + verify only; orchestrator commits.
|
|
||||||
- Every commit must pass build / clippy / test before pushing.
|
|
||||||
- Push to GitHub (origin) — gh auth setup-git wired on
|
|
||||||
primary dev box; verify on laptop before first push.
|
|
||||||
|
|
||||||
OPEN AT THE START: ask which of A–F. Don't pick unilaterally.
|
|
||||||
```
|
```
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 469 B |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 469 B |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 469 B |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 472 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 472 B |
|
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 185 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 191 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 283 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 300 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 357 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 300 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 318 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 365 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 179 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 196 KiB After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 263 B |
|
After Width: | Height: | Size: 369 B |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 489 B |
|
After Width: | Height: | Size: 759 B |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 927 B |
@@ -0,0 +1,245 @@
|
|||||||
|
# Android Playability TODO
|
||||||
|
|
||||||
|
**Started:** 2026-05-10 — first hardware screenshot of v0.22.3 APK
|
||||||
|
running on a real device showed the desktop HUD projected onto a
|
||||||
|
360 dp portrait viewport with no mobile adaptation. This list
|
||||||
|
tracks the work needed to make the APK genuinely playable, not
|
||||||
|
just "boots without crashing."
|
||||||
|
|
||||||
|
**Context:** v0.22.3 (signed release APK) builds and launches.
|
||||||
|
JNI bridges (clipboard, keystore) compile but are untested on
|
||||||
|
hardware. The work below is UI/UX port work — no architectural
|
||||||
|
rewrites required.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Reading from the v0.22.3 screenshot
|
||||||
|
|
||||||
|
| Region | Observation |
|
||||||
|
|--------|-------------|
|
||||||
|
| Top ~5 % | System bar (clock, signal, battery) overlapped by game HUD — no safe-area inset |
|
||||||
|
| HUD text row | `Score:0 Pause Esc Help A Modes [] New_Game N Moves:0 0:08` all overlapping — desktop layout crammed into 360 dp |
|
||||||
|
| Keyboard hints | `Esc`, `A`, `[]`, `N` shown next to buttons — meaningless on touch |
|
||||||
|
| Foundations row | Leftmost foundation (♥) clipped left; rightmost tableau column (♠ 4) clipped right |
|
||||||
|
| Card backs | Face-down cards render as solid red squares, not back-art texture |
|
||||||
|
| Vertical use | Cards occupy top ~30 % only; bottom 70 % empty black — no portrait-aware layout |
|
||||||
|
| Bottom edge | No accommodation for Android gesture / home-indicator area |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## P0 — Blocking playability
|
||||||
|
|
||||||
|
- [x] **Safe-area insets (top + bottom).** *Closed 2026-05-10 by
|
||||||
|
`b9aa262`.* `SafeAreaInsets` resource + `SafeAreaInsetsPlugin`
|
||||||
|
query `WindowInsets.getInsets(systemBars())` via JNI on Android;
|
||||||
|
HUD anchors carry `SafeAreaAnchoredTop { base_top }` and the
|
||||||
|
change-detection fix-up system re-applies `base_top + insets.top`
|
||||||
|
whenever the resource updates. Bottom inset is captured but not
|
||||||
|
yet consumed (waits for bottom-anchored UI).
|
||||||
|
- [x] **Mobile HUD layout.** *Closed 2026-05-10.* Both the left HUD
|
||||||
|
column and the right action button row are now capped at
|
||||||
|
`max_width: 50 %` and the button row + tier-row child Nodes carry
|
||||||
|
`flex_wrap: Wrap`. On a 360 dp viewport the 6-button row breaks
|
||||||
|
to multiple lines (right-justified) and the tier rows wrap
|
||||||
|
individually instead of overflowing into the action column. On
|
||||||
|
desktop (≥ 1280 px) the 50 % cap is wider than any natural row
|
||||||
|
width so the existing single-line layout is unchanged.
|
||||||
|
- [x] **Card-back asset not rendering.** *Closed 2026-05-10 by
|
||||||
|
`fcc7337`.* `AssetPlugin::file_path = "../assets"` was set
|
||||||
|
unconditionally to fix the desktop `cargo run -p solitaire_app`
|
||||||
|
CWD relativity, but on Android cargo-apk packages the same
|
||||||
|
directory into the APK at `assets/` and Bevy's
|
||||||
|
AndroidAssetReader is already rooted there — prepending `../`
|
||||||
|
walked the reader out of the APK assets root and every load
|
||||||
|
failed silently. The face-down branch then fell through to the
|
||||||
|
`card_back_colour(0)` solid-red brick fallback. Gated the
|
||||||
|
override behind `#[cfg(not(target_os = "android"))]`.
|
||||||
|
- [x] **Viewport overflow.** *Closed 2026-05-10.* `compute_layout`
|
||||||
|
was clamping the input window up to `MIN_WINDOW = 800 × 600`,
|
||||||
|
so a 360 dp phone got laid out as if it were 800-wide and the
|
||||||
|
outer piles fell outside the actual viewport. Lowered the floor
|
||||||
|
to 320 × 400 (below the smallest reasonable phone) so real
|
||||||
|
Android resolutions flow through without clamping, while keeping
|
||||||
|
a sentinel to guard against degenerate / startup-zero windows.
|
||||||
|
New regression test `phone_portrait_layout_fits_horizontally`
|
||||||
|
asserts all 13 piles fit a 360 × 800 viewport.
|
||||||
|
|
||||||
|
## P1 — Touch UX
|
||||||
|
|
||||||
|
- [x] **Suppress keyboard-hint labels on Android.** *Closed
|
||||||
|
2026-05-10.* `spawn_action_button` now nulls the `hotkey`
|
||||||
|
argument on Android via a `#[cfg(target_os = "android")]` rebind,
|
||||||
|
so the U / Esc / F1 / N chips next to the action row labels
|
||||||
|
disappear on touch builds. Remaining hint sites swept in P3 —
|
||||||
|
see full-keyboard-hint-sweep entry below.
|
||||||
|
- [x] **Thumb-sized hit targets.** *Closed 2026-05-10.* Action
|
||||||
|
button Node carries `min_width: Val::Px(48.0), min_height:
|
||||||
|
Val::Px(48.0)` — meets Material's 48 dp baseline on touch and is
|
||||||
|
a no-op for buttons whose content already exceeds 48 px in
|
||||||
|
either axis. Applied universally rather than cfg-gated since
|
||||||
|
Material's guideline applies to all input modes. Cards, pile
|
||||||
|
markers, modal close buttons not yet audited — track as P3 if
|
||||||
|
they fall below threshold on hardware.
|
||||||
|
- [x] **Portrait-first card spacing.** *Closed 2026-05-11.*
|
||||||
|
`compute_layout` now derives an adaptive `tableau_fan_frac` from the
|
||||||
|
available vertical space below the tableau row. On height-limited
|
||||||
|
(desktop) windows the formula returns ≈ 0.25 and the clamp keeps the
|
||||||
|
existing behaviour. On width-limited (portrait phone) windows — where
|
||||||
|
card size is constrained by the 9-column horizontal packing — the fan
|
||||||
|
fraction expands to fill the viewport (≈ 0.84 at 360 × 800 dp).
|
||||||
|
`tableau_facedown_fan_frac` scales proportionally. Both values live in
|
||||||
|
the `Layout` struct; `card_plugin::card_positions` and
|
||||||
|
`input_plugin::card_position` / `pile_drop_rect` read from the struct
|
||||||
|
so rendering and hit-testing stay in sync across viewport sizes.
|
||||||
|
- [x] **Double-tap auto-move visible feedback.** *Closed 2026-05-11.*
|
||||||
|
On a recognised double-tap (priority 1 single-card or priority 2
|
||||||
|
stack move), the moved card(s) receive a 0.35 s lime flash
|
||||||
|
(`STATE_SUCCESS` tint + `HintHighlight { remaining: 0.35 }`) before
|
||||||
|
the move request is written. The flash persists through the card
|
||||||
|
animation and is cleaned up by the existing `tick_hint_highlight`
|
||||||
|
system. Hardware trigger-verification remains a manual step — connect
|
||||||
|
AVD or device and confirm two rapid `TouchPhase::Ended` events within
|
||||||
|
0.5 s produce the lime flash.
|
||||||
|
|
||||||
|
## P2 — Polish
|
||||||
|
|
||||||
|
- [x] **Drag responsiveness on touch.** *Closed 2026-05-11.*
|
||||||
|
Two code-side improvements shipped; final feel confirmation still needs
|
||||||
|
hardware:
|
||||||
|
1. `start_drag` (mouse path) now bails out when a touch is just-pressed
|
||||||
|
(`Touches::iter_just_pressed()`), ensuring `touch_start_drag` always
|
||||||
|
owns the drag state on touch-screen devices — including Bevy/Winit
|
||||||
|
versions that simulate `MouseButton::Left` from the primary touch.
|
||||||
|
2. Mobile drag commit threshold lowered 10 px → 8 px, matching Android's
|
||||||
|
`ViewConfiguration.getScaledTouchSlop()` spec. Smaller threshold →
|
||||||
|
smaller snap-on-commit and faster perceived response.
|
||||||
|
**Remaining:** connect AVD or device and verify drag feels responsive
|
||||||
|
with no stutter; tune threshold further if needed.
|
||||||
|
- [x] **Long-press menu.** *Closed 2026-05-11.* New system
|
||||||
|
`radial_open_on_long_press` in `radial_menu.rs` counts up while a
|
||||||
|
touch is held (`drag.active_touch_id.is_some() && !drag.committed`)
|
||||||
|
and opens `RightClickRadialState::Active` after 0.5 s — the same
|
||||||
|
state the right-click path uses. Existing radial infrastructure
|
||||||
|
then handles everything:
|
||||||
|
- `radial_track_cursor` extended to fall back to the first active
|
||||||
|
touch when no cursor position is available, so sliding the held
|
||||||
|
finger moves the hover ring.
|
||||||
|
- `radial_handle_release_or_cancel` extended to confirm/cancel on
|
||||||
|
`Touches::iter_just_released()` in addition to right-mouse release.
|
||||||
|
- `handle_double_tap` skips when the radial is active (guards a
|
||||||
|
narrow edge case where the finger lifts at exactly the same frame
|
||||||
|
the 0.5 s threshold fires).
|
||||||
|
Hardware verification needed: confirm the 0.5 s hold feel, verify
|
||||||
|
sliding to a destination and lifting confirms the move.
|
||||||
|
- [x] **HUD typography.** *Closed 2026-05-11.* New system
|
||||||
|
`update_hud_typography` fires on `WindowResized` and adjusts Tier-1
|
||||||
|
font sizes based on viewport width. Below 480 logical px: Score
|
||||||
|
`TYPE_HEADLINE` (26) → `TYPE_BODY_LG` (18), Moves/Timer
|
||||||
|
`TYPE_BODY_LG` (18) → `TYPE_CAPTION` (11), so all three items fit
|
||||||
|
in the 180 dp HUD column on a 360 dp phone. At ≥ 480 px the
|
||||||
|
original sizes are restored — desktop/tablet layout unchanged.
|
||||||
|
`add_message::<WindowResized>()` added defensively to `HudPlugin`
|
||||||
|
so the system works under `MinimalPlugins` in tests.
|
||||||
|
- [x] **Orientation lock.** *Closed 2026-05-11.* Added
|
||||||
|
`[package.metadata.android.application.activity]` section to
|
||||||
|
`solitaire_app/Cargo.toml` with `orientation = "portrait"`.
|
||||||
|
cargo-apk/ndk-build maps this to `android:screenOrientation="portrait"`
|
||||||
|
in the generated `AndroidManifest.xml`. Remove (or add a landscape
|
||||||
|
layout) before enabling auto-rotate.
|
||||||
|
|
||||||
|
## P3 — Asset density
|
||||||
|
|
||||||
|
- [x] **Density-aware card scaling.** *Closed 2026-05-11 — no code change
|
||||||
|
required.* `WindowResized` fires with **logical** pixels; sprites are
|
||||||
|
sized in world units (1 world unit = 1 logical pixel); Bevy's renderer
|
||||||
|
maps logical → physical via `scale_factor` internally. On a 360 dp
|
||||||
|
3×-DPI phone, cards are 40 logical dp = 120 physical px. The 256 × 384 px
|
||||||
|
card textures are **downscaled** to fit (256 → 120 px) — quality is fine.
|
||||||
|
Upscaling only occurs if `card_width × scale_factor > 256`, i.e. a
|
||||||
|
tablet with a logical width > 765 dp at 3× DPI — no current target
|
||||||
|
device falls in that range. Revisit if the game ships on large-screen
|
||||||
|
high-DPI tablets.
|
||||||
|
- [x] **App-icon density buckets.** *Closed 2026-05-11.* Created
|
||||||
|
`solitaire_app/res/mipmap-{mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi}/ic_launcher.png`
|
||||||
|
from the existing `assets/icon/` PNGs (48→mdpi, 64→hdpi, 128→xhdpi,
|
||||||
|
256→xxhdpi+xxxhdpi). Added `resources = "res"` to
|
||||||
|
`[package.metadata.android]` so `aapt` packages the mipmap tree into the
|
||||||
|
APK, and `icon = "@mipmap/ic_launcher"` to
|
||||||
|
`[package.metadata.android.application]` so the launcher references it.
|
||||||
|
- [x] **Full keyboard-hint sweep.** *Closed 2026-05-11.* Extended the
|
||||||
|
P1 suppression to cover all remaining hint sites:
|
||||||
|
- `ui_modal.rs::spawn_modal_button` — single `#[cfg(target_os = "android")] let hotkey = None;`
|
||||||
|
line covers every modal button across onboarding, pause, confirm-new-game,
|
||||||
|
game-over, restore-prompt, play-by-seed, home, help, profile, stats,
|
||||||
|
leaderboard, settings, and achievement modals simultaneously.
|
||||||
|
- `home_plugin.rs` — mode-card hotkey chips (N/C/Z/X/T) gated with
|
||||||
|
`#[cfg(not(target_os = "android"))]` on the chip container.
|
||||||
|
- `replay_overlay.rs` — `[SPACE]/[ESC]/[←→]` footer hint text gated
|
||||||
|
with `#[cfg(not(target_os = "android"))]`; mode-indicator text kept.
|
||||||
|
- `help_plugin.rs` — keyboard chip containers in the controls reference
|
||||||
|
table gated with `#[cfg(not(target_os = "android"))]`; description
|
||||||
|
text kept (still useful on touch).
|
||||||
|
|
||||||
|
## P4 — Stability / runtime
|
||||||
|
|
||||||
|
- [x] **B0004 ECS hierarchy warnings.** *Investigated 2026-05-11 — no
|
||||||
|
fix required.* B0004 fires via Bevy's `validate_parent_has_component<C>`
|
||||||
|
hook when a child entity has UI component `C` (e.g. `Node`,
|
||||||
|
`InheritedVisibility`) but its parent doesn't yet. In Bevy 0.18,
|
||||||
|
`.despawn()` is recursive (docs: "When a parent is despawned, all
|
||||||
|
children will also be despawned"), so all `.despawn()` calls in the
|
||||||
|
engine are safe. The warnings seen on the Pixel 7 AVD during startup
|
||||||
|
are a component-propagation timing artifact — UI children reach the
|
||||||
|
hook before the parent's inherited components finish initialising —
|
||||||
|
not a gameplay defect. `despawn_related::<Children>()` in
|
||||||
|
`card_plugin.rs` is explicit child-only teardown (parent kept alive)
|
||||||
|
and is correct. No gameplay bugs attributed to these warnings over 2+
|
||||||
|
min AVD runtime.
|
||||||
|
- [x] **AVD functional tests for JNI bridges.** *Closed 2026-05-11.*
|
||||||
|
Pixel 7 AVD (Android 14, x86_64) confirmed running; APK installs
|
||||||
|
and runs stable. Key findings:
|
||||||
|
|
||||||
|
**Keystore JNI — verified working.** Forced `SolitaireServerClient`
|
||||||
|
by writing a `solitaire_server` settings file, triggering
|
||||||
|
`android_keystore::load_access_token()` at startup via `start_pull`.
|
||||||
|
Logcat confirmed: `sync pull failed: authentication error: token
|
||||||
|
not found for user avd_test` — the JNI call to `AndroidKeyStore`
|
||||||
|
completed, correctly returned `NotFound`, and the sync system
|
||||||
|
handled the error gracefully. No panic, no crash from the JNI layer.
|
||||||
|
|
||||||
|
**Clipboard JNI — verified working.** Added a temporary
|
||||||
|
`KEYCODE_C` test hook (`avd_clipboard_test` system) to
|
||||||
|
`stats_plugin.rs`, rebuilt the APK, pressed C on the AVD.
|
||||||
|
Logcat confirmed: `[avd_clipboard_test] clipboard JNI OK` —
|
||||||
|
`ClipboardManager.setPrimaryClip()` succeeded on Android 14.
|
||||||
|
Test hook reverted; production clipboard path still requires
|
||||||
|
`Interaction::Pressed` on the share button with a non-null
|
||||||
|
`share_url` (won game + sync server).
|
||||||
|
|
||||||
|
**Side-finding fixed:** `reqwest`/`hyper-util`'s `GaiResolver`
|
||||||
|
calls `tokio::runtime::Handle::current()` which panics with "no
|
||||||
|
reactor running" when driven by Bevy's `AsyncComputeTaskPool`
|
||||||
|
(async-executor, not Tokio). Fixed in `sync_plugin.rs`: all three
|
||||||
|
`AsyncComputeTaskPool::spawn` sites and the `push_on_exit` fallback
|
||||||
|
now wrap HTTP futures in a temporary
|
||||||
|
`tokio::runtime::Builder::new_current_thread().enable_all()` runtime.
|
||||||
|
|
||||||
|
**Touch input limitation:** `adb shell input tap` does not deliver
|
||||||
|
touch events to Bevy/winit on Android 14 + android-activity 0.6.1
|
||||||
|
in headless AVD mode. Keyboard events (`KEYCODE_*`) work normally.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes / decisions
|
||||||
|
|
||||||
|
* This list is screenshot-driven; expect more items to surface once
|
||||||
|
P0 unblocks actually moving cards on hardware.
|
||||||
|
* The pattern across all the bugs is "no one ran the relevant code
|
||||||
|
path on Android yet." The hard work — Bevy 0.18 on Android,
|
||||||
|
JNI bridges, signed CI builds — is done. What's left is a
|
||||||
|
coordinated pass of `#[cfg(target_os = "android")]` gates plus
|
||||||
|
making `LayoutResource` query the real surface size.
|
||||||
|
* Where possible, prefer responsive layout (query window size) over
|
||||||
|
branching `#[cfg]` blocks. Branches are fine for input methods
|
||||||
|
(touch vs. mouse) but not for screen geometry — a foldable or
|
||||||
|
desktop window of equivalent size should look the same.
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
# Card-face artwork migration plan
|
||||||
|
|
||||||
|
**Status:** planning artifact (no code changed by this document).
|
||||||
|
**Tracks:** the "Card-face / suit / card-back artwork regeneration"
|
||||||
|
item in `SESSION_HANDOFF.md` → "Visual-identity follow-ups"
|
||||||
|
(SESSION_HANDOFF Resume prompt option D).
|
||||||
|
**Companion to:** `docs/ui-mockups/design-system.md` (Game Cards
|
||||||
|
spec, lines 214–233) and `docs/ui-mockups/desktop-adaptation.md`
|
||||||
|
(rules-based companion to the mockups).
|
||||||
|
|
||||||
|
## Why this is a multi-session arc
|
||||||
|
|
||||||
|
Every post-v0.20.0 visual-identity port to date (modal scaffold,
|
||||||
|
toasts, table chrome, splash boot screen, replay overlay) was a
|
||||||
|
**single rendering path** — change tokens, change comments, ship.
|
||||||
|
Cards have **two** rendering paths that are visually identical
|
||||||
|
today and would visually disagree the moment one moves:
|
||||||
|
|
||||||
|
1. **PNG path (production).** `assets/cards/faces/<rank><suit>.png`
|
||||||
|
loaded into `CardImageSet.faces[suit][rank]` at startup; card
|
||||||
|
sprites blit the texture. 52 face PNGs + 5 back PNGs already
|
||||||
|
in `assets/`, all the legacy white-card aesthetic from the
|
||||||
|
pre-Terminal design system.
|
||||||
|
2. **Constant fallback (tests + asset-missing edge).** When
|
||||||
|
`CardImageSet` isn't a registered resource (the case under
|
||||||
|
`MinimalPlugins` test fixtures, and the bare-bones path the
|
||||||
|
first-frame of production hits before assets resolve), the
|
||||||
|
renderer falls back to solid-colour sprites driven by the
|
||||||
|
`card_plugin` constants:
|
||||||
|
- `CARD_FACE_COLOUR` — `(0.98, 0.98, 0.95)` cream-ish white.
|
||||||
|
- `RED_SUIT_COLOUR` — `(0.78, 0.12, 0.15)` warm red.
|
||||||
|
- `BLACK_SUIT_COLOUR` — `(0.08, 0.08, 0.08)` near-black.
|
||||||
|
- `CARD_FACE_COLOUR_RED_CBM` — `(0.85, 0.92, 1.0, 1.0)` light
|
||||||
|
blue (the legacy color-blind tint).
|
||||||
|
- `card_back_colour(idx)` — five legacy back themes.
|
||||||
|
|
||||||
|
A single-path migration leaves a known-broken state where tests
|
||||||
|
pass against Terminal constants while a human sees legacy artwork
|
||||||
|
on screen — the exact bisection-hostile drift the handoff's
|
||||||
|
"in lockstep" warning preempts.
|
||||||
|
|
||||||
|
## Target state — Terminal aesthetic
|
||||||
|
|
||||||
|
Per `design-system.md` § Game Cards (lines 214–233):
|
||||||
|
|
||||||
|
### Card face
|
||||||
|
|
||||||
|
| Element | Spec |
|
||||||
|
|---|---|
|
||||||
|
| Background | `#1a1a1a` |
|
||||||
|
| Border | 1 px solid in **suit colour** (pink for ♥/♦, foreground gray for ♠/♣) |
|
||||||
|
| Corner radius | 8 px |
|
||||||
|
| Top-left | rank in JetBrains Mono **Bold 18 px** + small suit glyph (10 px) |
|
||||||
|
| Bottom-right | large suit glyph (32 px), rotated 180° |
|
||||||
|
| Glyph fill rule | ♥ ♠ filled; ♦ ♣ outlined (1.5 px stroke). Always on, not a toggle. |
|
||||||
|
|
||||||
|
### Suit colours (always-on glyph differentiation is the *primary*
|
||||||
|
distinguishing mechanism; colour is supplementary):
|
||||||
|
|
||||||
|
| Suit | Default | Color-blind mode |
|
||||||
|
|---|---|---|
|
||||||
|
| Hearts | `#fb9fb1` (pink) | `#6fc2ef` (cyan) |
|
||||||
|
| Diamonds | `#fb9fb1` (pink) | `#6fc2ef` (cyan) |
|
||||||
|
| Spades | `#d0d0d0` (gray) | `#d0d0d0` (unchanged) |
|
||||||
|
| Clubs | `#d0d0d0` (gray) | `#d0d0d0` (unchanged) |
|
||||||
|
|
||||||
|
### Card back ("Terminal" theme)
|
||||||
|
|
||||||
|
| Element | Spec |
|
||||||
|
|---|---|
|
||||||
|
| Background | `#151515` |
|
||||||
|
| Pattern | horizontal scanlines at 2 px pitch in `#1a1a1a` (1 px line, 1 px gap), full bleed |
|
||||||
|
| Border | 1 px solid `#353535` |
|
||||||
|
| Top-left badge | 12×16 px solid `#6fc2ef` block, 6 px from corner |
|
||||||
|
| Bottom-right monogram | `▌RS` in JetBrains Mono 12 px `#505050`, 6 px from corner |
|
||||||
|
| Corner radius | 8 px |
|
||||||
|
| Theme name / author | `"Terminal"` / `"Rusty Solitaire"` |
|
||||||
|
|
||||||
|
## Generation pipeline — programmatic SVG via the existing
|
||||||
|
`resvg` stack
|
||||||
|
|
||||||
|
### Why this path (vs. external tooling or direct `tiny_skia`)
|
||||||
|
|
||||||
|
The codebase already ships an SVG-to-PNG rasteriser at
|
||||||
|
`solitaire_engine/src/assets/svg_loader.rs`:
|
||||||
|
|
||||||
|
- Public `rasterize_svg(svg_bytes: &[u8], target: UVec2) -> Result<Image, _>`
|
||||||
|
- Backed by `usvg` (parser) + `resvg` (renderer) + `tiny_skia`
|
||||||
|
(CPU pixmap)
|
||||||
|
- Bundled font db includes JetBrains-style mono (FiraMono — same
|
||||||
|
face the splash uses; close enough to JetBrains Mono for
|
||||||
|
rasterisation purposes, and identical to what the Bevy UI
|
||||||
|
consumes in the rest of the app)
|
||||||
|
- `RenderAssetUsages::default()` is the call-site convention here
|
||||||
|
|
||||||
|
This means: **generating new card PNGs is one new file
|
||||||
|
(`solitaire_engine/examples/card_face_generator.rs`) calling an
|
||||||
|
existing public function.** No new dependencies, no asset-pipeline
|
||||||
|
changes, no build-script machinery. Anyone who runs the example
|
||||||
|
gets bit-identical artwork.
|
||||||
|
|
||||||
|
The two alternatives are weaker:
|
||||||
|
|
||||||
|
- **External tool (Inkscape / Figma / hand-design)** — produces
|
||||||
|
one-off PNGs that can't be re-generated reproducibly without
|
||||||
|
re-opening the source files in a specific tool. Iteration cost
|
||||||
|
is high; design tweaks (e.g. "make the suit glyph 2 px larger")
|
||||||
|
require a designer-in-the-loop.
|
||||||
|
- **Direct `tiny_skia` painting calls** — bypasses SVG entirely,
|
||||||
|
but loses the readability of "open the SVG to see exactly what
|
||||||
|
the card looks like." Also reinvents primitives (rounded
|
||||||
|
rectangles, text layout) that `usvg` already handles.
|
||||||
|
|
||||||
|
### Output format
|
||||||
|
|
||||||
|
PNG, RGBA8 sRGB, **dimensions 256 × 384** (2:3 aspect, half the
|
||||||
|
default `SvgLoaderSettings` of 512 × 768).
|
||||||
|
|
||||||
|
Rationale: cards never exceed ~250 px wide on desktop windows
|
||||||
|
today, and 256 × 384 PNGs are ~6 KB each at this content density
|
||||||
|
(13.4 KB total for a full deck of 52 + 5 backs). The default 512 ×
|
||||||
|
768 is 2× what's needed and quadruples the on-disk asset weight.
|
||||||
|
The existing legacy PNGs are 512 × 768 — reducing the new ones
|
||||||
|
halves the runtime asset size.
|
||||||
|
|
||||||
|
## Lockstep migration — recommended order
|
||||||
|
|
||||||
|
Each step is a separate commit; the constraint is that **steps 4
|
||||||
|
and 5 must land in the same commit** (or at most adjacent commits
|
||||||
|
on the same branch) so the rendered output never diverges between
|
||||||
|
the two paths.
|
||||||
|
|
||||||
|
1. **(Done — this commit)** Land the migration plan doc.
|
||||||
|
2. **Land the SVG generator example.** New
|
||||||
|
`solitaire_engine/examples/card_face_generator.rs`. Output
|
||||||
|
goes to `assets/cards/faces/` and `assets/cards/backs/`. Run
|
||||||
|
once locally to seed the new artwork. The example file stays
|
||||||
|
in-tree as a regenerator for future tweaks.
|
||||||
|
3. **(Optional — can land separately)** Add a one-shot regression
|
||||||
|
test that re-runs the generator into a `tempdir` and compares
|
||||||
|
the resulting bytes against the on-disk artwork; pinning the
|
||||||
|
generator output prevents silent drift if `usvg`/`resvg` ever
|
||||||
|
tweak rendering. Skip if the test runtime cost is unacceptable.
|
||||||
|
4. **Land the new artwork** (PNG bytes from step 2 committed to
|
||||||
|
`assets/cards/`) **and** the constant migration in the *same
|
||||||
|
commit*:
|
||||||
|
- `CARD_FACE_COLOUR` → `Color::srgb(0.102, 0.102, 0.102)` (`#1a1a1a`)
|
||||||
|
- `RED_SUIT_COLOUR` → `Color::srgb(0.984, 0.624, 0.694)` (`#fb9fb1`)
|
||||||
|
- `BLACK_SUIT_COLOUR` → `Color::srgb(0.816, 0.816, 0.816)` (`#d0d0d0`)
|
||||||
|
- `CARD_FACE_COLOUR_RED_CBM` → `Color::srgb(0.435, 0.761, 0.937)` (`#6fc2ef`) — note this is now the colour-blind *suit* colour, not a face tint; semantics shift slightly.
|
||||||
|
- `card_back_colour(idx)` — re-author for the Terminal palette;
|
||||||
|
index 0 stays the canonical "Terminal" back from `design-system.md`.
|
||||||
|
5. **Test updates land in step 4's commit.** The pinning tests at
|
||||||
|
`card_plugin.rs` lines 1749, 1750, 1767, 1768, 2057, 2063,
|
||||||
|
2071, 2081 all assert against the old constants. New
|
||||||
|
assertions update in lockstep with the constant changes.
|
||||||
|
|
||||||
|
## CBM (color-blind mode) semantics shift — flag
|
||||||
|
|
||||||
|
The **legacy** `CARD_FACE_COLOUR_RED_CBM` was a *face tint* — red
|
||||||
|
suits got a light-blue background wash. The **Terminal** spec
|
||||||
|
moves CBM into the *suit colour* itself (red glyphs swap to cyan).
|
||||||
|
Step 4 will rename / repurpose this constant; it's not a 1:1
|
||||||
|
replacement.
|
||||||
|
|
||||||
|
Two options:
|
||||||
|
|
||||||
|
- **Rename + repurpose:** `CARD_FACE_COLOUR_RED_CBM` →
|
||||||
|
`RED_SUIT_COLOUR_CBM`. Communicates the semantic shift in the
|
||||||
|
symbol name. Requires touching every callsite.
|
||||||
|
- **Keep the name, change the meaning:** less code churn but
|
||||||
|
worse for greppability — a future reader hitting the legacy
|
||||||
|
name will assume face-tint behaviour.
|
||||||
|
|
||||||
|
Recommendation: **rename**. The CBM swap is a one-frame operation
|
||||||
|
even if it touches every existing callsite (currently lines 642,
|
||||||
|
2071, 2081 per `grep -n CARD_FACE_COLOUR_RED_CBM`).
|
||||||
|
|
||||||
|
## Theme system — out of scope here
|
||||||
|
|
||||||
|
The card-theme system (`docs/CARD_PLAN.md`, `theme/plugin.rs`)
|
||||||
|
already supports user-supplied themes via `assets/themes/<theme>/`
|
||||||
|
SVG files rasterised by `svg_loader.rs`. The new Terminal artwork
|
||||||
|
is the **default theme**, not a new entry in the theme picker —
|
||||||
|
the theme system continues to overlay user themes on top of the
|
||||||
|
default at runtime.
|
||||||
|
|
||||||
|
If the next session wants to also ship Terminal as a *named theme
|
||||||
|
slot* (so a user can switch back to the legacy artwork via the
|
||||||
|
theme picker), that's an additive change after step 4 and lives
|
||||||
|
in `theme::plugin::apply_theme_to_card_image_set`.
|
||||||
|
|
||||||
|
## Test impact summary
|
||||||
|
|
||||||
|
`grep -n CARD_FACE_COLOUR\\b\|RED_SUIT_COLOUR\\b\|BLACK_SUIT_COLOUR\\b` in
|
||||||
|
`card_plugin.rs`:
|
||||||
|
|
||||||
|
- Line 1749–1750: red-suit text colour assertions (♥ + ♦).
|
||||||
|
- Line 1767–1768: black-suit text colour assertions (♠ + ♣).
|
||||||
|
- Line 2057, 2063: face-colour assertion in default mode.
|
||||||
|
- Line 2071, 2081: face-colour assertion in CBM.
|
||||||
|
|
||||||
|
The four suit-colour and two face-colour tests are **invariant
|
||||||
|
guards** — they exist precisely so a constant tweak surfaces here
|
||||||
|
rather than in a visual review. Step 4 updates each in lockstep
|
||||||
|
with the constant value change. No new test infrastructure
|
||||||
|
needed.
|
||||||
|
|
||||||
|
## Open questions to resolve before step 4
|
||||||
|
|
||||||
|
1. **Border colour conflict.** The spec (line 218) says "Border:
|
||||||
|
1 px solid in suit colour." The fallback path doesn't draw a
|
||||||
|
border today — it draws solid-colour sprites. Step 4 either:
|
||||||
|
(a) leaves the fallback as solid-colour squares (the test
|
||||||
|
environment doesn't visually validate borders anyway), or
|
||||||
|
(b) extends the fallback renderer to paint a 1 px outline.
|
||||||
|
Recommend (a) — fallback fidelity isn't load-bearing.
|
||||||
|
2. **Glyph rendering in the constant fallback.** The fallback
|
||||||
|
today doesn't render suit glyphs at all — it's a coloured
|
||||||
|
square. The spec's filled-vs-outlined glyph differentiation
|
||||||
|
only matters in the PNG path. No change to the constant
|
||||||
|
fallback for glyphs.
|
||||||
|
3. **High-contrast mode.** `design-system.md` line 274 mentions
|
||||||
|
a high-contrast accessibility mode (boosts foreground from
|
||||||
|
`#d0d0d0` to `#f5f5f5`, suit-red from `#fb9fb1` to `#ff8aa0`).
|
||||||
|
Not currently implemented anywhere; out of scope for this
|
||||||
|
migration but worth flagging for a future accessibility pass.
|
||||||
|
|
||||||
|
## Post-migration — what's still open
|
||||||
|
|
||||||
|
- **High-contrast mode** (above).
|
||||||
|
- **Reduced-motion mode** for card lift / drop transitions
|
||||||
|
(also a `design-system.md` accessibility item, separate from
|
||||||
|
artwork).
|
||||||
|
- **The 9 missing-plugin screens** (splash, challenge,
|
||||||
|
time-attack, weekly-goals, leaderboard, sync, level-up,
|
||||||
|
replay, radial-menu) per `project_ui_overhaul` memory still
|
||||||
|
need their plugin ports — separate from the cards arc.
|
||||||
|
|
||||||
|
## Sign-off criteria for "D closed"
|
||||||
|
|
||||||
|
D from the SESSION_HANDOFF Resume prompt is closed when **all of
|
||||||
|
the following hold simultaneously**:
|
||||||
|
|
||||||
|
- The 52 face PNGs + 5 back PNGs in `assets/cards/` are the
|
||||||
|
Terminal-aesthetic artwork (regeneratable via the example).
|
||||||
|
- The five `card_plugin` constants reflect the Terminal palette.
|
||||||
|
- All pinning tests pass against the new values.
|
||||||
|
- A human boots the game and sees Terminal cards (not white
|
||||||
|
cards). This sign-off needs a real `cargo run`, not just
|
||||||
|
`cargo test`.
|
||||||
@@ -15,12 +15,12 @@ colors:
|
|||||||
inverse-on-surface: '#151515'
|
inverse-on-surface: '#151515'
|
||||||
outline: '#505050'
|
outline: '#505050'
|
||||||
outline-variant: '#353535'
|
outline-variant: '#353535'
|
||||||
surface-tint: '#6fc2ef'
|
surface-tint: '#a54242'
|
||||||
primary: '#6fc2ef'
|
primary: '#a54242'
|
||||||
on-primary: '#151515'
|
on-primary: '#151515'
|
||||||
primary-container: '#1f3a4a'
|
primary-container: '#3a1f1f'
|
||||||
on-primary-container: '#a8dcf5'
|
on-primary-container: '#d5a8a8'
|
||||||
inverse-primary: '#0e6e99'
|
inverse-primary: '#993e3e'
|
||||||
secondary: '#acc267'
|
secondary: '#acc267'
|
||||||
on-secondary: '#151515'
|
on-secondary: '#151515'
|
||||||
secondary-container: '#2a3320'
|
secondary-container: '#2a3320'
|
||||||
@@ -38,7 +38,7 @@ colors:
|
|||||||
surface-variant: '#353535'
|
surface-variant: '#353535'
|
||||||
suit-red: '#fb9fb1'
|
suit-red: '#fb9fb1'
|
||||||
suit-black: '#d0d0d0'
|
suit-black: '#d0d0d0'
|
||||||
suit-red-cb: '#6fc2ef'
|
suit-red-cb: '#acc267'
|
||||||
highlight-valid: '#acc267'
|
highlight-valid: '#acc267'
|
||||||
highlight-celebration: '#e1a3ee'
|
highlight-celebration: '#e1a3ee'
|
||||||
highlight-warning: '#ddb26f'
|
highlight-warning: '#ddb26f'
|
||||||
@@ -119,14 +119,16 @@ The palette is base16-eighties — a 16-slot terminal palette where indices 00
|
|||||||
| base09 | `#ddb26f` | orange — used for warning chips |
|
| base09 | `#ddb26f` | orange — used for warning chips |
|
||||||
| base0A | `#acc267` | yellow/lime — used for `highlight-valid` (drag targets, valid moves) |
|
| base0A | `#acc267` | yellow/lime — used for `highlight-valid` (drag targets, valid moves) |
|
||||||
| base0B | `#12cfc0` | green/teal — used for `highlight-info` (toasts, neutral status) |
|
| base0B | `#12cfc0` | green/teal — used for `highlight-info` (toasts, neutral status) |
|
||||||
| base0C | `#6fc2ef` | cyan/sky — primary CTA, focus ring, `selection`, `suit-red-cb` (color-blind tinted red) |
|
| base0C | `#6fc2ef` | cyan/sky — historically the primary CTA; now reserved for ad-hoc accents only |
|
||||||
| base0D | `#6fc2ef` | (alias) |
|
| base0D | `#6fc2ef` | (alias) |
|
||||||
|
| base08 (project) | `#a54242` | brick red — primary CTA, focus ring, `selection` (project-specific extension; the base16-eighties `base08` slot is `#fb9fb1` pink which we keep as `error`/`suit-red`) |
|
||||||
|
| `suit-red-cb` slot | `#acc267` | lime — color-blind-mode swap for red suits (was `#6fc2ef` cyan before the 2026-05-08 primary-accent swap; lime is the next-best non-red base16-eighties accent) |
|
||||||
| base0E | `#e1a3ee` | violet — used for celebration (level-up, achievement unlock) |
|
| base0E | `#e1a3ee` | violet — used for celebration (level-up, achievement unlock) |
|
||||||
| base0F | `#fb9fb1` | (alias) |
|
| base0F | `#fb9fb1` | (alias) |
|
||||||
|
|
||||||
### Semantic assignments
|
### Semantic assignments
|
||||||
|
|
||||||
- **CTA / Primary action**: cyan `#6fc2ef`. Reserved for "Play," "New Game," "Save," "Resume," and the focus ring on selected cards. Never used decoratively.
|
- **CTA / Primary action**: brick red `#a54242`. Reserved for "Play," "New Game," "Save," "Resume," and the focus ring on selected cards. Never used decoratively. (Was cyan `#6fc2ef` before the 2026-05-08 swap.)
|
||||||
- **Valid-move / drag-target highlight**: lime `#acc267`. Reserved for in-game feedback only. Never appears in chrome.
|
- **Valid-move / drag-target highlight**: lime `#acc267`. Reserved for in-game feedback only. Never appears in chrome.
|
||||||
- **Celebration**: lavender `#e1a3ee`. Used for level-up flashes, achievement unlock cards, and the daily-streak chip when the streak is active. Quiet otherwise.
|
- **Celebration**: lavender `#e1a3ee`. Used for level-up flashes, achievement unlock cards, and the daily-streak chip when the streak is active. Quiet otherwise.
|
||||||
- **Warning / soft alert**: gold `#ddb26f`. Used for "challenge expires in N minutes" chips, sync-pending status, and the daily-seed countdown.
|
- **Warning / soft alert**: gold `#ddb26f`. Used for "challenge expires in N minutes" chips, sync-pending status, and the daily-seed countdown.
|
||||||
@@ -135,18 +137,23 @@ The palette is base16-eighties — a 16-slot terminal palette where indices 00
|
|||||||
|
|
||||||
## Suit Colors
|
## Suit Colors
|
||||||
|
|
||||||
**Two-color traditional mapping**, with mandatory color-blind support:
|
**Two-color traditional pairing**, with mandatory color-blind
|
||||||
|
support. Saturated red for hearts + diamonds, near-white for clubs
|
||||||
|
+ spades — the "Microsoft Solitaire on dark mode" feel of a real
|
||||||
|
playing-card deck. (A brief 4-color-deck experiment shipped between
|
||||||
|
v0.21.0 and the next post-cut commit; reverted to traditional
|
||||||
|
2-color at the player's request.)
|
||||||
|
|
||||||
| Suit | Default | Color-blind mode | Glyph differentiation |
|
| Suit | Default | Color-blind mode | Glyph differentiation |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| Hearts | `#fb9fb1` (pink) | `#6fc2ef` (cyan) | Solid filled glyph |
|
| Hearts | `#e35353` (saturated red) | `#acc267` (lime) | Solid filled glyph |
|
||||||
| Diamonds | `#fb9fb1` (pink) | `#6fc2ef` (cyan) | **Outlined glyph (1.5px stroke)** |
|
| Diamonds | `#e35353` (saturated red) | `#acc267` (lime) | **Outlined glyph (1.5px stroke)** |
|
||||||
| Spades | `#d0d0d0` (foreground) | `#d0d0d0` | Solid filled glyph |
|
| Spades | `#e8e8e8` (near-white) | `#e8e8e8` (unchanged) | Solid filled glyph |
|
||||||
| Clubs | `#d0d0d0` (foreground) | `#d0d0d0` | **Outlined glyph (1.5px stroke)** |
|
| Clubs | `#e8e8e8` (near-white) | `#e8e8e8` (unchanged) | **Outlined glyph (1.5px stroke)** |
|
||||||
|
|
||||||
The outlined-glyph treatment is the **primary** differentiation mechanism. Color is supplementary. This means a player viewing the game on a monochrome display, or with severe red-green deficiency, can still distinguish all four suits without context. This is a hard requirement, not an optional setting.
|
The outlined-glyph treatment is the **primary** differentiation mechanism. Color is supplementary. This means a player viewing the game on a monochrome display, or with severe red-green deficiency, can still distinguish all four suits without context. This is a hard requirement, not an optional setting.
|
||||||
|
|
||||||
The "color-blind mode" toggle in Settings only swaps red→cyan; it does not turn the outlined glyphs on or off, because outlined glyphs are always on.
|
The "color-blind mode" toggle in Settings swaps both red suits (hearts + diamonds) from `#e35353` to `#acc267` (lime); clubs + spades stay at the near-white. The toggle does not turn the outlined glyphs on or off, because outlined glyphs are always on. (Was red→cyan before the 2026-05-08 primary-accent swap; CBM moved to lime to stay hue-distinct from the new red-family primary.)
|
||||||
|
|
||||||
## Typography
|
## Typography
|
||||||
|
|
||||||
@@ -177,7 +184,7 @@ Depth is created through **tonal layering and 1px outlines**, not blur shadows.
|
|||||||
- **Level 0 (Background)**: the `#151515` base canvas.
|
- **Level 0 (Background)**: the `#151515` base canvas.
|
||||||
- **Level 1 (Tableau slots, empty piles)**: 1px dashed outline in `#353535`. Empty foundations show a faint suit glyph at 12% opacity inside the outline.
|
- **Level 1 (Tableau slots, empty piles)**: 1px dashed outline in `#353535`. Empty foundations show a faint suit glyph at 12% opacity inside the outline.
|
||||||
- **Level 2 (Cards at rest)**: solid `#1a1a1a` fill, 1px solid border in the suit color (so the suit is detectable at a glance even if the card is partially obscured).
|
- **Level 2 (Cards at rest)**: solid `#1a1a1a` fill, 1px solid border in the suit color (so the suit is detectable at a glance even if the card is partially obscured).
|
||||||
- **Level 3 (Active / dragged card)**: same border, but glow effect: 0 0 12px of `#6fc2ef` at 40% opacity. **No scale transform** — flatness preserved. Z-index lifts above siblings.
|
- **Level 3 (Active / dragged card)**: same border, but glow effect: 0 0 12px of `#a54242` at 40% opacity. **No scale transform** — flatness preserved. Z-index lifts above siblings.
|
||||||
- **Modals**: full-screen with backdrop `#151515` at 95% opacity (just enough to dim the table without blurring it). Modal panel is `#202020` with a 1px `#505050` border — like a terminal pane.
|
- **Modals**: full-screen with backdrop `#151515` at 95% opacity (just enough to dim the table without blurring it). Modal panel is `#202020` with a 1px `#505050` border — like a terminal pane.
|
||||||
- **Toasts**: bottom of screen, `#202020` fill, 1px border in the toast's accent color (info=teal, warning=gold, error=pink, celebration=lavender). 16px monospaced caption.
|
- **Toasts**: bottom of screen, `#202020` fill, 1px border in the toast's accent color (info=teal, warning=gold, error=pink, celebration=lavender). 16px monospaced caption.
|
||||||
|
|
||||||
@@ -193,7 +200,7 @@ The shape language is **soft-rounded but tight**:
|
|||||||
- **Avatars / circular indicators**: `rounded-full`.
|
- **Avatars / circular indicators**: `rounded-full`.
|
||||||
- **Card-back pattern corners**: matches the card's `rounded-md`.
|
- **Card-back pattern corners**: matches the card's `rounded-md`.
|
||||||
|
|
||||||
Selection highlights use a **2px inset stroke** in `#6fc2ef` following the host shape's corner radius. Never an outer stroke — the outer stroke is reserved for the suit-color hairline.
|
Selection highlights use a **2px inset stroke** in `#a54242` following the host shape's corner radius. Never an outer stroke — the outer stroke is reserved for the suit-color hairline.
|
||||||
|
|
||||||
## Motion
|
## Motion
|
||||||
|
|
||||||
@@ -215,9 +222,9 @@ Selection highlights use a **2px inset stroke** in `#6fc2ef` following the host
|
|||||||
|
|
||||||
Flat face design.
|
Flat face design.
|
||||||
- Background: `#1a1a1a`
|
- Background: `#1a1a1a`
|
||||||
- Border: 1px solid in suit color (pink for hearts/diamonds, foreground gray for spades/clubs)
|
- Border: none. The card shape is defined by the body fill alone against the play surface. The earlier 1px suit-coloured border was removed because it produced visible anti-aliasing artifacts at the rounded corners (a "gray sliver" where the colored stroke faded through gray pixels into the dark play surface). The 5-unit brightness gap between `#1a1a1a` body and `#151515` surface is enough to read as a card edge without an explicit stroke.
|
||||||
- Top-left: rank in JetBrains Mono Bold 18px + small suit glyph (10px)
|
- Top-left: rank in JetBrains Mono Bold 18px + small suit glyph (10px)
|
||||||
- Bottom-right: large suit glyph (32px), rotated 180°
|
- Bottom-right: large suit glyph (32px), upright (same orientation as the top-left small glyph — single-orientation digital play does not benefit from the traditional 180° inverted-corner indicator)
|
||||||
- Corner radius: 8px
|
- Corner radius: 8px
|
||||||
- Suit differentiation: hearts and spades have **filled** glyphs; diamonds and clubs have **outlined** glyphs (1.5px stroke)
|
- Suit differentiation: hearts and spades have **filled** glyphs; diamonds and clubs have **outlined** glyphs (1.5px stroke)
|
||||||
|
|
||||||
@@ -228,17 +235,17 @@ Flat face design.
|
|||||||
- Background: `#151515`
|
- Background: `#151515`
|
||||||
- Pattern: horizontal scanlines at 2px pitch in `#1a1a1a` (1px line, 1px gap), full bleed
|
- Pattern: horizontal scanlines at 2px pitch in `#1a1a1a` (1px line, 1px gap), full bleed
|
||||||
- Border: 1px solid `#353535`
|
- Border: 1px solid `#353535`
|
||||||
- Top-left badge: a 12×16px solid `#6fc2ef` block (the "terminal cursor"), 6px from the corner
|
- Top-left badge: a 12×16px solid `#a54242` block (the "terminal cursor"), 6px from the corner
|
||||||
- Bottom-right monogram: the characters `▌RS` in JetBrains Mono 12px, color `#505050`, 6px from the corner
|
- Bottom-right monogram: the characters `▌RS` in JetBrains Mono 12px, color `#505050`, 6px from the corner
|
||||||
- Corner radius: 8px (matches face)
|
- Corner radius: 8px (matches face)
|
||||||
|
|
||||||
### Primary Buttons
|
### Primary Buttons
|
||||||
|
|
||||||
Solid `#6fc2ef` fill, `#151515` text, JetBrains Mono Medium 14px uppercase with `+0.08em` tracking. 4px corner radius. Pressed state: darken to `#5aa9d4`. Disabled: `#353535` fill, `#505050` text.
|
Solid `#a54242` fill, `#151515` text, JetBrains Mono Medium 14px uppercase with `+0.08em` tracking. 4px corner radius. Pressed state: darken to `#7a3030`. Disabled: `#353535` fill, `#505050` text.
|
||||||
|
|
||||||
### Secondary Buttons
|
### Secondary Buttons
|
||||||
|
|
||||||
Transparent fill, 1px `#505050` border, `#d0d0d0` text. Hover/press: border becomes `#6fc2ef`, text becomes `#6fc2ef`.
|
Transparent fill, 1px `#505050` border, `#d0d0d0` text. Hover/press: border becomes `#a54242`, text becomes `#a54242`.
|
||||||
|
|
||||||
### HUD Chips
|
### HUD Chips
|
||||||
|
|
||||||
@@ -258,7 +265,7 @@ Full-screen backdrop at 95% opacity. Centered panel: `#202020` fill, 1px `#50505
|
|||||||
|
|
||||||
### Navigation Bar
|
### Navigation Bar
|
||||||
|
|
||||||
Fixed at the bottom of in-game screens. Height: 64px. `#202020` fill, 1px top border in `#353535`. Four icon buttons: Undo / Hint / New / Auto-complete. Icons: 24px, 1.5px stroke weight, color `#d0d0d0`. Active/pressed: icon color `#6fc2ef`.
|
Fixed at the bottom of in-game screens. Height: 64px. `#202020` fill, 1px top border in `#353535`. Four icon buttons: Undo / Hint / New / Auto-complete. Icons: 24px, 1.5px stroke weight, color `#d0d0d0`. Active/pressed: icon color `#a54242`.
|
||||||
|
|
||||||
### Status / Sync Indicator
|
### Status / Sync Indicator
|
||||||
|
|
||||||
@@ -270,7 +277,7 @@ Top-right corner of the HUD: a 6px circular dot.
|
|||||||
|
|
||||||
## Accessibility
|
## Accessibility
|
||||||
|
|
||||||
1. **Color-blind mode** (Settings → Gameplay): swaps red suits' default `#fb9fb1` for `#6fc2ef`. Outlined-glyph differentiation remains active in *all* modes.
|
1. **Color-blind mode** (Settings → Gameplay): swaps the red suits' default `#e35353` for `#acc267` (lime). Outlined-glyph differentiation remains active in *all* modes.
|
||||||
2. **High-contrast mode** (Settings → Gameplay): boosts on-surface from `#d0d0d0` to `#f5f5f5`, outline from `#505050` to `#a0a0a0`, suit-red from `#fb9fb1` to `#ff8aa0`.
|
2. **High-contrast mode** (Settings → Gameplay): boosts on-surface from `#d0d0d0` to `#f5f5f5`, outline from `#505050` to `#a0a0a0`, suit-red from `#fb9fb1` to `#ff8aa0`.
|
||||||
3. **Reduce-motion mode** (Settings → Gameplay): disables card-lift transition (instant z-lift), disables CRT scanline effect, disables the warning-chip pulse animation.
|
3. **Reduce-motion mode** (Settings → Gameplay): disables card-lift transition (instant z-lift), disables CRT scanline effect, disables the warning-chip pulse animation.
|
||||||
4. **Tabular figures** are mandatory for any number that updates live (timer, score, moves) so they don't reflow.
|
4. **Tabular figures** are mandatory for any number that updates live (timer, score, moves) so they don't reflow.
|
||||||
|
|||||||
@@ -0,0 +1,283 @@
|
|||||||
|
# Terminal — Desktop Adaptation Spec
|
||||||
|
|
||||||
|
> **Why this exists.** The 24 mockups in this directory are mobile
|
||||||
|
> (390 × 844 logical, iPhone 14 Pro frame) with one exception
|
||||||
|
> (`home-menu-desktop.html`). The Stitch project that produced them
|
||||||
|
> is named "Solitaire Quest *Mobile* Redesign" — the mobile-first
|
||||||
|
> framing was deliberate when the new Android target opened, but
|
||||||
|
> desktop is still the primary delivery surface. Porting the mobile
|
||||||
|
> mockups 1:1 would land a 390-px-wide column floating in the middle
|
||||||
|
> of an 1800 × 1100 window. This file is the rules-based desktop
|
||||||
|
> companion — apply these adaptations whenever you port a Bevy
|
||||||
|
> plugin against a mobile mockup in this directory.
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
* **Token system.** All tokens (palette, type scale, spacing,
|
||||||
|
radii, motion) in `design-system.md` are layout-agnostic and
|
||||||
|
apply unchanged on both targets. Do **not** introduce desktop-
|
||||||
|
specific token variants — adapt geometry, not tokens.
|
||||||
|
* **Already adapted in code.** v0.20.0's port is layout-agnostic
|
||||||
|
(modal scaffold, toasts, table chrome, card chrome, gameplay-
|
||||||
|
feedback, splash cursor). Those surfaces already adapt
|
||||||
|
correctly because their Bevy UI nodes use flex / percent /
|
||||||
|
stretch sizing rather than fixed pixel widths from the
|
||||||
|
mockups.
|
||||||
|
* **Not yet adapted in code.** Any future plugin port that
|
||||||
|
copies layout from a mobile mockup must apply the rules below.
|
||||||
|
|
||||||
|
## Viewport assumptions
|
||||||
|
|
||||||
|
| Range | Width × height | Source |
|
||||||
|
|---|---|---|
|
||||||
|
| Mobile target | 390 × 844 | iPhone 14 Pro logical, Stitch mockup canvas |
|
||||||
|
| Desktop minimum | 1024 × 600 | Smaller windows degrade to mobile rules |
|
||||||
|
| Desktop default | ~70 % of monitor | `apply_smart_default_window_size` (since v0.19.0) |
|
||||||
|
| Desktop typical | 1600 × 900 to 2560 × 1440 | The range we tune for |
|
||||||
|
| Desktop max | 3840 × 2160 | 4K, with HiDPI scaling already applied |
|
||||||
|
|
||||||
|
The "smart default" sizer means a 1080p monitor opens a ~1344 × 756
|
||||||
|
window, a 1440p monitor opens ~1792 × 1008, a 4K monitor opens
|
||||||
|
~2688 × 1512. Tune for the 1600–2400 width band as the centre of
|
||||||
|
the distribution; below 1024 width, fall back to the mobile rules
|
||||||
|
verbatim.
|
||||||
|
|
||||||
|
## Universal adaptation rules
|
||||||
|
|
||||||
|
Apply these to every screen unless the per-screen section
|
||||||
|
overrides them.
|
||||||
|
|
||||||
|
### 1. Edge margins
|
||||||
|
|
||||||
|
| Mobile | Desktop |
|
||||||
|
|---|---|
|
||||||
|
| `margin-edge: 16px` (`SPACE_4`) | `SPACE_5` (24 px) for windows < 1440 wide; `SPACE_6` (32 px) for 1440–2400; `SPACE_7` (48 px) for ≥ 2400 |
|
||||||
|
|
||||||
|
Engine: drive from `LayoutResource` based on `Window` size, not a
|
||||||
|
constant.
|
||||||
|
|
||||||
|
### 2. Modal max-width
|
||||||
|
|
||||||
|
| Mobile | Desktop |
|
||||||
|
|---|---|
|
||||||
|
| `100% - 2 × edge-margin` | `min(720 px, 50 % of viewport)` |
|
||||||
|
|
||||||
|
The 720 px cap is already in `ui_modal::spawn_modal`. No code
|
||||||
|
change needed; this rule documents *why* it's there.
|
||||||
|
|
||||||
|
### 3. Vertical content stacks
|
||||||
|
|
||||||
|
A mobile screen often stacks `Header → Body → Footer` vertically
|
||||||
|
to fit a tall narrow column. On desktop, prefer horizontal
|
||||||
|
distribution where the content allows:
|
||||||
|
|
||||||
|
* **Header rows that stack vertically on mobile** (title above
|
||||||
|
count above timer) → keep them in one horizontal row on
|
||||||
|
desktop.
|
||||||
|
* **Two-column flex layouts** (e.g. Settings rows: label left,
|
||||||
|
control right) — already work on both targets; no change.
|
||||||
|
* **Cards stacking with `mt-48`-style fixed gaps** — replace with
|
||||||
|
flex / percent gaps so the layout breathes.
|
||||||
|
|
||||||
|
### 4. Touch-target minimums
|
||||||
|
|
||||||
|
Mobile spec mandates 48 dp minimum touch targets. Desktop has no
|
||||||
|
such floor (mouse precision is finer), but **don't shrink below
|
||||||
|
mobile's 48 px** for primary actions — keyboard / gamepad focus
|
||||||
|
rings still need a visible target.
|
||||||
|
|
||||||
|
Secondary controls (chip-style toggles, hotkey hints, etc.) can
|
||||||
|
shrink to `TYPE_BODY` (14 px) text + `SPACE_3` (12 px) padding on
|
||||||
|
desktop where they were larger on mobile.
|
||||||
|
|
||||||
|
### 5. Bottom-anchored elements
|
||||||
|
|
||||||
|
Mobile mockups often anchor key controls (action bar, primary CTA,
|
||||||
|
toast position) to the bottom of the viewport for thumb reach.
|
||||||
|
Desktop has no thumb-reach concern:
|
||||||
|
|
||||||
|
* **Toasts** — keep bottom-anchored (already done in `a137607`),
|
||||||
|
the design language is consistent across targets and the
|
||||||
|
bottom is still the least-disruptive overlay zone.
|
||||||
|
* **Action bars** — top of viewport on desktop unless the
|
||||||
|
per-screen section says otherwise. The HUD already sits on
|
||||||
|
top.
|
||||||
|
* **Single primary CTA** — modals already right-align in the
|
||||||
|
actions row; no change.
|
||||||
|
|
||||||
|
### 6. Typography rungs unchanged
|
||||||
|
|
||||||
|
Do **not** shift `TYPE_*` tokens up a rung for desktop. The
|
||||||
|
spec's 14 / 18 / 26 / 40 progression is already calibrated for
|
||||||
|
the desktop reading distance (60–90 cm). Mobile uses the same
|
||||||
|
rungs at a closer reading distance (30–40 cm); same physical
|
||||||
|
angular size on the eye.
|
||||||
|
|
||||||
|
### 7. Hotkey hints become full strings
|
||||||
|
|
||||||
|
Mobile cells like `▌Esc` — the cursor block plus key letter — can
|
||||||
|
expand to `[Esc] cancel` style on desktop where horizontal
|
||||||
|
real-estate is cheap. Drives discoverability of keyboard-only
|
||||||
|
flows. Optional; only apply where horizontal space exists.
|
||||||
|
|
||||||
|
## Per-screen adaptation rules
|
||||||
|
|
||||||
|
### Game Table
|
||||||
|
|
||||||
|
Mockup: `game-table-mobile.html` (390 × 844).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| HUD band | full width, 56 px tall | full width, 48 px tall |
|
||||||
|
| Foundation row | 4 piles centred, fan-tight | 4 piles centred, **gutter doubled** so the row fills ~50 % of viewport width |
|
||||||
|
| Stock + waste | left of foundations, stacked | left of foundations, **horizontal pair**: stock on the left, waste to its immediate right (the mobile vertical pair feels cramped on a wide canvas) |
|
||||||
|
| Tableau row | 7 columns, 4 % gutter | 7 columns, **6 % gutter**, total tableau block ≤ 70 % viewport width |
|
||||||
|
| Card aspect | 2 : 3 (already in `Layout::card_size`) | unchanged — card aspect is domain |
|
||||||
|
| Tableau fan | `TABLEAU_FAN_FRAC = 0.25` | unchanged — fan is in card-height units, not viewport units |
|
||||||
|
| Drag-shadow offset | small | unchanged — pinned to 0 alpha under Terminal anyway |
|
||||||
|
|
||||||
|
**Engine impact:** `solitaire_engine/src/layout.rs::compute_layout`
|
||||||
|
already drives most of this from `Window::size()`. The mobile vs.
|
||||||
|
desktop difference is the gutter percentages — bake desktop
|
||||||
|
gutters when window width ≥ 1024.
|
||||||
|
|
||||||
|
### Win Summary
|
||||||
|
|
||||||
|
Mockup: `win-summary-mobile.html` (390 × 858).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| Modal width | 100 % − 2 × edge | **`min(720 px, 50 % viewport)`** (already done by `ui_modal`) |
|
||||||
|
| Score row | stacked vertically (line per metric) | **3-column grid**: Score / Time / Moves in one row, breakdown rows below in single-line per row |
|
||||||
|
| Action buttons | full-width stacked (Play Again, Continue, Stats) | **right-aligned action row** — the existing `spawn_modal_actions` already does this on both targets |
|
||||||
|
|
||||||
|
**Engine impact:** `solitaire_engine/src/win_summary_plugin.rs`. The
|
||||||
|
score-breakdown-stagger animation (`MOTION_SCORE_BREAKDOWN_*`) is
|
||||||
|
unchanged across targets.
|
||||||
|
|
||||||
|
### Settings
|
||||||
|
|
||||||
|
Mockup: `settings-mobile.html` (390 × 4330 — long scroll).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| Modal width | 100 % − 2 × edge | `min(720 px, 50 % viewport)` |
|
||||||
|
| Sections | full-width labels above stacked controls | **section labels left, control widget right** — already the engine's pattern; no change |
|
||||||
|
| Long page | scroll the whole modal | **two-column layout**: nav (sections list) on left ~30 %, current section on right ~70 %. Reduces scroll distance on desktop |
|
||||||
|
| Sliders | full-width on mobile | cap at 320 px on desktop |
|
||||||
|
|
||||||
|
**Engine impact:** if a desktop port wants the two-column nav, it's
|
||||||
|
a `settings_plugin` rewrite. Keep the existing single-column
|
||||||
|
stacked-modal layout for now — it works on both targets and the
|
||||||
|
two-column variant is a polish item, not a blocker.
|
||||||
|
|
||||||
|
### Help & Controls
|
||||||
|
|
||||||
|
Mockup: `help-mobile.html` (390 × 2544).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| Modal width | 100 % − 2 × edge | `min(720 px, 50 % viewport)` |
|
||||||
|
| Section list | one column of `Heading → 2-col rows` | **two columns of section blocks** for windows ≥ 1280 wide; halves vertical scroll distance |
|
||||||
|
| Hotkey rows | `key | description` 2-col flex | unchanged; 2-col already adapts |
|
||||||
|
|
||||||
|
**Engine impact:** `help_plugin`. Single-column on mobile, 2-col
|
||||||
|
on desktop windows ≥ 1280 wide is a flex-wrap option.
|
||||||
|
|
||||||
|
### Pause Menu
|
||||||
|
|
||||||
|
Mockup: `pause-menu-mobile.html` (390 × 1768).
|
||||||
|
|
||||||
|
Already a small modal; no significant geometry change. Modal
|
||||||
|
already uses `ui_modal::spawn_modal` which caps width and centres.
|
||||||
|
No desktop-specific rule.
|
||||||
|
|
||||||
|
### Home Menu
|
||||||
|
|
||||||
|
Mockup: `home-menu-mobile.html` and `home-menu-desktop.html`
|
||||||
|
(both already in this directory — desktop variant is the
|
||||||
|
authoritative reference).
|
||||||
|
|
||||||
|
The desktop mockup already specifies the layout. Cross-check it
|
||||||
|
against the mobile version when porting; differences are
|
||||||
|
deliberate (more horizontal real-estate, larger primary CTA, the
|
||||||
|
secondary actions row).
|
||||||
|
|
||||||
|
### Splash
|
||||||
|
|
||||||
|
Mockup: `splash-mobile.html` (390 × 844).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| Full-screen overlay | `inset-0` | unchanged — splash always covers the viewport |
|
||||||
|
| Cursor block (`▌`) | 96 px JetBrains Mono | unchanged — already done in `cdcadda`. The 96 px size scales fine on desktop because the splash is a brand beat, not a layout-driven element |
|
||||||
|
| Title `RUSTY SOLITAIRE` | 32 px | scale to 40 px (`TYPE_DISPLAY`) on desktop |
|
||||||
|
| Subtitle `TERMINAL EDITION` | 12 px | unchanged |
|
||||||
|
| Boot log lines | 70 % width column | cap at 480 px so the column doesn't stretch on a wide window |
|
||||||
|
| Progress bar | 100 % − 2 × edge | cap at 720 px |
|
||||||
|
| Palette swatch row + version footer | bottom-anchored | unchanged; bottom-anchor still reads correctly on desktop |
|
||||||
|
|
||||||
|
**Engine impact:** `splash_plugin` already has the cursor block
|
||||||
|
(`cdcadda`). The boot log / progress bar / palette swatch rows
|
||||||
|
are the next polish increment when option D is picked up.
|
||||||
|
|
||||||
|
### Stats
|
||||||
|
|
||||||
|
Mockup: `stats-mobile.html` (390 × 2624).
|
||||||
|
|
||||||
|
| Element | Mobile | Desktop |
|
||||||
|
|---|---|---|
|
||||||
|
| Modal width | 100 % − 2 × edge | `min(720 px, 50 % viewport)` |
|
||||||
|
| Big-number cards | 2 × 2 grid | **4 × 1 row** for windows ≥ 1024 wide (the four headline metrics fit in a single horizontal row at desktop scale) |
|
||||||
|
| Latest-win caption | full-width line | unchanged |
|
||||||
|
| Replay clip / share row | full-width row | unchanged |
|
||||||
|
|
||||||
|
### Profile / Achievements / Theme Picker / Daily Challenge
|
||||||
|
|
||||||
|
These follow the **standard modal pattern** (`spawn_modal` with
|
||||||
|
header / body / actions). They already work on desktop because
|
||||||
|
`ui_modal` handles modal-width capping. Per-screen tweaks are
|
||||||
|
small and listed below; no structural changes:
|
||||||
|
|
||||||
|
* **Profile** — avatar + level / streak chips can flow into a
|
||||||
|
single horizontal row on desktop instead of stacking.
|
||||||
|
* **Achievements** — 3 × N grid on mobile becomes 4 × N or 5 × N
|
||||||
|
on desktop where windows ≥ 1280 wide.
|
||||||
|
* **Theme Picker** — 2-col grid of theme cards on mobile becomes
|
||||||
|
3- or 4-col on desktop.
|
||||||
|
* **Daily Challenge** — single-column scroll on both; no change.
|
||||||
|
|
||||||
|
## Mockup parity gap
|
||||||
|
|
||||||
|
The 9 missing-plugin screens (`splash`, `challenge`, `time-attack`,
|
||||||
|
`weekly-goals`, `leaderboard`, `sync`, `level-up`, `replay-overlay`,
|
||||||
|
`radial-menu`) have only mobile mockups. When porting any of these
|
||||||
|
plugins:
|
||||||
|
|
||||||
|
1. Read the mobile mockup for content + visual hierarchy.
|
||||||
|
2. Apply the universal adaptation rules above.
|
||||||
|
3. Apply the closest matching per-screen rule (e.g. an info modal
|
||||||
|
uses the same shape as Win Summary or Stats).
|
||||||
|
4. **No new layout pattern without explicit user approval.**
|
||||||
|
Adapting an existing pattern is in scope; inventing a desktop-
|
||||||
|
specific component is design work and should be flagged as such.
|
||||||
|
|
||||||
|
## Process notes
|
||||||
|
|
||||||
|
* **Smart-default sizer is the layout's source of truth.** Before
|
||||||
|
reading the mockup, always re-read `Window::size()` —
|
||||||
|
`apply_smart_default_window_size` runs at startup and the
|
||||||
|
player can resize freely. Hardcoded breakpoints in plugin code
|
||||||
|
should reference the *current* `Window` width via a
|
||||||
|
`LayoutResource` lookup, not the launch size.
|
||||||
|
* **`WindowResized` already drives layout recomputes** (CLAUDE.md
|
||||||
|
§3.4). Any per-window-width adaptation in this file should hook
|
||||||
|
into the existing recompute path, not a new system.
|
||||||
|
* **Mobile rules win at narrow desktop windows.** A user dragging
|
||||||
|
their desktop window down to 600 px width is closer to the
|
||||||
|
mobile use-case than the desktop one. Below 1024 px width,
|
||||||
|
apply the mobile rules verbatim.
|
||||||
|
* **Run on a 4K monitor before declaring a port done.** HiDPI
|
||||||
|
scaling routes through Bevy's logical sizing, but visual
|
||||||
|
polish (border thickness, motion budgets at high refresh rate)
|
||||||
|
is worth eyeballing.
|
||||||
@@ -22,16 +22,25 @@ bevy = { workspace = true }
|
|||||||
solitaire_engine = { workspace = true }
|
solitaire_engine = { workspace = true }
|
||||||
solitaire_data = { workspace = true }
|
solitaire_data = { workspace = true }
|
||||||
|
|
||||||
# `keyring`'s default-store init only matters on platforms with a
|
# Desktop-only deps. `keyring`'s default-store init only matters on
|
||||||
# real keychain backend (Linux Secret Service, macOS Keychain,
|
# platforms with a real keychain backend (Linux Secret Service,
|
||||||
# Windows Credential Store). The crate also pulls `rpassword`
|
# macOS Keychain, Windows Credential Store), and its transitive
|
||||||
# transitively, which uses `libc::__errno_location` — a symbol
|
# `rpassword` uses `libc::__errno_location` — a symbol Android's
|
||||||
# Android's bionic doesn't expose. Target-gating keeps
|
# bionic doesn't expose. `winit` is promoted from a transitive
|
||||||
# `cargo apk build` viable; the call site in `lib.rs` has its own
|
# Bevy 0.18 → bevy_winit 0.18 → winit 0.30 dep to a direct dep so
|
||||||
# `cfg(not(target_os = "android"))` guard so the desktop init path
|
# the `Window::icon` wiring in `set_window_icon` can construct
|
||||||
# is unchanged.
|
# `winit::window::Icon` values (bevy_winit 0.18 doesn't re-export
|
||||||
|
# `Icon`). Android draws its launcher icon from the APK manifest,
|
||||||
|
# so neither dep matters there. Target-gating keeps `cargo apk
|
||||||
|
# build` viable; the desktop call sites have their own
|
||||||
|
# `cfg(not(target_os = "android"))` guards.
|
||||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
keyring = { workspace = true }
|
keyring = { workspace = true }
|
||||||
|
winit = { version = "0.30", default-features = false }
|
||||||
|
# `tiny-skia` is already in the workspace deps for `solitaire_engine`;
|
||||||
|
# `solitaire_app` consumes it directly only on the desktop icon path
|
||||||
|
# (PNG → raw RGBA decode for `set_window_icon`).
|
||||||
|
tiny-skia = { workspace = true }
|
||||||
|
|
||||||
# --- Android packaging metadata (read by `cargo-apk`) -------------------
|
# --- Android packaging metadata (read by `cargo-apk`) -------------------
|
||||||
#
|
#
|
||||||
@@ -51,6 +60,15 @@ package = "com.solitairequest.app"
|
|||||||
apk_name = "solitaire-quest"
|
apk_name = "solitaire-quest"
|
||||||
build_targets = ["aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android"]
|
build_targets = ["aarch64-linux-android", "armv7-linux-androideabi", "x86_64-linux-android"]
|
||||||
assets = "../assets"
|
assets = "../assets"
|
||||||
|
# Density-bucketed launcher icons. `aapt` processes `res/mipmap-*/` and
|
||||||
|
# packages them into the APK; the launcher selects the best-fit bucket
|
||||||
|
# for the device screen density. Sizes used:
|
||||||
|
# mdpi (1×, 48 dp) → 48 px (exact)
|
||||||
|
# hdpi (1.5×, 72 dp) → 64 px (88 %, aapt scales up slightly)
|
||||||
|
# xhdpi (2×, 96 dp) → 128 px (133 %, aapt scales down)
|
||||||
|
# xxhdpi (3×, 144 dp) → 256 px (178 %, aapt scales down)
|
||||||
|
# xxxhdpi (4×, 192 dp) → 256 px (133 %, aapt scales down)
|
||||||
|
resources = "res"
|
||||||
# No `runtime_libs` — we don't ship any precompiled .so files,
|
# No `runtime_libs` — we don't ship any precompiled .so files,
|
||||||
# the entire app is pure Rust + Bevy. cargo-apk would try to
|
# the entire app is pure Rust + Bevy. cargo-apk would try to
|
||||||
# resolve `runtime_libs/<arch>/` if set, and fail on a non-existent
|
# resolve `runtime_libs/<arch>/` if set, and fail on a non-existent
|
||||||
@@ -70,6 +88,14 @@ name = "android.permission.INTERNET"
|
|||||||
|
|
||||||
[package.metadata.android.application]
|
[package.metadata.android.application]
|
||||||
label = "Solitaire Quest"
|
label = "Solitaire Quest"
|
||||||
|
# Launcher icon — references the density-bucketed mipmap resource above.
|
||||||
|
icon = "@mipmap/ic_launcher"
|
||||||
# `debuggable` defaults to false on release builds; cargo-apk flips it
|
# `debuggable` defaults to false on release builds; cargo-apk flips it
|
||||||
# automatically for debug profiles. Leaving the field unset keeps the
|
# automatically for debug profiles. Leaving the field unset keeps the
|
||||||
# default behaviour.
|
# default behaviour.
|
||||||
|
|
||||||
|
[package.metadata.android.application.activity]
|
||||||
|
# Lock to portrait — the current layout has only been designed and tested
|
||||||
|
# in portrait orientation. Remove (or add a landscape layout) before
|
||||||
|
# enabling auto-rotate.
|
||||||
|
orientation = "portrait"
|
||||||
|
|||||||
|
After Width: | Height: | Size: 927 B |
|
After Width: | Height: | Size: 759 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
@@ -18,19 +18,23 @@ use std::io::Write;
|
|||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::{
|
use bevy::window::{MonitorSelection, PresentMode, WindowPosition};
|
||||||
Monitor, MonitorSelection, PresentMode, PrimaryMonitor, PrimaryWindow, WindowPosition,
|
#[cfg(not(target_os = "android"))]
|
||||||
};
|
use bevy::window::{Monitor, PrimaryMonitor, PrimaryWindow};
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
use bevy::winit::WinitWindows;
|
||||||
use solitaire_data::{load_settings_from, provider_for_backend, settings_file_path, Settings};
|
use solitaire_data::{load_settings_from, provider_for_backend, settings_file_path, Settings};
|
||||||
use solitaire_engine::{
|
use solitaire_engine::{
|
||||||
register_theme_asset_sources, AchievementPlugin, AnimationPlugin, AssetSourcesPlugin,
|
register_theme_asset_sources, AchievementPlugin, AnimationPlugin, AssetSourcesPlugin,
|
||||||
AudioPlugin, AutoCompletePlugin, CardAnimationPlugin, CardPlugin, ChallengePlugin,
|
AudioPlugin, AutoCompletePlugin, CardAnimationPlugin, CardPlugin, ChallengePlugin,
|
||||||
CursorPlugin, DailyChallengePlugin, DiagnosticsHudPlugin, FeedbackAnimPlugin, FontPlugin,
|
CursorPlugin, DailyChallengePlugin, DiagnosticsHudPlugin, DifficultyPlugin, FeedbackAnimPlugin,
|
||||||
GamePlugin, HelpPlugin, HomePlugin, HudPlugin, InputPlugin, LeaderboardPlugin,
|
FontPlugin, GamePlugin, HelpPlugin, HomePlugin, HudPlugin, InputPlugin, LeaderboardPlugin,
|
||||||
OnboardingPlugin, PausePlugin, ProfilePlugin, ProgressPlugin, RadialMenuPlugin,
|
OnboardingPlugin, PausePlugin, PlayBySeedPlugin, ProfilePlugin, ProgressPlugin,
|
||||||
ReplayOverlayPlugin, ReplayPlaybackPlugin, SelectionPlugin, SettingsPlugin, SplashPlugin,
|
RadialMenuPlugin, ReplayOverlayPlugin, ReplayPlaybackPlugin, SafeAreaInsetsPlugin,
|
||||||
StatsPlugin, SyncPlugin, TablePlugin, ThemePlugin, ThemeRegistryPlugin, TimeAttackPlugin,
|
SelectionPlugin, SettingsPlugin,
|
||||||
UiFocusPlugin, UiModalPlugin, UiTooltipPlugin, WeeklyGoalsPlugin, WinSummaryPlugin,
|
SplashPlugin, StatsPlugin, SyncPlugin, SyncSetupPlugin, TablePlugin, ThemePlugin, ThemeRegistryPlugin,
|
||||||
|
TimeAttackPlugin, UiFocusPlugin, UiModalPlugin, UiTooltipPlugin, WeeklyGoalsPlugin,
|
||||||
|
WinSummaryPlugin,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// App entry point — builds and runs the Bevy app.
|
/// App entry point — builds and runs the Bevy app.
|
||||||
@@ -74,6 +78,7 @@ pub fn run() {
|
|||||||
// primary monitor) — `apply_smart_default_window_size` will resize
|
// primary monitor) — `apply_smart_default_window_size` will resize
|
||||||
// up to a monitor-relative target on the first frame so HiDPI / 4K
|
// up to a monitor-relative target on the first frame so HiDPI / 4K
|
||||||
// sessions don't end up with a comparatively tiny window.
|
// sessions don't end up with a comparatively tiny window.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
let had_saved_geometry = settings.window_geometry.is_some();
|
let had_saved_geometry = settings.window_geometry.is_some();
|
||||||
let (window_resolution, window_position) = match settings.window_geometry {
|
let (window_resolution, window_position) = match settings.window_geometry {
|
||||||
Some(geom) => (
|
Some(geom) => (
|
||||||
@@ -114,6 +119,9 @@ pub fn run() {
|
|||||||
// small enough that a few stray dropped frames from
|
// small enough that a few stray dropped frames from
|
||||||
// disabling vsync are imperceptible.
|
// disabling vsync are imperceptible.
|
||||||
present_mode: PresentMode::AutoNoVsync,
|
present_mode: PresentMode::AutoNoVsync,
|
||||||
|
// Android windows always fill the screen; max_width/max_height
|
||||||
|
// default to 0.0, which panics Bevy's clamp when min > max.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
resize_constraints: bevy::window::WindowResizeConstraints {
|
resize_constraints: bevy::window::WindowResizeConstraints {
|
||||||
min_width: 800.0,
|
min_width: 800.0,
|
||||||
min_height: 600.0,
|
min_height: 600.0,
|
||||||
@@ -124,11 +132,20 @@ pub fn run() {
|
|||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
// The `assets/` directory lives at the workspace root, but
|
// The `assets/` directory lives at the workspace root, but
|
||||||
// Bevy resolves `AssetPlugin::file_path` relative to the
|
// on desktop Bevy resolves `AssetPlugin::file_path` relative
|
||||||
// binary package's `CARGO_MANIFEST_DIR` (`solitaire_app/`).
|
// to the binary package's `CARGO_MANIFEST_DIR`
|
||||||
// Point one level up so `cargo run -p solitaire_app` finds
|
// (`solitaire_app/`), so `cargo run -p solitaire_app` would
|
||||||
// card faces, backs, backgrounds, and the UI font.
|
// miss the workspace-root `assets/` without a `../` prefix.
|
||||||
|
//
|
||||||
|
// On Android cargo-apk packages the same directory into the
|
||||||
|
// APK at `assets/` (via `[package.metadata.android].assets`
|
||||||
|
// in solitaire_app/Cargo.toml). Bevy's `AndroidAssetReader`
|
||||||
|
// is already rooted there, so any `file_path` other than the
|
||||||
|
// default makes it walk *out* of the APK's assets root and
|
||||||
|
// all loads fail silently — which is what produced the
|
||||||
|
// solid-red card-back fallback in the v0.22.3 screenshot.
|
||||||
.set(bevy::asset::AssetPlugin {
|
.set(bevy::asset::AssetPlugin {
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
file_path: "../assets".to_string(),
|
file_path: "../assets".to_string(),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
@@ -140,6 +157,13 @@ pub fn run() {
|
|||||||
.add_plugins(GamePlugin)
|
.add_plugins(GamePlugin)
|
||||||
.add_plugins(TablePlugin)
|
.add_plugins(TablePlugin)
|
||||||
.add_plugins(CardPlugin)
|
.add_plugins(CardPlugin)
|
||||||
|
// Cursor-icon feedback is desktop-only; Android has no pointer cursor.
|
||||||
|
// The drop-target highlight systems (update_drop_highlights,
|
||||||
|
// update_drop_target_overlays) live in CursorPlugin but ARE useful
|
||||||
|
// on Android — they've been left running because their Bevy system
|
||||||
|
// params compile and function on Android; only the CursorIcon insert
|
||||||
|
// is inert. Gate the whole plugin if the cursor APIs ever cause
|
||||||
|
// Android linker issues; for now it's harmless to leave it registered.
|
||||||
.add_plugins(CursorPlugin)
|
.add_plugins(CursorPlugin)
|
||||||
.add_plugins(InputPlugin)
|
.add_plugins(InputPlugin)
|
||||||
.add_plugins(RadialMenuPlugin)
|
.add_plugins(RadialMenuPlugin)
|
||||||
@@ -156,7 +180,10 @@ pub fn run() {
|
|||||||
.add_plugins(DailyChallengePlugin)
|
.add_plugins(DailyChallengePlugin)
|
||||||
.add_plugins(WeeklyGoalsPlugin)
|
.add_plugins(WeeklyGoalsPlugin)
|
||||||
.add_plugins(ChallengePlugin)
|
.add_plugins(ChallengePlugin)
|
||||||
|
.add_plugins(PlayBySeedPlugin)
|
||||||
|
.add_plugins(DifficultyPlugin)
|
||||||
.add_plugins(TimeAttackPlugin)
|
.add_plugins(TimeAttackPlugin)
|
||||||
|
.add_plugins(SafeAreaInsetsPlugin)
|
||||||
.add_plugins(HudPlugin)
|
.add_plugins(HudPlugin)
|
||||||
.add_plugins(HelpPlugin)
|
.add_plugins(HelpPlugin)
|
||||||
.add_plugins(HomePlugin::default())
|
.add_plugins(HomePlugin::default())
|
||||||
@@ -166,6 +193,7 @@ pub fn run() {
|
|||||||
.add_plugins(AudioPlugin)
|
.add_plugins(AudioPlugin)
|
||||||
.add_plugins(OnboardingPlugin)
|
.add_plugins(OnboardingPlugin)
|
||||||
.add_plugins(SyncPlugin::new(sync_provider))
|
.add_plugins(SyncPlugin::new(sync_provider))
|
||||||
|
.add_plugins(SyncSetupPlugin)
|
||||||
.add_plugins(LeaderboardPlugin)
|
.add_plugins(LeaderboardPlugin)
|
||||||
.add_plugins(WinSummaryPlugin)
|
.add_plugins(WinSummaryPlugin)
|
||||||
.add_plugins(UiModalPlugin)
|
.add_plugins(UiModalPlugin)
|
||||||
@@ -174,6 +202,14 @@ pub fn run() {
|
|||||||
.add_plugins(SplashPlugin)
|
.add_plugins(SplashPlugin)
|
||||||
.add_plugins(DiagnosticsHudPlugin);
|
.add_plugins(DiagnosticsHudPlugin);
|
||||||
|
|
||||||
|
// Wire the runtime window icon. Bevy 0.18 has no first-class
|
||||||
|
// `Window::icon` field; the icon is set through the underlying
|
||||||
|
// `winit::window::Window` via `WinitWindows`. Android draws its
|
||||||
|
// launcher icon from the APK manifest, so the system is desktop-
|
||||||
|
// only — same target-gate as the `winit` dep itself.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
app.add_systems(Update, set_window_icon);
|
||||||
|
|
||||||
// Smart default window sizing: when no saved geometry was loaded,
|
// Smart default window sizing: when no saved geometry was loaded,
|
||||||
// resize the freshly-opened 1280×800 window to ~70 % of the primary
|
// resize the freshly-opened 1280×800 window to ~70 % of the primary
|
||||||
// monitor's logical size on the first frame. Without this, a 4K
|
// monitor's logical size on the first frame. Without this, a 4K
|
||||||
@@ -185,6 +221,8 @@ pub fn run() {
|
|||||||
// every fresh launch can flip `disable_smart_default_size` in
|
// every fresh launch can flip `disable_smart_default_size` in
|
||||||
// Settings to opt out. The flag is checked once at startup; a
|
// Settings to opt out. The flag is checked once at startup; a
|
||||||
// mid-session change applies on the next launch.
|
// mid-session change applies on the next launch.
|
||||||
|
// Android windows are always full-screen; the OS controls sizing.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
if !had_saved_geometry && !settings.disable_smart_default_size {
|
if !had_saved_geometry && !settings.disable_smart_default_size {
|
||||||
app.add_systems(Update, apply_smart_default_window_size);
|
app.add_systems(Update, apply_smart_default_window_size);
|
||||||
}
|
}
|
||||||
@@ -205,6 +243,7 @@ pub fn run() {
|
|||||||
/// a dedicated resource. The Update tick is necessary because Bevy
|
/// a dedicated resource. The Update tick is necessary because Bevy
|
||||||
/// populates the `Monitor` entities asynchronously after winit's
|
/// populates the `Monitor` entities asynchronously after winit's
|
||||||
/// Resumed event fires; they may not exist on the first Startup pass.
|
/// Resumed event fires; they may not exist on the first Startup pass.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
fn apply_smart_default_window_size(
|
fn apply_smart_default_window_size(
|
||||||
mut applied: Local<bool>,
|
mut applied: Local<bool>,
|
||||||
monitors: Query<&Monitor, With<PrimaryMonitor>>,
|
monitors: Query<&Monitor, With<PrimaryMonitor>>,
|
||||||
@@ -251,6 +290,94 @@ fn apply_smart_default_window_size(
|
|||||||
*applied = true;
|
*applied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One-shot Update system that sets the primary window's taskbar /
|
||||||
|
/// title-bar icon to the embedded 256 px Terminal-aesthetic mark
|
||||||
|
/// generated by `solitaire_engine/examples/icon_generator.rs`.
|
||||||
|
///
|
||||||
|
/// Bevy 0.18 has no `Window::icon` field — the icon is set through
|
||||||
|
/// the underlying `winit::window::Window` via the `WinitWindows`
|
||||||
|
/// resource. The system is desktop-only (Android draws its launcher
|
||||||
|
/// icon from the APK manifest, not from any runtime call). Returns
|
||||||
|
/// silently and tries again next frame until both the primary
|
||||||
|
/// window and `WinitWindows` are populated, then sets the icon
|
||||||
|
/// once and self-disables via `Local<bool>`.
|
||||||
|
///
|
||||||
|
/// Icon bytes are `include_bytes!()`-embedded at compile time, same
|
||||||
|
/// shape as the audio assets and default-theme SVGs — no runtime
|
||||||
|
/// asset-path resolution, no `cargo run` working-directory
|
||||||
|
/// assumptions. PNG → RGBA decode runs through `tiny_skia` (already
|
||||||
|
/// in the build for SVG rasterisation), so this system adds zero
|
||||||
|
/// new dependencies on top of the direct `winit` dep that's
|
||||||
|
/// already required for `Icon` construction.
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
fn set_window_icon(
|
||||||
|
mut applied: Local<bool>,
|
||||||
|
primary_window: Query<Entity, With<PrimaryWindow>>,
|
||||||
|
// `Option<NonSend<...>>` rather than `NonSend<...>` because Bevy
|
||||||
|
// 0.18's stricter system-param validation panics on the first
|
||||||
|
// few frames before `WinitWindows` is inserted (the resource is
|
||||||
|
// populated after winit's `Resumed` event, which fires after
|
||||||
|
// the first system-tick batch). The early-return below handles
|
||||||
|
// the `None` window-wrapper case for the same lifecycle reason.
|
||||||
|
winit_windows: Option<NonSend<WinitWindows>>,
|
||||||
|
) {
|
||||||
|
if *applied {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(winit_windows) = winit_windows else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Ok(primary_entity) = primary_window.single() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(window_wrapper) = winit_windows.get_window(primary_entity) else {
|
||||||
|
// Primary window's underlying winit handle not yet
|
||||||
|
// populated — `WinitWindows` fills in after the first
|
||||||
|
// `Resumed` event. Try again next frame.
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
// The 256 × 256 PNG is sufficient for `set_window_icon`; winit
|
||||||
|
// scales it for the actual rendered size. Smaller PNGs in
|
||||||
|
// `assets/icon/` exist for downstream Linux hicolor / Windows
|
||||||
|
// `.ico` / macOS `.icns` packaging — they're not used here.
|
||||||
|
const ICON_BYTES: &[u8] = include_bytes!("../../assets/icon/icon_256.png");
|
||||||
|
|
||||||
|
let pixmap = match tiny_skia::Pixmap::decode_png(ICON_BYTES) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("warn: could not decode embedded window icon PNG: {e}");
|
||||||
|
*applied = true; // don't retry every frame
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let rgba = pixmap.data().to_vec();
|
||||||
|
let icon = match winit::window::Icon::from_rgba(rgba, pixmap.width(), pixmap.height()) {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("warn: could not construct window icon: {e}");
|
||||||
|
*applied = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window_wrapper.set_window_icon(Some(icon));
|
||||||
|
*applied = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Android entry point called by NativeActivity after dlopen-ing the `.so`.
|
||||||
|
/// Sets the `AndroidApp` handle that Bevy's winit backend reads before
|
||||||
|
/// constructing the event loop, then delegates to [`run`].
|
||||||
|
///
|
||||||
|
/// The `#[bevy_main]` proc-macro would generate the same code but only
|
||||||
|
/// works on a function named `main`; our shared entry point is `run`, so
|
||||||
|
/// we emit the equivalent expansion manually.
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
fn android_main(android_app: bevy::android::android_activity::AndroidApp) {
|
||||||
|
let _ = bevy::android::ANDROID_APP.set(android_app);
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
/// Wraps the default panic hook with one that also appends a crash log
|
/// Wraps the default panic hook with one that also appends a crash log
|
||||||
/// to `<data_dir>/crash.log` (next to `settings.json`). The default hook
|
/// to `<data_dir>/crash.log` (next to `settings.json`). The default hook
|
||||||
/// still runs afterwards, so stderr output and debugger integration are
|
/// still runs afterwards, so stderr output and debugger integration are
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
png = "0.17"
|
png = "0.17"
|
||||||
ab_glyph = "0.2"
|
ab_glyph = "0.2"
|
||||||
|
solitaire_core = { path = "../solitaire_core" }
|
||||||
|
solitaire_data = { path = "../solitaire_data" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "gen_sfx"
|
name = "gen_sfx"
|
||||||
@@ -20,3 +22,11 @@ path = "src/bin/gen_sfx.rs"
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "gen_art"
|
name = "gen_art"
|
||||||
path = "src/bin/gen_art.rs"
|
path = "src/bin/gen_art.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "gen_seeds"
|
||||||
|
path = "src/bin/gen_seeds.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "gen_difficulty_seeds"
|
||||||
|
path = "src/bin/gen_difficulty_seeds.rs"
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
//! Generate difficulty-stratified seed catalogs for `EASY_SEEDS`, `MEDIUM_SEEDS`,
|
||||||
|
//! `HARD_SEEDS`, `EXPERT_SEEDS`, and `GRANDMASTER_SEEDS` in
|
||||||
|
//! `solitaire_data/src/difficulty_seeds.rs`.
|
||||||
|
//!
|
||||||
|
//! A seed's tier is determined by the **smallest** `SolverConfig` budget that
|
||||||
|
//! returns `SolverResult::Winnable`. Seeds that are `Unwinnable` at any budget
|
||||||
|
//! are discarded; `Inconclusive` at all budgets are also discarded (we only emit
|
||||||
|
//! provably-winnable seeds).
|
||||||
|
//!
|
||||||
|
//! # Usage
|
||||||
|
//!
|
||||||
|
//! ```bash
|
||||||
|
//! cargo run -p solitaire_assetgen --bin gen_difficulty_seeds --release -- \
|
||||||
|
//! --start 0xD1FF0000_00000000 --per-tier 40
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Flags:
|
||||||
|
//! --start Starting seed (decimal or 0x-prefixed hex, default 0xD1FF000000000000)
|
||||||
|
//! --per-tier Seeds to emit per tier (default 40)
|
||||||
|
//! --help Print this message
|
||||||
|
|
||||||
|
use solitaire_core::game_state::DrawMode;
|
||||||
|
use solitaire_core::solver::{try_solve, SolverConfig, SolverResult};
|
||||||
|
|
||||||
|
// Budget boundaries defining each tier. A seed belongs to the lowest tier
|
||||||
|
// whose budget proves it Winnable.
|
||||||
|
const BUDGETS: &[(&str, u64, usize)] = &[
|
||||||
|
("Easy", 1_000, 1_000),
|
||||||
|
("Medium", 5_000, 5_000),
|
||||||
|
("Hard", 25_000, 25_000),
|
||||||
|
("Expert", 100_000, 100_000),
|
||||||
|
("Grandmaster", 200_000, 200_000),
|
||||||
|
];
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args().skip(1).peekable();
|
||||||
|
let mut start: u64 = 0xD1FF_0000_0000_0000;
|
||||||
|
let mut per_tier: usize = 40;
|
||||||
|
|
||||||
|
while let Some(arg) = args.next() {
|
||||||
|
match arg.as_str() {
|
||||||
|
"--start" => {
|
||||||
|
let val = args.next().unwrap_or_else(|| {
|
||||||
|
eprintln!("error: --start requires a value");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
start = parse_u64(&val);
|
||||||
|
}
|
||||||
|
"--per-tier" => {
|
||||||
|
let val = args.next().unwrap_or_else(|| {
|
||||||
|
eprintln!("error: --per-tier requires a value");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
per_tier = val.parse().unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: --per-tier must be a positive integer");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"--help" | "-h" => {
|
||||||
|
eprintln!("gen_difficulty_seeds: generate tiered seed catalogs");
|
||||||
|
eprintln!(" --start <seed> starting seed (hex or decimal)");
|
||||||
|
eprintln!(" --per-tier <n> seeds per tier (default 40)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
other => {
|
||||||
|
eprintln!("error: unknown argument: {other}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if per_tier == 0 {
|
||||||
|
eprintln!("error: --per-tier must be > 0");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let draw_mode = DrawMode::DrawOne;
|
||||||
|
let num_tiers = BUDGETS.len();
|
||||||
|
let mut buckets: Vec<Vec<u64>> = vec![Vec::with_capacity(per_tier); num_tiers];
|
||||||
|
let mut tried: u64 = 0;
|
||||||
|
let mut seed = start;
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"gen_difficulty_seeds: finding {} seeds per tier from 0x{start:016X} (DrawOne) …",
|
||||||
|
per_tier
|
||||||
|
);
|
||||||
|
eprintln!(
|
||||||
|
" Tiers: {}",
|
||||||
|
BUDGETS.iter().map(|(n, _, _)| *n).collect::<Vec<_>>().join(", ")
|
||||||
|
);
|
||||||
|
|
||||||
|
while buckets.iter().any(|b| b.len() < per_tier) {
|
||||||
|
tried += 1;
|
||||||
|
'tier: for (i, &(name, move_budget, state_budget)) in BUDGETS.iter().enumerate() {
|
||||||
|
if buckets[i].len() >= per_tier {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let cfg = SolverConfig { move_budget, state_budget };
|
||||||
|
match try_solve(seed, draw_mode.clone(), &cfg) {
|
||||||
|
SolverResult::Winnable => {
|
||||||
|
buckets[i].push(seed);
|
||||||
|
eprintln!(
|
||||||
|
" [{name} {:>3}/{}] 0x{seed:016X} (tried {tried})",
|
||||||
|
buckets[i].len(),
|
||||||
|
per_tier
|
||||||
|
);
|
||||||
|
break 'tier; // assign to the cheapest tier that proves it winnable
|
||||||
|
}
|
||||||
|
SolverResult::Unwinnable => {
|
||||||
|
// Definitely unsolvable — skip all remaining tiers.
|
||||||
|
break 'tier;
|
||||||
|
}
|
||||||
|
SolverResult::Inconclusive => {
|
||||||
|
// Budget exhausted without proof — try the next larger tier.
|
||||||
|
// If this is the last tier, the seed is discarded (Inconclusive
|
||||||
|
// at max budget means "probably but not provably winnable").
|
||||||
|
if i == num_tiers - 1 {
|
||||||
|
break 'tier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seed = seed.wrapping_add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
eprintln!("\nDone ({tried} seeds examined). Paste the blocks below into difficulty_seeds.rs:\n");
|
||||||
|
|
||||||
|
let date = current_date();
|
||||||
|
for (i, (tier_name, _, _)) in BUDGETS.iter().enumerate() {
|
||||||
|
println!(
|
||||||
|
" // Generated by solitaire_assetgen::gen_difficulty_seeds \
|
||||||
|
(tier={tier_name}, date={date})"
|
||||||
|
);
|
||||||
|
for chunk in buckets[i].chunks(5) {
|
||||||
|
for s in chunk {
|
||||||
|
println!(
|
||||||
|
" 0x{:04X}_{:04X}_{:04X}_{:04X},",
|
||||||
|
(s >> 48) & 0xFFFF,
|
||||||
|
(s >> 32) & 0xFFFF,
|
||||||
|
(s >> 16) & 0xFFFF,
|
||||||
|
s & 0xFFFF,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_u64(s: &str) -> u64 {
|
||||||
|
let cleaned = s.replace('_', "");
|
||||||
|
if let Some(hex) = cleaned.strip_prefix("0x").or_else(|| cleaned.strip_prefix("0X")) {
|
||||||
|
u64::from_str_radix(hex, 16).unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: could not parse '{s}' as a hex u64");
|
||||||
|
std::process::exit(1);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
cleaned.parse().unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: could not parse '{s}' as a decimal u64");
|
||||||
|
std::process::exit(1);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_date() -> String {
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
let secs = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_secs())
|
||||||
|
.unwrap_or(0);
|
||||||
|
let days = secs / 86400;
|
||||||
|
let mut y = 1970u64;
|
||||||
|
let mut d = days;
|
||||||
|
loop {
|
||||||
|
let leap = (y.is_multiple_of(4) && !y.is_multiple_of(100)) || y.is_multiple_of(400);
|
||||||
|
let days_in_year = if leap { 366 } else { 365 };
|
||||||
|
if d < days_in_year {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
d -= days_in_year;
|
||||||
|
y += 1;
|
||||||
|
}
|
||||||
|
let leap = (y.is_multiple_of(4) && !y.is_multiple_of(100)) || y.is_multiple_of(400);
|
||||||
|
let month_days: [u64; 12] = [
|
||||||
|
31, if leap { 29 } else { 28 }, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
|
||||||
|
];
|
||||||
|
let mut m = 0usize;
|
||||||
|
for &md in &month_days {
|
||||||
|
if d < md {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
d -= md;
|
||||||
|
m += 1;
|
||||||
|
}
|
||||||
|
format!("{y}-{:02}-{:02}", m + 1, d + 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
//! Generate provably-winnable Klondike seeds for `CHALLENGE_SEEDS`.
|
||||||
|
//!
|
||||||
|
//! Walks seeds incrementally from `--start`, calls the solver on each, and
|
||||||
|
//! collects only those that return `SolverResult::Winnable` (Inconclusive is
|
||||||
|
//! rejected — the curated list wants proof). Prints Rust source suitable for
|
||||||
|
//! pasting into `solitaire_data/src/challenge.rs`.
|
||||||
|
//!
|
||||||
|
//! # Usage
|
||||||
|
//!
|
||||||
|
//! ```bash
|
||||||
|
//! cargo run -p solitaire_assetgen --bin gen_seeds --release -- \
|
||||||
|
//! --start 0xCAFE_BABE_0000_0000 --count 75
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! Flags:
|
||||||
|
//! --start Starting seed (decimal or 0x-prefixed hex, default 0xCAFEBABE00000000)
|
||||||
|
//! --count Number of Winnable seeds to emit (default 75)
|
||||||
|
//! --help Print this message
|
||||||
|
|
||||||
|
use solitaire_core::game_state::DrawMode;
|
||||||
|
use solitaire_core::solver::{try_solve, SolverConfig, SolverResult};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args().skip(1).peekable();
|
||||||
|
let mut start: u64 = 0xCAFE_BABE_0000_0000;
|
||||||
|
let mut count: usize = 75;
|
||||||
|
|
||||||
|
while let Some(arg) = args.next() {
|
||||||
|
match arg.as_str() {
|
||||||
|
"--start" => {
|
||||||
|
let val = args.next().unwrap_or_else(|| {
|
||||||
|
eprintln!("error: --start requires a value");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
start = parse_u64(&val);
|
||||||
|
}
|
||||||
|
"--count" => {
|
||||||
|
let val = args.next().unwrap_or_else(|| {
|
||||||
|
eprintln!("error: --count requires a value");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
count = val.parse().unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: --count must be a positive integer");
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"--help" | "-h" => {
|
||||||
|
eprintln!("{}", include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/bin/gen_seeds.rs")).lines().take(20).collect::<Vec<_>>().join("\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
other => {
|
||||||
|
eprintln!("error: unknown argument: {other}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
eprintln!("error: --count must be > 0");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cfg = SolverConfig::default();
|
||||||
|
let draw_mode = DrawMode::DrawOne;
|
||||||
|
let mut found: Vec<u64> = Vec::with_capacity(count);
|
||||||
|
let mut tried: u64 = 0;
|
||||||
|
let mut seed = start;
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"gen_seeds: finding {count} Winnable seeds from 0x{start:016X} (DrawOne) …"
|
||||||
|
);
|
||||||
|
|
||||||
|
while found.len() < count {
|
||||||
|
tried += 1;
|
||||||
|
if matches!(
|
||||||
|
try_solve(seed, draw_mode.clone(), &cfg),
|
||||||
|
SolverResult::Winnable
|
||||||
|
) {
|
||||||
|
found.push(seed);
|
||||||
|
eprintln!(
|
||||||
|
" [{:>3}/{}] 0x{:016X} ({} tried so far)",
|
||||||
|
found.len(),
|
||||||
|
count,
|
||||||
|
seed,
|
||||||
|
tried
|
||||||
|
);
|
||||||
|
}
|
||||||
|
seed = seed.wrapping_add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
eprintln!("\nDone. Paste the block below into CHALLENGE_SEEDS in solitaire_data/src/challenge.rs:\n");
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" // Generated by solitaire_assetgen::gen_seeds \
|
||||||
|
(start=0x{start:016X}, count={count}, date={date})",
|
||||||
|
date = current_date()
|
||||||
|
);
|
||||||
|
for chunk in found.chunks(5) {
|
||||||
|
for s in chunk {
|
||||||
|
println!(
|
||||||
|
" 0x{:04X}_{:04X}_{:04X}_{:04X},",
|
||||||
|
(s >> 48) & 0xFFFF,
|
||||||
|
(s >> 32) & 0xFFFF,
|
||||||
|
(s >> 16) & 0xFFFF,
|
||||||
|
s & 0xFFFF,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_u64(s: &str) -> u64 {
|
||||||
|
let cleaned = s.replace('_', "");
|
||||||
|
if let Some(hex) = cleaned.strip_prefix("0x").or_else(|| cleaned.strip_prefix("0X")) {
|
||||||
|
u64::from_str_radix(hex, 16).unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: could not parse '{s}' as a hex u64");
|
||||||
|
std::process::exit(1);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
cleaned.parse().unwrap_or_else(|_| {
|
||||||
|
eprintln!("error: could not parse '{s}' as a decimal u64");
|
||||||
|
std::process::exit(1);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_date() -> String {
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
let secs = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_secs())
|
||||||
|
.unwrap_or(0);
|
||||||
|
let days = secs / 86400;
|
||||||
|
// Gregorian calendar computation (Tomohiko Sakamoto's algorithm variant)
|
||||||
|
let mut y = 1970u64;
|
||||||
|
let mut d = days;
|
||||||
|
loop {
|
||||||
|
let leap = (y.is_multiple_of(4) && !y.is_multiple_of(100)) || y.is_multiple_of(400);
|
||||||
|
let days_in_year = if leap { 366 } else { 365 };
|
||||||
|
if d < days_in_year {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
d -= days_in_year;
|
||||||
|
y += 1;
|
||||||
|
}
|
||||||
|
let leap = (y.is_multiple_of(4) && !y.is_multiple_of(100)) || y.is_multiple_of(400);
|
||||||
|
let month_days: [u64; 12] = [31, if leap { 29 } else { 28 }, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||||
|
let mut m = 0usize;
|
||||||
|
for &md in &month_days {
|
||||||
|
if d < md {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
d -= md;
|
||||||
|
m += 1;
|
||||||
|
}
|
||||||
|
format!("{y}-{:02}-{:02}", m + 1, d + 1)
|
||||||
|
}
|
||||||
@@ -50,6 +50,35 @@ pub enum DrawMode {
|
|||||||
DrawThree,
|
DrawThree,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Difficulty tier for `GameMode::Difficulty`. Controls which pre-verified seed
|
||||||
|
/// catalog is drawn from. `Random` skips verification entirely and uses a
|
||||||
|
/// system-time seed — deals may or may not be winnable.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
|
||||||
|
pub enum DifficultyLevel {
|
||||||
|
#[default]
|
||||||
|
Easy,
|
||||||
|
Medium,
|
||||||
|
Hard,
|
||||||
|
Expert,
|
||||||
|
Grandmaster,
|
||||||
|
/// Unverified system-time seed — may or may not be winnable.
|
||||||
|
Random,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DifficultyLevel {
|
||||||
|
/// Short human-readable label shown in the HUD and win summary.
|
||||||
|
pub fn label(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Easy => "Easy",
|
||||||
|
Self::Medium => "Medium",
|
||||||
|
Self::Hard => "Hard",
|
||||||
|
Self::Expert => "Expert",
|
||||||
|
Self::Grandmaster => "Grandmaster",
|
||||||
|
Self::Random => "Random",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Top-level game mode. Affects scoring, undo, and (eventually) timer behaviour.
|
/// Top-level game mode. Affects scoring, undo, and (eventually) timer behaviour.
|
||||||
///
|
///
|
||||||
/// - `Classic`: standard Klondike scoring, undo allowed.
|
/// - `Classic`: standard Klondike scoring, undo allowed.
|
||||||
@@ -59,6 +88,8 @@ pub enum DrawMode {
|
|||||||
/// - `TimeAttack`: standard scoring + undo; the engine wraps a 10-minute
|
/// - `TimeAttack`: standard scoring + undo; the engine wraps a 10-minute
|
||||||
/// countdown around the session and auto-deals a fresh game on every win
|
/// countdown around the session and auto-deals a fresh game on every win
|
||||||
/// (see `solitaire_engine::TimeAttackPlugin`).
|
/// (see `solitaire_engine::TimeAttackPlugin`).
|
||||||
|
/// - `Difficulty(DifficultyLevel)`: seed drawn from a pre-verified per-tier catalog
|
||||||
|
/// (or system-time for `Random`). Rules identical to Classic.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
pub enum GameMode {
|
pub enum GameMode {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -70,6 +101,8 @@ pub enum GameMode {
|
|||||||
Challenge,
|
Challenge,
|
||||||
/// Play as many games as possible within 10 minutes.
|
/// Play as many games as possible within 10 minutes.
|
||||||
TimeAttack,
|
TimeAttack,
|
||||||
|
/// Seed drawn from a difficulty-tiered catalog; rules identical to Classic.
|
||||||
|
Difficulty(DifficultyLevel),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Snapshot of game state used for undo.
|
/// Snapshot of game state used for undo.
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ tokio = { workspace = true }
|
|||||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
keyring-core = { workspace = true }
|
keyring-core = { workspace = true }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
|
jni = { workspace = true }
|
||||||
|
# android_keystore.rs uses bevy::android::ANDROID_APP to obtain the
|
||||||
|
# process-wide JavaVM handle for JNI. Must be listed here so the
|
||||||
|
# symbol resolves when cross-compiling for Android targets.
|
||||||
|
bevy = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solitaire_server = { path = "../solitaire_server" }
|
solitaire_server = { path = "../solitaire_server" }
|
||||||
solitaire_sync = { workspace = true }
|
solitaire_sync = { workspace = true }
|
||||||
|
|||||||
@@ -0,0 +1,409 @@
|
|||||||
|
/// Android Keystore token storage via JNI.
|
||||||
|
///
|
||||||
|
/// Tokens are serialised to JSON, encrypted with AES-256/GCM/NoPadding using a
|
||||||
|
/// device-bound key from the Android Keystore, and written atomically to
|
||||||
|
/// `{data_dir}/auth_tokens.bin` as `[12-byte IV][ciphertext+GCM-tag]`.
|
||||||
|
///
|
||||||
|
/// The Keystore key survives app restarts but is destroyed on uninstall (or if
|
||||||
|
/// the user changes biometric/lock credentials, in which case decryption fails
|
||||||
|
/// and we surface `TokenError::KeychainUnavailable` so the caller knows to
|
||||||
|
/// prompt re-login — identical semantics to a Linux box without Secret Service).
|
||||||
|
///
|
||||||
|
/// Only compiled and linked on `target_os = "android"`.
|
||||||
|
use jni::{
|
||||||
|
objects::{JByteArray, JObject, JObjectArray, JValue, JValueOwned},
|
||||||
|
JNIEnv, JavaVM,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::auth_tokens::TokenError;
|
||||||
|
|
||||||
|
const KEY_ALIAS: &str = "solitaire_quest_token_key";
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct TokenBlob {
|
||||||
|
username: String,
|
||||||
|
access_token: String,
|
||||||
|
refresh_token: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// JVM helper
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
fn with_jvm<F, R>(f: F) -> Result<R, TokenError>
|
||||||
|
where
|
||||||
|
F: for<'env> FnOnce(&mut JNIEnv<'env>) -> Result<R, jni::errors::Error>,
|
||||||
|
{
|
||||||
|
let app = bevy::android::ANDROID_APP
|
||||||
|
.get()
|
||||||
|
.ok_or_else(|| TokenError::KeychainUnavailable("ANDROID_APP not initialised".into()))?;
|
||||||
|
|
||||||
|
// SAFETY: vm_as_ptr() is the process-wide JavaVM* set by the Android runtime.
|
||||||
|
let vm = unsafe { JavaVM::from_raw(app.vm_as_ptr().cast()) }
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("JavaVM: {e}")))?;
|
||||||
|
|
||||||
|
let mut env = vm
|
||||||
|
.attach_current_thread_permanently()
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("attach: {e}")))?;
|
||||||
|
|
||||||
|
f(&mut env).map_err(|e| TokenError::Keyring(format!("JNI: {e}")))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Keystore key management
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Load the existing AES key from the Android Keystore, or generate one if it
|
||||||
|
/// doesn't exist yet. Returns a local reference valid for the current JNI frame.
|
||||||
|
fn load_or_create_key<'local>(env: &mut JNIEnv<'local>) -> jni::errors::Result<JObject<'local>> {
|
||||||
|
// KeyStore ks = KeyStore.getInstance("AndroidKeyStore"); ks.load(null);
|
||||||
|
let ks_class = env.find_class("java/security/KeyStore")?;
|
||||||
|
let ks_type = JValueOwned::from(env.new_string("AndroidKeyStore")?);
|
||||||
|
let ks = env
|
||||||
|
.call_static_method(
|
||||||
|
&ks_class,
|
||||||
|
"getInstance",
|
||||||
|
"(Ljava/lang/String;)Ljava/security/KeyStore;",
|
||||||
|
&[ks_type.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
let null = JObject::null();
|
||||||
|
env.call_method(
|
||||||
|
&ks,
|
||||||
|
"load",
|
||||||
|
"(Ljava/security/KeyStore$LoadStoreParameter;)V",
|
||||||
|
&[JValue::Object(&null)],
|
||||||
|
)?
|
||||||
|
.v()?;
|
||||||
|
|
||||||
|
// Key key = ks.getKey(ALIAS, null) — char[] password is null for hardware keys
|
||||||
|
let alias = JValueOwned::from(env.new_string(KEY_ALIAS)?);
|
||||||
|
let null2 = JObject::null();
|
||||||
|
let key = env
|
||||||
|
.call_method(
|
||||||
|
&ks,
|
||||||
|
"getKey",
|
||||||
|
"(Ljava/lang/String;[C)Ljava/security/Key;",
|
||||||
|
&[alias.borrow(), JValue::Object(&null2)],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
if !env.is_same_object(&key, JObject::null())? {
|
||||||
|
return Ok(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No key yet — generate AES-256 with GCM block mode.
|
||||||
|
let builder_class =
|
||||||
|
env.find_class("android/security/keystore/KeyGenParameterSpec$Builder")?;
|
||||||
|
let alias2 = JValueOwned::from(env.new_string(KEY_ALIAS)?);
|
||||||
|
// PURPOSE_ENCRYPT | PURPOSE_DECRYPT = 1 | 2 = 3
|
||||||
|
let purpose = JValueOwned::Int(3);
|
||||||
|
let builder = env.new_object(
|
||||||
|
&builder_class,
|
||||||
|
"(Ljava/lang/String;I)V",
|
||||||
|
&[alias2.borrow(), purpose.borrow()],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let str_class = env.find_class("java/lang/String")?;
|
||||||
|
|
||||||
|
// builder.setBlockModes(["GCM"])
|
||||||
|
let gcm_str = env.new_string("GCM")?;
|
||||||
|
let block_modes: JObjectArray = env.new_object_array(1, &str_class, &gcm_str)?;
|
||||||
|
let block_modes_val = JValueOwned::Object(block_modes.into());
|
||||||
|
let builder = env
|
||||||
|
.call_method(
|
||||||
|
&builder,
|
||||||
|
"setBlockModes",
|
||||||
|
"([Ljava/lang/String;)Landroid/security/keystore/KeyGenParameterSpec$Builder;",
|
||||||
|
&[block_modes_val.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// builder.setEncryptionPaddings(["NoPadding"])
|
||||||
|
let nopad_str = env.new_string("NoPadding")?;
|
||||||
|
let enc_pads: JObjectArray = env.new_object_array(1, &str_class, &nopad_str)?;
|
||||||
|
let enc_pads_val = JValueOwned::Object(enc_pads.into());
|
||||||
|
let builder = env
|
||||||
|
.call_method(
|
||||||
|
&builder,
|
||||||
|
"setEncryptionPaddings",
|
||||||
|
"([Ljava/lang/String;)Landroid/security/keystore/KeyGenParameterSpec$Builder;",
|
||||||
|
&[enc_pads_val.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// KeyGenParameterSpec spec = builder.build()
|
||||||
|
let spec = env
|
||||||
|
.call_method(
|
||||||
|
&builder,
|
||||||
|
"build",
|
||||||
|
"()Landroid/security/keystore/KeyGenParameterSpec;",
|
||||||
|
&[],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// KeyGenerator kg = KeyGenerator.getInstance("AES", "AndroidKeyStore")
|
||||||
|
let kg_class = env.find_class("javax/crypto/KeyGenerator")?;
|
||||||
|
let aes = JValueOwned::from(env.new_string("AES")?);
|
||||||
|
let ks_name = JValueOwned::from(env.new_string("AndroidKeyStore")?);
|
||||||
|
let kg = env
|
||||||
|
.call_static_method(
|
||||||
|
&kg_class,
|
||||||
|
"getInstance",
|
||||||
|
"(Ljava/lang/String;Ljava/lang/String;)Ljavax/crypto/KeyGenerator;",
|
||||||
|
&[aes.borrow(), ks_name.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// kg.init(spec); return kg.generateKey()
|
||||||
|
let spec_val = JValueOwned::Object(spec);
|
||||||
|
env.call_method(
|
||||||
|
&kg,
|
||||||
|
"init",
|
||||||
|
"(Ljava/security/spec/AlgorithmParameterSpec;)V",
|
||||||
|
&[spec_val.borrow()],
|
||||||
|
)?
|
||||||
|
.v()?;
|
||||||
|
|
||||||
|
env.call_method(&kg, "generateKey", "()Ljavax/crypto/SecretKey;", &[])?
|
||||||
|
.l()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// AES-GCM encrypt / decrypt
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Returns `[12-byte IV][ciphertext+GCM-tag]`.
|
||||||
|
fn encrypt_gcm(
|
||||||
|
env: &mut JNIEnv<'_>,
|
||||||
|
key: &JObject<'_>,
|
||||||
|
plaintext: &[u8],
|
||||||
|
) -> jni::errors::Result<Vec<u8>> {
|
||||||
|
let cipher_class = env.find_class("javax/crypto/Cipher")?;
|
||||||
|
let transform = JValueOwned::from(env.new_string("AES/GCM/NoPadding")?);
|
||||||
|
let cipher = env
|
||||||
|
.call_static_method(
|
||||||
|
&cipher_class,
|
||||||
|
"getInstance",
|
||||||
|
"(Ljava/lang/String;)Ljavax/crypto/Cipher;",
|
||||||
|
&[transform.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// cipher.init(Cipher.ENCRYPT_MODE=1, key)
|
||||||
|
let mode = JValueOwned::Int(1);
|
||||||
|
env.call_method(
|
||||||
|
&cipher,
|
||||||
|
"init",
|
||||||
|
"(ILjava/security/Key;)V",
|
||||||
|
&[mode.borrow(), JValue::Object(key)],
|
||||||
|
)?
|
||||||
|
.v()?;
|
||||||
|
|
||||||
|
// IV is generated by Android's provider; read it back after init.
|
||||||
|
let iv_jobj = env.call_method(&cipher, "getIV", "()[B", &[])?.l()?;
|
||||||
|
// SAFETY: the method signature guarantees a byte array return.
|
||||||
|
let iv_arr = unsafe { JByteArray::from_raw(iv_jobj.into_raw()) };
|
||||||
|
let iv = env.convert_byte_array(&iv_arr)?;
|
||||||
|
|
||||||
|
let pt_arr = env.byte_array_from_slice(plaintext)?;
|
||||||
|
let pt_val = JValueOwned::Object(pt_arr.into());
|
||||||
|
let ct_jobj = env
|
||||||
|
.call_method(&cipher, "doFinal", "([B)[B", &[pt_val.borrow()])?
|
||||||
|
.l()?;
|
||||||
|
// SAFETY: doFinal([B) returns [B.
|
||||||
|
let ct_arr = unsafe { JByteArray::from_raw(ct_jobj.into_raw()) };
|
||||||
|
let ciphertext = env.convert_byte_array(&ct_arr)?;
|
||||||
|
|
||||||
|
let mut out = Vec::with_capacity(iv.len() + ciphertext.len());
|
||||||
|
out.extend_from_slice(&iv);
|
||||||
|
out.extend_from_slice(&ciphertext);
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Expects `data` as `[12-byte IV][ciphertext+GCM-tag]`.
|
||||||
|
fn decrypt_gcm(
|
||||||
|
env: &mut JNIEnv<'_>,
|
||||||
|
key: &JObject<'_>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> jni::errors::Result<Vec<u8>> {
|
||||||
|
let (iv, ciphertext) = data.split_at(12);
|
||||||
|
|
||||||
|
let cipher_class = env.find_class("javax/crypto/Cipher")?;
|
||||||
|
let transform = JValueOwned::from(env.new_string("AES/GCM/NoPadding")?);
|
||||||
|
let cipher = env
|
||||||
|
.call_static_method(
|
||||||
|
&cipher_class,
|
||||||
|
"getInstance",
|
||||||
|
"(Ljava/lang/String;)Ljavax/crypto/Cipher;",
|
||||||
|
&[transform.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
// GCMParameterSpec spec = new GCMParameterSpec(128, iv)
|
||||||
|
let spec_class = env.find_class("javax/crypto/spec/GCMParameterSpec")?;
|
||||||
|
let tag_len = JValueOwned::Int(128);
|
||||||
|
let iv_arr = env.byte_array_from_slice(iv)?;
|
||||||
|
let iv_val = JValueOwned::Object(iv_arr.into());
|
||||||
|
let spec = env.new_object(
|
||||||
|
&spec_class,
|
||||||
|
"(I[B)V",
|
||||||
|
&[tag_len.borrow(), iv_val.borrow()],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// cipher.init(Cipher.DECRYPT_MODE=2, key, spec)
|
||||||
|
let mode = JValueOwned::Int(2);
|
||||||
|
let spec_val = JValueOwned::Object(spec);
|
||||||
|
env.call_method(
|
||||||
|
&cipher,
|
||||||
|
"init",
|
||||||
|
"(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V",
|
||||||
|
&[mode.borrow(), JValue::Object(key), spec_val.borrow()],
|
||||||
|
)?
|
||||||
|
.v()?;
|
||||||
|
|
||||||
|
let ct_arr = env.byte_array_from_slice(ciphertext)?;
|
||||||
|
let ct_val = JValueOwned::Object(ct_arr.into());
|
||||||
|
let pt_jobj = env
|
||||||
|
.call_method(&cipher, "doFinal", "([B)[B", &[ct_val.borrow()])?
|
||||||
|
.l()?;
|
||||||
|
// SAFETY: doFinal([B) returns [B.
|
||||||
|
let pt_arr = unsafe { JByteArray::from_raw(pt_jobj.into_raw()) };
|
||||||
|
env.convert_byte_array(&pt_arr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// File helpers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
fn token_file_path() -> Option<PathBuf> {
|
||||||
|
crate::platform::data_dir().map(|d| d.join("auth_tokens.bin"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_file_bytes() -> Result<Vec<u8>, TokenError> {
|
||||||
|
let path = token_file_path()
|
||||||
|
.ok_or_else(|| TokenError::KeychainUnavailable("no data dir".into()))?;
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(TokenError::NotFound(String::new()));
|
||||||
|
}
|
||||||
|
std::fs::read(&path).map_err(|e| TokenError::Keyring(format!("read auth_tokens.bin: {e}")))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_file_bytes(data: &[u8]) -> Result<(), TokenError> {
|
||||||
|
let path = token_file_path()
|
||||||
|
.ok_or_else(|| TokenError::KeychainUnavailable("no data dir".into()))?;
|
||||||
|
let tmp = path.with_extension("tmp");
|
||||||
|
std::fs::write(&tmp, data)
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("write auth_tokens.tmp: {e}")))?;
|
||||||
|
std::fs::rename(&tmp, &path)
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("rename auth_tokens: {e}")))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_blob(username: &str) -> Result<TokenBlob, TokenError> {
|
||||||
|
let data = read_file_bytes().map_err(|e| match e {
|
||||||
|
TokenError::NotFound(_) => TokenError::NotFound(username.to_string()),
|
||||||
|
other => other,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if data.len() < 12 {
|
||||||
|
return Err(TokenError::Keyring("auth_tokens.bin corrupt (too short)".into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let plaintext = with_jvm(|env| {
|
||||||
|
let key = load_or_create_key(env)?;
|
||||||
|
decrypt_gcm(env, &key, &data)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let blob: TokenBlob = serde_json::from_slice(&plaintext)
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("JSON decode: {e}")))?;
|
||||||
|
|
||||||
|
if blob.username != username {
|
||||||
|
return Err(TokenError::NotFound(username.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public API — mirrors auth_tokens desktop surface exactly.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Encrypt and store `access_token` and `refresh_token` for `username`.
|
||||||
|
///
|
||||||
|
/// Overwrites any previously stored tokens.
|
||||||
|
pub fn store_tokens(
|
||||||
|
username: &str,
|
||||||
|
access_token: &str,
|
||||||
|
refresh_token: &str,
|
||||||
|
) -> Result<(), TokenError> {
|
||||||
|
let blob = TokenBlob {
|
||||||
|
username: username.to_string(),
|
||||||
|
access_token: access_token.to_string(),
|
||||||
|
refresh_token: refresh_token.to_string(),
|
||||||
|
};
|
||||||
|
let plaintext = serde_json::to_vec(&blob)
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("JSON encode: {e}")))?;
|
||||||
|
|
||||||
|
let encrypted = with_jvm(|env| {
|
||||||
|
let key = load_or_create_key(env)?;
|
||||||
|
encrypt_gcm(env, &key, &plaintext)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
write_file_bytes(&encrypted)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the stored access token for `username`.
|
||||||
|
///
|
||||||
|
/// Returns [`TokenError::NotFound`] if no token has been stored yet.
|
||||||
|
pub fn load_access_token(username: &str) -> Result<String, TokenError> {
|
||||||
|
load_blob(username).map(|b| b.access_token)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the stored refresh token for `username`.
|
||||||
|
///
|
||||||
|
/// Returns [`TokenError::NotFound`] if no token has been stored yet.
|
||||||
|
pub fn load_refresh_token(username: &str) -> Result<String, TokenError> {
|
||||||
|
load_blob(username).map(|b| b.refresh_token)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete stored tokens and remove the Keystore key for `username`.
|
||||||
|
///
|
||||||
|
/// Missing file or missing Keystore entry are silently ignored.
|
||||||
|
pub fn delete_tokens(_username: &str) -> Result<(), TokenError> {
|
||||||
|
if let Some(path) = token_file_path() {
|
||||||
|
if path.exists() {
|
||||||
|
std::fs::remove_file(&path)
|
||||||
|
.map_err(|e| TokenError::Keyring(format!("delete auth_tokens.bin: {e}")))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the Keystore key so a future re-login generates a fresh key.
|
||||||
|
with_jvm(|env| {
|
||||||
|
let ks_class = env.find_class("java/security/KeyStore")?;
|
||||||
|
let ks_type = JValueOwned::from(env.new_string("AndroidKeyStore")?);
|
||||||
|
let ks = env
|
||||||
|
.call_static_method(
|
||||||
|
&ks_class,
|
||||||
|
"getInstance",
|
||||||
|
"(Ljava/lang/String;)Ljava/security/KeyStore;",
|
||||||
|
&[ks_type.borrow()],
|
||||||
|
)?
|
||||||
|
.l()?;
|
||||||
|
|
||||||
|
let null = JObject::null();
|
||||||
|
env.call_method(
|
||||||
|
&ks,
|
||||||
|
"load",
|
||||||
|
"(Ljava/security/KeyStore$LoadStoreParameter;)V",
|
||||||
|
&[JValue::Object(&null)],
|
||||||
|
)?
|
||||||
|
.v()?;
|
||||||
|
|
||||||
|
let alias = JValueOwned::from(env.new_string(KEY_ALIAS)?);
|
||||||
|
env.call_method(&ks, "deleteEntry", "(Ljava/lang/String;)V", &[alias.borrow()])?
|
||||||
|
.v()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -131,35 +131,29 @@ pub fn delete_tokens(username: &str) -> Result<(), TokenError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Android stub — same public API, always returns KeychainUnavailable.
|
// Android — delegate to the JNI Keystore bridge in android_keystore.
|
||||||
// Lets `sync_client::*` compile unchanged on Android; the runtime
|
|
||||||
// effect is "session login required every launch", same as a Linux
|
|
||||||
// box without Secret Service.
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
const ANDROID_STUB_MSG: &str = "android stub: keychain not yet wired (Phase-Android task)";
|
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn store_tokens(
|
pub fn store_tokens(
|
||||||
_username: &str,
|
username: &str,
|
||||||
_access_token: &str,
|
access_token: &str,
|
||||||
_refresh_token: &str,
|
refresh_token: &str,
|
||||||
) -> Result<(), TokenError> {
|
) -> Result<(), TokenError> {
|
||||||
Err(TokenError::KeychainUnavailable(ANDROID_STUB_MSG.to_string()))
|
crate::android_keystore::store_tokens(username, access_token, refresh_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn load_access_token(_username: &str) -> Result<String, TokenError> {
|
pub fn load_access_token(username: &str) -> Result<String, TokenError> {
|
||||||
Err(TokenError::KeychainUnavailable(ANDROID_STUB_MSG.to_string()))
|
crate::android_keystore::load_access_token(username)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn load_refresh_token(_username: &str) -> Result<String, TokenError> {
|
pub fn load_refresh_token(username: &str) -> Result<String, TokenError> {
|
||||||
Err(TokenError::KeychainUnavailable(ANDROID_STUB_MSG.to_string()))
|
crate::android_keystore::load_refresh_token(username)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn delete_tokens(_username: &str) -> Result<(), TokenError> {
|
pub fn delete_tokens(username: &str) -> Result<(), TokenError> {
|
||||||
Err(TokenError::KeychainUnavailable(ANDROID_STUB_MSG.to_string()))
|
crate::android_keystore::delete_tokens(username)
|
||||||
}
|
}
|
||||||
|
|||||||