-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from willroberts/local-development
Improves local development
- Loading branch information
Showing
11 changed files
with
231 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,24 @@ | ||
node_modules/* | ||
desktop/app/node_modules/* | ||
.tmp | ||
.sass-cache | ||
# Build artifacts | ||
/app/data/packages.js | ||
/app/localization/locales/en/index.json | ||
/dist | ||
node_modules | ||
|
||
# Development artifacts | ||
*.log | ||
*.log.txt | ||
dump.rdb | ||
.env | ||
.env_for_alpha | ||
.foreman | ||
.vagrant/ | ||
.idea/ | ||
.DS_Store | ||
/app/data/packages.js | ||
/matchmaker/*.log | ||
/server/*.log | ||
.env_for_alpha | ||
/public | ||
/dist | ||
.node-version | ||
.env_for_dev | ||
dump.rdb | ||
cli/config/*.temp | ||
cli/config | ||
.vscode | ||
scripts/codex/images | ||
npm-debug.log | ||
scripts/**/*.log.txt | ||
desktop/node_modules | ||
desktop/src | ||
scratch.txt | ||
Procfile | ||
/scratch | ||
.sass-cache | ||
.steamcache | ||
/config/production_local.json | ||
/scripts/aws-utility/node_modules | ||
/scripts/codex/node_modules | ||
/cli/codes | ||
/app/localization/locales/en/index.json | ||
/scripts/localization/localization_output/ | ||
/scripts/localization/node_modules/ | ||
/cli/*Snapshots/ | ||
yarn-error.log | ||
.pgdata | ||
.tmp | ||
.vagrant/ | ||
.vscode | ||
/.pgdata | ||
|
||
# OSX-specific artifacts | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
yarn install --dev | ||
# NODE_ENV=development yarn migrate:latest | ||
DEBUG=* yarn $1 | ||
|
||
# To enable socket debug logs, prepend this command with DEBUG=* | ||
yarn $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.