Browse Source

top level layout changes

a much cleaner separation:
- core : the core platform-independent rust game code
- client : an npm package that wraps the core code and outputs wasm
- client/www : a web-app that uses the client npm package
master
Inderjit Gill 1 year ago
parent
commit
df47091e81
47 changed files with 1153 additions and 1371 deletions
  1. +6
    -3
      .gitignore
  2. +26
    -9
      README.md
  3. +116
    -56
      client/Cargo.lock
  4. +30
    -5
      client/Cargo.toml
  5. +0
    -13
      client/benches/bench.rs
  6. +0
    -18
      client/package.json
  7. +0
    -11
      client/rust/sokoban-wasm/Cargo.toml
  8. +14
    -0
      client/src/lib.rs
  9. +17
    -0
      client/src/utils.rs
  10. +13
    -0
      client/tests/web.rs
  11. +0
    -4
      client/web/js/bootstrap.js
  12. +0
    -13
      client/webpack.config.js
  13. +5
    -0
      client/www/bootstrap.js
  14. +0
    -0
      client/www/img/sokoban_tilesheet.png
  15. +0
    -0
      client/www/img/tileset.png
  16. +1
    -0
      client/www/index.html
  17. +7
    -8
      client/www/index.js
  18. +0
    -0
      client/www/js/Audio.js
  19. +0
    -0
      client/www/js/GLRenderer.js
  20. +0
    -0
      client/www/js/Matrix.js
  21. +0
    -0
      client/www/js/Metric.js
  22. +719
    -1218
      client/www/package-lock.json
  23. +29
    -0
      client/www/package.json
  24. +0
    -0
      client/www/sfx/menu_move4.mp3
  25. +0
    -0
      client/www/sfx/pause2_in.mp3
  26. +0
    -0
      client/www/sfx/pause2_out.mp3
  27. +14
    -0
      client/www/webpack.config.js
  28. +146
    -0
      core/Cargo.lock
  29. +0
    -0
      core/Cargo.toml
  30. +3
    -3
      core/src/audio.rs
  31. +0
    -0
      core/src/config.rs
  32. +0
    -0
      core/src/controller.rs
  33. +0
    -0
      core/src/entity.rs
  34. +0
    -0
      core/src/error.rs
  35. +0
    -0
      core/src/game.rs
  36. +0
    -0
      core/src/geometry.rs
  37. +0
    -0
      core/src/history.rs
  38. +0
    -0
      core/src/host.rs
  39. +0
    -0
      core/src/level.rs
  40. +0
    -0
      core/src/level_builder.rs
  41. +0
    -0
      core/src/lib.rs
  42. +0
    -0
      core/src/mathutils.rs
  43. +0
    -0
      core/src/sprite.rs
  44. +0
    -0
      core/src/text.rs
  45. +0
    -0
      core/src/tile.rs
  46. +0
    -3
      package-lock.json
  47. +7
    -7
      server/src/main.rs

+ 6
- 3
.gitignore View File

@@ -1,8 +1,11 @@
/assets/research

/client/dist
/client/node_modules/
/client/target
/client/web/sokoban_wasm*
/client/pkg
/client/wasm-pack.log
/client/www/dist
/client/www/node_modules

/core/target

/server/target

+ 26
- 9
README.md View File

@@ -3,7 +3,24 @@ Sokoban

## Overview

core : the core game code, independent of output format (native/web etc). Written entirely in Rust

client : the web version, a wrapper around the core crate that generates wasm and js files and packages them as a local npm package in the client/pkg directory
build with:
$ wasm-pack build

client/www : an npm package that references the client npm package (in client/pkg) to build a web app. There's no rust code here it's all javascript, css and html
setup with:
$ npm install
(note: The post-install stage of npm install will symlink a reference to client/pkg, so ensure that the client has already been built)
dev with:
$ npm run start
build for production with:
$ npm run build

server : a separate rust codebase for serving the web app in client/www

(todo one day) native : a native build of Sokoban that wraps the core crate with a native sdk

## ensure that the correct toolchain is installed
```sh
@@ -11,24 +28,24 @@ $ rustup update
$ rustup install nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ cargo +nightly install wasm-bindgen-cli
$ cd client

-- installl wasm-pack --

$ cd client/www
$ npm install
```
## during dev
```sh
$ cd client
$ npm run dev:build:wasm
$ npm run dev:build
$ npm run dev:serve
$ wasm-pack build
$ cd www
$ npm run start
```
can now visit http://localhost:8080

## for 'release'
```sh
$ cd server
$ cargo run
$ cd ../client
$ npm run release:build

$ cd client/www
$ npm run start
```
can now visit http://localhost:8080

+ 116
- 56
client/Cargo.lock View File

@@ -30,6 +30,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "console_error_panic_hook"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -50,9 +59,17 @@ dependencies = [
]

[[package]]
name = "itoa"
version = "0.4.3"
name = "futures"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "js-sys"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "lazy_static"
@@ -76,6 +93,11 @@ dependencies = [
]

[[package]]
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -97,33 +119,20 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "ryu"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "serde"
version = "1.0.79"
name = "scoped-tls"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "serde_derive"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde_json"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
name = "sokoban-client"
version = "0.1.0"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sokoban-core 0.1.0",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -134,14 +143,6 @@ dependencies = [
]

[[package]]
name = "sokoban-wasm"
version = "0.1.0"
dependencies = [
"sokoban-core 0.1.0",
"wasm-bindgen 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -178,60 +179,113 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen"
version = "0.2.25"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen-macro 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.25"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-futures"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.25"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.25"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.25"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen-test"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-test-macro"
version = "0.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wee_alloc"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -258,29 +312,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6c5dd2c094474ec60a6acaf31780af270275e3153bafff2db5995b715295762e"
"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8398e64a4381e93044f63287109e5f1cb65122e63ad2f0607ec6a239d9e13464"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe"
"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
"checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28"
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
"checksum syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b10ee269228fb723234fce98e9aac0eaed2bd5f1ad2f6930e8d5b93f04445a1a"
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum wasm-bindgen 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f311aadd18256d877892bec29178d70f5c19788ecbe6c48a9a7f2577b95dcc01"
"checksum wasm-bindgen-backend 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "0cb9404593b0eaca49dfd3637645c465242e267c0f3b2043c71a0c873cf9d03a"
"checksum wasm-bindgen-macro 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "4d41d4dad37cc64374a4026f4d7b4f513f83538c14e1633b6566dda5a5c099d9"
"checksum wasm-bindgen-macro-support 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cf86d2aa910c060fbdb0396ce17cfb5f1a5bcae833bd195cf2b3911f152a90"
"checksum wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "b719b78cb42bd6376de5efd85c991cb8e3fb0cef7adf01e56cec6d8cb9e20470"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "ddabe7a233fc293b35f9754067580906c14b5a14b68da67d21ac109f8624c3fe"
"checksum wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4420cb4101491fa91a0aa488584bf359ec4d805667982d3de37ad18c1adc6c62"
"checksum wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "510541c3a3e13763785f6066ad8823f522fc214f867c1af9469092a5f740230f"
"checksum wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83b50f7b3fad6acd49da239daf5a7a358c554e94e904549f4fd2d7a34d692fb0"
"checksum wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a0970181097265052ae1822d0203412ab7ca5a0f05b8d6581c23ec31e9b99b95"
"checksum wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "251fcb2edbdc5baace161ed8ab680c6cd0ff35b50bdf3eb21afb81fd42c0eb78"
"checksum wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0cb421c529d70602b52be2ae5bf0260a718e2f69514d3841cb43e094f5c3f0f1"
"checksum wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0068543ec0dd625181605c62da925b06e8a3e51aac1c4035943717cb3c91bed2"
"checksum wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27875be1daf838fa18f3e94fd19fd12638e34615b42f56da2610c8f46be80cc6"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 30
- 5
client/Cargo.toml View File

@@ -1,9 +1,34 @@
[package]
name = "sokoban-client"
version = "0.1.0"
authors = ["Inderjit Gill <email@indy.io>"]

[workspace]
members = [
"rust/sokoban-core",
"rust/sokoban-wasm",
]
[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
cfg-if = "0.1.2"
wasm-bindgen = "0.2"
sokoban-core = { path = "../core" }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.2", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.2"

[profile.release]
# Include function names in the `.wasm` for better debugging and

+ 0
- 13
client/benches/bench.rs View File

@@ -1,13 +0,0 @@
#![feature(test)]

extern crate test;
extern crate wasm_tetris;

#[bench]
fn universe_ticks(b: &mut test::Bencher) {
let mut universe = wasm_game_of_life::Universe::new();

b.iter(|| {
universe.tick();
});
}

+ 0
- 18
client/package.json View File

@@ -1,18 +0,0 @@
{
"scripts": {
"dev:serve": "webpack-dev-server --port 8060",
"dev:build": "webpack --mode=development --progress",
"dev:build:wasm": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/sokoban_wasm.wasm --out-dir web",
"release:serve": "cd rust/sokoban-serve && cargo run",
"release:build": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/sokoban_wasm.wasm --out-dir web && webpack --mode=production --progress && cp index.html dist/index.html && mkdirp dist/web && cp -r web/img dist/web/img && cp -r web/sfx dist/web/sfx"
},
"devDependencies": {
"webpack": "4.16.1",
"webpack-cli": "3.1.0",
"webpack-dev-server": "3.1.4",
"mkdirp": "0.5.1"
},
"dependencies": {
"howler": "2.0.14"
}
}

+ 0
- 11
client/rust/sokoban-wasm/Cargo.toml View File

@@ -1,11 +0,0 @@
[package]
name = "sokoban-wasm"
version = "0.1.0"
authors = ["Inderjit Gill <email@indy.io>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2.25"
sokoban-core = { path = "../sokoban-core" }

client/rust/sokoban-wasm/src/lib.rs → client/src/lib.rs View File

@@ -1,9 +1,13 @@
#![allow(dead_code)]
#![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names, too_many_arguments))]

extern crate cfg_if;
extern crate sokoban_core;
extern crate wasm_bindgen;

mod utils;

use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;

use sokoban_core::audio::AudioConfig;
@@ -14,6 +18,16 @@ use sokoban_core::game::Game;
use sokoban_core::geometry::Geometry;
use sokoban_core::host::Host;

cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
if #[cfg(feature = "wee_alloc")] {
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
}
}

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]

+ 17
- 0
client/src/utils.rs View File

@@ -0,0 +1,17 @@
use cfg_if::cfg_if;

cfg_if! {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook;
pub use self::console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}

+ 13
- 0
client/tests/web.rs View File

@@ -0,0 +1,13 @@
//! Test suite for the Web and headless browsers.

#![cfg(target_arch = "wasm32")]

extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn pass() {
assert_eq!(1 + 1, 2);
}

+ 0
- 4
client/web/js/bootstrap.js View File

@@ -1,4 +0,0 @@
const index = import("./index");
index.then(() => {
console.log("Loaded...");
});

+ 0
- 13
client/webpack.config.js View File

@@ -1,13 +0,0 @@
const path = require("path");

module.exports = {
entry: "./web/js/bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
optimization: {
minimize: false
},
mode: "development"
};

+ 5
- 0
client/www/bootstrap.js View File

@@ -0,0 +1,5 @@
// A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again.
import("./index.js")
.catch(e => console.error("Error importing `index.js`:", e));

client/web/img/sokoban_tilesheet.png → client/www/img/sokoban_tilesheet.png View File


client/web/img/tileset.png → client/www/img/tileset.png View File


client/index.html → client/www/index.html View File

@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>

client/web/js/index.js → client/www/index.js View File

@@ -1,12 +1,13 @@
import { Bridge, BridgeConfig } from "../sokoban_wasm";
import { memory } from "../sokoban_wasm_bg";
import { GLRenderer } from "./GLRenderer";
import { Audio } from "./Audio";
import { Metric } from "./Metric";
import { Bridge, BridgeConfig } from "sokoban-client";
import { memory } from "sokoban-client/sokoban_client_bg";

import { GLRenderer } from "./js/GLRenderer";
import { Audio } from "./js/Audio";
import { Metric } from "./js/Metric";

let gState = {
canvasId: 'render-canvas',
tilesetFilename: '/web/img/sokoban_tilesheet.png',
tilesetFilename: '/img/sokoban_tilesheet.png',

bridgeConfig: undefined,
bridge: undefined,
@@ -198,6 +199,4 @@ function main() {
// gState.bridge.free();
}



main();

client/web/js/Audio.js → client/www/js/Audio.js View File


client/web/js/GLRenderer.js → client/www/js/GLRenderer.js View File


client/web/js/Matrix.js → client/www/js/Matrix.js View File


client/web/js/Metric.js → client/www/js/Metric.js View File


client/www/package-lock.json
File diff suppressed because it is too large
View File


+ 29
- 0
client/www/package.json View File

@@ -0,0 +1,29 @@
{
"name": "sokoban-client-www",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"postinstall": "symlink-dir '../pkg' 'node_modules/sokoban-client'",
"build": "webpack --config webpack.config.js",
"start": "webpack-dev-server"
},
"keywords": [
"webassembly",
"wasm",
"rust",
"webpack"
],
"author": "Inderjit Gill <email@indy.io>",
"license": "(MIT OR Apache-2.0)",
"devDependencies": {
"symlink-dir": "2.0.0",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"copy-webpack-plugin": "^4.5.2"
},
"dependencies": {
"howler": "2.0.14"
}
}

client/web/sfx/menu_move4.mp3 → client/www/sfx/menu_move4.mp3 View File


client/web/sfx/pause2_in.mp3 → client/www/sfx/pause2_in.mp3 View File


client/web/sfx/pause2_out.mp3 → client/www/sfx/pause2_out.mp3 View File


+ 14
- 0
client/www/webpack.config.js View File

@@ -0,0 +1,14 @@
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require('path');

module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development",
plugins: [
new CopyWebpackPlugin(['index.html'])
],
};

+ 146
- 0
core/Cargo.lock View File

@@ -0,0 +1,146 @@
[[package]]
name = "backtrace"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "backtrace-sys"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cc"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "cfg-if"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "failure"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure_derive"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "libc"
version = "0.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "quote"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rustc-demangle"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "sokoban-core"
version = "0.1.0"
dependencies = [
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.15.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synstructure"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
"checksum quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5829244f52738cfee93b3a165c1911388675be000c888d2fae620dee8fa5b"
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
"checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

client/rust/sokoban-core/Cargo.toml → core/Cargo.toml View File


client/rust/sokoban-core/src/audio.rs → core/src/audio.rs View File

@@ -20,15 +20,15 @@ impl AudioConfig {
tracks: vec![
AudioTrackInfo {
id: SoundEffect::PauseIn as i32,
path: "web/sfx/pause2_in.mp3".to_owned(),
path: "sfx/pause2_in.mp3".to_owned(),
},
AudioTrackInfo {
id: SoundEffect::PauseOut as i32,
path: "web/sfx/pause2_out.mp3".to_owned(),
path: "sfx/pause2_out.mp3".to_owned(),
},
AudioTrackInfo {
id: SoundEffect::MenuMove as i32,
path: "web/sfx/menu_move4.mp3".to_owned(),
path: "sfx/menu_move4.mp3".to_owned(),
},
],
}

client/rust/sokoban-core/src/config.rs → core/src/config.rs View File


client/rust/sokoban-core/src/controller.rs → core/src/controller.rs View File


client/rust/sokoban-core/src/entity.rs → core/src/entity.rs View File


client/rust/sokoban-core/src/error.rs → core/src/error.rs View File


client/rust/sokoban-core/src/game.rs → core/src/game.rs View File


client/rust/sokoban-core/src/geometry.rs → core/src/geometry.rs View File


client/rust/sokoban-core/src/history.rs → core/src/history.rs View File


client/rust/sokoban-core/src/host.rs → core/src/host.rs View File


client/rust/sokoban-core/src/level.rs → core/src/level.rs View File


client/rust/sokoban-core/src/level_builder.rs → core/src/level_builder.rs View File


client/rust/sokoban-core/src/lib.rs → core/src/lib.rs View File


client/rust/sokoban-core/src/mathutils.rs → core/src/mathutils.rs View File


client/rust/sokoban-core/src/sprite.rs → core/src/sprite.rs View File


client/rust/sokoban-core/src/text.rs → core/src/text.rs View File


client/rust/sokoban-core/src/tile.rs → core/src/tile.rs View File


+ 0
- 3
package-lock.json View File

@@ -1,3 +0,0 @@
{
"lockfileVersion": 1
}

+ 7
- 7
server/src/main.rs View File

@@ -11,20 +11,20 @@ use actix_web::{
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("roguelike-server");
let sys = actix::System::new("sokoban-server");

server::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
// redirect
.resource("/", |r| r.method(Method::GET).f(|_req| {
HttpResponse::Found()
.header(header::LOCATION, "/index.html")
.finish()
}))
// .resource("/", |r| r.method(Method::GET).f(|_req| {
// HttpResponse::Found()
// .header(header::LOCATION, "../client/index.html")
// .finish()
// }))
// static files
.handler("/", fs::StaticFiles::new("../client/dist").unwrap())
.handler("/", fs::StaticFiles::new("../client/web").unwrap())
}).bind("127.0.0.1:8080")
.unwrap()
.shutdown_timeout(1)

Loading…
Cancel
Save