-
-
Save z3t0/948e9e9262856e773190380d5ba36b97 to your computer and use it in GitHub Desktop.
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
// modloader.js | |
load (module: constructor) { | |
try { | |
let mod = new module(this.game) | |
this.registerMod(mod) | |
this.log(`loaded mod: '${mod.name}'`) | |
} catch (e) { | |
this.log('Failed to load: ' + module.name) | |
} | |
} | |
// app.js | |
let Game = require('./game.js') | |
var game = new Game({'name': 'Haxel'}) | |
// Mods | |
let engine = require('./engine.js') | |
// here engine is a constructor for class type Engine? | |
game.modLoader.load(engine) | |
game.init() | |
// engine.js | |
// @flow | |
let Mod = require('./mod.js') | |
let Game = require('./game.js') | |
class Engine extends Mod { | |
constructor (game : Game) { | |
var opts = { | |
name: 'Engine', | |
dependencies: [] | |
} | |
super(game, opts) | |
this.game = game | |
} | |
} | |
module.exports = Engine | |
// mod.js | |
// @flow | |
let Game = require('./game.js') | |
class Mod { | |
name : string | |
game: Game | |
enabled: boolean | |
dependencies: Array<any> | |
constructor (game: Game, opts: { name: string, dependencies: Array<any>}) { | |
this.game = game | |
this.name = opts.name | |
this.dependencies = opts.dependencies | |
this.enabled = false | |
} | |
} | |
module.exports = Mod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment