mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-09 00:20:03 +08:00
Added events
This commit is contained in:
@@ -15,8 +15,19 @@ options = {
|
||||
onPlayerDisconnect: function (socket),
|
||||
onPing: function (socket, data)
|
||||
}
|
||||
api methods
|
||||
createGarageServer(io, options)
|
||||
start()
|
||||
stop()
|
||||
getPlayers() : [player] : { id: '', state: {}, inputs: [{}], stateHistory: [{ state, executionTime }] }
|
||||
getEntities() : [entity] : { id: '', state: {}, stateHistory: [{ state, executionTime }] }
|
||||
updatePlayerState(id, state)
|
||||
updateEntityState(id, state)
|
||||
addEntity(id)
|
||||
removeEntity(id)
|
||||
sendPlayerEvent(id, data)
|
||||
sendPlayersEvent(data)
|
||||
*/
|
||||
|
||||
function GarageServer(socketio, options) {
|
||||
this.socketPath = '/garageserver.io';
|
||||
this.io = socketio;
|
||||
@@ -127,6 +138,14 @@ GarageServer.prototype.removeEntity = function (id) {
|
||||
this.game.removeEntity(id);
|
||||
};
|
||||
|
||||
GarageServer.prototype.sendPlayerEvent = function (id, data) {
|
||||
this.game.sendPlayerEvent(id, data);
|
||||
};
|
||||
|
||||
GarageServer.prototype.sendPlayersEvent = function (data) {
|
||||
this.io.of(this.socketPath).emit('event', data);
|
||||
};
|
||||
|
||||
exports.createGarageServer = function (io, options) {
|
||||
return new GarageServer(io, options);
|
||||
};
|
||||
@@ -20,7 +20,7 @@ GarageServerGame.prototype.start = function () {
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.stop = function () {
|
||||
clearInterval(this.stateIntervalId);
|
||||
clearInterval(this.stateIntervalId);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.broadcastState = function () {
|
||||
@@ -100,4 +100,13 @@ GarageServerGame.prototype.removeEntity = function (id) {
|
||||
|
||||
GarageServerGame.prototype.addPlayerInput = function (id, input, sequence, time) {
|
||||
this.playerController.addInput(id, input, sequence, time);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.sendPlayerEvent = function (id, data) {
|
||||
this.playerController.entities.some(function (player) {
|
||||
if (player.id === id) {
|
||||
player.client.emit('event', data);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user