mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-09-09 11:14:19 +08:00
NPM Publish prep
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
var entity = require('../entities/entity');
|
||||
|
||||
exports = module.exports = EntityController;
|
||||
|
||||
function EntityController (maxHistorySecondBuffer) {
|
||||
this.entities = [];
|
||||
this.maxHistorySecondBuffer = maxHistorySecondBuffer;
|
||||
}
|
||||
|
||||
EntityController.prototype = {
|
||||
add: function (id) {
|
||||
var newEntity, entityFound = false;
|
||||
|
||||
this.entities.some(function (entity) {
|
||||
if (entity.id === id) {
|
||||
newEntity = entity;
|
||||
entityFound = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!entityFound) {
|
||||
newEntity = new entity(id, this.maxHistorySecondBuffer);
|
||||
this.entities.push(newEntity);
|
||||
}
|
||||
return newEntity;
|
||||
},
|
||||
remove: function (id) {
|
||||
for (var i = 0; i < this.entities.length; i ++) {
|
||||
if (this.entities[i].id === id) {
|
||||
this.entities.splice(i, 1)[0];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
var entityController = require('./entitycontroller'),
|
||||
player = require('../entities/player');
|
||||
|
||||
exports = module.exports = PlayerController;
|
||||
|
||||
function PlayerController (maxHistorySecondBuffer) {
|
||||
entityController.call(this, maxHistorySecondBuffer);
|
||||
}
|
||||
|
||||
PlayerController.prototype = Object.create(entityController.prototype);
|
||||
|
||||
PlayerController.prototype.add = function (client) {
|
||||
var newPlayer, playerFound = false;
|
||||
|
||||
this.entities.some(function (player) {
|
||||
if (player.client.id === client.id) {
|
||||
newPlayer = player;
|
||||
playerFound = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!playerFound) {
|
||||
newPlayer = new player(client, this.maxHistorySecondBuffer);
|
||||
this.entities.push(newPlayer);
|
||||
}
|
||||
return newPlayer;
|
||||
};
|
||||
|
||||
PlayerController.prototype.addInput = function (id, input, sequence, time) {
|
||||
this.entities.some(function (player) {
|
||||
if (player.client.id === id) {
|
||||
player.inputs.push({ input: input, seq: sequence, time: time });
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user