-
Notifications
You must be signed in to change notification settings - Fork 5
🔌Socket.IO API docs
Shea Janke edited this page Apr 26, 2020
·
5 revisions
Message name | Description | Message data | Callback |
---|---|---|---|
newgame |
Generates a new game ID, starts a new game and makes the client the host of the game | none | Returns { gameID: "ABCDE" }
|
joingame |
Joins an existing game | { gameID: "ABCDE", username: "my-user" } |
Returns { gameState: "joined game's current state" }
|
updateGameState |
Changes the state of the current game. Client must be the host of the game. Sends a gameStateChanged message to all clients in the game. |
{ gameState: "new game state" } |
Returns { message: "ok" }
|
game-message |
General purpose message for the React app and Unity app to send messages to each other about events happening in the game. See game-message actions section | { action: "action name", /* other properties as needed */ } |
Returns { message: "ok" }
|
When an emitted message causes an error, the returned object from the callback contains the property error: "error message here"
, example: { error: "Invalid game id" }
Message name | Description | Message data |
---|---|---|
playerConnect |
When a player connects to the current game | { username: "player's username" } |
playerDisconnect |
When a player disconnects to the current game | { username: "player's username" } |
gameStateChanged |
When the current game's state changes. Caused by the game's host sending a updateGameState message |
{ gameState: "the new game state" } |
game-message |
General purpose message for the React app and Unity app to send messages to each other about events happening in the game. See game-message actions section | { action: "action name", username: "user who sent the message", /* other properties as needed */ } |
When receiving a game-message, there will also be the property { username: "sender's username }
action | description | properties |
---|---|---|
submitrobot |
When a user submits their built robot | { parts: [/* list of parts the robot is made of. See Robot parts format section */] } |
currentParts |
When a part is destroyed | { parts: [/* list of parts the robot is made of. See Robot parts format section */], name: /* name of the gameObject whose parts are being sent. */} |
currentBoosts |
When a player gains or uses a boost. | { boosts: /* number of boosts the player has. */, name: /* name of the gameObject whose parts are being sent. */} |
Specifying a robot is done by sending an array of parts, each part has the following properties:
- type: "block" | "center" | "spike"
- x: 0 - 4
- y: 0 - 4
- direction: "north" | "east" | "south" | "west"
- health: 0.0 - 1.0
Example:
[
{
"type": "block",
"x": 2,
"y": 4,
"direction": "north",
"health": 1.0
},
{
"type": "spike",
"x": 2,
"y": 3,
"direction": "north",
"health": 1.0
},
{
"type": "center",
"x": 3,
"y": 3,
"direction": "north",
"health": 1.0
}
]