mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-01 12:11:03 +08:00
Progress: Client
This commit is contained in:
@@ -11,11 +11,18 @@ window.GarageServerIO = (function (window, socketio) {
|
||||
|
||||
registerSocketEvents = function () {
|
||||
io.on('update', function(data) {
|
||||
|
||||
if(garageServerGame.addPlayerInput) {
|
||||
garageServerGame.addPlayerInput(data);
|
||||
}
|
||||
});
|
||||
io.on('ping', function(data) {
|
||||
|
||||
});
|
||||
io.on('removePlayer', function(id) {
|
||||
if(garageServerGame.removePlayer) {
|
||||
garageServerGame.removePlayer(id);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
startGarageServerGame = function (options) {
|
||||
@@ -23,15 +30,34 @@ window.GarageServerIO = (function (window, socketio) {
|
||||
};
|
||||
|
||||
function GarageServerGame (options) {
|
||||
|
||||
this.players = [];
|
||||
this.updates = [];
|
||||
}
|
||||
|
||||
GarageServerGame.prototype.update = function () {
|
||||
GarageServerGame.prototype.addPlayerInput = function (input) {
|
||||
this.updates.push(input);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.sendPlayerInput = function (input) {
|
||||
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.removePlayer = function (id) {
|
||||
for(var i = 0; i < this.players.length; i ++) {
|
||||
if(this.players[i].id === id) {
|
||||
this.players.splice(i, 1)[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updatePlayers = function () {
|
||||
|
||||
};
|
||||
|
||||
return {
|
||||
connectToGarageServer: connectToGarageServer
|
||||
connectToGarageServer: connectToGarageServer,
|
||||
startGarageServerGame: startGarageServerGame
|
||||
};
|
||||
|
||||
}) (window, io);
|
||||
@@ -39,6 +39,7 @@ GarageServer.prototype.onPlayerConnect = function (socket, options) {
|
||||
|
||||
GarageServer.prototype.onPlayerDisconnect = function (socket, options) {
|
||||
this.game.removePlayer(socket);
|
||||
socket.broadcast.emit('removePlayer', socket.id);
|
||||
if(options.onPlayerDisconnect) {
|
||||
options.onPlayerDisconnect(socket);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ GarageServerGame.prototype.removePlayer = function (client) {
|
||||
for(var i = 0; i < this.players.length; i ++) {
|
||||
if(this.players[i].id === client.id) {
|
||||
this.players.splice(i, 1)[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user