diff --git a/lib/ouyo.js b/lib/ouyo.js index 842a33b..86ada96 100644 --- a/lib/ouyo.js +++ b/lib/ouyo.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("OUYO",[],t):"object"==typeof exports?exports.OUYO=t():e.OUYO=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,n){"use strict";function i(e,t){for(var n=[],i=0;i=o;)n++,e-=o;var i=0!=(this.values[n]&s[e]);t&&!i?this.values[n]+=s[e]:!t&&i&&(this.values[n]-=s[e])}},{key:"matches",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:l.a;i(this,e),this.changed=[],this.removed=[],this.systems=[],this.queries=[],this.events=[],this.eventTimes={},this.componentCount=0,this.started=!1,this.runtime=0,this.registerUpdate=n,this.onEntityChange=function(e){return t.changed.push(e)}}return v(e,[{key:"createComponent",value:function(){Object(h.a)(!this.started,"Cannot create component after the game was started.");for(var e=arguments.length,t=Array(e),n=0;nt&&(t=n)}),t}n.d(t,"a",function(){return c});var o=n(1),s=n(8),u=n(0),a=function(){function e(e,t){for(var n=0;n=o;)n++,e-=o;var i=0!=(this.values[n]&s[e]);t&&!i?this.values[n]+=s[e]:!t&&i&&(this.values[n]-=s[e])}},{key:"matches",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:l.a;i(this,e),this.changed=[],this.removed=[],this.systems=[],this.queries=[],this.events=[],this.eventTimes={},this.componentCount=0,this.started=!1,this.runtime=0,this.registerUpdate=n,this.onEntityChange=function(e){return t.changed.push(e)}}return v(e,[{key:"createComponent",value:function(){Object(h.a)(!this.started,"Cannot create component after the game was started.");for(var e=arguments.length,t=Array(e),n=0;n0&&void 0!==arguments[0]?arguments[0]:d;Object(h.a)(this.started,"Entities cannot be created before the game is started.");var t=new c.a(this.componentCount,this.onEntityChange);return e(t),t}},{key:"removeEntity",value:function(e){Object(h.a)(this.started,"Entities cannot be removed before the game is started."),this.removed.push(e)}},{key:"emit",value:function(e){"string"==typeof e&&(e={type:e});var t=this.runtime,n=o(this.eventTimes[e.type],t);e.timeDelta=(t-n)/1e3,this.eventTimes[e.type]=t,this.events.push(e)}}]),e}()},function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e){for(var t=[],n=0;nt&&(t=n)}),t}n.d(t,"a",function(){return c});var o=n(1),s=n(8),u=n(0),a=function(){function e(e,t){for(var n=0;n= KEY_BITS) {\n valueIndex++;\n index -= KEY_BITS;\n }\n\n var previousValue = (this.values[valueIndex] & POWERS[index]) !== 0;\n if (value && !previousValue) {\n this.values[valueIndex] += POWERS[index];\n } else if (!value && previousValue) {\n this.values[valueIndex] -= POWERS[index];\n }\n }\n }, {\n key: \"matches\",\n value: function matches(other) {\n for (var _i2 = 0; _i2 < other.values.length; _i2++) {\n var currentValue = this.values[_i2] || 0;\n var otherValue = other.values[_i2];\n if ((currentValue & otherValue) !== otherValue) {\n return false;\n }\n }\n return true;\n }\n }]);\n\n return Key;\n}();\n\n/***/ }),\n/* 2 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\nObject.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Game__ = __webpack_require__(3);\n/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, \"Game\", function() { return __WEBPACK_IMPORTED_MODULE_0__Game__[\"a\"]; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Query__ = __webpack_require__(7);\n/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, \"Query\", function() { return __WEBPACK_IMPORTED_MODULE_1__Query__[\"a\"]; });\n\n\n\n/***/ }),\n/* 3 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Game; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Entity__ = __webpack_require__(4);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(0);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__component__ = __webpack_require__(5);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__ticker__ = __webpack_require__(6);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\n\n\nvar Game = function () {\n function Game() {\n var _this = this;\n\n var registerUpdate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : __WEBPACK_IMPORTED_MODULE_3__ticker__[\"a\" /* defaultTicker */];\n\n _classCallCheck(this, Game);\n\n this.changed = [];\n this.removed = [];\n\n this.systems = [];\n this.queries = [];\n\n this.events = [];\n this.eventTimes = {};\n\n this.componentCount = 0;\n\n this.started = false;\n this.runtime = 0;\n this.registerUpdate = registerUpdate;\n this.onEntityChange = function (entity) {\n return _this.changed.push(entity);\n };\n }\n\n _createClass(Game, [{\n key: 'createComponent',\n value: function createComponent() {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'Cannot create component after the game was started.');\n\n for (var _len = arguments.length, fields = Array(_len), _key = 0; _key < _len; _key++) {\n fields[_key] = arguments[_key];\n }\n\n return Object(__WEBPACK_IMPORTED_MODULE_2__component__[\"a\" /* createComponent */])(fields, this.componentCount++);\n }\n }, {\n key: 'registerSystems',\n value: function registerSystems(systems) {\n var _this2 = this;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(systems, function (system) {\n return _this2._registerSystem(system);\n });\n }\n }, {\n key: '_registerSystem',\n value: function _registerSystem(system) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'Cannot register systems after the game was started.');\n\n var unifiedSystem = {\n query: system.query || [],\n on: system.on,\n process: system.process || createProcess(system.processEntity)\n };\n\n this.systems.push(unifiedSystem);\n this._registerQuery(system.query);\n }\n }, {\n key: '_registerQuery',\n value: function _registerQuery(query) {\n var _this3 = this;\n\n if (Array.isArray(query)) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(query, function (subQuery) {\n return _this3.queries.push(subQuery);\n });\n } else if (query) {\n this.queries.push(query);\n }\n }\n }, {\n key: 'start',\n value: function start(init) {\n var _this4 = this;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'A game can only be started once!');\n this.started = true;\n\n init(this);\n\n this.registerUpdate(function (timeDelta) {\n return _this4._update(timeDelta);\n });\n }\n }, {\n key: '_update',\n value: function _update(timeDelta) {\n var _this5 = this;\n\n this.runtime += timeDelta;\n this.events.length = 0;\n this.emit('tick');\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(this.systems, function (system) {\n return _this5._runSystem(system);\n });\n }\n }, {\n key: '_runSystem',\n value: function _runSystem(system, timeDelta) {\n var _this6 = this;\n\n var events = this._getEventsFor(system);\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(events, function (event) {\n _this6._handleChanges();\n var entities = getEntities(system.query);\n system.process(entities, event, _this6);\n });\n }\n }, {\n key: '_getEventsFor',\n value: function _getEventsFor(system) {\n if (!system.on) {\n return [this.events[0]];\n } else {\n return this.events.filter(function (event) {\n return event.type === system.on;\n });\n }\n }\n }, {\n key: '_handleChanges',\n value: function _handleChanges() {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"c\" /* forEach2 */])(this.changed, this.queries, handleEntityChange);\n this.changed.length = 0;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"c\" /* forEach2 */])(this.removed, this.queries, handleEntityRemove);\n this.removed.length = 0;\n }\n }, {\n key: 'createEntity',\n value: function createEntity() {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(this.started, 'Entities cannot be created before the game is started.');\n return new __WEBPACK_IMPORTED_MODULE_0__Entity__[\"a\" /* Entity */](this.componentCount, this.onEntityChange);\n }\n }, {\n key: 'removeEntity',\n value: function removeEntity(entity) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(this.started, 'Entities cannot be removed before the game is started.');\n this.removed.push(entity);\n }\n }, {\n key: 'emit',\n value: function emit(event) {\n if (typeof event === 'string') {\n event = { type: event };\n }\n var now = this.runtime;\n var lastTime = fallback(this.eventTimes[event.type], now);\n event.timeDelta = (now - lastTime) / 1000;\n this.eventTimes[event.type] = now;\n this.events.push(event);\n }\n }]);\n\n return Game;\n}();\n\nfunction createProcess(processEntity) {\n return function (entities, event, game) {\n for (var i = 0; i < entities.length; ++i) {\n processEntity(entities[i], event, game);\n }\n };\n}\n\nfunction fallback(value, fallback) {\n return value !== undefined ? value : fallback;\n}\n\nfunction getEntities(query) {\n if (Array.isArray(query)) {\n return Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"d\" /* map */])(query, function (subQuery) {\n return subQuery.entities;\n });\n } else {\n return query.entities;\n }\n}\n\nfunction handleEntityChange(entity, query) {\n query.onChange(entity);\n}\n\nfunction handleEntityRemove(entity, query) {\n query.onRemove(entity);\n}\n\n/***/ }),\n/* 4 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Entity; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Key__ = __webpack_require__(1);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(0);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\nvar index = 0;\n\nvar Entity = function () {\n function Entity(componentCount, onKeyChanged) {\n _classCallCheck(this, Entity);\n\n this.id = index++;\n\n this.key = new __WEBPACK_IMPORTED_MODULE_0__Key__[\"a\" /* Key */](componentCount);\n this._components = makeNullArray(componentCount);\n\n this._changeAnnounced = false;\n this._onKeyChanged = onKeyChanged;\n }\n\n _createClass(Entity, [{\n key: 'add',\n value: function add(componentInstance) {\n var index = componentInstance._id;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this._components[index], 'Cannot add another instance of the same component.');\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(index < this._components.length, 'Unknown component passed as argument.');\n\n this.key.setBit(index, true);\n this._components[index] = componentInstance;\n\n this._onChange();\n return this;\n }\n }, {\n key: 'has',\n value: function has(Component) {\n return !!this._components[Component.id];\n }\n }, {\n key: 'get',\n value: function get(Component) {\n var component = this._components[Component.id];\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(component, 'Requested component is not present.');\n return component;\n }\n }, {\n key: 'remove',\n value: function remove(Component) {\n var index = Component.id;\n var component = this._components[index];\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(component, 'Cannot remove component instance, because it doesn\\'t exist on target entity.');\n\n this.key.unset(index);\n this._components[index] = null;\n this._onChange();\n return this;\n }\n }, {\n key: '_onChange',\n value: function _onChange() {\n if (!this._changeAnnounced) {\n this._onKeyChanged(this);\n }\n this._changeAnnounced = true;\n }\n }, {\n key: 'onChangeRegistered',\n value: function onChangeRegistered() {\n this._changeAnnounced = false;\n }\n }]);\n\n return Entity;\n}();\n\nfunction makeNullArray(size) {\n var array = [];\n for (var i = 0; i < size; i++) {\n array[i] = null;\n }\n return array;\n}\n\n/***/ }),\n/* 5 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (immutable) */ __webpack_exports__[\"a\"] = createComponent;\n/* unused harmony export decorate */\nfunction createComponent(fields, id) {\n var body = '';\n for (var i = 0; i < fields.length; i++) {\n var field = fields[i];\n if (/^[a-zA-Z]\\w*$/.exec(field)) {\n body += 'this.' + field + '=' + field + ';';\n } else {\n throw new Error('Invalid identifier: ' + field);\n }\n }\n /* eslint-disable no-new-func */\n return decorate(new Function(fields, body), id);\n}\n\nfunction decorate(constructor, id) {\n constructor.id = id;\n constructor.prototype._id = id;\n return constructor;\n}\n\n/***/ }),\n/* 6 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return defaultTicker; });\nvar defaultTicker = function defaultTicker(update) {\n window.requestAnimationFrame(onAnimationFrame);\n var lastTime = Date.now();\n function onAnimationFrame() {\n window.requestAnimationFrame(onAnimationFrame);\n var now = Date.now();\n update(Math.min(now - lastTime, 100));\n lastTime = now;\n }\n};\n\n/***/ }),\n/* 7 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Query; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Key__ = __webpack_require__(1);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__IndexedArray__ = __webpack_require__(8);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__utils__ = __webpack_require__(0);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\n\nvar Query = function () {\n function Query() {\n var _this = this;\n\n _classCallCheck(this, Query);\n\n this._entities = new __WEBPACK_IMPORTED_MODULE_1__IndexedArray__[\"a\" /* IndexedArray */]();\n this._one = false;\n\n for (var _len = arguments.length, components = Array(_len), _key = 0; _key < _len; _key++) {\n components[_key] = arguments[_key];\n }\n\n this.key = new __WEBPACK_IMPORTED_MODULE_0__Key__[\"a\" /* Key */](maxId(components) + 1);\n Object(__WEBPACK_IMPORTED_MODULE_2__utils__[\"b\" /* forEach */])(components, function (_ref) {\n var id = _ref.id;\n return _this.key.set(id);\n });\n }\n\n _createClass(Query, [{\n key: 'one',\n value: function one() {\n this._one = true;\n return this;\n }\n }, {\n key: 'onChange',\n value: function onChange(entity) {\n var isInQuery = this._entities.has(entity);\n var matched = entity.key.matches(this.key);\n\n if (!isInQuery && matched) {\n this._entities.put(entity);\n } else if (isInQuery && !matched) {\n this._entities.remove(entity);\n }\n }\n }, {\n key: 'onRemove',\n value: function onRemove(entity) {\n this._entities.remove(entity);\n }\n }, {\n key: 'entities',\n get: function get() {\n return this._one ? this._entities.elements[0] : this._entities.elements;\n }\n }]);\n\n return Query;\n}();\n\nfunction maxId(components) {\n var maxId = 0;\n Object(__WEBPACK_IMPORTED_MODULE_2__utils__[\"b\" /* forEach */])(components, function (_ref2) {\n var id = _ref2.id;\n return id > maxId && (maxId = id);\n });\n return maxId;\n}\n\n/***/ }),\n/* 8 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return IndexedArray; });\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar IndexedArray = function () {\n function IndexedArray() {\n _classCallCheck(this, IndexedArray);\n\n this._indices = {};\n this.elements = [];\n }\n\n _createClass(IndexedArray, [{\n key: \"put\",\n value: function put(object) {\n this._indices[object.id] = this.elements.length;\n this.elements.push(object);\n }\n }, {\n key: \"has\",\n value: function has(object) {\n return this._indices[object.id] !== undefined;\n }\n }, {\n key: \"remove\",\n value: function remove(object) {\n var index = this._indices[object.id];\n if (index !== undefined) {\n delete this._indices[object.id];\n var otherObject = this.elements.pop();\n if (otherObject.id !== object.id) {\n this.elements[index] = otherObject;\n this._indices[otherObject.id] = index;\n }\n }\n }\n }]);\n\n return IndexedArray;\n}();\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// ouyo.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 14792c71cdfbf6e37dbd","export function map (array, fn) {\n let result = []\n for (let i = 0; i < array.length; i++) {\n result[i] = fn(array[i])\n }\n return result\n}\n\nexport function forEach (array, fn) {\n for (let i = 0; i < array.length; i++) {\n fn(array[i])\n }\n}\n\nexport function forEach2 (a, b, fn) {\n for (let i = 0; i < a.length; i++) {\n let aItem = a[i]\n for (let j = 0; j < b.length; j++) {\n fn(aItem, b[j])\n }\n }\n}\n\nexport function assert (condition, errorMessage) {\n if (!condition) {\n throw new Error(errorMessage)\n }\n}\n\nexport function xor (a, b) {\n return (a || b) && !(a && b)\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.js","const KEY_BITS = 31\r\n\r\nconst POWERS = []\r\nfor (let i = 0; i < KEY_BITS; i++) {\r\n POWERS[i] = 2 ** i\r\n}\r\n\r\nexport class Key {\r\n constructor (length) {\r\n this.values = []\r\n for (let i = 0; i < length / KEY_BITS; i++) {\r\n this.values.push(0)\r\n }\r\n }\r\n\r\n set (index) {\r\n this.setBit(index, true)\r\n return this\r\n }\r\n\r\n unset (index) {\r\n this.setBit(index, false)\r\n return this\r\n }\r\n\r\n setBit (index, value) {\r\n let valueIndex = 0\r\n while (index >= KEY_BITS) {\r\n valueIndex++\r\n index -= KEY_BITS\r\n }\r\n\r\n const previousValue = (this.values[valueIndex] & POWERS[index]) !== 0\r\n if (value && !previousValue) {\r\n this.values[valueIndex] += POWERS[index]\r\n } else if (!value && previousValue) {\r\n this.values[valueIndex] -= POWERS[index]\r\n }\r\n }\r\n\r\n matches (other) {\r\n for (let i = 0; i < other.values.length; i++) {\r\n const currentValue = this.values[i] || 0\r\n const otherValue = other.values[i]\r\n if ((currentValue & otherValue) !== otherValue) {\r\n return false\r\n }\r\n }\r\n return true\r\n }\r\n}\r\n\n\n\n// WEBPACK FOOTER //\n// ./src/Key.js","import { Entity } from './Entity'\nimport { assert, map, forEach, forEach2 } from './utils'\nimport { createComponent } from './component'\nimport { defaultTicker } from './ticker'\n\nexport class Game {\n constructor (registerUpdate = defaultTicker) {\n this.changed = []\n this.removed = []\n\n this.systems = []\n this.queries = []\n\n this.events = []\n this.eventTimes = {}\n\n this.componentCount = 0\n\n this.started = false\n this.runtime = 0\n this.registerUpdate = registerUpdate\n this.onEntityChange = entity => this.changed.push(entity)\n }\n\n createComponent (...fields) {\n assert(!this.started, 'Cannot create component after the game was started.')\n return createComponent(fields, this.componentCount++)\n }\n\n registerSystems (systems) {\n forEach(systems, system => this._registerSystem(system))\n }\n\n _registerSystem (system) {\n assert(!this.started, 'Cannot register systems after the game was started.')\n\n const unifiedSystem = {\n query: system.query || [],\n on: system.on,\n process: system.process || createProcess(system.processEntity)\n }\n\n this.systems.push(unifiedSystem)\n this._registerQuery(system.query)\n }\n\n _registerQuery (query) {\n if (Array.isArray(query)) {\n forEach(query, subQuery => this.queries.push(subQuery))\n } else if (query) {\n this.queries.push(query)\n }\n }\n\n start (init) {\n assert(!this.started, 'A game can only be started once!')\n this.started = true\n\n init(this)\n\n this.registerUpdate(timeDelta => this._update(timeDelta))\n }\n\n _update (timeDelta) {\n this.runtime += timeDelta\n this.events.length = 0\n this.emit('tick')\n forEach(this.systems, system => this._runSystem(system))\n }\n\n _runSystem (system, timeDelta) {\n const events = this._getEventsFor(system)\n forEach(events, event => {\n this._handleChanges()\n const entities = getEntities(system.query)\n system.process(entities, event, this)\n })\n }\n\n _getEventsFor (system) {\n if (!system.on) {\n return [this.events[0]]\n } else {\n return this.events.filter(event => event.type === system.on)\n }\n }\n\n _handleChanges () {\n forEach2(this.changed, this.queries, handleEntityChange)\n this.changed.length = 0\n\n forEach2(this.removed, this.queries, handleEntityRemove)\n this.removed.length = 0\n }\n\n createEntity () {\n assert(this.started, 'Entities cannot be created before the game is started.')\n return new Entity(this.componentCount, this.onEntityChange)\n }\n\n removeEntity (entity) {\n assert(this.started, 'Entities cannot be removed before the game is started.')\n this.removed.push(entity)\n }\n\n emit (event) {\n if (typeof event === 'string') {\n event = { type: event }\n }\n const now = this.runtime\n const lastTime = fallback(this.eventTimes[event.type], now)\n event.timeDelta = (now - lastTime) / 1000\n this.eventTimes[event.type] = now\n this.events.push(event)\n }\n}\n\nfunction createProcess (processEntity) {\n return function (entities, event, game) {\n for (let i = 0; i < entities.length; ++i) {\n processEntity(entities[i], event, game)\n }\n }\n}\n\nfunction fallback (value, fallback) {\n return value !== undefined ? value : fallback\n}\n\nfunction getEntities (query) {\n if (Array.isArray(query)) {\n return map(query, subQuery => subQuery.entities)\n } else {\n return query.entities\n }\n}\n\nfunction handleEntityChange (entity, query) {\n query.onChange(entity)\n}\n\nfunction handleEntityRemove (entity, query) {\n query.onRemove(entity)\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Game.js","import { Key } from './Key'\nimport { assert } from './utils'\n\nlet index = 0\n\nexport class Entity {\n constructor (componentCount, onKeyChanged) {\n this.id = index++\n\n this.key = new Key(componentCount)\n this._components = makeNullArray(componentCount)\n\n this._changeAnnounced = false\n this._onKeyChanged = onKeyChanged\n }\n\n add (componentInstance) {\n const index = componentInstance._id\n\n assert(!this._components[index], 'Cannot add another instance of the same component.')\n assert(index < this._components.length, 'Unknown component passed as argument.')\n\n this.key.setBit(index, true)\n this._components[index] = componentInstance\n\n this._onChange()\n return this\n }\n\n has (Component) {\n return !!this._components[Component.id]\n }\n\n get (Component) {\n const component = this._components[Component.id]\n assert(component, 'Requested component is not present.')\n return component\n }\n\n remove (Component) {\n const index = Component.id\n const component = this._components[index]\n\n assert(component, 'Cannot remove component instance, because it doesn\\'t exist on target entity.')\n\n this.key.unset(index)\n this._components[index] = null\n this._onChange()\n return this\n }\n\n _onChange () {\n if (!this._changeAnnounced) {\n this._onKeyChanged(this)\n }\n this._changeAnnounced = true\n }\n\n onChangeRegistered () {\n this._changeAnnounced = false\n }\n}\n\nfunction makeNullArray (size) {\n const array = []\n for (let i = 0; i < size; i++) {\n array[i] = null\n }\n return array\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Entity.js","export function createComponent (fields, id) {\n let body = ''\n for (let i = 0; i < fields.length; i++) {\n let field = fields[i]\n if (/^[a-zA-Z]\\w*$/.exec(field)) {\n body += `this.${field}=${field};`\n } else {\n throw new Error('Invalid identifier: ' + field)\n }\n }\n /* eslint-disable no-new-func */\n return decorate(new Function(fields, body), id)\n}\n\nexport function decorate (constructor, id) {\n constructor.id = id\n constructor.prototype._id = id\n return constructor\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/component.js","export const defaultTicker = function (update) {\n window.requestAnimationFrame(onAnimationFrame)\n let lastTime = Date.now()\n function onAnimationFrame () {\n window.requestAnimationFrame(onAnimationFrame)\n let now = Date.now()\n update(Math.min(now - lastTime, 100))\n lastTime = now\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ticker.js","import { Key } from './Key'\nimport { IndexedArray } from './IndexedArray'\nimport { forEach } from './utils'\n\nexport class Query {\n constructor (...components) {\n this._entities = new IndexedArray()\n this._one = false\n\n this.key = new Key(maxId(components) + 1)\n forEach(components, ({ id }) => this.key.set(id))\n }\n\n one () {\n this._one = true\n return this\n }\n\n get entities () {\n return this._one\n ? this._entities.elements[0]\n : this._entities.elements\n }\n\n onChange (entity) {\n const isInQuery = this._entities.has(entity)\n const matched = entity.key.matches(this.key)\n\n if (!isInQuery && matched) {\n this._entities.put(entity)\n } else if (isInQuery && !matched) {\n this._entities.remove(entity)\n }\n }\n\n onRemove (entity) {\n this._entities.remove(entity)\n }\n}\n\nfunction maxId (components) {\n let maxId = 0\n forEach(components, ({ id }) => id > maxId && (maxId = id))\n return maxId\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Query.js","export class IndexedArray {\n constructor () {\n this._indices = {}\n this.elements = []\n }\n\n put (object) {\n this._indices[object.id] = this.elements.length\n this.elements.push(object)\n }\n\n has (object) {\n return this._indices[object.id] !== undefined\n }\n\n remove (object) {\n const index = this._indices[object.id]\n if (index !== undefined) {\n delete this._indices[object.id]\n const otherObject = this.elements.pop()\n if (otherObject.id !== object.id) {\n this.elements[index] = otherObject\n this._indices[otherObject.id] = index\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/IndexedArray.js"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///ouyo.js","webpack:///webpack/bootstrap c36d6c916fdb32d97b33","webpack:///./src/utils.js","webpack:///./src/Key.js","webpack:///./src/Game.js","webpack:///./src/Entity.js","webpack:///./src/component.js","webpack:///./src/ticker.js","webpack:///./src/Query.js","webpack:///./src/IndexedArray.js"],"names":["root","factory","exports","module","define","amd","self","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","__webpack_exports__","map","array","fn","result","length","forEach","forEach2","a","b","aItem","j","assert","condition","errorMessage","Error","_classCallCheck","instance","Constructor","TypeError","Key","_createClass","defineProperties","target","props","descriptor","writable","key","protoProps","staticProps","KEY_BITS","POWERS","Math","pow","values","push","value","index","setBit","valueIndex","previousValue","other","currentValue","otherValue","__WEBPACK_IMPORTED_MODULE_0__Game__","__WEBPACK_IMPORTED_MODULE_1__Query__","createProcess","processEntity","entities","event","game","fallback","undefined","getEntities","query","Array","isArray","__WEBPACK_IMPORTED_MODULE_1__utils__","subQuery","handleEntityChange","entity","onChange","handleEntityRemove","onRemove","Game","__WEBPACK_IMPORTED_MODULE_0__Entity__","__WEBPACK_IMPORTED_MODULE_2__component__","__WEBPACK_IMPORTED_MODULE_3__ticker__","doNothing","_this","registerUpdate","arguments","changed","removed","systems","queries","events","eventTimes","componentCount","started","runtime","onEntityChange","_len","fields","_key","_this2","system","_registerSystem","unifiedSystem","on","process","_registerQuery","_this3","init","_this4","timeDelta","_update","_this5","emit","_runSystem","_this6","_getEventsFor","_handleChanges","filter","type","assemblage","now","lastTime","makeNullArray","size","Entity","__WEBPACK_IMPORTED_MODULE_0__Key__","onKeyChanged","id","_components","_changeAnnounced","_onKeyChanged","componentInstance","_id","_onChange","Component","component","unset","createComponent","body","field","exec","decorate","Function","constructor","defaultTicker","update","onAnimationFrame","window","requestAnimationFrame","Date","min","maxId","components","__WEBPACK_IMPORTED_MODULE_2__utils__","_ref2","Query","__WEBPACK_IMPORTED_MODULE_1__IndexedArray__","_entities","_one","_ref","set","isInQuery","has","matched","matches","put","remove","elements","IndexedArray","_indices","otherObject","pop"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,OAAA,UAAAH,GACA,gBAAAC,SACAA,QAAA,KAAAD,IAEAD,EAAA,KAAAC,KACC,mBAAAK,WAAAC,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAR,OAGA,IAAAC,GAAAQ,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAX,WAUA,OANAM,GAAAE,GAAAI,KAAAX,EAAAD,QAAAC,IAAAD,QAAAO,GAGAN,EAAAU,GAAA,EAGAV,EAAAD,QAvBA,GAAAS,KA4DA,OAhCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,SAAAf,EAAAgB,EAAAC,GACAV,EAAAW,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAV,EAAAiB,EAAA,SAAAvB,GACA,GAAAgB,GAAAhB,KAAAwB,WACA,WAA2B,MAAAxB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAM,GAAAQ,EAAAE,EAAA,IAAAA,GACAA,GAIAV,EAAAW,EAAA,SAAAQ,EAAAC,GAAsD,MAAAR,QAAAS,UAAAC,eAAAjB,KAAAc,EAAAC,IAGtDpB,EAAAuB,EAAA,GAGAvB,IAAAwB,EAAA,KDgBM,SAAU9B,EAAQ+B,EAAqBzB,GAE7C,YE/EO,SAAS0B,GAAKC,EAAOC,GAE1B,IAAK,GADDC,MACK1B,EAAI,EAAGA,EAAIwB,EAAMG,OAAQ3B,IAChC0B,EAAO1B,GAAKyB,EAAGD,EAAMxB,GAEvB,OAAO0B,GAGF,QAAS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AqB,IAAK,WAAa,MAAO0J,IACnG,IAAIrI,GAAe,WAAc,QAASC,GAAiBC,EAAQC,GAAS,IAAK,GAAI9C,GAAI,EAAGA,EAAI8C,EAAMnB,OAAQ3B,IAAK,CAAE,GAAI+C,GAAaD,EAAM9C,EAAI+C,GAAWnC,WAAamC,EAAWnC,aAAc,EAAOmC,EAAWpC,cAAe,EAAU,SAAWoC,KAAYA,EAAWC,UAAW,GAAMvC,OAAOC,eAAemC,EAAQE,EAAWE,IAAKF,IAAiB,MAAO,UAAUP,EAAaU,EAAYC,GAAiJ,MAA9HD,IAAYN,EAAiBJ,EAAYtB,UAAWgC,GAAiBC,GAAaP,EAAiBJ,EAAaW,GAAqBX,MSnoBnhBwI,EAAb,WACE,QAAAA,KAAe1I,EAAA3C,KAAAqL,GACbrL,KAAKsL,YACLtL,KAAKoL,YAHT,MAAApI,GAAAqI,IAAA/H,IAAA,MAAAS,MAAA,SAMO1C,GACHrB,KAAKsL,SAASjK,EAAOuH,IAAM5I,KAAKoL,SAASpJ,OACzChC,KAAKoL,SAAStH,KAAKzC,MARvBiC,IAAA,MAAAS,MAAA,SAWO1C,GACH,WAAoC0D,KAA7B/E,KAAKsL,SAASjK,EAAOuH,OAZhCtF,IAAA,SAAAS,MAAA,SAeU1C,GACN,GAAM2C,GAAQhE,KAAKsL,SAASjK,EAAOuH,GACnC,QAAc7D,KAAVf,EAAqB,OAChBhE,MAAKsL,SAASjK,EAAOuH,GAC5B,IAAM2C,GAAcvL,KAAKoL,SAASI,KAC9BD,GAAY3C,KAAOvH,EAAOuH,KAC5B5I,KAAKoL,SAASpH,GAASuH,EACvBvL,KAAKsL,SAASC,EAAY3C,IAAM5E,QAtBxCqH","file":"ouyo.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"OUYO\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"OUYO\"] = factory();\n\telse\n\t\troot[\"OUYO\"] = factory();\n})(typeof self !== 'undefined' ? self : this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"OUYO\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"OUYO\"] = factory();\n\telse\n\t\troot[\"OUYO\"] = factory();\n})(typeof self !== 'undefined' ? self : this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 2);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (immutable) */ __webpack_exports__[\"d\"] = map;\n/* harmony export (immutable) */ __webpack_exports__[\"b\"] = forEach;\n/* harmony export (immutable) */ __webpack_exports__[\"c\"] = forEach2;\n/* harmony export (immutable) */ __webpack_exports__[\"a\"] = assert;\n/* unused harmony export xor */\nfunction map(array, fn) {\n var result = [];\n for (var i = 0; i < array.length; i++) {\n result[i] = fn(array[i]);\n }\n return result;\n}\n\nfunction forEach(array, fn) {\n for (var i = 0; i < array.length; i++) {\n fn(array[i]);\n }\n}\n\nfunction forEach2(a, b, fn) {\n for (var i = 0; i < a.length; i++) {\n var aItem = a[i];\n for (var j = 0; j < b.length; j++) {\n fn(aItem, b[j]);\n }\n }\n}\n\nfunction assert(condition, errorMessage) {\n if (!condition) {\n throw new Error(errorMessage);\n }\n}\n\nfunction xor(a, b) {\n return (a || b) && !(a && b);\n}\n\n/***/ }),\n/* 1 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Key; });\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar KEY_BITS = 31;\n\nvar POWERS = [];\nfor (var i = 0; i < KEY_BITS; i++) {\n POWERS[i] = Math.pow(2, i);\n}\n\nvar Key = function () {\n function Key(length) {\n _classCallCheck(this, Key);\n\n this.values = [];\n for (var _i = 0; _i < length / KEY_BITS; _i++) {\n this.values.push(0);\n }\n }\n\n _createClass(Key, [{\n key: \"set\",\n value: function set(index) {\n this.setBit(index, true);\n return this;\n }\n }, {\n key: \"unset\",\n value: function unset(index) {\n this.setBit(index, false);\n return this;\n }\n }, {\n key: \"setBit\",\n value: function setBit(index, value) {\n var valueIndex = 0;\n while (index >= KEY_BITS) {\n valueIndex++;\n index -= KEY_BITS;\n }\n\n var previousValue = (this.values[valueIndex] & POWERS[index]) !== 0;\n if (value && !previousValue) {\n this.values[valueIndex] += POWERS[index];\n } else if (!value && previousValue) {\n this.values[valueIndex] -= POWERS[index];\n }\n }\n }, {\n key: \"matches\",\n value: function matches(other) {\n for (var _i2 = 0; _i2 < other.values.length; _i2++) {\n var currentValue = this.values[_i2] || 0;\n var otherValue = other.values[_i2];\n if ((currentValue & otherValue) !== otherValue) {\n return false;\n }\n }\n return true;\n }\n }]);\n\n return Key;\n}();\n\n/***/ }),\n/* 2 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\nObject.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Game__ = __webpack_require__(3);\n/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, \"Game\", function() { return __WEBPACK_IMPORTED_MODULE_0__Game__[\"a\"]; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Query__ = __webpack_require__(7);\n/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, \"Query\", function() { return __WEBPACK_IMPORTED_MODULE_1__Query__[\"a\"]; });\n\n\n\n/***/ }),\n/* 3 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Game; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Entity__ = __webpack_require__(4);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(0);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__component__ = __webpack_require__(5);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__ticker__ = __webpack_require__(6);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\n\n\nvar doNothing = function doNothing() {};\n\nvar Game = function () {\n function Game() {\n var _this = this;\n\n var registerUpdate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : __WEBPACK_IMPORTED_MODULE_3__ticker__[\"a\" /* defaultTicker */];\n\n _classCallCheck(this, Game);\n\n this.changed = [];\n this.removed = [];\n\n this.systems = [];\n this.queries = [];\n\n this.events = [];\n this.eventTimes = {};\n\n this.componentCount = 0;\n\n this.started = false;\n this.runtime = 0;\n this.registerUpdate = registerUpdate;\n this.onEntityChange = function (entity) {\n return _this.changed.push(entity);\n };\n }\n\n _createClass(Game, [{\n key: 'createComponent',\n value: function createComponent() {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'Cannot create component after the game was started.');\n\n for (var _len = arguments.length, fields = Array(_len), _key = 0; _key < _len; _key++) {\n fields[_key] = arguments[_key];\n }\n\n return Object(__WEBPACK_IMPORTED_MODULE_2__component__[\"a\" /* createComponent */])(fields, this.componentCount++);\n }\n }, {\n key: 'registerSystems',\n value: function registerSystems(systems) {\n var _this2 = this;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(systems, function (system) {\n return _this2._registerSystem(system);\n });\n }\n }, {\n key: '_registerSystem',\n value: function _registerSystem(system) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'Cannot register systems after the game was started.');\n\n var unifiedSystem = {\n query: system.query || [],\n on: system.on,\n process: system.process || createProcess(system.processEntity)\n };\n\n this.systems.push(unifiedSystem);\n this._registerQuery(system.query);\n }\n }, {\n key: '_registerQuery',\n value: function _registerQuery(query) {\n var _this3 = this;\n\n if (Array.isArray(query)) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(query, function (subQuery) {\n return _this3.queries.push(subQuery);\n });\n } else if (query) {\n this.queries.push(query);\n }\n }\n }, {\n key: 'start',\n value: function start(init) {\n var _this4 = this;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this.started, 'A game can only be started once!');\n this.started = true;\n\n init(this);\n\n this.registerUpdate(function (timeDelta) {\n return _this4._update(timeDelta);\n });\n }\n }, {\n key: '_update',\n value: function _update(timeDelta) {\n var _this5 = this;\n\n this.runtime += timeDelta;\n this.events.length = 0;\n this.emit('tick');\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(this.systems, function (system) {\n return _this5._runSystem(system);\n });\n }\n }, {\n key: '_runSystem',\n value: function _runSystem(system, timeDelta) {\n var _this6 = this;\n\n var events = this._getEventsFor(system);\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"b\" /* forEach */])(events, function (event) {\n _this6._handleChanges();\n var entities = getEntities(system.query);\n system.process(entities, event, _this6);\n });\n }\n }, {\n key: '_getEventsFor',\n value: function _getEventsFor(system) {\n if (!system.on) {\n return [this.events[0]];\n } else {\n return this.events.filter(function (event) {\n return event.type === system.on;\n });\n }\n }\n }, {\n key: '_handleChanges',\n value: function _handleChanges() {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"c\" /* forEach2 */])(this.changed, this.queries, handleEntityChange);\n this.changed.length = 0;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"c\" /* forEach2 */])(this.removed, this.queries, handleEntityRemove);\n this.removed.length = 0;\n }\n }, {\n key: 'createEntity',\n value: function createEntity() {\n var assemblage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : doNothing;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(this.started, 'Entities cannot be created before the game is started.');\n var entity = new __WEBPACK_IMPORTED_MODULE_0__Entity__[\"a\" /* Entity */](this.componentCount, this.onEntityChange);\n assemblage(entity);\n return entity;\n }\n }, {\n key: 'removeEntity',\n value: function removeEntity(entity) {\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(this.started, 'Entities cannot be removed before the game is started.');\n this.removed.push(entity);\n }\n }, {\n key: 'emit',\n value: function emit(event) {\n if (typeof event === 'string') {\n event = { type: event };\n }\n var now = this.runtime;\n var lastTime = fallback(this.eventTimes[event.type], now);\n event.timeDelta = (now - lastTime) / 1000;\n this.eventTimes[event.type] = now;\n this.events.push(event);\n }\n }]);\n\n return Game;\n}();\n\nfunction createProcess(processEntity) {\n return function (entities, event, game) {\n for (var i = 0; i < entities.length; ++i) {\n processEntity(entities[i], event, game);\n }\n };\n}\n\nfunction fallback(value, fallback) {\n return value !== undefined ? value : fallback;\n}\n\nfunction getEntities(query) {\n if (Array.isArray(query)) {\n return Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"d\" /* map */])(query, function (subQuery) {\n return subQuery.entities;\n });\n } else {\n return query.entities;\n }\n}\n\nfunction handleEntityChange(entity, query) {\n query.onChange(entity);\n}\n\nfunction handleEntityRemove(entity, query) {\n query.onRemove(entity);\n}\n\n/***/ }),\n/* 4 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Entity; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Key__ = __webpack_require__(1);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(0);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\nvar index = 0;\n\nvar Entity = function () {\n function Entity(componentCount, onKeyChanged) {\n _classCallCheck(this, Entity);\n\n this.id = index++;\n\n this.key = new __WEBPACK_IMPORTED_MODULE_0__Key__[\"a\" /* Key */](componentCount);\n this._components = makeNullArray(componentCount);\n\n this._changeAnnounced = false;\n this._onKeyChanged = onKeyChanged;\n }\n\n _createClass(Entity, [{\n key: 'add',\n value: function add(componentInstance) {\n var index = componentInstance._id;\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(!this._components[index], 'Cannot add another instance of the same component.');\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(index < this._components.length, 'Unknown component passed as argument.');\n\n this.key.setBit(index, true);\n this._components[index] = componentInstance;\n\n this._onChange();\n return this;\n }\n }, {\n key: 'has',\n value: function has(Component) {\n return !!this._components[Component.id];\n }\n }, {\n key: 'get',\n value: function get(Component) {\n var component = this._components[Component.id];\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(component, 'Requested component is not present.');\n return component;\n }\n }, {\n key: 'remove',\n value: function remove(Component) {\n var index = Component.id;\n var component = this._components[index];\n\n Object(__WEBPACK_IMPORTED_MODULE_1__utils__[\"a\" /* assert */])(component, 'Cannot remove component instance, because it doesn\\'t exist on target entity.');\n\n this.key.unset(index);\n this._components[index] = null;\n this._onChange();\n return this;\n }\n }, {\n key: '_onChange',\n value: function _onChange() {\n if (!this._changeAnnounced) {\n this._onKeyChanged(this);\n }\n this._changeAnnounced = true;\n }\n }, {\n key: 'onChangeRegistered',\n value: function onChangeRegistered() {\n this._changeAnnounced = false;\n }\n }]);\n\n return Entity;\n}();\n\nfunction makeNullArray(size) {\n var array = [];\n for (var i = 0; i < size; i++) {\n array[i] = null;\n }\n return array;\n}\n\n/***/ }),\n/* 5 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (immutable) */ __webpack_exports__[\"a\"] = createComponent;\n/* unused harmony export decorate */\nfunction createComponent(fields, id) {\n var body = '';\n for (var i = 0; i < fields.length; i++) {\n var field = fields[i];\n if (/^[a-zA-Z]\\w*$/.exec(field)) {\n body += 'this.' + field + '=' + field + ';';\n } else {\n throw new Error('Invalid identifier: ' + field);\n }\n }\n /* eslint-disable no-new-func */\n return decorate(new Function(fields, body), id);\n}\n\nfunction decorate(constructor, id) {\n constructor.id = id;\n constructor.prototype._id = id;\n return constructor;\n}\n\n/***/ }),\n/* 6 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return defaultTicker; });\nvar defaultTicker = function defaultTicker(update) {\n window.requestAnimationFrame(onAnimationFrame);\n var lastTime = Date.now();\n function onAnimationFrame() {\n window.requestAnimationFrame(onAnimationFrame);\n var now = Date.now();\n update(Math.min(now - lastTime, 100));\n lastTime = now;\n }\n};\n\n/***/ }),\n/* 7 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return Query; });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Key__ = __webpack_require__(1);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__IndexedArray__ = __webpack_require__(8);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__utils__ = __webpack_require__(0);\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n\n\nvar Query = function () {\n function Query() {\n var _this = this;\n\n _classCallCheck(this, Query);\n\n this._entities = new __WEBPACK_IMPORTED_MODULE_1__IndexedArray__[\"a\" /* IndexedArray */]();\n this._one = false;\n\n for (var _len = arguments.length, components = Array(_len), _key = 0; _key < _len; _key++) {\n components[_key] = arguments[_key];\n }\n\n this.key = new __WEBPACK_IMPORTED_MODULE_0__Key__[\"a\" /* Key */](maxId(components) + 1);\n Object(__WEBPACK_IMPORTED_MODULE_2__utils__[\"b\" /* forEach */])(components, function (_ref) {\n var id = _ref.id;\n return _this.key.set(id);\n });\n }\n\n _createClass(Query, [{\n key: 'one',\n value: function one() {\n this._one = true;\n return this;\n }\n }, {\n key: 'onChange',\n value: function onChange(entity) {\n var isInQuery = this._entities.has(entity);\n var matched = entity.key.matches(this.key);\n\n if (!isInQuery && matched) {\n this._entities.put(entity);\n } else if (isInQuery && !matched) {\n this._entities.remove(entity);\n }\n }\n }, {\n key: 'onRemove',\n value: function onRemove(entity) {\n this._entities.remove(entity);\n }\n }, {\n key: 'entities',\n get: function get() {\n return this._one ? this._entities.elements[0] : this._entities.elements;\n }\n }]);\n\n return Query;\n}();\n\nfunction maxId(components) {\n var maxId = 0;\n Object(__WEBPACK_IMPORTED_MODULE_2__utils__[\"b\" /* forEach */])(components, function (_ref2) {\n var id = _ref2.id;\n return id > maxId && (maxId = id);\n });\n return maxId;\n}\n\n/***/ }),\n/* 8 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return IndexedArray; });\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar IndexedArray = function () {\n function IndexedArray() {\n _classCallCheck(this, IndexedArray);\n\n this._indices = {};\n this.elements = [];\n }\n\n _createClass(IndexedArray, [{\n key: \"put\",\n value: function put(object) {\n this._indices[object.id] = this.elements.length;\n this.elements.push(object);\n }\n }, {\n key: \"has\",\n value: function has(object) {\n return this._indices[object.id] !== undefined;\n }\n }, {\n key: \"remove\",\n value: function remove(object) {\n var index = this._indices[object.id];\n if (index !== undefined) {\n delete this._indices[object.id];\n var otherObject = this.elements.pop();\n if (otherObject.id !== object.id) {\n this.elements[index] = otherObject;\n this._indices[otherObject.id] = index;\n }\n }\n }\n }]);\n\n return IndexedArray;\n}();\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// ouyo.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap c36d6c916fdb32d97b33","export function map (array, fn) {\n let result = []\n for (let i = 0; i < array.length; i++) {\n result[i] = fn(array[i])\n }\n return result\n}\n\nexport function forEach (array, fn) {\n for (let i = 0; i < array.length; i++) {\n fn(array[i])\n }\n}\n\nexport function forEach2 (a, b, fn) {\n for (let i = 0; i < a.length; i++) {\n let aItem = a[i]\n for (let j = 0; j < b.length; j++) {\n fn(aItem, b[j])\n }\n }\n}\n\nexport function assert (condition, errorMessage) {\n if (!condition) {\n throw new Error(errorMessage)\n }\n}\n\nexport function xor (a, b) {\n return (a || b) && !(a && b)\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.js","const KEY_BITS = 31\r\n\r\nconst POWERS = []\r\nfor (let i = 0; i < KEY_BITS; i++) {\r\n POWERS[i] = 2 ** i\r\n}\r\n\r\nexport class Key {\r\n constructor (length) {\r\n this.values = []\r\n for (let i = 0; i < length / KEY_BITS; i++) {\r\n this.values.push(0)\r\n }\r\n }\r\n\r\n set (index) {\r\n this.setBit(index, true)\r\n return this\r\n }\r\n\r\n unset (index) {\r\n this.setBit(index, false)\r\n return this\r\n }\r\n\r\n setBit (index, value) {\r\n let valueIndex = 0\r\n while (index >= KEY_BITS) {\r\n valueIndex++\r\n index -= KEY_BITS\r\n }\r\n\r\n const previousValue = (this.values[valueIndex] & POWERS[index]) !== 0\r\n if (value && !previousValue) {\r\n this.values[valueIndex] += POWERS[index]\r\n } else if (!value && previousValue) {\r\n this.values[valueIndex] -= POWERS[index]\r\n }\r\n }\r\n\r\n matches (other) {\r\n for (let i = 0; i < other.values.length; i++) {\r\n const currentValue = this.values[i] || 0\r\n const otherValue = other.values[i]\r\n if ((currentValue & otherValue) !== otherValue) {\r\n return false\r\n }\r\n }\r\n return true\r\n }\r\n}\r\n\n\n\n// WEBPACK FOOTER //\n// ./src/Key.js","import { Entity } from './Entity'\nimport { assert, map, forEach, forEach2 } from './utils'\nimport { createComponent } from './component'\nimport { defaultTicker } from './ticker'\n\nconst doNothing = () => {}\n\nexport class Game {\n constructor (registerUpdate = defaultTicker) {\n this.changed = []\n this.removed = []\n\n this.systems = []\n this.queries = []\n\n this.events = []\n this.eventTimes = {}\n\n this.componentCount = 0\n\n this.started = false\n this.runtime = 0\n this.registerUpdate = registerUpdate\n this.onEntityChange = entity => this.changed.push(entity)\n }\n\n createComponent (...fields) {\n assert(!this.started, 'Cannot create component after the game was started.')\n return createComponent(fields, this.componentCount++)\n }\n\n registerSystems (systems) {\n forEach(systems, system => this._registerSystem(system))\n }\n\n _registerSystem (system) {\n assert(!this.started, 'Cannot register systems after the game was started.')\n\n const unifiedSystem = {\n query: system.query || [],\n on: system.on,\n process: system.process || createProcess(system.processEntity)\n }\n\n this.systems.push(unifiedSystem)\n this._registerQuery(system.query)\n }\n\n _registerQuery (query) {\n if (Array.isArray(query)) {\n forEach(query, subQuery => this.queries.push(subQuery))\n } else if (query) {\n this.queries.push(query)\n }\n }\n\n start (init) {\n assert(!this.started, 'A game can only be started once!')\n this.started = true\n\n init(this)\n\n this.registerUpdate(timeDelta => this._update(timeDelta))\n }\n\n _update (timeDelta) {\n this.runtime += timeDelta\n this.events.length = 0\n this.emit('tick')\n forEach(this.systems, system => this._runSystem(system))\n }\n\n _runSystem (system, timeDelta) {\n const events = this._getEventsFor(system)\n forEach(events, event => {\n this._handleChanges()\n const entities = getEntities(system.query)\n system.process(entities, event, this)\n })\n }\n\n _getEventsFor (system) {\n if (!system.on) {\n return [this.events[0]]\n } else {\n return this.events.filter(event => event.type === system.on)\n }\n }\n\n _handleChanges () {\n forEach2(this.changed, this.queries, handleEntityChange)\n this.changed.length = 0\n\n forEach2(this.removed, this.queries, handleEntityRemove)\n this.removed.length = 0\n }\n\n createEntity (assemblage = doNothing) {\n assert(this.started, 'Entities cannot be created before the game is started.')\n const entity = new Entity(this.componentCount, this.onEntityChange)\n assemblage(entity)\n return entity\n }\n\n removeEntity (entity) {\n assert(this.started, 'Entities cannot be removed before the game is started.')\n this.removed.push(entity)\n }\n\n emit (event) {\n if (typeof event === 'string') {\n event = { type: event }\n }\n const now = this.runtime\n const lastTime = fallback(this.eventTimes[event.type], now)\n event.timeDelta = (now - lastTime) / 1000\n this.eventTimes[event.type] = now\n this.events.push(event)\n }\n}\n\nfunction createProcess (processEntity) {\n return function (entities, event, game) {\n for (let i = 0; i < entities.length; ++i) {\n processEntity(entities[i], event, game)\n }\n }\n}\n\nfunction fallback (value, fallback) {\n return value !== undefined ? value : fallback\n}\n\nfunction getEntities (query) {\n if (Array.isArray(query)) {\n return map(query, subQuery => subQuery.entities)\n } else {\n return query.entities\n }\n}\n\nfunction handleEntityChange (entity, query) {\n query.onChange(entity)\n}\n\nfunction handleEntityRemove (entity, query) {\n query.onRemove(entity)\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Game.js","import { Key } from './Key'\nimport { assert } from './utils'\n\nlet index = 0\n\nexport class Entity {\n constructor (componentCount, onKeyChanged) {\n this.id = index++\n\n this.key = new Key(componentCount)\n this._components = makeNullArray(componentCount)\n\n this._changeAnnounced = false\n this._onKeyChanged = onKeyChanged\n }\n\n add (componentInstance) {\n const index = componentInstance._id\n\n assert(!this._components[index], 'Cannot add another instance of the same component.')\n assert(index < this._components.length, 'Unknown component passed as argument.')\n\n this.key.setBit(index, true)\n this._components[index] = componentInstance\n\n this._onChange()\n return this\n }\n\n has (Component) {\n return !!this._components[Component.id]\n }\n\n get (Component) {\n const component = this._components[Component.id]\n assert(component, 'Requested component is not present.')\n return component\n }\n\n remove (Component) {\n const index = Component.id\n const component = this._components[index]\n\n assert(component, 'Cannot remove component instance, because it doesn\\'t exist on target entity.')\n\n this.key.unset(index)\n this._components[index] = null\n this._onChange()\n return this\n }\n\n _onChange () {\n if (!this._changeAnnounced) {\n this._onKeyChanged(this)\n }\n this._changeAnnounced = true\n }\n\n onChangeRegistered () {\n this._changeAnnounced = false\n }\n}\n\nfunction makeNullArray (size) {\n const array = []\n for (let i = 0; i < size; i++) {\n array[i] = null\n }\n return array\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Entity.js","export function createComponent (fields, id) {\n let body = ''\n for (let i = 0; i < fields.length; i++) {\n let field = fields[i]\n if (/^[a-zA-Z]\\w*$/.exec(field)) {\n body += `this.${field}=${field};`\n } else {\n throw new Error('Invalid identifier: ' + field)\n }\n }\n /* eslint-disable no-new-func */\n return decorate(new Function(fields, body), id)\n}\n\nexport function decorate (constructor, id) {\n constructor.id = id\n constructor.prototype._id = id\n return constructor\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/component.js","export const defaultTicker = function (update) {\n window.requestAnimationFrame(onAnimationFrame)\n let lastTime = Date.now()\n function onAnimationFrame () {\n window.requestAnimationFrame(onAnimationFrame)\n let now = Date.now()\n update(Math.min(now - lastTime, 100))\n lastTime = now\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ticker.js","import { Key } from './Key'\nimport { IndexedArray } from './IndexedArray'\nimport { forEach } from './utils'\n\nexport class Query {\n constructor (...components) {\n this._entities = new IndexedArray()\n this._one = false\n\n this.key = new Key(maxId(components) + 1)\n forEach(components, ({ id }) => this.key.set(id))\n }\n\n one () {\n this._one = true\n return this\n }\n\n get entities () {\n return this._one\n ? this._entities.elements[0]\n : this._entities.elements\n }\n\n onChange (entity) {\n const isInQuery = this._entities.has(entity)\n const matched = entity.key.matches(this.key)\n\n if (!isInQuery && matched) {\n this._entities.put(entity)\n } else if (isInQuery && !matched) {\n this._entities.remove(entity)\n }\n }\n\n onRemove (entity) {\n this._entities.remove(entity)\n }\n}\n\nfunction maxId (components) {\n let maxId = 0\n forEach(components, ({ id }) => id > maxId && (maxId = id))\n return maxId\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/Query.js","export class IndexedArray {\n constructor () {\n this._indices = {}\n this.elements = []\n }\n\n put (object) {\n this._indices[object.id] = this.elements.length\n this.elements.push(object)\n }\n\n has (object) {\n return this._indices[object.id] !== undefined\n }\n\n remove (object) {\n const index = this._indices[object.id]\n if (index !== undefined) {\n delete this._indices[object.id]\n const otherObject = this.elements.pop()\n if (otherObject.id !== object.id) {\n this.elements[index] = otherObject\n this._indices[otherObject.id] = index\n }\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/IndexedArray.js"],"sourceRoot":""} \ No newline at end of file