From 0c60e3ad3818304103b80dc247cd6b347a1d1406 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Thu, 26 Dec 2024 10:54:30 -0800 Subject: [PATCH] docs: Update documentation --- Dockerfile | 2 ++ README.md | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index b45abba..7840d77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ COPY --exclude=*/target/* server /build/server/ COPY --exclude=*/node_modules/* --exclude=*/dist/* ui /build/ui/ COPY resources /build/resources/ +# for some reason wasm-pack wasn't on the PATH RUN cd wasm && ~/.cargo/bin/wasm-pack build --target=web RUN cd ui && npm install RUN cd ui && npm run build @@ -38,6 +39,7 @@ COPY --from=build-stage /build/target/release/server server RUN cp /srv/static/*.csv dictionary.csv RUN echo '{"dictionary_path": "dictionary.csv", "static_path": "static"}' > config.json +# See https://rocket.rs/guide/v0.5/deploying/#containerization ENV ROCKET_ADDRESS=0.0.0.0 ENV ROCKET_PORT=8000 diff --git a/README.md b/README.md index 51f18dc..8f69233 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,25 @@ # README -This repository contains the code for 'WordGrid', a (currently) single-player browser game where you use letter tiles to form words. +This repository contains the code for 'WordGrid', a browser game where you use letter tiles to form words. -Game logic resides in `src/` as Rust code, which gets compiled into WebAssembly. +There is support for both multiplayer and singleplayer, where singleplayer runs entirely in the browser through WebAssembly. -UI logic resides in `ui/src/`, which gets bundled by Parcel into the web application. +Here's the rough layout of the repository: -If you want to try it now, I host a version at https://joeltherrien.ca/wordgrid +1. The core game logic resides in the `wordgrid/` folder as Rust code and is a library for either the `wasm/` code (if compiled to WebAssembly for singleplayer), or for the `server/` code (if used in multiplayer). +2. The Rust code in `wasm/` is a small compatibility layer between the library and the browser. It gets compiled using `wasm-pack` to a Node package into `wasm/pkg/` that gets read by `ui/` +3. `ui/` is a Node package that uses React & Typescript. Currently it assumes it's being run in an environment that supports both singleplayer & multiplayer. This can't be built until the `wasm/` code has been built. +4. `server/` is a Rust program that runs a small web server for multiplayer purposes. + +If you want to try it now, I host a version at https://wordgrid.joeltherrien.ca ## Setup -* Make sure you have [Node.js](https://nodejs.org/en) installed and [rustup and Cargo](https://www.rust-lang.org/learn/get-started). +I'd suggest just reading through the `Dockerfile` to precisely see what to do, but it's basically the following steps: -1. Clone this repository. -2. If not already installed, install the Rust `wasm32-unknown-unknown` target with `rustup target add wasm32-unknown-unknown`. -3. In the base project directory, run `make build-all` to build both the Rust wasm project (gets stored in `pkg/`) and the final bundled web files (gets stored in `ui/dist/`). -4. Place the files in `ui/dist/` onto a web server and access them. +1. Ensure you have Rust, Node, npm, and wasm-pack installed. +2. Build wasm by navigating to the `wasm/` folder and running `wasm-pack build --target=web` +3. Build the ui by navigating to the `ui/` folder and running `npm run build`. You may need to first run `npm install`. +4. Build the server by navigating to the `server/` folder and running `cargo build --release`. -During development, you'll often want to serve the UI component in serve mode that auto-updates when you make a change. In the `ui/` directory you can run `npm run start`. Note that Parcel doesn't always detect changes to the compiled Rust code, so if you recompile the Rust code with changes you should delete `ui/.parcel-cache/` and `ui/dist/` or else the UI may continue to use older WASM. - -## Future Plans - -I intend on building a multiplayer component to this game, where the Rust code will form a webserver for connecting players and the UI will make server calls instead of calling web assembly. \ No newline at end of file +If you just want singleplayer, you can stop after step 3 and the static files you'll want are in `ui/dist/`. You can rename `singleplayer.html` -> `index.html` if you want to save a click. \ No newline at end of file