Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aebb401c44 | |||
| a550a0cdf9 | |||
| 8f5193035b | |||
| c21c0ebf99 | |||
| ccccdd2b40 |
@@ -1,5 +0,0 @@
|
|||||||
[registries.Quaternions]
|
|
||||||
index = "sparse+https://git.aleshym.co/api/packages/Quaternions/cargo/"
|
|
||||||
|
|
||||||
[target.wasm32-unknown-unknown]
|
|
||||||
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
|
|
||||||
@@ -6,14 +6,10 @@ on:
|
|||||||
branches: [master]
|
branches: [master]
|
||||||
paths:
|
paths:
|
||||||
- 'solitaire_server/**'
|
- 'solitaire_server/**'
|
||||||
- 'solitaire_wasm/**'
|
|
||||||
- 'solitaire_web/**'
|
|
||||||
- 'solitaire_sync/**'
|
- 'solitaire_sync/**'
|
||||||
- 'solitaire_core/**'
|
- 'solitaire_core/**'
|
||||||
- 'solitaire_engine/**'
|
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
- 'Cargo.lock'
|
- 'Cargo.lock'
|
||||||
- 'solitaire_server/Dockerfile'
|
|
||||||
- '.gitea/workflows/docker-build.yml'
|
- '.gitea/workflows/docker-build.yml'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -36,48 +32,6 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Check wasm pkg drift
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
BASE_SHA="${{ github.event.before }}"
|
|
||||||
HEAD_SHA="${{ github.sha }}"
|
|
||||||
if [ -n "$BASE_SHA" ] && git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then
|
|
||||||
RANGE="$BASE_SHA..$HEAD_SHA"
|
|
||||||
else
|
|
||||||
RANGE="HEAD~1..HEAD"
|
|
||||||
fi
|
|
||||||
|
|
||||||
CHANGED="$(git diff --name-only "$RANGE")"
|
|
||||||
echo "Changed files:"
|
|
||||||
echo "$CHANGED"
|
|
||||||
|
|
||||||
if echo "$CHANGED" | grep -Eq '^(solitaire_wasm/|solitaire_core/|Cargo\.toml|Cargo\.lock)$|^(solitaire_wasm/|solitaire_core/)'; then
|
|
||||||
if ! echo "$CHANGED" | grep -Eq '^solitaire_server/web/pkg/solitaire_wasm\.js$|^solitaire_server/web/pkg/solitaire_wasm_bg\.wasm$'; then
|
|
||||||
echo "error: wasm/core/Cargo changed but committed web pkg artifacts are missing."
|
|
||||||
echo "Run: wasm-pack build --target web --out-dir solitaire_server/web/pkg --no-typescript solitaire_wasm"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Hard check: solitaire_web/ is the direct Bevy WASM source — any
|
|
||||||
# change there MUST rebuild canvas_bg.wasm or the binary goes stale.
|
|
||||||
if echo "$CHANGED" | grep -Eq '^solitaire_web/'; then
|
|
||||||
if ! echo "$CHANGED" | grep -Eq '^solitaire_server/web/pkg/canvas_bg\.wasm$'; then
|
|
||||||
echo "error: solitaire_web/ changed but canvas_bg.wasm not updated."
|
|
||||||
echo "Run: ./build_wasm.sh (requires wasm-bindgen-cli + wasm32-unknown-unknown target)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Advisory notice: solitaire_engine/ and solitaire_core/ changes often
|
|
||||||
# require a Bevy WASM rebuild but are not enforced (formatting-only
|
|
||||||
# commits should not be blocked).
|
|
||||||
if echo "$CHANGED" | grep -Eq '^(solitaire_engine/|solitaire_core/)' && \
|
|
||||||
! echo "$CHANGED" | grep -Eq '^solitaire_server/web/pkg/canvas_bg\.wasm$'; then
|
|
||||||
echo "notice: solitaire_engine/core changed without a canvas_bg.wasm rebuild."
|
|
||||||
echo " If the change affects gameplay run ./build_wasm.sh before pushing."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Log in to Gitea registry
|
- name: Log in to Gitea registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -15,11 +15,6 @@ agentdb.rvf.lock
|
|||||||
# IDE project files
|
# IDE project files
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Browser e2e harness artifacts
|
|
||||||
solitaire_server/e2e/node_modules/
|
|
||||||
solitaire_server/e2e/playwright-report/
|
|
||||||
solitaire_server/e2e/test-results/
|
|
||||||
|
|
||||||
# Android signing keystores — never commit
|
# Android signing keystores — never commit
|
||||||
*.jks
|
*.jks
|
||||||
*.jks.bak
|
*.jks.bak
|
||||||
|
|||||||
Generated
+13
-352
@@ -364,12 +364,6 @@ version = "0.7.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arrayvec"
|
|
||||||
version = "0.7.6"
|
|
||||||
source = "sparse+https://git.aleshym.co/api/packages/Quaternions/cargo/"
|
|
||||||
checksum = "813440870d646c57c222c1d713dc4e3ddcb2919c3801564d767d85d7bf2afee4"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "as-raw-xcb-connection"
|
name = "as-raw-xcb-connection"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -723,28 +717,6 @@ dependencies = [
|
|||||||
"android-activity",
|
"android-activity",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_anti_alias"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "726cc494eb7d6a84ce6291c23636fd451fa4846604dc059fa93febca4e60a928"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_core_pipeline",
|
|
||||||
"bevy_derive",
|
|
||||||
"bevy_diagnostic",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_image",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_render",
|
|
||||||
"bevy_shader",
|
|
||||||
"bevy_utils",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_app"
|
name = "bevy_app"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -906,35 +878,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_dev_tools"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a4f1464a3f5ef5c23d917987714ee89881f9f791e9ff97ecf6600ee846b9569e"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_color",
|
|
||||||
"bevy_diagnostic",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_image",
|
|
||||||
"bevy_input",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_picking",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_render",
|
|
||||||
"bevy_shader",
|
|
||||||
"bevy_state",
|
|
||||||
"bevy_text",
|
|
||||||
"bevy_time",
|
|
||||||
"bevy_transform",
|
|
||||||
"bevy_ui",
|
|
||||||
"bevy_ui_render",
|
|
||||||
"bevy_window",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_diagnostic"
|
name = "bevy_diagnostic"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -958,7 +901,7 @@ version = "0.18.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c9cf7a3ee41342dd7b5a5d82e200d0e8efb933169247fce853b4ad633d51e87d"
|
checksum = "c9cf7a3ee41342dd7b5a5d82e200d0e8efb933169247fce853b4ad633d51e87d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bevy_ecs_macros",
|
"bevy_ecs_macros",
|
||||||
"bevy_platform",
|
"bevy_platform",
|
||||||
"bevy_ptr",
|
"bevy_ptr",
|
||||||
@@ -1002,36 +945,6 @@ dependencies = [
|
|||||||
"encase_derive_impl",
|
"encase_derive_impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_feathers"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1cb29be8f8443c5cc44e1c4710bbe02877e73703c60228ca043f20529a5496c6"
|
|
||||||
dependencies = [
|
|
||||||
"accesskit",
|
|
||||||
"bevy_a11y",
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_color",
|
|
||||||
"bevy_derive",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_input_focus",
|
|
||||||
"bevy_log",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_picking",
|
|
||||||
"bevy_platform",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_render",
|
|
||||||
"bevy_shader",
|
|
||||||
"bevy_text",
|
|
||||||
"bevy_ui",
|
|
||||||
"bevy_ui_render",
|
|
||||||
"bevy_ui_widgets",
|
|
||||||
"bevy_window",
|
|
||||||
"smol_str",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_gizmos"
|
name = "bevy_gizmos"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -1154,17 +1067,14 @@ checksum = "6a11df62e49897def470471551c02f13c6fb488e55dddb5ab7ef098132e07754"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy_a11y",
|
"bevy_a11y",
|
||||||
"bevy_android",
|
"bevy_android",
|
||||||
"bevy_anti_alias",
|
|
||||||
"bevy_app",
|
"bevy_app",
|
||||||
"bevy_asset",
|
"bevy_asset",
|
||||||
"bevy_camera",
|
"bevy_camera",
|
||||||
"bevy_color",
|
"bevy_color",
|
||||||
"bevy_core_pipeline",
|
"bevy_core_pipeline",
|
||||||
"bevy_derive",
|
"bevy_derive",
|
||||||
"bevy_dev_tools",
|
|
||||||
"bevy_diagnostic",
|
"bevy_diagnostic",
|
||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
"bevy_feathers",
|
|
||||||
"bevy_gizmos_render",
|
"bevy_gizmos_render",
|
||||||
"bevy_image",
|
"bevy_image",
|
||||||
"bevy_input",
|
"bevy_input",
|
||||||
@@ -1172,7 +1082,6 @@ dependencies = [
|
|||||||
"bevy_log",
|
"bevy_log",
|
||||||
"bevy_math",
|
"bevy_math",
|
||||||
"bevy_mesh",
|
"bevy_mesh",
|
||||||
"bevy_pbr",
|
|
||||||
"bevy_platform",
|
"bevy_platform",
|
||||||
"bevy_ptr",
|
"bevy_ptr",
|
||||||
"bevy_reflect",
|
"bevy_reflect",
|
||||||
@@ -1192,27 +1101,6 @@ dependencies = [
|
|||||||
"bevy_winit",
|
"bevy_winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_light"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d9d2ac64390a9baacb3c0fa0f5456ac1553959d5a387874c102a09aab8b92cc"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_color",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_image",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_mesh",
|
|
||||||
"bevy_platform",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_transform",
|
|
||||||
"bevy_utils",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_log"
|
name = "bevy_log"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -1250,7 +1138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "e931fa969f89c83498b22c97432383afe90e90fd1a5e04fa07be8da4d3bcac84"
|
checksum = "e931fa969f89c83498b22c97432383afe90e90fd1a5e04fa07be8da4d3bcac84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"approx",
|
"approx",
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bevy_reflect",
|
"bevy_reflect",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"glam 0.30.10",
|
"glam 0.30.10",
|
||||||
@@ -1273,9 +1161,7 @@ dependencies = [
|
|||||||
"bevy_asset",
|
"bevy_asset",
|
||||||
"bevy_derive",
|
"bevy_derive",
|
||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
"bevy_image",
|
|
||||||
"bevy_math",
|
"bevy_math",
|
||||||
"bevy_mikktspace",
|
|
||||||
"bevy_platform",
|
"bevy_platform",
|
||||||
"bevy_reflect",
|
"bevy_reflect",
|
||||||
"bevy_transform",
|
"bevy_transform",
|
||||||
@@ -1288,71 +1174,6 @@ dependencies = [
|
|||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_mikktspace"
|
|
||||||
version = "0.17.0-dev"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7ef8e4b7e61dfe7719bb03c884dc270cd46a82efb40f93e9933b990c5c190c59"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_pbr"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a5ab6944ffc6fd71604c0fbca68cc3e2a3654edfcdbfd232f9d8b88e3d20fdc0"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_color",
|
|
||||||
"bevy_core_pipeline",
|
|
||||||
"bevy_derive",
|
|
||||||
"bevy_diagnostic",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_image",
|
|
||||||
"bevy_light",
|
|
||||||
"bevy_log",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_mesh",
|
|
||||||
"bevy_platform",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_render",
|
|
||||||
"bevy_shader",
|
|
||||||
"bevy_transform",
|
|
||||||
"bevy_utils",
|
|
||||||
"bitflags 2.11.1",
|
|
||||||
"bytemuck",
|
|
||||||
"derive_more",
|
|
||||||
"fixedbitset",
|
|
||||||
"nonmax",
|
|
||||||
"offset-allocator",
|
|
||||||
"smallvec",
|
|
||||||
"static_assertions",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_picking"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b7d524dbc8f2c9e73f7ab70c148c8f7886f3c24b8aa8c252a38ba68ed06cbf10"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_asset",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_derive",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_input",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_platform",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_time",
|
|
||||||
"bevy_transform",
|
|
||||||
"bevy_window",
|
|
||||||
"tracing",
|
|
||||||
"uuid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_platform"
|
name = "bevy_platform"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -1679,7 +1500,6 @@ dependencies = [
|
|||||||
"bevy_input",
|
"bevy_input",
|
||||||
"bevy_input_focus",
|
"bevy_input_focus",
|
||||||
"bevy_math",
|
"bevy_math",
|
||||||
"bevy_picking",
|
|
||||||
"bevy_platform",
|
"bevy_platform",
|
||||||
"bevy_reflect",
|
"bevy_reflect",
|
||||||
"bevy_sprite",
|
"bevy_sprite",
|
||||||
@@ -1692,7 +1512,6 @@ dependencies = [
|
|||||||
"taffy",
|
"taffy",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uuid",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1726,26 +1545,6 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_ui_widgets"
|
|
||||||
version = "0.18.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b6a63cb818b0de41bdb14990e0ce1aaaa347f871750ab280f80c427e83d72712"
|
|
||||||
dependencies = [
|
|
||||||
"accesskit",
|
|
||||||
"bevy_a11y",
|
|
||||||
"bevy_app",
|
|
||||||
"bevy_camera",
|
|
||||||
"bevy_ecs",
|
|
||||||
"bevy_input",
|
|
||||||
"bevy_input_focus",
|
|
||||||
"bevy_log",
|
|
||||||
"bevy_math",
|
|
||||||
"bevy_picking",
|
|
||||||
"bevy_reflect",
|
|
||||||
"bevy_ui",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_utils"
|
name = "bevy_utils"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
@@ -1873,7 +1672,6 @@ version = "2.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
|
||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1905,7 +1703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"
|
checksum = "0aa83c34e62843d924f905e0f5c866eb1dd6545fc4d719e803d9ba6030371fce"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
@@ -2081,15 +1879,6 @@ dependencies = [
|
|||||||
"wayland-client",
|
"wayland-client",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "card_game"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "sparse+https://git.aleshym.co/api/packages/Quaternions/cargo/"
|
|
||||||
checksum = "d206df6d87340019a0f5b621976cf98bc75c659a7f93ef348aaab2a9336098a9"
|
|
||||||
dependencies = [
|
|
||||||
"arrayvec 0.7.6 (sparse+https://git.aleshym.co/api/packages/Quaternions/cargo/)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cbc"
|
name = "cbc"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@@ -2150,17 +1939,6 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487"
|
checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "chacha20"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures 0.3.0",
|
|
||||||
"rand_core 0.10.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.44"
|
version = "0.4.44"
|
||||||
@@ -3679,17 +3457,6 @@ dependencies = [
|
|||||||
"weezl",
|
"weezl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gl_generator"
|
|
||||||
version = "0.14.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d"
|
|
||||||
dependencies = [
|
|
||||||
"khronos_api",
|
|
||||||
"log",
|
|
||||||
"xml-rs",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glam"
|
name = "glam"
|
||||||
version = "0.30.10"
|
version = "0.30.10"
|
||||||
@@ -3718,27 +3485,6 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glow"
|
|
||||||
version = "0.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c5e5ea60d70410161c8bf5da3fdfeaa1c72ed2c15f8bbb9d19fe3a4fad085f08"
|
|
||||||
dependencies = [
|
|
||||||
"js-sys",
|
|
||||||
"slotmap",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"web-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glutin_wgl_sys"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2c4ee00b289aba7a9e5306d57c2d05499b2e5dc427f84ac708bd2c090212cf3e"
|
|
||||||
dependencies = [
|
|
||||||
"gl_generator",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "governor"
|
name = "governor"
|
||||||
version = "0.10.4"
|
version = "0.10.4"
|
||||||
@@ -4563,23 +4309,6 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "khronos-egl"
|
|
||||||
version = "6.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"libloading",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "khronos_api"
|
|
||||||
version = "3.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kira"
|
name = "kira"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
@@ -4597,23 +4326,13 @@ dependencies = [
|
|||||||
"triple_buffer",
|
"triple_buffer",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "klondike"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "sparse+https://git.aleshym.co/api/packages/Quaternions/cargo/"
|
|
||||||
checksum = "347d55e6cf7c90b3d038262071eb2fdb0b75a713fe66c452a3400ff08fb716bc"
|
|
||||||
dependencies = [
|
|
||||||
"card_game",
|
|
||||||
"rand 0.10.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kurbo"
|
name = "kurbo"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7564e90fe3c0d5771e1f0bc95322b21baaeaa0d9213fa6a0b61c99f8b17b3bfb"
|
checksum = "7564e90fe3c0d5771e1f0bc95322b21baaeaa0d9213fa6a0b61c99f8b17b3bfb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"euclid",
|
"euclid",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
@@ -5021,7 +4740,7 @@ version = "27.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "066cf25f0e8b11ee0df221219010f213ad429855f57c494f995590c861a9a7d8"
|
checksum = "066cf25f0e8b11ee0df221219010f213ad429855f57c494f995590c861a9a7d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bit-set",
|
"bit-set",
|
||||||
"bitflags 2.11.1",
|
"bitflags 2.11.1",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
@@ -6228,16 +5947,6 @@ dependencies = [
|
|||||||
"rand_core 0.9.5",
|
"rand_core 0.9.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207"
|
|
||||||
dependencies = [
|
|
||||||
"chacha20",
|
|
||||||
"rand_core 0.10.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -6276,12 +5985,6 @@ dependencies = [
|
|||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_core"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_distr"
|
name = "rand_distr"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -7277,8 +6980,7 @@ dependencies = [
|
|||||||
name = "solitaire_core"
|
name = "solitaire_core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"card_game",
|
"rand 0.9.4",
|
||||||
"klondike",
|
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
]
|
]
|
||||||
@@ -7295,7 +6997,6 @@ dependencies = [
|
|||||||
"jni 0.21.1",
|
"jni 0.21.1",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"keyring-core",
|
"keyring-core",
|
||||||
"klondike",
|
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -7322,7 +7023,6 @@ dependencies = [
|
|||||||
"image",
|
"image",
|
||||||
"jni 0.21.1",
|
"jni 0.21.1",
|
||||||
"kira",
|
"kira",
|
||||||
"klondike",
|
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"resvg",
|
"resvg",
|
||||||
"ron",
|
"ron",
|
||||||
@@ -7382,7 +7082,6 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
"klondike",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde-wasm-bindgen",
|
"serde-wasm-bindgen",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -7391,18 +7090,6 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "solitaire_web"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bevy",
|
|
||||||
"console_error_panic_hook",
|
|
||||||
"getrandom 0.3.4",
|
|
||||||
"solitaire_data",
|
|
||||||
"solitaire_engine",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "spin"
|
||||||
version = "0.9.8"
|
version = "0.9.8"
|
||||||
@@ -7815,7 +7502,7 @@ version = "0.5.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea00cc4f79b7f6bb7ff87eddc065a1066f3a43fe1875979056672c9ef948c2af"
|
checksum = "ea00cc4f79b7f6bb7ff87eddc065a1066f3a43fe1875979056672c9ef948c2af"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -7914,7 +7601,7 @@ version = "0.9.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41ba83ebaf2954d31d05d67340fd46cebe99da2b7133b0dd68d70c65473a437b"
|
checksum = "41ba83ebaf2954d31d05d67340fd46cebe99da2b7133b0dd68d70c65473a437b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"grid",
|
"grid",
|
||||||
"serde",
|
"serde",
|
||||||
"slotmap",
|
"slotmap",
|
||||||
@@ -8183,7 +7870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
|
checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"log",
|
"log",
|
||||||
@@ -8197,7 +7884,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea"
|
checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"log",
|
"log",
|
||||||
@@ -9357,13 +9044,12 @@ version = "27.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfe68bac7cde125de7a731c3400723cadaaf1703795ad3f4805f187459cd7a77"
|
checksum = "bfe68bac7cde125de7a731c3400723cadaaf1703795ad3f4805f187459cd7a77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bitflags 2.11.1",
|
"bitflags 2.11.1",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"document-features",
|
"document-features",
|
||||||
"hashbrown 0.16.1",
|
"hashbrown 0.16.1",
|
||||||
"js-sys",
|
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
@@ -9371,8 +9057,6 @@ dependencies = [
|
|||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"wasm-bindgen",
|
|
||||||
"web-sys",
|
|
||||||
"wgpu-core",
|
"wgpu-core",
|
||||||
"wgpu-hal",
|
"wgpu-hal",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
@@ -9384,7 +9068,7 @@ version = "27.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "27a75de515543b1897b26119f93731b385a19aea165a1ec5f0e3acecc229cae7"
|
checksum = "27a75de515543b1897b26119f93731b385a19aea165a1ec5f0e3acecc229cae7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"bit-set",
|
"bit-set",
|
||||||
"bit-vec",
|
"bit-vec",
|
||||||
"bitflags 2.11.1",
|
"bitflags 2.11.1",
|
||||||
@@ -9404,7 +9088,6 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"wgpu-core-deps-apple",
|
"wgpu-core-deps-apple",
|
||||||
"wgpu-core-deps-wasm",
|
|
||||||
"wgpu-core-deps-windows-linux-android",
|
"wgpu-core-deps-windows-linux-android",
|
||||||
"wgpu-hal",
|
"wgpu-hal",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
@@ -9419,15 +9102,6 @@ dependencies = [
|
|||||||
"wgpu-hal",
|
"wgpu-hal",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wgpu-core-deps-wasm"
|
|
||||||
version = "27.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9b1027dcf3b027a877e44819df7ceb0e2e98578830f8cd34cd6c3c7c2a7a50b7"
|
|
||||||
dependencies = [
|
|
||||||
"wgpu-hal",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wgpu-core-deps-windows-linux-android"
|
name = "wgpu-core-deps-windows-linux-android"
|
||||||
version = "27.0.0"
|
version = "27.0.0"
|
||||||
@@ -9444,7 +9118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "5b21cb61c57ee198bc4aff71aeadff4cbb80b927beb912506af9c780d64313ce"
|
checksum = "5b21cb61c57ee198bc4aff71aeadff4cbb80b927beb912506af9c780d64313ce"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android_system_properties",
|
"android_system_properties",
|
||||||
"arrayvec 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec",
|
||||||
"ash",
|
"ash",
|
||||||
"bit-set",
|
"bit-set",
|
||||||
"bitflags 2.11.1",
|
"bitflags 2.11.1",
|
||||||
@@ -9453,20 +9127,15 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"core-graphics-types 0.2.0",
|
"core-graphics-types 0.2.0",
|
||||||
"glow",
|
|
||||||
"glutin_wgl_sys",
|
|
||||||
"gpu-alloc",
|
"gpu-alloc",
|
||||||
"gpu-allocator",
|
"gpu-allocator",
|
||||||
"gpu-descriptor",
|
"gpu-descriptor",
|
||||||
"hashbrown 0.16.1",
|
"hashbrown 0.16.1",
|
||||||
"js-sys",
|
|
||||||
"khronos-egl",
|
|
||||||
"libc",
|
"libc",
|
||||||
"libloading",
|
"libloading",
|
||||||
"log",
|
"log",
|
||||||
"metal",
|
"metal",
|
||||||
"naga",
|
"naga",
|
||||||
"ndk-sys",
|
|
||||||
"objc",
|
"objc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"ordered-float",
|
"ordered-float",
|
||||||
@@ -9479,8 +9148,6 @@ dependencies = [
|
|||||||
"renderdoc-sys",
|
"renderdoc-sys",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"wasm-bindgen",
|
|
||||||
"web-sys",
|
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
"windows 0.58.0",
|
"windows 0.58.0",
|
||||||
"windows-core 0.58.0",
|
"windows-core 0.58.0",
|
||||||
@@ -10363,12 +10030,6 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xml-rs"
|
|
||||||
version = "0.8.28"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xmlwriter"
|
name = "xmlwriter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
+1
-4
@@ -8,7 +8,6 @@ members = [
|
|||||||
"solitaire_app",
|
"solitaire_app",
|
||||||
"solitaire_assetgen",
|
"solitaire_assetgen",
|
||||||
"solitaire_wasm",
|
"solitaire_wasm",
|
||||||
"solitaire_web",
|
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ rust-version = "1.95"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
uuid = { version = "1", features = ["v4", "serde"] }
|
uuid = { version = "1", features = ["v4", "serde"] }
|
||||||
chrono = { version = "0.4", features = ["serde", "wasmbind"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
@@ -38,8 +37,6 @@ solitaire_core = { path = "solitaire_core" }
|
|||||||
solitaire_sync = { path = "solitaire_sync" }
|
solitaire_sync = { path = "solitaire_sync" }
|
||||||
solitaire_data = { path = "solitaire_data" }
|
solitaire_data = { path = "solitaire_data" }
|
||||||
solitaire_engine = { path = "solitaire_engine" }
|
solitaire_engine = { path = "solitaire_engine" }
|
||||||
klondike = { version = "0.3.0", registry = "Quaternions" }
|
|
||||||
card_game = { version = "0.4.0", registry = "Quaternions" }
|
|
||||||
|
|
||||||
# Bevy with `default-features = false` to avoid the unused
|
# Bevy with `default-features = false` to avoid the unused
|
||||||
# `bevy_audio → rodio + symphonia + cpal 0.15 + alsa 0.9` chain.
|
# `bevy_audio → rodio + symphonia + cpal 0.15 + alsa 0.9` chain.
|
||||||
|
|||||||
@@ -118,28 +118,8 @@ cargo test -p solitaire_core -p solitaire_sync -p solitaire_data -p solitaire_se
|
|||||||
|
|
||||||
# Lint
|
# Lint
|
||||||
cargo clippy --workspace --all-targets -- -D warnings
|
cargo clippy --workspace --all-targets -- -D warnings
|
||||||
|
|
||||||
# Browser e2e smoke (starts solitaire_server automatically)
|
|
||||||
cd solitaire_server/e2e
|
|
||||||
npm ci
|
|
||||||
npx playwright install chromium
|
|
||||||
npm test
|
|
||||||
|
|
||||||
# Seed-batch cycle regression gate (thresholded)
|
|
||||||
npm run review:cycles:regression
|
|
||||||
|
|
||||||
# Loop-aware candidate benchmark (writes test-results/cycle-candidate.json)
|
|
||||||
npm run review:cycles:candidate
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For layered engine-vs-UI automation design (Rust unit tests, wasm debug-API
|
|
||||||
integration tests, and Playwright UI validation), see
|
|
||||||
[docs/testing-architecture.md](docs/testing-architecture.md).
|
|
||||||
|
|
||||||
For Quaternions (`klondike` / `card_game`) dependency upgrades, use
|
|
||||||
[`scripts/update_quaternions_deps.sh`](scripts/update_quaternions_deps.sh) and
|
|
||||||
the runbook in [docs/card-game-integration.md](docs/card-game-integration.md).
|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
Built on [Bevy](https://bevyengine.org/) and the wider Rust ecosystem
|
Built on [Bevy](https://bevyengine.org/) and the wider Rust ecosystem
|
||||||
|
|||||||
+7
-48
@@ -1,21 +1,18 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Rebuild WASM artifacts and install them into solitaire_server/web/pkg/.
|
# Rebuild the solitaire_wasm crate and install the output into
|
||||||
#
|
# solitaire_server/web/pkg/ so the server can serve the replay viewer.
|
||||||
# Two artifacts are produced:
|
|
||||||
# solitaire_wasm.* — thin replay-viewer + interactive JS API (wasm-pack)
|
|
||||||
# canvas.* — full Bevy WASM app for play.html (cargo + wasm-bindgen)
|
|
||||||
#
|
#
|
||||||
# Prerequisites:
|
# Prerequisites:
|
||||||
# cargo install wasm-pack wasm-bindgen-cli
|
# cargo install wasm-pack
|
||||||
# rustup target add wasm32-unknown-unknown
|
# rustup target add wasm32-unknown-unknown
|
||||||
# (optional) cargo install wasm-opt # for smaller canvas_bg.wasm
|
|
||||||
#
|
#
|
||||||
# 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 files (solitaire_wasm.js + solitaire_wasm_bg.wasm) are
|
||||||
# touch the WASM crates can skip this step. Regenerate after any change to
|
# committed to git so self-hosters who don't touch the WASM crate can
|
||||||
# solitaire_wasm/, solitaire_web/, solitaire_engine/, or solitaire_core/.
|
# skip this step. Regenerate after any change to solitaire_wasm/ or
|
||||||
|
# solitaire_core/.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -39,43 +36,5 @@ wasm-pack build \
|
|||||||
# Remove them — we manage the output directory ourselves.
|
# Remove them — we manage the output directory ourselves.
|
||||||
rm -f "$OUT_DIR/package.json" "$OUT_DIR/.gitignore"
|
rm -f "$OUT_DIR/package.json" "$OUT_DIR/.gitignore"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Bevy WASM app (solitaire_web → canvas.js + canvas_bg.wasm)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
if ! command -v wasm-bindgen &> /dev/null; then
|
|
||||||
echo "error: wasm-bindgen not found." >&2
|
|
||||||
echo " Install with: cargo install wasm-bindgen-cli" >&2
|
|
||||||
echo " The CLI version must match the wasm-bindgen crate dep." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Building solitaire_web (Bevy WASM app)..."
|
|
||||||
cargo build --release --target wasm32-unknown-unknown -p solitaire_web
|
|
||||||
|
|
||||||
echo "Running wasm-bindgen for solitaire_web..."
|
|
||||||
wasm-bindgen \
|
|
||||||
--out-dir "$OUT_DIR" \
|
|
||||||
--out-name canvas \
|
|
||||||
--target web \
|
|
||||||
--no-typescript \
|
|
||||||
"$REPO_ROOT/target/wasm32-unknown-unknown/release/solitaire_web.wasm"
|
|
||||||
|
|
||||||
# Optional size optimisation — Bevy bundles are large (~5-15 MB uncompressed).
|
|
||||||
# wasm-opt passes are skipped silently when the tool is not installed.
|
|
||||||
if command -v wasm-opt &> /dev/null; then
|
|
||||||
echo "Running wasm-opt on canvas_bg.wasm..."
|
|
||||||
# Use -O2 (not -Oz): Bevy's render pipeline uses deep call stacks and
|
|
||||||
# complex memory patterns that wasm-opt -Oz can miscompile, resulting
|
|
||||||
# in a grey screen on first load. -O2 is speed-optimised and avoids
|
|
||||||
# the size-focused transforms that trigger the regression.
|
|
||||||
wasm-opt -O2 \
|
|
||||||
-o "$OUT_DIR/canvas_bg.wasm" \
|
|
||||||
"$OUT_DIR/canvas_bg.wasm"
|
|
||||||
else
|
|
||||||
echo "note: wasm-opt not found; skipping size optimisation."
|
|
||||||
echo " Install with: cargo install wasm-opt (or via binaryen)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Done. Output:"
|
echo "Done. Output:"
|
||||||
ls -lh "$OUT_DIR"
|
ls -lh "$OUT_DIR"
|
||||||
|
|||||||
@@ -101,11 +101,6 @@ Our 767-line `solitaire_core::solver` reimplements the full game rules to run th
|
|||||||
### 5. JSON Serialisation / Persistence
|
### 5. JSON Serialisation / Persistence
|
||||||
`solitaire_core::GameState` serialises the full mid-game state to JSON via `serde` so the engine can save on exit and restore on launch. `KlondikeState` derives `Clone` + `Eq` + `Hash` but not `Serialize` / `Deserialize`. No upstream changes are needed — this is handled externally.
|
`solitaire_core::GameState` serialises the full mid-game state to JSON via `serde` so the engine can save on exit and restore on launch. `KlondikeState` derives `Clone` + `Eq` + `Hash` but not `Serialize` / `Deserialize`. No upstream changes are needed — this is handled externally.
|
||||||
|
|
||||||
**Current verification (2026-06-01):** `klondike v0.3.0` and `card_game v0.4.0`
|
|
||||||
crate manifests expose no `serde` dependency/feature, and source exports no
|
|
||||||
serde derives for instruction/state snapshot types. Keep Ferrous'
|
|
||||||
`SavedInstruction` bridge in place.
|
|
||||||
|
|
||||||
**Session history:** `StateSnapshot<G>` stores the pre-move game state and instruction. On load, the session is reconstructed from the serialised snapshot history — no full replay from seed needed.
|
**Session history:** `StateSnapshot<G>` stores the pre-move game state and instruction. On load, the session is reconstructed from the serialised snapshot history — no full replay from seed needed.
|
||||||
|
|
||||||
**In our wrapper:** Serialise the `solitaire_core` wrapper struct using newtypes. Define `SavedInstruction` (a `Serialize + Deserialize` mirror of `KlondikeInstruction`) and `SavedStateSnapshot`. Reconstruct `SessionState` from the deserialised history. Schema version field lives on our wrapper.
|
**In our wrapper:** Serialise the `solitaire_core` wrapper struct using newtypes. Define `SavedInstruction` (a `Serialize + Deserialize` mirror of `KlondikeInstruction`) and `SavedStateSnapshot`. Reconstruct `SessionState` from the deserialised history. Schema version field lives on our wrapper.
|
||||||
@@ -152,29 +147,6 @@ Steps in dependency order. Upstream issues #10, #11, and the solver are all merg
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Quaternions Upgrade Runbook
|
|
||||||
|
|
||||||
Use this sequence whenever upgrading `klondike` / `card_game` from the
|
|
||||||
Quaternions registry:
|
|
||||||
|
|
||||||
1. Review upstream changes/releases:
|
|
||||||
- <https://git.aleshym.co/Quaternions/card_game>
|
|
||||||
- <https://git.aleshym.co/Quaternions/klondike>
|
|
||||||
2. Run:
|
|
||||||
```bash
|
|
||||||
scripts/update_quaternions_deps.sh <klondike_version> <card_game_version>
|
|
||||||
```
|
|
||||||
3. If the script passes, inspect the resulting `Cargo.lock` diff and land the
|
|
||||||
upgrade with the normal PR flow.
|
|
||||||
|
|
||||||
The script enforces:
|
|
||||||
- lockfile update to requested versions
|
|
||||||
- `cargo test --workspace`
|
|
||||||
- `cargo clippy --workspace -- -D warnings`
|
|
||||||
- deterministic replay/debug-API smoke tests in `solitaire_wasm`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What Does NOT Need to Change
|
## What Does NOT Need to Change
|
||||||
|
|
||||||
- The `solitaire_engine` Bevy layer — it works against `solitaire_core` types; changes are isolated to `solitaire_core`.
|
- The `solitaire_engine` Bevy layer — it works against `solitaire_core` types; changes are isolated to `solitaire_core`.
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ use bevy::window::{MonitorSelection, PresentMode, WindowPosition};
|
|||||||
use bevy::winit::WinitWindows;
|
use bevy::winit::WinitWindows;
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
use bevy::winit::{UpdateMode, WinitSettings};
|
use bevy::winit::{UpdateMode, WinitSettings};
|
||||||
use solitaire_data::{
|
use solitaire_data::{Settings, load_settings_from, provider_for_backend, settings_file_path};
|
||||||
Settings, cleanup_orphaned_tmp_files, load_settings_from, provider_for_backend,
|
|
||||||
settings_file_path,
|
|
||||||
};
|
|
||||||
use solitaire_engine::{CoreGamePlugin, SyncProvider, register_theme_asset_sources};
|
use solitaire_engine::{CoreGamePlugin, SyncProvider, register_theme_asset_sources};
|
||||||
|
|
||||||
fn load_settings() -> Settings {
|
fn load_settings() -> Settings {
|
||||||
@@ -52,12 +49,6 @@ pub fn run() {
|
|||||||
// and any debugger attached still sees the panic).
|
// and any debugger attached still sees the panic).
|
||||||
install_crash_log_hook();
|
install_crash_log_hook();
|
||||||
|
|
||||||
// Remove any *.tmp files left behind by a crash between an atomic write
|
|
||||||
// and its rename. Safe to call unconditionally — missing data dir is a
|
|
||||||
// no-op. Must run before GamePlugin loads saved state so orphaned files
|
|
||||||
// don't accumulate across launches.
|
|
||||||
let _ = cleanup_orphaned_tmp_files();
|
|
||||||
|
|
||||||
// Initialise the platform keyring store before any token operations.
|
// Initialise the platform keyring store before any token operations.
|
||||||
// On Linux this uses the Secret Service (GNOME Keyring / KWallet); on
|
// On Linux this uses the Secret Service (GNOME Keyring / KWallet); on
|
||||||
// macOS it uses the Keychain; on Windows it uses the Credential store.
|
// macOS it uses the Keychain; on Windows it uses the Credential store.
|
||||||
@@ -181,16 +172,13 @@ fn build_app_with_settings(
|
|||||||
// a 1-second ceiling when the app is backgrounded cuts wake-up frequency
|
// a 1-second ceiling when the app is backgrounded cuts wake-up frequency
|
||||||
// from ~60 Hz to ≤1 Hz, dramatically reducing background battery drain.
|
// from ~60 Hz to ≤1 Hz, dramatically reducing background battery drain.
|
||||||
//
|
//
|
||||||
// focused_mode uses reactive_low_power(100 ms) so the CPU only wakes when
|
// The focused mode stays Continuous so that card-slide animations remain
|
||||||
// an event arrives (touch, resize, etc.) or an animation system writes
|
// smooth. PresentMode::AutoVsync (set above) keeps the GPU capped at the
|
||||||
// RequestRedraw. The 100 ms ceiling is a fallback that ensures the game
|
// display refresh rate (~60 Hz) when foregrounded, which already prevents
|
||||||
// timer ticks at least 10×/s even with no input, while keeping the GPU
|
// the GPU from spinning at 200+ fps between vsync intervals.
|
||||||
// completely idle between frames when the board is static.
|
|
||||||
// PresentMode::AutoVsync (set above) still caps the GPU at the display
|
|
||||||
// refresh rate when frames do render.
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
app.insert_resource(WinitSettings {
|
app.insert_resource(WinitSettings {
|
||||||
focused_mode: UpdateMode::reactive_low_power(std::time::Duration::from_millis(100)),
|
focused_mode: UpdateMode::Continuous,
|
||||||
unfocused_mode: UpdateMode::reactive_low_power(std::time::Duration::from_secs(1)),
|
unfocused_mode: UpdateMode::reactive_low_power(std::time::Duration::from_secs(1)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ version.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
|
||||||
[features]
|
|
||||||
default = []
|
|
||||||
test-support = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
klondike = { workspace = true }
|
rand = { workspace = true }
|
||||||
card_game = { workspace = true }
|
|
||||||
|
|||||||
@@ -111,28 +111,6 @@ pub struct Card {
|
|||||||
pub face_up: bool,
|
pub face_up: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Card {
|
|
||||||
/// Creates a card with explicit face orientation.
|
|
||||||
pub const fn new(id: u32, suit: Suit, rank: Rank, face_up: bool) -> Self {
|
|
||||||
Self {
|
|
||||||
id,
|
|
||||||
suit,
|
|
||||||
rank,
|
|
||||||
face_up,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a face-up card.
|
|
||||||
pub const fn face_up(id: u32, suit: Suit, rank: Rank) -> Self {
|
|
||||||
Self::new(id, suit, rank, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a face-down card.
|
|
||||||
pub const fn face_down(id: u32, suit: Suit, rank: Rank) -> Self {
|
|
||||||
Self::new(id, suit, rank, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -188,19 +166,4 @@ mod tests {
|
|||||||
assert!(Suit::Diamonds.is_red() && Suit::Hearts.is_red());
|
assert!(Suit::Diamonds.is_red() && Suit::Hearts.is_red());
|
||||||
assert!(Suit::Clubs.is_black() && Suit::Spades.is_black());
|
assert!(Suit::Clubs.is_black() && Suit::Spades.is_black());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn card_constructors_set_fields() {
|
|
||||||
let up = Card::face_up(10, Suit::Spades, Rank::Queen);
|
|
||||||
assert_eq!(up.id, 10);
|
|
||||||
assert_eq!(up.suit, Suit::Spades);
|
|
||||||
assert_eq!(up.rank, Rank::Queen);
|
|
||||||
assert!(up.face_up);
|
|
||||||
|
|
||||||
let down = Card::face_down(11, Suit::Diamonds, Rank::King);
|
|
||||||
assert_eq!(down.id, 11);
|
|
||||||
assert_eq!(down.suit, Suit::Diamonds);
|
|
||||||
assert_eq!(down.rank, Rank::King);
|
|
||||||
assert!(!down.face_up);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
use crate::card::{Card, Rank, Suit};
|
||||||
|
use crate::pile::{Pile, PileType};
|
||||||
|
use rand::rngs::StdRng;
|
||||||
|
use rand::{SeedableRng, seq::SliceRandom};
|
||||||
|
|
||||||
|
const ALL_SUITS: [Suit; 4] = [Suit::Clubs, Suit::Diamonds, Suit::Hearts, Suit::Spades];
|
||||||
|
const ALL_RANKS: [Rank; 13] = [
|
||||||
|
Rank::Ace,
|
||||||
|
Rank::Two,
|
||||||
|
Rank::Three,
|
||||||
|
Rank::Four,
|
||||||
|
Rank::Five,
|
||||||
|
Rank::Six,
|
||||||
|
Rank::Seven,
|
||||||
|
Rank::Eight,
|
||||||
|
Rank::Nine,
|
||||||
|
Rank::Ten,
|
||||||
|
Rank::Jack,
|
||||||
|
Rank::Queen,
|
||||||
|
Rank::King,
|
||||||
|
];
|
||||||
|
|
||||||
|
/// A standard 52-card deck.
|
||||||
|
pub struct Deck {
|
||||||
|
/// All 52 cards in the deck, in deal order.
|
||||||
|
pub cards: Vec<Card>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deck {
|
||||||
|
/// Creates an unshuffled deck with all 52 unique cards (id 0–51).
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let mut cards = Vec::with_capacity(52);
|
||||||
|
let mut id = 0u32;
|
||||||
|
for &suit in &ALL_SUITS {
|
||||||
|
for &rank in &ALL_RANKS {
|
||||||
|
cards.push(Card {
|
||||||
|
id,
|
||||||
|
suit,
|
||||||
|
rank,
|
||||||
|
face_up: false,
|
||||||
|
});
|
||||||
|
id += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self { cards }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shuffles the deck in-place using Fisher-Yates with a seeded `StdRng`.
|
||||||
|
/// The same seed always produces the same order on any platform.
|
||||||
|
pub fn shuffle(&mut self, seed: u64) {
|
||||||
|
let mut rng = StdRng::seed_from_u64(seed);
|
||||||
|
self.cards.shuffle(&mut rng);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Deck {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deals a standard Klondike layout from a pre-shuffled deck.
|
||||||
|
///
|
||||||
|
/// Returns 7 tableau piles and the remaining stock pile.
|
||||||
|
/// Column `i` contains `i + 1` cards; only the top card is face-up.
|
||||||
|
/// Stock receives the remaining 24 cards, all face-down.
|
||||||
|
pub fn deal_klondike(deck: Deck) -> ([Pile; 7], Pile) {
|
||||||
|
debug_assert_eq!(
|
||||||
|
deck.cards.len(),
|
||||||
|
52,
|
||||||
|
"deal_klondike requires a full 52-card deck"
|
||||||
|
);
|
||||||
|
let mut tableau: [Pile; 7] = core::array::from_fn(|i| Pile::new(PileType::Tableau(i)));
|
||||||
|
// Safety: the debug_assert above documents the 52-card contract; index arithmetic is bounded.
|
||||||
|
let mut idx = 0usize;
|
||||||
|
|
||||||
|
for (col, pile) in tableau.iter_mut().enumerate() {
|
||||||
|
for row in 0..=col {
|
||||||
|
let mut card = deck.cards[idx].clone();
|
||||||
|
card.face_up = row == col;
|
||||||
|
pile.cards.push(card);
|
||||||
|
idx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut stock = Pile::new(PileType::Stock);
|
||||||
|
stock.cards.extend(deck.cards.into_iter().skip(idx));
|
||||||
|
(tableau, stock)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deck_new_has_52_cards() {
|
||||||
|
assert_eq!(Deck::new().cards.len(), 52);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deck_new_has_unique_ids() {
|
||||||
|
let deck = Deck::new();
|
||||||
|
let mut ids: Vec<u32> = deck.cards.iter().map(|c| c.id).collect();
|
||||||
|
ids.sort_unstable();
|
||||||
|
ids.dedup();
|
||||||
|
assert_eq!(ids.len(), 52);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deck_new_has_all_suits_and_ranks() {
|
||||||
|
let deck = Deck::new();
|
||||||
|
for suit in ALL_SUITS {
|
||||||
|
for rank in ALL_RANKS {
|
||||||
|
assert!(
|
||||||
|
deck.cards.iter().any(|c| c.suit == suit && c.rank == rank),
|
||||||
|
"missing {rank:?} {suit:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn same_seed_produces_same_order() {
|
||||||
|
let mut d1 = Deck::new();
|
||||||
|
d1.shuffle(42);
|
||||||
|
let mut d2 = Deck::new();
|
||||||
|
d2.shuffle(42);
|
||||||
|
assert_eq!(d1.cards, d2.cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn different_seeds_produce_different_orders() {
|
||||||
|
let mut d1 = Deck::new();
|
||||||
|
d1.shuffle(1);
|
||||||
|
let mut d2 = Deck::new();
|
||||||
|
d2.shuffle(2);
|
||||||
|
assert_ne!(d1.cards, d2.cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deal_klondike_correct_tableau_sizes() {
|
||||||
|
let mut deck = Deck::new();
|
||||||
|
deck.shuffle(0);
|
||||||
|
let (tableau, stock) = deal_klondike(deck);
|
||||||
|
for (i, pile) in tableau.iter().enumerate() {
|
||||||
|
assert_eq!(pile.cards.len(), i + 1, "col {i} wrong size");
|
||||||
|
}
|
||||||
|
assert_eq!(stock.cards.len(), 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deal_klondike_top_cards_are_face_up() {
|
||||||
|
let mut deck = Deck::new();
|
||||||
|
deck.shuffle(0);
|
||||||
|
let (tableau, _) = deal_klondike(deck);
|
||||||
|
for pile in &tableau {
|
||||||
|
assert!(pile.cards.last().unwrap().face_up);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deal_klondike_non_top_cards_are_face_down() {
|
||||||
|
let mut deck = Deck::new();
|
||||||
|
deck.shuffle(0);
|
||||||
|
let (tableau, _) = deal_klondike(deck);
|
||||||
|
for pile in &tableau {
|
||||||
|
for card in &pile.cards[..pile.cards.len().saturating_sub(1)] {
|
||||||
|
assert!(!card.face_up);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deal_klondike_stock_is_face_down() {
|
||||||
|
let mut deck = Deck::new();
|
||||||
|
deck.shuffle(0);
|
||||||
|
let (_, stock) = deal_klondike(deck);
|
||||||
|
assert!(stock.cards.iter().all(|c| !c.face_up));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deal_klondike_all_52_cards_present() {
|
||||||
|
let mut deck = Deck::new();
|
||||||
|
deck.shuffle(99);
|
||||||
|
let (tableau, stock) = deal_klondike(deck);
|
||||||
|
let mut ids: Vec<u32> = stock.cards.iter().map(|c| c.id).collect();
|
||||||
|
for pile in &tableau {
|
||||||
|
ids.extend(pile.cards.iter().map(|c| c.id));
|
||||||
|
}
|
||||||
|
ids.sort_unstable();
|
||||||
|
assert_eq!(ids, (0u32..52).collect::<Vec<_>>());
|
||||||
|
}
|
||||||
|
}
|
||||||
+1940
-714
File diff suppressed because it is too large
Load Diff
@@ -1,506 +0,0 @@
|
|||||||
//! Adapter bridging `solitaire_core` types to the upstream `klondike` crate.
|
|
||||||
//!
|
|
||||||
//! # Current scope (integration steps 1–4)
|
|
||||||
//!
|
|
||||||
//! [`KlondikeAdapter`] is a pure helper namespace for:
|
|
||||||
//! - building [`KlondikeConfig`] from Ferrous settings
|
|
||||||
//! - translating between local and upstream types
|
|
||||||
//! - applying Ferrous-specific scoring policy on top of upstream defaults
|
|
||||||
//!
|
|
||||||
//! # Not yet implemented
|
|
||||||
//!
|
|
||||||
//! - Live [`klondike::Klondike`] shadow state (requires pile-mapping, step 2).
|
|
||||||
//! - Move validation via klondike's rule engine (step 2).
|
|
||||||
//! - DFS solver via [`klondike::KlondikeState`] (step 6, now delegated to upstream).
|
|
||||||
|
|
||||||
use card_game::{Card as KlCard, Rank as KlRank, Suit as KlSuit};
|
|
||||||
use klondike::{
|
|
||||||
DrawStockConfig, DstFoundation, DstTableau, Foundation, KlondikeConfig, KlondikeInstruction,
|
|
||||||
KlondikePile, KlondikePileStack, MoveFromFoundationConfig, ScoringConfig, SkipCards, Tableau,
|
|
||||||
TableauStack,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::game_state::{DrawMode, GameMode};
|
|
||||||
|
|
||||||
/// Bridges `solitaire_core` game config and scoring to the upstream `klondike` crate.
|
|
||||||
///
|
|
||||||
/// This type is intentionally zero-sized: it does not carry mutable runtime
|
|
||||||
/// state, and exists only as a namespace for configuration, conversion, and
|
|
||||||
/// scoring helpers.
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
||||||
pub struct KlondikeAdapter;
|
|
||||||
|
|
||||||
impl KlondikeAdapter {
|
|
||||||
/// Build a [`KlondikeConfig`] from draw mode and foundation house-rule setting.
|
|
||||||
pub fn config_for(draw_mode: DrawMode, take_from_foundation: bool) -> KlondikeConfig {
|
|
||||||
KlondikeConfig {
|
|
||||||
draw_stock: match draw_mode {
|
|
||||||
DrawMode::DrawOne => DrawStockConfig::DrawOne,
|
|
||||||
DrawMode::DrawThree => DrawStockConfig::DrawThree,
|
|
||||||
},
|
|
||||||
move_from_foundation: if take_from_foundation {
|
|
||||||
MoveFromFoundationConfig::Allowed
|
|
||||||
} else {
|
|
||||||
MoveFromFoundationConfig::Disallowed
|
|
||||||
},
|
|
||||||
scoring: ScoringConfig::DEFAULT,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Scoring helpers ───────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/// Score delta for a card move.
|
|
||||||
///
|
|
||||||
/// Reads from [`ScoringConfig`] (WXP Standard values):
|
|
||||||
/// - Any pile → Foundation: +10
|
|
||||||
/// - Waste → Tableau: +5
|
|
||||||
/// - Foundation → Tableau: −15
|
|
||||||
/// - All other moves: 0
|
|
||||||
pub fn score_for_move(from: &KlondikePile, to: &KlondikePile) -> i32 {
|
|
||||||
let sc = ScoringConfig::DEFAULT;
|
|
||||||
match (from, to) {
|
|
||||||
(_, KlondikePile::Foundation(_)) => sc.move_to_foundation,
|
|
||||||
(KlondikePile::Stock, KlondikePile::Tableau(_)) => sc.move_to_tableau,
|
|
||||||
(KlondikePile::Foundation(_), KlondikePile::Tableau(_)) => sc.move_from_foundation,
|
|
||||||
_ => 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for exposing a face-down tableau card: +5.
|
|
||||||
pub fn score_for_flip() -> i32 {
|
|
||||||
ScoringConfig::DEFAULT.flip_up_bonus
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for undo: −15.
|
|
||||||
///
|
|
||||||
/// [`card_game::Session`] handles this via `SessionConfig::undo_penalty`
|
|
||||||
/// (default −15). We mirror the constant here so `GameState` can apply it
|
|
||||||
/// in its snapshot-based undo path without owning a `Session`.
|
|
||||||
pub const fn score_for_undo() -> i32 {
|
|
||||||
-15
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for recycling waste → stock.
|
|
||||||
///
|
|
||||||
/// [`ScoringConfig::recycle`] is a flat delta (default 0 = always free).
|
|
||||||
/// WXP allows a fixed number of free recycles before charging a penalty,
|
|
||||||
/// which the upstream library cannot express with a single delta:
|
|
||||||
///
|
|
||||||
/// | Mode | Free recycles | Penalty per extra recycle |
|
|
||||||
/// |---|---|---|
|
|
||||||
/// | Draw-1 | 1 | −100 |
|
|
||||||
/// | Draw-3 | 3 | −20 |
|
|
||||||
///
|
|
||||||
/// **Design note:** recycling is *never* blocked — only penalised.
|
|
||||||
/// This is intentional: Draw-1 can be played indefinitely with the score
|
|
||||||
/// dropping toward zero after the first free recycle. A hard cap would
|
|
||||||
/// create unwinnable positions when the solver cannot find a path without
|
|
||||||
/// additional recycling. Zen mode suppresses the penalty entirely.
|
|
||||||
///
|
|
||||||
/// `recycle_count` must be the new total **after** this recycle.
|
|
||||||
pub fn score_for_recycle(recycle_count: u32, is_draw_three: bool) -> i32 {
|
|
||||||
if is_draw_three {
|
|
||||||
if recycle_count > 3 { -20 } else { 0 }
|
|
||||||
} else if recycle_count > 1 {
|
|
||||||
-100
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for a card move, accounting for game mode.
|
|
||||||
///
|
|
||||||
/// Returns 0 in [`GameMode::Zen`] (all scoring suppressed).
|
|
||||||
pub fn score_for_move_with_mode(from: &KlondikePile, to: &KlondikePile, mode: GameMode) -> i32 {
|
|
||||||
if mode == GameMode::Zen {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
Self::score_for_move(from, to)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for exposing a face-down card, accounting for game mode.
|
|
||||||
///
|
|
||||||
/// Returns 0 in [`GameMode::Zen`].
|
|
||||||
pub fn score_for_flip_with_mode(mode: GameMode) -> i32 {
|
|
||||||
if mode == GameMode::Zen {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
Self::score_for_flip()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compute the new score after an undo, accounting for game mode.
|
|
||||||
///
|
|
||||||
/// In [`GameMode::Zen`] the score is always 0. Otherwise applies the
|
|
||||||
/// −15 undo penalty and clamps to 0 via [`Self::score_for_undo`].
|
|
||||||
pub fn apply_undo_score(snapshot_score: i32, mode: GameMode) -> i32 {
|
|
||||||
if mode == GameMode::Zen {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
(snapshot_score + Self::score_for_undo()).max(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Score delta for recycling, accounting for game mode.
|
|
||||||
///
|
|
||||||
/// Returns 0 in [`GameMode::Zen`].
|
|
||||||
pub fn score_for_recycle_with_mode(
|
|
||||||
recycle_count: u32,
|
|
||||||
is_draw_three: bool,
|
|
||||||
mode: GameMode,
|
|
||||||
) -> i32 {
|
|
||||||
if mode == GameMode::Zen {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
Self::score_for_recycle(recycle_count, is_draw_three)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Type-conversion utilities ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
/// Convert a zero-based tableau index (0..=6) into [`Tableau`].
|
|
||||||
pub fn tableau_from_index(index: usize) -> Option<Tableau> {
|
|
||||||
match index {
|
|
||||||
0 => Some(Tableau::Tableau1),
|
|
||||||
1 => Some(Tableau::Tableau2),
|
|
||||||
2 => Some(Tableau::Tableau3),
|
|
||||||
3 => Some(Tableau::Tableau4),
|
|
||||||
4 => Some(Tableau::Tableau5),
|
|
||||||
5 => Some(Tableau::Tableau6),
|
|
||||||
6 => Some(Tableau::Tableau7),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a zero-based foundation slot (0..=3) into [`Foundation`].
|
|
||||||
pub fn foundation_from_slot(slot: u8) -> Option<Foundation> {
|
|
||||||
match slot {
|
|
||||||
0 => Some(Foundation::Foundation1),
|
|
||||||
1 => Some(Foundation::Foundation2),
|
|
||||||
2 => Some(Foundation::Foundation3),
|
|
||||||
3 => Some(Foundation::Foundation4),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a tableau skip count (0..=12) into [`SkipCards`].
|
|
||||||
pub fn skip_cards_from_count(skip: usize) -> Option<SkipCards> {
|
|
||||||
match skip {
|
|
||||||
0 => Some(SkipCards::Skip0),
|
|
||||||
1 => Some(SkipCards::Skip1),
|
|
||||||
2 => Some(SkipCards::Skip2),
|
|
||||||
3 => Some(SkipCards::Skip3),
|
|
||||||
4 => Some(SkipCards::Skip4),
|
|
||||||
5 => Some(SkipCards::Skip5),
|
|
||||||
6 => Some(SkipCards::Skip6),
|
|
||||||
7 => Some(SkipCards::Skip7),
|
|
||||||
8 => Some(SkipCards::Skip8),
|
|
||||||
9 => Some(SkipCards::Skip9),
|
|
||||||
10 => Some(SkipCards::Skip10),
|
|
||||||
11 => Some(SkipCards::Skip11),
|
|
||||||
12 => Some(SkipCards::Skip12),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert [`card_game::Suit`] back to our [`crate::card::Suit`].
|
|
||||||
pub(crate) fn suit_from_kl(suit: KlSuit) -> crate::card::Suit {
|
|
||||||
match suit {
|
|
||||||
KlSuit::Clubs => crate::card::Suit::Clubs,
|
|
||||||
KlSuit::Diamonds => crate::card::Suit::Diamonds,
|
|
||||||
KlSuit::Hearts => crate::card::Suit::Hearts,
|
|
||||||
KlSuit::Spades => crate::card::Suit::Spades,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert [`card_game::Rank`] back to our [`crate::card::Rank`].
|
|
||||||
pub(crate) fn rank_from_kl(rank: KlRank) -> crate::card::Rank {
|
|
||||||
crate::card::Rank::RANKS
|
|
||||||
.into_iter()
|
|
||||||
.find(|r| r.value() == rank as u8)
|
|
||||||
.expect("KlRank 1-13 always maps to a valid Rank")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a [`card_game::Card`] back to our [`crate::card::Card`], assigning
|
|
||||||
/// a stable `id` derived from the suit and rank (0–51, Clubs-first ordering).
|
|
||||||
///
|
|
||||||
/// The id is consistent for the same logical card across all reconstructions.
|
|
||||||
pub fn card_from_kl(card: &KlCard) -> crate::card::Card {
|
|
||||||
let suit = suit_from_kl(card.suit());
|
|
||||||
let rank = rank_from_kl(card.rank());
|
|
||||||
let suit_index = crate::card::Suit::SUITS
|
|
||||||
.iter()
|
|
||||||
.position(|s| *s == suit)
|
|
||||||
.expect("suit always in SUITS") as u32;
|
|
||||||
let id = suit_index * 13 + (rank.value() as u32 - 1);
|
|
||||||
crate::card::Card {
|
|
||||||
id,
|
|
||||||
suit,
|
|
||||||
rank,
|
|
||||||
face_up: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Serde newtypes for KlondikeInstruction (Step 7) ──────────────────────────
|
|
||||||
//
|
|
||||||
// `klondike::KlondikeInstruction` (and its sub-types) do not derive
|
|
||||||
// `Serialize` / `Deserialize`. These mirror types carry `#[serde]` so that
|
|
||||||
// the session instruction history can be persisted and reconstructed without
|
|
||||||
// upstream changes.
|
|
||||||
//
|
|
||||||
// Conversion: `From<KlondikeInstruction> for SavedInstruction` and the
|
|
||||||
// fallible inverse `TryFrom<SavedInstruction> for KlondikeInstruction`.
|
|
||||||
// Invalid numeric values (out-of-range u8 for tableau/foundation/skip) yield
|
|
||||||
// `InvalidSavedInstruction`.
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::Tableau`] (0 = Tableau1 … 6 = Tableau7).
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedTableau(pub u8);
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::Foundation`] (0 = Foundation1 … 3 = Foundation4).
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedFoundation(pub u8);
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::SkipCards`] (0 = Skip0 … 12 = Skip12).
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedSkipCards(pub u8);
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::KlondikePile`].
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub enum SavedKlondikePile {
|
|
||||||
Tableau(SavedTableau),
|
|
||||||
Stock,
|
|
||||||
Foundation(SavedFoundation),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::TableauStack`].
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedTableauStack {
|
|
||||||
pub tableau: SavedTableau,
|
|
||||||
pub skip_cards: SavedSkipCards,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::KlondikePileStack`].
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub enum SavedKlondikePileStack {
|
|
||||||
Tableau(SavedTableauStack),
|
|
||||||
Stock,
|
|
||||||
Foundation(SavedFoundation),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::DstFoundation`].
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedDstFoundation {
|
|
||||||
pub src: SavedKlondikePile,
|
|
||||||
pub foundation: SavedFoundation,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::DstTableau`].
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct SavedDstTableau {
|
|
||||||
pub src: SavedKlondikePileStack,
|
|
||||||
pub tableau: SavedTableau,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Serialize` + `Deserialize` mirror of [`klondike::KlondikeInstruction`].
|
|
||||||
///
|
|
||||||
/// Convert to/from the upstream type with:
|
|
||||||
/// ```ignore
|
|
||||||
/// let saved = SavedInstruction::from(instruction);
|
|
||||||
/// let instruction = KlondikeInstruction::try_from(saved)?;
|
|
||||||
/// ```
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub enum SavedInstruction {
|
|
||||||
DstFoundation(SavedDstFoundation),
|
|
||||||
DstTableau(SavedDstTableau),
|
|
||||||
RotateStock,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Error returned when a [`SavedInstruction`] contains an out-of-range numeric value
|
|
||||||
/// and cannot be converted back to a [`klondike::KlondikeInstruction`].
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
|
||||||
pub enum InvalidSavedInstruction {
|
|
||||||
#[error("invalid tableau index {0} (expected 0–6)")]
|
|
||||||
Tableau(u8),
|
|
||||||
#[error("invalid foundation index {0} (expected 0–3)")]
|
|
||||||
Foundation(u8),
|
|
||||||
#[error("invalid skip_cards value {0} (expected 0–12)")]
|
|
||||||
SkipCards(u8),
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── From impls: KlondikeInstruction → Saved* ─────────────────────────────────
|
|
||||||
|
|
||||||
impl From<Tableau> for SavedTableau {
|
|
||||||
fn from(t: Tableau) -> Self {
|
|
||||||
Self(t as u8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Foundation> for SavedFoundation {
|
|
||||||
fn from(f: Foundation) -> Self {
|
|
||||||
Self(f as u8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<SkipCards> for SavedSkipCards {
|
|
||||||
fn from(s: SkipCards) -> Self {
|
|
||||||
Self(s as u8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<KlondikePile> for SavedKlondikePile {
|
|
||||||
fn from(p: KlondikePile) -> Self {
|
|
||||||
match p {
|
|
||||||
KlondikePile::Tableau(t) => Self::Tableau(t.into()),
|
|
||||||
KlondikePile::Stock => Self::Stock,
|
|
||||||
KlondikePile::Foundation(f) => Self::Foundation(f.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TableauStack> for SavedTableauStack {
|
|
||||||
fn from(ts: TableauStack) -> Self {
|
|
||||||
Self {
|
|
||||||
tableau: ts.tableau.into(),
|
|
||||||
skip_cards: ts.skip_cards.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<KlondikePileStack> for SavedKlondikePileStack {
|
|
||||||
fn from(ps: KlondikePileStack) -> Self {
|
|
||||||
match ps {
|
|
||||||
KlondikePileStack::Tableau(ts) => Self::Tableau(ts.into()),
|
|
||||||
KlondikePileStack::Stock => Self::Stock,
|
|
||||||
KlondikePileStack::Foundation(f) => Self::Foundation(f.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DstFoundation> for SavedDstFoundation {
|
|
||||||
fn from(df: DstFoundation) -> Self {
|
|
||||||
Self {
|
|
||||||
src: df.src.into(),
|
|
||||||
foundation: df.foundation.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DstTableau> for SavedDstTableau {
|
|
||||||
fn from(dt: DstTableau) -> Self {
|
|
||||||
Self {
|
|
||||||
src: dt.src.into(),
|
|
||||||
tableau: dt.tableau.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<KlondikeInstruction> for SavedInstruction {
|
|
||||||
fn from(i: KlondikeInstruction) -> Self {
|
|
||||||
match i {
|
|
||||||
KlondikeInstruction::RotateStock => Self::RotateStock,
|
|
||||||
KlondikeInstruction::DstFoundation(df) => Self::DstFoundation(df.into()),
|
|
||||||
KlondikeInstruction::DstTableau(dt) => Self::DstTableau(dt.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── TryFrom impls: Saved* → KlondikeInstruction ──────────────────────────────
|
|
||||||
|
|
||||||
impl TryFrom<SavedTableau> for Tableau {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedTableau) -> Result<Self, Self::Error> {
|
|
||||||
tableau_from_index(s.0 as usize).ok_or(InvalidSavedInstruction::Tableau(s.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedFoundation> for Foundation {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedFoundation) -> Result<Self, Self::Error> {
|
|
||||||
foundation_from_slot(s.0).ok_or(InvalidSavedInstruction::Foundation(s.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedSkipCards> for SkipCards {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedSkipCards) -> Result<Self, Self::Error> {
|
|
||||||
skip_cards_from_count(s.0 as usize).ok_or(InvalidSavedInstruction::SkipCards(s.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedKlondikePile> for KlondikePile {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedKlondikePile) -> Result<Self, Self::Error> {
|
|
||||||
Ok(match s {
|
|
||||||
SavedKlondikePile::Tableau(t) => KlondikePile::Tableau(t.try_into()?),
|
|
||||||
SavedKlondikePile::Stock => KlondikePile::Stock,
|
|
||||||
SavedKlondikePile::Foundation(f) => KlondikePile::Foundation(f.try_into()?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedTableauStack> for TableauStack {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedTableauStack) -> Result<Self, Self::Error> {
|
|
||||||
Ok(TableauStack {
|
|
||||||
tableau: s.tableau.try_into()?,
|
|
||||||
skip_cards: s.skip_cards.try_into()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedKlondikePileStack> for KlondikePileStack {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedKlondikePileStack) -> Result<Self, Self::Error> {
|
|
||||||
Ok(match s {
|
|
||||||
SavedKlondikePileStack::Tableau(ts) => KlondikePileStack::Tableau(ts.try_into()?),
|
|
||||||
SavedKlondikePileStack::Stock => KlondikePileStack::Stock,
|
|
||||||
SavedKlondikePileStack::Foundation(f) => KlondikePileStack::Foundation(f.try_into()?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedDstFoundation> for DstFoundation {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedDstFoundation) -> Result<Self, Self::Error> {
|
|
||||||
Ok(DstFoundation {
|
|
||||||
src: s.src.try_into()?,
|
|
||||||
foundation: s.foundation.try_into()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedDstTableau> for DstTableau {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedDstTableau) -> Result<Self, Self::Error> {
|
|
||||||
Ok(DstTableau {
|
|
||||||
src: s.src.try_into()?,
|
|
||||||
tableau: s.tableau.try_into()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SavedInstruction> for KlondikeInstruction {
|
|
||||||
type Error = InvalidSavedInstruction;
|
|
||||||
fn try_from(s: SavedInstruction) -> Result<Self, Self::Error> {
|
|
||||||
Ok(match s {
|
|
||||||
SavedInstruction::RotateStock => KlondikeInstruction::RotateStock,
|
|
||||||
SavedInstruction::DstFoundation(df) => {
|
|
||||||
KlondikeInstruction::DstFoundation(df.try_into()?)
|
|
||||||
}
|
|
||||||
SavedInstruction::DstTableau(dt) => KlondikeInstruction::DstTableau(dt.try_into()?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Time bonus added to the score on a win: `700_000 / elapsed_seconds`.
|
|
||||||
/// Returns 0 when `elapsed_seconds` is 0 to avoid division by zero.
|
|
||||||
pub fn compute_time_bonus(elapsed_seconds: u64) -> i32 {
|
|
||||||
if elapsed_seconds == 0 {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
(700_000u64 / elapsed_seconds).min(i32::MAX as u64) as i32
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
pub mod achievement;
|
pub mod achievement;
|
||||||
pub mod card;
|
pub mod card;
|
||||||
|
pub mod deck;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod game_state;
|
pub mod game_state;
|
||||||
pub mod klondike_adapter;
|
|
||||||
pub mod pile;
|
pub mod pile;
|
||||||
|
pub mod rules;
|
||||||
|
pub mod scoring;
|
||||||
pub mod solver;
|
pub mod solver;
|
||||||
|
|||||||
+67
-17
@@ -1,18 +1,33 @@
|
|||||||
use crate::card::{Card, Suit};
|
use crate::card::{Card, Suit};
|
||||||
use klondike::KlondikePile;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Identifies which pile on the board a set of cards belongs to.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum PileType {
|
||||||
|
/// The face-down draw pile.
|
||||||
|
Stock,
|
||||||
|
/// The face-up discard pile drawn to.
|
||||||
|
Waste,
|
||||||
|
/// One of the four foundation slots (0..=3). The claimed suit, if any,
|
||||||
|
/// is derived from the bottom card of the pile (always an Ace by
|
||||||
|
/// construction).
|
||||||
|
Foundation(u8),
|
||||||
|
/// One of the seven tableau columns (0–6).
|
||||||
|
Tableau(usize),
|
||||||
|
}
|
||||||
|
|
||||||
/// A named collection of cards in a specific board position.
|
/// A named collection of cards in a specific board position.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Pile {
|
pub struct Pile {
|
||||||
/// Which logical Klondike pile this is.
|
/// Which pile this is (Stock, Waste, Foundation slot, or Tableau column).
|
||||||
pub pile_type: KlondikePile,
|
pub pile_type: PileType,
|
||||||
/// Cards in the pile, bottom-to-top stacking order. Last element is the top card.
|
/// Cards in the pile, bottom-to-top stacking order. Last element is the top card.
|
||||||
pub cards: Vec<Card>,
|
pub cards: Vec<Card>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pile {
|
impl Pile {
|
||||||
/// Creates a new empty pile of the given type.
|
/// Creates a new empty pile of the given type.
|
||||||
pub fn new(pile_type: KlondikePile) -> Self {
|
pub fn new(pile_type: PileType) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pile_type,
|
pile_type,
|
||||||
cards: Vec::new(),
|
cards: Vec::new(),
|
||||||
@@ -29,7 +44,7 @@ impl Pile {
|
|||||||
/// Returns `None` for empty foundations or non-foundation piles.
|
/// Returns `None` for empty foundations or non-foundation piles.
|
||||||
pub fn claimed_suit(&self) -> Option<Suit> {
|
pub fn claimed_suit(&self) -> Option<Suit> {
|
||||||
match self.pile_type {
|
match self.pile_type {
|
||||||
KlondikePile::Foundation(_) => self.cards.first().map(|c| c.suit),
|
PileType::Foundation(_) => self.cards.first().map(|c| c.suit),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,42 +57,77 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_pile_is_empty() {
|
fn new_pile_is_empty() {
|
||||||
let pile = Pile::new(KlondikePile::Stock);
|
let pile = Pile::new(PileType::Stock);
|
||||||
assert!(pile.cards.is_empty());
|
assert!(pile.cards.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pile_top_returns_last_card() {
|
fn pile_top_returns_last_card() {
|
||||||
let mut pile = Pile::new(KlondikePile::Stock);
|
let mut pile = Pile::new(PileType::Waste);
|
||||||
pile.cards.push(Card::face_up(0, Suit::Hearts, Rank::Ace));
|
pile.cards.push(Card {
|
||||||
pile.cards.push(Card::face_up(1, Suit::Clubs, Rank::Two));
|
id: 0,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Ace,
|
||||||
|
face_up: true,
|
||||||
|
});
|
||||||
|
pile.cards.push(Card {
|
||||||
|
id: 1,
|
||||||
|
suit: Suit::Clubs,
|
||||||
|
rank: Rank::Two,
|
||||||
|
face_up: true,
|
||||||
|
});
|
||||||
assert_eq!(pile.top().unwrap().id, 1);
|
assert_eq!(pile.top().unwrap().id, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pile_top_on_empty_is_none() {
|
fn pile_top_on_empty_is_none() {
|
||||||
let pile = Pile::new(KlondikePile::Stock);
|
let pile = Pile::new(PileType::Waste);
|
||||||
assert!(pile.top().is_none());
|
assert!(pile.top().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pile_type_foundation_uses_slot_index() {
|
||||||
|
assert_ne!(PileType::Foundation(0), PileType::Foundation(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pile_type_tableau_uses_index() {
|
||||||
|
assert_ne!(PileType::Tableau(0), PileType::Tableau(6));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn claimed_suit_is_none_for_empty_foundation() {
|
fn claimed_suit_is_none_for_empty_foundation() {
|
||||||
let pile = Pile::new(KlondikePile::Foundation(klondike::Foundation::Foundation1));
|
let pile = Pile::new(PileType::Foundation(0));
|
||||||
assert!(pile.claimed_suit().is_none());
|
assert!(pile.claimed_suit().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn claimed_suit_is_none_for_non_foundation() {
|
fn claimed_suit_is_none_for_non_foundation() {
|
||||||
let mut pile = Pile::new(KlondikePile::Tableau(klondike::Tableau::Tableau1));
|
let mut pile = Pile::new(PileType::Tableau(0));
|
||||||
pile.cards.push(Card::face_up(0, Suit::Hearts, Rank::Ace));
|
pile.cards.push(Card {
|
||||||
|
id: 0,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Ace,
|
||||||
|
face_up: true,
|
||||||
|
});
|
||||||
assert!(pile.claimed_suit().is_none());
|
assert!(pile.claimed_suit().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn claimed_suit_returns_bottom_card_suit() {
|
fn claimed_suit_returns_bottom_card_suit() {
|
||||||
let mut pile = Pile::new(KlondikePile::Foundation(klondike::Foundation::Foundation3));
|
let mut pile = Pile::new(PileType::Foundation(2));
|
||||||
pile.cards.push(Card::face_up(0, Suit::Hearts, Rank::Ace));
|
pile.cards.push(Card {
|
||||||
pile.cards.push(Card::face_up(1, Suit::Hearts, Rank::Two));
|
id: 0,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Ace,
|
||||||
|
face_up: true,
|
||||||
|
});
|
||||||
|
pile.cards.push(Card {
|
||||||
|
id: 1,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Two,
|
||||||
|
face_up: true,
|
||||||
|
});
|
||||||
assert_eq!(pile.claimed_suit(), Some(Suit::Hearts));
|
assert_eq!(pile.claimed_suit(), Some(Suit::Hearts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
use crate::card::{Card, Rank};
|
||||||
|
use crate::pile::Pile;
|
||||||
|
|
||||||
|
/// Returns `true` if `card` can be placed on the foundation `pile`.
|
||||||
|
///
|
||||||
|
/// Foundation rules:
|
||||||
|
/// - When the pile is empty, any Ace is accepted; the placed Ace's suit
|
||||||
|
/// becomes the pile's claimed suit (derived from the bottom card via
|
||||||
|
/// [`Pile::claimed_suit`](crate::pile::Pile::claimed_suit)).
|
||||||
|
/// - When the pile is non-empty, the next card must match the top card's
|
||||||
|
/// suit and be exactly one rank higher.
|
||||||
|
#[must_use]
|
||||||
|
pub fn can_place_on_foundation(card: &Card, pile: &Pile) -> bool {
|
||||||
|
match pile.cards.last() {
|
||||||
|
None => card.rank == Rank::Ace,
|
||||||
|
Some(top) => card.suit == top.suit && card.rank.checked_sub(1) == Some(top.rank),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `card` (or the bottom card of a sequence) can be placed on `pile` in the tableau.
|
||||||
|
///
|
||||||
|
/// Tableau rules: Kings go on empty piles; otherwise alternating colour, one rank lower.
|
||||||
|
#[must_use]
|
||||||
|
pub fn can_place_on_tableau(card: &Card, pile: &Pile) -> bool {
|
||||||
|
match pile.cards.last() {
|
||||||
|
None => card.rank == Rank::King,
|
||||||
|
Some(top) => {
|
||||||
|
top.face_up
|
||||||
|
&& card.rank.checked_add(1) == Some(top.rank)
|
||||||
|
&& card.suit.is_red() != top.suit.is_red()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `cards` is a legal tableau run on its own — every
|
||||||
|
/// adjacent pair descends by one rank and alternates colour. A single
|
||||||
|
/// card is trivially valid. The destination check is separate; this
|
||||||
|
/// only validates the sequence's *internal* structure, which the tableau
|
||||||
|
/// move path must enforce so a player can't smuggle an arbitrary stack
|
||||||
|
/// onto another column when the bottom card happens to land legally.
|
||||||
|
#[must_use]
|
||||||
|
pub fn is_valid_tableau_sequence(cards: &[Card]) -> bool {
|
||||||
|
cards.windows(2).all(|w| {
|
||||||
|
w[0].rank.checked_sub(1) == Some(w[1].rank) && w[0].suit.is_red() != w[1].suit.is_red()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::card::{Card, Rank, Suit};
|
||||||
|
use crate::pile::{Pile, PileType};
|
||||||
|
|
||||||
|
fn card(suit: Suit, rank: Rank) -> Card {
|
||||||
|
Card {
|
||||||
|
id: 0,
|
||||||
|
suit,
|
||||||
|
rank,
|
||||||
|
face_up: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pile_with(pile_type: PileType, cards: Vec<Card>) -> Pile {
|
||||||
|
Pile { pile_type, cards }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Foundation tests
|
||||||
|
#[test]
|
||||||
|
fn foundation_ace_on_empty_is_valid() {
|
||||||
|
// Every suit's Ace must land on an empty foundation slot regardless of
|
||||||
|
// its slot index; the slot claims the suit only after the Ace lands.
|
||||||
|
for suit in [Suit::Clubs, Suit::Diamonds, Suit::Hearts, Suit::Spades] {
|
||||||
|
let c = card(suit, Rank::Ace);
|
||||||
|
let p = Pile::new(PileType::Foundation(0));
|
||||||
|
assert!(
|
||||||
|
can_place_on_foundation(&c, &p),
|
||||||
|
"Ace of {suit:?} must land on empty slot 0",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_non_ace_on_empty_is_invalid() {
|
||||||
|
let c = card(Suit::Hearts, Rank::Two);
|
||||||
|
let p = Pile::new(PileType::Foundation(0));
|
||||||
|
assert!(!can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_two_on_ace_same_suit_is_valid() {
|
||||||
|
let c = card(Suit::Clubs, Rank::Two);
|
||||||
|
let p = pile_with(PileType::Foundation(0), vec![card(Suit::Clubs, Rank::Ace)]);
|
||||||
|
assert!(can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_second_card_must_match_claimed_suit() {
|
||||||
|
// Place Ace of Hearts on slot 0, then attempt 2 of Spades — rejected
|
||||||
|
// because the slot's claimed suit is Hearts after the Ace lands.
|
||||||
|
let p = pile_with(PileType::Foundation(0), vec![card(Suit::Hearts, Rank::Ace)]);
|
||||||
|
let c = card(Suit::Spades, Rank::Two);
|
||||||
|
assert!(!can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_skipping_rank_is_invalid() {
|
||||||
|
let c = card(Suit::Diamonds, Rank::Three);
|
||||||
|
let p = pile_with(
|
||||||
|
PileType::Foundation(0),
|
||||||
|
vec![card(Suit::Diamonds, Rank::Ace)],
|
||||||
|
);
|
||||||
|
assert!(!can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tableau tests
|
||||||
|
#[test]
|
||||||
|
fn tableau_king_on_empty_is_valid() {
|
||||||
|
let c = card(Suit::Hearts, Rank::King);
|
||||||
|
let p = Pile::new(PileType::Tableau(0));
|
||||||
|
assert!(can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_non_king_on_empty_is_invalid() {
|
||||||
|
let c = card(Suit::Hearts, Rank::Queen);
|
||||||
|
let p = Pile::new(PileType::Tableau(0));
|
||||||
|
assert!(!can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_red_on_black_one_lower_is_valid() {
|
||||||
|
let c = card(Suit::Hearts, Rank::Nine);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Spades, Rank::Ten)]);
|
||||||
|
assert!(can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_same_color_is_invalid() {
|
||||||
|
let c = card(Suit::Clubs, Rank::Nine);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Spades, Rank::Ten)]);
|
||||||
|
assert!(!can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_wrong_rank_difference_is_invalid() {
|
||||||
|
let c = card(Suit::Hearts, Rank::Eight);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Spades, Rank::Ten)]);
|
||||||
|
assert!(!can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_black_on_red_one_lower_is_valid() {
|
||||||
|
let c = card(Suit::Clubs, Rank::Six);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Hearts, Rank::Seven)]);
|
||||||
|
assert!(can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_king_on_queen_completes_suit() {
|
||||||
|
// The last card placed to complete a foundation is always King on Queen.
|
||||||
|
let c = card(Suit::Spades, Rank::King);
|
||||||
|
let p = pile_with(
|
||||||
|
PileType::Foundation(0),
|
||||||
|
vec![card(Suit::Spades, Rank::Queen)],
|
||||||
|
);
|
||||||
|
assert!(can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_king_wrong_suit_is_invalid() {
|
||||||
|
// King of Hearts cannot go on a Spades-claimed foundation even if rank matches.
|
||||||
|
let c = card(Suit::Hearts, Rank::King);
|
||||||
|
let p = pile_with(
|
||||||
|
PileType::Foundation(0),
|
||||||
|
vec![card(Suit::Spades, Rank::Queen)],
|
||||||
|
);
|
||||||
|
assert!(!can_place_on_foundation(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_ace_on_two_different_color_is_valid() {
|
||||||
|
// Ace (rank 1) can be placed on a Two of the opposite colour in the tableau.
|
||||||
|
// rank check: Ace.value() + 1 = 2 == Two.value() — passes.
|
||||||
|
let c = card(Suit::Hearts, Rank::Ace);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Spades, Rank::Two)]);
|
||||||
|
assert!(can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_same_rank_different_color_is_invalid() {
|
||||||
|
// Two cards of the same rank cannot be stacked regardless of colour.
|
||||||
|
let c = card(Suit::Hearts, Rank::Nine);
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![card(Suit::Spades, Rank::Nine)]);
|
||||||
|
assert!(!can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_face_down_destination_top_is_invalid() {
|
||||||
|
// A face-down top card must never be a valid placement target.
|
||||||
|
let c = card(Suit::Hearts, Rank::Nine);
|
||||||
|
let mut top = card(Suit::Spades, Rank::Ten);
|
||||||
|
top.face_up = false;
|
||||||
|
let p = pile_with(PileType::Tableau(0), vec![top]);
|
||||||
|
assert!(!can_place_on_tableau(&c, &p));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_sequence_validation() {
|
||||||
|
// Single card is trivially a valid sequence.
|
||||||
|
assert!(is_valid_tableau_sequence(&[card(Suit::Hearts, Rank::Five)]));
|
||||||
|
// Valid descending alternating-colour run K♠ Q♥ J♣.
|
||||||
|
assert!(is_valid_tableau_sequence(&[
|
||||||
|
card(Suit::Spades, Rank::King),
|
||||||
|
card(Suit::Hearts, Rank::Queen),
|
||||||
|
card(Suit::Clubs, Rank::Jack),
|
||||||
|
]));
|
||||||
|
// Same colour twice (Q♠ on K♠) — invalid.
|
||||||
|
assert!(!is_valid_tableau_sequence(&[
|
||||||
|
card(Suit::Spades, Rank::King),
|
||||||
|
card(Suit::Spades, Rank::Queen),
|
||||||
|
]));
|
||||||
|
// Rank gap (K♠ → J♥) — invalid.
|
||||||
|
assert!(!is_valid_tableau_sequence(&[
|
||||||
|
card(Suit::Spades, Rank::King),
|
||||||
|
card(Suit::Hearts, Rank::Jack),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
use crate::pile::PileType;
|
||||||
|
|
||||||
|
/// Score delta for moving cards from `from` to `to`.
|
||||||
|
///
|
||||||
|
/// Windows XP Standard scoring:
|
||||||
|
/// - +10 for any card reaching a foundation pile
|
||||||
|
/// - +5 for a waste → tableau move
|
||||||
|
/// - -15 for a foundation → tableau (take-from-foundation) move
|
||||||
|
/// - 0 for all other moves
|
||||||
|
///
|
||||||
|
/// Note: the +5 flip bonus for exposing a face-down tableau card is applied
|
||||||
|
/// separately in `game_state::move_cards` because it depends on post-move state.
|
||||||
|
pub fn score_move(from: &PileType, to: &PileType) -> i32 {
|
||||||
|
match to {
|
||||||
|
PileType::Foundation(_) => 10,
|
||||||
|
PileType::Tableau(_) => match from {
|
||||||
|
PileType::Waste => 5,
|
||||||
|
PileType::Foundation(_) => -15,
|
||||||
|
_ => 0,
|
||||||
|
},
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Score penalty applied when the player uses undo: -15.
|
||||||
|
pub fn score_undo() -> i32 {
|
||||||
|
-15
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Score bonus awarded when a face-down tableau card is flipped face-up: +5.
|
||||||
|
pub fn score_flip() -> i32 {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Score penalty for recycling the waste pile back to stock.
|
||||||
|
///
|
||||||
|
/// Windows standard: the first N recycles are free (N=1 for Draw-1, N=3 for Draw-3).
|
||||||
|
/// Subsequent recycles cost -100 (Draw-1) or -20 (Draw-3).
|
||||||
|
/// `recycle_count` is the new total count **after** this recycle.
|
||||||
|
pub fn score_recycle(recycle_count: u32, is_draw_three: bool) -> i32 {
|
||||||
|
let (free, penalty) = if is_draw_three {
|
||||||
|
(3_u32, -20_i32)
|
||||||
|
} else {
|
||||||
|
(1_u32, -100_i32)
|
||||||
|
};
|
||||||
|
if recycle_count > free { penalty } else { 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Time bonus added to the score on a win: `700_000 / elapsed_seconds`.
|
||||||
|
/// Returns 0 when `elapsed_seconds` is 0 to avoid division by zero.
|
||||||
|
pub fn compute_time_bonus(elapsed_seconds: u64) -> i32 {
|
||||||
|
if elapsed_seconds == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
(700_000u64 / elapsed_seconds).min(i32::MAX as u64) as i32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn move_to_foundation_scores_ten() {
|
||||||
|
assert_eq!(score_move(&PileType::Waste, &PileType::Foundation(2)), 10);
|
||||||
|
assert_eq!(
|
||||||
|
score_move(&PileType::Tableau(0), &PileType::Foundation(0)),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn waste_to_tableau_scores_five() {
|
||||||
|
assert_eq!(score_move(&PileType::Waste, &PileType::Tableau(3)), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tableau_to_tableau_scores_zero() {
|
||||||
|
assert_eq!(score_move(&PileType::Tableau(0), &PileType::Tableau(1)), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn undo_penalty_is_negative_fifteen() {
|
||||||
|
assert_eq!(score_undo(), -15);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn time_bonus_at_100_seconds() {
|
||||||
|
assert_eq!(compute_time_bonus(100), 7000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn time_bonus_at_zero_is_zero() {
|
||||||
|
assert_eq!(compute_time_bonus(0), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn time_bonus_at_one_second() {
|
||||||
|
assert_eq!(compute_time_bonus(1), 700_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foundation_to_tableau_penalises_fifteen() {
|
||||||
|
// Moving a card back off a foundation (take_from_foundation rule) costs -15.
|
||||||
|
assert_eq!(
|
||||||
|
score_move(&PileType::Foundation(0), &PileType::Tableau(0)),
|
||||||
|
-15
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn move_to_stock_or_waste_scores_zero() {
|
||||||
|
// These destinations are illegal moves in practice, but the function
|
||||||
|
// must not panic and should return 0.
|
||||||
|
assert_eq!(score_move(&PileType::Waste, &PileType::Stock), 0);
|
||||||
|
assert_eq!(score_move(&PileType::Waste, &PileType::Waste), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn time_bonus_is_capped_at_i32_max_for_huge_values() {
|
||||||
|
// Very short elapsed time would overflow without the .min() guard.
|
||||||
|
let bonus = compute_time_bonus(1);
|
||||||
|
assert!(
|
||||||
|
bonus >= 0,
|
||||||
|
"time bonus must be non-negative after u64→i32 cast"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn flip_bonus_is_five() {
|
||||||
|
assert_eq!(score_flip(), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recycle_draw1_first_pass_free() {
|
||||||
|
assert_eq!(score_recycle(1, false), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recycle_draw1_second_pass_penalised() {
|
||||||
|
assert_eq!(score_recycle(2, false), -100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recycle_draw3_third_pass_free() {
|
||||||
|
assert_eq!(score_recycle(3, true), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recycle_draw3_fourth_pass_penalised() {
|
||||||
|
assert_eq!(score_recycle(4, true), -20);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1286
-151
File diff suppressed because it is too large
Load Diff
@@ -12,17 +12,10 @@ serde_json = { workspace = true }
|
|||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
uuid = { workspace = true }
|
|
||||||
klondike = { workspace = true }
|
|
||||||
|
|
||||||
# These deps are not available / not needed on wasm32:
|
|
||||||
# dirs — platform data directories (no filesystem on browser)
|
|
||||||
# reqwest — native HTTP client (sync/analytics gated out on wasm32)
|
|
||||||
# tokio — OS-threaded async runtime (mio doesn't compile on wasm32)
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
dirs = { workspace = true }
|
dirs = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
|
uuid = { workspace = true }
|
||||||
|
|
||||||
# `keyring-core` is the typed Entry/Error API used by
|
# `keyring-core` is the typed Entry/Error API used by
|
||||||
# `auth_tokens`. The crate's own dependency tree pulls in
|
# `auth_tokens`. The crate's own dependency tree pulls in
|
||||||
@@ -31,7 +24,7 @@ tokio = { workspace = true }
|
|||||||
# on bionic). On Android `auth_tokens` falls back to a stub
|
# on bionic). On Android `auth_tokens` falls back to a stub
|
||||||
# implementation that always returns `KeychainUnavailable`; the
|
# implementation that always returns `KeychainUnavailable`; the
|
||||||
# real backend lands when we wire Android Keystore via JNI.
|
# real backend lands when we wire Android Keystore via JNI.
|
||||||
[target.'cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))'.dependencies]
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
keyring-core = { workspace = true }
|
keyring-core = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
|
|||||||
@@ -146,17 +146,13 @@ pub use settings::{
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
mod android_keystore;
|
mod android_keystore;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod auth_tokens;
|
pub mod auth_tokens;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use auth_tokens::{
|
pub use auth_tokens::{
|
||||||
TokenError, delete_tokens, load_access_token, load_refresh_token, store_tokens,
|
TokenError, delete_tokens, load_access_token, load_refresh_token, store_tokens,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod sync_client;
|
pub mod sync_client;
|
||||||
pub use sync_client::LocalOnlyProvider;
|
pub use sync_client::{LocalOnlyProvider, SolitaireServerClient, provider_for_backend};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use sync_client::{SolitaireServerClient, provider_for_backend};
|
|
||||||
|
|
||||||
pub mod replay;
|
pub mod replay;
|
||||||
pub use replay::{
|
pub use replay::{
|
||||||
@@ -167,9 +163,7 @@ pub use replay::{
|
|||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
pub use replay::{latest_replay_path, load_latest_replay_from, save_latest_replay_to};
|
pub use replay::{latest_replay_path, load_latest_replay_from, save_latest_replay_to};
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod matomo_client;
|
pub mod matomo_client;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use matomo_client::MatomoClient;
|
pub use matomo_client::MatomoClient;
|
||||||
|
|
||||||
pub mod platform;
|
pub mod platform;
|
||||||
|
|||||||
@@ -55,15 +55,7 @@ pub fn data_dir() -> Option<PathBuf> {
|
|||||||
{
|
{
|
||||||
Some(PathBuf::from(ANDROID_APP_FILES_DIR))
|
Some(PathBuf::from(ANDROID_APP_FILES_DIR))
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(not(target_os = "android"))]
|
||||||
{
|
|
||||||
// No filesystem on the browser; all persistence goes through
|
|
||||||
// WasmStorage (localStorage-backed). Return None so every caller
|
|
||||||
// degrades gracefully (the same path they take on a
|
|
||||||
// misconfigured desktop environment).
|
|
||||||
None
|
|
||||||
}
|
|
||||||
#[cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))]
|
|
||||||
{
|
{
|
||||||
dirs::data_dir()
|
dirs::data_dir()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solitaire_core::game_state::{DrawMode, GameMode};
|
use solitaire_core::game_state::{DrawMode, GameMode};
|
||||||
use solitaire_core::klondike_adapter::SavedKlondikePile;
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
const LATEST_REPLAY_FILE_NAME: &str = "latest_replay.json";
|
const LATEST_REPLAY_FILE_NAME: &str = "latest_replay.json";
|
||||||
const REPLAY_HISTORY_FILE_NAME: &str = "replays.json";
|
const REPLAY_HISTORY_FILE_NAME: &str = "replays.json";
|
||||||
@@ -96,9 +96,9 @@ pub enum ReplayMove {
|
|||||||
/// A successful `move_cards(from, to, count)` call.
|
/// A successful `move_cards(from, to, count)` call.
|
||||||
Move {
|
Move {
|
||||||
/// Source pile.
|
/// Source pile.
|
||||||
from: SavedKlondikePile,
|
from: PileType,
|
||||||
/// Destination pile.
|
/// Destination pile.
|
||||||
to: SavedKlondikePile,
|
to: PileType,
|
||||||
/// Number of cards moved.
|
/// Number of cards moved.
|
||||||
count: usize,
|
count: usize,
|
||||||
},
|
},
|
||||||
@@ -442,7 +442,6 @@ pub fn migrate_legacy_latest_replay(latest_path: &Path, history_path: &Path) {
|
|||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solitaire_core::klondike_adapter::{SavedFoundation, SavedTableau};
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
fn tmp_path(name: &str) -> PathBuf {
|
fn tmp_path(name: &str) -> PathBuf {
|
||||||
@@ -461,14 +460,14 @@ mod tests {
|
|||||||
vec![
|
vec![
|
||||||
ReplayMove::StockClick,
|
ReplayMove::StockClick,
|
||||||
ReplayMove::Move {
|
ReplayMove::Move {
|
||||||
from: SavedKlondikePile::Stock,
|
from: PileType::Waste,
|
||||||
to: SavedKlondikePile::Tableau(SavedTableau(3)),
|
to: PileType::Tableau(3),
|
||||||
count: 1,
|
count: 1,
|
||||||
},
|
},
|
||||||
ReplayMove::StockClick,
|
ReplayMove::StockClick,
|
||||||
ReplayMove::Move {
|
ReplayMove::Move {
|
||||||
from: SavedKlondikePile::Tableau(SavedTableau(3)),
|
from: PileType::Tableau(3),
|
||||||
to: SavedKlondikePile::Foundation(SavedFoundation(0)),
|
to: PileType::Foundation(0),
|
||||||
count: 1,
|
count: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
//! All saves go through `filename.json.tmp` → `rename()` so a crash or power
|
//! All saves go through `filename.json.tmp` → `rename()` so a crash or power
|
||||||
//! loss during a write never corrupts the saved data.
|
//! loss during a write never corrupts the saved data.
|
||||||
|
|
||||||
use chrono::Utc;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solitaire_core::game_state::{GAME_STATE_SCHEMA_VERSION, GameState};
|
use solitaire_core::game_state::{GAME_STATE_SCHEMA_VERSION, GameState};
|
||||||
@@ -234,7 +234,9 @@ pub fn load_time_attack_session_from_at(
|
|||||||
/// See [`load_time_attack_session_from_at`] for the rules under which
|
/// See [`load_time_attack_session_from_at`] for the rules under which
|
||||||
/// the call returns `None` (missing file, corrupt JSON, expired window).
|
/// the call returns `None` (missing file, corrupt JSON, expired window).
|
||||||
pub fn load_time_attack_session_from(path: &Path) -> Option<TimeAttackSession> {
|
pub fn load_time_attack_session_from(path: &Path) -> Option<TimeAttackSession> {
|
||||||
let now = Utc::now().timestamp().max(0) as u64;
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map_or(0, |d| d.as_secs());
|
||||||
load_time_attack_session_from_at(path, now)
|
load_time_attack_session_from_at(path, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +254,9 @@ pub fn delete_time_attack_session_at(path: &Path) -> io::Result<()> {
|
|||||||
/// current wall-clock time. Equivalent to constructing the struct
|
/// current wall-clock time. Equivalent to constructing the struct
|
||||||
/// manually and setting `saved_at_unix_secs` to `SystemTime::now()`.
|
/// manually and setting `saved_at_unix_secs` to `SystemTime::now()`.
|
||||||
pub fn time_attack_session_with_now(remaining_secs: f32, wins: u32) -> TimeAttackSession {
|
pub fn time_attack_session_with_now(remaining_secs: f32, wins: u32) -> TimeAttackSession {
|
||||||
let now = Utc::now().timestamp().max(0) as u64;
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map_or(0, |d| d.as_secs());
|
||||||
TimeAttackSession {
|
TimeAttackSession {
|
||||||
remaining_secs,
|
remaining_secs,
|
||||||
wins,
|
wins,
|
||||||
@@ -422,6 +426,23 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn load_game_state_ignores_won_games() {
|
||||||
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
let path = gs_path("won_load");
|
||||||
|
let _ = fs::remove_file(&path);
|
||||||
|
|
||||||
|
// Write a won game directly (bypassing save_game_state_to's guard).
|
||||||
|
let mut gs = GameState::new(77, DrawMode::DrawOne);
|
||||||
|
gs.is_won = true;
|
||||||
|
let json = serde_json::to_string_pretty(&gs).unwrap();
|
||||||
|
let tmp = path.with_extension("json.tmp");
|
||||||
|
fs::write(&tmp, json.as_bytes()).unwrap();
|
||||||
|
fs::rename(&tmp, &path).unwrap();
|
||||||
|
|
||||||
|
assert!(load_game_state_from(&path).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete_game_state_removes_file() {
|
fn delete_game_state_removes_file() {
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
|||||||
@@ -12,14 +12,10 @@
|
|||||||
//! without matching on [`SyncBackend`] anywhere else in the codebase.
|
//! without matching on [`SyncBackend`] anywhere else in the codebase.
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
use solitaire_sync::{ChallengeGoal, LeaderboardEntry, SyncPayload, SyncResponse};
|
||||||
use solitaire_sync::{ChallengeGoal, LeaderboardEntry};
|
|
||||||
use solitaire_sync::{SyncPayload, SyncResponse};
|
|
||||||
|
|
||||||
use crate::{SyncError, SyncProvider};
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
SyncError, SyncProvider,
|
||||||
auth_tokens::{load_access_token, load_refresh_token, store_tokens},
|
auth_tokens::{load_access_token, load_refresh_token, store_tokens},
|
||||||
replay::Replay,
|
replay::Replay,
|
||||||
settings::SyncBackend,
|
settings::SyncBackend,
|
||||||
@@ -58,17 +54,12 @@ impl SyncProvider for LocalOnlyProvider {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// SolitaireServerClient
|
// SolitaireServerClient
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Native-only: HTTP sync client and factory function.
|
|
||||||
// On wasm32 these are gated out because reqwest uses native OS networking
|
|
||||||
// (mio + hyper) which does not compile for wasm32-unknown-unknown.
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/// HTTP sync client for the self-hosted Ferrous Solitaire server.
|
/// HTTP sync client for the self-hosted Ferrous Solitaire server.
|
||||||
///
|
///
|
||||||
/// Authenticates via JWT stored in the OS keychain. On a 401 response the
|
/// Authenticates via JWT stored in the OS keychain. On a 401 response the
|
||||||
/// client automatically attempts a token refresh and retries the request once
|
/// client automatically attempts a token refresh and retries the request once
|
||||||
/// before returning an error.
|
/// before returning an error.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub struct SolitaireServerClient {
|
pub struct SolitaireServerClient {
|
||||||
/// Base URL of the server, e.g. `"https://solitaire.example.com"`.
|
/// Base URL of the server, e.g. `"https://solitaire.example.com"`.
|
||||||
/// Trailing slashes are stripped on construction.
|
/// Trailing slashes are stripped on construction.
|
||||||
@@ -79,7 +70,6 @@ pub struct SolitaireServerClient {
|
|||||||
client: reqwest::Client,
|
client: reqwest::Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
impl SolitaireServerClient {
|
impl SolitaireServerClient {
|
||||||
/// Construct a new client for the given server URL and username.
|
/// Construct a new client for the given server URL and username.
|
||||||
///
|
///
|
||||||
@@ -211,7 +201,6 @@ impl SolitaireServerClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl SyncProvider for SolitaireServerClient {
|
impl SyncProvider for SolitaireServerClient {
|
||||||
/// Fetch the latest sync payload from the server.
|
/// Fetch the latest sync payload from the server.
|
||||||
@@ -497,7 +486,6 @@ impl SyncProvider for SolitaireServerClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
impl SolitaireServerClient {
|
impl SolitaireServerClient {
|
||||||
/// Pulled out of `push_replay` so both the first attempt and the
|
/// Pulled out of `push_replay` so both the first attempt and the
|
||||||
/// post-401-retry attempt go through the same parse path.
|
/// post-401-retry attempt go through the same parse path.
|
||||||
@@ -593,10 +581,9 @@ impl SolitaireServerClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Response extraction helpers (native-only, use reqwest::Response)
|
// Response extraction helpers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// Deserialize a pull response body as [`SyncResponse`] and return its
|
/// Deserialize a pull response body as [`SyncResponse`] and return its
|
||||||
/// `merged` field, or map non-200 statuses to the appropriate [`SyncError`].
|
/// `merged` field, or map non-200 statuses to the appropriate [`SyncError`].
|
||||||
///
|
///
|
||||||
@@ -620,7 +607,6 @@ async fn extract_pull_body(resp: reqwest::Response) -> Result<SyncPayload, SyncE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// Deserialize a leaderboard response body as `Vec<LeaderboardEntry>`.
|
/// Deserialize a leaderboard response body as `Vec<LeaderboardEntry>`.
|
||||||
async fn extract_leaderboard_body(
|
async fn extract_leaderboard_body(
|
||||||
resp: reqwest::Response,
|
resp: reqwest::Response,
|
||||||
@@ -635,7 +621,6 @@ async fn extract_leaderboard_body(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// Deserialize a push response body as [`SyncResponse`], or map non-200
|
/// Deserialize a push response body as [`SyncResponse`], or map non-200
|
||||||
/// statuses to the appropriate [`SyncError`].
|
/// statuses to the appropriate [`SyncError`].
|
||||||
///
|
///
|
||||||
@@ -667,7 +652,6 @@ async fn extract_push_body(resp: reqwest::Response) -> Result<SyncResponse, Sync
|
|||||||
/// This is the **one** place in the codebase that matches on [`SyncBackend`]
|
/// This is the **one** place in the codebase that matches on [`SyncBackend`]
|
||||||
/// variants. All other code receives a `Box<dyn SyncProvider + Send + Sync>`
|
/// variants. All other code receives a `Box<dyn SyncProvider + Send + Sync>`
|
||||||
/// and remains backend-agnostic.
|
/// and remains backend-agnostic.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub fn provider_for_backend(backend: &SyncBackend) -> Box<dyn SyncProvider + Send + Sync> {
|
pub fn provider_for_backend(backend: &SyncBackend) -> Box<dyn SyncProvider + Send + Sync> {
|
||||||
match backend {
|
match backend {
|
||||||
SyncBackend::Local => Box::new(LocalOnlyProvider),
|
SyncBackend::Local => Box::new(LocalOnlyProvider),
|
||||||
|
|||||||
+11
-17
@@ -7,12 +7,14 @@ edition.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { workspace = true }
|
bevy = { workspace = true }
|
||||||
image = { workspace = true }
|
image = { workspace = true }
|
||||||
|
reqwest = { workspace = true }
|
||||||
|
kira = { workspace = true }
|
||||||
solitaire_core = { workspace = true }
|
solitaire_core = { workspace = true }
|
||||||
solitaire_data = { workspace = true }
|
solitaire_data = { workspace = true }
|
||||||
solitaire_sync = { workspace = true }
|
solitaire_sync = { workspace = true }
|
||||||
klondike = { workspace = true }
|
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
@@ -20,24 +22,17 @@ usvg = { workspace = true }
|
|||||||
resvg = { workspace = true }
|
resvg = { workspace = true }
|
||||||
tiny-skia = { workspace = true }
|
tiny-skia = { workspace = true }
|
||||||
ron = { workspace = true }
|
ron = { workspace = true }
|
||||||
|
|
||||||
# These deps are not available / not needed on wasm32:
|
|
||||||
# reqwest — uses mio/hyper native networking (sync plugin is gated out)
|
|
||||||
# kira — uses cpal OS audio (audio plugin is gated out)
|
|
||||||
# tokio — multi-threaded runtime (TokioRuntimeResource is gated out)
|
|
||||||
# dirs — platform data directories (storage uses WasmStorage instead)
|
|
||||||
# zip — theme ZIP importer (importer is gated out on wasm32)
|
|
||||||
# arboard — clipboard (no wasm backend; stats copy-link uses localStorage)
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
reqwest = { workspace = true }
|
|
||||||
kira = { workspace = true }
|
|
||||||
tokio = { workspace = true }
|
|
||||||
dirs = { workspace = true }
|
dirs = { workspace = true }
|
||||||
zip = { workspace = true }
|
zip = { workspace = true }
|
||||||
|
|
||||||
# `arboard` has no Android backend and no wasm32 backend. Gate it out for
|
# `arboard` provides clipboard access for the Stats overlay's
|
||||||
# both; the copy-share-link button surfaces an informational toast instead.
|
# "Copy share link" button. The crate has no Android backend
|
||||||
[target.'cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))'.dependencies]
|
# (its `platform::Clipboard` module is unimplemented for the
|
||||||
|
# android target — `cargo apk build` fails with E0433 if this is
|
||||||
|
# left unconditional). On Android the same button surfaces an
|
||||||
|
# informational toast instead; see
|
||||||
|
# `stats_plugin::handle_copy_share_link_button`.
|
||||||
|
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||||
arboard = { workspace = true }
|
arboard = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
@@ -52,4 +47,3 @@ web-sys = { version = "0.3", features = ["Storage", "Window"] }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
solitaire_core = { workspace = true, features = ["test-support"] }
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::RequestRedraw;
|
|
||||||
use solitaire_data::{AnimSpeed, Settings};
|
use solitaire_data::{AnimSpeed, Settings};
|
||||||
|
|
||||||
use crate::achievement_plugin::display_name_for;
|
use crate::achievement_plugin::display_name_for;
|
||||||
@@ -181,7 +180,6 @@ impl Plugin for AnimationPlugin {
|
|||||||
.add_message::<MoveRejectedEvent>()
|
.add_message::<MoveRejectedEvent>()
|
||||||
.add_message::<WarningToastEvent>()
|
.add_message::<WarningToastEvent>()
|
||||||
.add_message::<XpAwardedEvent>()
|
.add_message::<XpAwardedEvent>()
|
||||||
.add_message::<RequestRedraw>()
|
|
||||||
.init_resource::<EffectiveSlideDuration>()
|
.init_resource::<EffectiveSlideDuration>()
|
||||||
.init_resource::<ToastQueue>()
|
.init_resource::<ToastQueue>()
|
||||||
.init_resource::<ActiveToast>()
|
.init_resource::<ActiveToast>()
|
||||||
@@ -1078,7 +1076,7 @@ mod tests {
|
|||||||
// Pairs the existing audio (`card_invalid.wav`) and visual
|
// Pairs the existing audio (`card_invalid.wav`) and visual
|
||||||
// (`feedback_anim_plugin::queue_shake_for_rejected_move`) feedback
|
// (`feedback_anim_plugin::queue_shake_for_rejected_move`) feedback
|
||||||
// with an accessibility-focused readable text cue.
|
// with an accessibility-focused readable text cue.
|
||||||
use klondike::{KlondikePile, Tableau};
|
use solitaire_core::pile::PileType;
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.add_plugins(MinimalPlugins).add_plugins(AnimationPlugin);
|
app.add_plugins(MinimalPlugins).add_plugins(AnimationPlugin);
|
||||||
|
|
||||||
@@ -1090,8 +1088,8 @@ mod tests {
|
|||||||
.count();
|
.count();
|
||||||
|
|
||||||
app.world_mut().write_message(MoveRejectedEvent {
|
app.world_mut().write_message(MoveRejectedEvent {
|
||||||
from: KlondikePile::Tableau(Tableau::Tableau1),
|
from: PileType::Tableau(0),
|
||||||
to: KlondikePile::Tableau(Tableau::Tableau2),
|
to: PileType::Tableau(1),
|
||||||
count: 1,
|
count: 1,
|
||||||
});
|
});
|
||||||
app.update();
|
app.update();
|
||||||
|
|||||||
@@ -47,16 +47,12 @@
|
|||||||
//! comments on each call out the pairing so a future reader doesn't
|
//! comments on each call out the pairing so a future reader doesn't
|
||||||
//! accidentally drop one half.
|
//! accidentally drop one half.
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use bevy::asset::AssetApp;
|
use bevy::asset::AssetApp;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use bevy::asset::io::AssetSourceBuilder;
|
use bevy::asset::io::AssetSourceBuilder;
|
||||||
use bevy::asset::io::embedded::EmbeddedAssetRegistry;
|
use bevy::asset::io::embedded::EmbeddedAssetRegistry;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use bevy::asset::io::file::FileAssetReader;
|
use bevy::asset::io::file::FileAssetReader;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::assets::user_dir::user_theme_dir;
|
use crate::assets::user_dir::user_theme_dir;
|
||||||
|
|
||||||
/// `AssetSourceId` of the user-themes asset source. Use it as
|
/// `AssetSourceId` of the user-themes asset source. Use it as
|
||||||
@@ -239,16 +235,11 @@ const CLASSIC_THEME_SVGS: &[(&str, &[u8])] = &[
|
|||||||
/// Returns the `&mut App` so the call can be chained from the binary
|
/// Returns the `&mut App` so the call can be chained from the binary
|
||||||
/// entry point.
|
/// entry point.
|
||||||
pub fn register_theme_asset_sources(app: &mut App) -> &mut App {
|
pub fn register_theme_asset_sources(app: &mut App) -> &mut App {
|
||||||
// User themes are stored on the filesystem; wasm32 has no filesystem and
|
let root = user_theme_dir();
|
||||||
// `FileAssetReader` is not available on that target.
|
app.register_asset_source(
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
USER_THEMES,
|
||||||
{
|
AssetSourceBuilder::new(move || Box::new(FileAssetReader::new(root.clone()))),
|
||||||
let root = user_theme_dir();
|
);
|
||||||
app.register_asset_source(
|
|
||||||
USER_THEMES,
|
|
||||||
AssetSourceBuilder::new(move || Box::new(FileAssetReader::new(root.clone()))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,23 +82,13 @@ fn user_theme_dir_for(data_dir: PathBuf) -> PathBuf {
|
|||||||
/// the panic message names the supported workaround.
|
/// the panic message names the supported workaround.
|
||||||
fn detected_platform_data_dir() -> PathBuf {
|
fn detected_platform_data_dir() -> PathBuf {
|
||||||
solitaire_data::data_dir().unwrap_or_else(|| {
|
solitaire_data::data_dir().unwrap_or_else(|| {
|
||||||
// On wasm32, data_dir() always returns None — there is no filesystem.
|
panic!(
|
||||||
// User themes are not supported in the browser build; return an empty
|
"user_theme_dir(): platform data directory is unavailable. \
|
||||||
// path so callers produce a benign empty dir rather than panicking.
|
On Linux check $XDG_DATA_HOME or $HOME; on macOS / Windows \
|
||||||
#[cfg(target_arch = "wasm32")]
|
the OS reported no Application Support / AppData path. \
|
||||||
{
|
As a workaround call solitaire_engine::assets::user_dir::\
|
||||||
PathBuf::new()
|
set_user_theme_dir() before App::run()."
|
||||||
}
|
)
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
{
|
|
||||||
panic!(
|
|
||||||
"user_theme_dir(): platform data directory is unavailable. \
|
|
||||||
On Linux check $XDG_DATA_HOME or $HOME; on macOS / Windows \
|
|
||||||
the OS reported no Application Support / AppData path. \
|
|
||||||
As a workaround call solitaire_engine::assets::user_dir::\
|
|
||||||
set_user_theme_dir() before App::run()."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use crate::events::{
|
|||||||
use crate::pause_plugin::PausedResource;
|
use crate::pause_plugin::PausedResource;
|
||||||
use crate::resources::GameStateResource;
|
use crate::resources::GameStateResource;
|
||||||
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource};
|
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource};
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
/// Volume amplitude for the stock-recycle draw sound (half of normal 1.0).
|
/// Volume amplitude for the stock-recycle draw sound (half of normal 1.0).
|
||||||
const RECYCLE_VOLUME: f64 = 0.5;
|
const RECYCLE_VOLUME: f64 = 0.5;
|
||||||
@@ -373,7 +374,10 @@ fn play_on_draw(
|
|||||||
// When the stock pile is empty the draw action recycles the waste pile
|
// When the stock pile is empty the draw action recycles the waste pile
|
||||||
// back to stock. Play the flip sound at half volume to give audible
|
// back to stock. Play the flip sound at half volume to give audible
|
||||||
// feedback that distinguishes a recycle from a normal draw.
|
// feedback that distinguishes a recycle from a normal draw.
|
||||||
let stock_len = game.as_ref().map_or(1, |g| g.0.stock_cards().len()); // default > 0 → normal draw sound
|
let stock_len = game
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|g| g.0.piles.get(&PileType::Stock))
|
||||||
|
.map_or(1, |p| p.cards.len()); // default > 0 → normal draw sound
|
||||||
|
|
||||||
if is_recycle(stock_len) {
|
if is_recycle(stock_len) {
|
||||||
let mut data = lib.flip.clone();
|
let mut data = lib.flip.clone();
|
||||||
|
|||||||
@@ -9,9 +9,7 @@
|
|||||||
//! returns `None` (e.g. a transient state), the plugin retries next tick.
|
//! returns `None` (e.g. a transient state), the plugin retries next tick.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::RequestRedraw;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::audio_plugin::{AudioState, SoundLibrary};
|
use crate::audio_plugin::{AudioState, SoundLibrary};
|
||||||
use crate::events::{MoveRequestEvent, StateChangedEvent};
|
use crate::events::{MoveRequestEvent, StateChangedEvent};
|
||||||
use crate::game_plugin::GameMutation;
|
use crate::game_plugin::GameMutation;
|
||||||
@@ -22,18 +20,11 @@ use crate::resources::GameStateResource;
|
|||||||
///
|
///
|
||||||
/// Plays the win fanfare at half volume so it is clearly distinguishable from
|
/// Plays the win fanfare at half volume so it is clearly distinguishable from
|
||||||
/// both normal card-place sounds and the full win fanfare that fires later.
|
/// both normal card-place sounds and the full win fanfare that fires later.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
const AUTO_COMPLETE_CHIME_VOLUME: f64 = 0.5;
|
const AUTO_COMPLETE_CHIME_VOLUME: f64 = 0.5;
|
||||||
|
|
||||||
/// Seconds between consecutive auto-complete moves.
|
/// Seconds between consecutive auto-complete moves.
|
||||||
const STEP_INTERVAL: f32 = 0.12;
|
const STEP_INTERVAL: f32 = 0.12;
|
||||||
|
|
||||||
/// Seconds to wait after detection before firing the first auto-complete move.
|
|
||||||
///
|
|
||||||
/// This pause gives the player a moment to register that the game is
|
|
||||||
/// transitioning into auto-complete mode before cards start moving.
|
|
||||||
const AUTO_COMPLETE_INITIAL_DELAY: f32 = 0.75;
|
|
||||||
|
|
||||||
/// Tracks whether auto-complete is active and when the next move fires.
|
/// Tracks whether auto-complete is active and when the next move fires.
|
||||||
#[derive(Resource, Default, Debug)]
|
#[derive(Resource, Default, Debug)]
|
||||||
pub struct AutoCompleteState {
|
pub struct AutoCompleteState {
|
||||||
@@ -48,18 +39,16 @@ pub struct AutoCompletePlugin;
|
|||||||
|
|
||||||
impl Plugin for AutoCompletePlugin {
|
impl Plugin for AutoCompletePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.init_resource::<AutoCompleteState>()
|
app.init_resource::<AutoCompleteState>().add_systems(
|
||||||
.add_message::<RequestRedraw>()
|
Update,
|
||||||
.add_systems(
|
(
|
||||||
Update,
|
detect_auto_complete,
|
||||||
(
|
on_auto_complete_start,
|
||||||
detect_auto_complete,
|
drive_auto_complete,
|
||||||
on_auto_complete_start,
|
)
|
||||||
drive_auto_complete,
|
.chain()
|
||||||
)
|
.after(GameMutation),
|
||||||
.chain()
|
);
|
||||||
.after(GameMutation),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,22 +71,15 @@ fn detect_auto_complete(
|
|||||||
}
|
}
|
||||||
if game.0.is_auto_completable && !state.active {
|
if game.0.is_auto_completable && !state.active {
|
||||||
state.active = true;
|
state.active = true;
|
||||||
state.cooldown = AUTO_COMPLETE_INITIAL_DELAY;
|
state.cooldown = 0.0; // fire first move immediately
|
||||||
} else if !game.0.is_auto_completable && state.active {
|
|
||||||
// `is_auto_completable` only becomes false after an explicit undo
|
|
||||||
// (which puts a card back on the tableau or re-fills the stock/waste)
|
|
||||||
// or a new-game reset — never as a transient gap during a normal
|
|
||||||
// auto-complete sequence. Deactivate here so `drive_auto_complete`
|
|
||||||
// does not keep retrying indefinitely after the player undoes out of
|
|
||||||
// the sequence.
|
|
||||||
//
|
|
||||||
// Note: the transient-`None` case mentioned in older versions of this
|
|
||||||
// comment referred to `next_auto_complete_move()` returning `None`, not
|
|
||||||
// to `is_auto_completable` being false. Those are independent fields;
|
|
||||||
// `drive_auto_complete` still retries on a transient `None` return from
|
|
||||||
// `next_auto_complete_move` because that check happens there, not here.
|
|
||||||
state.active = false;
|
|
||||||
}
|
}
|
||||||
|
// Intentionally no `else if !is_auto_completable` branch here.
|
||||||
|
// Deactivating on every frame where `is_auto_completable` is false
|
||||||
|
// would hard-stop the sequence mid-flight whenever `next_auto_complete_move`
|
||||||
|
// transiently returns `None` (e.g. while the previous move is still
|
||||||
|
// in-flight). The `is_won` check above already handles the definitive
|
||||||
|
// end-of-game case; `drive_auto_complete` simply retries next tick
|
||||||
|
// when no move is available yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Plays a distinct chime the moment auto-complete first activates.
|
/// Plays a distinct chime the moment auto-complete first activates.
|
||||||
@@ -106,7 +88,6 @@ fn detect_auto_complete(
|
|||||||
/// exactly once on the `false → true` edge. The win fanfare is played at half
|
/// exactly once on the `false → true` edge. The win fanfare is played at half
|
||||||
/// volume (`AUTO_COMPLETE_CHIME_VOLUME`) so it is clearly recognisable but does
|
/// volume (`AUTO_COMPLETE_CHIME_VOLUME`) so it is clearly recognisable but does
|
||||||
/// not overwhelm the card-place sounds that follow immediately.
|
/// not overwhelm the card-place sounds that follow immediately.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn on_auto_complete_start(
|
fn on_auto_complete_start(
|
||||||
state: Res<AutoCompleteState>,
|
state: Res<AutoCompleteState>,
|
||||||
mut was_active: Local<bool>,
|
mut was_active: Local<bool>,
|
||||||
@@ -127,12 +108,6 @@ fn on_auto_complete_start(
|
|||||||
audio.play_sfx_at_volume(&lib.fanfare, AUTO_COMPLETE_CHIME_VOLUME);
|
audio.play_sfx_at_volume(&lib.fanfare, AUTO_COMPLETE_CHIME_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No audio on wasm — stub keeps the system registration unconditional.
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn on_auto_complete_start(state: Res<AutoCompleteState>, mut was_active: Local<bool>) {
|
|
||||||
*was_active = state.active;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fires one `MoveRequestEvent` per `STEP_INTERVAL` while auto-complete is active.
|
/// Fires one `MoveRequestEvent` per `STEP_INTERVAL` while auto-complete is active.
|
||||||
fn drive_auto_complete(
|
fn drive_auto_complete(
|
||||||
mut state: ResMut<AutoCompleteState>,
|
mut state: ResMut<AutoCompleteState>,
|
||||||
@@ -167,9 +142,9 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::game_plugin::GamePlugin;
|
use crate::game_plugin::GamePlugin;
|
||||||
use crate::table_plugin::TablePlugin;
|
use crate::table_plugin::TablePlugin;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
use solitaire_core::card::{Card, Rank, Suit};
|
||||||
use solitaire_core::card::{Rank, Suit};
|
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
fn headless_app() -> App {
|
fn headless_app() -> App {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
@@ -182,45 +157,31 @@ mod tests {
|
|||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
fn seeded_state_with_auto_move() -> (GameState, (KlondikePile, KlondikePile)) {
|
/// Build a nearly-won game: one Ace of Clubs in Tableau(0), all other
|
||||||
let mut g = GameState::new(1, DrawMode::DrawOne);
|
/// tableau piles empty, stock/waste empty, Clubs foundation empty.
|
||||||
g.set_test_stock_cards(Vec::new());
|
fn nearly_won_state() -> GameState {
|
||||||
g.set_test_waste_cards(Vec::new());
|
let mut g = GameState::new(42, DrawMode::DrawOne);
|
||||||
for foundation in [
|
g.piles.get_mut(&PileType::Stock).unwrap().cards.clear();
|
||||||
Foundation::Foundation1,
|
g.piles.get_mut(&PileType::Waste).unwrap().cards.clear();
|
||||||
Foundation::Foundation2,
|
for i in 0..7 {
|
||||||
Foundation::Foundation3,
|
g.piles
|
||||||
Foundation::Foundation4,
|
.get_mut(&PileType::Tableau(i))
|
||||||
] {
|
.unwrap()
|
||||||
g.set_test_foundation_cards(foundation, Vec::new());
|
.cards
|
||||||
|
.clear();
|
||||||
}
|
}
|
||||||
for tableau in [
|
g.piles
|
||||||
Tableau::Tableau1,
|
.get_mut(&PileType::Tableau(0))
|
||||||
Tableau::Tableau2,
|
.unwrap()
|
||||||
Tableau::Tableau3,
|
.cards
|
||||||
Tableau::Tableau4,
|
.push(Card {
|
||||||
Tableau::Tableau5,
|
id: 99,
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
g.set_test_tableau_cards(tableau, Vec::new());
|
|
||||||
}
|
|
||||||
g.set_test_tableau_cards(
|
|
||||||
Tableau::Tableau1,
|
|
||||||
vec![solitaire_core::card::Card {
|
|
||||||
id: 7_001,
|
|
||||||
suit: Suit::Clubs,
|
suit: Suit::Clubs,
|
||||||
rank: Rank::Ace,
|
rank: Rank::Ace,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
|
||||||
g.is_auto_completable = true;
|
g.is_auto_completable = true;
|
||||||
let expected = (
|
g
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
|
||||||
KlondikePile::Foundation(Foundation::Foundation1),
|
|
||||||
);
|
|
||||||
assert_eq!(g.next_auto_complete_move(), Some(expected));
|
|
||||||
(g, expected)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -232,9 +193,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn detect_activates_when_auto_completable() {
|
fn detect_activates_when_auto_completable() {
|
||||||
let mut app = headless_app();
|
let mut app = headless_app();
|
||||||
let mut g = GameState::new(42, DrawMode::DrawOne);
|
// Install a nearly-won state and fire StateChangedEvent.
|
||||||
g.is_auto_completable = true;
|
app.world_mut().resource_mut::<GameStateResource>().0 = nearly_won_state();
|
||||||
app.world_mut().resource_mut::<GameStateResource>().0 = g;
|
|
||||||
app.world_mut().write_message(StateChangedEvent);
|
app.world_mut().write_message(StateChangedEvent);
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
@@ -244,14 +204,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn drive_fires_move_request_when_active() {
|
fn drive_fires_move_request_when_active() {
|
||||||
let mut app = headless_app();
|
let mut app = headless_app();
|
||||||
let (g, (expected_from, expected_to)) = seeded_state_with_auto_move();
|
app.world_mut().resource_mut::<GameStateResource>().0 = nearly_won_state();
|
||||||
app.world_mut().resource_mut::<GameStateResource>().0 = g;
|
|
||||||
app.world_mut().write_message(StateChangedEvent);
|
app.world_mut().write_message(StateChangedEvent);
|
||||||
app.update(); // detect runs, sets active
|
app.update(); // detect runs, sets active
|
||||||
|
|
||||||
// Zero out the cooldown so drive fires on the next update regardless
|
|
||||||
// of the initial delay constant.
|
|
||||||
app.world_mut().resource_mut::<AutoCompleteState>().cooldown = 0.0;
|
|
||||||
app.update(); // drive fires the move
|
app.update(); // drive fires the move
|
||||||
|
|
||||||
let events = app.world().resource::<Messages<MoveRequestEvent>>();
|
let events = app.world().resource::<Messages<MoveRequestEvent>>();
|
||||||
@@ -259,15 +214,16 @@ mod tests {
|
|||||||
let fired: Vec<_> = cursor.read(events).collect();
|
let fired: Vec<_> = cursor.read(events).collect();
|
||||||
// At least one MoveRequestEvent should have been fired.
|
// At least one MoveRequestEvent should have been fired.
|
||||||
assert!(!fired.is_empty(), "expected at least one MoveRequestEvent");
|
assert!(!fired.is_empty(), "expected at least one MoveRequestEvent");
|
||||||
assert_eq!(fired[0].from, expected_from);
|
assert_eq!(fired[0].from, PileType::Tableau(0));
|
||||||
assert_eq!(fired[0].to, expected_to);
|
// First empty foundation slot wins on a fresh nearly-won board.
|
||||||
|
assert_eq!(fired[0].to, PileType::Foundation(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drive_deactivates_on_win() {
|
fn drive_deactivates_on_win() {
|
||||||
let mut app = headless_app();
|
let mut app = headless_app();
|
||||||
// Inject a won game state — active should not be set.
|
// Inject a won game state — active should not be set.
|
||||||
let (mut gs, _) = seeded_state_with_auto_move();
|
let mut gs = nearly_won_state();
|
||||||
gs.is_won = true;
|
gs.is_won = true;
|
||||||
app.world_mut().resource_mut::<GameStateResource>().0 = gs;
|
app.world_mut().resource_mut::<GameStateResource>().0 = gs;
|
||||||
app.world_mut().write_message(StateChangedEvent);
|
app.world_mut().write_message(StateChangedEvent);
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ pub use timing::{
|
|||||||
pub use tuning::{AnimationTuning, InputPlatform};
|
pub use tuning::{AnimationTuning, InputPlatform};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::RequestRedraw;
|
|
||||||
|
|
||||||
use crate::card_plugin::CardEntity;
|
use crate::card_plugin::CardEntity;
|
||||||
use crate::events::{DrawRequestEvent, GameWonEvent, MoveRequestEvent, UndoRequestEvent};
|
use crate::events::{DrawRequestEvent, GameWonEvent, MoveRequestEvent, UndoRequestEvent};
|
||||||
@@ -126,7 +125,6 @@ impl Plugin for CardAnimationPlugin {
|
|||||||
.add_message::<DrawRequestEvent>()
|
.add_message::<DrawRequestEvent>()
|
||||||
.add_message::<UndoRequestEvent>()
|
.add_message::<UndoRequestEvent>()
|
||||||
.add_message::<GameWonEvent>()
|
.add_message::<GameWonEvent>()
|
||||||
.add_message::<RequestRedraw>()
|
|
||||||
.init_resource::<DragState>()
|
.init_resource::<DragState>()
|
||||||
.init_resource::<HoverState>()
|
.init_resource::<HoverState>()
|
||||||
.init_resource::<InputBuffer>()
|
.init_resource::<InputBuffer>()
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ impl AnimationTuning {
|
|||||||
platform: InputPlatform::Mouse,
|
platform: InputPlatform::Mouse,
|
||||||
duration_scale: 1.0,
|
duration_scale: 1.0,
|
||||||
overshoot_scale: 1.0,
|
overshoot_scale: 1.0,
|
||||||
drag_threshold_px: 6.0,
|
drag_threshold_px: 4.0,
|
||||||
drag_scale: 1.08,
|
drag_scale: 1.08,
|
||||||
hover_scale: 1.04,
|
hover_scale: 1.04,
|
||||||
hover_lerp_speed: 14.0,
|
hover_lerp_speed: 14.0,
|
||||||
|
|||||||
+132
-139
@@ -16,9 +16,11 @@ use bevy::color::Color;
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::sprite::Anchor;
|
use bevy::sprite::Anchor;
|
||||||
use bevy::window::WindowResized;
|
use bevy::window::WindowResized;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::{Card, Rank, Suit};
|
use solitaire_core::card::{Card, Rank, Suit};
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
|
use solitaire_core::rules::{can_place_on_foundation, can_place_on_tableau};
|
||||||
|
|
||||||
use crate::animation_plugin::{CARD_ANIM_Z_LIFT, CardAnim, EffectiveSlideDuration};
|
use crate::animation_plugin::{CARD_ANIM_Z_LIFT, CardAnim, EffectiveSlideDuration};
|
||||||
use crate::card_animation::CardAnimation;
|
use crate::card_animation::CardAnimation;
|
||||||
@@ -732,10 +734,10 @@ fn sync_cards(
|
|||||||
DrawMode::DrawOne => 1_usize,
|
DrawMode::DrawOne => 1_usize,
|
||||||
DrawMode::DrawThree => 3_usize,
|
DrawMode::DrawThree => 3_usize,
|
||||||
};
|
};
|
||||||
let waste_cards = game.waste_cards();
|
game.piles
|
||||||
(waste_cards.len() > visible)
|
.get(&PileType::Waste)
|
||||||
.then_some(waste_cards)
|
.filter(|w| w.cards.len() > visible)
|
||||||
.and_then(|w| w.get(w.len().saturating_sub(visible + 1)).cloned())
|
.and_then(|w| w.cards.get(w.cards.len().saturating_sub(visible + 1)))
|
||||||
.map(|c| c.id)
|
.map(|c| c.id)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -788,7 +790,7 @@ fn sync_cards(
|
|||||||
update_card_entity(
|
update_card_entity(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
entity,
|
entity,
|
||||||
&card,
|
card,
|
||||||
position,
|
position,
|
||||||
z,
|
z,
|
||||||
layout,
|
layout,
|
||||||
@@ -806,7 +808,7 @@ fn sync_cards(
|
|||||||
}
|
}
|
||||||
None => spawn_card_entity(
|
None => spawn_card_entity(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
&card,
|
card,
|
||||||
position,
|
position,
|
||||||
z,
|
z,
|
||||||
layout,
|
layout,
|
||||||
@@ -828,22 +830,22 @@ fn sync_cards(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an ordered vec of (card, position, z) for every card in the game.
|
/// Returns an ordered vec of (card, position, z) for every card in the game.
|
||||||
fn card_positions(game: &GameState, layout: &Layout) -> Vec<(Card, Vec2, f32)> {
|
fn card_positions<'a>(game: &'a GameState, layout: &Layout) -> Vec<(&'a Card, Vec2, f32)> {
|
||||||
let mut out: Vec<(Card, Vec2, f32)> = Vec::with_capacity(52);
|
let mut out: Vec<(&'a Card, Vec2, f32)> = Vec::with_capacity(52);
|
||||||
let piles = [
|
let piles = [
|
||||||
(KlondikePile::Stock, true),
|
PileType::Stock,
|
||||||
(KlondikePile::Stock, false),
|
PileType::Waste,
|
||||||
(KlondikePile::Foundation(Foundation::Foundation1), false),
|
PileType::Foundation(0),
|
||||||
(KlondikePile::Foundation(Foundation::Foundation2), false),
|
PileType::Foundation(1),
|
||||||
(KlondikePile::Foundation(Foundation::Foundation3), false),
|
PileType::Foundation(2),
|
||||||
(KlondikePile::Foundation(Foundation::Foundation4), false),
|
PileType::Foundation(3),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau1), false),
|
PileType::Tableau(0),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau2), false),
|
PileType::Tableau(1),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau3), false),
|
PileType::Tableau(2),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau4), false),
|
PileType::Tableau(3),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau5), false),
|
PileType::Tableau(4),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau6), false),
|
PileType::Tableau(5),
|
||||||
(KlondikePile::Tableau(Tableau::Tableau7), false),
|
PileType::Tableau(6),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Compute the Draw-Three waste fan step proportional to the column spacing
|
// Compute the Draw-Three waste fan step proportional to the column spacing
|
||||||
@@ -853,39 +855,29 @@ fn card_positions(game: &GameState, layout: &Layout) -> Vec<(Card, Vec2, f32)> {
|
|||||||
// (H_GAP_DIVISOR=32) col_step ≈ 1.031×cw so fan_step ≈ 0.231×cw, keeping
|
// (H_GAP_DIVISOR=32) col_step ≈ 1.031×cw so fan_step ≈ 0.231×cw, keeping
|
||||||
// the top fanned card's centre within the waste column's own horizontal
|
// the top fanned card's centre within the waste column's own horizontal
|
||||||
// footprint instead of spilling into the adjacent gap.
|
// footprint instead of spilling into the adjacent gap.
|
||||||
let tableau_col_step = {
|
let waste_fan_step = {
|
||||||
let t1 = layout
|
let s = layout
|
||||||
.pile_positions
|
.pile_positions
|
||||||
.get(&KlondikePile::Tableau(Tableau::Tableau1))
|
.get(&PileType::Stock)
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let t2 = layout
|
let w = layout
|
||||||
.pile_positions
|
.pile_positions
|
||||||
.get(&KlondikePile::Tableau(Tableau::Tableau2))
|
.get(&PileType::Waste)
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
(t2.x - t1.x).abs()
|
(w.x - s.x).abs() * 0.224
|
||||||
};
|
};
|
||||||
let waste_fan_step = tableau_col_step * 0.224;
|
|
||||||
|
|
||||||
for (pile_type, is_stock_area) in piles {
|
for pile_type in piles {
|
||||||
let Some(mut base) = layout.pile_positions.get(&pile_type).copied() else {
|
let Some(base) = layout.pile_positions.get(&pile_type) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if matches!(pile_type, KlondikePile::Stock) && is_stock_area {
|
let Some(pile) = game.piles.get(&pile_type) else {
|
||||||
base.x -= tableau_col_step;
|
continue;
|
||||||
}
|
|
||||||
let is_tableau = matches!(pile_type, KlondikePile::Tableau(_));
|
|
||||||
let is_waste = matches!(pile_type, KlondikePile::Stock) && !is_stock_area;
|
|
||||||
let cards = if matches!(pile_type, KlondikePile::Stock) {
|
|
||||||
if is_stock_area {
|
|
||||||
game.stock_cards()
|
|
||||||
} else {
|
|
||||||
game.waste_cards()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
game.pile(pile_type)
|
|
||||||
};
|
};
|
||||||
|
let is_tableau = matches!(pile_type, PileType::Tableau(_));
|
||||||
|
let is_waste = matches!(pile_type, PileType::Waste);
|
||||||
|
|
||||||
// Tableau uses a two-speed fan: face-down cards are packed tighter
|
// Tableau uses a two-speed fan: face-down cards are packed tighter
|
||||||
// than face-up cards so the visible (playable) portion stands out.
|
// than face-up cards so the visible (playable) portion stands out.
|
||||||
@@ -894,6 +886,7 @@ fn card_positions(game: &GameState, layout: &Layout) -> Vec<(Card, Vec2, f32)> {
|
|||||||
// Waste pile: only the top N cards are rendered to prevent bleed-through
|
// Waste pile: only the top N cards are rendered to prevent bleed-through
|
||||||
// while new cards animate in from the stock. Draw-One shows 1; Draw-Three
|
// while new cards animate in from the stock. Draw-One shows 1; Draw-Three
|
||||||
// shows up to 3 fanned in X (matching the standard Klondike presentation).
|
// shows up to 3 fanned in X (matching the standard Klondike presentation).
|
||||||
|
let cards = &pile.cards;
|
||||||
let render_start = if is_waste {
|
let render_start = if is_waste {
|
||||||
let visible = match game.draw_mode {
|
let visible = match game.draw_mode {
|
||||||
DrawMode::DrawOne => 1_usize,
|
DrawMode::DrawOne => 1_usize,
|
||||||
@@ -923,7 +916,7 @@ fn card_positions(game: &GameState, layout: &Layout) -> Vec<(Card, Vec2, f32)> {
|
|||||||
};
|
};
|
||||||
let pos = Vec2::new(base.x + x_offset, base.y + y_offset);
|
let pos = Vec2::new(base.x + x_offset, base.y + y_offset);
|
||||||
let z = 1.0 + (slot as f32) * STACK_FAN_FRAC;
|
let z = 1.0 + (slot as f32) * STACK_FAN_FRAC;
|
||||||
out.push((card.clone(), pos, z));
|
out.push((card, pos, z));
|
||||||
if is_tableau {
|
if is_tableau {
|
||||||
let step = if card.face_up {
|
let step = if card.face_up {
|
||||||
layout.tableau_fan_frac
|
layout.tableau_fan_frac
|
||||||
@@ -937,32 +930,6 @@ fn card_positions(game: &GameState, layout: &Layout) -> Vec<(Card, Vec2, f32)> {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_cards(game: &GameState) -> Vec<Card> {
|
|
||||||
let mut cards = Vec::with_capacity(52);
|
|
||||||
cards.extend(game.stock_cards());
|
|
||||||
cards.extend(game.waste_cards());
|
|
||||||
for foundation in [
|
|
||||||
Foundation::Foundation1,
|
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
] {
|
|
||||||
cards.extend(game.pile(KlondikePile::Foundation(foundation)));
|
|
||||||
}
|
|
||||||
for tableau in [
|
|
||||||
Tableau::Tableau1,
|
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
cards.extend(game.pile(KlondikePile::Tableau(tableau)));
|
|
||||||
}
|
|
||||||
cards
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn spawn_card_entity(
|
fn spawn_card_entity(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
@@ -1541,8 +1508,11 @@ fn tick_hint_highlight(
|
|||||||
sprite.color = if use_images {
|
sprite.color = if use_images {
|
||||||
Color::WHITE
|
Color::WHITE
|
||||||
} else {
|
} else {
|
||||||
let is_face_up = all_cards(&game.0)
|
let is_face_up = game
|
||||||
.iter()
|
.0
|
||||||
|
.piles
|
||||||
|
.values()
|
||||||
|
.flat_map(|p| p.cards.iter())
|
||||||
.find(|c| c.id == card_entity.card_id)
|
.find(|c| c.id == card_entity.card_id)
|
||||||
.is_some_and(|c| c.face_up);
|
.is_some_and(|c| c.face_up);
|
||||||
if is_face_up {
|
if is_face_up {
|
||||||
@@ -1713,13 +1683,17 @@ fn handle_right_click(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(source_pile) = game.0.pile_containing_card(card.id) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Tint piles that legally accept the card.
|
// Tint piles that legally accept the card.
|
||||||
for (entity, pile_marker, mut sprite) in &mut pile_markers {
|
for (entity, pile_marker, mut sprite) in &mut pile_markers {
|
||||||
let legal = game.0.can_move_cards(&source_pile, &pile_marker.0, 1);
|
let pile_type = &pile_marker.0;
|
||||||
|
let Some(pile) = game.0.piles.get(pile_type) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let legal = match pile_type {
|
||||||
|
PileType::Foundation(_) => can_place_on_foundation(&card, pile),
|
||||||
|
PileType::Tableau(_) => can_place_on_tableau(&card, pile),
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
if legal {
|
if legal {
|
||||||
sprite.color = RIGHT_CLICK_HIGHLIGHT_COLOUR;
|
sprite.color = RIGHT_CLICK_HIGHLIGHT_COLOUR;
|
||||||
commands
|
commands
|
||||||
@@ -1761,9 +1735,12 @@ fn find_top_card_at(
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let card = all_cards(game)
|
let card = game
|
||||||
.into_iter()
|
.piles
|
||||||
.find(|c| c.id == card_entity.card_id && c.face_up);
|
.values()
|
||||||
|
.flat_map(|p| p.cards.iter())
|
||||||
|
.find(|c| c.id == card_entity.card_id && c.face_up)
|
||||||
|
.cloned();
|
||||||
if let Some(card) = card {
|
if let Some(card) = card {
|
||||||
let z = transform.translation.z;
|
let z = transform.translation.z;
|
||||||
if best.as_ref().is_none_or(|(bz, _)| z > *bz) {
|
if best.as_ref().is_none_or(|(bz, _)| z > *bz) {
|
||||||
@@ -1805,10 +1782,13 @@ fn apply_stock_empty_indicator<F: bevy::ecs::query::QueryFilter>(
|
|||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
font: Handle<Font>,
|
font: Handle<Font>,
|
||||||
) {
|
) {
|
||||||
let stock_empty = game.stock_cards().is_empty();
|
let stock_empty = game
|
||||||
|
.piles
|
||||||
|
.get(&PileType::Stock)
|
||||||
|
.is_none_or(|p| p.cards.is_empty());
|
||||||
|
|
||||||
for (entity, pile_marker, mut sprite) in pile_markers.iter_mut() {
|
for (entity, pile_marker, mut sprite) in pile_markers.iter_mut() {
|
||||||
if pile_marker.0 != KlondikePile::Stock {
|
if pile_marker.0 != PileType::Stock {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1924,7 +1904,9 @@ const STOCK_BADGE_SIZE: Vec2 = Vec2::new(34.0, 20.0);
|
|||||||
/// Pure helper extracted so the count source is identical between the spawn
|
/// Pure helper extracted so the count source is identical between the spawn
|
||||||
/// system, the update system, and the unit tests.
|
/// system, the update system, and the unit tests.
|
||||||
fn stock_card_count(game: &GameState) -> usize {
|
fn stock_card_count(game: &GameState) -> usize {
|
||||||
game.stock_cards().len()
|
game.piles
|
||||||
|
.get(&PileType::Stock)
|
||||||
|
.map_or(0, |p| p.cards.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the world-space `Vec3` for the centre of the stock-count badge,
|
/// Returns the world-space `Vec3` for the centre of the stock-count badge,
|
||||||
@@ -1935,7 +1917,7 @@ fn stock_badge_translation(layout: &Layout) -> Vec3 {
|
|||||||
// the badge stays in a deterministic spot until the layout is filled.
|
// the badge stays in a deterministic spot until the layout is filled.
|
||||||
let pile_pos = layout
|
let pile_pos = layout
|
||||||
.pile_positions
|
.pile_positions
|
||||||
.get(&KlondikePile::Stock)
|
.get(&PileType::Stock)
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or(Vec2::ZERO);
|
.unwrap_or(Vec2::ZERO);
|
||||||
let half = layout.card_size * 0.5;
|
let half = layout.card_size * 0.5;
|
||||||
@@ -2345,25 +2327,15 @@ fn update_tableau_fan_frac(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let max_depth = [
|
let max_depth = (0..7_usize)
|
||||||
Tableau::Tableau1,
|
.filter_map(|i| {
|
||||||
Tableau::Tableau2,
|
game.0
|
||||||
Tableau::Tableau3,
|
.piles
|
||||||
Tableau::Tableau4,
|
.get(&solitaire_core::pile::PileType::Tableau(i))
|
||||||
Tableau::Tableau5,
|
})
|
||||||
Tableau::Tableau6,
|
.map(|pile| pile.cards.iter().filter(|c| c.face_up).count())
|
||||||
Tableau::Tableau7,
|
.max()
|
||||||
]
|
.unwrap_or(0);
|
||||||
.into_iter()
|
|
||||||
.map(|tableau| {
|
|
||||||
game.0
|
|
||||||
.pile(klondike::KlondikePile::Tableau(tableau))
|
|
||||||
.into_iter()
|
|
||||||
.filter(|c| c.face_up)
|
|
||||||
.count()
|
|
||||||
})
|
|
||||||
.max()
|
|
||||||
.unwrap_or(0);
|
|
||||||
|
|
||||||
let card_h = layout.0.card_size.y;
|
let card_h = layout.0.card_size.y;
|
||||||
let avail = layout.0.available_tableau_height;
|
let avail = layout.0.available_tableau_height;
|
||||||
@@ -2530,8 +2502,11 @@ mod tests {
|
|||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
let _ = g.draw();
|
let _ = g.draw();
|
||||||
}
|
}
|
||||||
let waste_ids: std::collections::HashSet<u32> =
|
let waste_ids: std::collections::HashSet<u32> = g.piles[&PileType::Waste]
|
||||||
g.waste_cards().iter().map(|c| c.id).collect();
|
.cards
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.id)
|
||||||
|
.collect();
|
||||||
assert_eq!(waste_ids.len(), 3);
|
assert_eq!(waste_ids.len(), 3);
|
||||||
|
|
||||||
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
@@ -2553,7 +2528,7 @@ mod tests {
|
|||||||
"at least the top waste card must be rendered"
|
"at least the top waste card must be rendered"
|
||||||
);
|
);
|
||||||
// The top (last) waste card must always be among the rendered cards.
|
// The top (last) waste card must always be among the rendered cards.
|
||||||
let top_id = g.waste_cards().last().unwrap().id;
|
let top_id = g.piles[&PileType::Waste].cards.last().unwrap().id;
|
||||||
assert!(
|
assert!(
|
||||||
waste_rendered.iter().any(|(c, _, _)| c.id == top_id),
|
waste_rendered.iter().any(|(c, _, _)| c.id == top_id),
|
||||||
"top waste card must be rendered"
|
"top waste card must be rendered"
|
||||||
@@ -2568,7 +2543,7 @@ mod tests {
|
|||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let _ = g.draw();
|
let _ = g.draw();
|
||||||
}
|
}
|
||||||
let waste_pile = g.waste_cards();
|
let waste_pile = &g.piles[&PileType::Waste].cards;
|
||||||
assert!(
|
assert!(
|
||||||
waste_pile.len() >= 3,
|
waste_pile.len() >= 3,
|
||||||
"need at least 3 waste cards for this test"
|
"need at least 3 waste cards for this test"
|
||||||
@@ -2620,7 +2595,7 @@ mod tests {
|
|||||||
// Draw exactly once — in Draw-Three mode with a full stock this gives
|
// Draw exactly once — in Draw-Three mode with a full stock this gives
|
||||||
// 3 waste cards (still ≤ visible=3, so no hidden buffer needed).
|
// 3 waste cards (still ≤ visible=3, so no hidden buffer needed).
|
||||||
let _ = g.draw();
|
let _ = g.draw();
|
||||||
let waste_pile = g.waste_cards();
|
let waste_pile = &g.piles[&PileType::Waste].cards;
|
||||||
// We need exactly 2 or 3 waste cards to hit the small-pile path.
|
// We need exactly 2 or 3 waste cards to hit the small-pile path.
|
||||||
// One draw in Draw-Three adds up to 3 cards; take the first 2 if needed.
|
// One draw in Draw-Three adds up to 3 cards; take the first 2 if needed.
|
||||||
let count = waste_pile.len();
|
let count = waste_pile.len();
|
||||||
@@ -2663,8 +2638,11 @@ mod tests {
|
|||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
let _ = g.draw();
|
let _ = g.draw();
|
||||||
}
|
}
|
||||||
let waste_ids: std::collections::HashSet<u32> =
|
let waste_ids: std::collections::HashSet<u32> = g.piles[&PileType::Waste]
|
||||||
g.waste_cards().iter().map(|c| c.id).collect();
|
.cards
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.id)
|
||||||
|
.collect();
|
||||||
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let positions = card_positions(&g, &layout);
|
let positions = card_positions(&g, &layout);
|
||||||
let waste_rendered: Vec<_> = positions
|
let waste_rendered: Vec<_> = positions
|
||||||
@@ -2693,7 +2671,7 @@ mod tests {
|
|||||||
let positions = card_positions(&g, &layout);
|
let positions = card_positions(&g, &layout);
|
||||||
|
|
||||||
// Collect positions for Tableau(6) (should have 7 cards).
|
// Collect positions for Tableau(6) (should have 7 cards).
|
||||||
let tableau_6_base = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau7)];
|
let tableau_6_base = layout.pile_positions[&PileType::Tableau(6)];
|
||||||
let mut ys: Vec<f32> = positions
|
let mut ys: Vec<f32> = positions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, pos, _)| (pos.x - tableau_6_base.x).abs() < 1e-3)
|
.filter(|(_, pos, _)| (pos.x - tableau_6_base.x).abs() < 1e-3)
|
||||||
@@ -3080,7 +3058,7 @@ mod tests {
|
|||||||
// Tableau(6) has 7 cards: 6 face-down + 1 face-up on top.
|
// Tableau(6) has 7 cards: 6 face-down + 1 face-up on top.
|
||||||
// Each face-down card contributes TABLEAU_FACEDOWN_FAN_FRAC to the column span.
|
// Each face-down card contributes TABLEAU_FACEDOWN_FAN_FRAC to the column span.
|
||||||
// Total span should be 6 * FACEDOWN < 6 * TABLEAU_FAN_FRAC (the old uniform value).
|
// Total span should be 6 * FACEDOWN < 6 * TABLEAU_FAN_FRAC (the old uniform value).
|
||||||
let col6_base = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau7)];
|
let col6_base = layout.pile_positions[&PileType::Tableau(6)];
|
||||||
let mut col6_ys: Vec<f32> = positions
|
let mut col6_ys: Vec<f32> = positions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, pos, _)| (pos.x - col6_base.x).abs() < 1e-3)
|
.filter(|(_, pos, _)| (pos.x - col6_base.x).abs() < 1e-3)
|
||||||
@@ -3490,7 +3468,9 @@ mod tests {
|
|||||||
let mut app = app();
|
let mut app = app();
|
||||||
{
|
{
|
||||||
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
||||||
game.0.set_test_stock_cards(Vec::new());
|
if let Some(stock) = game.0.piles.get_mut(&PileType::Stock) {
|
||||||
|
stock.cards.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.update();
|
app.update();
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
@@ -3508,9 +3488,9 @@ mod tests {
|
|||||||
assert_eq!(stock_badge_text(&mut app), "24");
|
assert_eq!(stock_badge_text(&mut app), "24");
|
||||||
{
|
{
|
||||||
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
||||||
let mut stock = game.0.stock_cards();
|
if let Some(stock) = game.0.piles.get_mut(&PileType::Stock) {
|
||||||
let _ = stock.pop();
|
let _ = stock.cards.pop();
|
||||||
game.0.set_test_stock_cards(stock);
|
}
|
||||||
}
|
}
|
||||||
app.update();
|
app.update();
|
||||||
assert_eq!(stock_badge_text(&mut app), "23");
|
assert_eq!(stock_badge_text(&mut app), "23");
|
||||||
@@ -3521,11 +3501,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stock_card_count_helper_reads_zero_for_empty_stock() {
|
fn stock_card_count_helper_reads_zero_when_pile_missing() {
|
||||||
|
// If the stock pile entry is somehow absent (defensive path), the
|
||||||
|
// helper must return 0 rather than panicking — the badge then
|
||||||
|
// renders as hidden via the count-zero branch in the update system.
|
||||||
let g = GameState::new(42, solitaire_core::game_state::DrawMode::DrawOne);
|
let g = GameState::new(42, solitaire_core::game_state::DrawMode::DrawOne);
|
||||||
let mut g_empty_stock = g.clone();
|
let mut g_no_stock = g.clone();
|
||||||
g_empty_stock.set_test_stock_cards(Vec::new());
|
g_no_stock.piles.remove(&PileType::Stock);
|
||||||
assert_eq!(stock_card_count(&g_empty_stock), 0);
|
assert_eq!(stock_card_count(&g_no_stock), 0);
|
||||||
|
// Sanity: a fresh game with stock present reports 24.
|
||||||
assert_eq!(stock_card_count(&g), 24);
|
assert_eq!(stock_card_count(&g), 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3815,8 +3799,11 @@ mod tests {
|
|||||||
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let positions = card_positions(&g, &layout);
|
let positions = card_positions(&g, &layout);
|
||||||
|
|
||||||
let waste_ids: std::collections::HashSet<u32> =
|
let waste_ids: std::collections::HashSet<u32> = g.piles[&PileType::Waste]
|
||||||
g.waste_cards().iter().map(|c| c.id).collect();
|
.cards
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.id)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut waste_zs: Vec<f32> = positions
|
let mut waste_zs: Vec<f32> = positions
|
||||||
.iter()
|
.iter()
|
||||||
@@ -3863,24 +3850,27 @@ mod tests {
|
|||||||
let window = Vec2::new(900.0, 2000.0);
|
let window = Vec2::new(900.0, 2000.0);
|
||||||
let layout = crate::layout::compute_layout(window, 32.0, 110.0, true);
|
let layout = crate::layout::compute_layout(window, 32.0, 110.0, true);
|
||||||
|
|
||||||
let stock_x = layout.pile_positions[&KlondikePile::Stock].x;
|
let stock_x = layout.pile_positions[&PileType::Stock].x;
|
||||||
|
let stock_right_edge = stock_x + layout.card_size.x / 2.0;
|
||||||
|
|
||||||
let waste_ids: std::collections::HashSet<u32> =
|
let waste_ids: std::collections::HashSet<u32> = g.piles[&PileType::Waste]
|
||||||
g.waste_cards().iter().map(|c| c.id).collect();
|
.cards
|
||||||
|
.iter()
|
||||||
let mut waste_positions: Vec<_> = card_positions(&g, &layout)
|
.map(|c| c.id)
|
||||||
.into_iter()
|
|
||||||
.filter(|(c, _, _)| waste_ids.contains(&c.id))
|
|
||||||
.collect();
|
.collect();
|
||||||
waste_positions.sort_by(|a, b| a.1.x.partial_cmp(&b.1.x).unwrap());
|
|
||||||
let visible_count = waste_positions.len().min(3);
|
let positions = card_positions(&g, &layout);
|
||||||
for (card, pos, _) in waste_positions.iter().rev().take(visible_count) {
|
for (card, pos, _) in positions
|
||||||
|
.iter()
|
||||||
|
.filter(|(c, _, _)| waste_ids.contains(&c.id))
|
||||||
|
{
|
||||||
|
let left_edge = pos.x - layout.card_size.x / 2.0;
|
||||||
assert!(
|
assert!(
|
||||||
pos.x >= stock_x - 1e-3,
|
left_edge >= stock_right_edge - 1e-3,
|
||||||
"waste card {} x {:.2} drifted left of stock origin {:.2} on portrait window",
|
"waste card {} left edge {:.2} overlaps stock right edge {:.2} on portrait window",
|
||||||
card.id,
|
card.id,
|
||||||
pos.x,
|
left_edge,
|
||||||
stock_x,
|
stock_right_edge,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3895,8 +3885,11 @@ mod tests {
|
|||||||
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = crate::layout::compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let positions = card_positions(&g, &layout);
|
let positions = card_positions(&g, &layout);
|
||||||
|
|
||||||
let waste_ids: std::collections::HashSet<u32> =
|
let waste_ids: std::collections::HashSet<u32> = g.piles[&PileType::Waste]
|
||||||
g.waste_cards().iter().map(|c| c.id).collect();
|
.cards
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.id)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut waste_zs: Vec<f32> = positions
|
let mut waste_zs: Vec<f32> = positions
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -13,18 +13,16 @@ use crate::platform::{
|
|||||||
default_storage_backend,
|
default_storage_backend,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
AchievementPlugin, AnimationPlugin, AssetSourcesPlugin, AutoCompletePlugin,
|
AchievementPlugin, AnalyticsPlugin, AnimationPlugin, AssetSourcesPlugin, AudioPlugin,
|
||||||
CardAnimationPlugin, CardPlugin, ChallengePlugin, CursorPlugin, DailyChallengePlugin,
|
AutoCompletePlugin, AvatarPlugin, CardAnimationPlugin, CardPlugin, ChallengePlugin,
|
||||||
DiagnosticsHudPlugin, DifficultyPlugin, FeedbackAnimPlugin, FontPlugin, GamePlugin, HelpPlugin,
|
CursorPlugin, DailyChallengePlugin, DiagnosticsHudPlugin, DifficultyPlugin, FeedbackAnimPlugin,
|
||||||
HomePlugin, HudPlugin, InputPlugin, OnboardingPlugin, PausePlugin, PlayBySeedPlugin,
|
FontPlugin, GamePlugin, HelpPlugin, HomePlugin, HudPlugin, InputPlugin, LeaderboardPlugin,
|
||||||
ProfilePlugin, ProgressPlugin, RadialMenuPlugin, ReplayOverlayPlugin, ReplayPlaybackPlugin,
|
OnboardingPlugin, PausePlugin, PlayBySeedPlugin, ProfilePlugin, ProgressPlugin,
|
||||||
SafeAreaInsetsPlugin, SelectionPlugin, SettingsPlugin, SplashPlugin, StatsPlugin, SyncProvider,
|
RadialMenuPlugin, ReplayOverlayPlugin, ReplayPlaybackPlugin, SafeAreaInsetsPlugin,
|
||||||
TablePlugin, ThemePlugin, ThemeRegistryPlugin, TimeAttackPlugin, TouchSelectionPlugin,
|
SelectionPlugin, SettingsPlugin, SplashPlugin, StatsPlugin, SyncPlugin, SyncProvider,
|
||||||
UiFocusPlugin, UiModalPlugin, UiTooltipPlugin, WeeklyGoalsPlugin, WinSummaryPlugin,
|
SyncSetupPlugin, TablePlugin, ThemePlugin, ThemeRegistryPlugin, TimeAttackPlugin,
|
||||||
};
|
TouchSelectionPlugin, UiFocusPlugin, UiModalPlugin, UiTooltipPlugin, WeeklyGoalsPlugin,
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
WinSummaryPlugin,
|
||||||
use crate::{
|
|
||||||
AnalyticsPlugin, AudioPlugin, AvatarPlugin, LeaderboardPlugin, SyncPlugin, SyncSetupPlugin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Groups all Ferrous Solitaire gameplay plugins.
|
/// Groups all Ferrous Solitaire gameplay plugins.
|
||||||
@@ -47,7 +45,6 @@ impl Plugin for CoreGamePlugin {
|
|||||||
Ok(guard) => guard,
|
Ok(guard) => guard,
|
||||||
Err(poisoned) => poisoned.into_inner(),
|
Err(poisoned) => poisoned.into_inner(),
|
||||||
};
|
};
|
||||||
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
|
|
||||||
let sync_provider = sync_provider
|
let sync_provider = sync_provider
|
||||||
.take()
|
.take()
|
||||||
.expect("CoreGamePlugin::build called twice");
|
.expect("CoreGamePlugin::build called twice");
|
||||||
@@ -107,26 +104,21 @@ impl Plugin for CoreGamePlugin {
|
|||||||
.add_plugins(HudPlugin)
|
.add_plugins(HudPlugin)
|
||||||
.add_plugins(HelpPlugin)
|
.add_plugins(HelpPlugin)
|
||||||
.add_plugins(HomePlugin::default())
|
.add_plugins(HomePlugin::default())
|
||||||
|
.add_plugins(AvatarPlugin)
|
||||||
.add_plugins(ProfilePlugin)
|
.add_plugins(ProfilePlugin)
|
||||||
.add_plugins(PausePlugin)
|
.add_plugins(PausePlugin)
|
||||||
.add_plugins(SettingsPlugin::default())
|
.add_plugins(SettingsPlugin::default())
|
||||||
|
.add_plugins(AudioPlugin)
|
||||||
.add_plugins(OnboardingPlugin)
|
.add_plugins(OnboardingPlugin)
|
||||||
|
.add_plugins(SyncPlugin::new(sync_provider))
|
||||||
|
.add_plugins(SyncSetupPlugin)
|
||||||
|
.add_plugins(AnalyticsPlugin)
|
||||||
|
.add_plugins(LeaderboardPlugin)
|
||||||
.add_plugins(WinSummaryPlugin)
|
.add_plugins(WinSummaryPlugin)
|
||||||
.add_plugins(UiModalPlugin)
|
.add_plugins(UiModalPlugin)
|
||||||
.add_plugins(UiFocusPlugin)
|
.add_plugins(UiFocusPlugin)
|
||||||
.add_plugins(UiTooltipPlugin)
|
.add_plugins(UiTooltipPlugin)
|
||||||
.add_plugins(SplashPlugin)
|
.add_plugins(SplashPlugin)
|
||||||
.add_plugins(DiagnosticsHudPlugin);
|
.add_plugins(DiagnosticsHudPlugin);
|
||||||
|
|
||||||
// Plugins that use kira/cpal audio or multi-threaded Tokio are not
|
|
||||||
// compatible with the single-threaded wasm32 runtime. Gate them out
|
|
||||||
// so the browser build boots silently and without a sync backend.
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
app.add_plugins(AvatarPlugin)
|
|
||||||
.add_plugins(AudioPlugin)
|
|
||||||
.add_plugins(SyncPlugin::new(sync_provider))
|
|
||||||
.add_plugins(SyncSetupPlugin)
|
|
||||||
.add_plugins(AnalyticsPlugin)
|
|
||||||
.add_plugins(LeaderboardPlugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,9 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::{CursorIcon, PrimaryWindow, SystemCursorIcon};
|
use bevy::window::{CursorIcon, PrimaryWindow, SystemCursorIcon};
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
use solitaire_core::rules::{can_place_on_foundation, can_place_on_tableau};
|
||||||
|
|
||||||
use crate::card_plugin::RightClickHighlight;
|
use crate::card_plugin::RightClickHighlight;
|
||||||
use crate::layout::{Layout, LayoutResource};
|
use crate::layout::{Layout, LayoutResource};
|
||||||
@@ -65,10 +66,10 @@ const MARKER_VALID: Color = Color::srgba(0.675, 0.761, 0.404, 0.55);
|
|||||||
|
|
||||||
/// Marker component on a parent entity that owns one drop-target overlay
|
/// Marker component on a parent entity that owns one drop-target overlay
|
||||||
/// (a translucent fill plus four outline edges as children). The wrapped
|
/// (a translucent fill plus four outline edges as children). The wrapped
|
||||||
/// `KlondikePile` identifies which pile this overlay highlights, so test
|
/// `PileType` identifies which pile this overlay highlights, so test
|
||||||
/// queries and the despawn-on-target-change logic can filter by pile.
|
/// queries and the despawn-on-target-change logic can filter by pile.
|
||||||
#[derive(Component, Debug, Clone, PartialEq, Eq)]
|
#[derive(Component, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct DropTargetOverlay(pub KlondikePile);
|
pub struct DropTargetOverlay(pub PileType);
|
||||||
|
|
||||||
/// Renders a custom cursor sprite that follows the pointer and swaps to a grab-hand icon while a card drag is in progress.
|
/// Renders a custom cursor sprite that follows the pointer and swaps to a grab-hand icon while a card drag is in progress.
|
||||||
pub struct CursorPlugin;
|
pub struct CursorPlugin;
|
||||||
@@ -162,34 +163,33 @@ fn update_cursor_icon(
|
|||||||
/// Returns `true` if `cursor` (world-space) is over any face-up draggable card.
|
/// Returns `true` if `cursor` (world-space) is over any face-up draggable card.
|
||||||
fn cursor_over_draggable(cursor: Vec2, game: &GameState, layout: &Layout) -> bool {
|
fn cursor_over_draggable(cursor: Vec2, game: &GameState, layout: &Layout) -> bool {
|
||||||
let piles = [
|
let piles = [
|
||||||
KlondikePile::Stock,
|
PileType::Waste,
|
||||||
KlondikePile::Foundation(Foundation::Foundation1),
|
PileType::Foundation(0),
|
||||||
KlondikePile::Foundation(Foundation::Foundation2),
|
PileType::Foundation(1),
|
||||||
KlondikePile::Foundation(Foundation::Foundation3),
|
PileType::Foundation(2),
|
||||||
KlondikePile::Foundation(Foundation::Foundation4),
|
PileType::Foundation(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
PileType::Tableau(0),
|
||||||
KlondikePile::Tableau(Tableau::Tableau2),
|
PileType::Tableau(1),
|
||||||
KlondikePile::Tableau(Tableau::Tableau3),
|
PileType::Tableau(2),
|
||||||
KlondikePile::Tableau(Tableau::Tableau4),
|
PileType::Tableau(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau5),
|
PileType::Tableau(4),
|
||||||
KlondikePile::Tableau(Tableau::Tableau6),
|
PileType::Tableau(5),
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
PileType::Tableau(6),
|
||||||
];
|
];
|
||||||
|
|
||||||
for pile in piles {
|
for pile in piles {
|
||||||
let pile_cards = pile_cards(game, &pile);
|
let Some(pile_cards) = game.piles.get(&pile) else {
|
||||||
if pile_cards.is_empty() {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
let is_tableau = matches!(pile, KlondikePile::Tableau(_));
|
let is_tableau = matches!(pile, PileType::Tableau(_));
|
||||||
let base = layout.pile_positions[&pile];
|
let base = layout.pile_positions[&pile];
|
||||||
|
|
||||||
for (i, card) in pile_cards.iter().enumerate().rev() {
|
for (i, card) in pile_cards.cards.iter().enumerate().rev() {
|
||||||
if !card.face_up {
|
if !card.face_up {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Only the topmost card is draggable on non-tableau piles.
|
// Only the topmost card is draggable on non-tableau piles.
|
||||||
if !is_tableau && i != pile_cards.len() - 1 {
|
if !is_tableau && i != pile_cards.cards.len() - 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let pos = tableau_or_stack_pos(game, layout, &pile, i, base, is_tableau);
|
let pos = tableau_or_stack_pos(game, layout, &pile, i, base, is_tableau);
|
||||||
@@ -226,14 +226,38 @@ fn update_drop_highlights(
|
|||||||
|
|
||||||
let Some(game) = game else { return };
|
let Some(game) = game else { return };
|
||||||
|
|
||||||
let drag_count = drag.cards.len();
|
// The first element of drag.cards is the bottom card that lands on the target.
|
||||||
|
let Some(&bottom_id) = drag.cards.first() else {
|
||||||
let Some(origin) = drag.origin_pile.as_ref() else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let bottom_card = game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.values()
|
||||||
|
.flat_map(|p| p.cards.iter())
|
||||||
|
.find(|c| c.id == bottom_id)
|
||||||
|
.cloned();
|
||||||
|
let Some(bottom_card) = bottom_card else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let drag_count = drag.cards.len();
|
||||||
|
|
||||||
for (marker, mut sprite, _rch) in &mut markers {
|
for (marker, mut sprite, _rch) in &mut markers {
|
||||||
let valid = game.0.can_move_cards(origin, &marker.0, drag_count);
|
let valid = match &marker.0 {
|
||||||
|
PileType::Foundation(slot) => {
|
||||||
|
if drag_count != 1 {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
let pile = game.0.piles.get(&PileType::Foundation(*slot));
|
||||||
|
pile.is_some_and(|p| can_place_on_foundation(&bottom_card, p))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PileType::Tableau(idx) => {
|
||||||
|
let pile = game.0.piles.get(&PileType::Tableau(*idx));
|
||||||
|
pile.is_some_and(|p| can_place_on_tableau(&bottom_card, p))
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
sprite.color = if valid { MARKER_VALID } else { MARKER_DEFAULT };
|
sprite.color = if valid { MARKER_VALID } else { MARKER_DEFAULT };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +297,20 @@ fn update_drop_target_overlays(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(origin) = drag.origin_pile.as_ref() else {
|
// Resolve the bottom card of the dragged stack — same logic as
|
||||||
|
// `update_drop_highlights` so rules can't drift between the marker
|
||||||
|
// tint and the overlay.
|
||||||
|
let Some(&bottom_id) = drag.cards.first() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let bottom_card = game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.values()
|
||||||
|
.flat_map(|p| p.cards.iter())
|
||||||
|
.find(|c| c.id == bottom_id)
|
||||||
|
.cloned();
|
||||||
|
let Some(bottom_card) = bottom_card else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let drag_count = drag.cards.len();
|
let drag_count = drag.cards.len();
|
||||||
@@ -281,24 +318,44 @@ fn update_drop_target_overlays(
|
|||||||
// Iterate the same pile list as `update_drop_highlights`. Stock and
|
// Iterate the same pile list as `update_drop_highlights`. Stock and
|
||||||
// Waste are excluded because they are never legal drop targets.
|
// Waste are excluded because they are never legal drop targets.
|
||||||
let candidates = [
|
let candidates = [
|
||||||
KlondikePile::Foundation(Foundation::Foundation1),
|
PileType::Foundation(0),
|
||||||
KlondikePile::Foundation(Foundation::Foundation2),
|
PileType::Foundation(1),
|
||||||
KlondikePile::Foundation(Foundation::Foundation3),
|
PileType::Foundation(2),
|
||||||
KlondikePile::Foundation(Foundation::Foundation4),
|
PileType::Foundation(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
PileType::Tableau(0),
|
||||||
KlondikePile::Tableau(Tableau::Tableau2),
|
PileType::Tableau(1),
|
||||||
KlondikePile::Tableau(Tableau::Tableau3),
|
PileType::Tableau(2),
|
||||||
KlondikePile::Tableau(Tableau::Tableau4),
|
PileType::Tableau(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau5),
|
PileType::Tableau(4),
|
||||||
KlondikePile::Tableau(Tableau::Tableau6),
|
PileType::Tableau(5),
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
PileType::Tableau(6),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Compute the new set of valid piles for this frame.
|
// Compute the new set of valid piles for this frame.
|
||||||
let mut valid: Vec<KlondikePile> = Vec::new();
|
let mut valid: Vec<PileType> = Vec::new();
|
||||||
for pile in &candidates {
|
for pile in &candidates {
|
||||||
if game.0.can_move_cards(origin, pile, drag_count) {
|
let is_valid = match pile {
|
||||||
valid.push(*pile);
|
PileType::Foundation(_) => {
|
||||||
|
if drag_count != 1 {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
game.0
|
||||||
|
.piles
|
||||||
|
.get(pile)
|
||||||
|
.is_some_and(|p| can_place_on_foundation(&bottom_card, p))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PileType::Tableau(_) => game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.get(pile)
|
||||||
|
.is_some_and(|p| can_place_on_tableau(&bottom_card, p)),
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
// Don't highlight the origin pile — dropping onto the source is
|
||||||
|
// a no-op.
|
||||||
|
if is_valid && drag.origin_pile.as_ref() != Some(pile) {
|
||||||
|
valid.push(pile.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,9 +367,9 @@ fn update_drop_target_overlays(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn overlays for piles that are now valid but don't yet have one.
|
// Spawn overlays for piles that are now valid but don't yet have one.
|
||||||
let already_overlaid: Vec<KlondikePile> = overlays
|
let already_overlaid: Vec<PileType> = overlays
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, m)| m.0)
|
.map(|(_, m)| m.0.clone())
|
||||||
.filter(|p| valid.contains(p))
|
.filter(|p| valid.contains(p))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -331,14 +388,10 @@ fn update_drop_target_overlays(
|
|||||||
/// for everything else it is card-sized. Replicated here rather than
|
/// for everything else it is card-sized. Replicated here rather than
|
||||||
/// imported because `pile_drop_rect` is private to `input_plugin` and
|
/// imported because `pile_drop_rect` is private to `input_plugin` and
|
||||||
/// this overlay is the only other consumer.
|
/// this overlay is the only other consumer.
|
||||||
fn drop_overlay_rect(
|
fn drop_overlay_rect(pile: &PileType, layout: &Layout, game: &GameState) -> Option<(Vec2, Vec2)> {
|
||||||
pile: &KlondikePile,
|
|
||||||
layout: &Layout,
|
|
||||||
game: &GameState,
|
|
||||||
) -> Option<(Vec2, Vec2)> {
|
|
||||||
let centre = layout.pile_positions.get(pile).copied()?;
|
let centre = layout.pile_positions.get(pile).copied()?;
|
||||||
if matches!(pile, KlondikePile::Tableau(_)) {
|
if matches!(pile, PileType::Tableau(_)) {
|
||||||
let card_count = game.pile(*pile).len();
|
let card_count = game.piles.get(pile).map_or(0, |p| p.cards.len());
|
||||||
if card_count > 1 {
|
if card_count > 1 {
|
||||||
let fan = -layout.card_size.y * layout.tableau_fan_frac;
|
let fan = -layout.card_size.y * layout.tableau_fan_frac;
|
||||||
let bottom_card_centre_y = centre.y + fan * (card_count - 1) as f32;
|
let bottom_card_centre_y = centre.y + fan * (card_count - 1) as f32;
|
||||||
@@ -359,7 +412,7 @@ fn drop_overlay_rect(
|
|||||||
/// the appropriate world position for `pile`.
|
/// the appropriate world position for `pile`.
|
||||||
fn spawn_drop_target_overlay(
|
fn spawn_drop_target_overlay(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
pile: &KlondikePile,
|
pile: &PileType,
|
||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
game: &GameState,
|
game: &GameState,
|
||||||
) {
|
) {
|
||||||
@@ -377,7 +430,7 @@ fn spawn_drop_target_overlay(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Transform::from_xyz(centre.x, centre.y, Z_DROP_OVERLAY),
|
Transform::from_xyz(centre.x, centre.y, Z_DROP_OVERLAY),
|
||||||
DropTargetOverlay(*pile),
|
DropTargetOverlay(pile.clone()),
|
||||||
))
|
))
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
// Top edge.
|
// Top edge.
|
||||||
@@ -426,7 +479,7 @@ fn spawn_drop_target_overlay(
|
|||||||
fn tableau_or_stack_pos(
|
fn tableau_or_stack_pos(
|
||||||
game: &GameState,
|
game: &GameState,
|
||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
pile: &KlondikePile,
|
pile: &PileType,
|
||||||
index: usize,
|
index: usize,
|
||||||
base: Vec2,
|
base: Vec2,
|
||||||
is_tableau: bool,
|
is_tableau: bool,
|
||||||
@@ -436,8 +489,8 @@ fn tableau_or_stack_pos(
|
|||||||
base.x,
|
base.x,
|
||||||
base.y - layout.card_size.y * layout.tableau_fan_frac * (index as f32),
|
base.y - layout.card_size.y * layout.tableau_fan_frac * (index as f32),
|
||||||
)
|
)
|
||||||
} else if matches!(pile, KlondikePile::Stock) && game.draw_mode == DrawMode::DrawThree {
|
} else if matches!(pile, PileType::Waste) && game.draw_mode == DrawMode::DrawThree {
|
||||||
let pile_len = game.waste_cards().len();
|
let pile_len = game.piles.get(pile).map_or(0, |p| p.cards.len());
|
||||||
let visible_start = pile_len.saturating_sub(3);
|
let visible_start = pile_len.saturating_sub(3);
|
||||||
let slot = index.saturating_sub(visible_start) as f32;
|
let slot = index.saturating_sub(visible_start) as f32;
|
||||||
Vec2::new(base.x + slot * layout.card_size.x * 0.28, base.y)
|
Vec2::new(base.x + slot * layout.card_size.x * 0.28, base.y)
|
||||||
@@ -446,14 +499,6 @@ fn tableau_or_stack_pos(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pile_cards(game: &GameState, pile: &KlondikePile) -> Vec<solitaire_core::card::Card> {
|
|
||||||
if matches!(pile, KlondikePile::Stock) {
|
|
||||||
game.waste_cards()
|
|
||||||
} else {
|
|
||||||
game.pile(*pile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn point_in_rect(point: Vec2, center: Vec2, size: Vec2) -> bool {
|
fn point_in_rect(point: Vec2, center: Vec2, size: Vec2) -> bool {
|
||||||
let half = size / 2.0;
|
let half = size / 2.0;
|
||||||
point.x >= center.x - half.x
|
point.x >= center.x - half.x
|
||||||
@@ -604,8 +649,12 @@ mod tests {
|
|||||||
/// card. Used to make a specific tableau column accept a chosen
|
/// card. Used to make a specific tableau column accept a chosen
|
||||||
/// drag stack.
|
/// drag stack.
|
||||||
fn set_tableau_top(game: &mut GameState, idx: usize, card: Card) {
|
fn set_tableau_top(game: &mut GameState, idx: usize, card: Card) {
|
||||||
let tableau = GameState::tableau_from_index(idx).expect("tableau pile exists");
|
let pile = game
|
||||||
game.set_test_tableau_cards(tableau, vec![card]);
|
.piles
|
||||||
|
.get_mut(&PileType::Tableau(idx))
|
||||||
|
.expect("tableau pile exists");
|
||||||
|
pile.cards.clear();
|
||||||
|
pile.cards.push(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a single face-up dragged card into the waste pile and
|
/// Inserts a single face-up dragged card into the waste pile and
|
||||||
@@ -615,14 +664,59 @@ mod tests {
|
|||||||
// Place the dragged card on the waste pile (origin).
|
// Place the dragged card on the waste pile (origin).
|
||||||
{
|
{
|
||||||
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
let mut game = app.world_mut().resource_mut::<GameStateResource>();
|
||||||
game.0.set_test_waste_cards(vec![dragged.clone()]);
|
let waste = game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.get_mut(&PileType::Waste)
|
||||||
|
.expect("waste pile exists");
|
||||||
|
waste.cards.clear();
|
||||||
|
waste.cards.push(dragged.clone());
|
||||||
}
|
}
|
||||||
let mut drag = app.world_mut().resource_mut::<DragState>();
|
let mut drag = app.world_mut().resource_mut::<DragState>();
|
||||||
drag.cards = vec![dragged.id];
|
drag.cards = vec![dragged.id];
|
||||||
drag.origin_pile = Some(KlondikePile::Stock);
|
drag.origin_pile = Some(PileType::Waste);
|
||||||
drag.committed = true;
|
drag.committed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn drop_target_overlay_spawns_for_valid_tableau_during_drag() {
|
||||||
|
// 5 of Hearts (red, rank 5) on top of Tableau(2)'s 6 of Spades
|
||||||
|
// (black, rank 6) — alternating colour, one rank lower → legal.
|
||||||
|
let mut game = GameState::new_with_mode(7, DrawMode::DrawOne, GameMode::Classic);
|
||||||
|
set_tableau_top(
|
||||||
|
&mut game,
|
||||||
|
2,
|
||||||
|
Card {
|
||||||
|
id: 9001,
|
||||||
|
suit: Suit::Spades,
|
||||||
|
rank: Rank::Six,
|
||||||
|
face_up: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let dragged = Card {
|
||||||
|
id: 9002,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Five,
|
||||||
|
face_up: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut app = overlay_test_app(game);
|
||||||
|
begin_drag_with(&mut app, dragged);
|
||||||
|
|
||||||
|
app.update();
|
||||||
|
|
||||||
|
let overlays: Vec<PileType> = app
|
||||||
|
.world_mut()
|
||||||
|
.query::<&DropTargetOverlay>()
|
||||||
|
.iter(app.world())
|
||||||
|
.map(|o| o.0.clone())
|
||||||
|
.collect();
|
||||||
|
assert!(
|
||||||
|
overlays.contains(&PileType::Tableau(2)),
|
||||||
|
"expected Tableau(2) to be highlighted as a legal drop target, got {overlays:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_target_overlay_does_not_spawn_for_invalid_destination() {
|
fn drop_target_overlay_does_not_spawn_for_invalid_destination() {
|
||||||
// 5 of Spades (black) onto Tableau(2)'s 6 of Clubs (also black)
|
// 5 of Spades (black) onto Tableau(2)'s 6 of Clubs (also black)
|
||||||
@@ -651,15 +745,67 @@ mod tests {
|
|||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let overlays: Vec<KlondikePile> = app
|
let overlays: Vec<PileType> = app
|
||||||
.world_mut()
|
.world_mut()
|
||||||
.query::<&DropTargetOverlay>()
|
.query::<&DropTargetOverlay>()
|
||||||
.iter(app.world())
|
.iter(app.world())
|
||||||
.map(|o| o.0.clone())
|
.map(|o| o.0.clone())
|
||||||
.collect();
|
.collect();
|
||||||
assert!(
|
assert!(
|
||||||
!overlays.contains(&KlondikePile::Tableau(Tableau::Tableau3)),
|
!overlays.contains(&PileType::Tableau(2)),
|
||||||
"Tableau(2) must not be highlighted for an illegal drop, got {overlays:?}"
|
"Tableau(2) must not be highlighted for an illegal drop, got {overlays:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn drop_target_overlays_despawn_on_drag_end() {
|
||||||
|
// Set up a scenario that produces at least one valid overlay,
|
||||||
|
// confirm it spawns, then clear the drag and confirm every
|
||||||
|
// overlay is despawned.
|
||||||
|
let mut game = GameState::new_with_mode(7, DrawMode::DrawOne, GameMode::Classic);
|
||||||
|
set_tableau_top(
|
||||||
|
&mut game,
|
||||||
|
2,
|
||||||
|
Card {
|
||||||
|
id: 9201,
|
||||||
|
suit: Suit::Spades,
|
||||||
|
rank: Rank::Six,
|
||||||
|
face_up: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let dragged = Card {
|
||||||
|
id: 9202,
|
||||||
|
suit: Suit::Hearts,
|
||||||
|
rank: Rank::Five,
|
||||||
|
face_up: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut app = overlay_test_app(game);
|
||||||
|
begin_drag_with(&mut app, dragged);
|
||||||
|
app.update();
|
||||||
|
|
||||||
|
let count_during_drag = app
|
||||||
|
.world_mut()
|
||||||
|
.query::<&DropTargetOverlay>()
|
||||||
|
.iter(app.world())
|
||||||
|
.count();
|
||||||
|
assert!(
|
||||||
|
count_during_drag >= 1,
|
||||||
|
"expected ≥1 overlay during drag, got {count_during_drag}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// End the drag — every overlay should despawn next frame.
|
||||||
|
app.world_mut().resource_mut::<DragState>().clear();
|
||||||
|
app.update();
|
||||||
|
|
||||||
|
let count_after_drag = app
|
||||||
|
.world_mut()
|
||||||
|
.query::<&DropTargetOverlay>()
|
||||||
|
.iter(app.world())
|
||||||
|
.count();
|
||||||
|
assert_eq!(
|
||||||
|
count_after_drag, 0,
|
||||||
|
"all overlays must despawn when the drag ends"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,9 @@
|
|||||||
|
|
||||||
use bevy::input::ButtonInput;
|
use bevy::input::ButtonInput;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use bevy::tasks::{AsyncComputeTaskPool, Task, futures_lite::future};
|
use bevy::tasks::{AsyncComputeTaskPool, Task, futures_lite::future};
|
||||||
use chrono::{DateTime, Duration, Local, NaiveDate, Utc};
|
use chrono::{DateTime, Duration, Local, NaiveDate, Utc};
|
||||||
use solitaire_data::{daily_seed_for, save_progress_to};
|
use solitaire_data::{daily_seed_for, save_progress_to};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use solitaire_sync::ChallengeGoal;
|
use solitaire_sync::ChallengeGoal;
|
||||||
|
|
||||||
use crate::events::{
|
use crate::events::{
|
||||||
@@ -27,7 +25,6 @@ use crate::events::{
|
|||||||
use crate::game_plugin::GameMutation;
|
use crate::game_plugin::GameMutation;
|
||||||
use crate::progress_plugin::{ProgressResource, ProgressStoragePath, ProgressUpdate};
|
use crate::progress_plugin::{ProgressResource, ProgressStoragePath, ProgressUpdate};
|
||||||
use crate::resources::GameStateResource;
|
use crate::resources::GameStateResource;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::sync_plugin::SyncProviderResource;
|
use crate::sync_plugin::SyncProviderResource;
|
||||||
|
|
||||||
/// Bonus XP awarded for completing today's daily challenge.
|
/// Bonus XP awarded for completing today's daily challenge.
|
||||||
@@ -80,13 +77,8 @@ pub struct DailyChallengeCompletedEvent {
|
|||||||
/// Holds the in-flight server challenge fetch so the result can be polled
|
/// Holds the in-flight server challenge fetch so the result can be polled
|
||||||
/// each frame without blocking the main thread.
|
/// each frame without blocking the main thread.
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
struct DailyChallengeTask(Option<Task<Option<ChallengeGoal>>>);
|
struct DailyChallengeTask(Option<Task<Option<ChallengeGoal>>>);
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
struct DailyChallengeTask;
|
|
||||||
|
|
||||||
/// Tracks which `DailyChallengeResource::date` the expiry-warning toast has
|
/// Tracks which `DailyChallengeResource::date` the expiry-warning toast has
|
||||||
/// already fired for, so the toast spawns at most once per day.
|
/// already fired for, so the toast spawns at most once per day.
|
||||||
///
|
///
|
||||||
@@ -124,21 +116,17 @@ impl Plugin for DailyChallengePlugin {
|
|||||||
.add_message::<StartDailyChallengeRequestEvent>()
|
.add_message::<StartDailyChallengeRequestEvent>()
|
||||||
.add_message::<WarningToastEvent>()
|
.add_message::<WarningToastEvent>()
|
||||||
.add_message::<XpAwardedEvent>()
|
.add_message::<XpAwardedEvent>()
|
||||||
|
.add_systems(Startup, fetch_server_challenge)
|
||||||
|
.add_systems(Update, poll_server_challenge)
|
||||||
// record/award after the base ProgressUpdate so we don't fight
|
// record/award after the base ProgressUpdate so we don't fight
|
||||||
// ProgressPlugin's add_xp on the same frame.
|
// ProgressPlugin's add_xp on the same frame.
|
||||||
.add_systems(Update, handle_daily_completion.after(ProgressUpdate))
|
.add_systems(Update, handle_daily_completion.after(ProgressUpdate))
|
||||||
.add_systems(Update, handle_start_daily_request.before(GameMutation))
|
.add_systems(Update, handle_start_daily_request.before(GameMutation))
|
||||||
.add_systems(Update, check_daily_expiry_warning)
|
.add_systems(Update, check_daily_expiry_warning)
|
||||||
.add_systems(Update, check_date_rollover);
|
.add_systems(Update, check_date_rollover);
|
||||||
|
|
||||||
// Server-challenge fetch uses SyncProviderResource (reqwest), not available on wasm.
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
app.add_systems(Startup, fetch_server_challenge)
|
|
||||||
.add_systems(Update, poll_server_challenge);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// Startup system: spawns an async task to fetch the server's daily challenge.
|
/// Startup system: spawns an async task to fetch the server's daily challenge.
|
||||||
///
|
///
|
||||||
/// Only runs when `SyncProviderResource` is present (i.e. `SyncPlugin` is
|
/// Only runs when `SyncProviderResource` is present (i.e. `SyncPlugin` is
|
||||||
@@ -154,7 +142,6 @@ fn fetch_server_challenge(
|
|||||||
task_res.0 = Some(task);
|
task_res.0 = Some(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// Update system: polls the server-challenge fetch task.
|
/// Update system: polls the server-challenge fetch task.
|
||||||
///
|
///
|
||||||
/// On success, replaces the locally-computed seed in `DailyChallengeResource`
|
/// On success, replaces the locally-computed seed in `DailyChallengeResource`
|
||||||
@@ -354,6 +341,7 @@ fn check_date_rollover(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
//! because the starting position is effectively random (player-chosen timing
|
//! because the starting position is effectively random (player-chosen timing
|
||||||
//! determines which seed in the 40-entry catalog they start at).
|
//! determines which seed in the 40-entry catalog they start at).
|
||||||
|
|
||||||
use chrono::Utc;
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use solitaire_core::game_state::{DifficultyLevel, GameMode};
|
use solitaire_core::game_state::{DifficultyLevel, GameMode};
|
||||||
@@ -104,9 +104,10 @@ fn handle_difficulty_request(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn seed_from_system_time() -> u64 {
|
fn seed_from_system_time() -> u64 {
|
||||||
// Use chrono so this works on wasm32 (chrono has the `wasmbind` feature;
|
SystemTime::now()
|
||||||
// std::time::SystemTime panics on wasm32-unknown-unknown).
|
.duration_since(UNIX_EPOCH)
|
||||||
Utc::now().timestamp_nanos_opt().unwrap_or(0) as u64
|
.map(|d| d.as_nanos() as u64)
|
||||||
|
.unwrap_or(0xD1FF_0000_DEAD_BEEF)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//! Cross-system events used by the engine's plugins.
|
//! Cross-system events used by the engine's plugins.
|
||||||
|
|
||||||
use bevy::prelude::Message;
|
use bevy::prelude::Message;
|
||||||
use klondike::KlondikePile;
|
|
||||||
use solitaire_core::card::Suit;
|
use solitaire_core::card::Suit;
|
||||||
use solitaire_core::game_state::GameMode;
|
use solitaire_core::game_state::GameMode;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
use solitaire_data::AchievementRecord;
|
use solitaire_data::AchievementRecord;
|
||||||
use solitaire_sync::SyncResponse;
|
use solitaire_sync::SyncResponse;
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@ use solitaire_sync::SyncResponse;
|
|||||||
/// consumed by `GamePlugin`.
|
/// consumed by `GamePlugin`.
|
||||||
#[derive(Message, Debug, Clone)]
|
#[derive(Message, Debug, Clone)]
|
||||||
pub struct MoveRequestEvent {
|
pub struct MoveRequestEvent {
|
||||||
pub from: KlondikePile,
|
pub from: PileType,
|
||||||
pub to: KlondikePile,
|
pub to: PileType,
|
||||||
pub count: usize,
|
pub count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ pub struct StateChangedEvent;
|
|||||||
/// `card_invalid.wav` SFX. Not fired for drops in empty space.
|
/// `card_invalid.wav` SFX. Not fired for drops in empty space.
|
||||||
#[derive(Message, Debug, Clone)]
|
#[derive(Message, Debug, Clone)]
|
||||||
pub struct MoveRejectedEvent {
|
pub struct MoveRejectedEvent {
|
||||||
pub from: KlondikePile,
|
pub from: PileType,
|
||||||
pub to: KlondikePile,
|
pub to: PileType,
|
||||||
pub count: usize,
|
pub count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,5 +302,5 @@ pub struct HintVisualEvent {
|
|||||||
/// The `Card::id` of the source card to be highlighted.
|
/// The `Card::id` of the source card to be highlighted.
|
||||||
pub source_card_id: u32,
|
pub source_card_id: u32,
|
||||||
/// The destination pile whose `PileMarker` should be tinted gold.
|
/// The destination pile whose `PileMarker` should be tinted gold.
|
||||||
pub dest_pile: KlondikePile,
|
pub dest_pile: solitaire_core::pile::PileType,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ use std::f32::consts::PI;
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::RequestRedraw;
|
use solitaire_core::pile::PileType;
|
||||||
use klondike::{Foundation, KlondikePile};
|
|
||||||
use solitaire_data::AnimSpeed;
|
use solitaire_data::AnimSpeed;
|
||||||
|
|
||||||
use crate::animation_plugin::CardAnim;
|
use crate::animation_plugin::CardAnim;
|
||||||
@@ -205,7 +204,6 @@ impl Plugin for FeedbackAnimPlugin {
|
|||||||
.add_message::<MoveRejectedEvent>()
|
.add_message::<MoveRejectedEvent>()
|
||||||
.add_message::<NewGameRequestEvent>()
|
.add_message::<NewGameRequestEvent>()
|
||||||
.add_message::<FoundationCompletedEvent>()
|
.add_message::<FoundationCompletedEvent>()
|
||||||
.add_message::<RequestRedraw>()
|
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
@@ -246,8 +244,10 @@ fn start_shake_anim(
|
|||||||
}
|
}
|
||||||
let dest_pile = &ev.to;
|
let dest_pile = &ev.to;
|
||||||
// Collect the card ids that belong to the destination pile.
|
// Collect the card ids that belong to the destination pile.
|
||||||
let dest_cards = pile_cards(&game.0, dest_pile);
|
let Some(pile) = game.0.piles.get(dest_pile) else {
|
||||||
let dest_card_ids: Vec<u32> = dest_cards.iter().map(|c| c.id).collect();
|
continue;
|
||||||
|
};
|
||||||
|
let dest_card_ids: Vec<u32> = pile.cards.iter().map(|c| c.id).collect();
|
||||||
|
|
||||||
if dest_card_ids.is_empty() {
|
if dest_card_ids.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
@@ -317,19 +317,19 @@ fn start_settle_anim(
|
|||||||
let mut bounce_ids: Vec<u32> = Vec::new();
|
let mut bounce_ids: Vec<u32> = Vec::new();
|
||||||
|
|
||||||
for ev in moves.read() {
|
for ev in moves.read() {
|
||||||
let pile = pile_cards(&game.0, &ev.to);
|
if let Some(pile) = game.0.piles.get(&ev.to) {
|
||||||
if !pile.is_empty() {
|
|
||||||
// The moved cards land on top — take the last `count` ids.
|
// The moved cards land on top — take the last `count` ids.
|
||||||
let n = ev.count.min(pile.len());
|
let n = ev.count.min(pile.cards.len());
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
let start = pile.len() - n;
|
let start = pile.cards.len() - n;
|
||||||
bounce_ids.extend(pile[start..].iter().map(|c| c.id));
|
bounce_ids.extend(pile.cards[start..].iter().map(|c| c.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if draws.read().next().is_some()
|
if draws.read().next().is_some()
|
||||||
&& let Some(top) = game.0.waste_cards().last()
|
&& let Some(pile) = game.0.piles.get(&PileType::Waste)
|
||||||
|
&& let Some(top) = pile.cards.last()
|
||||||
{
|
{
|
||||||
bounce_ids.push(top.id);
|
bounce_ids.push(top.id);
|
||||||
}
|
}
|
||||||
@@ -397,7 +397,7 @@ fn start_deal_anim(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(layout) = layout else { return };
|
let Some(layout) = layout else { return };
|
||||||
let Some(&stock_pos) = layout.0.pile_positions.get(&KlondikePile::Stock) else {
|
let Some(&stock_pos) = layout.0.pile_positions.get(&PileType::Stock) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let stock_start = Vec3::new(stock_pos.x, stock_pos.y, 0.0);
|
let stock_start = Vec3::new(stock_pos.x, stock_pos.y, 0.0);
|
||||||
@@ -518,13 +518,15 @@ fn start_foundation_flourish(
|
|||||||
if reduce_motion {
|
if reduce_motion {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let Some(foundation) = foundation_from_slot(ev.slot) else {
|
let pile_type = PileType::Foundation(ev.slot);
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let pile_type = KlondikePile::Foundation(foundation);
|
|
||||||
// Top card of the completed foundation is the King.
|
// Top card of the completed foundation is the King.
|
||||||
let cards = game.0.pile(pile_type);
|
let Some(king_id) = game
|
||||||
let Some(king_id) = cards.last().map(|c| c.id) else {
|
.0
|
||||||
|
.piles
|
||||||
|
.get(&pile_type)
|
||||||
|
.and_then(|p| p.cards.last())
|
||||||
|
.map(|c| c.id)
|
||||||
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -630,26 +632,6 @@ fn lerp_color(from: Color, to: Color, t: f32) -> Color {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pile_cards(
|
|
||||||
game: &solitaire_core::game_state::GameState,
|
|
||||||
pile: &KlondikePile,
|
|
||||||
) -> Vec<solitaire_core::card::Card> {
|
|
||||||
match pile {
|
|
||||||
KlondikePile::Stock => game.waste_cards(),
|
|
||||||
_ => game.pile(*pile),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn foundation_from_slot(slot: u8) -> Option<Foundation> {
|
|
||||||
match slot {
|
|
||||||
0 => Some(Foundation::Foundation1),
|
|
||||||
1 => Some(Foundation::Foundation2),
|
|
||||||
2 => Some(Foundation::Foundation3),
|
|
||||||
3 => Some(Foundation::Foundation4),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Unit tests (pure functions only — no Bevy world required)
|
// Unit tests (pure functions only — no Bevy world required)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -849,7 +831,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn shake_anim_skipped_under_reduce_motion() {
|
fn shake_anim_skipped_under_reduce_motion() {
|
||||||
use bevy::ecs::message::Messages;
|
use bevy::ecs::message::Messages;
|
||||||
use klondike::Tableau;
|
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
use solitaire_data::Settings;
|
use solitaire_data::Settings;
|
||||||
|
|
||||||
@@ -864,13 +845,14 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
// Pick a card from Tableau(0) so the event refers to a real pile.
|
// Pick a card from Tableau(0) so the event refers to a real pile.
|
||||||
let dest_pile = KlondikePile::Tableau(Tableau::Tableau1);
|
let dest_pile = PileType::Tableau(0);
|
||||||
let card_id = app
|
let card_id = app
|
||||||
.world()
|
.world()
|
||||||
.resource::<GameStateResource>()
|
.resource::<GameStateResource>()
|
||||||
.0
|
.0
|
||||||
.pile(dest_pile)
|
.piles
|
||||||
.last()
|
.get(&dest_pile)
|
||||||
|
.and_then(|p| p.cards.last())
|
||||||
.map(|c| c.id)
|
.map(|c| c.id)
|
||||||
.expect("Tableau(0) should have at least one card in a fresh game");
|
.expect("Tableau(0) should have at least one card in a fresh game");
|
||||||
|
|
||||||
@@ -882,7 +864,7 @@ mod tests {
|
|||||||
app.world_mut()
|
app.world_mut()
|
||||||
.resource_mut::<Messages<MoveRejectedEvent>>()
|
.resource_mut::<Messages<MoveRejectedEvent>>()
|
||||||
.write(MoveRejectedEvent {
|
.write(MoveRejectedEvent {
|
||||||
from: KlondikePile::Stock,
|
from: PileType::Stock,
|
||||||
to: dest_pile,
|
to: dest_pile,
|
||||||
count: 1,
|
count: 1,
|
||||||
});
|
});
|
||||||
|
|||||||
+735
-310
File diff suppressed because it is too large
Load Diff
@@ -8,19 +8,12 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::WindowResized;
|
use bevy::window::WindowResized;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::Suit;
|
use solitaire_core::card::Suit;
|
||||||
use solitaire_core::game_state::{DrawMode, GameMode};
|
use solitaire_core::game_state::{DrawMode, GameMode};
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
use crate::auto_complete_plugin::AutoCompleteState;
|
use crate::auto_complete_plugin::AutoCompleteState;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::avatar_plugin::AvatarResource;
|
use crate::avatar_plugin::AvatarResource;
|
||||||
// On wasm32 AvatarPlugin is gated out; define a placeholder type so the
|
|
||||||
// Option<Res<AvatarResource>> parameters below compile without changes.
|
|
||||||
// The resource is never inserted on wasm, so every call resolves to None.
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
#[derive(bevy::prelude::Resource)]
|
|
||||||
struct AvatarResource(Option<bevy::prelude::Handle<bevy::prelude::Image>>);
|
|
||||||
use crate::challenge_plugin::CHALLENGE_UNLOCK_LEVEL;
|
use crate::challenge_plugin::CHALLENGE_UNLOCK_LEVEL;
|
||||||
use crate::daily_challenge_plugin::DailyChallengeResource;
|
use crate::daily_challenge_plugin::DailyChallengeResource;
|
||||||
use crate::events::{
|
use crate::events::{
|
||||||
@@ -2323,7 +2316,7 @@ fn update_hud(
|
|||||||
// Hide when not in Draw-Three or after the game is won.
|
// Hide when not in Draw-Three or after the game is won.
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
let stock_len = g.stock_cards().len();
|
let stock_len = g.piles[&solitaire_core::pile::PileType::Stock].cards.len();
|
||||||
let next_draw = stock_len.min(3);
|
let next_draw = stock_len.min(3);
|
||||||
format!("Cycle: {next_draw}/3")
|
format!("Cycle: {next_draw}/3")
|
||||||
};
|
};
|
||||||
@@ -2387,14 +2380,15 @@ fn update_selection_hud(
|
|||||||
let Ok(mut t) = q.single_mut() else { return };
|
let Ok(mut t) = q.single_mut() else { return };
|
||||||
let label = match selection.as_deref().and_then(|s| s.selected_pile.as_ref()) {
|
let label = match selection.as_deref().and_then(|s| s.selected_pile.as_ref()) {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
Some(KlondikePile::Stock) => "▶ Waste".to_string(),
|
Some(PileType::Waste) => "▶ Waste".to_string(),
|
||||||
Some(KlondikePile::Foundation(slot)) => match game.as_deref() {
|
Some(PileType::Stock) => "▶ Stock".to_string(),
|
||||||
|
Some(PileType::Foundation(slot)) => match game.as_deref() {
|
||||||
Some(g) => foundation_selection_label(*slot, &g.0),
|
Some(g) => foundation_selection_label(*slot, &g.0),
|
||||||
// No game resource means we can't probe claimed_suit; show the
|
// No game resource means we can't probe claimed_suit; show the
|
||||||
// slot-based placeholder so the HUD still surfaces the selection.
|
// slot-based placeholder so the HUD still surfaces the selection.
|
||||||
None => format!("▶ Foundation {}", foundation_number(*slot)),
|
None => format!("▶ Foundation {}", slot + 1),
|
||||||
},
|
},
|
||||||
Some(KlondikePile::Tableau(idx)) => format!("▶ Column {}", tableau_number(*idx)),
|
Some(PileType::Tableau(idx)) => format!("▶ Column {}", idx + 1),
|
||||||
};
|
};
|
||||||
**t = label;
|
**t = label;
|
||||||
}
|
}
|
||||||
@@ -2404,14 +2398,11 @@ fn update_selection_hud(
|
|||||||
/// When the slot has a claimed suit (any card has landed) the announcement is
|
/// When the slot has a claimed suit (any card has landed) the announcement is
|
||||||
/// "▶ {Suit} Foundation"; while the slot is empty it falls back to a
|
/// "▶ {Suit} Foundation"; while the slot is empty it falls back to a
|
||||||
/// "▶ Foundation N" placeholder labelled by the 1-based slot index.
|
/// "▶ Foundation N" placeholder labelled by the 1-based slot index.
|
||||||
fn foundation_selection_label(
|
fn foundation_selection_label(slot: u8, game: &solitaire_core::game_state::GameState) -> String {
|
||||||
slot: Foundation,
|
|
||||||
game: &solitaire_core::game_state::GameState,
|
|
||||||
) -> String {
|
|
||||||
let claimed = game
|
let claimed = game
|
||||||
.pile(KlondikePile::Foundation(slot))
|
.piles
|
||||||
.first()
|
.get(&PileType::Foundation(slot))
|
||||||
.map(|c| c.suit);
|
.and_then(|p| p.claimed_suit());
|
||||||
match claimed {
|
match claimed {
|
||||||
Some(suit) => {
|
Some(suit) => {
|
||||||
let s = match suit {
|
let s = match suit {
|
||||||
@@ -2422,28 +2413,7 @@ fn foundation_selection_label(
|
|||||||
};
|
};
|
||||||
format!("▶ {s} Foundation")
|
format!("▶ {s} Foundation")
|
||||||
}
|
}
|
||||||
None => format!("▶ Foundation {}", foundation_number(slot)),
|
None => format!("▶ Foundation {}", slot + 1),
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn foundation_number(foundation: Foundation) -> u8 {
|
|
||||||
match foundation {
|
|
||||||
Foundation::Foundation1 => 1,
|
|
||||||
Foundation::Foundation2 => 2,
|
|
||||||
Foundation::Foundation3 => 3,
|
|
||||||
Foundation::Foundation4 => 4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn tableau_number(tableau: Tableau) -> u8 {
|
|
||||||
match tableau {
|
|
||||||
Tableau::Tableau1 => 1,
|
|
||||||
Tableau::Tableau2 => 2,
|
|
||||||
Tableau::Tableau3 => 3,
|
|
||||||
Tableau::Tableau4 => 4,
|
|
||||||
Tableau::Tableau5 => 5,
|
|
||||||
Tableau::Tableau6 => 6,
|
|
||||||
Tableau::Tableau7 => 7,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+52
-107
@@ -7,7 +7,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use bevy::math::Vec2;
|
use bevy::math::Vec2;
|
||||||
use bevy::prelude::{Resource, SystemSet};
|
use bevy::prelude::{Resource, SystemSet};
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
/// Schedule labels for layout-related systems so cross-plugin ordering is
|
/// Schedule labels for layout-related systems so cross-plugin ordering is
|
||||||
/// explicit instead of relying on Bevy's automatic resource-conflict ordering
|
/// explicit instead of relying on Bevy's automatic resource-conflict ordering
|
||||||
@@ -138,9 +138,9 @@ pub struct Layout {
|
|||||||
/// Centre position of each pile, in 2D world coordinates.
|
/// Centre position of each pile, in 2D world coordinates.
|
||||||
///
|
///
|
||||||
/// World origin `(0, 0)` is the window centre; `+x` is right, `+y` is up.
|
/// World origin `(0, 0)` is the window centre; `+x` is right, `+y` is up.
|
||||||
/// Every `KlondikePile` (Stock, Waste, four Foundations, seven Tableaux) has an
|
/// Every `PileType` (Stock, Waste, four Foundations, seven Tableaux) has an
|
||||||
/// entry. The map always contains exactly 13 entries after `compute_layout`.
|
/// entry. The map always contains exactly 13 entries after `compute_layout`.
|
||||||
pub pile_positions: HashMap<KlondikePile, Vec2>,
|
pub pile_positions: HashMap<PileType, Vec2>,
|
||||||
/// Per-step vertical offset fraction for face-up tableau cards, as a
|
/// Per-step vertical offset fraction for face-up tableau cards, as a
|
||||||
/// fraction of `card_size.y`. On height-limited (desktop) windows this
|
/// fraction of `card_size.y`. On height-limited (desktop) windows this
|
||||||
/// equals `TABLEAU_FAN_FRAC` (0.18); on width-limited (portrait phone)
|
/// equals `TABLEAU_FAN_FRAC` (0.18); on width-limited (portrait phone)
|
||||||
@@ -241,38 +241,21 @@ pub fn compute_layout(
|
|||||||
let top_y = window.y / 2.0 - safe_area_top - band_h - h_gap - card_height / 2.0;
|
let top_y = window.y / 2.0 - safe_area_top - band_h - h_gap - card_height / 2.0;
|
||||||
let tableau_y = top_y - card_height - vertical_gap;
|
let tableau_y = top_y - card_height - vertical_gap;
|
||||||
|
|
||||||
let mut pile_positions: HashMap<KlondikePile, Vec2> = HashMap::with_capacity(13);
|
let mut pile_positions: HashMap<PileType, Vec2> = HashMap::with_capacity(13);
|
||||||
|
|
||||||
pile_positions.insert(KlondikePile::Stock, Vec2::new(col_x(1), top_y));
|
pile_positions.insert(PileType::Stock, Vec2::new(col_x(0), top_y));
|
||||||
|
pile_positions.insert(PileType::Waste, Vec2::new(col_x(1), top_y));
|
||||||
|
|
||||||
// Column 2 is skipped — visual separation between waste and foundations.
|
// Column 2 is skipped — visual separation between waste and foundations.
|
||||||
for slot in 0..4_u8 {
|
for slot in 0..4_u8 {
|
||||||
let foundation = match slot {
|
|
||||||
0 => Foundation::Foundation1,
|
|
||||||
1 => Foundation::Foundation2,
|
|
||||||
2 => Foundation::Foundation3,
|
|
||||||
_ => Foundation::Foundation4,
|
|
||||||
};
|
|
||||||
pile_positions.insert(
|
pile_positions.insert(
|
||||||
KlondikePile::Foundation(foundation),
|
PileType::Foundation(slot),
|
||||||
Vec2::new(col_x(3 + slot as usize), top_y),
|
Vec2::new(col_x(3 + slot as usize), top_y),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..7 {
|
for i in 0..7 {
|
||||||
let tableau = match i {
|
pile_positions.insert(PileType::Tableau(i), Vec2::new(col_x(i), tableau_y));
|
||||||
0 => Tableau::Tableau1,
|
|
||||||
1 => Tableau::Tableau2,
|
|
||||||
2 => Tableau::Tableau3,
|
|
||||||
3 => Tableau::Tableau4,
|
|
||||||
4 => Tableau::Tableau5,
|
|
||||||
5 => Tableau::Tableau6,
|
|
||||||
_ => Tableau::Tableau7,
|
|
||||||
};
|
|
||||||
pile_positions.insert(
|
|
||||||
KlondikePile::Tableau(tableau),
|
|
||||||
Vec2::new(col_x(i), tableau_y),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adaptive tableau fan fraction. On height-limited (desktop) windows the
|
// Adaptive tableau fan fraction. On height-limited (desktop) windows the
|
||||||
@@ -318,37 +301,23 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn assert_all_piles_present(layout: &Layout) {
|
fn assert_all_piles_present(layout: &Layout) {
|
||||||
assert!(layout.pile_positions.contains_key(&KlondikePile::Stock));
|
assert!(layout.pile_positions.contains_key(&PileType::Stock));
|
||||||
for foundation in [
|
assert!(layout.pile_positions.contains_key(&PileType::Waste));
|
||||||
Foundation::Foundation1,
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
] {
|
|
||||||
assert!(
|
assert!(
|
||||||
layout
|
layout
|
||||||
.pile_positions
|
.pile_positions
|
||||||
.contains_key(&KlondikePile::Foundation(foundation)),
|
.contains_key(&PileType::Foundation(slot)),
|
||||||
"missing foundation slot {foundation:?}",
|
"missing foundation slot {slot}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7 {
|
||||||
Tableau::Tableau1,
|
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
assert!(
|
assert!(
|
||||||
layout
|
layout.pile_positions.contains_key(&PileType::Tableau(i)),
|
||||||
.pile_positions
|
"missing tableau {i}"
|
||||||
.contains_key(&KlondikePile::Tableau(tableau)),
|
|
||||||
"missing tableau {tableau:?}"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
assert_eq!(layout.pile_positions.len(), 12);
|
assert_eq!(layout.pile_positions.len(), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -407,18 +376,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn tableau_columns_are_sorted_left_to_right() {
|
fn tableau_columns_are_sorted_left_to_right() {
|
||||||
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let tableaus = [
|
for i in 0..6 {
|
||||||
Tableau::Tableau1,
|
let lhs = layout.pile_positions[&PileType::Tableau(i)].x;
|
||||||
Tableau::Tableau2,
|
let rhs = layout.pile_positions[&PileType::Tableau(i + 1)].x;
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
];
|
|
||||||
for i in 0..tableaus.len() - 1 {
|
|
||||||
let lhs = layout.pile_positions[&KlondikePile::Tableau(tableaus[i])].x;
|
|
||||||
let rhs = layout.pile_positions[&KlondikePile::Tableau(tableaus[i + 1])].x;
|
|
||||||
assert!(lhs < rhs, "tableau {i} should be left of tableau {}", i + 1);
|
assert!(lhs < rhs, "tableau {i} should be left of tableau {}", i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,8 +386,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn top_row_is_above_tableau_row() {
|
fn top_row_is_above_tableau_row() {
|
||||||
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let stock_y = layout.pile_positions[&KlondikePile::Stock].y;
|
let stock_y = layout.pile_positions[&PileType::Stock].y;
|
||||||
let tableau_y = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)].y;
|
let tableau_y = layout.pile_positions[&PileType::Tableau(0)].y;
|
||||||
assert!(stock_y > tableau_y);
|
assert!(stock_y > tableau_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +399,7 @@ mod tests {
|
|||||||
fn top_row_clears_hud_band() {
|
fn top_row_clears_hud_band() {
|
||||||
let window = Vec2::new(1280.0, 800.0);
|
let window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(window, 0.0, 0.0, true);
|
let layout = compute_layout(window, 0.0, 0.0, true);
|
||||||
let stock_y = layout.pile_positions[&KlondikePile::Stock].y;
|
let stock_y = layout.pile_positions[&PileType::Stock].y;
|
||||||
let card_top = stock_y + layout.card_size.y / 2.0;
|
let card_top = stock_y + layout.card_size.y / 2.0;
|
||||||
let band_bottom = window.y / 2.0 - HUD_BAND_HEIGHT;
|
let band_bottom = window.y / 2.0 - HUD_BAND_HEIGHT;
|
||||||
assert!(
|
assert!(
|
||||||
@@ -451,35 +411,24 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn stock_aligns_with_tableau_col_0_and_waste_with_col_1() {
|
fn stock_aligns_with_tableau_col_0_and_waste_with_col_1() {
|
||||||
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let stock_x = layout.pile_positions[&KlondikePile::Stock].x;
|
let stock_x = layout.pile_positions[&PileType::Stock].x;
|
||||||
let t1_x = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau2)].x;
|
let waste_x = layout.pile_positions[&PileType::Waste].x;
|
||||||
assert!((stock_x - t1_x).abs() < 1e-5);
|
let t0_x = layout.pile_positions[&PileType::Tableau(0)].x;
|
||||||
|
let t1_x = layout.pile_positions[&PileType::Tableau(1)].x;
|
||||||
|
assert!((stock_x - t0_x).abs() < 1e-5);
|
||||||
|
assert!((waste_x - t1_x).abs() < 1e-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn foundations_align_with_tableau_cols_3_to_6() {
|
fn foundations_align_with_tableau_cols_3_to_6() {
|
||||||
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
let layout = compute_layout(Vec2::new(1280.0, 800.0), 0.0, 0.0, true);
|
||||||
let target_tableaus = [
|
for slot in 0..4_u8 {
|
||||||
Tableau::Tableau4,
|
let f_x = layout.pile_positions[&PileType::Foundation(slot)].x;
|
||||||
Tableau::Tableau5,
|
let t_x = layout.pile_positions[&PileType::Tableau(3 + slot as usize)].x;
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
];
|
|
||||||
for (idx, foundation) in [
|
|
||||||
Foundation::Foundation1,
|
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
{
|
|
||||||
let f_x = layout.pile_positions[&KlondikePile::Foundation(*foundation)].x;
|
|
||||||
let t_x = layout.pile_positions[&KlondikePile::Tableau(target_tableaus[idx])].x;
|
|
||||||
assert!(
|
assert!(
|
||||||
(f_x - t_x).abs() < 1e-5,
|
(f_x - t_x).abs() < 1e-5,
|
||||||
"foundation slot {idx} should align with tableau {}",
|
"foundation slot {slot} should align with tableau {}",
|
||||||
3 + idx,
|
3 + slot as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -521,7 +470,7 @@ mod tests {
|
|||||||
// Default app resolution (see solitaire_app/src/main.rs).
|
// Default app resolution (see solitaire_app/src/main.rs).
|
||||||
let window = Vec2::new(1280.0, 800.0);
|
let window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(window, 0.0, 0.0, true);
|
let layout = compute_layout(window, 0.0, 0.0, true);
|
||||||
let tableau_y = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau7)].y;
|
let tableau_y = layout.pile_positions[&PileType::Tableau(6)].y;
|
||||||
let card_h = layout.card_size.y;
|
let card_h = layout.card_size.y;
|
||||||
// Bottom edge of the 13th fanned face-up card.
|
// Bottom edge of the 13th fanned face-up card.
|
||||||
let bottom_edge = tableau_y - 12.0 * card_h * TABLEAU_FAN_FRAC - card_h / 2.0;
|
let bottom_edge = tableau_y - 12.0 * card_h * TABLEAU_FAN_FRAC - card_h / 2.0;
|
||||||
@@ -540,7 +489,7 @@ mod tests {
|
|||||||
// The bug originally reproduced at 1920x1080. Lock in a regression test.
|
// The bug originally reproduced at 1920x1080. Lock in a regression test.
|
||||||
let window = Vec2::new(1920.0, 1080.0);
|
let window = Vec2::new(1920.0, 1080.0);
|
||||||
let layout = compute_layout(window, 0.0, 0.0, true);
|
let layout = compute_layout(window, 0.0, 0.0, true);
|
||||||
let tableau_y = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau7)].y;
|
let tableau_y = layout.pile_positions[&PileType::Tableau(6)].y;
|
||||||
let card_h = layout.card_size.y;
|
let card_h = layout.card_size.y;
|
||||||
let bottom_edge = tableau_y - 12.0 * card_h * TABLEAU_FAN_FRAC - card_h / 2.0;
|
let bottom_edge = tableau_y - 12.0 * card_h * TABLEAU_FAN_FRAC - card_h / 2.0;
|
||||||
let h_gap = layout.card_size.x / 4.0;
|
let h_gap = layout.card_size.x / 4.0;
|
||||||
@@ -571,7 +520,7 @@ mod tests {
|
|||||||
fn expanded_fan_fits_phone_viewport() {
|
fn expanded_fan_fits_phone_viewport() {
|
||||||
let window = Vec2::new(360.0, 800.0);
|
let window = Vec2::new(360.0, 800.0);
|
||||||
let layout = compute_layout(window, 0.0, 0.0, true);
|
let layout = compute_layout(window, 0.0, 0.0, true);
|
||||||
let tableau_y = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)].y;
|
let tableau_y = layout.pile_positions[&PileType::Tableau(0)].y;
|
||||||
let card_h = layout.card_size.y;
|
let card_h = layout.card_size.y;
|
||||||
let h_gap = layout.card_size.x / 4.0;
|
let h_gap = layout.card_size.x / 4.0;
|
||||||
// Bottom of the 13th (worst-case) fanned face-up card.
|
// Bottom of the 13th (worst-case) fanned face-up card.
|
||||||
@@ -630,8 +579,8 @@ mod tests {
|
|||||||
let window = Vec2::new(360.0, 800.0);
|
let window = Vec2::new(360.0, 800.0);
|
||||||
let without = compute_layout(window, 0.0, 0.0, true);
|
let without = compute_layout(window, 0.0, 0.0, true);
|
||||||
let with_inset = compute_layout(window, 32.0, 0.0, true);
|
let with_inset = compute_layout(window, 32.0, 0.0, true);
|
||||||
let stock_no_inset = without.pile_positions[&KlondikePile::Stock].y;
|
let stock_no_inset = without.pile_positions[&PileType::Stock].y;
|
||||||
let stock_with_inset = with_inset.pile_positions[&KlondikePile::Stock].y;
|
let stock_with_inset = with_inset.pile_positions[&PileType::Stock].y;
|
||||||
assert!(
|
assert!(
|
||||||
stock_with_inset < stock_no_inset,
|
stock_with_inset < stock_no_inset,
|
||||||
"safe_area_top=32 must shift stock pile down (y decreased): {} → {}",
|
"safe_area_top=32 must shift stock pile down (y decreased): {} → {}",
|
||||||
@@ -653,10 +602,10 @@ mod tests {
|
|||||||
let without = compute_layout(window, 0.0, 0.0, true);
|
let without = compute_layout(window, 0.0, 0.0, true);
|
||||||
let with_inset = compute_layout(window, 32.0, 0.0, true);
|
let with_inset = compute_layout(window, 32.0, 0.0, true);
|
||||||
for pile in [
|
for pile in [
|
||||||
KlondikePile::Stock,
|
PileType::Stock,
|
||||||
KlondikePile::Stock,
|
PileType::Waste,
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
PileType::Tableau(0),
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
PileType::Tableau(6),
|
||||||
] {
|
] {
|
||||||
assert!(
|
assert!(
|
||||||
(without.pile_positions[&pile].x - with_inset.pile_positions[&pile].x).abs() < 1e-3,
|
(without.pile_positions[&pile].x - with_inset.pile_positions[&pile].x).abs() < 1e-3,
|
||||||
@@ -679,7 +628,7 @@ mod tests {
|
|||||||
with_inset.tableau_fan_frac,
|
with_inset.tableau_fan_frac,
|
||||||
);
|
);
|
||||||
let card_h = with_inset.card_size.y;
|
let card_h = with_inset.card_size.y;
|
||||||
let tableau_y = with_inset.pile_positions[&KlondikePile::Tableau(Tableau::Tableau7)].y;
|
let tableau_y = with_inset.pile_positions[&PileType::Tableau(6)].y;
|
||||||
let bottom_edge = tableau_y - 12.0 * card_h * with_inset.tableau_fan_frac - card_h / 2.0;
|
let bottom_edge = tableau_y - 12.0 * card_h * with_inset.tableau_fan_frac - card_h / 2.0;
|
||||||
let h_gap = with_inset.card_size.x / 4.0;
|
let h_gap = with_inset.card_size.x / 4.0;
|
||||||
let margin = -window.y / 2.0 + 48.0 + h_gap;
|
let margin = -window.y / 2.0 + 48.0 + h_gap;
|
||||||
@@ -712,8 +661,8 @@ mod tests {
|
|||||||
|
|
||||||
// Verify the "wrong" layout actually differs — the bug would push the
|
// Verify the "wrong" layout actually differs — the bug would push the
|
||||||
// top card row upward by exactly safe_top pixels.
|
// top card row upward by exactly safe_top pixels.
|
||||||
let fresh_stock_y = fresh.pile_positions[&KlondikePile::Stock].y;
|
let fresh_stock_y = fresh.pile_positions[&PileType::Stock].y;
|
||||||
let wrong_stock_y = wrong.pile_positions[&KlondikePile::Stock].y;
|
let wrong_stock_y = wrong.pile_positions[&PileType::Stock].y;
|
||||||
// In Bevy's +y-is-up system, adding safe_area_top pushes the stock
|
// In Bevy's +y-is-up system, adding safe_area_top pushes the stock
|
||||||
// downward (−y direction). So wrong_stock_y > fresh_stock_y by safe_top.
|
// downward (−y direction). So wrong_stock_y > fresh_stock_y by safe_top.
|
||||||
assert!(
|
assert!(
|
||||||
@@ -731,14 +680,14 @@ mod tests {
|
|||||||
"card size must be preserved after resume",
|
"card size must be preserved after resume",
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
(corrected.pile_positions[&KlondikePile::Stock].y - fresh_stock_y).abs() < 1e-3,
|
(corrected.pile_positions[&PileType::Stock].y - fresh_stock_y).abs() < 1e-3,
|
||||||
"stock y must match fresh launch after resume: \
|
"stock y must match fresh launch after resume: \
|
||||||
corrected={:.2} fresh={fresh_stock_y:.2}",
|
corrected={:.2} fresh={fresh_stock_y:.2}",
|
||||||
corrected.pile_positions[&KlondikePile::Stock].y,
|
corrected.pile_positions[&PileType::Stock].y,
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
(corrected.pile_positions[&KlondikePile::Stock].x
|
(corrected.pile_positions[&PileType::Stock].x
|
||||||
- fresh.pile_positions[&KlondikePile::Stock].x)
|
- fresh.pile_positions[&PileType::Stock].x)
|
||||||
.abs()
|
.abs()
|
||||||
< 1e-3,
|
< 1e-3,
|
||||||
"stock x must be unchanged after resume",
|
"stock x must be unchanged after resume",
|
||||||
@@ -746,7 +695,7 @@ mod tests {
|
|||||||
// The HUD band top clearance (distance from window top to card top)
|
// The HUD band top clearance (distance from window top to card top)
|
||||||
// must match as well — this is the quantity directly visible in Bug 2.
|
// must match as well — this is the quantity directly visible in Bug 2.
|
||||||
let card_top = |layout: &super::Layout| {
|
let card_top = |layout: &super::Layout| {
|
||||||
layout.pile_positions[&KlondikePile::Stock].y + layout.card_size.y / 2.0
|
layout.pile_positions[&PileType::Stock].y + layout.card_size.y / 2.0
|
||||||
};
|
};
|
||||||
assert!(
|
assert!(
|
||||||
(card_top(&corrected) - card_top(&fresh)).abs() < 1e-3,
|
(card_top(&corrected) - card_top(&fresh)).abs() < 1e-3,
|
||||||
@@ -763,11 +712,7 @@ mod tests {
|
|||||||
let window = Vec2::new(360.0, 800.0);
|
let window = Vec2::new(360.0, 800.0);
|
||||||
let without = compute_layout(window, 0.0, 0.0, true);
|
let without = compute_layout(window, 0.0, 0.0, true);
|
||||||
let with_inset = compute_layout(window, 0.0, 48.0, true);
|
let with_inset = compute_layout(window, 0.0, 48.0, true);
|
||||||
for pile in [
|
for pile in [PileType::Stock, PileType::Tableau(0), PileType::Tableau(6)] {
|
||||||
KlondikePile::Stock,
|
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
|
||||||
] {
|
|
||||||
assert!(
|
assert!(
|
||||||
(without.pile_positions[&pile].x - with_inset.pile_positions[&pile].x).abs() < 1e-3,
|
(without.pile_positions[&pile].x - with_inset.pile_positions[&pile].x).abs() < 1e-3,
|
||||||
"{pile:?} x-position must not change with safe_area_bottom",
|
"{pile:?} x-position must not change with safe_area_bottom",
|
||||||
|
|||||||
@@ -191,7 +191,6 @@ fn toggle_leaderboard_screen(
|
|||||||
keys: Res<ButtonInput<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
mut requests: MessageReader<ToggleLeaderboardRequestEvent>,
|
mut requests: MessageReader<ToggleLeaderboardRequestEvent>,
|
||||||
screens: Query<Entity, With<LeaderboardScreen>>,
|
screens: Query<Entity, With<LeaderboardScreen>>,
|
||||||
other_modal_scrims: Query<(), (With<ModalScrim>, Without<LeaderboardScreen>)>,
|
|
||||||
data: Res<LeaderboardResource>,
|
data: Res<LeaderboardResource>,
|
||||||
provider: Option<Res<SyncProviderResource>>,
|
provider: Option<Res<SyncProviderResource>>,
|
||||||
settings: Option<Res<SettingsResource>>,
|
settings: Option<Res<SettingsResource>>,
|
||||||
@@ -209,11 +208,6 @@ fn toggle_leaderboard_screen(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't stack a second modal scrim over one that is already open.
|
|
||||||
if !other_modal_scrims.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn the panel immediately with whatever data we have so far.
|
// Spawn the panel immediately with whatever data we have so far.
|
||||||
let remote_available = provider
|
let remote_available = provider
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
//! Bevy integration layer for Ferrous Solitaire.
|
//! Bevy integration layer for Ferrous Solitaire.
|
||||||
|
|
||||||
pub mod achievement_plugin;
|
pub mod achievement_plugin;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod analytics_plugin;
|
pub mod analytics_plugin;
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub mod android_clipboard;
|
pub mod android_clipboard;
|
||||||
pub mod animation_plugin;
|
pub mod animation_plugin;
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod audio_plugin;
|
pub mod audio_plugin;
|
||||||
pub mod auto_complete_plugin;
|
pub mod auto_complete_plugin;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod avatar_plugin;
|
pub mod avatar_plugin;
|
||||||
pub mod card_animation;
|
pub mod card_animation;
|
||||||
pub mod card_plugin;
|
pub mod card_plugin;
|
||||||
@@ -29,7 +26,6 @@ pub mod home_plugin;
|
|||||||
pub mod hud_plugin;
|
pub mod hud_plugin;
|
||||||
pub mod input_plugin;
|
pub mod input_plugin;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod leaderboard_plugin;
|
pub mod leaderboard_plugin;
|
||||||
pub mod onboarding_plugin;
|
pub mod onboarding_plugin;
|
||||||
pub mod pause_plugin;
|
pub mod pause_plugin;
|
||||||
@@ -47,9 +43,7 @@ pub mod selection_plugin;
|
|||||||
pub mod settings_plugin;
|
pub mod settings_plugin;
|
||||||
pub mod splash_plugin;
|
pub mod splash_plugin;
|
||||||
pub mod stats_plugin;
|
pub mod stats_plugin;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod sync_plugin;
|
pub mod sync_plugin;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod sync_setup_plugin;
|
pub mod sync_setup_plugin;
|
||||||
pub mod table_plugin;
|
pub mod table_plugin;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
@@ -63,17 +57,14 @@ pub mod weekly_goals_plugin;
|
|||||||
pub mod win_summary_plugin;
|
pub mod win_summary_plugin;
|
||||||
|
|
||||||
pub use achievement_plugin::{AchievementPlugin, AchievementsResource, AchievementsScreen};
|
pub use achievement_plugin::{AchievementPlugin, AchievementsResource, AchievementsScreen};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use analytics_plugin::{AnalyticsPlugin, AnalyticsResource};
|
pub use analytics_plugin::{AnalyticsPlugin, AnalyticsResource};
|
||||||
pub use animation_plugin::{ActiveToast, AnimationPlugin, CardAnim, ToastEntity, ToastQueue};
|
pub use animation_plugin::{ActiveToast, AnimationPlugin, CardAnim, ToastEntity, ToastQueue};
|
||||||
pub use assets::{
|
pub use assets::{
|
||||||
AssetSourcesPlugin, DARK_THEME_MANIFEST_URL, USER_THEMES, bundled_theme_url,
|
AssetSourcesPlugin, DARK_THEME_MANIFEST_URL, USER_THEMES, bundled_theme_url,
|
||||||
populate_embedded_dark_theme, register_theme_asset_sources,
|
populate_embedded_dark_theme, register_theme_asset_sources,
|
||||||
};
|
};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use audio_plugin::{AudioPlugin, AudioState, SoundLibrary};
|
pub use audio_plugin::{AudioPlugin, AudioState, SoundLibrary};
|
||||||
pub use auto_complete_plugin::AutoCompletePlugin;
|
pub use auto_complete_plugin::AutoCompletePlugin;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use avatar_plugin::{AvatarFetchEvent, AvatarPlugin, AvatarResource};
|
pub use avatar_plugin::{AvatarFetchEvent, AvatarPlugin, AvatarResource};
|
||||||
pub use card_animation::{
|
pub use card_animation::{
|
||||||
AnimationChain, AnimationTuning, BufferedInput, CardAnimation, CardAnimationPlugin,
|
AnimationChain, AnimationTuning, BufferedInput, CardAnimation, CardAnimationPlugin,
|
||||||
@@ -126,7 +117,6 @@ pub use hud_plugin::{
|
|||||||
};
|
};
|
||||||
pub use input_plugin::InputPlugin;
|
pub use input_plugin::InputPlugin;
|
||||||
pub use layout::{Layout, LayoutResource, compute_layout};
|
pub use layout::{Layout, LayoutResource, compute_layout};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use leaderboard_plugin::{LeaderboardPlugin, LeaderboardResource, LeaderboardScreen};
|
pub use leaderboard_plugin::{LeaderboardPlugin, LeaderboardResource, LeaderboardScreen};
|
||||||
pub use onboarding_plugin::{OnboardingPlugin, OnboardingScreen};
|
pub use onboarding_plugin::{OnboardingPlugin, OnboardingScreen};
|
||||||
pub use pause_plugin::{ForfeitConfirmScreen, PausePlugin, PauseScreen, PausedResource};
|
pub use pause_plugin::{ForfeitConfirmScreen, PausePlugin, PauseScreen, PausedResource};
|
||||||
@@ -153,6 +143,7 @@ pub use safe_area::{SafeAreaAnchoredTop, SafeAreaInsets, SafeAreaInsetsPlugin};
|
|||||||
pub use selection_plugin::{
|
pub use selection_plugin::{
|
||||||
KeyboardDragState, SelectionHighlight, SelectionPlugin, SelectionState,
|
KeyboardDragState, SelectionHighlight, SelectionPlugin, SelectionState,
|
||||||
};
|
};
|
||||||
|
pub use touch_selection_plugin::{TouchSelectionPlugin, TouchSelectionState};
|
||||||
pub use settings_plugin::{
|
pub use settings_plugin::{
|
||||||
PendingWindowGeometry, SFX_STEP, SettingsChangedEvent, SettingsPlugin, SettingsResource,
|
PendingWindowGeometry, SFX_STEP, SettingsChangedEvent, SettingsPlugin, SettingsResource,
|
||||||
SettingsScreen, WINDOW_GEOMETRY_DEBOUNCE_SECS,
|
SettingsScreen, WINDOW_GEOMETRY_DEBOUNCE_SECS,
|
||||||
@@ -164,9 +155,7 @@ pub use stats_plugin::{
|
|||||||
ReplaySelectorCaption, SelectedReplayIndex, StatsPlugin, StatsResource, StatsScreen,
|
ReplaySelectorCaption, SelectedReplayIndex, StatsPlugin, StatsResource, StatsScreen,
|
||||||
StatsUpdate, WatchReplayButton, format_replay_caption,
|
StatsUpdate, WatchReplayButton, format_replay_caption,
|
||||||
};
|
};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use sync_plugin::{SyncPlugin, SyncProviderResource};
|
pub use sync_plugin::{SyncPlugin, SyncProviderResource};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use sync_setup_plugin::SyncSetupPlugin;
|
pub use sync_setup_plugin::SyncSetupPlugin;
|
||||||
pub use table_plugin::{
|
pub use table_plugin::{
|
||||||
BackgroundImageSet, HintPileHighlight, PileMarker, TableBackground, TablePlugin,
|
BackgroundImageSet, HintPileHighlight, PileMarker, TableBackground, TablePlugin,
|
||||||
@@ -178,7 +167,6 @@ pub use theme::{
|
|||||||
pub use time_attack_plugin::{
|
pub use time_attack_plugin::{
|
||||||
TIME_ATTACK_DURATION_SECS, TimeAttackEndedEvent, TimeAttackPlugin, TimeAttackResource,
|
TIME_ATTACK_DURATION_SECS, TimeAttackEndedEvent, TimeAttackPlugin, TimeAttackResource,
|
||||||
};
|
};
|
||||||
pub use touch_selection_plugin::{TouchSelectionPlugin, TouchSelectionState};
|
|
||||||
pub use ui_focus::{Disabled, FocusGroup, Focusable, FocusedButton, UiFocusPlugin};
|
pub use ui_focus::{Disabled, FocusGroup, Focusable, FocusedButton, UiFocusPlugin};
|
||||||
pub use ui_modal::{
|
pub use ui_modal::{
|
||||||
ButtonVariant, ModalActions, ModalBody, ModalButton, ModalCard, ModalHeader, ModalScrim,
|
ButtonVariant, ModalActions, ModalBody, ModalButton, ModalCard, ModalHeader, ModalScrim,
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::tasks::{AsyncComputeTaskPool, Task, futures_lite::future};
|
use bevy::tasks::{AsyncComputeTaskPool, Task, futures_lite::future};
|
||||||
use klondike::KlondikePile;
|
|
||||||
use solitaire_core::game_state::GameState;
|
use solitaire_core::game_state::GameState;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
use solitaire_core::solver::{SolverConfig, SolverResult, try_solve_from_state};
|
use solitaire_core::solver::{SolverConfig, SolverResult, try_solve_from_state};
|
||||||
|
|
||||||
use crate::card_plugin::CardEntity;
|
use crate::card_plugin::CardEntity;
|
||||||
@@ -101,10 +101,7 @@ struct HintTask {
|
|||||||
enum HintTaskOutput {
|
enum HintTaskOutput {
|
||||||
/// Solver verdict was `Winnable`; here is the first move on the
|
/// Solver verdict was `Winnable`; here is the first move on the
|
||||||
/// solution path.
|
/// solution path.
|
||||||
SolverMove {
|
SolverMove { from: PileType, to: PileType },
|
||||||
from: KlondikePile,
|
|
||||||
to: KlondikePile,
|
|
||||||
},
|
|
||||||
/// Solver was `Unwinnable` or `Inconclusive`. The poll system
|
/// Solver was `Unwinnable` or `Inconclusive`. The poll system
|
||||||
/// runs the legacy heuristic against the live `GameState` so the
|
/// runs the legacy heuristic against the live `GameState` so the
|
||||||
/// H key always produces feedback while any legal move exists.
|
/// H key always produces feedback while any legal move exists.
|
||||||
@@ -186,7 +183,6 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::events::HintVisualEvent;
|
use crate::events::HintVisualEvent;
|
||||||
use crate::input_plugin::HintSolverConfig;
|
use crate::input_plugin::HintSolverConfig;
|
||||||
use klondike::{Foundation, Tableau};
|
|
||||||
use solitaire_core::card::{Card, Rank, Suit};
|
use solitaire_core::card::{Card, Rank, Suit};
|
||||||
use solitaire_core::game_state::{DrawMode, GameState};
|
use solitaire_core::game_state::{DrawMode, GameState};
|
||||||
|
|
||||||
@@ -218,27 +214,22 @@ mod tests {
|
|||||||
/// tableau columns 0..3, stock and waste empty.
|
/// tableau columns 0..3, stock and waste empty.
|
||||||
fn near_finished_state() -> GameState {
|
fn near_finished_state() -> GameState {
|
||||||
let mut game = GameState::new(1, DrawMode::DrawOne);
|
let mut game = GameState::new(1, DrawMode::DrawOne);
|
||||||
game.set_test_stock_cards(Vec::new());
|
for slot in 0..4_u8 {
|
||||||
game.set_test_waste_cards(Vec::new());
|
game.piles
|
||||||
for foundation in [
|
.get_mut(&PileType::Foundation(slot))
|
||||||
Foundation::Foundation1,
|
.unwrap()
|
||||||
Foundation::Foundation2,
|
.cards
|
||||||
Foundation::Foundation3,
|
.clear();
|
||||||
Foundation::Foundation4,
|
|
||||||
] {
|
|
||||||
game.set_test_foundation_cards(foundation, Vec::new());
|
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7_usize {
|
||||||
Tableau::Tableau1,
|
game.piles
|
||||||
Tableau::Tableau2,
|
.get_mut(&PileType::Tableau(i))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
Tableau::Tableau4,
|
.cards
|
||||||
Tableau::Tableau5,
|
.clear();
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
game.set_test_tableau_cards(tableau, Vec::new());
|
|
||||||
}
|
}
|
||||||
|
game.piles.get_mut(&PileType::Stock).unwrap().cards.clear();
|
||||||
|
game.piles.get_mut(&PileType::Waste).unwrap().cards.clear();
|
||||||
let suits = [Suit::Clubs, Suit::Diamonds, Suit::Hearts, Suit::Spades];
|
let suits = [Suit::Clubs, Suit::Diamonds, Suit::Hearts, Suit::Spades];
|
||||||
let ranks_below_king = [
|
let ranks_below_king = [
|
||||||
Rank::Ace,
|
Rank::Ace,
|
||||||
@@ -254,44 +245,31 @@ mod tests {
|
|||||||
Rank::Jack,
|
Rank::Jack,
|
||||||
Rank::Queen,
|
Rank::Queen,
|
||||||
];
|
];
|
||||||
for (foundation, suit) in [
|
for (slot, suit) in suits.iter().enumerate() {
|
||||||
Foundation::Foundation1,
|
let pile = game
|
||||||
Foundation::Foundation2,
|
.piles
|
||||||
Foundation::Foundation3,
|
.get_mut(&PileType::Foundation(slot as u8))
|
||||||
Foundation::Foundation4,
|
.unwrap();
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.zip(suits.iter())
|
|
||||||
{
|
|
||||||
let mut cards = Vec::new();
|
|
||||||
for (i, rank) in ranks_below_king.iter().enumerate() {
|
for (i, rank) in ranks_below_king.iter().enumerate() {
|
||||||
cards.push(Card {
|
pile.cards.push(Card {
|
||||||
id: (foundation as u32) * 13 + i as u32,
|
id: (slot as u32) * 13 + i as u32,
|
||||||
suit: *suit,
|
suit: *suit,
|
||||||
rank: *rank,
|
rank: *rank,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
game.set_test_foundation_cards(foundation, cards);
|
|
||||||
}
|
}
|
||||||
for (tableau, suit) in [
|
for (col, suit) in suits.iter().enumerate() {
|
||||||
Tableau::Tableau1,
|
game.piles
|
||||||
Tableau::Tableau2,
|
.get_mut(&PileType::Tableau(col))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
Tableau::Tableau4,
|
.cards
|
||||||
]
|
.push(Card {
|
||||||
.into_iter()
|
id: 100 + col as u32,
|
||||||
.zip(suits.iter())
|
|
||||||
{
|
|
||||||
game.set_test_tableau_cards(
|
|
||||||
tableau,
|
|
||||||
vec![Card {
|
|
||||||
id: 100 + tableau as u32,
|
|
||||||
suit: *suit,
|
suit: *suit,
|
||||||
rank: Rank::King,
|
rank: Rank::King,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
game
|
game
|
||||||
}
|
}
|
||||||
@@ -331,7 +309,7 @@ mod tests {
|
|||||||
"exactly one HintVisualEvent must fire when the solver returns Winnable",
|
"exactly one HintVisualEvent must fire when the solver returns Winnable",
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
matches!(collected[0].dest_pile, KlondikePile::Foundation(_)),
|
matches!(collected[0].dest_pile, PileType::Foundation(_)),
|
||||||
"solver hint destination must be a foundation slot; got {:?}",
|
"solver hint destination must be a foundation slot; got {:?}",
|
||||||
collected[0].dest_pile,
|
collected[0].dest_pile,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ use solitaire_core::achievement::{ALL_ACHIEVEMENTS, achievement_by_id};
|
|||||||
use solitaire_data::SyncBackend;
|
use solitaire_data::SyncBackend;
|
||||||
|
|
||||||
use crate::achievement_plugin::AchievementsResource;
|
use crate::achievement_plugin::AchievementsResource;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::avatar_plugin::AvatarResource;
|
use crate::avatar_plugin::AvatarResource;
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
#[derive(bevy::prelude::Resource)]
|
|
||||||
struct AvatarResource(Option<bevy::prelude::Handle<bevy::prelude::Image>>);
|
|
||||||
use crate::events::ToggleProfileRequestEvent;
|
use crate::events::ToggleProfileRequestEvent;
|
||||||
use crate::font_plugin::FontResource;
|
use crate::font_plugin::FontResource;
|
||||||
use crate::progress_plugin::ProgressResource;
|
use crate::progress_plugin::ProgressResource;
|
||||||
|
|||||||
+157
-179
@@ -47,12 +47,13 @@ use bevy::input::touch::Touches;
|
|||||||
use bevy::math::Vec2;
|
use bevy::math::Vec2;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::PrimaryWindow;
|
use bevy::window::PrimaryWindow;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::Card;
|
use solitaire_core::card::Card;
|
||||||
use solitaire_core::game_state::GameState;
|
use solitaire_core::game_state::GameState;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
use solitaire_core::rules::{can_place_on_foundation, can_place_on_tableau};
|
||||||
|
|
||||||
use crate::card_plugin::TABLEAU_FACEDOWN_FAN_FRAC;
|
use crate::card_plugin::TABLEAU_FACEDOWN_FAN_FRAC;
|
||||||
use crate::events::{MoveRejectedEvent, MoveRequestEvent};
|
use crate::events::MoveRequestEvent;
|
||||||
use crate::layout::{Layout, LayoutResource, TABLEAU_FAN_FRAC};
|
use crate::layout::{Layout, LayoutResource, TABLEAU_FAN_FRAC};
|
||||||
use crate::pause_plugin::PausedResource;
|
use crate::pause_plugin::PausedResource;
|
||||||
use crate::resources::{DragState, GameStateResource};
|
use crate::resources::{DragState, GameStateResource};
|
||||||
@@ -107,7 +108,7 @@ pub enum RightClickRadialState {
|
|||||||
/// `hovered_index` (or none).
|
/// `hovered_index` (or none).
|
||||||
Active {
|
Active {
|
||||||
/// Pile the right-clicked card came from.
|
/// Pile the right-clicked card came from.
|
||||||
source_pile: KlondikePile,
|
source_pile: PileType,
|
||||||
/// Number of cards that would be moved (always `1` — only the
|
/// Number of cards that would be moved (always `1` — only the
|
||||||
/// top face-up card is ever offered for a quick-drop, since the
|
/// top face-up card is ever offered for a quick-drop, since the
|
||||||
/// radial is built around single-card foundation/tableau
|
/// radial is built around single-card foundation/tableau
|
||||||
@@ -122,7 +123,7 @@ pub enum RightClickRadialState {
|
|||||||
/// [`RADIAL_RADIUS_PX`] centred on the press position. A single
|
/// [`RADIAL_RADIUS_PX`] centred on the press position. A single
|
||||||
/// destination is placed directly above the cursor; multiple
|
/// destination is placed directly above the cursor; multiple
|
||||||
/// destinations span an arc.
|
/// destinations span an arc.
|
||||||
legal_destinations: Vec<(KlondikePile, Vec2)>,
|
legal_destinations: Vec<(PileType, Vec2)>,
|
||||||
/// Cursor position (world space) the radial was opened at —
|
/// Cursor position (world space) the radial was opened at —
|
||||||
/// used as the centre of the ring for cursor-hover hit testing.
|
/// used as the centre of the ring for cursor-hover hit testing.
|
||||||
centre: Vec2,
|
centre: Vec2,
|
||||||
@@ -249,20 +250,30 @@ pub fn radial_hovered_index(cursor: Vec2, anchors: &[Vec2]) -> Option<usize> {
|
|||||||
/// that legally accept the card. The source pile is excluded because
|
/// that legally accept the card. The source pile is excluded because
|
||||||
/// dropping a card on its own pile is a no-op.
|
/// dropping a card on its own pile is a no-op.
|
||||||
pub fn legal_destinations_for_card(
|
pub fn legal_destinations_for_card(
|
||||||
_card: &Card,
|
card: &Card,
|
||||||
source_pile: &KlondikePile,
|
source_pile: &PileType,
|
||||||
game: &GameState,
|
game: &GameState,
|
||||||
) -> Vec<KlondikePile> {
|
) -> Vec<PileType> {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
for foundation in foundations() {
|
for slot in 0..4_u8 {
|
||||||
let dest = KlondikePile::Foundation(foundation);
|
let dest = PileType::Foundation(slot);
|
||||||
if game.can_move_cards(source_pile, &dest, 1) {
|
if dest == *source_pile {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(pile) = game.piles.get(&dest)
|
||||||
|
&& can_place_on_foundation(card, pile)
|
||||||
|
{
|
||||||
out.push(dest);
|
out.push(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for tableau in tableaus() {
|
for i in 0..7_usize {
|
||||||
let dest = KlondikePile::Tableau(tableau);
|
let dest = PileType::Tableau(i);
|
||||||
if game.can_move_cards(source_pile, &dest, 1) {
|
if dest == *source_pile {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(pile) = game.piles.get(&dest)
|
||||||
|
&& can_place_on_tableau(card, pile)
|
||||||
|
{
|
||||||
out.push(dest);
|
out.push(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,34 +292,36 @@ pub fn find_top_face_up_card_at(
|
|||||||
cursor: Vec2,
|
cursor: Vec2,
|
||||||
game: &GameState,
|
game: &GameState,
|
||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
) -> Option<(KlondikePile, Card)> {
|
) -> Option<(PileType, Card)> {
|
||||||
let piles = [
|
let piles = [
|
||||||
KlondikePile::Stock,
|
PileType::Waste,
|
||||||
KlondikePile::Foundation(Foundation::Foundation1),
|
PileType::Foundation(0),
|
||||||
KlondikePile::Foundation(Foundation::Foundation2),
|
PileType::Foundation(1),
|
||||||
KlondikePile::Foundation(Foundation::Foundation3),
|
PileType::Foundation(2),
|
||||||
KlondikePile::Foundation(Foundation::Foundation4),
|
PileType::Foundation(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
PileType::Tableau(0),
|
||||||
KlondikePile::Tableau(Tableau::Tableau2),
|
PileType::Tableau(1),
|
||||||
KlondikePile::Tableau(Tableau::Tableau3),
|
PileType::Tableau(2),
|
||||||
KlondikePile::Tableau(Tableau::Tableau4),
|
PileType::Tableau(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau5),
|
PileType::Tableau(4),
|
||||||
KlondikePile::Tableau(Tableau::Tableau6),
|
PileType::Tableau(5),
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
PileType::Tableau(6),
|
||||||
];
|
];
|
||||||
for pile in piles {
|
for pile in piles {
|
||||||
let pile_cards = pile_cards(game, &pile);
|
let Some(pile_cards) = game.piles.get(&pile) else {
|
||||||
if pile_cards.is_empty() {
|
continue;
|
||||||
|
};
|
||||||
|
if pile_cards.cards.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let is_tableau = matches!(pile, KlondikePile::Tableau(_));
|
let is_tableau = matches!(pile, PileType::Tableau(_));
|
||||||
for i in (0..pile_cards.len()).rev() {
|
for i in (0..pile_cards.cards.len()).rev() {
|
||||||
let card = &pile_cards[i];
|
let card = &pile_cards.cards[i];
|
||||||
if !card.face_up {
|
if !card.face_up {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Only the top card is draggable on non-tableau piles.
|
// Only the top card is draggable on non-tableau piles.
|
||||||
if !is_tableau && i != pile_cards.len() - 1 {
|
if !is_tableau && i != pile_cards.cards.len() - 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let pos = card_position(game, layout, &pile, i);
|
let pos = card_position(game, layout, &pile, i);
|
||||||
@@ -329,22 +342,19 @@ pub fn find_top_face_up_card_at(
|
|||||||
/// Mirror of `input_plugin::card_position` — kept private to this
|
/// Mirror of `input_plugin::card_position` — kept private to this
|
||||||
/// module so the radial's hit-test geometry tracks renderer geometry
|
/// module so the radial's hit-test geometry tracks renderer geometry
|
||||||
/// without depending on `input_plugin` internals.
|
/// without depending on `input_plugin` internals.
|
||||||
fn card_position(
|
fn card_position(game: &GameState, layout: &Layout, pile: &PileType, stack_index: usize) -> Vec2 {
|
||||||
game: &GameState,
|
|
||||||
layout: &Layout,
|
|
||||||
pile: &KlondikePile,
|
|
||||||
stack_index: usize,
|
|
||||||
) -> Vec2 {
|
|
||||||
let base = layout.pile_positions[pile];
|
let base = layout.pile_positions[pile];
|
||||||
if matches!(pile, KlondikePile::Tableau(_)) {
|
if matches!(pile, PileType::Tableau(_)) {
|
||||||
let mut y_offset = 0.0_f32;
|
let mut y_offset = 0.0_f32;
|
||||||
for card in pile_cards(game, pile).iter().take(stack_index) {
|
if let Some(pile_cards) = game.piles.get(pile) {
|
||||||
let step = if card.face_up {
|
for card in pile_cards.cards.iter().take(stack_index) {
|
||||||
TABLEAU_FAN_FRAC
|
let step = if card.face_up {
|
||||||
} else {
|
TABLEAU_FAN_FRAC
|
||||||
TABLEAU_FACEDOWN_FAN_FRAC
|
} else {
|
||||||
};
|
TABLEAU_FACEDOWN_FAN_FRAC
|
||||||
y_offset -= layout.card_size.y * step;
|
};
|
||||||
|
y_offset -= layout.card_size.y * step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Vec2::new(base.x, base.y + y_offset)
|
Vec2::new(base.x, base.y + y_offset)
|
||||||
} else {
|
} else {
|
||||||
@@ -352,56 +362,17 @@ fn card_position(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pile_cards(game: &GameState, pile: &KlondikePile) -> Vec<Card> {
|
|
||||||
match pile {
|
|
||||||
KlondikePile::Stock => game.waste_cards(),
|
|
||||||
_ => game.pile(*pile),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn foundations() -> [Foundation; 4] {
|
|
||||||
[
|
|
||||||
Foundation::Foundation1,
|
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn tableaus() -> [Tableau; 7] {
|
|
||||||
[
|
|
||||||
Tableau::Tableau1,
|
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds the `(destination, anchor)` list for a fresh radial open.
|
/// Builds the `(destination, anchor)` list for a fresh radial open.
|
||||||
///
|
fn build_radial_destinations(centre: Vec2, dests: Vec<PileType>) -> Vec<(PileType, Vec2)> {
|
||||||
/// `half_extents` is the window half-size in world space — icons are clamped
|
|
||||||
/// so that their edges stay within the viewport, preventing them from appearing
|
|
||||||
/// off-screen on small or narrow devices.
|
|
||||||
fn build_radial_destinations(
|
|
||||||
centre: Vec2,
|
|
||||||
dests: Vec<KlondikePile>,
|
|
||||||
half_extents: Vec2,
|
|
||||||
) -> Vec<(KlondikePile, Vec2)> {
|
|
||||||
let count = dests.len();
|
let count = dests.len();
|
||||||
let margin = RADIAL_ICON_SIZE_PX / 2.0;
|
|
||||||
dests
|
dests
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, d)| {
|
.map(|(i, d)| {
|
||||||
let raw = radial_anchor_for_index(centre, count, i, RADIAL_RADIUS_PX);
|
(
|
||||||
let clamped = Vec2::new(
|
d,
|
||||||
raw.x.clamp(-half_extents.x + margin, half_extents.x - margin),
|
radial_anchor_for_index(centre, count, i, RADIAL_RADIUS_PX),
|
||||||
raw.y.clamp(-half_extents.y + margin, half_extents.y - margin),
|
)
|
||||||
);
|
|
||||||
(d, clamped)
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -436,10 +407,9 @@ fn cursor_world(
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/// On `MouseButton::Right` `just_pressed`, attempts to open the radial
|
/// On `MouseButton::Right` `just_pressed`, attempts to open the radial
|
||||||
/// menu over the card the cursor is on. When the cursor is on a face-up
|
/// menu over the card the cursor is on. Skips when a left-mouse drag is
|
||||||
/// card but no legal destinations exist, fires `MoveRejectedEvent` so the
|
/// in progress, when the game is paused, or when the clicked card has no
|
||||||
/// shake animation and invalid-move sound play. Skips silently when no
|
/// legal destinations.
|
||||||
/// card is under the cursor, when a drag is in progress, or when paused.
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn radial_open_on_right_click(
|
fn radial_open_on_right_click(
|
||||||
buttons: Option<Res<ButtonInput<MouseButton>>>,
|
buttons: Option<Res<ButtonInput<MouseButton>>>,
|
||||||
@@ -451,7 +421,6 @@ fn radial_open_on_right_click(
|
|||||||
layout: Option<Res<LayoutResource>>,
|
layout: Option<Res<LayoutResource>>,
|
||||||
game: Option<Res<GameStateResource>>,
|
game: Option<Res<GameStateResource>>,
|
||||||
mut state: ResMut<RightClickRadialState>,
|
mut state: ResMut<RightClickRadialState>,
|
||||||
mut rejected: MessageWriter<MoveRejectedEvent>,
|
|
||||||
) {
|
) {
|
||||||
if paused.is_some_and(|p| p.0) {
|
if paused.is_some_and(|p| p.0) {
|
||||||
return;
|
return;
|
||||||
@@ -480,20 +449,9 @@ fn radial_open_on_right_click(
|
|||||||
// cards and the highlight tint shows the same set the radial offers.
|
// cards and the highlight tint shows the same set the radial offers.
|
||||||
let dests = legal_destinations_for_card(&card, &source_pile, &game.0);
|
let dests = legal_destinations_for_card(&card, &source_pile, &game.0);
|
||||||
if dests.is_empty() {
|
if dests.is_empty() {
|
||||||
// No legal destinations — shake the source pile as feedback.
|
|
||||||
rejected.write(MoveRejectedEvent {
|
|
||||||
from: source_pile,
|
|
||||||
to: source_pile,
|
|
||||||
count: 1,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let half_extents = windows
|
let legal_destinations = build_radial_destinations(world, dests);
|
||||||
.single()
|
|
||||||
.ok()
|
|
||||||
.map(|w| Vec2::new(w.width() / 2.0, w.height() / 2.0))
|
|
||||||
.unwrap_or(Vec2::splat(f32::MAX));
|
|
||||||
let legal_destinations = build_radial_destinations(world, dests, half_extents);
|
|
||||||
|
|
||||||
*state = RightClickRadialState::Active {
|
*state = RightClickRadialState::Active {
|
||||||
source_pile,
|
source_pile,
|
||||||
@@ -519,7 +477,6 @@ fn radial_open_on_long_press(
|
|||||||
drag: Res<DragState>,
|
drag: Res<DragState>,
|
||||||
paused: Option<Res<PausedResource>>,
|
paused: Option<Res<PausedResource>>,
|
||||||
touches: Option<Res<Touches>>,
|
touches: Option<Res<Touches>>,
|
||||||
windows: Query<&Window, With<PrimaryWindow>>,
|
|
||||||
cameras: Query<(&Camera, &GlobalTransform)>,
|
cameras: Query<(&Camera, &GlobalTransform)>,
|
||||||
layout: Option<Res<LayoutResource>>,
|
layout: Option<Res<LayoutResource>>,
|
||||||
game: Option<Res<GameStateResource>>,
|
game: Option<Res<GameStateResource>>,
|
||||||
@@ -562,12 +519,7 @@ fn radial_open_on_long_press(
|
|||||||
if dests.is_empty() {
|
if dests.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let half_extents = windows
|
let legal_destinations = build_radial_destinations(world, dests);
|
||||||
.single()
|
|
||||||
.ok()
|
|
||||||
.map(|w| Vec2::new(w.width() / 2.0, w.height() / 2.0))
|
|
||||||
.unwrap_or(Vec2::splat(f32::MAX));
|
|
||||||
let legal_destinations = build_radial_destinations(world, dests, half_extents);
|
|
||||||
*state = RightClickRadialState::Active {
|
*state = RightClickRadialState::Active {
|
||||||
source_pile,
|
source_pile,
|
||||||
count: 1,
|
count: 1,
|
||||||
@@ -657,8 +609,8 @@ fn radial_handle_release_or_cancel(
|
|||||||
&& let Some((dest, _)) = legal_destinations.get(*idx)
|
&& let Some((dest, _)) = legal_destinations.get(*idx)
|
||||||
{
|
{
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *source_pile,
|
from: source_pile.clone(),
|
||||||
to: *dest,
|
to: dest.clone(),
|
||||||
count: *count,
|
count: *count,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -804,7 +756,6 @@ mod tests {
|
|||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.add_plugins(MinimalPlugins);
|
app.add_plugins(MinimalPlugins);
|
||||||
app.add_message::<MoveRequestEvent>();
|
app.add_message::<MoveRequestEvent>();
|
||||||
app.add_message::<MoveRejectedEvent>();
|
|
||||||
app.init_resource::<DragState>();
|
app.init_resource::<DragState>();
|
||||||
app.init_resource::<ButtonInput<MouseButton>>();
|
app.init_resource::<ButtonInput<MouseButton>>();
|
||||||
app.init_resource::<ButtonInput<KeyCode>>();
|
app.init_resource::<ButtonInput<KeyCode>>();
|
||||||
@@ -820,37 +771,33 @@ mod tests {
|
|||||||
fn ace_only_state() -> GameState {
|
fn ace_only_state() -> GameState {
|
||||||
let mut g = GameState::new(0, DrawMode::DrawOne);
|
let mut g = GameState::new(0, DrawMode::DrawOne);
|
||||||
// Wipe everything.
|
// Wipe everything.
|
||||||
g.set_test_stock_cards(Vec::new());
|
g.piles.get_mut(&PileType::Stock).unwrap().cards.clear();
|
||||||
g.set_test_waste_cards(Vec::new());
|
g.piles.get_mut(&PileType::Waste).unwrap().cards.clear();
|
||||||
for foundation in [
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation1,
|
g.piles
|
||||||
Foundation::Foundation2,
|
.get_mut(&PileType::Foundation(slot))
|
||||||
Foundation::Foundation3,
|
.unwrap()
|
||||||
Foundation::Foundation4,
|
.cards
|
||||||
] {
|
.clear();
|
||||||
g.set_test_foundation_cards(foundation, Vec::new());
|
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7_usize {
|
||||||
Tableau::Tableau1,
|
g.piles
|
||||||
Tableau::Tableau2,
|
.get_mut(&PileType::Tableau(i))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
Tableau::Tableau4,
|
.cards
|
||||||
Tableau::Tableau5,
|
.clear();
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
g.set_test_tableau_cards(tableau, Vec::new());
|
|
||||||
}
|
}
|
||||||
// Ace of Clubs on Tableau(0).
|
// Ace of Clubs on Tableau(0).
|
||||||
g.set_test_tableau_cards(
|
g.piles
|
||||||
Tableau::Tableau1,
|
.get_mut(&PileType::Tableau(0))
|
||||||
vec![CoreCard {
|
.unwrap()
|
||||||
|
.cards
|
||||||
|
.push(CoreCard {
|
||||||
id: 100,
|
id: 100,
|
||||||
suit: Suit::Clubs,
|
suit: Suit::Clubs,
|
||||||
rank: Rank::Ace,
|
rank: Rank::Ace,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
|
||||||
g
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,36 +805,32 @@ mod tests {
|
|||||||
/// must skip it.
|
/// must skip it.
|
||||||
fn face_down_only_state() -> GameState {
|
fn face_down_only_state() -> GameState {
|
||||||
let mut g = GameState::new(0, DrawMode::DrawOne);
|
let mut g = GameState::new(0, DrawMode::DrawOne);
|
||||||
g.set_test_stock_cards(Vec::new());
|
g.piles.get_mut(&PileType::Stock).unwrap().cards.clear();
|
||||||
g.set_test_waste_cards(Vec::new());
|
g.piles.get_mut(&PileType::Waste).unwrap().cards.clear();
|
||||||
for foundation in [
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation1,
|
g.piles
|
||||||
Foundation::Foundation2,
|
.get_mut(&PileType::Foundation(slot))
|
||||||
Foundation::Foundation3,
|
.unwrap()
|
||||||
Foundation::Foundation4,
|
.cards
|
||||||
] {
|
.clear();
|
||||||
g.set_test_foundation_cards(foundation, Vec::new());
|
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7_usize {
|
||||||
Tableau::Tableau1,
|
g.piles
|
||||||
Tableau::Tableau2,
|
.get_mut(&PileType::Tableau(i))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
Tableau::Tableau4,
|
.cards
|
||||||
Tableau::Tableau5,
|
.clear();
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
g.set_test_tableau_cards(tableau, Vec::new());
|
|
||||||
}
|
}
|
||||||
g.set_test_tableau_cards(
|
g.piles
|
||||||
Tableau::Tableau1,
|
.get_mut(&PileType::Tableau(0))
|
||||||
vec![CoreCard {
|
.unwrap()
|
||||||
|
.cards
|
||||||
|
.push(CoreCard {
|
||||||
id: 100,
|
id: 100,
|
||||||
suit: Suit::Spades,
|
suit: Suit::Spades,
|
||||||
rank: Rank::King,
|
rank: Rank::King,
|
||||||
face_up: false,
|
face_up: false,
|
||||||
}],
|
});
|
||||||
);
|
|
||||||
g
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -985,15 +928,14 @@ mod tests {
|
|||||||
rank: Rank::Ace,
|
rank: Rank::Ace,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
};
|
};
|
||||||
let dests =
|
let dests = legal_destinations_for_card(&card, &PileType::Tableau(0), &g);
|
||||||
legal_destinations_for_card(&card, &KlondikePile::Tableau(Tableau::Tableau1), &g);
|
|
||||||
// Ace can be placed on every empty foundation. We only need
|
// Ace can be placed on every empty foundation. We only need
|
||||||
// the count to be ≥ 1 and the source pile to be excluded.
|
// the count to be ≥ 1 and the source pile to be excluded.
|
||||||
assert!(
|
assert!(
|
||||||
!dests.is_empty(),
|
!dests.is_empty(),
|
||||||
"Ace must have at least one legal destination"
|
"Ace must have at least one legal destination"
|
||||||
);
|
);
|
||||||
assert!(!dests.contains(&KlondikePile::Tableau(Tableau::Tableau1)));
|
assert!(!dests.contains(&PileType::Tableau(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1005,12 +947,8 @@ mod tests {
|
|||||||
rank: Rank::Ace,
|
rank: Rank::Ace,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
};
|
};
|
||||||
let dests = legal_destinations_for_card(
|
let dests = legal_destinations_for_card(&card, &PileType::Foundation(0), &g);
|
||||||
&card,
|
assert!(!dests.contains(&PileType::Foundation(0)));
|
||||||
&KlondikePile::Foundation(Foundation::Foundation1),
|
|
||||||
&g,
|
|
||||||
);
|
|
||||||
assert!(!dests.contains(&KlondikePile::Foundation(Foundation::Foundation1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -1020,6 +958,46 @@ mod tests {
|
|||||||
/// Pressing right-click on a face-up card with at least one legal
|
/// Pressing right-click on a face-up card with at least one legal
|
||||||
/// destination must transition the state to `Active` carrying the
|
/// destination must transition the state to `Active` carrying the
|
||||||
/// expected source / count / legal-destination set.
|
/// expected source / count / legal-destination set.
|
||||||
|
#[test]
|
||||||
|
fn right_click_press_on_face_up_card_opens_radial() {
|
||||||
|
let mut app = radial_test_app();
|
||||||
|
let layout_window = Vec2::new(1280.0, 800.0);
|
||||||
|
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
||||||
|
let ace_pos = layout.pile_positions[&PileType::Tableau(0)];
|
||||||
|
|
||||||
|
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
||||||
|
// Initial state — Idle.
|
||||||
|
assert_eq!(
|
||||||
|
*app.world().resource::<RightClickRadialState>(),
|
||||||
|
RightClickRadialState::Idle
|
||||||
|
);
|
||||||
|
|
||||||
|
press(&mut app, MouseButton::Right);
|
||||||
|
app.update();
|
||||||
|
|
||||||
|
let state = app.world().resource::<RightClickRadialState>().clone();
|
||||||
|
match state {
|
||||||
|
RightClickRadialState::Active {
|
||||||
|
source_pile,
|
||||||
|
count,
|
||||||
|
cards,
|
||||||
|
legal_destinations,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
assert_eq!(source_pile, PileType::Tableau(0));
|
||||||
|
assert_eq!(count, 1);
|
||||||
|
assert_eq!(cards, vec![100]);
|
||||||
|
assert!(!legal_destinations.is_empty());
|
||||||
|
assert!(
|
||||||
|
legal_destinations
|
||||||
|
.iter()
|
||||||
|
.any(|(p, _)| matches!(p, PileType::Foundation(_)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
other => panic!("expected Active, got {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Releasing the right button while the cursor is over a destination
|
/// Releasing the right button while the cursor is over a destination
|
||||||
/// icon must fire a `MoveRequestEvent` and return the state to Idle.
|
/// icon must fire a `MoveRequestEvent` and return the state to Idle.
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1027,7 +1005,7 @@ mod tests {
|
|||||||
let mut app = radial_test_app();
|
let mut app = radial_test_app();
|
||||||
let layout_window = Vec2::new(1280.0, 800.0);
|
let layout_window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
||||||
let ace_pos = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)];
|
let ace_pos = layout.pile_positions[&PileType::Tableau(0)];
|
||||||
|
|
||||||
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
||||||
press(&mut app, MouseButton::Right);
|
press(&mut app, MouseButton::Right);
|
||||||
@@ -1054,7 +1032,7 @@ mod tests {
|
|||||||
let events = collect_move_events(&mut app);
|
let events = collect_move_events(&mut app);
|
||||||
assert_eq!(events.len(), 1, "exactly one MoveRequestEvent expected");
|
assert_eq!(events.len(), 1, "exactly one MoveRequestEvent expected");
|
||||||
let evt = &events[0];
|
let evt = &events[0];
|
||||||
assert_eq!(evt.from, KlondikePile::Tableau(Tableau::Tableau1));
|
assert_eq!(evt.from, PileType::Tableau(0));
|
||||||
assert_eq!(evt.to, dest_pile);
|
assert_eq!(evt.to, dest_pile);
|
||||||
assert_eq!(evt.count, 1);
|
assert_eq!(evt.count, 1);
|
||||||
// State must return to Idle.
|
// State must return to Idle.
|
||||||
@@ -1071,7 +1049,7 @@ mod tests {
|
|||||||
let mut app = radial_test_app();
|
let mut app = radial_test_app();
|
||||||
let layout_window = Vec2::new(1280.0, 800.0);
|
let layout_window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
||||||
let ace_pos = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)];
|
let ace_pos = layout.pile_positions[&PileType::Tableau(0)];
|
||||||
|
|
||||||
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
||||||
press(&mut app, MouseButton::Right);
|
press(&mut app, MouseButton::Right);
|
||||||
@@ -1102,7 +1080,7 @@ mod tests {
|
|||||||
let mut app = radial_test_app();
|
let mut app = radial_test_app();
|
||||||
let layout_window = Vec2::new(1280.0, 800.0);
|
let layout_window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
||||||
let ace_pos = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)];
|
let ace_pos = layout.pile_positions[&PileType::Tableau(0)];
|
||||||
|
|
||||||
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
install_resources(&mut app, ace_only_state(), layout_window, ace_pos);
|
||||||
press(&mut app, MouseButton::Right);
|
press(&mut app, MouseButton::Right);
|
||||||
@@ -1128,7 +1106,7 @@ mod tests {
|
|||||||
let mut app = radial_test_app();
|
let mut app = radial_test_app();
|
||||||
let layout_window = Vec2::new(1280.0, 800.0);
|
let layout_window = Vec2::new(1280.0, 800.0);
|
||||||
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
let layout = compute_layout(layout_window, 0.0, 0.0, true);
|
||||||
let king_pos = layout.pile_positions[&KlondikePile::Tableau(Tableau::Tableau1)];
|
let king_pos = layout.pile_positions[&PileType::Tableau(0)];
|
||||||
|
|
||||||
install_resources(&mut app, face_down_only_state(), layout_window, king_pos);
|
install_resources(&mut app, face_down_only_state(), layout_window, king_pos);
|
||||||
press(&mut app, MouseButton::Right);
|
press(&mut app, MouseButton::Right);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,273 +0,0 @@
|
|||||||
use super::ReplayPlaybackState;
|
|
||||||
use chrono::Datelike;
|
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::{Card, Rank, Suit};
|
|
||||||
use solitaire_core::game_state::GameState;
|
|
||||||
use solitaire_core::klondike_adapter::SavedKlondikePile;
|
|
||||||
use solitaire_data::ReplayMove;
|
|
||||||
|
|
||||||
/// Pure helper — formats the `GAME #YYYY-DDD` caption for the given
|
|
||||||
/// state. Returns `None` for `Inactive` / `Completed` (the replay is
|
|
||||||
/// consumed when transitioning out of `Playing`, so the identifier
|
|
||||||
/// isn't recoverable from state in those branches); spawn-time
|
|
||||||
/// callers fall back to an empty string.
|
|
||||||
///
|
|
||||||
/// Year + chrono ordinal (`{year}-{ordinal:03}`) gives a compact
|
|
||||||
/// monotonically-increasing identifier shaped like `2026-127` — same
|
|
||||||
/// shape as the mockup's `GAME #2024-127` motif.
|
|
||||||
pub(crate) fn format_game_caption(state: &ReplayPlaybackState) -> Option<String> {
|
|
||||||
match state {
|
|
||||||
ReplayPlaybackState::Playing { replay, .. } => Some(format!(
|
|
||||||
"GAME #{}-{:03}",
|
|
||||||
replay.recorded_at.year(),
|
|
||||||
replay.recorded_at.ordinal()
|
|
||||||
)),
|
|
||||||
ReplayPlaybackState::Inactive | ReplayPlaybackState::Completed => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats the centre progress readout for the given state.
|
|
||||||
/// Exposed at module scope so the spawn path and the per-frame update
|
|
||||||
/// path produce the exact same string.
|
|
||||||
pub(crate) fn format_progress(state: &ReplayPlaybackState) -> String {
|
|
||||||
match state.progress() {
|
|
||||||
// `MOVE N/M` (uppercase + slash) reads as a Terminal output
|
|
||||||
// line and matches the floating-chip motif in the mockup at
|
|
||||||
// `docs/ui-mockups/replay-overlay-mobile.html`.
|
|
||||||
Some((cursor, total)) => format!("MOVE {cursor}/{total}"),
|
|
||||||
None if state.is_completed() => "REPLAY COMPLETE".to_string(),
|
|
||||||
None => String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats a [`KlondikePile`] as a short, lowercase,
|
|
||||||
/// 1-indexed display string for the move-log row. `Foundation(2)`
|
|
||||||
/// renders as `"foundation 3"` rather than `"foundation 2"` so
|
|
||||||
/// players see human-friendly numbers; the underlying enum
|
|
||||||
/// remains 0-indexed.
|
|
||||||
///
|
|
||||||
/// Returns `String` rather than `&'static str` because the
|
|
||||||
/// `Foundation` / `Tableau` variants need formatting; the static
|
|
||||||
/// variants (`Stock`, `Waste`) still allocate but the cost is
|
|
||||||
/// trivial against the per-frame update cadence.
|
|
||||||
pub(crate) fn format_pile(p: &KlondikePile) -> String {
|
|
||||||
match p {
|
|
||||||
KlondikePile::Stock => "waste".to_string(),
|
|
||||||
KlondikePile::Foundation(foundation) => {
|
|
||||||
format!("foundation {}", foundation_number(*foundation))
|
|
||||||
}
|
|
||||||
KlondikePile::Tableau(tableau) => format!("tableau {}", tableau_number(*tableau)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn format_saved_pile(p: &SavedKlondikePile) -> String {
|
|
||||||
KlondikePile::try_from(*p)
|
|
||||||
.map(|pile| format_pile(&pile))
|
|
||||||
.unwrap_or_else(|_| "unknown pile".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn foundation_number(foundation: Foundation) -> u8 {
|
|
||||||
match foundation {
|
|
||||||
Foundation::Foundation1 => 1,
|
|
||||||
Foundation::Foundation2 => 2,
|
|
||||||
Foundation::Foundation3 => 3,
|
|
||||||
Foundation::Foundation4 => 4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tableau_number(tableau: Tableau) -> u8 {
|
|
||||||
match tableau {
|
|
||||||
Tableau::Tableau1 => 1,
|
|
||||||
Tableau::Tableau2 => 2,
|
|
||||||
Tableau::Tableau3 => 3,
|
|
||||||
Tableau::Tableau4 => 4,
|
|
||||||
Tableau::Tableau5 => 5,
|
|
||||||
Tableau::Tableau6 => 6,
|
|
||||||
Tableau::Tableau7 => 7,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats a [`ReplayMove`] as the body of a
|
|
||||||
/// move-log row. `StockClick` reads as `"stock cycle"`; `Move`
|
|
||||||
/// reads as `"{from} → {to}"` using [`format_pile`] for both
|
|
||||||
/// endpoints. The `count` field is omitted from the row body —
|
|
||||||
/// at row scale it adds visual noise without meaningful
|
|
||||||
/// information for the typical 1-card moves.
|
|
||||||
pub(crate) fn format_move_body(m: &ReplayMove) -> String {
|
|
||||||
match m {
|
|
||||||
ReplayMove::StockClick => "stock cycle".to_string(),
|
|
||||||
ReplayMove::Move { from, to, .. } => {
|
|
||||||
format!(
|
|
||||||
"{} \u{2192} {}",
|
|
||||||
format_saved_pile(from),
|
|
||||||
format_saved_pile(to)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats the move-log panel's header text. Reads
|
|
||||||
/// `▌ MOVE LOG · N/M` while playing, where `N` is the count of
|
|
||||||
/// moves applied so far and `M` is the total in the replay. The
|
|
||||||
/// cursor-block prefix (`▌`) matches the splash and replay-banner
|
|
||||||
/// motifs. Empty in `Inactive` (no replay attached); reads
|
|
||||||
/// `▌ MOVE LOG · COMPLETE` in `Completed`.
|
|
||||||
pub(crate) fn format_move_log_header(state: &ReplayPlaybackState) -> String {
|
|
||||||
match state {
|
|
||||||
ReplayPlaybackState::Playing { replay, cursor, .. } => {
|
|
||||||
format!(
|
|
||||||
"\u{258C} MOVE LOG \u{00B7} {}/{}",
|
|
||||||
cursor,
|
|
||||||
replay.moves.len()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ReplayPlaybackState::Completed => "\u{258C} MOVE LOG \u{00B7} COMPLETE".to_string(),
|
|
||||||
ReplayPlaybackState::Inactive => String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats the kth-most-recently-applied move's row
|
|
||||||
/// text. `k = 1` is the active row (`replay.moves[cursor - 1]`,
|
|
||||||
/// displayed as `"{cursor} │ {body}"`). `k = 2` is the row above
|
|
||||||
/// that (`moves[cursor - 2]` displayed as `"{cursor - 1} │ {body}"`),
|
|
||||||
/// and so on.
|
|
||||||
///
|
|
||||||
/// Returns the empty string in any of these cases:
|
|
||||||
/// - State isn't `Playing` (no replay attached).
|
|
||||||
/// - `k == 0` (no kth-most-recent for k=0; the active is k=1).
|
|
||||||
/// - `k > cursor` (not enough history — e.g. cursor=2 has rows
|
|
||||||
/// for k=1 and k=2 only, k=3 returns empty).
|
|
||||||
/// - The move list is shorter than expected (defensive guard).
|
|
||||||
pub(crate) fn format_kth_recent_row(state: &ReplayPlaybackState, k: usize) -> String {
|
|
||||||
let ReplayPlaybackState::Playing { replay, cursor, .. } = state else {
|
|
||||||
return String::new();
|
|
||||||
};
|
|
||||||
if k == 0 || k > *cursor {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
let zero_idx = *cursor - k;
|
|
||||||
let Some(m) = replay.moves.get(zero_idx) else {
|
|
||||||
return String::new();
|
|
||||||
};
|
|
||||||
let display_idx = *cursor - k + 1;
|
|
||||||
format!("{} \u{2502} {}", display_idx, format_move_body(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats the kth-NEXT move's row text. `k = 1`
|
|
||||||
/// is the move that will apply next (`replay.moves[cursor]`,
|
|
||||||
/// displayed as `cursor + 1`); `k = 2` is the move after that,
|
|
||||||
/// and so on.
|
|
||||||
///
|
|
||||||
/// Returns the empty string in any of these cases:
|
|
||||||
/// - State isn't `Playing` (no replay attached).
|
|
||||||
/// - `k == 0` (degenerate; the active is k=1 of *recent*, not
|
|
||||||
/// *next*).
|
|
||||||
/// - `cursor + k - 1 >= moves.len()` (not enough remaining
|
|
||||||
/// replay — late in the move list, the trailing next rows
|
|
||||||
/// stay empty).
|
|
||||||
pub(crate) fn format_kth_next_row(state: &ReplayPlaybackState, k: usize) -> String {
|
|
||||||
let ReplayPlaybackState::Playing { replay, cursor, .. } = state else {
|
|
||||||
return String::new();
|
|
||||||
};
|
|
||||||
if k == 0 {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
let zero_idx = *cursor + k - 1;
|
|
||||||
let Some(m) = replay.moves.get(zero_idx) else {
|
|
||||||
return String::new();
|
|
||||||
};
|
|
||||||
let display_idx = *cursor + k;
|
|
||||||
format!("{} \u{2502} {}", display_idx, format_move_body(m))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — formats the active-row text for the move-log
|
|
||||||
/// panel. Wraps [`format_kth_recent_row`] with `k=1` and prepends
|
|
||||||
/// a `▶` focus marker so the active row reads visually distinct
|
|
||||||
/// from prev rows even before the highlight background lands.
|
|
||||||
/// Returns empty when there's no row to render (cursor=0 or
|
|
||||||
/// non-`Playing` state) — never `"▶ "` alone, which would paint
|
|
||||||
/// a stray prefix.
|
|
||||||
pub(crate) fn format_active_move_row(state: &ReplayPlaybackState) -> String {
|
|
||||||
let body = format_kth_recent_row(state, 1);
|
|
||||||
if body.is_empty() {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
format!("\u{25B6} {body}") // ▶
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Mini-tableau format helpers and update system
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/// Pure helper — short rank symbol. Single character for all ranks
|
|
||||||
/// except Ten which uses "T" (keeps every card a consistent 2-char
|
|
||||||
/// wide render: rank-char + suit-glyph). Players familiar with
|
|
||||||
/// solitaire shorthand read "T" instantly; the suit glyph immediately
|
|
||||||
/// follows and disambiguates from an ambiguous "T".
|
|
||||||
pub(crate) fn format_rank_short(rank: Rank) -> &'static str {
|
|
||||||
match rank {
|
|
||||||
Rank::Ace => "A",
|
|
||||||
Rank::Two => "2",
|
|
||||||
Rank::Three => "3",
|
|
||||||
Rank::Four => "4",
|
|
||||||
Rank::Five => "5",
|
|
||||||
Rank::Six => "6",
|
|
||||||
Rank::Seven => "7",
|
|
||||||
Rank::Eight => "8",
|
|
||||||
Rank::Nine => "9",
|
|
||||||
Rank::Ten => "T",
|
|
||||||
Rank::Jack => "J",
|
|
||||||
Rank::Queen => "Q",
|
|
||||||
Rank::King => "K",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — Unicode suit glyph from FiraMono's covered range
|
|
||||||
/// (U+2660–U+2666). These four code points are confirmed present in
|
|
||||||
/// the bundled FiraMono on Android (verified on Pixel 7 / API 34).
|
|
||||||
pub(crate) fn format_suit_glyph(suit: Suit) -> &'static str {
|
|
||||||
match suit {
|
|
||||||
Suit::Spades => "\u{2660}", // ♠
|
|
||||||
Suit::Hearts => "\u{2665}", // ♥
|
|
||||||
Suit::Diamonds => "\u{2666}", // ♦
|
|
||||||
Suit::Clubs => "\u{2663}", // ♣
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — compact 2-char card label (`rank + suit glyph`) for a
|
|
||||||
/// known card, or `"--"` for an absent top card (empty pile).
|
|
||||||
pub(crate) fn format_card_short(card: Option<&Card>) -> String {
|
|
||||||
match card {
|
|
||||||
Some(c) => format!("{}{}", format_rank_short(c.rank), format_suit_glyph(c.suit)),
|
|
||||||
None => "--".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — one-line summary of the four foundation tops.
|
|
||||||
/// Renders as `F: A♠ 7♥ 5♦ K♣` with `--` for any empty slot.
|
|
||||||
/// Foundation slots are displayed in their natural 0-3 order
|
|
||||||
/// (matching the visual left-to-right order on screen).
|
|
||||||
pub(crate) fn format_foundations_row(game: &GameState) -> String {
|
|
||||||
let slots = [
|
|
||||||
Foundation::Foundation1,
|
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
]
|
|
||||||
.map(|foundation| {
|
|
||||||
let cards = game.pile(KlondikePile::Foundation(foundation));
|
|
||||||
format_card_short(cards.last())
|
|
||||||
});
|
|
||||||
format!("F: {} {} {} {}", slots[0], slots[1], slots[2], slots[3])
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pure helper — one-line stock / waste summary.
|
|
||||||
/// Renders as `STK:N WST:X♠` where N is the stock card count and
|
|
||||||
/// X♠ is the top waste card (or `--` when the waste pile is empty).
|
|
||||||
pub(crate) fn format_stock_waste_row(game: &GameState) -> String {
|
|
||||||
let stock_cards = game.stock_cards();
|
|
||||||
let waste_cards = game.waste_cards();
|
|
||||||
let stock_count = stock_cards.len();
|
|
||||||
let waste_top = waste_cards.last();
|
|
||||||
format!("STK:{} WST:{}", stock_count, format_card_short(waste_top))
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,249 +0,0 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
use super::format::{
|
|
||||||
format_active_move_row, format_foundations_row, format_kth_next_row, format_kth_recent_row,
|
|
||||||
format_move_log_header, format_progress, format_stock_waste_row,
|
|
||||||
};
|
|
||||||
use super::*;
|
|
||||||
use crate::layout::LayoutResource;
|
|
||||||
use crate::replay_playback::ReplayPlaybackState;
|
|
||||||
use crate::resources::GameStateResource;
|
|
||||||
use klondike::KlondikePile;
|
|
||||||
use solitaire_data::ReplayMove;
|
|
||||||
|
|
||||||
/// Overwrites the banner label whenever the resource changes — covers the
|
|
||||||
/// `Playing → Completed` transition by swapping "▌ replay" for
|
|
||||||
/// "▌ replay complete" in place without despawning the overlay.
|
|
||||||
pub(crate) fn update_banner_label(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayOverlayBannerText>>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let label = if state.is_completed() {
|
|
||||||
"\u{258C} replay complete" // ▌
|
|
||||||
} else if state.is_playing() {
|
|
||||||
"\u{258C} replay" // ▌
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
for mut text in &mut q {
|
|
||||||
**text = label.to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the "Move N of M" centre readout every frame the cursor moves.
|
|
||||||
/// Cheap — early-exits if the resource has not changed since the last
|
|
||||||
/// frame so idle replays don't churn the text mesh.
|
|
||||||
pub(crate) fn update_progress_text(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayOverlayProgressText>>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let label = format_progress(&state);
|
|
||||||
for mut text in &mut q {
|
|
||||||
**text = label.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repositions the floating progress chip above the destination
|
|
||||||
/// pile of the most-recently-applied move and repaints its text.
|
|
||||||
///
|
|
||||||
/// The chip is hidden when:
|
|
||||||
/// - the cursor is at 0 (no moves applied yet — chip would have
|
|
||||||
/// nowhere meaningful to land), OR
|
|
||||||
/// - the most-recently-applied move was a `StockClick` (no
|
|
||||||
/// destination pile — stock-click feedback already lives at
|
|
||||||
/// the stock pile and we don't want the chip to jitter back
|
|
||||||
/// to the stock pile every cycle).
|
|
||||||
///
|
|
||||||
/// When visible, the chip's world-space `Transform.translation`
|
|
||||||
/// is set to the destination pile's centre plus a fixed upward
|
|
||||||
/// offset (`card_size.y * 0.6`) so the chip floats just above
|
|
||||||
/// the top edge of the card. World-space placement (rather than
|
|
||||||
/// UI-space + camera projection) keeps the math trivial and means
|
|
||||||
/// the chip stays correctly positioned through window resizes
|
|
||||||
/// without any extra wiring — `LayoutResource` already drives
|
|
||||||
/// every other piece of pile geometry.
|
|
||||||
pub(crate) fn update_floating_progress_chip(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
layout: Option<Res<LayoutResource>>,
|
|
||||||
mut chips: Query<
|
|
||||||
(&mut Transform, &mut Visibility, &mut Text2d),
|
|
||||||
With<ReplayFloatingProgressChip>,
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
let Some(layout) = layout else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Resolve the destination pile of the last-applied move (if
|
|
||||||
// any). `cursor` is the index of the *next* move to apply, so
|
|
||||||
// the most-recently-applied move sits at `cursor - 1`.
|
|
||||||
let dest_pile = match state.as_ref() {
|
|
||||||
ReplayPlaybackState::Playing { replay, cursor, .. } if *cursor > 0 => {
|
|
||||||
match &replay.moves[cursor - 1] {
|
|
||||||
ReplayMove::Move { to, .. } => Some(*to),
|
|
||||||
ReplayMove::StockClick => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(world_pos) = dest_pile
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|p| KlondikePile::try_from(*p).ok())
|
|
||||||
.and_then(|p| layout.0.pile_positions.get(&p).copied())
|
|
||||||
else {
|
|
||||||
// Nothing to point at — hide every chip and exit.
|
|
||||||
for (_, mut visibility, _) in chips.iter_mut() {
|
|
||||||
*visibility = Visibility::Hidden;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Position above the destination pile by ~60 % of a card
|
|
||||||
// height. Half a card lifts above the centre, the extra 10 %
|
|
||||||
// is breathing room above the top edge so the chip doesn't
|
|
||||||
// visually clip the card.
|
|
||||||
let above = Vec2::new(0.0, layout.0.card_size.y * 0.6);
|
|
||||||
let target = (world_pos + above).extend(100.0);
|
|
||||||
let label = format_progress(&state);
|
|
||||||
|
|
||||||
for (mut transform, mut visibility, mut text2d) in chips.iter_mut() {
|
|
||||||
transform.translation = target;
|
|
||||||
*visibility = Visibility::Inherited;
|
|
||||||
if **text2d != label {
|
|
||||||
**text2d = label.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the move-log panel's `▌ MOVE LOG · N/M` header text
|
|
||||||
/// whenever [`ReplayPlaybackState`] changes. Cheap — early-exits
|
|
||||||
/// when nothing moved so an idle replay leaves the text mesh
|
|
||||||
/// untouched.
|
|
||||||
pub(crate) fn update_move_log_header(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayOverlayMoveLogHeader>>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let label = format_move_log_header(&state);
|
|
||||||
for mut text in &mut q {
|
|
||||||
**text = label.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the move-log panel's active-row text whenever
|
|
||||||
/// [`ReplayPlaybackState`] changes. Same change-detection guard
|
|
||||||
/// as the header updater. Empty string at `cursor == 0` (no move
|
|
||||||
/// applied yet) and in non-`Playing` states; populated otherwise.
|
|
||||||
pub(crate) fn update_move_log_active_row(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayOverlayMoveLogActiveRow>>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let label = format_active_move_row(&state);
|
|
||||||
for mut text in &mut q {
|
|
||||||
**text = label.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints every "previous move" row text whenever
|
|
||||||
/// [`ReplayPlaybackState`] changes. Each row's `offset` is read
|
|
||||||
/// from the marker; `k = offset + 1` feeds [`format_kth_recent_row`]
|
|
||||||
/// (active is k=1, prev offset 1 is k=2, prev offset 2 is k=3).
|
|
||||||
/// Rows with `offset >= cursor` paint as empty — the panel
|
|
||||||
/// gracefully under-fills early in a replay without spurious
|
|
||||||
/// "out-of-range" text.
|
|
||||||
pub(crate) fn update_move_log_prev_rows(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<(&ReplayOverlayMoveLogPrevRow, &mut Text)>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (row, mut text) in &mut q {
|
|
||||||
let label = format_kth_recent_row(&state, row.offset as usize + 1);
|
|
||||||
**text = label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints every "next move" row text whenever
|
|
||||||
/// [`ReplayPlaybackState`] changes. Symmetric to the prev-row
|
|
||||||
/// updater but feeds [`format_kth_next_row`]. Rows where
|
|
||||||
/// `cursor + offset > moves.len()` paint as empty — the panel
|
|
||||||
/// gracefully under-fills late in a replay (e.g. final moves)
|
|
||||||
/// without spurious out-of-range text.
|
|
||||||
pub(crate) fn update_move_log_next_rows(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<(&ReplayOverlayMoveLogNextRow, &mut Text)>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (row, mut text) in &mut q {
|
|
||||||
let label = format_kth_next_row(&state, row.offset as usize);
|
|
||||||
**text = label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the bottom-edge accent scrub fill to mirror cursor progress.
|
|
||||||
/// Same change-detection guard as the text updaters — the overlay
|
|
||||||
/// already early-exits when nothing moved, so an idle replay leaves the
|
|
||||||
/// scrub bar's `Node` untouched.
|
|
||||||
pub(crate) fn update_scrub_fill(
|
|
||||||
state: Res<ReplayPlaybackState>,
|
|
||||||
mut q: Query<&mut Node, With<ReplayOverlayScrubFill>>,
|
|
||||||
) {
|
|
||||||
if !state.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let pct = scrub_pct(&state);
|
|
||||||
for mut node in &mut q {
|
|
||||||
node.width = Val::Percent(pct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the foundations row whenever [`GameStateResource`] changes.
|
|
||||||
/// Split into its own system (rather than combined with the stock/waste
|
|
||||||
/// updater) to avoid a Bevy B0001 query conflict: two `&mut Text`
|
|
||||||
/// queries in one system are always ambiguous regardless of marker
|
|
||||||
/// filters. Each updater owns exactly one `Query<&mut Text, With<…>>`.
|
|
||||||
pub(crate) fn update_mini_tableau_foundations(
|
|
||||||
game: Option<Res<GameStateResource>>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayMiniTableauFoundations>>,
|
|
||||||
) {
|
|
||||||
let Some(game) = game else { return };
|
|
||||||
if !game.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let text = format_foundations_row(&game.0);
|
|
||||||
for mut t in &mut q {
|
|
||||||
**t = text.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Repaints the stock/waste row whenever [`GameStateResource`] changes.
|
|
||||||
/// Sibling of [`update_mini_tableau_foundations`] — same change-detection
|
|
||||||
/// guard, separate system to avoid the B0001 query conflict.
|
|
||||||
pub(crate) fn update_mini_tableau_stock_waste(
|
|
||||||
game: Option<Res<GameStateResource>>,
|
|
||||||
mut q: Query<&mut Text, With<ReplayMiniTableauStockWaste>>,
|
|
||||||
) {
|
|
||||||
let Some(game) = game else { return };
|
|
||||||
if !game.is_changed() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let text = format_stock_waste_row(&game.0);
|
|
||||||
for mut t in &mut q {
|
|
||||||
**t = text.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,6 @@
|
|||||||
//! flag is threaded through, no every-callsite gate is added.
|
//! flag is threaded through, no every-callsite gate is added.
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use klondike::KlondikePile;
|
|
||||||
use solitaire_data::{Replay, ReplayMove};
|
use solitaire_data::{Replay, ReplayMove};
|
||||||
|
|
||||||
use crate::events::{DrawRequestEvent, MoveRequestEvent, StateChangedEvent, UndoRequestEvent};
|
use crate::events::{DrawRequestEvent, MoveRequestEvent, StateChangedEvent, UndoRequestEvent};
|
||||||
@@ -268,18 +267,9 @@ pub fn step_replay_playback(
|
|||||||
}
|
}
|
||||||
match &replay.moves[*cursor] {
|
match &replay.moves[*cursor] {
|
||||||
ReplayMove::Move { from, to, count } => {
|
ReplayMove::Move { from, to, count } => {
|
||||||
let (Ok(from), Ok(to)) = (KlondikePile::try_from(*from), KlondikePile::try_from(*to))
|
|
||||||
else {
|
|
||||||
warn!(
|
|
||||||
"skipping replay move with invalid pile encoding at cursor {}",
|
|
||||||
*cursor
|
|
||||||
);
|
|
||||||
*cursor += 1;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
moves_writer.write(MoveRequestEvent {
|
moves_writer.write(MoveRequestEvent {
|
||||||
from,
|
from: from.clone(),
|
||||||
to,
|
to: to.clone(),
|
||||||
count: *count,
|
count: *count,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -380,20 +370,11 @@ fn tick_replay_playback(
|
|||||||
while *secs_to_next <= 0.0 && *cursor < replay.moves.len() {
|
while *secs_to_next <= 0.0 && *cursor < replay.moves.len() {
|
||||||
match &replay.moves[*cursor] {
|
match &replay.moves[*cursor] {
|
||||||
ReplayMove::Move { from, to, count } => {
|
ReplayMove::Move { from, to, count } => {
|
||||||
if let (Ok(from), Ok(to)) =
|
moves_writer.write(MoveRequestEvent {
|
||||||
(KlondikePile::try_from(*from), KlondikePile::try_from(*to))
|
from: from.clone(),
|
||||||
{
|
to: to.clone(),
|
||||||
moves_writer.write(MoveRequestEvent {
|
count: *count,
|
||||||
from,
|
});
|
||||||
to,
|
|
||||||
count: *count,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
warn!(
|
|
||||||
"skipping replay move with invalid pile encoding at cursor {}",
|
|
||||||
*cursor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ReplayMove::StockClick => {
|
ReplayMove::StockClick => {
|
||||||
draws_writer.write(DrawRequestEvent);
|
draws_writer.write(DrawRequestEvent);
|
||||||
@@ -555,9 +536,8 @@ mod tests {
|
|||||||
use crate::game_plugin::GamePlugin;
|
use crate::game_plugin::GamePlugin;
|
||||||
use bevy::time::TimeUpdateStrategy;
|
use bevy::time::TimeUpdateStrategy;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use klondike::{KlondikePile, Tableau};
|
|
||||||
use solitaire_core::game_state::{DrawMode, GameMode};
|
use solitaire_core::game_state::{DrawMode, GameMode};
|
||||||
use solitaire_core::klondike_adapter::{SavedKlondikePile, SavedTableau};
|
use solitaire_core::pile::PileType;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Builds a headless `App` with `MinimalPlugins`, `GamePlugin`, and
|
/// Builds a headless `App` with `MinimalPlugins`, `GamePlugin`, and
|
||||||
@@ -606,8 +586,8 @@ mod tests {
|
|||||||
vec![
|
vec![
|
||||||
ReplayMove::StockClick,
|
ReplayMove::StockClick,
|
||||||
ReplayMove::Move {
|
ReplayMove::Move {
|
||||||
from: SavedKlondikePile::Stock,
|
from: PileType::Waste,
|
||||||
to: SavedKlondikePile::Tableau(SavedTableau(3)),
|
to: PileType::Tableau(3),
|
||||||
count: 1,
|
count: 1,
|
||||||
},
|
},
|
||||||
ReplayMove::StockClick,
|
ReplayMove::StockClick,
|
||||||
@@ -759,8 +739,8 @@ mod tests {
|
|||||||
"expected 1 MoveRequestEvent (the single Move variant)",
|
"expected 1 MoveRequestEvent (the single Move variant)",
|
||||||
);
|
);
|
||||||
let m = &captured_moves.0[0];
|
let m = &captured_moves.0[0];
|
||||||
assert!(matches!(m.from, KlondikePile::Stock));
|
assert!(matches!(m.from, PileType::Waste));
|
||||||
assert!(matches!(m.to, KlondikePile::Tableau(Tableau::Tableau4)));
|
assert!(matches!(m.to, PileType::Tableau(3)));
|
||||||
assert_eq!(m.count, 1);
|
assert_eq!(m.count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
//! Bevy resources owned by the engine crate.
|
//! Bevy resources owned by the engine crate.
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bevy::math::Vec2;
|
use bevy::math::Vec2;
|
||||||
use bevy::prelude::Resource;
|
use bevy::prelude::Resource;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use klondike::KlondikePile;
|
|
||||||
use solitaire_core::game_state::GameState;
|
use solitaire_core::game_state::GameState;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
/// Wraps the currently active `GameState`. Single source of truth for the in-progress game.
|
/// Wraps the currently active `GameState`. Single source of truth for the in-progress game.
|
||||||
#[derive(Resource, Debug, Clone)]
|
#[derive(Resource, Debug, Clone)]
|
||||||
@@ -30,7 +29,7 @@ pub struct DragState {
|
|||||||
/// IDs of the cards being dragged (bottom-to-top stacking order).
|
/// IDs of the cards being dragged (bottom-to-top stacking order).
|
||||||
pub cards: Vec<u32>,
|
pub cards: Vec<u32>,
|
||||||
/// Pile the drag originated from.
|
/// Pile the drag originated from.
|
||||||
pub origin_pile: Option<KlondikePile>,
|
pub origin_pile: Option<PileType>,
|
||||||
/// World-space offset from the cursor/touch to the bottom card's centre.
|
/// World-space offset from the cursor/touch to the bottom card's centre.
|
||||||
pub cursor_offset: Vec2,
|
pub cursor_offset: Vec2,
|
||||||
/// Z coordinate used for the dragged cards.
|
/// Z coordinate used for the dragged cards.
|
||||||
@@ -129,16 +128,9 @@ pub struct GameInputConsumedResource(pub bool);
|
|||||||
/// multi-threaded runtime is built once at startup and its `Arc` cloned cheaply
|
/// multi-threaded runtime is built once at startup and its `Arc` cloned cheaply
|
||||||
/// into every network task — safe for concurrent `block_on` calls from multiple
|
/// into every network task — safe for concurrent `block_on` calls from multiple
|
||||||
/// worker threads.
|
/// worker threads.
|
||||||
///
|
|
||||||
/// Gated to non-wasm because `tokio::runtime::Builder::new_multi_thread()` uses
|
|
||||||
/// `mio` for OS-level I/O polling which does not compile for wasm32. The
|
|
||||||
/// plugins that depend on this resource (AudioPlugin, SyncPlugin,
|
|
||||||
/// AnalyticsPlugin) are also gated out on wasm32 in `CoreGamePlugin`.
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct TokioRuntimeResource(pub Arc<tokio::runtime::Runtime>);
|
pub struct TokioRuntimeResource(pub Arc<tokio::runtime::Runtime>);
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
impl TokioRuntimeResource {
|
impl TokioRuntimeResource {
|
||||||
/// Attempts to build the shared multi-threaded Tokio runtime.
|
/// Attempts to build the shared multi-threaded Tokio runtime.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -253,24 +253,24 @@ mod android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the inset poller on `AppLifecycle::WillResume` so that
|
/// Resets the inset poller and clears cached insets on
|
||||||
/// `refresh_insets` re-queries JNI in the frames immediately after the app
|
/// `AppLifecycle::WillResume` so that `refresh_insets` re-queries JNI in the
|
||||||
/// returns to the foreground.
|
/// frames immediately after the app returns to the foreground.
|
||||||
///
|
///
|
||||||
/// The cached `SafeAreaInsets` are intentionally **not** zeroed here.
|
/// Clearing `SafeAreaInsets` to the default (all-zero) fires
|
||||||
/// Zeroing them would cause two layout recomputes on every resume:
|
/// `on_safe_area_changed` in `table_plugin`, which emits a synthetic
|
||||||
/// once with zero insets (wrong position) and again when JNI resolves the
|
/// `WindowResized`. `on_window_resized` then recomputes the layout;
|
||||||
/// real values — visible as a flash. By preserving the last-known values
|
/// once `refresh_insets` resolves the real values a second synthetic
|
||||||
/// the layout remains stable; if JNI returns a different value (e.g. after
|
/// `WindowResized` fires and the layout converges to the correct position.
|
||||||
/// a rotation) the single update that fires when `SafeAreaInsets` actually
|
|
||||||
/// changes is enough.
|
|
||||||
pub(super) fn rearm_on_resumed(
|
pub(super) fn rearm_on_resumed(
|
||||||
mut lifecycle: MessageReader<AppLifecycle>,
|
mut lifecycle: MessageReader<AppLifecycle>,
|
||||||
mut poll: ResMut<SafeAreaPollTries>,
|
mut poll: ResMut<SafeAreaPollTries>,
|
||||||
|
mut insets: ResMut<SafeAreaInsets>,
|
||||||
) {
|
) {
|
||||||
for event in lifecycle.read() {
|
for event in lifecycle.read() {
|
||||||
if matches!(event, AppLifecycle::WillResume) {
|
if matches!(event, AppLifecycle::WillResume) {
|
||||||
poll.0 = 0;
|
poll.0 = 0;
|
||||||
|
*insets = SafeAreaInsets::default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@
|
|||||||
|
|
||||||
use bevy::input::ButtonInput;
|
use bevy::input::ButtonInput;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::Card;
|
|
||||||
use solitaire_core::game_state::GameState;
|
use solitaire_core::game_state::GameState;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
use solitaire_core::rules::{can_place_on_foundation, can_place_on_tableau};
|
||||||
|
|
||||||
use crate::card_plugin::CardEntity;
|
use crate::card_plugin::CardEntity;
|
||||||
use crate::events::{InfoToastEvent, MoveRequestEvent, StateChangedEvent};
|
use crate::events::{InfoToastEvent, MoveRequestEvent, StateChangedEvent};
|
||||||
@@ -60,7 +60,7 @@ use crate::ui_theme::{ACCENT_PRIMARY, STATE_SUCCESS, STATE_WARNING};
|
|||||||
#[derive(Resource, Debug, Default)]
|
#[derive(Resource, Debug, Default)]
|
||||||
pub struct SelectionState {
|
pub struct SelectionState {
|
||||||
/// The pile whose top face-up card is currently selected, or `None`.
|
/// The pile whose top face-up card is currently selected, or `None`.
|
||||||
pub selected_pile: Option<KlondikePile>,
|
pub selected_pile: Option<PileType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sentinel value used in [`crate::resources::DragState::active_touch_id`]
|
/// Sentinel value used in [`crate::resources::DragState::active_touch_id`]
|
||||||
@@ -87,7 +87,7 @@ pub enum KeyboardDragState {
|
|||||||
/// `legal_destinations` and `Enter` fires the move.
|
/// `legal_destinations` and `Enter` fires the move.
|
||||||
Lifted {
|
Lifted {
|
||||||
/// Pile the cards were lifted from.
|
/// Pile the cards were lifted from.
|
||||||
source_pile: KlondikePile,
|
source_pile: PileType,
|
||||||
/// Number of cards lifted (1 for waste / foundation, full face-up
|
/// Number of cards lifted (1 for waste / foundation, full face-up
|
||||||
/// run length for a tableau column).
|
/// run length for a tableau column).
|
||||||
count: usize,
|
count: usize,
|
||||||
@@ -98,7 +98,7 @@ pub enum KeyboardDragState {
|
|||||||
/// placed on. Always at least one entry while in this variant —
|
/// placed on. Always at least one entry while in this variant —
|
||||||
/// if no legal destinations exist the state machine refuses to
|
/// if no legal destinations exist the state machine refuses to
|
||||||
/// enter `Lifted` in the first place.
|
/// enter `Lifted` in the first place.
|
||||||
legal_destinations: Vec<KlondikePile>,
|
legal_destinations: Vec<PileType>,
|
||||||
/// Cursor into `legal_destinations`. Always `< legal_destinations.len()`.
|
/// Cursor into `legal_destinations`. Always `< legal_destinations.len()`.
|
||||||
destination_index: usize,
|
destination_index: usize,
|
||||||
},
|
},
|
||||||
@@ -110,7 +110,7 @@ impl KeyboardDragState {
|
|||||||
///
|
///
|
||||||
/// [`Lifted`]: KeyboardDragState::Lifted
|
/// [`Lifted`]: KeyboardDragState::Lifted
|
||||||
/// [`Idle`]: KeyboardDragState::Idle
|
/// [`Idle`]: KeyboardDragState::Idle
|
||||||
pub fn focused_destination(&self) -> Option<&KlondikePile> {
|
pub fn focused_destination(&self) -> Option<&PileType> {
|
||||||
match self {
|
match self {
|
||||||
Self::Idle => None,
|
Self::Idle => None,
|
||||||
Self::Lifted {
|
Self::Lifted {
|
||||||
@@ -173,26 +173,13 @@ impl Plugin for SelectionPlugin {
|
|||||||
/// The ordered list of piles that are considered for keyboard cycling.
|
/// The ordered list of piles that are considered for keyboard cycling.
|
||||||
///
|
///
|
||||||
/// Order: Waste → Foundation slots 0–3 → Tableau 0–6.
|
/// Order: Waste → Foundation slots 0–3 → Tableau 0–6.
|
||||||
fn cycled_piles() -> Vec<KlondikePile> {
|
fn cycled_piles() -> Vec<PileType> {
|
||||||
let mut piles = vec![KlondikePile::Stock];
|
let mut piles = vec![PileType::Waste];
|
||||||
for foundation in [
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation1,
|
piles.push(PileType::Foundation(slot));
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
] {
|
|
||||||
piles.push(KlondikePile::Foundation(foundation));
|
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7_usize {
|
||||||
Tableau::Tableau1,
|
piles.push(PileType::Tableau(i));
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
piles.push(KlondikePile::Tableau(tableau));
|
|
||||||
}
|
}
|
||||||
piles
|
piles
|
||||||
}
|
}
|
||||||
@@ -202,10 +189,7 @@ fn cycled_piles() -> Vec<KlondikePile> {
|
|||||||
///
|
///
|
||||||
/// If `current` is `None` the first available pile is returned.
|
/// If `current` is `None` the first available pile is returned.
|
||||||
/// If `available` is empty, `None` is returned.
|
/// If `available` is empty, `None` is returned.
|
||||||
pub fn cycle_next_pile(
|
pub fn cycle_next_pile(available: &[PileType], current: Option<&PileType>) -> Option<PileType> {
|
||||||
available: &[KlondikePile],
|
|
||||||
current: Option<&KlondikePile>,
|
|
||||||
) -> Option<KlondikePile> {
|
|
||||||
if available.is_empty() {
|
if available.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -226,7 +210,7 @@ pub fn cycle_next_pile(
|
|||||||
for offset in 0..n {
|
for offset in 0..n {
|
||||||
let candidate = &order[(start + offset) % n];
|
let candidate = &order[(start + offset) % n];
|
||||||
if available.contains(candidate) {
|
if available.contains(candidate) {
|
||||||
return Some(*candidate);
|
return Some(candidate.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@@ -238,18 +222,14 @@ pub fn cycle_next_pile(
|
|||||||
///
|
///
|
||||||
/// Both `current` and `next` must be `Some`; if either is `None` this returns
|
/// Both `current` and `next` must be `Some`; if either is `None` this returns
|
||||||
/// `false`.
|
/// `false`.
|
||||||
fn did_wrap(
|
fn did_wrap(available: &[PileType], current: Option<&PileType>, next: Option<&PileType>) -> bool {
|
||||||
available: &[KlondikePile],
|
|
||||||
current: Option<&KlondikePile>,
|
|
||||||
next: Option<&KlondikePile>,
|
|
||||||
) -> bool {
|
|
||||||
let (Some(cur), Some(nxt)) = (current, next) else {
|
let (Some(cur), Some(nxt)) = (current, next) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let order = cycled_piles();
|
let order = cycled_piles();
|
||||||
// Position of each pile within the *available* subset, ordered by the
|
// Position of each pile within the *available* subset, ordered by the
|
||||||
// global cycle order.
|
// global cycle order.
|
||||||
let pos_in_available = |target: &KlondikePile| -> Option<usize> {
|
let pos_in_available = |target: &PileType| -> Option<usize> {
|
||||||
order
|
order
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|p| available.contains(p))
|
.filter(|p| available.contains(p))
|
||||||
@@ -346,7 +326,7 @@ fn handle_selection_keys(
|
|||||||
if keys.just_pressed(KeyCode::Enter) {
|
if keys.just_pressed(KeyCode::Enter) {
|
||||||
if let Some(dest) = legal_destinations.get(*destination_index).cloned() {
|
if let Some(dest) = legal_destinations.get(*destination_index).cloned() {
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *source_pile,
|
from: source_pile.clone(),
|
||||||
to: dest,
|
to: dest,
|
||||||
count: *count,
|
count: *count,
|
||||||
});
|
});
|
||||||
@@ -377,23 +357,29 @@ fn handle_selection_keys(
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
// Build the list of piles that currently have a face-up draggable top card.
|
// Build the list of piles that currently have a face-up draggable top card.
|
||||||
let available: Vec<KlondikePile> = {
|
let available: Vec<PileType> = {
|
||||||
let all = [
|
let all = [
|
||||||
KlondikePile::Stock,
|
PileType::Waste,
|
||||||
KlondikePile::Foundation(Foundation::Foundation1),
|
PileType::Foundation(0),
|
||||||
KlondikePile::Foundation(Foundation::Foundation2),
|
PileType::Foundation(1),
|
||||||
KlondikePile::Foundation(Foundation::Foundation3),
|
PileType::Foundation(2),
|
||||||
KlondikePile::Foundation(Foundation::Foundation4),
|
PileType::Foundation(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau1),
|
PileType::Tableau(0),
|
||||||
KlondikePile::Tableau(Tableau::Tableau2),
|
PileType::Tableau(1),
|
||||||
KlondikePile::Tableau(Tableau::Tableau3),
|
PileType::Tableau(2),
|
||||||
KlondikePile::Tableau(Tableau::Tableau4),
|
PileType::Tableau(3),
|
||||||
KlondikePile::Tableau(Tableau::Tableau5),
|
PileType::Tableau(4),
|
||||||
KlondikePile::Tableau(Tableau::Tableau6),
|
PileType::Tableau(5),
|
||||||
KlondikePile::Tableau(Tableau::Tableau7),
|
PileType::Tableau(6),
|
||||||
];
|
];
|
||||||
all.into_iter()
|
all.into_iter()
|
||||||
.filter(|p| pile_cards(&game.0, p).last().is_some_and(|c| c.face_up))
|
.filter(|p| {
|
||||||
|
game.0
|
||||||
|
.piles
|
||||||
|
.get(p)
|
||||||
|
.and_then(|pile| pile.cards.last())
|
||||||
|
.is_some_and(|c| c.face_up)
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -421,16 +407,18 @@ fn handle_selection_keys(
|
|||||||
// tableau stack target. Preserved so the muscle memory built around
|
// tableau stack target. Preserved so the muscle memory built around
|
||||||
// `Tab` → `Space` keeps working; `Enter` is now the lift trigger.
|
// `Tab` → `Space` keeps working; `Enter` is now the lift trigger.
|
||||||
if keys.just_pressed(KeyCode::Space)
|
if keys.just_pressed(KeyCode::Space)
|
||||||
&& let Some(ref pile) = selection.selected_pile
|
&& let Some(ref pile) = selection.selected_pile.clone()
|
||||||
|
&& let Some(card) = game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.get(pile)
|
||||||
|
.and_then(|p| p.cards.last())
|
||||||
|
.filter(|c| c.face_up)
|
||||||
{
|
{
|
||||||
let selected_cards = pile_cards(&game.0, pile);
|
|
||||||
let Some(card) = selected_cards.last().filter(|c| c.face_up) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
// Priority 1: foundation move (single card).
|
// Priority 1: foundation move (single card).
|
||||||
if let Some(dest) = try_foundation_dest(card, &game.0) {
|
if let Some(dest) = try_foundation_dest(card, &game.0) {
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *pile,
|
from: pile.clone(),
|
||||||
to: dest,
|
to: dest,
|
||||||
count: 1,
|
count: 1,
|
||||||
});
|
});
|
||||||
@@ -438,16 +426,17 @@ fn handle_selection_keys(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Priority 2: tableau stack move.
|
// Priority 2: tableau stack move.
|
||||||
let run_len = face_up_run_len(&selected_cards);
|
let run_len = face_up_run_len(game.0.piles.get(pile).map_or(&[], |p| p.cards.as_slice()));
|
||||||
let bottom_card = selected_cards
|
let bottom_card = game.0.piles.get(pile).and_then(|p| {
|
||||||
.get(selected_cards.len().saturating_sub(run_len))
|
let start = p.cards.len().saturating_sub(run_len);
|
||||||
.cloned();
|
p.cards.get(start)
|
||||||
|
});
|
||||||
if let Some(bottom) = bottom_card
|
if let Some(bottom) = bottom_card
|
||||||
&& let Some((dest, count)) =
|
&& let Some((dest, count)) =
|
||||||
best_tableau_destination_for_stack(&bottom, pile, &game.0, run_len)
|
best_tableau_destination_for_stack(bottom, pile, &game.0, run_len)
|
||||||
{
|
{
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *pile,
|
from: pile.clone(),
|
||||||
to: dest,
|
to: dest,
|
||||||
count,
|
count,
|
||||||
});
|
});
|
||||||
@@ -457,7 +446,7 @@ fn handle_selection_keys(
|
|||||||
// Fallback for non-tableau sources.
|
// Fallback for non-tableau sources.
|
||||||
if let Some(dest) = best_destination(card, &game.0) {
|
if let Some(dest) = best_destination(card, &game.0) {
|
||||||
moves.write(MoveRequestEvent {
|
moves.write(MoveRequestEvent {
|
||||||
from: *pile,
|
from: pile.clone(),
|
||||||
to: dest,
|
to: dest,
|
||||||
count: 1,
|
count: 1,
|
||||||
});
|
});
|
||||||
@@ -468,23 +457,25 @@ fn handle_selection_keys(
|
|||||||
|
|
||||||
// Enter — lift the focused pile into destination-pick mode.
|
// Enter — lift the focused pile into destination-pick mode.
|
||||||
if keys.just_pressed(KeyCode::Enter)
|
if keys.just_pressed(KeyCode::Enter)
|
||||||
&& let Some(ref source) = selection.selected_pile
|
&& let Some(ref source) = selection.selected_pile.clone()
|
||||||
{
|
{
|
||||||
let source_cards = pile_cards(&game.0, source);
|
let Some(pile_cards) = game.0.piles.get(source) else {
|
||||||
if source_cards.is_empty() {
|
|
||||||
return;
|
return;
|
||||||
}
|
};
|
||||||
// Determine the lift range: tableau lifts the full face-up run, all
|
// Determine the lift range: tableau lifts the full face-up run, all
|
||||||
// other sources lift only the top card.
|
// other sources lift only the top card.
|
||||||
let run_len = face_up_run_len(&source_cards);
|
let run_len = face_up_run_len(pile_cards.cards.as_slice());
|
||||||
let count = if matches!(source, KlondikePile::Tableau(_)) {
|
let count = if matches!(source, PileType::Tableau(_)) {
|
||||||
run_len.max(1)
|
run_len.max(1)
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
let start = source_cards.len().saturating_sub(count);
|
if pile_cards.cards.is_empty() {
|
||||||
let lifted_cards: Vec<u32> = source_cards[start..].iter().map(|c| c.id).collect();
|
return;
|
||||||
let Some(bottom) = source_cards.get(start) else {
|
}
|
||||||
|
let start = pile_cards.cards.len().saturating_sub(count);
|
||||||
|
let lifted_cards: Vec<u32> = pile_cards.cards[start..].iter().map(|c| c.id).collect();
|
||||||
|
let Some(bottom) = pile_cards.cards.get(start) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let legal = legal_destinations_for(bottom, source, &game.0, count);
|
let legal = legal_destinations_for(bottom, source, &game.0, count);
|
||||||
@@ -496,7 +487,7 @@ fn handle_selection_keys(
|
|||||||
// Populate `DragState` with the keyboard sentinel so the existing
|
// Populate `DragState` with the keyboard sentinel so the existing
|
||||||
// mouse-drag systems treat this as "not their drag".
|
// mouse-drag systems treat this as "not their drag".
|
||||||
drag.cards = lifted_cards.clone();
|
drag.cards = lifted_cards.clone();
|
||||||
drag.origin_pile = Some(*source);
|
drag.origin_pile = Some(source.clone());
|
||||||
drag.cursor_offset = Vec2::ZERO;
|
drag.cursor_offset = Vec2::ZERO;
|
||||||
drag.origin_z = 1.0;
|
drag.origin_z = 1.0;
|
||||||
drag.press_pos = Vec2::ZERO;
|
drag.press_pos = Vec2::ZERO;
|
||||||
@@ -504,7 +495,7 @@ fn handle_selection_keys(
|
|||||||
drag.active_touch_id = Some(KEYBOARD_DRAG_TOUCH_ID);
|
drag.active_touch_id = Some(KEYBOARD_DRAG_TOUCH_ID);
|
||||||
|
|
||||||
*kbd_drag = KeyboardDragState::Lifted {
|
*kbd_drag = KeyboardDragState::Lifted {
|
||||||
source_pile: *source,
|
source_pile: source.clone(),
|
||||||
count,
|
count,
|
||||||
cards: lifted_cards,
|
cards: lifted_cards,
|
||||||
legal_destinations: legal,
|
legal_destinations: legal,
|
||||||
@@ -529,36 +520,33 @@ fn handle_selection_keys(
|
|||||||
/// destination after a lift. Players who want a different column simply
|
/// destination after a lift. Players who want a different column simply
|
||||||
/// press the right-arrow key once or twice.
|
/// press the right-arrow key once or twice.
|
||||||
pub(crate) fn legal_destinations_for(
|
pub(crate) fn legal_destinations_for(
|
||||||
_bottom: &solitaire_core::card::Card,
|
bottom: &solitaire_core::card::Card,
|
||||||
source: &KlondikePile,
|
source: &PileType,
|
||||||
game: &GameState,
|
game: &GameState,
|
||||||
stack_count: usize,
|
stack_count: usize,
|
||||||
) -> Vec<KlondikePile> {
|
) -> Vec<PileType> {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
if stack_count == 1 {
|
if stack_count == 1 {
|
||||||
for foundation in [
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation1,
|
let dest = PileType::Foundation(slot);
|
||||||
Foundation::Foundation2,
|
if &dest == source {
|
||||||
Foundation::Foundation3,
|
continue;
|
||||||
Foundation::Foundation4,
|
}
|
||||||
] {
|
if let Some(pile) = game.piles.get(&dest)
|
||||||
let dest = KlondikePile::Foundation(foundation);
|
&& can_place_on_foundation(bottom, pile)
|
||||||
if game.can_move_cards(source, &dest, 1) {
|
{
|
||||||
out.push(dest);
|
out.push(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for tableau in [
|
for i in 0..7_usize {
|
||||||
Tableau::Tableau1,
|
let dest = PileType::Tableau(i);
|
||||||
Tableau::Tableau2,
|
if &dest == source {
|
||||||
Tableau::Tableau3,
|
continue;
|
||||||
Tableau::Tableau4,
|
}
|
||||||
Tableau::Tableau5,
|
if let Some(pile) = game.piles.get(&dest)
|
||||||
Tableau::Tableau6,
|
&& can_place_on_tableau(bottom, pile)
|
||||||
Tableau::Tableau7,
|
{
|
||||||
] {
|
|
||||||
let dest = KlondikePile::Tableau(tableau);
|
|
||||||
if game.can_move_cards(source, &dest, stack_count) {
|
|
||||||
out.push(dest);
|
out.push(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,16 +583,13 @@ fn face_up_run_len(cards: &[solitaire_core::card::Card]) -> usize {
|
|||||||
fn try_foundation_dest(
|
fn try_foundation_dest(
|
||||||
card: &solitaire_core::card::Card,
|
card: &solitaire_core::card::Card,
|
||||||
game: &solitaire_core::game_state::GameState,
|
game: &solitaire_core::game_state::GameState,
|
||||||
) -> Option<KlondikePile> {
|
) -> Option<PileType> {
|
||||||
let source = game.pile_containing_card(card.id)?;
|
use solitaire_core::rules::can_place_on_foundation;
|
||||||
for foundation in [
|
for slot in 0..4_u8 {
|
||||||
Foundation::Foundation1,
|
let dest = PileType::Foundation(slot);
|
||||||
Foundation::Foundation2,
|
if let Some(pile) = game.piles.get(&dest)
|
||||||
Foundation::Foundation3,
|
&& can_place_on_foundation(card, pile)
|
||||||
Foundation::Foundation4,
|
{
|
||||||
] {
|
|
||||||
let dest = KlondikePile::Foundation(foundation);
|
|
||||||
if game.can_move_cards(&source, &dest, 1) {
|
|
||||||
return Some(dest);
|
return Some(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -684,9 +669,9 @@ fn update_selection_highlight(
|
|||||||
// Resolve the source pile from KeyboardDragState (when lifted) or
|
// Resolve the source pile from KeyboardDragState (when lifted) or
|
||||||
// SelectionState (otherwise). Lifted takes precedence so the gold
|
// SelectionState (otherwise). Lifted takes precedence so the gold
|
||||||
// outline follows the actual lifted cards.
|
// outline follows the actual lifted cards.
|
||||||
let source_pile: Option<KlondikePile> = match &*kbd_drag {
|
let source_pile: Option<PileType> = match &*kbd_drag {
|
||||||
KeyboardDragState::Lifted { source_pile, .. } => Some(*source_pile),
|
KeyboardDragState::Lifted { source_pile, .. } => Some(source_pile.clone()),
|
||||||
KeyboardDragState::Idle => selection.selected_pile,
|
KeyboardDragState::Idle => selection.selected_pile.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref pile) = source_pile
|
if let Some(ref pile) = source_pile
|
||||||
@@ -722,15 +707,14 @@ fn update_selection_highlight(
|
|||||||
|
|
||||||
/// Returns the top face-up card on `pile`, or `None` if the pile is
|
/// Returns the top face-up card on `pile`, or `None` if the pile is
|
||||||
/// empty or its top card is face-down.
|
/// empty or its top card is face-down.
|
||||||
fn top_face_up_card(pile: &KlondikePile, game: &GameState) -> Option<Card> {
|
fn top_face_up_card<'a>(
|
||||||
pile_cards(game, pile).last().filter(|c| c.face_up).cloned()
|
pile: &PileType,
|
||||||
}
|
game: &'a GameState,
|
||||||
|
) -> Option<&'a solitaire_core::card::Card> {
|
||||||
fn pile_cards(game: &GameState, pile: &KlondikePile) -> Vec<Card> {
|
game.piles
|
||||||
match pile {
|
.get(pile)
|
||||||
KlondikePile::Stock => game.waste_cards(),
|
.and_then(|p| p.cards.last())
|
||||||
_ => game.pile(*pile),
|
.filter(|c| c.face_up)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a `SelectionHighlight` sprite as a child of the entity carrying
|
/// Spawn a `SelectionHighlight` sprite as a child of the entity carrying
|
||||||
@@ -769,15 +753,15 @@ fn spawn_highlight_on_card(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn piles_from(names: &[&str]) -> Vec<KlondikePile> {
|
fn piles_from(names: &[&str]) -> Vec<PileType> {
|
||||||
names
|
names
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&n| match n {
|
.map(|&n| match n {
|
||||||
"Waste" => KlondikePile::Stock,
|
"Waste" => PileType::Waste,
|
||||||
"T0" => KlondikePile::Tableau(Tableau::Tableau1),
|
"T0" => PileType::Tableau(0),
|
||||||
"T1" => KlondikePile::Tableau(Tableau::Tableau2),
|
"T1" => PileType::Tableau(1),
|
||||||
"T2" => KlondikePile::Tableau(Tableau::Tableau3),
|
"T2" => PileType::Tableau(2),
|
||||||
_ => KlondikePile::Stock,
|
_ => PileType::Waste,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -791,23 +775,23 @@ mod tests {
|
|||||||
// With [Waste, Tableau(0), Tableau(1)] available, starting from None → Waste.
|
// With [Waste, Tableau(0), Tableau(1)] available, starting from None → Waste.
|
||||||
let available = piles_from(&["Waste", "T0", "T1"]);
|
let available = piles_from(&["Waste", "T0", "T1"]);
|
||||||
let result = cycle_next_pile(&available, None);
|
let result = cycle_next_pile(&available, None);
|
||||||
assert_eq!(result, Some(KlondikePile::Stock));
|
assert_eq!(result, Some(PileType::Waste));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cycle_next_pile_from_waste() {
|
fn cycle_next_pile_from_waste() {
|
||||||
// Starting from Waste → Tableau(0).
|
// Starting from Waste → Tableau(0).
|
||||||
let available = piles_from(&["Waste", "T0", "T1"]);
|
let available = piles_from(&["Waste", "T0", "T1"]);
|
||||||
let result = cycle_next_pile(&available, Some(&KlondikePile::Stock));
|
let result = cycle_next_pile(&available, Some(&PileType::Waste));
|
||||||
assert_eq!(result, Some(KlondikePile::Tableau(Tableau::Tableau1)));
|
assert_eq!(result, Some(PileType::Tableau(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cycle_next_pile_wraps() {
|
fn cycle_next_pile_wraps() {
|
||||||
// Starting from Tableau(1) → Waste (wraps back to start).
|
// Starting from Tableau(1) → Waste (wraps back to start).
|
||||||
let available = piles_from(&["Waste", "T0", "T1"]);
|
let available = piles_from(&["Waste", "T0", "T1"]);
|
||||||
let result = cycle_next_pile(&available, Some(&KlondikePile::Tableau(Tableau::Tableau2)));
|
let result = cycle_next_pile(&available, Some(&PileType::Tableau(1)));
|
||||||
assert_eq!(result, Some(KlondikePile::Stock));
|
assert_eq!(result, Some(PileType::Waste));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -832,7 +816,7 @@ mod tests {
|
|||||||
|
|
||||||
// Press 1: no current selection → first pile, no wrap.
|
// Press 1: no current selection → first pile, no wrap.
|
||||||
let sel1 = cycle_next_pile(&available, None);
|
let sel1 = cycle_next_pile(&available, None);
|
||||||
assert_eq!(sel1, Some(KlondikePile::Stock));
|
assert_eq!(sel1, Some(PileType::Waste));
|
||||||
assert!(
|
assert!(
|
||||||
!did_wrap(&available, None, sel1.as_ref()),
|
!did_wrap(&available, None, sel1.as_ref()),
|
||||||
"first Tab should not wrap"
|
"first Tab should not wrap"
|
||||||
@@ -840,7 +824,7 @@ mod tests {
|
|||||||
|
|
||||||
// Press 2: Waste → Tableau(0), no wrap.
|
// Press 2: Waste → Tableau(0), no wrap.
|
||||||
let sel2 = cycle_next_pile(&available, sel1.as_ref());
|
let sel2 = cycle_next_pile(&available, sel1.as_ref());
|
||||||
assert_eq!(sel2, Some(KlondikePile::Tableau(Tableau::Tableau1)));
|
assert_eq!(sel2, Some(PileType::Tableau(0)));
|
||||||
assert!(
|
assert!(
|
||||||
!did_wrap(&available, sel1.as_ref(), sel2.as_ref()),
|
!did_wrap(&available, sel1.as_ref(), sel2.as_ref()),
|
||||||
"second Tab should not wrap"
|
"second Tab should not wrap"
|
||||||
@@ -848,7 +832,7 @@ mod tests {
|
|||||||
|
|
||||||
// Press 3: Tableau(0) → Tableau(1), still no wrap.
|
// Press 3: Tableau(0) → Tableau(1), still no wrap.
|
||||||
let sel3 = cycle_next_pile(&available, sel2.as_ref());
|
let sel3 = cycle_next_pile(&available, sel2.as_ref());
|
||||||
assert_eq!(sel3, Some(KlondikePile::Tableau(Tableau::Tableau2)));
|
assert_eq!(sel3, Some(PileType::Tableau(1)));
|
||||||
assert!(
|
assert!(
|
||||||
!did_wrap(&available, sel2.as_ref(), sel3.as_ref()),
|
!did_wrap(&available, sel2.as_ref(), sel3.as_ref()),
|
||||||
"third Tab (T0→T1) should not wrap"
|
"third Tab (T0→T1) should not wrap"
|
||||||
@@ -856,7 +840,7 @@ mod tests {
|
|||||||
|
|
||||||
// Press 4: Tableau(1) → Waste, this IS the wrap.
|
// Press 4: Tableau(1) → Waste, this IS the wrap.
|
||||||
let sel4 = cycle_next_pile(&available, sel3.as_ref());
|
let sel4 = cycle_next_pile(&available, sel3.as_ref());
|
||||||
assert_eq!(sel4, Some(KlondikePile::Stock));
|
assert_eq!(sel4, Some(PileType::Waste));
|
||||||
assert!(
|
assert!(
|
||||||
did_wrap(&available, sel3.as_ref(), sel4.as_ref()),
|
did_wrap(&available, sel3.as_ref(), sel4.as_ref()),
|
||||||
"fourth Tab should wrap back to Waste"
|
"fourth Tab should wrap back to Waste"
|
||||||
@@ -865,9 +849,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cycle_next_pile_single_element_wraps_to_itself() {
|
fn cycle_next_pile_single_element_wraps_to_itself() {
|
||||||
let available = vec![KlondikePile::Stock];
|
let available = vec![PileType::Waste];
|
||||||
let result = cycle_next_pile(&available, Some(&KlondikePile::Stock));
|
let result = cycle_next_pile(&available, Some(&PileType::Waste));
|
||||||
assert_eq!(result, Some(KlondikePile::Stock));
|
assert_eq!(result, Some(PileType::Waste));
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -1015,47 +999,46 @@ mod tests {
|
|||||||
fn deterministic_state() -> GameState {
|
fn deterministic_state() -> GameState {
|
||||||
let mut g = GameState::new(0, DrawMode::DrawOne);
|
let mut g = GameState::new(0, DrawMode::DrawOne);
|
||||||
// Clear stock, waste, all tableaus.
|
// Clear stock, waste, all tableaus.
|
||||||
g.set_test_stock_cards(Vec::new());
|
g.piles.get_mut(&PileType::Stock).unwrap().cards.clear();
|
||||||
g.set_test_waste_cards(Vec::new());
|
g.piles.get_mut(&PileType::Waste).unwrap().cards.clear();
|
||||||
for tableau in [
|
for i in 0..7 {
|
||||||
Tableau::Tableau1,
|
g.piles
|
||||||
Tableau::Tableau2,
|
.get_mut(&PileType::Tableau(i))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
Tableau::Tableau4,
|
.cards
|
||||||
Tableau::Tableau5,
|
.clear();
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
g.set_test_tableau_cards(tableau, Vec::new());
|
|
||||||
}
|
}
|
||||||
// Place test cards.
|
// Place test cards.
|
||||||
g.set_test_tableau_cards(
|
g.piles
|
||||||
Tableau::Tableau1,
|
.get_mut(&PileType::Tableau(0))
|
||||||
vec![Card {
|
.unwrap()
|
||||||
|
.cards
|
||||||
|
.push(Card {
|
||||||
id: 100,
|
id: 100,
|
||||||
suit: Suit::Clubs,
|
suit: Suit::Clubs,
|
||||||
rank: Rank::Five,
|
rank: Rank::Five,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
g.piles
|
||||||
g.set_test_tableau_cards(
|
.get_mut(&PileType::Tableau(1))
|
||||||
Tableau::Tableau2,
|
.unwrap()
|
||||||
vec![Card {
|
.cards
|
||||||
|
.push(Card {
|
||||||
id: 101,
|
id: 101,
|
||||||
suit: Suit::Hearts,
|
suit: Suit::Hearts,
|
||||||
rank: Rank::Six,
|
rank: Rank::Six,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
g.piles
|
||||||
g.set_test_tableau_cards(
|
.get_mut(&PileType::Tableau(2))
|
||||||
Tableau::Tableau3,
|
.unwrap()
|
||||||
vec![Card {
|
.cards
|
||||||
|
.push(Card {
|
||||||
id: 102,
|
id: 102,
|
||||||
suit: Suit::Diamonds,
|
suit: Suit::Diamonds,
|
||||||
rank: Rank::Six,
|
rank: Rank::Six,
|
||||||
face_up: true,
|
face_up: true,
|
||||||
}],
|
});
|
||||||
);
|
|
||||||
g
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1114,7 +1097,7 @@ mod tests {
|
|||||||
.clone();
|
.clone();
|
||||||
// The cycle order starts at Waste, but Waste is empty so the next
|
// The cycle order starts at Waste, but Waste is empty so the next
|
||||||
// available pile (Tableau(0)) is selected.
|
// available pile (Tableau(0)) is selected.
|
||||||
assert_eq!(selected, Some(KlondikePile::Tableau(Tableau::Tableau1)));
|
assert_eq!(selected, Some(PileType::Tableau(0)));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*app.world().resource::<KeyboardDragState>(),
|
*app.world().resource::<KeyboardDragState>(),
|
||||||
KeyboardDragState::Idle
|
KeyboardDragState::Idle
|
||||||
@@ -1134,7 +1117,7 @@ mod tests {
|
|||||||
// Manually focus Tableau(0) so we don't depend on Tab.
|
// Manually focus Tableau(0) so we don't depend on Tab.
|
||||||
app.world_mut()
|
app.world_mut()
|
||||||
.resource_mut::<SelectionState>()
|
.resource_mut::<SelectionState>()
|
||||||
.selected_pile = Some(KlondikePile::Tableau(Tableau::Tableau1));
|
.selected_pile = Some(PileType::Tableau(0));
|
||||||
|
|
||||||
press_key(&mut app, KeyCode::Enter);
|
press_key(&mut app, KeyCode::Enter);
|
||||||
app.update();
|
app.update();
|
||||||
@@ -1149,7 +1132,7 @@ mod tests {
|
|||||||
legal_destinations,
|
legal_destinations,
|
||||||
destination_index,
|
destination_index,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(source_pile, KlondikePile::Tableau(Tableau::Tableau1));
|
assert_eq!(source_pile, PileType::Tableau(0));
|
||||||
assert_eq!(count, 1);
|
assert_eq!(count, 1);
|
||||||
assert_eq!(cards, vec![100]);
|
assert_eq!(cards, vec![100]);
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1164,16 +1147,95 @@ mod tests {
|
|||||||
// DragState must mirror the lifted cards and carry the keyboard sentinel.
|
// DragState must mirror the lifted cards and carry the keyboard sentinel.
|
||||||
let drag = app.world().resource::<DragState>();
|
let drag = app.world().resource::<DragState>();
|
||||||
assert_eq!(drag.cards, vec![100]);
|
assert_eq!(drag.cards, vec![100]);
|
||||||
assert_eq!(
|
assert_eq!(drag.origin_pile, Some(PileType::Tableau(0)));
|
||||||
drag.origin_pile,
|
|
||||||
Some(KlondikePile::Tableau(Tableau::Tableau1))
|
|
||||||
);
|
|
||||||
assert_eq!(drag.active_touch_id, Some(KEYBOARD_DRAG_TOUCH_ID));
|
assert_eq!(drag.active_touch_id, Some(KEYBOARD_DRAG_TOUCH_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test 3 — Arrow keys in `Lifted` cycle through *legal* destinations
|
/// Test 3 — Arrow keys in `Lifted` cycle through *legal* destinations
|
||||||
/// only (foundations and tableaus that pass `can_place_on_*`), and
|
/// only (foundations and tableaus that pass `can_place_on_*`), and
|
||||||
/// wrap at the end of the list.
|
/// wrap at the end of the list.
|
||||||
|
#[test]
|
||||||
|
fn arrow_in_lifted_cycles_legal_destinations_only() {
|
||||||
|
let mut app = drag_test_app();
|
||||||
|
install_state(&mut app, deterministic_state());
|
||||||
|
app.update();
|
||||||
|
app.world_mut()
|
||||||
|
.resource_mut::<SelectionState>()
|
||||||
|
.selected_pile = Some(PileType::Tableau(0));
|
||||||
|
press_key(&mut app, KeyCode::Enter);
|
||||||
|
app.update();
|
||||||
|
|
||||||
|
// Capture the destination list. For the deterministic state the 5♣
|
||||||
|
// (black) can land on 6♥ (T1) or 6♦ (T2) — both red, rank one
|
||||||
|
// higher. Verify that the destinations are exactly those tableaus
|
||||||
|
// (in cycle order T1 then T2).
|
||||||
|
let initial_dests: Vec<PileType> = match app.world().resource::<KeyboardDragState>() {
|
||||||
|
KeyboardDragState::Lifted {
|
||||||
|
legal_destinations, ..
|
||||||
|
} => legal_destinations.clone(),
|
||||||
|
_ => panic!("expected Lifted"),
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
initial_dests,
|
||||||
|
vec![PileType::Tableau(1), PileType::Tableau(2)],
|
||||||
|
"5♣ must legally accept exactly T1 (6♥) and T2 (6♦) as destinations",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify all are legal (defensive — equivalent to the assertion
|
||||||
|
// above but documented as a per-destination check).
|
||||||
|
for dest in &initial_dests {
|
||||||
|
let bottom_card = Card {
|
||||||
|
id: 100,
|
||||||
|
suit: Suit::Clubs,
|
||||||
|
rank: Rank::Five,
|
||||||
|
face_up: true,
|
||||||
|
};
|
||||||
|
let pile = app
|
||||||
|
.world()
|
||||||
|
.resource::<GameStateResource>()
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.get(dest)
|
||||||
|
.unwrap()
|
||||||
|
.clone();
|
||||||
|
assert!(
|
||||||
|
can_place_on_tableau(&bottom_card, &pile),
|
||||||
|
"destination {dest:?} must be legal for the lifted stack",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial focused destination = first entry.
|
||||||
|
assert_eq!(
|
||||||
|
app.world()
|
||||||
|
.resource::<KeyboardDragState>()
|
||||||
|
.focused_destination(),
|
||||||
|
Some(&PileType::Tableau(1)),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ArrowRight → next.
|
||||||
|
clear_input(&mut app);
|
||||||
|
press_key(&mut app, KeyCode::ArrowRight);
|
||||||
|
app.update();
|
||||||
|
assert_eq!(
|
||||||
|
app.world()
|
||||||
|
.resource::<KeyboardDragState>()
|
||||||
|
.focused_destination(),
|
||||||
|
Some(&PileType::Tableau(2)),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ArrowRight again → wraps to first.
|
||||||
|
clear_input(&mut app);
|
||||||
|
press_key(&mut app, KeyCode::ArrowRight);
|
||||||
|
app.update();
|
||||||
|
assert_eq!(
|
||||||
|
app.world()
|
||||||
|
.resource::<KeyboardDragState>()
|
||||||
|
.focused_destination(),
|
||||||
|
Some(&PileType::Tableau(1)),
|
||||||
|
"destination index must wrap back to 0 after exhausting the list",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Test 4 — Enter while `Lifted` with a destination focused fires
|
/// Test 4 — Enter while `Lifted` with a destination focused fires
|
||||||
/// exactly one `MoveRequestEvent` and resets the state machine to
|
/// exactly one `MoveRequestEvent` and resets the state machine to
|
||||||
/// `Idle` with `DragState` cleared.
|
/// `Idle` with `DragState` cleared.
|
||||||
@@ -1184,7 +1246,7 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
app.world_mut()
|
app.world_mut()
|
||||||
.resource_mut::<SelectionState>()
|
.resource_mut::<SelectionState>()
|
||||||
.selected_pile = Some(KlondikePile::Tableau(Tableau::Tableau1));
|
.selected_pile = Some(PileType::Tableau(0));
|
||||||
press_key(&mut app, KeyCode::Enter);
|
press_key(&mut app, KeyCode::Enter);
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
@@ -1204,7 +1266,7 @@ mod tests {
|
|||||||
|
|
||||||
let events = collect_move_events(&mut app);
|
let events = collect_move_events(&mut app);
|
||||||
assert_eq!(events.len(), 1, "exactly one MoveRequestEvent must fire");
|
assert_eq!(events.len(), 1, "exactly one MoveRequestEvent must fire");
|
||||||
assert_eq!(events[0].from, KlondikePile::Tableau(Tableau::Tableau1));
|
assert_eq!(events[0].from, PileType::Tableau(0));
|
||||||
assert_eq!(events[0].to, expected_dest);
|
assert_eq!(events[0].to, expected_dest);
|
||||||
assert_eq!(events[0].count, 1);
|
assert_eq!(events[0].count, 1);
|
||||||
|
|
||||||
@@ -1229,7 +1291,7 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
app.world_mut()
|
app.world_mut()
|
||||||
.resource_mut::<SelectionState>()
|
.resource_mut::<SelectionState>()
|
||||||
.selected_pile = Some(KlondikePile::Tableau(Tableau::Tableau1));
|
.selected_pile = Some(PileType::Tableau(0));
|
||||||
press_key(&mut app, KeyCode::Enter);
|
press_key(&mut app, KeyCode::Enter);
|
||||||
app.update();
|
app.update();
|
||||||
assert!(app.world().resource::<KeyboardDragState>().is_lifted());
|
assert!(app.world().resource::<KeyboardDragState>().is_lifted());
|
||||||
@@ -1246,7 +1308,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.world().resource::<SelectionState>().selected_pile,
|
app.world().resource::<SelectionState>().selected_pile,
|
||||||
Some(KlondikePile::Tableau(Tableau::Tableau1)),
|
Some(PileType::Tableau(0)),
|
||||||
"Esc on lifted must keep SelectionState intact (source-pick mode)",
|
"Esc on lifted must keep SelectionState intact (source-pick mode)",
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
@@ -1269,7 +1331,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let mut drag = app.world_mut().resource_mut::<DragState>();
|
let mut drag = app.world_mut().resource_mut::<DragState>();
|
||||||
drag.cards = vec![100];
|
drag.cards = vec![100];
|
||||||
drag.origin_pile = Some(KlondikePile::Tableau(Tableau::Tableau1));
|
drag.origin_pile = Some(PileType::Tableau(0));
|
||||||
drag.committed = true;
|
drag.committed = true;
|
||||||
drag.active_touch_id = None;
|
drag.active_touch_id = None;
|
||||||
}
|
}
|
||||||
@@ -1302,7 +1364,7 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
app.world_mut()
|
app.world_mut()
|
||||||
.resource_mut::<SelectionState>()
|
.resource_mut::<SelectionState>()
|
||||||
.selected_pile = Some(KlondikePile::Tableau(Tableau::Tableau1));
|
.selected_pile = Some(PileType::Tableau(0));
|
||||||
press_key(&mut app, KeyCode::Enter);
|
press_key(&mut app, KeyCode::Enter);
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
@@ -1311,7 +1373,7 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.world().resource::<SelectionState>().selected_pile,
|
app.world().resource::<SelectionState>().selected_pile,
|
||||||
Some(KlondikePile::Tableau(Tableau::Tableau1)),
|
Some(PileType::Tableau(0)),
|
||||||
"first Esc only cancels the lift",
|
"first Esc only cancels the lift",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ use solitaire_data::{
|
|||||||
|
|
||||||
use solitaire_data::settings::SyncBackend;
|
use solitaire_data::settings::SyncBackend;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::assets::user_theme_dir;
|
use crate::assets::user_theme_dir;
|
||||||
use crate::events::{
|
use crate::events::{
|
||||||
DeleteAccountRequestEvent, InfoToastEvent, ManualSyncRequestEvent, SyncConfigureRequestEvent,
|
DeleteAccountRequestEvent, InfoToastEvent, ManualSyncRequestEvent, SyncConfigureRequestEvent,
|
||||||
@@ -33,9 +32,9 @@ use crate::events::{
|
|||||||
use crate::font_plugin::FontResource;
|
use crate::font_plugin::FontResource;
|
||||||
use crate::progress_plugin::ProgressResource;
|
use crate::progress_plugin::ProgressResource;
|
||||||
use crate::resources::{SettingsScrollPos, SyncStatus, SyncStatusResource};
|
use crate::resources::{SettingsScrollPos, SyncStatus, SyncStatusResource};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
use crate::theme::{
|
||||||
use crate::theme::{ImportError, import_theme, refresh_registry};
|
ImportError, ThemeThumbnailCache, ThemeThumbnailPair, import_theme, refresh_registry,
|
||||||
use crate::theme::{ThemeThumbnailCache, ThemeThumbnailPair};
|
};
|
||||||
use crate::ui_focus::{FocusGroup, FocusRow, Focusable, FocusedButton};
|
use crate::ui_focus::{FocusGroup, FocusRow, Focusable, FocusedButton};
|
||||||
use crate::ui_modal::{
|
use crate::ui_modal::{
|
||||||
ButtonVariant, ModalButton, ModalScrim, spawn_modal, spawn_modal_actions, spawn_modal_button,
|
ButtonVariant, ModalButton, ModalScrim, spawn_modal, spawn_modal_actions, spawn_modal_button,
|
||||||
@@ -256,7 +255,6 @@ enum SettingsButton {
|
|||||||
/// local-only mode.
|
/// local-only mode.
|
||||||
ToggleAnalytics,
|
ToggleAnalytics,
|
||||||
/// Scan `user_theme_dir()` for new `.zip` files and import each one.
|
/// Scan `user_theme_dir()` for new `.zip` files and import each one.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
ScanThemes,
|
ScanThemes,
|
||||||
SyncNow,
|
SyncNow,
|
||||||
/// Open the sync-server Connect modal (shown when backend = Local).
|
/// Open the sync-server Connect modal (shown when backend = Local).
|
||||||
@@ -319,7 +317,6 @@ impl SettingsButton {
|
|||||||
SettingsButton::SelectCardBack(_) => 70,
|
SettingsButton::SelectCardBack(_) => 70,
|
||||||
SettingsButton::SelectBackground(_) => 80,
|
SettingsButton::SelectBackground(_) => 80,
|
||||||
SettingsButton::SelectTheme(_) => 85,
|
SettingsButton::SelectTheme(_) => 85,
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
SettingsButton::ScanThemes => 86,
|
SettingsButton::ScanThemes => 86,
|
||||||
// Sync section
|
// Sync section
|
||||||
SettingsButton::SyncNow => 90,
|
SettingsButton::SyncNow => 90,
|
||||||
@@ -407,7 +404,6 @@ impl Plugin for SettingsPlugin {
|
|||||||
sync_settings_panel_visibility,
|
sync_settings_panel_visibility,
|
||||||
handle_settings_buttons,
|
handle_settings_buttons,
|
||||||
handle_sync_buttons,
|
handle_sync_buttons,
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
handle_scan_themes,
|
handle_scan_themes,
|
||||||
update_sync_status_text,
|
update_sync_status_text,
|
||||||
update_card_back_text,
|
update_card_back_text,
|
||||||
@@ -1258,7 +1254,6 @@ fn handle_settings_buttons(
|
|||||||
changed.write(SettingsChangedEvent(settings.0.clone()));
|
changed.write(SettingsChangedEvent(settings.0.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
SettingsButton::ScanThemes => {
|
SettingsButton::ScanThemes => {
|
||||||
// Handled by `handle_scan_themes`.
|
// Handled by `handle_scan_themes`.
|
||||||
}
|
}
|
||||||
@@ -1862,7 +1857,6 @@ fn spawn_settings_panel(
|
|||||||
font_res,
|
font_res,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
import_themes_row(body, font_res);
|
import_themes_row(body, font_res);
|
||||||
|
|
||||||
// --- Privacy (only shown when a Matomo URL is configured) ---
|
// --- Privacy (only shown when a Matomo URL is configured) ---
|
||||||
@@ -2647,7 +2641,6 @@ fn value_text_font(font_res: Option<&FontResource>) -> TextFont {
|
|||||||
/// [`InfoToastEvent`] is fired per imported theme. `IdCollision` errors (theme
|
/// [`InfoToastEvent`] is fired per imported theme. `IdCollision` errors (theme
|
||||||
/// already installed) are silently skipped; all other errors produce a warning
|
/// already installed) are silently skipped; all other errors produce a warning
|
||||||
/// toast. A final toast tells the player to reopen Settings to see new themes.
|
/// toast. A final toast tells the player to reopen Settings to see new themes.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn handle_scan_themes(
|
fn handle_scan_themes(
|
||||||
interaction_query: Query<(&Interaction, &SettingsButton), Changed<Interaction>>,
|
interaction_query: Query<(&Interaction, &SettingsButton), Changed<Interaction>>,
|
||||||
mut toast: MessageWriter<InfoToastEvent>,
|
mut toast: MessageWriter<InfoToastEvent>,
|
||||||
@@ -2726,7 +2719,6 @@ fn handle_scan_themes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
/// A small pill-shaped settings button, matching the style used in `sync_row`.
|
/// A small pill-shaped settings button, matching the style used in `sync_row`.
|
||||||
fn pill_button(
|
fn pill_button(
|
||||||
parent: &mut ChildSpawnerCommands,
|
parent: &mut ChildSpawnerCommands,
|
||||||
@@ -2767,7 +2759,6 @@ fn pill_button(
|
|||||||
/// then presses the button. [`handle_scan_themes`] picks them up, validates,
|
/// then presses the button. [`handle_scan_themes`] picks them up, validates,
|
||||||
/// and installs them. Reopen Settings to see newly imported themes in the
|
/// and installs them. Reopen Settings to see newly imported themes in the
|
||||||
/// card-theme picker.
|
/// card-theme picker.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn import_themes_row(parent: &mut ChildSpawnerCommands, font_res: Option<&FontResource>) {
|
fn import_themes_row(parent: &mut ChildSpawnerCommands, font_res: Option<&FontResource>) {
|
||||||
let caption_font = TextFont {
|
let caption_font = TextFont {
|
||||||
font: font_res.map(|f| f.0.clone()).unwrap_or_default(),
|
font: font_res.map(|f| f.0.clone()).unwrap_or_default(),
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::WindowResized;
|
use bevy::window::WindowResized;
|
||||||
use klondike::{Foundation, KlondikePile, Tableau};
|
|
||||||
use solitaire_core::card::Suit;
|
use solitaire_core::card::Suit;
|
||||||
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
use crate::events::{HintVisualEvent, StateChangedEvent};
|
use crate::events::{HintVisualEvent, StateChangedEvent};
|
||||||
use crate::hud_plugin::HudVisibility;
|
use crate::hud_plugin::HudVisibility;
|
||||||
@@ -54,7 +54,7 @@ pub struct TableBackground;
|
|||||||
|
|
||||||
/// Marker component attached to each of the 13 empty-pile placeholders.
|
/// Marker component attached to each of the 13 empty-pile placeholders.
|
||||||
#[derive(Component, Debug, Clone)]
|
#[derive(Component, Debug, Clone)]
|
||||||
pub struct PileMarker(pub KlondikePile);
|
pub struct PileMarker(pub PileType);
|
||||||
|
|
||||||
/// Attached to a `PileMarker` entity when it has been temporarily tinted gold
|
/// Attached to a `PileMarker` entity when it has been temporarily tinted gold
|
||||||
/// as a hint destination. Stores the remaining countdown and the original sprite
|
/// as a hint destination. Stores the remaining countdown and the original sprite
|
||||||
@@ -265,13 +265,14 @@ fn spawn_pile_markers(commands: &mut Commands, layout: &Layout) {
|
|||||||
let marker_size = layout.card_size;
|
let marker_size = layout.card_size;
|
||||||
let font_size = layout.card_size.x * 0.28;
|
let font_size = layout.card_size.x * 0.28;
|
||||||
|
|
||||||
let mut piles: Vec<KlondikePile> = Vec::with_capacity(12);
|
let mut piles: Vec<PileType> = Vec::with_capacity(13);
|
||||||
piles.push(KlondikePile::Stock);
|
piles.push(PileType::Stock);
|
||||||
for foundation in foundations() {
|
piles.push(PileType::Waste);
|
||||||
piles.push(KlondikePile::Foundation(foundation));
|
for slot in 0..4_u8 {
|
||||||
|
piles.push(PileType::Foundation(slot));
|
||||||
}
|
}
|
||||||
for tableau in tableaus() {
|
for i in 0..7 {
|
||||||
piles.push(KlondikePile::Tableau(tableau));
|
piles.push(PileType::Tableau(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
for pile in piles {
|
for pile in piles {
|
||||||
@@ -283,14 +284,14 @@ fn spawn_pile_markers(commands: &mut Commands, layout: &Layout) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Transform::from_xyz(pos.x, pos.y, Z_PILE_MARKER),
|
Transform::from_xyz(pos.x, pos.y, Z_PILE_MARKER),
|
||||||
PileMarker(pile),
|
PileMarker(pile.clone()),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Tableau markers show "K" (only a King may start an empty column).
|
// Tableau markers show "K" (only a King may start an empty column).
|
||||||
// Foundation markers show "A" (only an Ace may claim an empty slot).
|
// Foundation markers show "A" (only an Ace may claim an empty slot).
|
||||||
// Neither label carries a suit because any suit may start any slot.
|
// Neither label carries a suit because any suit may start any slot.
|
||||||
match &pile {
|
match &pile {
|
||||||
KlondikePile::Tableau(_) => {
|
PileType::Tableau(_) => {
|
||||||
entity.with_children(|b| {
|
entity.with_children(|b| {
|
||||||
b.spawn((
|
b.spawn((
|
||||||
Text2d::new("K"),
|
Text2d::new("K"),
|
||||||
@@ -303,7 +304,7 @@ fn spawn_pile_markers(commands: &mut Commands, layout: &Layout) {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
KlondikePile::Foundation(_) => {
|
PileType::Foundation(_) => {
|
||||||
entity.with_children(|b| {
|
entity.with_children(|b| {
|
||||||
b.spawn((
|
b.spawn((
|
||||||
Text2d::new("A"),
|
Text2d::new("A"),
|
||||||
@@ -479,7 +480,11 @@ fn sync_pile_marker_visibility(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (pile_marker, mut visibility) in markers.iter_mut() {
|
for (pile_marker, mut visibility) in markers.iter_mut() {
|
||||||
let is_empty = pile_cards(&game.0, &pile_marker.0).is_empty();
|
let is_empty = game
|
||||||
|
.0
|
||||||
|
.piles
|
||||||
|
.get(&pile_marker.0)
|
||||||
|
.is_none_or(|pile| pile.cards.is_empty());
|
||||||
*visibility = if is_empty {
|
*visibility = if is_empty {
|
||||||
Visibility::Inherited
|
Visibility::Inherited
|
||||||
} else {
|
} else {
|
||||||
@@ -488,44 +493,6 @@ fn sync_pile_marker_visibility(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pile_cards(
|
|
||||||
game: &solitaire_core::game_state::GameState,
|
|
||||||
pile: &KlondikePile,
|
|
||||||
) -> Vec<solitaire_core::card::Card> {
|
|
||||||
match pile {
|
|
||||||
KlondikePile::Stock => {
|
|
||||||
let stock = game.stock_cards();
|
|
||||||
if stock.is_empty() {
|
|
||||||
game.waste_cards()
|
|
||||||
} else {
|
|
||||||
stock
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => game.pile(*pile),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn foundations() -> [Foundation; 4] {
|
|
||||||
[
|
|
||||||
Foundation::Foundation1,
|
|
||||||
Foundation::Foundation2,
|
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn tableaus() -> [Tableau; 7] {
|
|
||||||
[
|
|
||||||
Tableau::Tableau1,
|
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -543,14 +510,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn table_plugin_spawns_twelve_pile_markers() {
|
fn table_plugin_spawns_thirteen_pile_markers() {
|
||||||
let mut app = headless_app();
|
let mut app = headless_app();
|
||||||
let count = app
|
let count = app
|
||||||
.world_mut()
|
.world_mut()
|
||||||
.query::<&PileMarker>()
|
.query::<&PileMarker>()
|
||||||
.iter(app.world())
|
.iter(app.world())
|
||||||
.count();
|
.count();
|
||||||
assert_eq!(count, 12);
|
assert_eq!(count, 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -573,7 +540,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn every_pile_marker_has_unique_type() {
|
fn every_pile_marker_has_unique_type() {
|
||||||
let mut app = headless_app();
|
let mut app = headless_app();
|
||||||
let mut types: Vec<KlondikePile> = app
|
let mut types: Vec<PileType> = app
|
||||||
.world_mut()
|
.world_mut()
|
||||||
.query::<&PileMarker>()
|
.query::<&PileMarker>()
|
||||||
.iter(app.world())
|
.iter(app.world())
|
||||||
@@ -581,15 +548,15 @@ mod tests {
|
|||||||
.collect();
|
.collect();
|
||||||
types.sort_by_key(|p| format!("{p:?}"));
|
types.sort_by_key(|p| format!("{p:?}"));
|
||||||
types.dedup();
|
types.dedup();
|
||||||
assert_eq!(types.len(), 12);
|
assert_eq!(types.len(), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pile_markers_hide_when_pile_is_occupied() {
|
fn pile_markers_hide_when_pile_is_occupied() {
|
||||||
// After a fresh deal: the 7 tableau piles + the stock pile are
|
// After a fresh deal: the 7 tableau piles + the stock pile are
|
||||||
// occupied; the 4 foundation piles are empty. The visibility-by-
|
// all occupied; the 4 foundation piles + the waste pile are
|
||||||
// occupancy system must hide the first 8 markers and keep the
|
// empty. The visibility-by-occupancy system must hide the
|
||||||
// last 4 visible. This implements
|
// first 8 markers and keep the last 5 visible. This implements
|
||||||
// the "remain visible only where a pile is empty" invariant
|
// the "remain visible only where a pile is empty" invariant
|
||||||
// in the module-level doc comment that was previously
|
// in the module-level doc comment that was previously
|
||||||
// declared but not enforced — pile markers used to always
|
// declared but not enforced — pile markers used to always
|
||||||
@@ -603,8 +570,8 @@ mod tests {
|
|||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let mut q = app.world_mut().query::<(&PileMarker, &Visibility)>();
|
let mut q = app.world_mut().query::<(&PileMarker, &Visibility)>();
|
||||||
let mut hidden_piles: Vec<KlondikePile> = Vec::new();
|
let mut hidden_piles: Vec<PileType> = Vec::new();
|
||||||
let mut visible_piles: Vec<KlondikePile> = Vec::new();
|
let mut visible_piles: Vec<PileType> = Vec::new();
|
||||||
for (marker, visibility) in q.iter(app.world()) {
|
for (marker, visibility) in q.iter(app.world()) {
|
||||||
if matches!(visibility, Visibility::Hidden) {
|
if matches!(visibility, Visibility::Hidden) {
|
||||||
hidden_piles.push(marker.0.clone());
|
hidden_piles.push(marker.0.clone());
|
||||||
@@ -619,31 +586,19 @@ mod tests {
|
|||||||
8,
|
8,
|
||||||
"stock + 7 tableau piles should hide their markers post-deal",
|
"stock + 7 tableau piles should hide their markers post-deal",
|
||||||
);
|
);
|
||||||
assert!(hidden_piles.contains(&KlondikePile::Stock));
|
assert!(hidden_piles.contains(&PileType::Stock));
|
||||||
for tableau in [
|
for i in 0..7 {
|
||||||
Tableau::Tableau1,
|
|
||||||
Tableau::Tableau2,
|
|
||||||
Tableau::Tableau3,
|
|
||||||
Tableau::Tableau4,
|
|
||||||
Tableau::Tableau5,
|
|
||||||
Tableau::Tableau6,
|
|
||||||
Tableau::Tableau7,
|
|
||||||
] {
|
|
||||||
assert!(
|
assert!(
|
||||||
hidden_piles.contains(&KlondikePile::Tableau(tableau)),
|
hidden_piles.contains(&PileType::Tableau(i)),
|
||||||
"{tableau:?} marker should be hidden — it has cards",
|
"tableau {i} marker should be hidden — it has cards",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 empty piles: foundations only.
|
// 5 empty piles: waste + 4 foundations.
|
||||||
assert_eq!(visible_piles.len(), 4);
|
assert_eq!(visible_piles.len(), 5);
|
||||||
for foundation in [
|
assert!(visible_piles.contains(&PileType::Waste));
|
||||||
Foundation::Foundation1,
|
for i in 0..4_u8 {
|
||||||
Foundation::Foundation2,
|
assert!(visible_piles.contains(&PileType::Foundation(i)));
|
||||||
Foundation::Foundation3,
|
|
||||||
Foundation::Foundation4,
|
|
||||||
] {
|
|
||||||
assert!(visible_piles.contains(&KlondikePile::Foundation(foundation)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
//! handles directly on card entities, so a theme switch propagates on
|
//! handles directly on card entities, so a theme switch propagates on
|
||||||
//! the next frame without re-spawning anything.
|
//! the next frame without re-spawning anything.
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub mod importer;
|
pub mod importer;
|
||||||
pub mod loader;
|
pub mod loader;
|
||||||
pub mod manifest;
|
pub mod manifest;
|
||||||
@@ -29,7 +28,6 @@ use thiserror::Error;
|
|||||||
|
|
||||||
use solitaire_core::card::{Rank, Suit};
|
use solitaire_core::card::{Rank, Suit};
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use importer::{ImportError, ThemeId, import_theme, import_theme_into};
|
pub use importer::{ImportError, ThemeId, import_theme, import_theme_into};
|
||||||
pub use loader::{CardThemeLoader, CardThemeLoaderError};
|
pub use loader::{CardThemeLoader, CardThemeLoaderError};
|
||||||
pub use manifest::ThemeManifest;
|
pub use manifest::ThemeManifest;
|
||||||
|
|||||||
@@ -22,15 +22,11 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use bevy::log::warn;
|
use bevy::log::warn;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
use bevy::prelude::{App, Plugin, Resource, Startup};
|
||||||
use bevy::prelude::Startup;
|
|
||||||
use bevy::prelude::{App, Plugin, Resource};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::ThemeMeta;
|
use super::ThemeMeta;
|
||||||
use crate::assets::DARK_THEME_MANIFEST_URL;
|
use crate::assets::{DARK_THEME_MANIFEST_URL, user_theme_dir};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
use crate::assets::user_theme_dir;
|
|
||||||
|
|
||||||
/// One entry in the [`ThemeRegistry`] — the data the picker UI needs
|
/// One entry in the [`ThemeRegistry`] — the data the picker UI needs
|
||||||
/// to render a row and load the theme on selection.
|
/// to render a row and load the theme on selection.
|
||||||
@@ -89,18 +85,13 @@ pub struct ThemeRegistryPlugin;
|
|||||||
|
|
||||||
impl Plugin for ThemeRegistryPlugin {
|
impl Plugin for ThemeRegistryPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.init_resource::<ThemeRegistry>();
|
app.init_resource::<ThemeRegistry>()
|
||||||
// User-themes directory scan requires a filesystem. On wasm32 there
|
.add_systems(Startup, build_registry_on_startup);
|
||||||
// is no filesystem so the scan is skipped; the bundled default theme
|
|
||||||
// (from the EmbeddedAssetRegistry) is all that's available.
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
app.add_systems(Startup, build_registry_on_startup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads `user_theme_dir()` and replaces the registry's contents with
|
/// Reads `user_theme_dir()` and replaces the registry's contents with
|
||||||
/// the bundled default plus every valid user theme.
|
/// the bundled default plus every valid user theme.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn build_registry_on_startup(mut registry: bevy::ecs::system::ResMut<ThemeRegistry>) {
|
fn build_registry_on_startup(mut registry: bevy::ecs::system::ResMut<ThemeRegistry>) {
|
||||||
*registry = build_registry(&user_theme_dir());
|
*registry = build_registry(&user_theme_dir());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
//! was closed, the file is treated as missing.
|
//! was closed, the file is treated as missing.
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use chrono::Utc;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use solitaire_core::game_state::GameMode;
|
use solitaire_core::game_state::GameMode;
|
||||||
@@ -223,9 +222,9 @@ fn auto_deal_on_time_attack_win(
|
|||||||
/// the system time predates the epoch (impossible under any sane clock,
|
/// the system time predates the epoch (impossible under any sane clock,
|
||||||
/// but the fallback keeps the function infallible).
|
/// but the fallback keeps the function infallible).
|
||||||
fn current_unix_secs() -> u64 {
|
fn current_unix_secs() -> u64 {
|
||||||
// Use chrono so this works on wasm32 (chrono has the `wasmbind` feature;
|
SystemTime::now()
|
||||||
// std::time::SystemTime panics on wasm32-unknown-unknown).
|
.duration_since(UNIX_EPOCH)
|
||||||
Utc::now().timestamp().max(0) as u64
|
.map_or(0, |d| d.as_secs())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Periodically persists the live `TimeAttackResource` to
|
/// Periodically persists the live `TimeAttackResource` to
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
use bevy::ecs::message::MessageReader;
|
use bevy::ecs::message::MessageReader;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use klondike::KlondikePile;
|
use solitaire_core::pile::PileType;
|
||||||
|
|
||||||
use crate::card_plugin::CardEntity;
|
use crate::card_plugin::CardEntity;
|
||||||
use crate::events::StateChangedEvent;
|
use crate::events::StateChangedEvent;
|
||||||
@@ -50,7 +50,7 @@ use crate::ui_theme::ACCENT_PRIMARY;
|
|||||||
#[derive(Resource, Debug, Default)]
|
#[derive(Resource, Debug, Default)]
|
||||||
pub struct TouchSelectionState {
|
pub struct TouchSelectionState {
|
||||||
/// Currently selected source pile and the card ids to move (bottom-to-top).
|
/// Currently selected source pile and the card ids to move (bottom-to-top).
|
||||||
pub selected: Option<(KlondikePile, Vec<u32>)>,
|
pub selected: Option<(PileType, Vec<u32>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TouchSelectionState {
|
impl TouchSelectionState {
|
||||||
@@ -60,12 +60,12 @@ impl TouchSelectionState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Takes the current selection, leaving `selected` as `None`.
|
/// Takes the current selection, leaving `selected` as `None`.
|
||||||
pub fn take(&mut self) -> Option<(KlondikePile, Vec<u32>)> {
|
pub fn take(&mut self) -> Option<(PileType, Vec<u32>)> {
|
||||||
self.selected.take()
|
self.selected.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the current selection.
|
/// Sets the current selection.
|
||||||
pub fn set(&mut self, pile: KlondikePile, cards: Vec<u32>) {
|
pub fn set(&mut self, pile: PileType, cards: Vec<u32>) {
|
||||||
self.selected = Some((pile, cards));
|
self.selected = Some((pile, cards));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +77,8 @@ impl TouchSelectionState {
|
|||||||
|
|
||||||
/// Marker component placed on the highlight sprite child of a selected source card.
|
/// Marker component placed on the highlight sprite child of a selected source card.
|
||||||
///
|
///
|
||||||
/// Despawned and respawned by [`update_touch_selection_highlight`] whenever
|
/// Despawned and respawned each frame by [`update_touch_selection_highlight`] so
|
||||||
/// [`TouchSelectionState`] changes. The system is gated on `is_changed()` so it
|
/// stale highlights never linger after a game-state change.
|
||||||
/// is a no-op every frame that the selection is stable.
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct TouchSelectionHighlight;
|
pub struct TouchSelectionHighlight;
|
||||||
|
|
||||||
@@ -92,15 +91,16 @@ pub struct TouchSelectionPlugin;
|
|||||||
|
|
||||||
impl Plugin for TouchSelectionPlugin {
|
impl Plugin for TouchSelectionPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.init_resource::<TouchSelectionState>().add_systems(
|
app.init_resource::<TouchSelectionState>()
|
||||||
Update,
|
.add_systems(
|
||||||
(
|
Update,
|
||||||
clear_touch_selection_on_state_change,
|
(
|
||||||
update_touch_selection_highlight,
|
clear_touch_selection_on_state_change,
|
||||||
)
|
update_touch_selection_highlight,
|
||||||
.chain()
|
)
|
||||||
.after(GameMutation),
|
.chain()
|
||||||
);
|
.after(GameMutation),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +121,9 @@ pub(crate) fn clear_touch_selection_on_state_change(
|
|||||||
|
|
||||||
/// Maintains the `TouchSelectionHighlight` outline sprite on the selected source card.
|
/// Maintains the `TouchSelectionHighlight` outline sprite on the selected source card.
|
||||||
///
|
///
|
||||||
/// Rebuilds the highlight set only when [`TouchSelectionState`] or the layout
|
/// All existing `TouchSelectionHighlight` entities are despawned each frame and
|
||||||
/// actually changes — not every frame. Existing highlights are despawned first,
|
/// a new one is spawned on the top card of the selected pile (if any). This
|
||||||
/// then a fresh highlight is spawned on every card in the selected stack.
|
/// matches the pattern used by `selection_plugin::update_selection_highlight`.
|
||||||
pub(crate) fn update_touch_selection_highlight(
|
pub(crate) fn update_touch_selection_highlight(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
selection: Res<TouchSelectionState>,
|
selection: Res<TouchSelectionState>,
|
||||||
@@ -131,12 +131,6 @@ pub(crate) fn update_touch_selection_highlight(
|
|||||||
highlights: Query<Entity, With<TouchSelectionHighlight>>,
|
highlights: Query<Entity, With<TouchSelectionHighlight>>,
|
||||||
layout: Option<Res<LayoutResource>>,
|
layout: Option<Res<LayoutResource>>,
|
||||||
) {
|
) {
|
||||||
// Skip when neither the selection nor the layout changed this frame.
|
|
||||||
let layout_changed = layout.as_ref().map(|l| l.is_changed()).unwrap_or(false);
|
|
||||||
if !selection.is_changed() && !layout_changed {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Despawn stale highlights first.
|
// Despawn stale highlights first.
|
||||||
for entity in &highlights {
|
for entity in &highlights {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
@@ -192,7 +186,6 @@ fn spawn_touch_highlight(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use klondike::Tableau;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn selection_state_default_is_idle() {
|
fn selection_state_default_is_idle() {
|
||||||
@@ -204,12 +197,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn set_and_take_roundtrip() {
|
fn set_and_take_roundtrip() {
|
||||||
let mut state = TouchSelectionState::default();
|
let mut state = TouchSelectionState::default();
|
||||||
state.set(KlondikePile::Tableau(Tableau::Tableau1), vec![1, 2, 3]);
|
state.set(PileType::Tableau(0), vec![1, 2, 3]);
|
||||||
assert!(state.has_selection());
|
assert!(state.has_selection());
|
||||||
let taken = state.take();
|
let taken = state.take();
|
||||||
assert!(taken.is_some());
|
assert!(taken.is_some());
|
||||||
let (pile, cards) = taken.unwrap();
|
let (pile, cards) = taken.unwrap();
|
||||||
assert_eq!(pile, KlondikePile::Tableau(Tableau::Tableau1));
|
assert_eq!(pile, PileType::Tableau(0));
|
||||||
assert_eq!(cards, vec![1, 2, 3]);
|
assert_eq!(cards, vec![1, 2, 3]);
|
||||||
assert!(!state.has_selection());
|
assert!(!state.has_selection());
|
||||||
}
|
}
|
||||||
@@ -217,7 +210,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn clear_removes_selection() {
|
fn clear_removes_selection() {
|
||||||
let mut state = TouchSelectionState::default();
|
let mut state = TouchSelectionState::default();
|
||||||
state.set(KlondikePile::Stock, vec![42]);
|
state.set(PileType::Waste, vec![42]);
|
||||||
state.clear();
|
state.clear();
|
||||||
assert!(!state.has_selection());
|
assert!(!state.has_selection());
|
||||||
}
|
}
|
||||||
@@ -232,10 +225,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn set_overwrites_previous_selection() {
|
fn set_overwrites_previous_selection() {
|
||||||
let mut state = TouchSelectionState::default();
|
let mut state = TouchSelectionState::default();
|
||||||
state.set(KlondikePile::Tableau(Tableau::Tableau1), vec![1]);
|
state.set(PileType::Tableau(0), vec![1]);
|
||||||
state.set(KlondikePile::Tableau(Tableau::Tableau4), vec![7, 8]);
|
state.set(PileType::Tableau(3), vec![7, 8]);
|
||||||
let (pile, cards) = state.take().unwrap();
|
let (pile, cards) = state.take().unwrap();
|
||||||
assert_eq!(pile, KlondikePile::Tableau(Tableau::Tableau4));
|
assert_eq!(pile, PileType::Tableau(3));
|
||||||
assert_eq!(cards, vec![7, 8]);
|
assert_eq!(cards, vec![7, 8]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use solitaire_core::game_state::GameMode;
|
use solitaire_core::game_state::GameMode;
|
||||||
use solitaire_core::klondike_adapter::compute_time_bonus;
|
use solitaire_core::scoring::compute_time_bonus;
|
||||||
use solitaire_data::AnimSpeed;
|
use solitaire_data::AnimSpeed;
|
||||||
|
|
||||||
use crate::achievement_plugin::display_name_for;
|
use crate::achievement_plugin::display_name_for;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
|
|
||||||
# Copy only the files needed to build the server crate.
|
# Copy only the files needed to build the server crate.
|
||||||
# Layer order: workspace manifests first so dependency fetches are cached.
|
# Layer order: workspace manifests first so dependency fetches are cached.
|
||||||
COPY .cargo/config.toml ./.cargo/config.toml
|
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
COPY solitaire_core/Cargo.toml ./solitaire_core/Cargo.toml
|
COPY solitaire_core/Cargo.toml ./solitaire_core/Cargo.toml
|
||||||
COPY solitaire_sync/Cargo.toml ./solitaire_sync/Cargo.toml
|
COPY solitaire_sync/Cargo.toml ./solitaire_sync/Cargo.toml
|
||||||
@@ -22,19 +21,17 @@ COPY solitaire_server/Cargo.toml ./solitaire_server/Cargo.toml
|
|||||||
COPY solitaire_app/Cargo.toml ./solitaire_app/Cargo.toml
|
COPY solitaire_app/Cargo.toml ./solitaire_app/Cargo.toml
|
||||||
COPY solitaire_assetgen/Cargo.toml ./solitaire_assetgen/Cargo.toml
|
COPY solitaire_assetgen/Cargo.toml ./solitaire_assetgen/Cargo.toml
|
||||||
COPY solitaire_wasm/Cargo.toml ./solitaire_wasm/Cargo.toml
|
COPY solitaire_wasm/Cargo.toml ./solitaire_wasm/Cargo.toml
|
||||||
COPY solitaire_web/Cargo.toml ./solitaire_web/Cargo.toml
|
|
||||||
|
|
||||||
# Stub every workspace crate so `cargo fetch --locked` resolves the full
|
# Stub every workspace crate so `cargo fetch --locked` resolves the full
|
||||||
# dependency graph without requiring source files beyond Cargo.toml.
|
# dependency graph without requiring source files beyond Cargo.toml.
|
||||||
RUN for crate in solitaire_core solitaire_sync solitaire_data solitaire_engine \
|
RUN for crate in solitaire_core solitaire_sync solitaire_data solitaire_engine \
|
||||||
solitaire_server solitaire_app solitaire_assetgen solitaire_wasm solitaire_web; do \
|
solitaire_server solitaire_app solitaire_assetgen solitaire_wasm; do \
|
||||||
mkdir -p $crate/src && echo "pub fn _stub() {}" > $crate/src/lib.rs; \
|
mkdir -p $crate/src && echo "pub fn _stub() {}" > $crate/src/lib.rs; \
|
||||||
done && \
|
done && \
|
||||||
echo "fn main() {}" > solitaire_server/src/main.rs && \
|
echo "fn main() {}" > solitaire_server/src/main.rs && \
|
||||||
echo "fn main() {}" > solitaire_app/src/main.rs && \
|
echo "fn main() {}" > solitaire_app/src/main.rs && \
|
||||||
echo "fn main() {}" > solitaire_assetgen/src/main.rs
|
echo "fn main() {}" > solitaire_assetgen/src/main.rs
|
||||||
|
|
||||||
# Registry config comes from .cargo/config.toml copied above.
|
|
||||||
RUN cargo fetch --locked
|
RUN cargo fetch --locked
|
||||||
|
|
||||||
# Now copy real source and build in release mode.
|
# Now copy real source and build in release mode.
|
||||||
|
|||||||
@@ -214,11 +214,6 @@ fn build_router_inner(state: AppState, rate_limit: bool) -> Router {
|
|||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/play",
|
"/play",
|
||||||
get(|| async { Html(include_str!("../web/play.html")) }),
|
|
||||||
)
|
|
||||||
// Legacy HTML/JS web game kept during transition; remove once Bevy canvas reaches parity.
|
|
||||||
.route(
|
|
||||||
"/play-classic",
|
|
||||||
get(|| async { Html(include_str!("../web/game.html")) }),
|
get(|| async { Html(include_str!("../web/game.html")) }),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
@@ -249,11 +244,11 @@ fn build_router_inner(state: AppState, rate_limit: bool) -> Router {
|
|||||||
|
|
||||||
const CSP: &str = concat!(
|
const CSP: &str = concat!(
|
||||||
"default-src 'self'; ",
|
"default-src 'self'; ",
|
||||||
"script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://analytics.aleshym.co; ",
|
"script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; ",
|
||||||
"style-src 'self' 'unsafe-inline'; ",
|
"style-src 'self' 'unsafe-inline'; ",
|
||||||
"font-src 'self'; ",
|
"font-src 'self'; ",
|
||||||
"img-src 'self' data: https://analytics.aleshym.co; ",
|
"img-src 'self' data:; ",
|
||||||
"connect-src 'self' https://analytics.aleshym.co; ",
|
"connect-src 'self'; ",
|
||||||
"object-src 'none'; ",
|
"object-src 'none'; ",
|
||||||
"frame-ancestors 'none'",
|
"frame-ancestors 'none'",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -196,11 +196,14 @@ async fn update_leaderboard_if_opted_in(
|
|||||||
user_id: &str,
|
user_id: &str,
|
||||||
payload: &SyncPayload,
|
payload: &SyncPayload,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
let opted_in = sqlx::query!("SELECT leaderboard_opt_in FROM users WHERE id = ?", user_id)
|
let opted_in = sqlx::query!(
|
||||||
.fetch_optional(pool)
|
"SELECT leaderboard_opt_in FROM users WHERE id = ?",
|
||||||
.await?
|
user_id
|
||||||
.map(|r| r.leaderboard_opt_in)
|
)
|
||||||
.unwrap_or(0);
|
.fetch_optional(pool)
|
||||||
|
.await?
|
||||||
|
.map(|r| r.leaderboard_opt_in)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
if opted_in != 1 {
|
if opted_in != 1 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
+18
-256
@@ -176,12 +176,9 @@ async function bootstrap() {
|
|||||||
if (saved) {
|
if (saved) {
|
||||||
showResumeDialog(saved);
|
showResumeDialog(saved);
|
||||||
} else {
|
} else {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const rawSeed = Number(params.get("seed"));
|
const urlSeed = params.has("seed") ? Number(params.get("seed")) : randomSeed();
|
||||||
const urlSeed = params.has("seed") && Number.isFinite(rawSeed) && rawSeed > 0
|
drawThree = params.has("draw3");
|
||||||
? Math.floor(rawSeed)
|
|
||||||
: randomSeed();
|
|
||||||
drawThree = params.has("draw3");
|
|
||||||
chkDraw3.checked = drawThree;
|
chkDraw3.checked = drawThree;
|
||||||
startGame(urlSeed);
|
startGame(urlSeed);
|
||||||
}
|
}
|
||||||
@@ -396,16 +393,8 @@ function render(s) {
|
|||||||
stopTimer();
|
stopTimer();
|
||||||
if (acTimer) { clearInterval(acTimer); acTimer = null; }
|
if (acTimer) { clearInterval(acTimer); acTimer = null; }
|
||||||
if (noMovesBanner) noMovesBanner.classList.add("hidden");
|
if (noMovesBanner) noMovesBanner.classList.add("hidden");
|
||||||
// Delay slightly so the last card's CSS transition finishes before
|
showWin(s);
|
||||||
// the win overlay covers the board. Card transitions are ~260 ms.
|
|
||||||
setTimeout(() => showWin(s), 320);
|
|
||||||
} else {
|
} else {
|
||||||
// If the player undid out of auto-complete, restart the timer —
|
|
||||||
// stopTimer() was called when auto-complete began, but no code path
|
|
||||||
// before here restarts it after an undo.
|
|
||||||
if (!s.is_auto_completable && !timerInterval) {
|
|
||||||
startTimer();
|
|
||||||
}
|
|
||||||
saveState();
|
saveState();
|
||||||
const noMoves = !s.has_moves && !s.is_auto_completable;
|
const noMoves = !s.has_moves && !s.is_auto_completable;
|
||||||
if (noMovesBanner) noMovesBanner.classList.toggle("hidden", !noMoves);
|
if (noMovesBanner) noMovesBanner.classList.toggle("hidden", !noMoves);
|
||||||
@@ -440,34 +429,20 @@ function showWin(s) {
|
|||||||
submitReplay(s);
|
submitReplay(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildReplayPayload(s) {
|
async function submitReplay(s) {
|
||||||
if (!game || !s) return null;
|
const token = localStorage.getItem('fs_token');
|
||||||
let moves;
|
if (!token) return;
|
||||||
try {
|
const payload = {
|
||||||
moves = game.replay_moves();
|
schema_version: 1,
|
||||||
if (!Array.isArray(moves) || moves.length === 0) return null;
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("fs: replay export failed", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
schema_version: 2,
|
|
||||||
seed: Math.round(game.seed()),
|
seed: Math.round(game.seed()),
|
||||||
draw_mode: drawThree ? "DrawThree" : "DrawOne",
|
draw_mode: drawThree ? "DrawThree" : "DrawOne",
|
||||||
mode: "Classic",
|
mode: "Classic",
|
||||||
time_seconds: Math.max(1, elapsedSecs),
|
time_seconds: elapsedSecs,
|
||||||
final_score: s.score,
|
final_score: s.score,
|
||||||
|
move_count: s.move_count,
|
||||||
recorded_at: new Date().toISOString().slice(0, 10),
|
recorded_at: new Date().toISOString().slice(0, 10),
|
||||||
moves,
|
moves: [],
|
||||||
win_move_index: moves.length - 1,
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
async function submitReplay(s) {
|
|
||||||
const token = localStorage.getItem('fs_token');
|
|
||||||
if (!token || !game) return;
|
|
||||||
const payload = buildReplayPayload(s);
|
|
||||||
if (!payload) return;
|
|
||||||
try {
|
try {
|
||||||
await fetch('/api/replays', {
|
await fetch('/api/replays', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -492,12 +467,7 @@ function flashIllegal(cardIds) {
|
|||||||
for (const id of cardIds) {
|
for (const id of cardIds) {
|
||||||
const el = cardEls.get(id);
|
const el = cardEls.get(id);
|
||||||
if (!el) continue;
|
if (!el) continue;
|
||||||
// Remove any in-progress shake before restarting. Reading offsetWidth
|
// Store current translate so the shake keyframe can reference it.
|
||||||
// forces a synchronous layout flush so the browser sees the removal
|
|
||||||
// before we re-add the class, restarting the animation from frame 0.
|
|
||||||
el.classList.remove("illegal");
|
|
||||||
el.style.removeProperty("--card-tx");
|
|
||||||
void el.offsetWidth; // flush layout — do not remove
|
|
||||||
el.style.setProperty("--card-tx", el.style.transform || "translate(0,0)");
|
el.style.setProperty("--card-tx", el.style.transform || "translate(0,0)");
|
||||||
el.classList.add("illegal");
|
el.classList.add("illegal");
|
||||||
el.addEventListener("animationend", () => {
|
el.addEventListener("animationend", () => {
|
||||||
@@ -526,34 +496,11 @@ function attachHandlers() {
|
|||||||
syncThemeButton();
|
syncThemeButton();
|
||||||
if (game) render(game.state());
|
if (game) render(game.state());
|
||||||
});
|
});
|
||||||
const doDraw = () => { const r = game.draw(); if (r.ok) render(r.snapshot); };
|
|
||||||
|
|
||||||
document.addEventListener("keydown", (e) => {
|
document.addEventListener("keydown", (e) => {
|
||||||
const tag = e.target?.tagName;
|
if (e.target.tagName === "INPUT") return;
|
||||||
if (e.target?.isContentEditable || tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
|
if (e.key === "z" || e.key === "Z") doUndo();
|
||||||
if (e.key === "z" || e.key === "Z" || e.key === "u" || e.key === "U") {
|
if (e.key === "n" || e.key === "N") startGame(randomSeed());
|
||||||
e.preventDefault();
|
|
||||||
doUndo();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (e.key === "n" || e.key === "N") {
|
|
||||||
startGame(randomSeed());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!e.repeat && (e.code === "Space" || e.key === " ")) {
|
|
||||||
e.preventDefault();
|
|
||||||
doDraw();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pause the game timer while the tab is hidden so background time doesn't
|
|
||||||
// inflate the player's recorded game duration.
|
|
||||||
document.addEventListener("visibilitychange", () => {
|
|
||||||
if (document.hidden) {
|
|
||||||
stopTimer();
|
|
||||||
} else if (snap && !snap.is_won && !snap.is_auto_completable) {
|
|
||||||
startTimer();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
board.addEventListener("pointerdown", onPointerDown);
|
board.addEventListener("pointerdown", onPointerDown);
|
||||||
@@ -759,7 +706,7 @@ function onPointerCancel() {
|
|||||||
|
|
||||||
// ── Click / dblclick ──────────────────────────────────────────────────────────
|
// ── Click / dblclick ──────────────────────────────────────────────────────────
|
||||||
function onBoardClick(e) {
|
function onBoardClick(e) {
|
||||||
if (drag || snap?.is_won) return;
|
if (drag) return;
|
||||||
const { x: bx, y: by } = boardRelative(e.clientX, e.clientY);
|
const { x: bx, y: by } = boardRelative(e.clientX, e.clientY);
|
||||||
const stock = PILE_ORIGIN.stock;
|
const stock = PILE_ORIGIN.stock;
|
||||||
if (bx >= stock.x && bx <= stock.x + CARD_W && by >= stock.y && by <= stock.y + CARD_H) {
|
if (bx >= stock.x && bx <= stock.x + CARD_W && by >= stock.y && by <= stock.y + CARD_H) {
|
||||||
@@ -794,7 +741,7 @@ function smartMove(pileName, fromIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onBoardDblClick(e) {
|
function onBoardDblClick(e) {
|
||||||
if (drag || snap?.is_won) return;
|
if (drag) return;
|
||||||
const { x: bx, y: by } = boardRelative(e.clientX, e.clientY);
|
const { x: bx, y: by } = boardRelative(e.clientX, e.clientY);
|
||||||
const hit = hitTestCard(bx, by);
|
const hit = hitTestCard(bx, by);
|
||||||
if (!hit || !hit.card.face_up) return;
|
if (!hit || !hit.card.face_up) return;
|
||||||
@@ -835,191 +782,6 @@ async function loadAvatar() {
|
|||||||
} catch { /* not signed in — avatar stays hidden */ }
|
} catch { /* not signed in — avatar stays hidden */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
function debugStateKey(state) {
|
|
||||||
if (!state) return "missing";
|
|
||||||
if (Array.isArray(state.stock) || Array.isArray(state.tableaus)) {
|
|
||||||
const out = [];
|
|
||||||
const push = cards => {
|
|
||||||
for (const c of cards || []) out.push(`${c.id}:${c.face_up ? 1 : 0}`);
|
|
||||||
out.push("|");
|
|
||||||
};
|
|
||||||
push(state.stock);
|
|
||||||
push(state.waste);
|
|
||||||
for (const pile of state.foundations || []) push(pile);
|
|
||||||
for (const pile of state.tableaus || []) push(pile);
|
|
||||||
return out.join("");
|
|
||||||
}
|
|
||||||
return JSON.stringify(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
function orderBaselineDebugMoves(legalMoves) {
|
|
||||||
const foundationSingles = [];
|
|
||||||
const moveKind = [];
|
|
||||||
const rest = [];
|
|
||||||
for (let i = 0; i < legalMoves.length; i++) {
|
|
||||||
const move = legalMoves[i];
|
|
||||||
if (
|
|
||||||
move?.kind === "move" &&
|
|
||||||
typeof move.to === "string" &&
|
|
||||||
move.to.startsWith("foundation-") &&
|
|
||||||
move.count === 1
|
|
||||||
) {
|
|
||||||
foundationSingles.push(i);
|
|
||||||
} else if (move?.kind === "move") {
|
|
||||||
moveKind.push(i);
|
|
||||||
} else {
|
|
||||||
rest.push(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [...foundationSingles, ...moveKind, ...rest];
|
|
||||||
}
|
|
||||||
|
|
||||||
function runDebugAutoplay(options = {}) {
|
|
||||||
if (!game) return { ok: false, reason: "game_not_ready", step: 0 };
|
|
||||||
|
|
||||||
const maxSteps = Number.isInteger(options.maxSteps) && options.maxSteps > 0 ? options.maxSteps : 220;
|
|
||||||
const maxVisitsPerState =
|
|
||||||
Number.isInteger(options.maxVisitsPerState) && options.maxVisitsPerState > 0
|
|
||||||
? options.maxVisitsPerState
|
|
||||||
: 2;
|
|
||||||
const policy = options.policy === "baseline" ? "baseline" : "loop_aware";
|
|
||||||
const seen = new Map();
|
|
||||||
|
|
||||||
function simulatedVisitCount(legalMoveIndex) {
|
|
||||||
let saved = null;
|
|
||||||
try {
|
|
||||||
saved = game.serialize();
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (typeof saved !== "string" || saved.length === 0) return null;
|
|
||||||
|
|
||||||
const applied = game.debug_apply_legal_move(legalMoveIndex);
|
|
||||||
if (!applied?.ok) {
|
|
||||||
try { game = SolitaireGame.from_saved(saved); } catch {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const nextKey = debugStateKey(applied.snapshot);
|
|
||||||
try {
|
|
||||||
game = SolitaireGame.from_saved(saved);
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return seen.get(nextKey) || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let step = 0; step < maxSteps; step++) {
|
|
||||||
const snap = game.debug_snapshot();
|
|
||||||
if (!snap?.state || !snap?.invariants) {
|
|
||||||
return { ok: false, reason: "missing_snapshot", step };
|
|
||||||
}
|
|
||||||
if (!snap.invariants.state_ok) {
|
|
||||||
return { ok: false, reason: "invariant_failed", step, snapshot: snap };
|
|
||||||
}
|
|
||||||
if (snap.state.is_won) {
|
|
||||||
return { ok: true, terminal: "won", step, snapshot: snap };
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = debugStateKey(snap.state);
|
|
||||||
const visits = (seen.get(key) || 0) + 1;
|
|
||||||
seen.set(key, visits);
|
|
||||||
if (visits > maxVisitsPerState) {
|
|
||||||
return { ok: true, terminal: "cycle", step, snapshot: snap };
|
|
||||||
}
|
|
||||||
|
|
||||||
const legalMoves = game.debug_legal_moves();
|
|
||||||
if (!Array.isArray(legalMoves) || legalMoves.length === 0) {
|
|
||||||
return { ok: true, terminal: "no_moves", step, snapshot: snap };
|
|
||||||
}
|
|
||||||
|
|
||||||
const ordered = orderBaselineDebugMoves(legalMoves);
|
|
||||||
let idx = ordered[0];
|
|
||||||
if (policy === "loop_aware" && ordered.length > 1) {
|
|
||||||
let bestIdx = ordered[0];
|
|
||||||
let bestVisitCount = Number.MAX_SAFE_INTEGER;
|
|
||||||
for (const candidate of ordered) {
|
|
||||||
const visitCount = simulatedVisitCount(candidate);
|
|
||||||
if (visitCount === null) continue;
|
|
||||||
if (visitCount < bestVisitCount) {
|
|
||||||
bestVisitCount = visitCount;
|
|
||||||
bestIdx = candidate;
|
|
||||||
if (visitCount === 0) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
idx = bestIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = game.debug_apply_legal_move(idx);
|
|
||||||
if (!result?.ok) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
reason: "apply_failed",
|
|
||||||
step,
|
|
||||||
idx,
|
|
||||||
error: result?.error ?? "unknown_error",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (result.snapshot) render(result.snapshot);
|
|
||||||
}
|
|
||||||
|
|
||||||
const finalSnap = game.debug_snapshot();
|
|
||||||
return { ok: !!finalSnap?.invariants?.state_ok, terminal: "step_budget", snapshot: finalSnap };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Debug API (engine-first automation surface) ───────────────────────────────
|
|
||||||
// Playwright and other automation harnesses use this object instead of pixel
|
|
||||||
// analysis or hardcoded coordinates. Every operation delegates to the Rust
|
|
||||||
// rules engine exported by `solitaire_wasm`.
|
|
||||||
window.__FERROUS_DEBUG__ = {
|
|
||||||
seed() {
|
|
||||||
return game ? Math.round(game.seed()) : null;
|
|
||||||
},
|
|
||||||
state() {
|
|
||||||
return game ? game.state() : null;
|
|
||||||
},
|
|
||||||
legalMoves() {
|
|
||||||
return game ? game.debug_legal_moves() : [];
|
|
||||||
},
|
|
||||||
moveHistory() {
|
|
||||||
return game ? game.debug_move_history() : [];
|
|
||||||
},
|
|
||||||
snapshot() {
|
|
||||||
return game ? game.debug_snapshot() : null;
|
|
||||||
},
|
|
||||||
applyLegalMove(index) {
|
|
||||||
if (!game) return { ok: false, error: "game_not_ready" };
|
|
||||||
const result = game.debug_apply_legal_move(index);
|
|
||||||
if (result?.ok && result.snapshot) render(result.snapshot);
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
applyMove(move) {
|
|
||||||
if (!game) return { ok: false, error: "game_not_ready" };
|
|
||||||
const payload = typeof move === "string" ? move : JSON.stringify(move);
|
|
||||||
const result = game.debug_apply_move_json(payload);
|
|
||||||
if (result?.ok && result.snapshot) render(result.snapshot);
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
failureReport() {
|
|
||||||
if (!game) return null;
|
|
||||||
const debug = game.debug_snapshot();
|
|
||||||
return {
|
|
||||||
seed: Math.round(game.seed()),
|
|
||||||
moveHistory: debug?.move_history ?? [],
|
|
||||||
currentState: debug?.state ?? game.state(),
|
|
||||||
stateJson: debug?.state_json ?? null,
|
|
||||||
legalMoves: debug?.legal_moves ?? [],
|
|
||||||
invariants: debug?.invariants ?? null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
replayPayload() {
|
|
||||||
if (!game) return null;
|
|
||||||
return buildReplayPayload(snap ?? game.state());
|
|
||||||
},
|
|
||||||
runAutoplay(options) {
|
|
||||||
return runDebugAutoplay(options);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── Start ─────────────────────────────────────────────────────────────────────
|
// ── Start ─────────────────────────────────────────────────────────────────────
|
||||||
bootstrap().catch(console.error);
|
bootstrap().catch(console.error);
|
||||||
loadAvatar();
|
loadAvatar();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -55,8 +55,6 @@ export class ReplayPlayer {
|
|||||||
* once the move list is exhausted.
|
* once the move list is exhausted.
|
||||||
*
|
*
|
||||||
* Returns `null` (not an exception) when the replay is finished.
|
* 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.
|
* Throws a JS string exception on serialisation failure.
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
@@ -122,67 +120,6 @@ export class SolitaireGame {
|
|||||||
const ret = wasm.solitairegame_auto_complete_step(this.__wbg_ptr);
|
const ret = wasm.solitairegame_auto_complete_step(this.__wbg_ptr);
|
||||||
return ret;
|
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).
|
* Draw from stock to waste (or recycle waste → stock when stock is empty).
|
||||||
* Returns `{ok, error?, snapshot?}`.
|
* Returns `{ok, error?, snapshot?}`.
|
||||||
@@ -243,21 +180,6 @@ export class SolitaireGame {
|
|||||||
SolitaireGameFinalization.register(this, this.__wbg_ptr, this);
|
SolitaireGameFinalization.register(this, this.__wbg_ptr, this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns replay moves encoded in the `solitaire_data::Replay` wire format.
|
|
||||||
*
|
|
||||||
* This derives move counts from the deterministic instruction history and
|
|
||||||
* validates that the resulting move stream replays cleanly from the current
|
|
||||||
* game's seed/draw mode.
|
|
||||||
* @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.
|
* The seed used to deal this game.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
@@ -331,9 +253,6 @@ function __wbg_get_imports() {
|
|||||||
__wbg___wbindgen_throw_9c75d47bf9e7731e: function(arg0, arg1) {
|
__wbg___wbindgen_throw_9c75d47bf9e7731e: function(arg0, arg1) {
|
||||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||||
},
|
},
|
||||||
__wbg_error_48655ee7e4756f8b: function(arg0) {
|
|
||||||
console.error(arg0);
|
|
||||||
},
|
|
||||||
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
||||||
let deferred0_0;
|
let deferred0_0;
|
||||||
let deferred0_1;
|
let deferred0_1;
|
||||||
|
|||||||
Binary file not shown.
@@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Ferrous Solitaire</title>
|
|
||||||
<style>
|
|
||||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
body { background: #000; overflow: hidden; }
|
|
||||||
#bevy-canvas { display: block; width: 100vw; height: 100vh; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas id="bevy-canvas"></canvas>
|
|
||||||
<script type="module">
|
|
||||||
import init from "/web/pkg/canvas.js";
|
|
||||||
await init();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -12,7 +12,6 @@ solitaire_core = { path = "../solitaire_core" }
|
|||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
klondike = { workspace = true }
|
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
serde-wasm-bindgen = "0.6"
|
serde-wasm-bindgen = "0.6"
|
||||||
console_error_panic_hook = { version = "0.1", optional = true }
|
console_error_panic_hook = { version = "0.1", optional = true }
|
||||||
|
|||||||
+336
-656
File diff suppressed because it is too large
Load Diff
@@ -1,23 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "solitaire_web"
|
|
||||||
version.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
solitaire_engine = { path = "../solitaire_engine" }
|
|
||||||
solitaire_data = { path = "../solitaire_data" }
|
|
||||||
# Direct dep so `bevy::` resolves in lib.rs; zero extra features so this
|
|
||||||
# contributes nothing to unification with the desktop/Android feature set.
|
|
||||||
bevy = { workspace = true }
|
|
||||||
wasm-bindgen = "0.2"
|
|
||||||
getrandom = { version = "0.3", features = ["wasm_js"] }
|
|
||||||
console_error_panic_hook = "0.1"
|
|
||||||
|
|
||||||
# webgl2 must only be enabled for the wasm target — it constrains the
|
|
||||||
# renderer to WebGL2 compatibility limits, which is wrong for native builds.
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
bevy = { workspace = true, features = ["webgl2"] }
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
//! Browser entry point for the Ferrous Solitaire Bevy WASM build.
|
|
||||||
//!
|
|
||||||
//! This crate compiles the full `solitaire_engine` to `wasm32-unknown-unknown`
|
|
||||||
//! and renders to a `<canvas id="bevy-canvas">` element. It shares the same
|
|
||||||
//! ECS code path as the desktop and Android builds; the only differences are:
|
|
||||||
//! - Audio, sync, and analytics plugins are cfg-gated out in `CoreGamePlugin`
|
|
||||||
//! on the wasm32 target (see `solitaire_engine/src/core_game_plugin.rs`).
|
|
||||||
//! - `LocalOnlyProvider` is passed as the sync provider (sync is disabled).
|
|
||||||
//! - Storage is handled automatically by `WasmStorage` (localStorage-backed),
|
|
||||||
//! wired by `CoreGamePlugin` via `default_storage_backend()`.
|
|
||||||
|
|
||||||
use bevy::asset::AssetMetaCheck;
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use bevy::render::RenderPlugin;
|
|
||||||
use bevy::render::settings::{RenderCreation, WgpuSettings, WgpuSettingsPriority};
|
|
||||||
use bevy::window::{Window, WindowPlugin};
|
|
||||||
use solitaire_data::LocalOnlyProvider;
|
|
||||||
use solitaire_engine::CoreGamePlugin;
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen(start)]
|
|
||||||
pub fn start() {
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
|
|
||||||
App::new()
|
|
||||||
.add_plugins(
|
|
||||||
DefaultPlugins
|
|
||||||
.set(WindowPlugin {
|
|
||||||
primary_window: Some(Window {
|
|
||||||
// Bind to the existing <canvas id="bevy-canvas"> in play.html.
|
|
||||||
// Without this, Bevy appends its own canvas to <body>.
|
|
||||||
canvas: Some("#bevy-canvas".into()),
|
|
||||||
// Let CSS size the canvas; Bevy follows the element's size.
|
|
||||||
fit_canvas_to_parent: true,
|
|
||||||
// Prevent the browser stealing keyboard events and scroll.
|
|
||||||
prevent_default_event_handling: true,
|
|
||||||
..default()
|
|
||||||
}),
|
|
||||||
..default()
|
|
||||||
})
|
|
||||||
// Bevy's default AssetPlugin fetches a `.meta` sidecar file for
|
|
||||||
// every asset before loading the asset itself. We don't ship
|
|
||||||
// `.meta` files, so skip the check to avoid a flood of 404s.
|
|
||||||
.set(AssetPlugin {
|
|
||||||
meta_check: AssetMetaCheck::Never,
|
|
||||||
..default()
|
|
||||||
})
|
|
||||||
// WebGL2 priority constrains naga (the shader translator) to emit
|
|
||||||
// GLES 300es-compatible GLSL. Without this, Chromium's ANGLE driver
|
|
||||||
// rejects certain shader constructs (storage buffers, tight component
|
|
||||||
// limits) causing a fatal wgpu "Shader translation error". Firefox is
|
|
||||||
// more lenient; this setting makes both browsers work identically.
|
|
||||||
.set(RenderPlugin {
|
|
||||||
render_creation: RenderCreation::Automatic(WgpuSettings {
|
|
||||||
priority: WgpuSettingsPriority::WebGL2,
|
|
||||||
..default()
|
|
||||||
}),
|
|
||||||
..default()
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
// LocalOnlyProvider disables cloud sync — correct for the web build
|
|
||||||
// since SyncPlugin is cfg-gated out on wasm32 anyway.
|
|
||||||
.add_plugins(CoreGamePlugin::new(Box::new(LocalOnlyProvider)))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user