feat(web): add browser build for TDK Pinball
Expose the existing Macroquad game as a static WASM website while preserving native desktop behavior. Native-only simulation/file-export code and the per-user filesystem save path are now separated from the browser build. The browser version uses a small WASM-only storage support crate and a Macroquad-compatible JavaScript plugin to persist the same JSON settings and high scores in localStorage. Browser audio decoding starts in an owned background coroutine so the game can render its original loading/attract screens while the embedded sounds finish loading. The checked-in web bundle contains the optimized WASM, centered black HTML shell, and build/serve instructions. Test Plan: - `just test` -- passed, 135 tests - `just clippy` -- passed - `cargo clippy --target wasm32-unknown-unknown -- -D warnings` -- passed - `cargo +nightly fmt --check` and web-storage format check -- passed - `just web-build` -- passed; packaged WASM matches the production artifact - Browser smoke test at `http://127.0.0.1:8000/` -- rendered the centered game, started gameplay, opened settings, and restored a changed language from browser storage in a fresh page with no runtime errors
This commit is contained in:
@@ -382,6 +382,7 @@ pub struct Game {
|
||||
}
|
||||
|
||||
impl Game {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn new(player_count: usize) -> Self {
|
||||
Self::new_with_seed(player_count, macroquad::rand::rand())
|
||||
}
|
||||
@@ -460,6 +461,7 @@ impl Game {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn begin_claw_scenario(&mut self, terminal_frame: u8) -> Vec<Event> {
|
||||
self.ball.in_launcher = false;
|
||||
self.ball.position = CLAW_TRIGGER_CENTER;
|
||||
@@ -469,6 +471,7 @@ impl Game {
|
||||
events
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn begin_effect_scenario(&mut self, effect: u8) {
|
||||
self.target_effect = effect.min(7);
|
||||
self.object_active[usize::from(EFFECT_SENSOR.id)] = self.target_effect != 0;
|
||||
@@ -478,6 +481,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub(crate) fn begin_target_scenario(&mut self) {
|
||||
self.ball.in_launcher = false;
|
||||
self.ball.position = vec2(170.0, 230.0);
|
||||
@@ -2024,6 +2028,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn begin_claw_capture(&mut self, terminal_frame: u8, events: &mut Vec<Event>) {
|
||||
debug_assert!(CLAW_TERMINAL_FRAMES.contains(&terminal_frame));
|
||||
if self.claw.active {
|
||||
|
||||
Reference in New Issue
Block a user