Enables various features from the ImpactJS HTML5 game engine in Node.js to enable code sharing and re-use between the client and server side.
The features that are emulated or re-created are:
- The Module system
- The Class system
- The Native type extensions
- Server authoritative multiplayer games
- High score validation - record inputs from the game, send over to server after level is done, server can then replay using the same logic and code on server
- Use or embed game data or game structures from your game into your webapp
Note: Enabling the systems should only be done in one place, in the entry point of your app. After that, their effect is global.
Enable the Class System:
Enable the Module System:
// Note: Must pass in the root class path folder. This can be the same lib folder that // contains your client-side modules require("node-impact-emu").useModule(__dirname + '/lib');
Enabling the module system allows you to manage all modules using the ImpactJS
ig.module('...').requires('...', '...', '...').defines(...); rather than using node.js's require function.
You can also enable more than one system at a time by chaining:
Or you can enable everything:
require("node-impact-emu").useAll(__dirname + '/lib'); // Also takes class path folder for useModule
See example folder for an example app.
Enabling these features diverges from typical Node.js development practices. The global namespace is modified, and modules are no longer entirely self-contained. Use at your own risk.