diff --git a/README.md b/README.md index c49ef3531..2c0b3db5b 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,127 @@ -# OPEN DUELYST -🚧 WIP 🚧 +# Duelyst -## Requirements +This is the source code for Duelyst, a digital collectible card game and turn-based strategy hybrid developed by Counterplay Games and released in 2016. + +### Client Architecture + +The game client is a Backbone.js + Marionette application which runs in the browser. Code can be found in `app/`, and configuration can be found in `app/common/config.js`. + +### Server Architecture + +Duelyst's backend primarily consists of four CoffeeScript services: + +API Server: + +- The API server is an Express.js app which handles routes for game clients. +- The service stores user and game data in Postgres and Redis. +- The service listens on port 3000 by default, and it serves the browser client on the default route. +- Code can be found in `server/api.coffee`, and configuration can be found in `config/`. + +Game Server: + +- The Game server is a Socket.IO WebSocket server which handles multiplayer games. +- The service enqueues tasks in Redis to be picked up by the workers. +- The service listens on port 8000 by default. +- Code can be found in `server/game.coffee`, and configuration can be found in `config/`. + +Single Player (SP) Server: + +- The SP server is a Socket.IO WebSocket server which handles single-player games. +- The service enqueues tasks in Redis to be picked up by the workers. +- The service listens on port 8000 by default. +- Code can be found in `server/single_player.coffee`, and configuration can be found in `config/`. + +Worker: + +- The worker uses Kue to poll Redis-backed queues for tasks like game creation and matchmaking. +- Some matchmaking tasks also use Postgres, for server healthchecks and retrieving bot users. +- Code can be found in `worker/worker.coffee`, and configuration can be found in `config/`. +- A Kue GUI is available at `http://localhost:3000` via `docker compose up worker-ui`). + +#### Other Dependencies + +Postgres: + +- Client code can be found in `server/lib/data_access/knex.coffee` and `server/knexfile.js`, and configuration can be found in `config/` +- Migrations can be run via `docker compose up migrate` +- An admin UI is available at `http://localhost:8080` via `docker compose up adminer` + +Redis: + +- Client code can be found in `server/redis/r-client.coffee`, and configuration can be found in `config/` + +Consul: + +- Not required in single-server deployments, but was historically used for service discovery, matchmaking, and spectating +- Client code can be found in `server/lib/consul.coffee`, and configuration can be found in `config/` + +## Setting up a development environment + +#### Requirements - [Docker](https://www.docker.com/products/docker-desktop/) -- [Node.js](https://nodejs.org/en/download/) +- [Node.js](https://nodejs.org/en/download/) with NPM -## Setup +#### Building the code -- `npm install -g yarn` -- `yarn install --dev` -- `yarn build` to build client -- `yarn watch` to build client continuously -- Modify `development.json` with: - - Firebase Realtime endpoint and secret - - Redis connection string - - Postgres connection string +Install NPM tools: +``` +npm install -g typescript yarn gulpjs/gulp-cli +``` -## Quick Start +Compile TypeScript dependencies: +``` +cd packages/chroma-js +tsc +``` -- `docker compose up -d` to start all services locally +Build the game: +``` +yarn install --dev +yarn build +``` + +The above build command builds the game and its required resources for the first time, which will take a few minutes. Use it when making changes to resources like cards, codex data, cosmetics, etc. + +Once the initial build is done, you can save time by rebuilding only the app (takes about 50 seconds): +``` +yarn build:app +``` + +Or rebuild only the HTML/CSS and localization files (takes about 5 seconds): +``` +yarn build:web +``` + +When working in the `server` or `worker` directories, no rebuilds are needed. See below for instructions to test changes in Docker instead. + +#### Starting a test environment in Docker + +- Modify `development.json` with: + - Firebase Realtime endpoint and secret + - Redis connection string + - Postgres connection string +- Optionally enable debug logging for sockets by prepending `yarn $1` with `DEBUG=*` in `docker/start` +- Use `docker compose up` to start required services locally, or start individual services: + - `redis` + - `db` (Postgres) + - `adminer` (Postgres admin UI) + - `api` (HTTP server) + - `game` (Multi-player server) + - `sp` (Single-player server) + - `worker` (Game workers) + - `worker-ui` (Game worker UI) + - `migrate` (Postgres migrations) +- Run database migrations + - Use `npm install -g knex` to install the Postgres client + - In another terminal window, use `NODE_ENV=development yarn migrate:latest` to run database migrations + - On Windows: `$env:NODE_ENV = 'development'; yarn migrate:latest` + - Only need to run this once (unless you change Postgres schema) - Open http://localhost:3000 in a browser to load the game client -## Scripts +#### Starting individual components - `yarn api` to start api server - `yarn game` to start game server - `yarn sp` to start single player game server -- `yarn worker` to start worker -- `NODE_ENV=development yarn migrate:latest` to run database migrations +- `yarn worker` to start worker \ No newline at end of file