Files
GarageServer.IO/lib/controllers/entitycontroller.js
T
Jeremiah Billmann 65673598dc NPM Publish prep
2013-08-01 15:18:40 -04:00

36 lines
959 B
JavaScript

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;
}
}
}
};