mousebelt / BrowserQuest

A HTML5/JavaScript multiplayer game experiment
http://browserquest.mozilla.org/
Other
2 stars 0 forks source link

BrowserQuest - Typescript/ECS

BrowserQuest's original project's last update was in 2012. Seeing that several browser game coding learning resources pointed at this project, I decided to change the code to Typescript, and change the architecture to Entity-Component-System. The objective of this project is to then be both a learning tool and a template for making multiplayer browser games in Typescript.

Getting Started

Prerequisites

You'll need npm and Node.js (https://nodejs.org/en/). Visual Studio Code is recommended as it was the IDE used in this project. Console Emulator cmder was used for all command-line tasks.

Setting Up

After getting the code and Node/npm, install the packages, by going to the main folder (the one with package.json) and running:

npm install

Copy configurations and .env.example by following commands:

$> cp .env.example .env
$> cd configuration
$> cp client.local.json.example client.local.json
$> cp server.json.example server.json

and update .env with your Wallet address and private key, as well as host address on server.json

Usage

First build client:

npm run buildclient

Then build server and run:

npm run buildserver
node dist\server\scripts\main.js

The port to access it can be set in the configuration folder.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details Code is licensed under MPL 2.0. Content is licensed under CC-BY-SA 3.0. See the LICENSE.md file for details.

Guide

Project Organization

Package.json

Browserify

The "main" field tells which file is the entry point, to indicate where to start.

The "transform" field sets up any transformations in the code that will be applied. The ones used are "babelify", which is the Babel transform, used to "compile" the Javascript code to the es2015 version, with the plugin transform-class-properties; and "browserify-shim", used to expose and shim jquery.

Module Aliases

Used for pathmapping by the server, as it works differently in a node environment compared to babel/browserify that can apply transforms to the code.

Scripts

.vscode/Tasks.json

2 tasks were created to watch for changes and show the errors in the Problems tab: Client Watcher and Server Watcher.

The Prefab Editor

To manage the prefabs more easily, the prefab editor was created. Its functionalities are very basic, but as the files can get pretty big, it can be very useful to manage the components of each prefab, and their children.

The Game

The code for the game is divided in 2 main parts - the systems and the components. Following the Entity-Component-System architecture, the systems don't store any data, and only have methods to work with the logic of the game. The components have all the data, but no logic. The entities are just a set of components. It's possible to get multiple components of an Entity at once by using the Nodes structure (defined in Component.ts).

Notes

TODO