-
Notifications
You must be signed in to change notification settings - Fork 2
Technical design
azziliz edited this page May 9, 2016
·
1 revision
- The game uses a client/server architecture.
- The client is a single-page application that runs inside a web browser.
- The server is a Node.js application.
- It is intended to be standalone (no package, no "npm install" required).
- It doesn't have any dependency with third-party modules.
- Game objects (characters, levels, ...) are modeled by javascript classes. Each class is in a separate file.
- Classes code is designed to be shared between the client and the server.
- This implies that the code cannot use "module.exports" or call the "require" function, as it would break the compatibility with clients.
- Getting the classes on client side is just a matter of downloading the files:
<script src="src/class1.js"></script><script src="src/class2.js"></script>...
- On server side, as the classes do not export anything, we cannot require them.
- To load them without require and to resolve dependencies between classes, we chose to use the Node VM.
- A single context is created and classes are added one by one inside it with a call to vm.runInContext.
- The first class to be loaded is "GameEngine". This enables the creation of an instance of it just after.
- The instance, named "gameEngine" is then added to the context, which creates a closure for subsequent classes.
- To load them without require and to resolve dependencies between classes, we chose to use the Node VM.