Merge remote-tracking branch 'origin/master' into chore/dead-code-removals
This commit is contained in:
@@ -10,9 +10,11 @@ on:
|
|||||||
- 'solitaire_web/**'
|
- 'solitaire_web/**'
|
||||||
- 'solitaire_sync/**'
|
- 'solitaire_sync/**'
|
||||||
- 'solitaire_core/**'
|
- 'solitaire_core/**'
|
||||||
|
- 'solitaire_data/**'
|
||||||
- 'solitaire_engine/**'
|
- 'solitaire_engine/**'
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
- 'Cargo.lock'
|
- 'Cargo.lock'
|
||||||
|
- 'build_wasm.sh'
|
||||||
- 'solitaire_server/Dockerfile'
|
- 'solitaire_server/Dockerfile'
|
||||||
- '.gitea/workflows/docker-build.yml'
|
- '.gitea/workflows/docker-build.yml'
|
||||||
|
|
||||||
@@ -36,12 +38,9 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# WASM artifact freshness is owned by the `web-wasm-rebuild` workflow,
|
# The wasm bundles (solitaire_server/web/pkg/) are not in the repo —
|
||||||
# which rebuilds pkg/ in CI on every master change to a wasm-feeding crate
|
# the Dockerfile's wasm-builder stage builds them from source inside
|
||||||
# and commits it back (CI is the single source of truth — the artifacts
|
# this image build, so the deployed image always ships fresh wasm.
|
||||||
# aren't byte-reproducible on contributor machines). That pkg/ commit then
|
|
||||||
# triggers this workflow, so the deployed image always ships fresh wasm.
|
|
||||||
# No drift check is needed here.
|
|
||||||
|
|
||||||
- name: Log in to Gitea registry
|
- name: Log in to Gitea registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Workspace gate: the same clippy + test commands CLAUDE.md §6 requires
|
# Workspace gate: the same clippy + test commands CLAUDE.md §6 requires
|
||||||
# locally, run on every master push and pull request. Until this workflow
|
# locally, run on every master push and pull request. Until this workflow
|
||||||
# existed, nothing in CI ran the test suite at all — a direct push to
|
# existed, nothing in CI ran the test suite at all — a direct push to
|
||||||
# master (or the web-wasm-rebuild bot commit) was entirely unguarded.
|
# master was entirely unguarded.
|
||||||
name: Test
|
name: Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ on:
|
|||||||
- 'solitaire_server/src/**'
|
- 'solitaire_server/src/**'
|
||||||
- 'solitaire_server/e2e/**'
|
- 'solitaire_server/e2e/**'
|
||||||
- 'solitaire_wasm/**'
|
- 'solitaire_wasm/**'
|
||||||
|
- 'solitaire_web/**'
|
||||||
|
- 'solitaire_engine/**'
|
||||||
|
- 'solitaire_data/**'
|
||||||
- 'solitaire_core/**'
|
- 'solitaire_core/**'
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
- 'Cargo.lock'
|
- 'Cargo.lock'
|
||||||
|
- 'build_wasm.sh'
|
||||||
- '.gitea/workflows/web-e2e.yml'
|
- '.gitea/workflows/web-e2e.yml'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
@@ -24,10 +28,31 @@ jobs:
|
|||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
targets: wasm32-unknown-unknown
|
||||||
|
|
||||||
- name: Cache cargo build
|
- name: Cache cargo build
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
# The wasm bundles (solitaire_server/web/pkg/) are not in the repo —
|
||||||
|
# build them here so the served pages have real wasm to load. Tool
|
||||||
|
# versions are pinned; keep in sync with solitaire_server/Dockerfile.
|
||||||
|
- name: Install wasm-bindgen-cli + wasm-pack (pinned)
|
||||||
|
uses: taiki-e/install-action@v2
|
||||||
|
with:
|
||||||
|
tool: wasm-bindgen-cli@0.2.120,wasm-pack@0.14.0
|
||||||
|
|
||||||
|
- name: Install binaryen 130 (wasm-opt, pinned)
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
curl -sSL \
|
||||||
|
https://github.com/WebAssembly/binaryen/releases/download/version_130/binaryen-version_130-x86_64-linux.tar.gz \
|
||||||
|
| tar xz
|
||||||
|
echo "$PWD/binaryen-version_130/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Build WASM artifacts
|
||||||
|
run: ./build_wasm.sh
|
||||||
|
|
||||||
# Prebuild the server so Playwright's `webServer` (which runs
|
# Prebuild the server so Playwright's `webServer` (which runs
|
||||||
# `cargo run -p solitaire_server`) starts from a compiled binary instead
|
# `cargo run -p solitaire_server`) starts from a compiled binary instead
|
||||||
# of cold-compiling the whole dependency graph (axum/sqlx/reqwest) inside
|
# of cold-compiling the whole dependency graph (axum/sqlx/reqwest) inside
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
name: Web WASM Rebuild
|
|
||||||
|
|
||||||
# CI is the single source of truth for solitaire_server/web/pkg/.
|
|
||||||
#
|
|
||||||
# The wasm artifacts cannot be reproduced byte-for-byte on an arbitrary
|
|
||||||
# contributor machine: even with identical rustc 1.95.0 / LLVM 22.1.2, the same
|
|
||||||
# flags, the same Cargo.lock and remapped source paths, the output still differs
|
|
||||||
# by host environment. So rather than police freshness with a rebuild-and-diff
|
|
||||||
# gate (which false-failed for exactly that reason), CI rebuilds the artifacts
|
|
||||||
# itself on every master change to a wasm-feeding crate and commits them back.
|
|
||||||
#
|
|
||||||
# Result: the deployed pkg/ can't silently rot, and contributors never need to
|
|
||||||
# run build_wasm.sh by hand. The commit touches only pkg/, which is not in this
|
|
||||||
# workflow's trigger paths (so it does not re-trigger here) but does match
|
|
||||||
# docker-build's, so the refreshed wasm deploys.
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
paths:
|
|
||||||
- 'solitaire_core/**'
|
|
||||||
- 'solitaire_engine/**'
|
|
||||||
- 'solitaire_data/**'
|
|
||||||
- 'solitaire_sync/**'
|
|
||||||
- 'solitaire_wasm/**'
|
|
||||||
- 'solitaire_web/**'
|
|
||||||
- 'Cargo.toml'
|
|
||||||
- 'Cargo.lock'
|
|
||||||
- 'build_wasm.sh'
|
|
||||||
- '.gitea/workflows/web-wasm-rebuild.yml'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: web-wasm-rebuild
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
rebuild:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
token: ${{ secrets.CI_TOKEN }}
|
|
||||||
|
|
||||||
- name: Install Rust 1.95.0
|
|
||||||
uses: dtolnay/rust-toolchain@master
|
|
||||||
with:
|
|
||||||
toolchain: 1.95.0
|
|
||||||
targets: wasm32-unknown-unknown
|
|
||||||
|
|
||||||
- name: Cache cargo build
|
|
||||||
uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- name: Install wasm-bindgen-cli + wasm-pack (pinned)
|
|
||||||
uses: taiki-e/install-action@v2
|
|
||||||
with:
|
|
||||||
tool: wasm-bindgen-cli@0.2.120,wasm-pack@0.14.0
|
|
||||||
|
|
||||||
- name: Install binaryen 130 (wasm-opt, pinned)
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
curl -sSL \
|
|
||||||
https://github.com/WebAssembly/binaryen/releases/download/version_130/binaryen-version_130-x86_64-linux.tar.gz \
|
|
||||||
| tar xz
|
|
||||||
echo "$PWD/binaryen-version_130/bin" >> "$GITHUB_PATH"
|
|
||||||
|
|
||||||
- name: Rebuild WASM artifacts
|
|
||||||
run: ./build_wasm.sh
|
|
||||||
|
|
||||||
- name: Commit refreshed artifacts if changed
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
if git diff --quiet -- solitaire_server/web/pkg/; then
|
|
||||||
echo "pkg/ already up to date — nothing to commit."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
git config user.email "ci@gitea.local"
|
|
||||||
git config user.name "Gitea CI"
|
|
||||||
git add solitaire_server/web/pkg/
|
|
||||||
git commit -m "chore(web): regenerate wasm artifacts"
|
|
||||||
# master is unprotected; retry once if the tip moved under us.
|
|
||||||
git push origin HEAD:master || {
|
|
||||||
git fetch origin master
|
|
||||||
git rebase origin/master
|
|
||||||
git push origin HEAD:master
|
|
||||||
}
|
|
||||||
@@ -41,3 +41,7 @@ deploy/*-auth-secret.yaml
|
|||||||
# Local token-saving helper scripts (peek/cargoclip/testfail/diffclip/etc.) —
|
# Local token-saving helper scripts (peek/cargoclip/testfail/diffclip/etc.) —
|
||||||
# inspection-only Go tools, not committed. Tracked scripts/*.sh and *.md stay.
|
# inspection-only Go tools, not committed. Tracked scripts/*.sh and *.md stay.
|
||||||
scripts/*.go
|
scripts/*.go
|
||||||
|
|
||||||
|
# WASM bundles — built by build_wasm.sh locally and by the Docker wasm-builder
|
||||||
|
# stage / web-e2e workflow in CI; never committed (issue #156)
|
||||||
|
solitaire_server/web/pkg/
|
||||||
|
|||||||
+2
-2
@@ -192,7 +192,7 @@ Owns:
|
|||||||
### `solitaire_wasm`
|
### `solitaire_wasm`
|
||||||
**Dependencies:** `solitaire_core`, `serde`, `serde_json`, `chrono`, `wasm-bindgen`, `serde-wasm-bindgen`.
|
**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.
|
WebAssembly bindings for browser-side replay playback. Compiled to `cdylib` via `wasm-pack build` (`build_wasm.sh`); the output lands in `solitaire_server/web/pkg/` — gitignored, built in CI (Docker `wasm-builder` stage, web-e2e workflow) — 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.
|
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.
|
||||||
|
|
||||||
@@ -743,7 +743,7 @@ All endpoints are under the base URL configured by the user (e.g., `https://soli
|
|||||||
| Method | Path | Auth | Notes |
|
| 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 | `/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) |
|
| GET | `/web/*` | None | Static assets served via `ServeDir` from `solitaire_server/web/` (includes `web/pkg/` with wasm-bindgen output — gitignored, produced by `build_wasm.sh` / CI) |
|
||||||
|
|
||||||
### Account Management
|
### Account Management
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -13,9 +13,10 @@
|
|||||||
# Run from the repo root:
|
# Run from the repo root:
|
||||||
# ./build_wasm.sh
|
# ./build_wasm.sh
|
||||||
#
|
#
|
||||||
# The generated pkg/ files are committed to git so self-hosters who don't
|
# The generated pkg/ files are NOT committed to git (issue #156). CI builds
|
||||||
# touch the WASM crates can skip this step. Regenerate after any change to
|
# them where needed: the Docker image's wasm-builder stage for deployment,
|
||||||
# solitaire_wasm/, solitaire_web/, solitaire_engine/, or solitaire_core/.
|
# and the web-e2e workflow for browser tests. Run this script locally before
|
||||||
|
# serving /web or /play from a source checkout.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# Live-watch the Gitea Actions deploy pipeline for Ferrous Solitaire.
|
# Live-watch the Gitea Actions deploy pipeline for Ferrous Solitaire.
|
||||||
#
|
#
|
||||||
# Polls recent workflow runs and prints a compact status block each cycle.
|
# Polls recent workflow runs and prints a compact status block each cycle.
|
||||||
# Stops when the newest docker-build (the deploy) has completed and no
|
# Stops when the newest docker-build (the deploy) has completed — the wasm
|
||||||
# web-wasm-rebuild is still pending — i.e. the full fix is live.
|
# is built inside that image build, so no other workflow gates the deploy.
|
||||||
#
|
#
|
||||||
# Usage: ./scripts/watch_deploy.sh [interval_seconds]
|
# Usage: ./scripts/watch_deploy.sh [interval_seconds]
|
||||||
# token is read from ~/.config/tea/config.yml (never printed).
|
# token is read from ~/.config/tea/config.yml (never printed).
|
||||||
@@ -49,16 +49,15 @@ for r in runs:
|
|||||||
r.get("id"), str(r.get("head_sha"))[:7], wf[:18],
|
r.get("id"), str(r.get("head_sha"))[:7], wf[:18],
|
||||||
r.get("status"), r.get("conclusion")))
|
r.get("status"), r.get("conclusion")))
|
||||||
db = [r for r in runs if "docker-build" in str(r.get("path"))]
|
db = [r for r in runs if "docker-build" in str(r.get("path"))]
|
||||||
wr_pending = any(r.get("status") != "completed" for r in runs if "web-wasm-rebuild" in str(r.get("path")))
|
|
||||||
top = db[0] if db else None
|
top = db[0] if db else None
|
||||||
live = bool(top and top.get("status")=="completed" and top.get("conclusion")=="success" and not wr_pending)
|
live = bool(top and top.get("status")=="completed" and top.get("conclusion")=="success")
|
||||||
print("STATE=%s" % ("LIVE" if live else ("WAIT_WASM" if wr_pending else "DEPLOYING")))
|
print("STATE=%s" % ("LIVE" if live else "DEPLOYING"))
|
||||||
PY
|
PY
|
||||||
)"
|
)"
|
||||||
echo "$out" | grep -v '^STATE='
|
echo "$out" | grep -v '^STATE='
|
||||||
if echo "$out" | grep -q '^STATE=LIVE'; then
|
if echo "$out" | grep -q '^STATE=LIVE'; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "DEPLOY LIVE — newest docker-build succeeded, no wasm rebuild pending."
|
echo "DEPLOY LIVE — newest docker-build succeeded."
|
||||||
echo " Test: https://klondike.aleshym.co/play?v=${RANDOM}"
|
echo " Test: https://klondike.aleshym.co/play?v=${RANDOM}"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1370,17 +1370,37 @@ pub fn best_tableau_destination_for_stack(
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Decide the auto-move for the face-up run headed by the clicked/tapped card.
|
||||||
|
///
|
||||||
|
/// The move covers **exactly** `run_len` cards — the run from the clicked
|
||||||
|
/// card to the top of its pile. A lone top card goes to its best foundation
|
||||||
|
/// (or tableau) destination; a multi-card run goes whole to the best tableau
|
||||||
|
/// column. Runs larger or smaller than the clicked one are never considered.
|
||||||
|
///
|
||||||
|
/// Returns `(destination, count)`, or `None` when the clicked run has no
|
||||||
|
/// legal destination.
|
||||||
|
pub fn auto_move_for_run(
|
||||||
|
clicked_card: &Card,
|
||||||
|
pile: &KlondikePile,
|
||||||
|
game: &GameState,
|
||||||
|
run_len: usize,
|
||||||
|
) -> Option<(KlondikePile, usize)> {
|
||||||
|
if run_len == 1 {
|
||||||
|
best_destination(clicked_card, game).map(|dest| (dest, 1))
|
||||||
|
} else {
|
||||||
|
best_tableau_destination_for_stack(clicked_card, pile, game, run_len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// System that detects double-clicks on face-up cards and fires `MoveRequestEvent`
|
/// System that detects double-clicks on face-up cards and fires `MoveRequestEvent`
|
||||||
/// to the best legal destination.
|
/// to the best legal destination.
|
||||||
///
|
///
|
||||||
/// Move priority:
|
/// The move covers exactly the face-up run headed by the clicked card —
|
||||||
/// 1. Move the single **top** card to its best foundation (or tableau) destination.
|
/// see [`auto_move_for_run`].
|
||||||
/// 2. If no single-card move exists and the clicked card is the base of a
|
|
||||||
/// multi-card face-up stack, move the whole stack to the best tableau column.
|
|
||||||
///
|
///
|
||||||
/// When a multi-card stack double-click finds no legal destination (Priority 2
|
/// When the clicked run has no legal destination, fires `MoveRejectedEvent`
|
||||||
/// returns `None`), fires `MoveRejectedEvent` with `from == to == pile` so the
|
/// with `from == to == pile` so the invalid-move sound plays and the source
|
||||||
/// invalid-move sound plays and the source pile cards shake as feedback.
|
/// pile cards shake as feedback.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn handle_double_click(
|
fn handle_double_click(
|
||||||
buttons: Res<ButtonInput<MouseButton>>,
|
buttons: Res<ButtonInput<MouseButton>>,
|
||||||
@@ -1411,7 +1431,11 @@ fn handle_double_click(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The topmost card in the draggable run — used as the double-click key.
|
// The clicked card heads the run and keys the double-click: two clicks
|
||||||
|
// on different cards of the same stack are not a double-click.
|
||||||
|
let Some(clicked_card) = card_ids.first() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let Some(top_card) = card_ids.last() else {
|
let Some(top_card) = card_ids.last() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -1426,31 +1450,15 @@ fn handle_double_click(
|
|||||||
|
|
||||||
let now = time.elapsed_secs();
|
let now = time.elapsed_secs();
|
||||||
let prev = last_click
|
let prev = last_click
|
||||||
.get(top_card)
|
.get(clicked_card)
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or(f32::NEG_INFINITY);
|
.unwrap_or(f32::NEG_INFINITY);
|
||||||
|
|
||||||
if now - prev <= DOUBLE_CLICK_WINDOW {
|
if now - prev <= DOUBLE_CLICK_WINDOW {
|
||||||
// Double-click confirmed.
|
// Double-click confirmed.
|
||||||
last_click.remove(top_card);
|
last_click.remove(clicked_card);
|
||||||
|
|
||||||
// Priority 1: move the single top card (foundation preferred, then tableau).
|
if let Some((dest, count)) = auto_move_for_run(clicked_card, &pile, &game.0, card_ids.len())
|
||||||
if let Some(dest) = best_destination(top_card, &game.0) {
|
|
||||||
moves.write(MoveRequestEvent {
|
|
||||||
from: pile,
|
|
||||||
to: dest,
|
|
||||||
count: 1,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Priority 2: if the player clicked the base of a multi-card face-up
|
|
||||||
// stack (card_ids.len() > 1), try moving the whole stack to another
|
|
||||||
// tableau column.
|
|
||||||
if card_ids.len() > 1
|
|
||||||
&& let Some((bottom_card, _)) = pile_cards.get(stack_index)
|
|
||||||
&& let Some((dest, count)) =
|
|
||||||
best_tableau_destination_for_stack(bottom_card, &pile, &game.0, card_ids.len())
|
|
||||||
{
|
{
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: pile,
|
from: pile,
|
||||||
@@ -1460,14 +1468,10 @@ fn handle_double_click(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both priorities failed — play the invalid-move sound and shake
|
// No legal destination for the clicked run — play the invalid-move
|
||||||
// the source pile as feedback. `MoveRejectedEvent` with
|
// sound and shake the source pile as feedback. `MoveRejectedEvent`
|
||||||
// `from == to` routes the shake to the source pile (which
|
// with `from == to` routes the shake to the source pile (which
|
||||||
// `start_shake_anim` reads from `ev.to`). Pre-fix, this branch
|
// `start_shake_anim` reads from `ev.to`).
|
||||||
// only fired for multi-card stacks, so a double-click on a
|
|
||||||
// single card with no legal destination did nothing — no
|
|
||||||
// sound, no shake. Now both single-card and stack misses get
|
|
||||||
// the same feedback.
|
|
||||||
rejected.write(MoveRejectedEvent {
|
rejected.write(MoveRejectedEvent {
|
||||||
from: pile,
|
from: pile,
|
||||||
to: pile,
|
to: pile,
|
||||||
@@ -1475,7 +1479,7 @@ fn handle_double_click(
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Single click — record the time.
|
// Single click — record the time.
|
||||||
last_click.insert(top_card.clone(), now);
|
last_click.insert(clicked_card.clone(), now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1491,10 +1495,9 @@ fn handle_double_click(
|
|||||||
/// `cards`, and `origin_pile`; once `touch_end_drag` fires those fields
|
/// `cards`, and `origin_pile`; once `touch_end_drag` fires those fields
|
||||||
/// are cleared and the tap/drag distinction is permanently lost.
|
/// are cleared and the tap/drag distinction is permanently lost.
|
||||||
///
|
///
|
||||||
/// Move priority:
|
/// The move covers exactly the face-up run headed by the tapped card —
|
||||||
/// 1. Single top card to its best foundation (or tableau).
|
/// see [`auto_move_for_run`]. Fires `MoveRejectedEvent` for audio + shake
|
||||||
/// 2. Whole face-up run to best tableau column when no single-card move exists.
|
/// feedback when the tapped run has no legal destination.
|
||||||
/// 3. `MoveRejectedEvent` for audio + shake feedback when no legal move found.
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn handle_double_tap(
|
fn handle_double_tap(
|
||||||
mut touch_events: MessageReader<TouchInput>,
|
mut touch_events: MessageReader<TouchInput>,
|
||||||
@@ -1554,8 +1557,7 @@ fn handle_double_tap(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((found_card, found_face_up)) = pile_cards.iter().find(|(c, _)| c == top_card)
|
let Some((_, found_face_up)) = pile_cards.iter().find(|(c, _)| c == top_card) else {
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if !*found_face_up {
|
if !*found_face_up {
|
||||||
@@ -1591,53 +1593,27 @@ fn handle_double_tap(
|
|||||||
|
|
||||||
// --- One-tap auto-move (original behaviour) ---
|
// --- One-tap auto-move (original behaviour) ---
|
||||||
|
|
||||||
// Priority 1: move single top card.
|
// Move exactly the run headed by the tapped card.
|
||||||
if let Some(dest) = best_destination(found_card, &game.0) {
|
if let Some(tapped_card) = drag.cards.first()
|
||||||
|
&& let Some((dest, count)) =
|
||||||
|
auto_move_for_run(tapped_card, tapped_pile, &game.0, drag.cards.len())
|
||||||
|
{
|
||||||
for (entity, ce, mut sprite) in card_sprites.iter_mut() {
|
for (entity, ce, mut sprite) in card_sprites.iter_mut() {
|
||||||
if ce.card == *top_card {
|
if drag.cards.contains(&ce.card) {
|
||||||
sprite.color = STATE_SUCCESS;
|
sprite.color = STATE_SUCCESS;
|
||||||
commands.entity(entity).insert(HintHighlight {
|
commands.entity(entity).insert(HintHighlight {
|
||||||
remaining: DOUBLE_TAP_FLASH_SECS,
|
remaining: DOUBLE_TAP_FLASH_SECS,
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *tapped_pile,
|
from: *tapped_pile,
|
||||||
to: dest,
|
to: dest,
|
||||||
count: 1,
|
count,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2: move whole face-up stack to best tableau column.
|
|
||||||
if drag.cards.len() > 1 {
|
|
||||||
let stack_index = pile_cards.len() - drag.cards.len();
|
|
||||||
if let Some((bottom_card, _)) = pile_cards.get(stack_index)
|
|
||||||
&& let Some((dest, count)) = best_tableau_destination_for_stack(
|
|
||||||
bottom_card,
|
|
||||||
tapped_pile,
|
|
||||||
&game.0,
|
|
||||||
drag.cards.len(),
|
|
||||||
)
|
|
||||||
{
|
|
||||||
for (entity, ce, mut sprite) in card_sprites.iter_mut() {
|
|
||||||
if drag.cards.contains(&ce.card) {
|
|
||||||
sprite.color = STATE_SUCCESS;
|
|
||||||
commands.entity(entity).insert(HintHighlight {
|
|
||||||
remaining: DOUBLE_TAP_FLASH_SECS,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
moves.write(MoveRequestEvent {
|
|
||||||
from: *tapped_pile,
|
|
||||||
to: dest,
|
|
||||||
count,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rejected.write(MoveRejectedEvent {
|
rejected.write(MoveRejectedEvent {
|
||||||
from: *tapped_pile,
|
from: *tapped_pile,
|
||||||
to: *tapped_pile,
|
to: *tapped_pile,
|
||||||
|
|||||||
@@ -429,6 +429,118 @@ fn best_tableau_destination_for_stack_returns_none_when_no_legal_move() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// auto_move_for_run pure-function tests (issue #158)
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// These need real positions — `can_move_cards` validates against the live
|
||||||
|
// session, not the `set_test_*` overlays. Seeds 51 and 145 both deal an
|
||||||
|
// Ace and its Two on tableau tops plus an opposite-color Three elsewhere,
|
||||||
|
// letting two moves build a face-up [Three, Two] run whose top card is
|
||||||
|
// foundation-eligible (the bait the pre-#158 code would take).
|
||||||
|
|
||||||
|
/// Deal `seed`, send the Ace on tableau 1 to its foundation, then stack the
|
||||||
|
/// matching Two from `two_from` onto the opposite-color Three on `run_on`.
|
||||||
|
/// Returns the game with a 2-card face-up run on `run_on`.
|
||||||
|
fn deal_run_with_foundation_bait(seed: u64, two_from: Tableau, run_on: Tableau) -> GameState {
|
||||||
|
let mut game = GameState::new(seed, DrawStockConfig::DrawOne);
|
||||||
|
let (ace, _) = game
|
||||||
|
.pile(KlondikePile::Tableau(Tableau::Tableau1))
|
||||||
|
.last()
|
||||||
|
.cloned()
|
||||||
|
.expect("seed deals a card on tableau 1");
|
||||||
|
let foundation = best_destination(&ace, &game).expect("ace has a foundation home");
|
||||||
|
game.move_cards(KlondikePile::Tableau(Tableau::Tableau1), foundation, 1)
|
||||||
|
.expect("ace moves to foundation");
|
||||||
|
game.move_cards(
|
||||||
|
KlondikePile::Tableau(two_from),
|
||||||
|
KlondikePile::Tableau(run_on),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
.expect("two stacks onto three");
|
||||||
|
game
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auto_move_for_run_moves_exact_clicked_run_not_top_card() {
|
||||||
|
let game = deal_run_with_foundation_bait(51, Tableau::Tableau6, Tableau::Tableau5);
|
||||||
|
let run_pile = KlondikePile::Tableau(Tableau::Tableau5);
|
||||||
|
let cards = game.pile(run_pile);
|
||||||
|
let (top, _) = cards.last().cloned().expect("run pile has cards");
|
||||||
|
let (clicked, _) = cards[cards.len() - 2].clone();
|
||||||
|
|
||||||
|
// The bait: the lone top card has a foundation move available.
|
||||||
|
assert!(
|
||||||
|
matches!(
|
||||||
|
best_destination(&top, &game),
|
||||||
|
Some(KlondikePile::Foundation(_))
|
||||||
|
),
|
||||||
|
"precondition: run top card must be foundation-eligible"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Clicking the run base must move exactly the 2-card run to a tableau.
|
||||||
|
match auto_move_for_run(&clicked, &run_pile, &game, 2) {
|
||||||
|
Some((KlondikePile::Tableau(dest), 2)) => assert_ne!(dest, Tableau::Tableau5),
|
||||||
|
other => panic!("expected a whole-run tableau move, got {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auto_move_for_run_rejects_when_clicked_run_cannot_move() {
|
||||||
|
let game = deal_run_with_foundation_bait(145, Tableau::Tableau4, Tableau::Tableau7);
|
||||||
|
let run_pile = KlondikePile::Tableau(Tableau::Tableau7);
|
||||||
|
let cards = game.pile(run_pile);
|
||||||
|
let (top, _) = cards.last().cloned().expect("run pile has cards");
|
||||||
|
let (clicked, _) = cards[cards.len() - 2].clone();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
matches!(
|
||||||
|
best_destination(&top, &game),
|
||||||
|
Some(KlondikePile::Foundation(_))
|
||||||
|
),
|
||||||
|
"precondition: run top card must be foundation-eligible"
|
||||||
|
);
|
||||||
|
|
||||||
|
// The 2-card run has no legal home — the top card's foundation move
|
||||||
|
// must NOT be taken as a substitute.
|
||||||
|
assert_eq!(
|
||||||
|
auto_move_for_run(&clicked, &run_pile, &game, 2),
|
||||||
|
None,
|
||||||
|
"an immovable clicked run must not fall back to a top-card move"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn auto_move_for_run_single_card_prefers_foundation() {
|
||||||
|
// Seed 51 after the Ace reaches the foundation: the Two on tableau 6
|
||||||
|
// is a lone face-up card that could go to the foundation OR onto the
|
||||||
|
// Three on tableau 5. Foundation must win.
|
||||||
|
let mut game = GameState::new(51, DrawStockConfig::DrawOne);
|
||||||
|
let (ace, _) = game
|
||||||
|
.pile(KlondikePile::Tableau(Tableau::Tableau1))
|
||||||
|
.last()
|
||||||
|
.cloned()
|
||||||
|
.expect("seed 51 deals a card on tableau 1");
|
||||||
|
let foundation = best_destination(&ace, &game).expect("ace has a foundation home");
|
||||||
|
game.move_cards(KlondikePile::Tableau(Tableau::Tableau1), foundation, 1)
|
||||||
|
.expect("ace moves to foundation");
|
||||||
|
|
||||||
|
let two_pile = KlondikePile::Tableau(Tableau::Tableau6);
|
||||||
|
let (two, _) = game.pile(two_pile).last().cloned().expect("two on top");
|
||||||
|
assert!(
|
||||||
|
game.can_move_cards(&two_pile, &KlondikePile::Tableau(Tableau::Tableau5), 1),
|
||||||
|
"precondition: a tableau destination also exists"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
matches!(
|
||||||
|
auto_move_for_run(&two, &two_pile, &game, 1),
|
||||||
|
Some((KlondikePile::Foundation(_), 1))
|
||||||
|
),
|
||||||
|
"a lone top card still prefers the foundation"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// Task #28 — find_hint pure-function tests
|
// Task #28 — find_hint pure-function tests
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,3 +1,68 @@
|
|||||||
|
# --- WASM build stage ---
|
||||||
|
# Builds solitaire_server/web/pkg/ (replay viewer + Bevy canvas app) from
|
||||||
|
# source. The artifacts are not committed to the repo (issue #156); this
|
||||||
|
# stage is their single source of truth for deployment.
|
||||||
|
FROM rust:1.95-slim AS wasm-builder
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
curl \
|
||||||
|
ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
|
|
||||||
|
# Pinned wasm toolchain — keep versions in sync with
|
||||||
|
# .gitea/workflows/web-e2e.yml and build_wasm.sh prerequisites.
|
||||||
|
RUN curl -sSL https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.120/wasm-bindgen-0.2.120-x86_64-unknown-linux-musl.tar.gz \
|
||||||
|
| tar xz -C /opt \
|
||||||
|
&& ln -s /opt/wasm-bindgen-0.2.120-x86_64-unknown-linux-musl/wasm-bindgen /usr/local/bin/wasm-bindgen \
|
||||||
|
&& curl -sSL https://github.com/rustwasm/wasm-pack/releases/download/v0.14.0/wasm-pack-v0.14.0-x86_64-unknown-linux-musl.tar.gz \
|
||||||
|
| tar xz -C /opt \
|
||||||
|
&& ln -s /opt/wasm-pack-v0.14.0-x86_64-unknown-linux-musl/wasm-pack /usr/local/bin/wasm-pack \
|
||||||
|
&& curl -sSL https://github.com/WebAssembly/binaryen/releases/download/version_130/binaryen-version_130-x86_64-linux.tar.gz \
|
||||||
|
| tar xz -C /opt \
|
||||||
|
&& ln -s /opt/binaryen-version_130/bin/wasm-opt /usr/local/bin/wasm-opt
|
||||||
|
|
||||||
|
# Manifests first so the dependency-fetch layer caches across source changes
|
||||||
|
# (same pattern as the server build stage below).
|
||||||
|
COPY .cargo/config.toml ./.cargo/config.toml
|
||||||
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
COPY solitaire_core/Cargo.toml ./solitaire_core/Cargo.toml
|
||||||
|
COPY solitaire_sync/Cargo.toml ./solitaire_sync/Cargo.toml
|
||||||
|
COPY solitaire_data/Cargo.toml ./solitaire_data/Cargo.toml
|
||||||
|
COPY solitaire_engine/Cargo.toml ./solitaire_engine/Cargo.toml
|
||||||
|
COPY solitaire_server/Cargo.toml ./solitaire_server/Cargo.toml
|
||||||
|
COPY solitaire_app/Cargo.toml ./solitaire_app/Cargo.toml
|
||||||
|
COPY solitaire_assetgen/Cargo.toml ./solitaire_assetgen/Cargo.toml
|
||||||
|
COPY solitaire_wasm/Cargo.toml ./solitaire_wasm/Cargo.toml
|
||||||
|
COPY solitaire_web/Cargo.toml ./solitaire_web/Cargo.toml
|
||||||
|
|
||||||
|
RUN for crate in solitaire_core solitaire_sync solitaire_data solitaire_engine \
|
||||||
|
solitaire_server solitaire_app solitaire_assetgen solitaire_wasm solitaire_web; do \
|
||||||
|
mkdir -p $crate/src && echo "pub fn _stub() {}" > $crate/src/lib.rs; \
|
||||||
|
done && \
|
||||||
|
echo "fn main() {}" > solitaire_server/src/main.rs && \
|
||||||
|
echo "fn main() {}" > solitaire_app/src/main.rs && \
|
||||||
|
echo "fn main() {}" > solitaire_assetgen/src/main.rs
|
||||||
|
|
||||||
|
RUN cargo fetch --locked
|
||||||
|
|
||||||
|
# Real source for the wasm-feeding crates. Whole crate directories (not just
|
||||||
|
# src/) because solitaire_engine embeds theme/audio/font assets at compile
|
||||||
|
# time from its own assets/ and the workspace assets/.
|
||||||
|
COPY build_wasm.sh ./
|
||||||
|
COPY solitaire_core ./solitaire_core
|
||||||
|
COPY solitaire_sync ./solitaire_sync
|
||||||
|
COPY solitaire_data ./solitaire_data
|
||||||
|
COPY solitaire_engine ./solitaire_engine
|
||||||
|
COPY solitaire_wasm ./solitaire_wasm
|
||||||
|
COPY solitaire_web ./solitaire_web
|
||||||
|
COPY assets ./assets
|
||||||
|
|
||||||
|
RUN ./build_wasm.sh
|
||||||
|
|
||||||
# --- Build stage ---
|
# --- Build stage ---
|
||||||
FROM rust:1.95-slim AS builder
|
FROM rust:1.95-slim AS builder
|
||||||
|
|
||||||
@@ -67,6 +132,8 @@ COPY --from=builder /build/target/release/solitaire_server ./server
|
|||||||
# /app/assets → /assets route
|
# /app/assets → /assets route
|
||||||
# Card themes (dark + classic) are embedded in the binary; no theme files needed here.
|
# Card themes (dark + classic) are embedded in the binary; no theme files needed here.
|
||||||
COPY solitaire_server/web ./solitaire_server/web
|
COPY solitaire_server/web ./solitaire_server/web
|
||||||
|
# The wasm bundles are never in the repo — they come from the wasm-builder stage.
|
||||||
|
COPY --from=wasm-builder /build/solitaire_server/web/pkg ./solitaire_server/web/pkg
|
||||||
COPY assets ./assets
|
COPY assets ./assets
|
||||||
|
|
||||||
ENV SERVER_PORT=8080
|
ENV SERVER_PORT=8080
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,587 +0,0 @@
|
|||||||
/**
|
|
||||||
* Browser-side replay state machine. Owns a live `GameState` and the
|
|
||||||
* replay's move list; each `step()` applies the next move.
|
|
||||||
*/
|
|
||||||
export class ReplayPlayer {
|
|
||||||
__destroy_into_raw() {
|
|
||||||
const ptr = this.__wbg_ptr;
|
|
||||||
this.__wbg_ptr = 0;
|
|
||||||
ReplayPlayerFinalization.unregister(this);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
free() {
|
|
||||||
const ptr = this.__destroy_into_raw();
|
|
||||||
wasm.__wbg_replayplayer_free(ptr, 0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Construct from a raw replay JSON string.
|
|
||||||
* @param {string} replay_json
|
|
||||||
*/
|
|
||||||
constructor(replay_json) {
|
|
||||||
const ptr0 = passStringToWasm0(replay_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const ret = wasm.replayplayer_new(ptr0, len0);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
this.__wbg_ptr = ret[0];
|
|
||||||
ReplayPlayerFinalization.register(this, this.__wbg_ptr, this);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Snapshot the current `GameState` as a JS object (see `StateSnapshot`).
|
|
||||||
*
|
|
||||||
* Throws a JS string exception on serialisation failure (should never
|
|
||||||
* occur in practice — `StateSnapshot` contains only primitive types).
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
state() {
|
|
||||||
const ret = wasm.replayplayer_state(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Apply the next move; returns the post-step snapshot, or `null`
|
|
||||||
* once the move list is exhausted.
|
|
||||||
*
|
|
||||||
* Returns `null` (not an exception) when the replay is finished.
|
|
||||||
* Throws `"replay_desync"` when the next recorded move is illegal for
|
|
||||||
* the current state, and logs the underlying core error to the JS console.
|
|
||||||
* Throws a JS string exception on serialisation failure.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
step() {
|
|
||||||
const ret = wasm.replayplayer_step(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 0-indexed position of the next move to apply.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
step_idx() {
|
|
||||||
const ret = wasm.replayplayer_step_idx(this.__wbg_ptr);
|
|
||||||
return ret >>> 0;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Total number of moves the replay contains.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
total_steps() {
|
|
||||||
const ret = wasm.replayplayer_total_steps(this.__wbg_ptr);
|
|
||||||
return ret >>> 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Symbol.dispose) ReplayPlayer.prototype[Symbol.dispose] = ReplayPlayer.prototype.free;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interactive Klondike game backed by the real `solitaire_core` rules engine.
|
|
||||||
*
|
|
||||||
* Construct with `new(seed, draw_three)`, then call `draw()`, `move_cards()`,
|
|
||||||
* `undo()`, `auto_complete_step()` to advance the game. `state()` returns the
|
|
||||||
* full pile snapshot at any time without mutating state.
|
|
||||||
*/
|
|
||||||
export class SolitaireGame {
|
|
||||||
static __wrap(ptr) {
|
|
||||||
const obj = Object.create(SolitaireGame.prototype);
|
|
||||||
obj.__wbg_ptr = ptr;
|
|
||||||
SolitaireGameFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
__destroy_into_raw() {
|
|
||||||
const ptr = this.__wbg_ptr;
|
|
||||||
this.__wbg_ptr = 0;
|
|
||||||
SolitaireGameFinalization.unregister(this);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
free() {
|
|
||||||
const ptr = this.__destroy_into_raw();
|
|
||||||
wasm.__wbg_solitairegame_free(ptr, 0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Apply one auto-complete move (only valid when `is_auto_completable`).
|
|
||||||
*
|
|
||||||
* If no card can go directly to a foundation this step, advances the
|
|
||||||
* waste by calling `draw()` so the next step can try again. Returns the
|
|
||||||
* post-move snapshot, or `null` when no progress is possible.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
auto_complete_step() {
|
|
||||||
const ret = wasm.solitairegame_auto_complete_step(this.__wbg_ptr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Applies the legal move currently at `index` from `debug_legal_moves()`.
|
|
||||||
* @param {number} index
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
debug_apply_legal_move(index) {
|
|
||||||
const ret = wasm.solitairegame_debug_apply_legal_move(this.__wbg_ptr, index);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Applies one debug move encoded as JSON.
|
|
||||||
*
|
|
||||||
* JSON must match [`DebugMove`], for example:
|
|
||||||
* `{"kind":"move","from":"tableau-0","to":"foundation-1","count":1}` or
|
|
||||||
* `{"kind":"stock_click"}`.
|
|
||||||
* @param {string} move_json
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
debug_apply_move_json(move_json) {
|
|
||||||
const ptr0 = passStringToWasm0(move_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const ret = wasm.solitairegame_debug_apply_move_json(this.__wbg_ptr, ptr0, len0);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns all currently-legal debug moves as a JS array.
|
|
||||||
*
|
|
||||||
* Includes [`DebugMove::StockClick`] when stock interaction is legal.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
debug_legal_moves() {
|
|
||||||
const ret = wasm.solitairegame_debug_legal_moves(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns deterministic instruction history for the current game.
|
|
||||||
*
|
|
||||||
* Together with `seed()` and `draw_mode`, this history is replayable.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
debug_move_history() {
|
|
||||||
const ret = wasm.solitairegame_debug_move_history(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns a comprehensive debug snapshot for automated verification.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
debug_snapshot() {
|
|
||||||
const ret = wasm.solitairegame_debug_snapshot(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Draw from stock to waste (or recycle waste → stock when stock is empty).
|
|
||||||
* Returns `{ok, error?, snapshot?}`.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
draw() {
|
|
||||||
const ret = wasm.solitairegame_draw(this.__wbg_ptr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Restore a game from a JSON string previously produced by [`SolitaireGame::serialize`].
|
|
||||||
*
|
|
||||||
* Returns an error string if the JSON is malformed or describes a state
|
|
||||||
* that can't be deserialised (e.g. from a future schema version).
|
|
||||||
* @param {string} json
|
|
||||||
* @returns {SolitaireGame}
|
|
||||||
*/
|
|
||||||
static from_saved(json) {
|
|
||||||
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const ret = wasm.solitairegame_from_saved(ptr0, len0);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return SolitaireGame.__wrap(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Move `count` cards from pile `from` to pile `to`.
|
|
||||||
*
|
|
||||||
* Pile names: `"stock"`, `"waste"`, `"foundation-0"` .. `"foundation-3"`,
|
|
||||||
* `"tableau-0"` .. `"tableau-6"`.
|
|
||||||
*
|
|
||||||
* Returns `{ok, error?, snapshot?}`.
|
|
||||||
* @param {string} from
|
|
||||||
* @param {string} to
|
|
||||||
* @param {number} count
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
move_cards(from, to, count) {
|
|
||||||
const ptr0 = passStringToWasm0(from, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len0 = WASM_VECTOR_LEN;
|
|
||||||
const ptr1 = passStringToWasm0(to, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len1 = WASM_VECTOR_LEN;
|
|
||||||
const ret = wasm.solitairegame_move_cards(this.__wbg_ptr, ptr0, len0, ptr1, len1, count);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Create a new DrawOne or DrawThree Classic game from the given seed.
|
|
||||||
*
|
|
||||||
* `seed` is a JS `number` (f64); values up to 2^53 are represented exactly.
|
|
||||||
* Pass `Date.now()` or a random integer from JS for variety.
|
|
||||||
* @param {number} seed
|
|
||||||
* @param {boolean} draw_three
|
|
||||||
*/
|
|
||||||
constructor(seed, draw_three) {
|
|
||||||
const ret = wasm.solitairegame_new(seed, draw_three);
|
|
||||||
this.__wbg_ptr = ret;
|
|
||||||
SolitaireGameFinalization.register(this, this.__wbg_ptr, this);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns replay moves encoded in the `solitaire_data::Replay` wire format
|
|
||||||
* — a list of upstream [`KlondikeInstruction`]s.
|
|
||||||
*
|
|
||||||
* This is the deterministic instruction history; together with `seed()`
|
|
||||||
* and the draw mode it replays cleanly via `apply_instruction`.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
replay_moves() {
|
|
||||||
const ret = wasm.solitairegame_replay_moves(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* The seed used to deal this game.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
seed() {
|
|
||||||
const ret = wasm.solitairegame_seed(this.__wbg_ptr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Serialise the full game state as a JSON string for `localStorage`.
|
|
||||||
*
|
|
||||||
* Use [`SolitaireGame::from_saved`] to restore it. The returned string is
|
|
||||||
* opaque — callers should treat it as a blob and store/restore it verbatim.
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
serialize() {
|
|
||||||
let deferred2_0;
|
|
||||||
let deferred2_1;
|
|
||||||
try {
|
|
||||||
const ret = wasm.solitairegame_serialize(this.__wbg_ptr);
|
|
||||||
var ptr1 = ret[0];
|
|
||||||
var len1 = ret[1];
|
|
||||||
if (ret[3]) {
|
|
||||||
ptr1 = 0; len1 = 0;
|
|
||||||
throw takeFromExternrefTable0(ret[2]);
|
|
||||||
}
|
|
||||||
deferred2_0 = ptr1;
|
|
||||||
deferred2_1 = len1;
|
|
||||||
return getStringFromWasm0(ptr1, len1);
|
|
||||||
} finally {
|
|
||||||
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Full pile snapshot as a JS object.
|
|
||||||
*
|
|
||||||
* Throws a JS string exception on serialisation failure.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
state() {
|
|
||||||
const ret = wasm.solitairegame_state(this.__wbg_ptr);
|
|
||||||
if (ret[2]) {
|
|
||||||
throw takeFromExternrefTable0(ret[1]);
|
|
||||||
}
|
|
||||||
return takeFromExternrefTable0(ret[0]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Undo the last move. Returns `{ok, error?, snapshot?}`.
|
|
||||||
* @returns {any}
|
|
||||||
*/
|
|
||||||
undo() {
|
|
||||||
const ret = wasm.solitairegame_undo(this.__wbg_ptr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Symbol.dispose) SolitaireGame.prototype[Symbol.dispose] = SolitaireGame.prototype.free;
|
|
||||||
function __wbg_get_imports() {
|
|
||||||
const import0 = {
|
|
||||||
__proto__: null,
|
|
||||||
__wbg_Error_3639a60ed15f87e7: function(arg0, arg1) {
|
|
||||||
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
||||||
const ret = String(arg1);
|
|
||||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len1 = WASM_VECTOR_LEN;
|
|
||||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
||||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
||||||
},
|
|
||||||
__wbg___wbindgen_throw_9c75d47bf9e7731e: function(arg0, arg1) {
|
|
||||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
||||||
},
|
|
||||||
__wbg_error_48655ee7e4756f8b: function(arg0) {
|
|
||||||
console.error(arg0);
|
|
||||||
},
|
|
||||||
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
||||||
let deferred0_0;
|
|
||||||
let deferred0_1;
|
|
||||||
try {
|
|
||||||
deferred0_0 = arg0;
|
|
||||||
deferred0_1 = arg1;
|
|
||||||
console.error(getStringFromWasm0(arg0, arg1));
|
|
||||||
} finally {
|
|
||||||
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
__wbg_new_227d7c05414eb861: function() {
|
|
||||||
const ret = new Error();
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbg_new_2fad8ca02fd00684: function() {
|
|
||||||
const ret = new Object();
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbg_new_3baa8d9866155c79: function() {
|
|
||||||
const ret = new Array();
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
||||||
arg0[arg1] = arg2;
|
|
||||||
},
|
|
||||||
__wbg_set_f614f6a0608d1d1d: function(arg0, arg1, arg2) {
|
|
||||||
arg0[arg1 >>> 0] = arg2;
|
|
||||||
},
|
|
||||||
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
||||||
const ret = arg1.stack;
|
|
||||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
||||||
const len1 = WASM_VECTOR_LEN;
|
|
||||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
||||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
||||||
},
|
|
||||||
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
||||||
// Cast intrinsic for `F64 -> Externref`.
|
|
||||||
const ret = arg0;
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
||||||
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
||||||
const ret = getStringFromWasm0(arg0, arg1);
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
||||||
// Cast intrinsic for `U64 -> Externref`.
|
|
||||||
const ret = BigInt.asUintN(64, arg0);
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
__wbindgen_init_externref_table: function() {
|
|
||||||
const table = wasm.__wbindgen_externrefs;
|
|
||||||
const offset = table.grow(4);
|
|
||||||
table.set(0, undefined);
|
|
||||||
table.set(offset + 0, undefined);
|
|
||||||
table.set(offset + 1, null);
|
|
||||||
table.set(offset + 2, true);
|
|
||||||
table.set(offset + 3, false);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
__proto__: null,
|
|
||||||
"./solitaire_wasm_bg.js": import0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const ReplayPlayerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
||||||
? { register: () => {}, unregister: () => {} }
|
|
||||||
: new FinalizationRegistry(ptr => wasm.__wbg_replayplayer_free(ptr, 1));
|
|
||||||
const SolitaireGameFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
||||||
? { register: () => {}, unregister: () => {} }
|
|
||||||
: new FinalizationRegistry(ptr => wasm.__wbg_solitairegame_free(ptr, 1));
|
|
||||||
|
|
||||||
let cachedDataViewMemory0 = null;
|
|
||||||
function getDataViewMemory0() {
|
|
||||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
||||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachedDataViewMemory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStringFromWasm0(ptr, len) {
|
|
||||||
return decodeText(ptr >>> 0, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachedUint8ArrayMemory0 = null;
|
|
||||||
function getUint8ArrayMemory0() {
|
|
||||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
||||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachedUint8ArrayMemory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function passStringToWasm0(arg, malloc, realloc) {
|
|
||||||
if (realloc === undefined) {
|
|
||||||
const buf = cachedTextEncoder.encode(arg);
|
|
||||||
const ptr = malloc(buf.length, 1) >>> 0;
|
|
||||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
||||||
WASM_VECTOR_LEN = buf.length;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let len = arg.length;
|
|
||||||
let ptr = malloc(len, 1) >>> 0;
|
|
||||||
|
|
||||||
const mem = getUint8ArrayMemory0();
|
|
||||||
|
|
||||||
let offset = 0;
|
|
||||||
|
|
||||||
for (; offset < len; offset++) {
|
|
||||||
const code = arg.charCodeAt(offset);
|
|
||||||
if (code > 0x7F) break;
|
|
||||||
mem[ptr + offset] = code;
|
|
||||||
}
|
|
||||||
if (offset !== len) {
|
|
||||||
if (offset !== 0) {
|
|
||||||
arg = arg.slice(offset);
|
|
||||||
}
|
|
||||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
||||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
||||||
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
||||||
|
|
||||||
offset += ret.written;
|
|
||||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
WASM_VECTOR_LEN = offset;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
function takeFromExternrefTable0(idx) {
|
|
||||||
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
||||||
wasm.__externref_table_dealloc(idx);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
||||||
cachedTextDecoder.decode();
|
|
||||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
||||||
let numBytesDecoded = 0;
|
|
||||||
function decodeText(ptr, len) {
|
|
||||||
numBytesDecoded += len;
|
|
||||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
||||||
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
||||||
cachedTextDecoder.decode();
|
|
||||||
numBytesDecoded = len;
|
|
||||||
}
|
|
||||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachedTextEncoder = new TextEncoder();
|
|
||||||
|
|
||||||
if (!('encodeInto' in cachedTextEncoder)) {
|
|
||||||
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
||||||
const buf = cachedTextEncoder.encode(arg);
|
|
||||||
view.set(buf);
|
|
||||||
return {
|
|
||||||
read: arg.length,
|
|
||||||
written: buf.length
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
|
||||||
|
|
||||||
let wasmModule, wasmInstance, wasm;
|
|
||||||
function __wbg_finalize_init(instance, module) {
|
|
||||||
wasmInstance = instance;
|
|
||||||
wasm = instance.exports;
|
|
||||||
wasmModule = module;
|
|
||||||
cachedDataViewMemory0 = null;
|
|
||||||
cachedUint8ArrayMemory0 = null;
|
|
||||||
wasm.__wbindgen_start();
|
|
||||||
return wasm;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function __wbg_load(module, imports) {
|
|
||||||
if (typeof Response === 'function' && module instanceof Response) {
|
|
||||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
||||||
try {
|
|
||||||
return await WebAssembly.instantiateStreaming(module, imports);
|
|
||||||
} catch (e) {
|
|
||||||
const validResponse = module.ok && expectedResponseType(module.type);
|
|
||||||
|
|
||||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
||||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
||||||
|
|
||||||
} else { throw e; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const bytes = await module.arrayBuffer();
|
|
||||||
return await WebAssembly.instantiate(bytes, imports);
|
|
||||||
} else {
|
|
||||||
const instance = await WebAssembly.instantiate(module, imports);
|
|
||||||
|
|
||||||
if (instance instanceof WebAssembly.Instance) {
|
|
||||||
return { instance, module };
|
|
||||||
} else {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function expectedResponseType(type) {
|
|
||||||
switch (type) {
|
|
||||||
case 'basic': case 'cors': case 'default': return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function initSync(module) {
|
|
||||||
if (wasm !== undefined) return wasm;
|
|
||||||
|
|
||||||
|
|
||||||
if (module !== undefined) {
|
|
||||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
||||||
({module} = module)
|
|
||||||
} else {
|
|
||||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const imports = __wbg_get_imports();
|
|
||||||
if (!(module instanceof WebAssembly.Module)) {
|
|
||||||
module = new WebAssembly.Module(module);
|
|
||||||
}
|
|
||||||
const instance = new WebAssembly.Instance(module, imports);
|
|
||||||
return __wbg_finalize_init(instance, module);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function __wbg_init(module_or_path) {
|
|
||||||
if (wasm !== undefined) return wasm;
|
|
||||||
|
|
||||||
|
|
||||||
if (module_or_path !== undefined) {
|
|
||||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
||||||
({module_or_path} = module_or_path)
|
|
||||||
} else {
|
|
||||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (module_or_path === undefined) {
|
|
||||||
module_or_path = new URL('solitaire_wasm_bg.wasm', import.meta.url);
|
|
||||||
}
|
|
||||||
const imports = __wbg_get_imports();
|
|
||||||
|
|
||||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
||||||
module_or_path = fetch(module_or_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
||||||
|
|
||||||
return __wbg_finalize_init(instance, module);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { initSync, __wbg_init as default };
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user