Definition files¶
Gameplay definitions are hosted under data/<gameplayName>/definition.js
. This file must be a node.js module: it means that it must return a javascript object. These two structures are valid:
module.exports = {
element: "value",
another: "bar"
}
module.exports = function() {
this.element = "value";
this.another = "bar";
}
This file is the entry point of your gameplay definition: you can create many javascript files in the gameplay directory if you need it! There is no restriction of size or compute time.
Note
You must provide valid keys in your definition file: it will be parsed at startup and invalid files will be rejected.
You can view a list of checked keys here.
Mandatory keys¶
-
'name'
¶ String
The name of the gameplay. It will be displayed in room properties.
-
'minPlayers'
¶ Number
The minimum/default number of players per room.
-
'maxPlayers'
¶ Number
-
'start'
¶ function (room, callback) {}
Called when the start command is emitted by the room creator. The callback must be called with null to confirm the room start. If
callback
is called with another value, a message would be printed in game chat.
Optional keys¶
-
'version'
¶ String
The current version of this gameplay.
-
'opVersion'
¶ String
The required version of OpenParty. Must be in semver format.
Examples:
"0.1.*" ">=0.1" "<1.0.0"
-
'description'
¶ String
A short description of the gameplay, displayed in room list.
-
'stages'
¶ Object
An object containing all available stages for this gameplay. This object can be dynamically updated by your gameplay. A stage is just a period of time and contains only two functions:
start
andend
.The key used to define a stage is saved in
room.currentStage
variable, and a room is always in a specific stage.-
'start'
function (room, cb) {}
Called by the engine when a stage is started.
cb
must be called with two parameters: the first one is an error indicator, and the second is the duration of the stage (seconds). A duration can be -1 for infinite.
-
'end'
¶ function (room) {}
Called when a stage ends.
Example of stages object
stages: { "default": { start: function(room, cb) { cb(null, 5); }, end: function(room) {} } }
-
-
'firstStage'
¶ String
The first stage to start.
-
'css'
¶ Array[String]
You can include custom css files in the web browser. Just place your css files in a
data/<gameplayName>/css
folder and specify their names in thecss
array.css: ["file1.css", "file2.css"]
-
'parameters'
¶ Array[Object]
Used to define specific parameters for room. Players can interract with these parameters to customize their gameplay experience.
Warning
This feature is currently in development.
Example of parameter:
{ name: "The name of the parameter", type: Number, // the type value: 1, // default value help: "An help text for this parameter" }
-
'init'
¶ function (room) {}
Called just after room creation.
-
'processMessage'
¶ function (channel, message, player) {}
Called for each message sent by players.
You must return the message to broadcast it, modified or not. Return
false
to ignore the message.
-
'onDisconnect'
¶ function (room, player) {}
-
'onReconnect'
¶ function (room, player) {}
-
'reconnectDelay'
¶ Integer
After a disconnection, a player has this delay (in second) to reconnect. Use -1 to disable reconnection. Defaults to one minute.
-
'sounds'
¶ Array[Sound]
An array of Sound objects to be preloaded automatically at start. Please provide only tiny sounds to avoid large bandwidth usage.