r3-legacy/src/game-lib-system-0.js

93 lines
2.1 KiB
JavaScript

/**
* System takes care of updating all the entities (based on their component data)
* @param implementation
* @param apiSystem GameLib.API.System
* @constructor
*/
GameLib.System = function(
apiSystem
) {
if (GameLib.Utils.UndefinedOrNull(apiSystem)) {
apiSystem = {};
}
if (apiSystem instanceof GameLib.System) {
return apiSystem;
}
GameLib.API.System.call(
this,
apiSystem.id,
apiSystem.name,
apiSystem.systemType,
apiSystem.parentEntity
);
this.started = false;
this.paused = false;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SYSTEM
);
};
GameLib.System.prototype = Object.create(GameLib.API.System.prototype);
GameLib.System.prototype.constructor = GameLib.System;
GameLib.System.SYSTEM_TYPE_NONE = 0x0;
GameLib.System.SYSTEM_TYPE_RENDER = 0x1;
GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
GameLib.System.SYSTEM_TYPE_INPUT = 0x4;
GameLib.System.SYSTEM_TYPE_STORAGE = 0x8;
GameLib.System.SYSTEM_TYPE_GUI = 0x10;
GameLib.System.SYSTEM_TYPE_PHYSICS = 0x20;
GameLib.System.SYSTEM_TYPE_LINKING = 0x40;
GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80;
GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100;
GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF;
GameLib.System.prototype.createInstance = function() {
this.instance = true;
GameLib.Component.prototype.createInstance.call(this);
};
/**
* @callback
* @override
*/
GameLib.System.prototype.start = function() {
this.started = true;
console.log('starting ' + this.name);
};
/**
* @callback
* @override
*/
GameLib.System.prototype.stop = function() {
this.started = false;
console.log('stopping ' + this.name);
};
/**
* Converts runtime vector to API Vector
* @returns {GameLib.API.System}
*/
GameLib.System.prototype.toApiObject = function() {
return new GameLib.API.System(
this.id,
this.name,
this.systemType,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
GameLib.System.prototype.restart = function() {
console.log('restarting system : ' + this.name);
this.stop();
this.start();
};