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
Inderjit Gill 8 months ago
parent
commit
df47091e81

+ 6
- 3
.gitignore View File

@@ -1,8 +1,11 @@
1 1
 /assets/research
2 2
 
3
-/client/dist
4
-/client/node_modules/
5 3
 /client/target
6
-/client/web/sokoban_wasm*
4
+/client/pkg
5
+/client/wasm-pack.log
6
+/client/www/dist
7
+/client/www/node_modules
8
+
9
+/core/target
7 10
 
8 11
 /server/target

+ 26
- 9
README.md View File

@@ -3,7 +3,24 @@ Sokoban
3 3
 
4 4
 ## Overview
5 5
 
6
+core : the core game code, independent of output format (native/web etc). Written entirely in Rust
6 7
 
8
+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
9
+build with:
10
+$ wasm-pack build
11
+
12
+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
13
+setup with:
14
+$ npm install
15
+(note: The post-install stage of npm install will symlink a reference to client/pkg, so ensure that the client has already been built)
16
+dev with:
17
+$ npm run start
18
+build for production with:
19
+$ npm run build
20
+
21
+server : a separate rust codebase for serving the web app in client/www
22
+
23
+(todo one day) native : a native build of Sokoban that wraps the core crate with a native sdk
7 24
 
8 25
 ## ensure that the correct toolchain is installed
9 26
 ```sh
@@ -11,24 +28,24 @@ $ rustup update
11 28
 $ rustup install nightly
12 29
 $ rustup target add wasm32-unknown-unknown --toolchain nightly
13 30
 $ cargo +nightly install wasm-bindgen-cli
14
-$ cd client
31
+
32
+-- installl wasm-pack --
33
+
34
+$ cd client/www
15 35
 $ npm install
16 36
 ```
17 37
 ## during dev
18 38
 ```sh
19 39
 $ cd client
20
-$ npm run dev:build:wasm
21
-$ npm run dev:build
22
-$ npm run dev:serve
40
+$ wasm-pack build
41
+$ cd www
42
+$ npm run start
23 43
 ```
24 44
 can now visit http://localhost:8080
25 45
 
26 46
 ## for 'release'
27 47
 ```sh
28
-$ cd server
29
-$ cargo run
30
-$ cd ../client
31
-$ npm run release:build
32
-
48
+$ cd client/www
49
+$ npm run start
33 50
 ```
34 51
 can now visit http://localhost:8080

+ 116
- 56
client/Cargo.lock View File

@@ -30,6 +30,15 @@ version = "0.1.5"
30 30
 source = "registry+https://github.com/rust-lang/crates.io-index"
31 31
 
32 32
 [[package]]
33
+name = "console_error_panic_hook"
34
+version = "0.1.5"
35
+source = "registry+https://github.com/rust-lang/crates.io-index"
36
+dependencies = [
37
+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
38
+ "wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
39
+]
40
+
41
+[[package]]
33 42
 name = "failure"
34 43
 version = "0.1.2"
35 44
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -50,9 +59,17 @@ dependencies = [
50 59
 ]
51 60
 
52 61
 [[package]]
53
-name = "itoa"
54
-version = "0.4.3"
62
+name = "futures"
63
+version = "0.1.25"
64
+source = "registry+https://github.com/rust-lang/crates.io-index"
65
+
66
+[[package]]
67
+name = "js-sys"
68
+version = "0.3.4"
55 69
 source = "registry+https://github.com/rust-lang/crates.io-index"
70
+dependencies = [
71
+ "wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
72
+]
56 73
 
57 74
 [[package]]
58 75
 name = "lazy_static"
@@ -76,6 +93,11 @@ dependencies = [
76 93
 ]
77 94
 
78 95
 [[package]]
96
+name = "memory_units"
97
+version = "0.4.0"
98
+source = "registry+https://github.com/rust-lang/crates.io-index"
99
+
100
+[[package]]
79 101
 name = "proc-macro2"
80 102
 version = "0.4.20"
81 103
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -97,33 +119,20 @@ version = "0.1.9"
97 119
 source = "registry+https://github.com/rust-lang/crates.io-index"
98 120
 
99 121
 [[package]]
100
-name = "ryu"
101
-version = "0.2.6"
102
-source = "registry+https://github.com/rust-lang/crates.io-index"
103
-
104
-[[package]]
105
-name = "serde"
106
-version = "1.0.79"
122
+name = "scoped-tls"
123
+version = "0.1.2"
107 124
 source = "registry+https://github.com/rust-lang/crates.io-index"
108 125
 
109 126
 [[package]]
110
-name = "serde_derive"
111
-version = "1.0.79"
112
-source = "registry+https://github.com/rust-lang/crates.io-index"
113
-dependencies = [
114
- "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
115
- "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
116
- "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
117
-]
118
-
119
-[[package]]
120
-name = "serde_json"
121
-version = "1.0.32"
122
-source = "registry+https://github.com/rust-lang/crates.io-index"
127
+name = "sokoban-client"
128
+version = "0.1.0"
123 129
 dependencies = [
124
- "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
125
- "ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
126
- "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
130
+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
131
+ "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
132
+ "sokoban-core 0.1.0",
133
+ "wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
134
+ "wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
135
+ "wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
127 136
 ]
128 137
 
129 138
 [[package]]
@@ -134,14 +143,6 @@ dependencies = [
134 143
 ]
135 144
 
136 145
 [[package]]
137
-name = "sokoban-wasm"
138
-version = "0.1.0"
139
-dependencies = [
140
- "sokoban-core 0.1.0",
141
- "wasm-bindgen 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
142
-]
143
-
144
-[[package]]
145 146
 name = "syn"
146 147
 version = "0.14.9"
147 148
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -178,60 +179,113 @@ version = "0.1.0"
178 179
 source = "registry+https://github.com/rust-lang/crates.io-index"
179 180
 
180 181
 [[package]]
182
+name = "unreachable"
183
+version = "1.0.0"
184
+source = "registry+https://github.com/rust-lang/crates.io-index"
185
+dependencies = [
186
+ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
187
+]
188
+
189
+[[package]]
181 190
 name = "version_check"
182 191
 version = "0.1.5"
183 192
 source = "registry+https://github.com/rust-lang/crates.io-index"
184 193
 
185 194
 [[package]]
195
+name = "void"
196
+version = "1.0.2"
197
+source = "registry+https://github.com/rust-lang/crates.io-index"
198
+
199
+[[package]]
186 200
 name = "wasm-bindgen"
187
-version = "0.2.25"
201
+version = "0.2.27"
188 202
 source = "registry+https://github.com/rust-lang/crates.io-index"
189 203
 dependencies = [
190
- "wasm-bindgen-macro 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
204
+ "wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
191 205
 ]
192 206
 
193 207
 [[package]]
194 208
 name = "wasm-bindgen-backend"
195
-version = "0.2.25"
209
+version = "0.2.27"
196 210
 source = "registry+https://github.com/rust-lang/crates.io-index"
197 211
 dependencies = [
198 212
  "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
199 213
  "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
200 214
  "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
201 215
  "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
202
- "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
203 216
  "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
204
- "wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
217
+ "wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
218
+]
219
+
220
+[[package]]
221
+name = "wasm-bindgen-futures"
222
+version = "0.3.4"
223
+source = "registry+https://github.com/rust-lang/crates.io-index"
224
+dependencies = [
225
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
226
+ "js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
227
+ "wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
205 228
 ]
206 229
 
207 230
 [[package]]
208 231
 name = "wasm-bindgen-macro"
209
-version = "0.2.25"
232
+version = "0.2.27"
210 233
 source = "registry+https://github.com/rust-lang/crates.io-index"
211 234
 dependencies = [
212 235
  "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
213
- "wasm-bindgen-macro-support 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
236
+ "wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
214 237
 ]
215 238
 
216 239
 [[package]]
217 240
 name = "wasm-bindgen-macro-support"
218
-version = "0.2.25"
241
+version = "0.2.27"
219 242
 source = "registry+https://github.com/rust-lang/crates.io-index"
220 243
 dependencies = [
221 244
  "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
222 245
  "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
223 246
  "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
224
- "wasm-bindgen-backend 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
225
- "wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
247
+ "wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
248
+ "wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
226 249
 ]
227 250
 
228 251
 [[package]]
229 252
 name = "wasm-bindgen-shared"
230
-version = "0.2.25"
253
+version = "0.2.27"
254
+source = "registry+https://github.com/rust-lang/crates.io-index"
255
+
256
+[[package]]
257
+name = "wasm-bindgen-test"
258
+version = "0.2.27"
231 259
 source = "registry+https://github.com/rust-lang/crates.io-index"
232 260
 dependencies = [
233
- "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
234
- "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
261
+ "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
262
+ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
263
+ "js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
264
+ "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
265
+ "wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
266
+ "wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
267
+ "wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
268
+]
269
+
270
+[[package]]
271
+name = "wasm-bindgen-test-macro"
272
+version = "0.2.27"
273
+source = "registry+https://github.com/rust-lang/crates.io-index"
274
+dependencies = [
275
+ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
276
+ "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
277
+]
278
+
279
+[[package]]
280
+name = "wee_alloc"
281
+version = "0.4.2"
282
+source = "registry+https://github.com/rust-lang/crates.io-index"
283
+dependencies = [
284
+ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
285
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
286
+ "memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
287
+ "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
288
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
235 289
 ]
236 290
 
237 291
 [[package]]
@@ -258,29 +312,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
258 312
 "checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
259 313
 "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
260 314
 "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
315
+"checksum console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6c5dd2c094474ec60a6acaf31780af270275e3153bafff2db5995b715295762e"
261 316
 "checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
262 317
 "checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
263
-"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
318
+"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
319
+"checksum js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8398e64a4381e93044f63287109e5f1cb65122e63ad2f0607ec6a239d9e13464"
264 320
 "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
265 321
 "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
266 322
 "checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
323
+"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
267 324
 "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
268 325
 "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
269 326
 "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
270
-"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
271
-"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
272
-"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe"
273
-"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
327
+"checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28"
274 328
 "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
275 329
 "checksum syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b10ee269228fb723234fce98e9aac0eaed2bd5f1ad2f6930e8d5b93f04445a1a"
276 330
 "checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
277 331
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
332
+"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
278 333
 "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
279
-"checksum wasm-bindgen 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f311aadd18256d877892bec29178d70f5c19788ecbe6c48a9a7f2577b95dcc01"
280
-"checksum wasm-bindgen-backend 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "0cb9404593b0eaca49dfd3637645c465242e267c0f3b2043c71a0c873cf9d03a"
281
-"checksum wasm-bindgen-macro 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "4d41d4dad37cc64374a4026f4d7b4f513f83538c14e1633b6566dda5a5c099d9"
282
-"checksum wasm-bindgen-macro-support 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cf86d2aa910c060fbdb0396ce17cfb5f1a5bcae833bd195cf2b3911f152a90"
283
-"checksum wasm-bindgen-shared 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "b719b78cb42bd6376de5efd85c991cb8e3fb0cef7adf01e56cec6d8cb9e20470"
334
+"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
335
+"checksum wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "ddabe7a233fc293b35f9754067580906c14b5a14b68da67d21ac109f8624c3fe"
336
+"checksum wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4420cb4101491fa91a0aa488584bf359ec4d805667982d3de37ad18c1adc6c62"
337
+"checksum wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "510541c3a3e13763785f6066ad8823f522fc214f867c1af9469092a5f740230f"
338
+"checksum wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83b50f7b3fad6acd49da239daf5a7a358c554e94e904549f4fd2d7a34d692fb0"
339
+"checksum wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a0970181097265052ae1822d0203412ab7ca5a0f05b8d6581c23ec31e9b99b95"
340
+"checksum wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "251fcb2edbdc5baace161ed8ab680c6cd0ff35b50bdf3eb21afb81fd42c0eb78"
341
+"checksum wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0cb421c529d70602b52be2ae5bf0260a718e2f69514d3841cb43e094f5c3f0f1"
342
+"checksum wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0068543ec0dd625181605c62da925b06e8a3e51aac1c4035943717cb3c91bed2"
343
+"checksum wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27875be1daf838fa18f3e94fd19fd12638e34615b42f56da2610c8f46be80cc6"
284 344
 "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
285 345
 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
286 346
 "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 @@
1
+[package]
2
+name = "sokoban-client"
3
+version = "0.1.0"
4
+authors = ["Inderjit Gill <email@indy.io>"]
1 5
 
2
-[workspace]
3
-members = [
4
-    "rust/sokoban-core",
5
-    "rust/sokoban-wasm",
6
-]
6
+[lib]
7
+crate-type = ["cdylib", "rlib"]
8
+
9
+[features]
10
+default = ["console_error_panic_hook"]
11
+
12
+[dependencies]
13
+cfg-if = "0.1.2"
14
+wasm-bindgen = "0.2"
15
+sokoban-core = { path = "../core" }
16
+
17
+# The `console_error_panic_hook` crate provides better debugging of panics by
18
+# logging them with `console.error`. This is great for development, but requires
19
+# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
20
+# code size when deploying.
21
+console_error_panic_hook = { version = "0.1.1", optional = true }
22
+
23
+# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
24
+# compared to the default allocator's ~10K. It is slower than the default
25
+# allocator, however.
26
+#
27
+# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
28
+wee_alloc = { version = "0.4.2", optional = true }
29
+
30
+[dev-dependencies]
31
+wasm-bindgen-test = "0.2"
7 32
 
8 33
 [profile.release]
9 34
 # Include function names in the `.wasm` for better debugging and

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

@@ -1,13 +0,0 @@
1
-#![feature(test)]
2
-
3
-extern crate test;
4
-extern crate wasm_tetris;
5
-
6
-#[bench]
7
-fn universe_ticks(b: &mut test::Bencher) {
8
-    let mut universe = wasm_game_of_life::Universe::new();
9
-
10
-    b.iter(|| {
11
-        universe.tick();
12
-    });
13
-}

+ 0
- 18
client/package.json View File

@@ -1,18 +0,0 @@
1
-{
2
-  "scripts": {
3
-    "dev:serve": "webpack-dev-server --port 8060",
4
-    "dev:build": "webpack --mode=development --progress",
5
-    "dev:build:wasm": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/sokoban_wasm.wasm --out-dir web",
6
-    "release:serve": "cd rust/sokoban-serve && cargo run",
7
-    "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"
8
-  },
9
-  "devDependencies": {
10
-    "webpack": "4.16.1",
11
-    "webpack-cli": "3.1.0",
12
-    "webpack-dev-server": "3.1.4",
13
-    "mkdirp": "0.5.1"
14
-  },
15
-  "dependencies": {
16
-    "howler": "2.0.14"
17
-  }
18
-}

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

@@ -1,11 +0,0 @@
1
-[package]
2
-name = "sokoban-wasm"
3
-version = "0.1.0"
4
-authors = ["Inderjit Gill <email@indy.io>"]
5
-
6
-[lib]
7
-crate-type = ["cdylib"]
8
-
9
-[dependencies]
10
-wasm-bindgen = "0.2.25"
11
-sokoban-core = { path = "../sokoban-core" }

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

@@ -1,9 +1,13 @@
1 1
 #![allow(dead_code)]
2 2
 #![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names, too_many_arguments))]
3 3
 
4
+extern crate cfg_if;
4 5
 extern crate sokoban_core;
5 6
 extern crate wasm_bindgen;
6 7
 
8
+mod utils;
9
+
10
+use cfg_if::cfg_if;
7 11
 use wasm_bindgen::prelude::*;
8 12
 
9 13
 use sokoban_core::audio::AudioConfig;
@@ -14,6 +18,16 @@ use sokoban_core::game::Game;
14 18
 use sokoban_core::geometry::Geometry;
15 19
 use sokoban_core::host::Host;
16 20
 
21
+cfg_if! {
22
+    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
23
+    // allocator.
24
+    if #[cfg(feature = "wee_alloc")] {
25
+        extern crate wee_alloc;
26
+        #[global_allocator]
27
+        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
28
+    }
29
+}
30
+
17 31
 #[wasm_bindgen]
18 32
 extern "C" {
19 33
     #[wasm_bindgen(js_namespace = console)]

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

@@ -0,0 +1,17 @@
1
+use cfg_if::cfg_if;
2
+
3
+cfg_if! {
4
+    // When the `console_error_panic_hook` feature is enabled, we can call the
5
+    // `set_panic_hook` function at least once during initialization, and then
6
+    // we will get better error messages if our code ever panics.
7
+    //
8
+    // For more details see
9
+    // https://github.com/rustwasm/console_error_panic_hook#readme
10
+    if #[cfg(feature = "console_error_panic_hook")] {
11
+        extern crate console_error_panic_hook;
12
+        pub use self::console_error_panic_hook::set_once as set_panic_hook;
13
+    } else {
14
+        #[inline]
15
+        pub fn set_panic_hook() {}
16
+    }
17
+}

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

@@ -0,0 +1,13 @@
1
+//! Test suite for the Web and headless browsers.
2
+
3
+#![cfg(target_arch = "wasm32")]
4
+
5
+extern crate wasm_bindgen_test;
6
+use wasm_bindgen_test::*;
7
+
8
+wasm_bindgen_test_configure!(run_in_browser);
9
+
10
+#[wasm_bindgen_test]
11
+fn pass() {
12
+    assert_eq!(1 + 1, 2);
13
+}

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

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

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

@@ -1,13 +0,0 @@
1
-const path = require("path");
2
-
3
-module.exports = {
4
-  entry: "./web/js/bootstrap.js",
5
-  output: {
6
-    path: path.resolve(__dirname, "dist"),
7
-    filename: "bootstrap.js",
8
-  },
9
-  optimization: {
10
-    minimize: false
11
-  },
12
-  mode: "development"
13
-};

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

@@ -0,0 +1,5 @@
1
+// A dependency graph that contains any wasm must all be imported
2
+// asynchronously. This `bootstrap.js` file does the single async import, so
3
+// that no one else needs to worry about it again.
4
+import("./index.js")
5
+  .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 @@
1
+<!DOCTYPE html>
1 2
 <html>
2 3
   <head>
3 4
     <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 @@
1
-import { Bridge, BridgeConfig } from "../sokoban_wasm";
2
-import { memory } from "../sokoban_wasm_bg";
3
-import { GLRenderer } from "./GLRenderer";
4
-import { Audio } from "./Audio";
5
-import { Metric } from "./Metric";
1
+import { Bridge, BridgeConfig } from "sokoban-client";
2
+import { memory } from "sokoban-client/sokoban_client_bg";
3
+
4
+import { GLRenderer } from "./js/GLRenderer";
5
+import { Audio } from "./js/Audio";
6
+import { Metric } from "./js/Metric";
6 7
 
7 8
 let gState = {
8 9
   canvasId: 'render-canvas',
9
-  tilesetFilename: '/web/img/sokoban_tilesheet.png',
10
+  tilesetFilename: '/img/sokoban_tilesheet.png',
10 11
 
11 12
   bridgeConfig: undefined,
12 13
   bridge: undefined,
@@ -198,6 +199,4 @@ function main() {
198 199
   // gState.bridge.free();
199 200
 }
200 201
 
201
-
202
-
203 202
 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 @@
1
+{
2
+  "name": "sokoban-client-www",
3
+  "version": "0.1.0",
4
+  "description": "",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "postinstall": "symlink-dir '../pkg' 'node_modules/sokoban-client'",
8
+    "build": "webpack --config webpack.config.js",
9
+    "start": "webpack-dev-server"
10
+  },
11
+  "keywords": [
12
+    "webassembly",
13
+    "wasm",
14
+    "rust",
15
+    "webpack"
16
+  ],
17
+  "author": "Inderjit Gill <email@indy.io>",
18
+  "license": "(MIT OR Apache-2.0)",
19
+  "devDependencies": {
20
+    "symlink-dir": "2.0.0",
21
+    "webpack": "^4.16.3",
22
+    "webpack-cli": "^3.1.0",
23
+    "webpack-dev-server": "^3.1.5",
24
+    "copy-webpack-plugin": "^4.5.2"
25
+  },
26
+  "dependencies": {
27
+    "howler": "2.0.14"
28
+  }
29
+}

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 @@
1
+const CopyWebpackPlugin = require("copy-webpack-plugin");
2
+const path = require('path');
3
+
4
+module.exports = {
5
+  entry: "./bootstrap.js",
6
+  output: {
7
+    path: path.resolve(__dirname, "dist"),
8
+    filename: "bootstrap.js",
9
+  },
10
+  mode: "development",
11
+  plugins: [
12
+    new CopyWebpackPlugin(['index.html'])
13
+  ],
14
+};

+ 146
- 0
core/Cargo.lock View File

@@ -0,0 +1,146 @@
1
+[[package]]
2
+name = "backtrace"
3
+version = "0.3.9"
4
+source = "registry+https://github.com/rust-lang/crates.io-index"
5
+dependencies = [
6
+ "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
7
+ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
8
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
9
+ "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
10
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
11
+]
12
+
13
+[[package]]
14
+name = "backtrace-sys"
15
+version = "0.1.24"
16
+source = "registry+https://github.com/rust-lang/crates.io-index"
17
+dependencies = [
18
+ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
19
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
20
+]
21
+
22
+[[package]]
23
+name = "cc"
24
+version = "1.0.25"
25
+source = "registry+https://github.com/rust-lang/crates.io-index"
26
+
27
+[[package]]
28
+name = "cfg-if"
29
+version = "0.1.6"
30
+source = "registry+https://github.com/rust-lang/crates.io-index"
31
+
32
+[[package]]
33
+name = "failure"
34
+version = "0.1.3"
35
+source = "registry+https://github.com/rust-lang/crates.io-index"
36
+dependencies = [
37
+ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
38
+ "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
39
+]
40
+
41
+[[package]]
42
+name = "failure_derive"
43
+version = "0.1.3"
44
+source = "registry+https://github.com/rust-lang/crates.io-index"
45
+dependencies = [
46
+ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
47
+ "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
48
+ "syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
49
+ "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
50
+]
51
+
52
+[[package]]
53
+name = "libc"
54
+version = "0.2.43"
55
+source = "registry+https://github.com/rust-lang/crates.io-index"
56
+
57
+[[package]]
58
+name = "proc-macro2"
59
+version = "0.4.20"
60
+source = "registry+https://github.com/rust-lang/crates.io-index"
61
+dependencies = [
62
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
63
+]
64
+
65
+[[package]]
66
+name = "quote"
67
+version = "0.6.9"
68
+source = "registry+https://github.com/rust-lang/crates.io-index"
69
+dependencies = [
70
+ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
71
+]
72
+
73
+[[package]]
74
+name = "rustc-demangle"
75
+version = "0.1.9"
76
+source = "registry+https://github.com/rust-lang/crates.io-index"
77
+
78
+[[package]]
79
+name = "sokoban-core"
80
+version = "0.1.0"
81
+dependencies = [
82
+ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
83
+]
84
+
85
+[[package]]
86
+name = "syn"
87
+version = "0.15.18"
88
+source = "registry+https://github.com/rust-lang/crates.io-index"
89
+dependencies = [
90
+ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
91
+ "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
93
+]
94
+
95
+[[package]]
96
+name = "synstructure"
97
+version = "0.10.1"
98
+source = "registry+https://github.com/rust-lang/crates.io-index"
99
+dependencies = [
100
+ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
101
+ "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
102
+ "syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
103
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
104
+]
105
+
106
+[[package]]
107
+name = "unicode-xid"
108
+version = "0.1.0"
109
+source = "registry+https://github.com/rust-lang/crates.io-index"
110
+
111
+[[package]]
112
+name = "winapi"
113
+version = "0.3.6"
114
+source = "registry+https://github.com/rust-lang/crates.io-index"
115
+dependencies = [
116
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
117
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
118
+]
119
+
120
+[[package]]
121
+name = "winapi-i686-pc-windows-gnu"
122
+version = "0.4.0"
123
+source = "registry+https://github.com/rust-lang/crates.io-index"
124
+
125
+[[package]]
126
+name = "winapi-x86_64-pc-windows-gnu"
127
+version = "0.4.0"
128
+source = "registry+https://github.com/rust-lang/crates.io-index"
129
+
130
+[metadata]
131
+"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
132
+"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
133
+"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
134
+"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
135
+"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
136
+"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
137
+"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
138
+"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
139
+"checksum quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5829244f52738cfee93b3a165c1911388675be000c888d2fae620dee8fa5b"
140
+"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
141
+"checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
142
+"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
143
+"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
144
+"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
145
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
146
+"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 {
20 20
             tracks: vec![
21 21
                 AudioTrackInfo {
22 22
                     id: SoundEffect::PauseIn as i32,
23
-                    path: "web/sfx/pause2_in.mp3".to_owned(),
23
+                    path: "sfx/pause2_in.mp3".to_owned(),
24 24
                 },
25 25
                 AudioTrackInfo {
26 26
                     id: SoundEffect::PauseOut as i32,
27
-                    path: "web/sfx/pause2_out.mp3".to_owned(),
27
+                    path: "sfx/pause2_out.mp3".to_owned(),
28 28
                 },
29 29
                 AudioTrackInfo {
30 30
                     id: SoundEffect::MenuMove as i32,
31
-                    path: "web/sfx/menu_move4.mp3".to_owned(),
31
+                    path: "sfx/menu_move4.mp3".to_owned(),
32 32
                 },
33 33
             ],
34 34
         }

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 @@
1
-{
2
-  "lockfileVersion": 1
3
-}

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

@@ -11,20 +11,20 @@ use actix_web::{
11 11
 fn main() {
12 12
     ::std::env::set_var("RUST_LOG", "actix_web=info");
13 13
     env_logger::init();
14
-    let sys = actix::System::new("roguelike-server");
14
+    let sys = actix::System::new("sokoban-server");
15 15
 
16 16
     server::new(|| {
17 17
         App::new()
18 18
             // enable logger
19 19
             .middleware(middleware::Logger::default())
20 20
             // redirect
21
-            .resource("/", |r| r.method(Method::GET).f(|_req| {
22
-                HttpResponse::Found()
23
-                    .header(header::LOCATION, "/index.html")
24
-                    .finish()
25
-            }))
21
+            // .resource("/", |r| r.method(Method::GET).f(|_req| {
22
+            //     HttpResponse::Found()
23
+            //         .header(header::LOCATION, "../client/index.html")
24
+            //         .finish()
25
+            // }))
26 26
             // static files
27
-            .handler("/", fs::StaticFiles::new("../client/dist").unwrap())
27
+            .handler("/", fs::StaticFiles::new("../client/web").unwrap())
28 28
     }).bind("127.0.0.1:8080")
29 29
         .unwrap()
30 30
         .shutdown_timeout(1)

Loading…
Cancel
Save