diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4718bb3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: weekly + - package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18151c4..e39f969 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,18 @@ jobs: - uses: jetli/wasm-pack-action@v0.4.0 with: version: 'latest' - # see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions - - run: ./scripts/publish-server.sh ${{ github.event.release.tag_name }} + - uses: jetli/wasm-bindgen-action@v0.2.0 + with: + version: 'latest' + - name: Publish Server + # see https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + run: | + ./scripts/publish-server.sh ${{ github.event.release.tag_name }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish Client + # rustup target add wasm32-unknown-unknown # automatically done by wasm-pack + run: | + ./scripts/publish-client.sh ${{ github.event.release.tag_name }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 2777910..e61072d 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,10 @@ - `cd client` - `cargo run`. -### Run local web client +### Run remote with boardgamers-mono web client locally -- `cd client` -- `./build-local.sh local_client` -- `cd dist` -- `basic-http-server .` -- open `http://localhost:4000` in a browser. - -### Run remote web client locally - -- `cd client` -- `./build-remote.sh` -- `cd remote_client/dist` -- `basic-http-server .` +- `./scripts/build-remote-client.sh` +- `cd client/js/dist && basic-http-server .` - `google-chrome --disable-web-security --user-data-dir=/tmp http://localhost:8612` ### Server wrapper @@ -45,8 +35,8 @@ - `docker run -d -p 27017:27017 mongo:4.4` - `cd apps/api && pnpm seed && echo cron=1 > .env` - `pnpm dev --filter @bgs/api --filter @bgs/game-server --filter @bgs/web --filter @bgs/admin` -- admin: http://localhost:3000 (admin@test.com/password) -- user: http://localhost:8612/ (user@test.com/password) +- admin: http://localhost:3000 (admin@test.com / password) +- user: http://localhost:8612/ (user@test.com / password) old @@ -102,7 +92,7 @@ diff --git a/apps/api/app/resources.ts b/apps/api/app/resources.ts const viewer: ViewerInfo = gameInfo?.viewer?.alternate?.url && ctx.query.alternate === "1" ? gameInfo?.viewer.alternate : gameInfo.viewer; - const viewerUrl = ctx.query.customViewerUrl || viewer.url; -+ const viewerUrl = "/home/gregor/source/clash/client/remote_client/index.js"; ++ const viewerUrl = "http://127.0.0.1:4000/client.js"; ctx.body = ` @@ -148,7 +138,7 @@ GameInfo.json (for now) "preferences": [], "rules": "", "viewer": { - "url": "http://localhost:4000/client.js", + "url": "//cdn.jsdelivr.net/npm/@boardgamers/clash-client@0.0.5/client.js", "topLevelVariable": "clash", "dependencies": { "scripts": [], diff --git a/client/Cargo.lock b/client/Cargo.lock index bad4fcd..2159474 100644 --- a/client/Cargo.lock +++ b/client/Cargo.lock @@ -205,6 +205,7 @@ name = "client" version = "0.1.0" dependencies = [ "async-std", + "console_error_panic_hook", "hex2d", "itertools", "lazy_static", @@ -232,6 +233,16 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -785,6 +796,7 @@ name = "server" version = "0.1.0" dependencies = [ "async-std", + "console_error_panic_hook", "hex2d", "itertools", "quad-rand", diff --git a/client/Cargo.toml b/client/Cargo.toml index dfc53fb..8bcd9fe 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -14,15 +14,6 @@ debug = true [profile.release] debug = true -[features] -# disable file import and export -wasm = [] - -# may be needed for remote client -#[lib] -#name = "client" -#crate-type = ["cdylib", "rlib"] - [dependencies] macroquad = "0.4.2" hex2d = "1.1.0" @@ -35,6 +26,7 @@ lazy_static = "1.4.0" log = "0.4.20" async-std = "1.13.0" serde-wasm-bindgen = "0.6.5" +console_error_panic_hook = "0.1.7" [[bin]] name = "local_client" diff --git a/client/build-local.sh b/client/build-local.sh deleted file mode 100755 index 0563821..0000000 --- a/client/build-local.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# from https://gist.github.com/nicolas-sabbatini/8af10dddc96be76d2bf24fc671131add - -HELP_STRING=$( - cat <<-END - usage: build_wasm.sh PROJECT_NAME [--release] - Build script for combining a Macroquad project with wasm-bindgen, - allowing integration with the greater wasm-ecosystem. - example: ./build_wasm.sh flappy-bird - This'll go through the following steps: - 1. Build as target 'wasm32-unknown-unknown'. - 2. Create the directory 'dist' if it doesn't already exist. - 3. Run wasm-bindgen with output into the 'dist' directory. - - If the '--release' flag is provided, the build will be optimized for release. - 4. Apply patches to the output js file (detailed here: https://github.com/not-fl3/macroquad/issues/212#issuecomment-835276147). - 5. Generate coresponding 'index.html' file. - Author: Tom Solberg - Edit: Nik codes - Edit: Nobbele - Edit: profan - Edit: Nik codes - Version: 0.4 - END -) - -die() { - echo >&2 "$HELP_STRING" - echo >&2 - echo >&2 "Error: $*" - exit 1 -} - -# Parse primary commands -while [[ $# -gt 0 ]]; do - key="$1" - case $key in - --release) - RELEASE=yes - shift - ;; - - -h | --help) - echo "$HELP_STRING" - exit 0 - ;; - - *) - POSITIONAL+=("$1") - shift - ;; - esac -done - -# Restore positionals -set -- "${POSITIONAL[@]}" -[ $# -ne 1 ] && die "too many arguments provided" - -PROJECT_NAME=$1 - -HTML=$( - cat <<-END - - - - ${PROJECT_NAME} - - - - - - -
- -
- - - END -) - -OUTER=$( - cat <<-END - - - - END -) - -TARGET_DIR="target/wasm32-unknown-unknown" -# Build -echo "Building $PROJECT_NAME..." -if [ -n "$RELEASE" ]; then - cargo build --release --target wasm32-unknown-unknown --features "wasm" - TARGET_DIR="$TARGET_DIR/release" -else - cargo build --target wasm32-unknown-unknown --features "wasm" - TARGET_DIR="$TARGET_DIR/debug" -fi - -# Generate bindgen outputs -echo "Running wasm-bindgen..." - -mkdir -p dist -cp -r assets dist/ -wasm-bindgen $TARGET_DIR/"$PROJECT_NAME".wasm --out-dir dist --target web --no-typescript - -echo "Patching wasm-bindgen output..." - -# Shim to tie the thing together -sed -i "s/import \* as __wbg_star0 from 'env';//" dist/"$PROJECT_NAME".js -sed -i "s/let wasm;/let wasm; export const set_wasm = (w) => wasm = w;/" dist/"$PROJECT_NAME".js -sed -i "s/imports\['env'\] = __wbg_star0;/return imports.wbg\;/" dist/"$PROJECT_NAME".js -sed -i "s/const imports = __wbg_get_imports();/return __wbg_get_imports();/" dist/"$PROJECT_NAME".js - -# Create index from the HTML variable -echo "$HTML" >dist/iframe.html -echo "$OUTER" >dist/index.html - -echo "Done!" diff --git a/client/remote_client/.tool-versions b/client/js/.tool-versions similarity index 100% rename from client/remote_client/.tool-versions rename to client/js/.tool-versions diff --git a/client/remote_client/package-lock.json b/client/js/package-lock.json similarity index 99% rename from client/remote_client/package-lock.json rename to client/js/package-lock.json index 60b1811..8ab520f 100644 --- a/client/remote_client/package-lock.json +++ b/client/js/package-lock.json @@ -1,6 +1,6 @@ { - "name": "remote_client", - "version": "1.0.0", + "name": "@boardgamers/clash-client", + "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/client/js/package.json b/client/js/package.json new file mode 100644 index 0000000..4daf1db --- /dev/null +++ b/client/js/package.json @@ -0,0 +1,27 @@ +{ + "name": "@boardgamers/clash-client", + "description": "A client for Clash of Cultures", + "version": "0.1.0", + "license": "MIT", + "repository": { + "type": "git", + "url": "git@github.com:boardgamers/clash.git" + }, + "files": [ + "assets/", + "client.js", + "client.wasm" + ], + "main": "index.js", + "homepage": "https://www.boardgamers.space/", + "scripts": { + "build": "webpack" + }, + "devDependencies": { + "webpack": "^5.94.0", + "webpack-cli": "^5.1.4" + }, + "dependencies": { + "events": "^3.3.0" + } +} diff --git a/client/remote_client/src/control.js b/client/js/src/control.js similarity index 69% rename from client/remote_client/src/control.js rename to client/js/src/control.js index bb40b1e..6cd502b 100644 --- a/client/remote_client/src/control.js +++ b/client/js/src/control.js @@ -5,10 +5,16 @@ export class Control extends EventEmitter { super(); this.state = null; this.player_index = null; + this._assets_url = null; this.addListener("state", (data) => { this.state = data; }); + // When we receive log slices, when executing a move + this.addListener("gamelog", (logData) => { + // Ignore the log data and tell the backend we want the new state + this.emit("fetchState"); + }); this.addListener("state:updated", () => { this.emit("fetchState"); }); @@ -36,6 +42,14 @@ export class Control extends EventEmitter { send_ready() { this.emit("ready"); } + + get assets_url() { + return this._assets_url; + } + + set assets_url(value) { + this._assets_url = value; + } } export function get_control() { diff --git a/client/remote_client/src/index.js b/client/js/src/index.js similarity index 87% rename from client/remote_client/src/index.js rename to client/js/src/index.js index d37012d..e96daac 100644 --- a/client/remote_client/src/index.js +++ b/client/js/src/index.js @@ -6,7 +6,7 @@ window.clash = { const control = new Control(); window.clash_control = control; - run(selector); + run(selector, control); return control; }, diff --git a/client/remote_client/src/run.js b/client/js/src/run.js similarity index 81% rename from client/remote_client/src/run.js rename to client/js/src/run.js index a47ab89..c2f7855 100644 --- a/client/remote_client/src/run.js +++ b/client/js/src/run.js @@ -8,7 +8,7 @@ function dynamicallyLoadScript(url, onload) { document.head.appendChild(script); } -export async function run(selector) { +export async function run(selector, control) { const root = document.querySelector(selector); const canvas = document.createElement("canvas"); canvas.setAttribute("id", "glcanvas"); @@ -31,7 +31,9 @@ export async function run(selector) { version: "0.0.1", name: "wbg", }); - const url = document.head.getElementsByTagName("script")[0].src.replace("client.js", "client.wasm"); + const src = document.head.getElementsByTagName("script")[0].src; + control.assets_url = src.replace("client.js", "assets/"); + const url = src.replace("client.js", "client.wasm"); console.log("Loading wasm from", url); await load(url); }); diff --git a/client/remote_client/webpack.config.js b/client/js/webpack.config.js similarity index 100% rename from client/remote_client/webpack.config.js rename to client/js/webpack.config.js diff --git a/client/remote_client/package.json b/client/remote_client/package.json deleted file mode 100644 index 734110f..0000000 --- a/client/remote_client/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "remote_client", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "build": "webpack" - }, - "keywords": [], - "author": "", - "license": "MIT", - "devDependencies": { - "webpack": "^5.94.0", - "webpack-cli": "^5.1.4" - }, - "dependencies": { - "events": "^3.3.0" - } -} diff --git a/client/src/assets.rs b/client/src/assets.rs index af9e8aa..745b15e 100644 --- a/client/src/assets.rs +++ b/client/src/assets.rs @@ -25,21 +25,15 @@ impl Assets { let mut map: HashMap = HashMap::new(); for (t, f) in [ - (Terrain::Barren, "assets/barren.png"), - (Terrain::Mountain, "assets/mountain.png"), - (Terrain::Fertile, "assets/grassland.png"), - (Terrain::Forest, "assets/forest.png"), - (Terrain::Water, "assets/water.png"), + (Terrain::Barren, "barren.png"), + (Terrain::Mountain, "mountain.png"), + (Terrain::Fertile, "grassland.png"), + (Terrain::Forest, "forest.png"), + (Terrain::Water, "water.png"), ] { - let p = if features.local_assets { - f - } else { - // todo use asset prefix feature - &format!("http://localhost:4000/{f}") - }; - map.insert(t, load_texture(p).await.unwrap()); + let url = &features.assets_url; + map.insert(t, load_texture(&format!("{url}{f}")).await.unwrap()); } - map } } diff --git a/client/src/client.rs b/client/src/client.rs index 5df9751..eecb3b3 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -203,7 +203,7 @@ pub fn try_click(game: &Game, state: &State, player: &ShownPlayer) -> StateUpdat pub struct Features { pub import_export: bool, - pub local_assets: bool, + pub assets_url: String, } pub enum GameSyncRequest { diff --git a/client/src/client_state.rs b/client/src/client_state.rs index 5ca5701..dcf564b 100644 --- a/client/src/client_state.rs +++ b/client/src/client_state.rs @@ -233,14 +233,6 @@ impl State { false } - #[must_use] - pub fn has_modal_dialog(&self) -> bool { - !matches!( - self.active_dialog, - ActiveDialog::None | ActiveDialog::TileMenu(_) | ActiveDialog::Log - ) - } - pub fn update(&mut self, game: &Game, update: StateUpdate) -> GameSyncRequest { match update { StateUpdate::None => GameSyncRequest::None, diff --git a/client/src/local_client/bin/main.rs b/client/src/local_client/bin/main.rs index d666eea..d791185 100644 --- a/client/src/local_client/bin/main.rs +++ b/client/src/local_client/bin/main.rs @@ -6,11 +6,10 @@ use server::game::Game; #[macroquad::main("Clash")] async fn main() { set_fullscreen(true); - let wasm = cfg!(feature = "wasm"); let features = Features { - import_export: !wasm, - local_assets: !wasm, + import_export: false, + assets_url: "assets/".to_string(), }; //todo add button to decide random or fixed game diff --git a/client/src/player_ui.rs b/client/src/player_ui.rs index bdb33ea..0156b96 100644 --- a/client/src/player_ui.rs +++ b/client/src/player_ui.rs @@ -163,27 +163,25 @@ pub fn show_global_controls(game: &Game, state: &State) -> StateUpdate { if game.can_redo() && root_ui().button(vec2(1250., 320.), "Redo") { return StateUpdate::Execute(Action::Redo); } - match game.state { - GameState::Playing if root_ui().button(vec2(1200., 350.), "End Turn") => { - let left = game.actions_left; - StateUpdate::execute_with_warning( - Action::Playing(PlayingAction::EndTurn), - if left > 0 { - vec![format!("{left} actions left")] - } else { - vec![] - }, - ) - } - GameState::Playing - if !state.has_modal_dialog() - && player.can_play_action - && root_ui().button(vec2(1200., 30.), "Move Units") => - { - StateUpdate::execute(Action::Playing(PlayingAction::MoveUnits)) - } - _ => StateUpdate::None, + if player.can_control + && matches!(game.state, GameState::Playing) + && root_ui().button(vec2(1200., 350.), "End Turn") + { + let left = game.actions_left; + return StateUpdate::execute_with_warning( + Action::Playing(PlayingAction::EndTurn), + if left > 0 { + vec![format!("{left} actions left")] + } else { + vec![] + }, + ); } + + if player.can_play_action && root_ui().button(vec2(1200., 30.), "Move Units") { + return StateUpdate::execute(Action::Playing(PlayingAction::MoveUnits)); + } + StateUpdate::None } pub fn player_color(player_index: usize) -> Color { diff --git a/client/src/remote_client/bin/main.rs b/client/src/remote_client/bin/main.rs index a330359..ad4741a 100644 --- a/client/src/remote_client/bin/main.rs +++ b/client/src/remote_client/bin/main.rs @@ -2,9 +2,11 @@ use server::game::Game; use macroquad::prelude::next_frame; +extern crate console_error_panic_hook; use client::client::{init, render_and_update, Features, GameSyncRequest, GameSyncResult}; use client::client_state::State; use server::action::Action; +use std::panic; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -13,7 +15,7 @@ extern "C" { fn log(s: &str); } -#[wasm_bindgen(module = "/remote_client/src/control.js")] +#[wasm_bindgen(module = "/js/src/control.js")] extern "C" { type Control; @@ -26,10 +28,13 @@ extern "C" { fn receive_player_index(this: &Control) -> JsValue; #[wasm_bindgen(method)] - fn send_move(this: &Control, action: &str); + fn send_move(this: &Control, action: JsValue); #[wasm_bindgen(method)] fn send_ready(this: &Control); + + #[wasm_bindgen(method, getter)] + fn assets_url(this: &Control) -> String; } enum SyncState { @@ -55,14 +60,16 @@ async fn main() { #[wasm_bindgen] impl RemoteClient { pub async fn start() { + panic::set_hook(Box::new(console_error_panic_hook::hook)); + let control = get_control(); let features = Features { import_export: false, - local_assets: false, + assets_url: control.assets_url(), }; let state = init(&features).await; let mut client = RemoteClient { - control: get_control(), + control, state, sync_state: SyncState::New, game: None, @@ -118,7 +125,7 @@ impl RemoteClient { fn execute_action(&mut self, a: &Action) { if let SyncState::Playing = &self.sync_state { self.control - .send_move(serde_json::to_string(&a).unwrap().as_str()); + .send_move(serde_wasm_bindgen::to_value(&a).unwrap()); self.sync_state = SyncState::WaitingForUpdate; } else { log("cannot execute action"); diff --git a/client/src/unit_ui.rs b/client/src/unit_ui.rs index c135a6f..abac594 100644 --- a/client/src/unit_ui.rs +++ b/client/src/unit_ui.rs @@ -143,9 +143,9 @@ pub fn name(u: &UnitType) -> &str { pub fn label(unit: &Unit) -> String { let name = name(&unit.unit_type); - let res = if !unit.can_move() || (unit.unit_type == UnitType::Settler && !unit.can_attack()) { + let res = if !unit.can_move() { " (can't move) " - } else if !unit.can_attack() { + } else if !unit.can_attack() && !unit.unit_type.is_settler() { " (can't attack) " } else { "" diff --git a/client/build-remote.sh b/scripts/build-remote-client.sh similarity index 80% rename from client/build-remote.sh rename to scripts/build-remote-client.sh index 3fc75b1..a491e46 100755 --- a/client/build-remote.sh +++ b/scripts/build-remote-client.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -euo pipefail # from https://gist.github.com/nicolas-sabbatini/8af10dddc96be76d2bf24fc671131add @@ -17,6 +17,7 @@ die() { exit 1 } +RELEASE=no # Parse primary commands while [[ $# -gt 0 ]]; do key="$1" @@ -42,16 +43,18 @@ done set -- "${POSITIONAL[@]}" [ $# -ne 0 ] && die "too many arguments provided" +pushd client + PROJECT_NAME=remote_client TARGET_DIR="target/wasm32-unknown-unknown" # Build echo "Building $PROJECT_NAME..." -if [ -n "$RELEASE" ]; then - cargo build --release --target wasm32-unknown-unknown --features "wasm" +if [ "$RELEASE" == "yes" ]; then + cargo build --release --target wasm32-unknown-unknown TARGET_DIR="$TARGET_DIR/release" else - cargo build --target wasm32-unknown-unknown --features "wasm" + cargo build --target wasm32-unknown-unknown TARGET_DIR="$TARGET_DIR/debug" fi @@ -60,8 +63,6 @@ echo "Running wasm-bindgen..." mkdir -p dist -#cp remote_client/*.js dist/ - wasm-bindgen $TARGET_DIR/"$PROJECT_NAME".wasm --out-dir dist --target web --no-typescript echo "Patching wasm-bindgen output..." @@ -71,17 +72,19 @@ sed -i "s/import \* as __wbg_star0 from 'env';//" dist/"$PROJECT_NAME".js sed -i "s/let wasm;/let wasm; export const set_wasm = (w) => wasm = w;/" dist/"$PROJECT_NAME".js sed -i "s/imports\['env'\] = __wbg_star0;/return imports.wbg\;/" dist/"$PROJECT_NAME".js sed -i "s/const imports = __wbg_get_imports();/return __wbg_get_imports();/" dist/"$PROJECT_NAME".js -#sed -i "s#import { get_control }.*#import { get_control } from './control.js'#" dist/"$PROJECT_NAME".js -#rm -rf dist/snippets -pushd remote_client +pushd js mkdir -p dist rm -rf dist/* +npm install npm run build cp -r ../assets dist/ +cp package.json dist/ pushd dist mv *.wasm client.wasm popd -popd +popd # js + +popd # client echo "Done!" diff --git a/scripts/build-wasm-server.sh b/scripts/build-wasm-server.sh index 9b480e6..6d83e65 100755 --- a/scripts/build-wasm-server.sh +++ b/scripts/build-wasm-server.sh @@ -2,8 +2,32 @@ set -euo pipefail +RELEASE=no + +# Parse primary commands +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + --release) + RELEASE=yes + shift + ;; + + *) + POSITIONAL+=("$1") + shift + ;; + esac +done + +ARGS="--dev --debug" +if [ "$RELEASE" = "yes" ]; then + ARGS="" +fi + +echo "Building server with release=$RELEASE..." pushd server -wasm-pack build --target nodejs +wasm-pack build $ARGS --target nodejs popd echo "Done!" diff --git a/scripts/publish-client.sh b/scripts/publish-client.sh new file mode 100755 index 0000000..28f30c3 --- /dev/null +++ b/scripts/publish-client.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -euo pipefail + +VERSION=${1:-} +if [ -z "$VERSION" ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Building client..." +./scripts/build-remote-client.sh # --release + +echo "Publishing client..." +pushd client/js/dist +sed -i "s#\"version\": \"0.1.0\"#\"version\": \"$VERSION\"#" package.json +npm publish --access public +popd + +echo "Done!" diff --git a/scripts/publish-server.sh b/scripts/publish-server.sh index 9d20479..71d8206 100755 --- a/scripts/publish-server.sh +++ b/scripts/publish-server.sh @@ -2,14 +2,14 @@ set -euo pipefail -VERSION=$1 +VERSION=${1:-} if [ -z "$VERSION" ]; then echo "Usage: $0 " exit 1 fi echo "Building server..." -./scripts/build-wasm-server.sh +./scripts/build-wasm-server.sh --release echo "Publishing server..." pushd server diff --git a/server/Cargo.lock b/server/Cargo.lock index a6e9dea..0c0f753 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -167,6 +167,16 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -559,6 +569,7 @@ name = "server" version = "0.1.0" dependencies = [ "async-std", + "console_error_panic_hook", "hex2d", "itertools", "quad-rand", diff --git a/server/Cargo.toml b/server/Cargo.toml index 5ad907b..7abdc81 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -24,3 +24,4 @@ wasm-bindgen-futures = "0.4.33" serde-wasm-bindgen = "0.6.0" itertools = "0.13.0" quad-rand = "0.2.2" +console_error_panic_hook = "0.1.7" diff --git a/server/src/game_api_wrapper.rs b/server/src/game_api_wrapper.rs index 5459d2f..1018751 100644 --- a/server/src/game_api_wrapper.rs +++ b/server/src/game_api_wrapper.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; use wasm_bindgen::prelude::*; use crate::{game::Game, game_api}; +extern crate console_error_panic_hook; #[derive(Serialize, Deserialize)] pub struct PlayerMetaData { @@ -11,6 +12,7 @@ pub struct PlayerMetaData { } fn get_game(data: JsValue) -> Game { + console_error_panic_hook::set_once(); Game::from_data(serde_wasm_bindgen::from_value(data).expect("game should be of type game data")) }