docs: Update documentation

This commit is contained in:
Joel Therrien 2024-12-26 10:54:30 -08:00
parent 1224035d7a
commit 0c60e3ad38
2 changed files with 17 additions and 14 deletions

View file

@ -23,6 +23,7 @@ COPY --exclude=*/target/* server /build/server/
COPY --exclude=*/node_modules/* --exclude=*/dist/* ui /build/ui/ COPY --exclude=*/node_modules/* --exclude=*/dist/* ui /build/ui/
COPY resources /build/resources/ 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 wasm && ~/.cargo/bin/wasm-pack build --target=web
RUN cd ui && npm install RUN cd ui && npm install
RUN cd ui && npm run build 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 cp /srv/static/*.csv dictionary.csv
RUN echo '{"dictionary_path": "dictionary.csv", "static_path": "static"}' > config.json 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_ADDRESS=0.0.0.0
ENV ROCKET_PORT=8000 ENV ROCKET_PORT=8000

View file

@ -1,24 +1,25 @@
# README # 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 ## 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. 1. Ensure you have Rust, Node, npm, and wasm-pack installed.
2. If not already installed, install the Rust `wasm32-unknown-unknown` target with `rustup target add wasm32-unknown-unknown`. 2. Build wasm by navigating to the `wasm/` folder and running `wasm-pack build --target=web`
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/`). 3. Build the ui by navigating to the `ui/` folder and running `npm run build`. You may need to first run `npm install`.
4. Place the files in `ui/dist/` onto a web server and access them. 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. 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.
## 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.