Module Overview
A module consists of a directory containing certain mandatory files which are loaded by the server. All the other resources needed for a module are also put in this directory. Note that all of the files in the module will be available on the web.
The module must be put in the server "public" directory, matching the name of title_id. If our example game has the title "My Example Module" and a title_id of "example", the module directory should be "public/example/".
Metadata
Each module needs to be registered in the database so that the system can find it. To do this we usually create a title.sql file that you will run to register the module.
insert or replace into titles ( title_id, title_name, bgg ) values ( 'example', 'Example', 123 ) ;
The bgg column should have the boardgamegeek.com game id.
After creating this file, source it into the database and restart the server program.
$ sqlite3 db < public/example/title.sql
Cover image
Each game needs a cover image! Create a file containing the high resolution cover image named cover.png or cover.jpg. After you have created or modified the cover image, run the following script to generate the small cover images and thumbnails that the site uses.
$ bash tools/gencovers.sh
This script requires ImageMagick (convert), netpbm (pngtopnm), and libjpeg (cjpeg) tools to be installed.
About text
The game landing page on the server has a bit of text introducing the game, and links to rules and other reference material.
Put the about text in the about.html file.
Dolorum fugiat dolor temporibus. Debitis ea non illo sed debitis cupiditate ipsum illo. Eos eos molestias illo quisquam dicta.
Create game options
When creating a game, the scenarios and common options are handled by the system. However, if your game uses custom options these need to be added as form fields.
Add a create.html file to inject form fields into the create game page.
Player count:
This file may be empty if your game doesn't have any custom options.
Client HTML
The game needs a play.html file using the following template:
View Program
As you saw above, the client page references a play.js script which should contain the code for updating the game. This script must provide a couple of functions that are called by the common client code whenever the game state changes.
The view object
TODO
Framework globals
These global variables are provided by the framework for use with your code.
- var player
- This variable holds the name of the current role the player has in this browser window. The value may change if the client is in replay mode.
- var view
- This object contains the view for the role as returned by the rules view method.
Framework functions
These functions are provided to your client code to build the game interface and communicate with the server.
- function send_action(verb, noun)
- Call this when player performs an action (such as clicking on a piece). If the action is not in the legal list of actions in the view object, this function does nothing and returns false. Returns true if the action is legal.
- function action_button(verb, label)
- Show a push button in the top bar for a simple action (if the action is legal).
- function action_button_with_argument(verb, noun, label)
- Show a push button in the top bar for an action taking a specific argument (if the action with the argument is legal).
- function confirm_send_action(verb, noun, question)
- Same as send_action but pop up a confirmation dialog first.
- function confirm_action_button(verb, label, question)
- Same as action_button but pop up a confirmation dialog first.
- function send_query(what)
- Send a "query" message to the rules. The result will be passed to on_reply.
function on_update()
This function is called whenever the "view" object has updated. It should update the visible game representation and highlight possible actions.
The client code has already updated the prompt message and log when this is called.
The view.actions object contains the list of legal actions to present.
function on_log(text)
Optional function to implement custom HTML formatting of log messages. If present, this function must return an HTML element representing the given text.
function on_reply(what, response)
This function is invoked with the result of send_query. The what parameter matches the argument to send_query and is used to identify different queries.
See rommel-in-the-desert and wilderness-war for examples of using the query mechanism.
Rules Program
The game object
TODO...
exports.scenarios
A list of scenarios! If there are no scenarios, it should be a list with one element "Standard".
exports.roles = function (scenario, options)
Either a list of roles, or a function returning a list of roles.
exports.setup = function (seed, scenario, options)
Create the initial game object with a random number seed, scenario, and options object.
The options object is filled in with values from the create.html form fields.
exports.view = function (game, player)
Given a game object, a player role, return the view object that is used by the client to display the game state. This should contain game state known to the player.
TODO: prompt
TODO: actions
exports.action = function (game, player, verb, noun)
Perform an action taken by a player. Return a game object representing the new state. It's okay to mutate the input game object.
exports.query = function (game, player, what)
A custom query for information that is normally not presented. For example showing a supply line overview, or a list of cards in a discard pile.