controller test
by mmis1000
JavaScript
function controller() {
this.constructerList = [];
this.resourceListByUid = {};
this.resourceByOrigin = {};
this.listGloabal = [];
this.singleListById = {};
this.singleList = [];
this.currentTime = null;
this.firstTime = null;
this.internalTime = 0;
}
/**will ignore any object marked with 'dead'*/
controller.prototype.tick = function tick(list, funcName, info) {
if(this.firstTime === null){this.firstTime = Date.now()}
this.currentTime = Date.now();
this.internalTime = this.currentTime - this.firstTime;
};
/** handle any requirement submitted by the contructer*/
controller.prototype.register = function register(itemConstructer) {
this.constructerList.push(itemConstructer);
/** chainable method */
return this;
};
/** register to global list */
controller.prototype.addItem = function addItem(item) {
this.listGloabal.push(item);
/** chainable method */
return this;
};
controller.prototype.getAllItem = function getAllItem() {
return this.listGloabal;
};
/** register to single list by id */
controller.prototype.addItemToList = function addItemToList(item, id) {
var newList;
if (!this.singleListById[id]) {
newList = {
items : [],
id : id
}
this.singleListById[id] = newList;
this.singleList.push(newList)
}
this.singleListById[id].items.push(item);
};
controller.prototype.getList = function getList(id) {
if(!this.singleListById[id]) {
return false;
}
return this.singleListById[id].items;
};
controller.prototype.getResource = function getResource(UID) {
}
/** start to load any resource required */
controller.prototype.exec = function exec(callback) {
};
/** remove all dead object */
controller.prototype.clear = function clear() {
var i, j;
var items
items = this.listGloabal
for (i = items.length - 1; i >= 0; i--) {
if (items[i].dead === true) {
...