]> git.cworth.org Git - empires-server/commitdiff
Add some documentation about the Game import interface
authorCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 21:24:29 +0000 (14:24 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 1 Jun 2020 21:24:29 +0000 (14:24 -0700)
Having some notes here will simplify the task of making a new Game by
copying an existing game, (since the game logic itself may obscure
some of the details of this interface).

lmno.js

diff --git a/lmno.js b/lmno.js
index 6651adfa692e60c401cb58d9cf4a5c5e951f4397..a22f9588537b2cae1e75adbbeb94a88e68420e0a 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -46,7 +46,37 @@ nunjucks.configure("templates", {
   express: app
 });
 
-/* Load each of our game mini-apps. */
+/* Load each of our game mini-apps.
+ *
+ * Each "engine" we load here must have a property .Game on the
+ * exports object that should be a class that extends the common base
+ * class Game.
+ *
+ * In turn, each engine's Game must have the following properties:
+ *
+ *     .meta:   An object with .name and .identifier properties.
+ *
+ *              Here, .name is a string giving a human-readable name
+ *              for the game, such as "Tic Tac Toe" while .identifier
+ *              is the short, single-word, all-lowercase identifier
+ *              that is used in the path of the URL, such as
+ *              "tictactoe".
+ *
+ *     .router: An express Router object
+ *
+ *              Any game-specific routes should already be on the
+ *              router. Then, LMNO will add common routes including:
+ *
+ *                 /        Serves <identifier>-game.html template
+ *
+ *                 /events  Serves a stream of events. Game can override
+ *                          the handle_events method, call super() first,
+ *                          and then have code to add custom events.
+ *
+ *                 /moves   Receives move data from clients. This route
+ *                          is only added if the Game class has an
+ *                          add_move method.
+ */
 const engines = {
   empires: require("./empires"),
   tictactoe: require("./tictactoe")