NPM Publish prep

This commit is contained in:
Jeremiah Billmann
2013-08-01 15:18:40 -04:00
parent 2eb752f71d
commit 65673598dc
9 changed files with 18 additions and 7 deletions
+36
View File
@@ -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;
}
}
}
};
+37
View File
@@ -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;
}
});
};