Command

Updated for v1.0.0

A command consists of zero or more properties and values to be sent from the game client to the server instance.

To make a command that is compatible with nengi, do the following:

ExampleCommand

class ExampleCommand {
    constructor(x, y, isMouseDown) {
        this.mouseX = x
        this.mouseY = y
        this.isMouseDown = isMouseDown
    }
}
ExampleCommand.protocol = {
    mouseX: nengi.Number,
    mouseY: nengi.Number,
    isMouseDown: nengi.Boolean
}

After creating this definition, be sure to add it to the nengiConfig protocols.

nengiConfig

import ExampleCommand from './path/ExampleCommand'
/* ... */
commands: [
    ['ExampleCommand', ExampleCommand]
],

usage (clientside)

client.addCommand(new ExampleCommand(40, 50, false))

Add as many commands as needed throughout the course of a frame on the client, and then invoke client.update() at the end of the frame.

usage (serverside)

See the manual page for nengi.Instance for information about receiving the command on the server side.

From here the command can be used to affect the game state on the server.