sam-ecs
Version:
A specialized entity component system
75 lines (61 loc) • 2.58 kB
JavaScript
;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//Processor.js//
/**
* @description - Defines a Processor's behavior. A processor 'processes' state
* and is updated every time. Each one is defined by the type of components
* it updates. Example: RenderProcessor processes every RenderComponent every
* frame to update the render view
* @author Samuel Faulkner
*/
var Processor = function () {
function Processor(name, manager) {
_classCallCheck(this, Processor);
var functions = ['update', 'getComponentNames'];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = functions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var fun = _step.value;
if (!this[fun]) {
throw new TypeError("'" + fun + "' function must be defined");
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
this._name = name;
this.manager = manager;
}
_createClass(Processor, [{
key: 'getName',
value: function getName() {
return this._name;
}
/**
* @description - called every frame to process the logic on the given
* entities
* @param {Array} entities - list of entities that intersect all of the
* component types that the processor was added to the manager with
* @param {Manager} manager - Manager object itself
*/
//abstract update(entites, manager)
}]);
return Processor;
}();
module.exports = {
Processor: Processor
};