X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=d818cd12fb16de02af766b02b995d5eac3f43886;hb=ab53a3a530ad30db6cf52b8507fa1cbddb28eecf;hp=8a3210e5229c14cd750d5bbd4408c2536eab6c59;hpb=c60da21a61ee8b98550618aa197aefb3cf69a725;p=empires-server diff --git a/lmno.js b/lmno.js index 8a3210e..d818cd1 100644 --- a/lmno.js +++ b/lmno.js @@ -47,8 +47,10 @@ nunjucks.configure("templates", { }); /* Load each of our game mini-apps. */ -var empires = require("./empires"); -var tictactoe = require("./tictactoe"); +const engines = { + empires: require("./empires"), + tictactoe: require("./tictactoe") +}; class LMNO { constructor() { @@ -59,17 +61,19 @@ class LMNO { return Array(4).fill(null).map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); } - create_game(engine) { + create_game(engine_name) { do { var id = this.generate_id(); } while (id in this.ids); - const game = new empires.Game(); + const engine = engines[engine_name]; + + const game = new engine.Game(); this.ids[id] = { - id: id, - engine: engine, - game: game + id: id, + engine: engine.name, + game: game }; return id; @@ -246,8 +250,10 @@ app.get('/admin/', auth_admin, (request, response) => { /* Mount sub apps. only _after_ we have done all the middleware we need. */ -app.use('/empires/[a-zA-Z0-9]{4}/', empires.app); -app.use('/tictactoe/[a-zA-Z0-9]{4}/', tictactoe.app); +for (let key in engines) { + const engine = engines[key]; + app.use(`/${engine.name}/[a-zA-Z0-9]{4}/`, engine.app); +} app.listen(4000, function () { console.log('LMNO server listening on localhost:4000');