Socket
Socket
Sign inDemoInstall

hecs

Package Overview
Dependencies
1
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.14.0 to 0.15.0

tests/added-removed.test.js

2

dist/hecs.js

@@ -1,1 +0,1 @@

!function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.hecs=t():e.HECS=t()}(this,(function(){return function(e){var t={};function __webpack_require__(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,n){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(e,t){if(1&t&&(e=__webpack_require__(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)__webpack_require__.d(n,r,function(t){return e[t]}.bind(null,r));return n},__webpack_require__.n=function(e){var t=e&&e.__esModule?function getDefault(){return e.default}:function getModuleExports(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=2)}([function(e,t,n){"use strict";(function(e){n.d(t,"a",(function(){return r})),n.d(t,"c",(function(){return i})),n.d(t,"e",(function(){return o})),n.d(t,"d",(function(){return s})),n.d(t,"b",(function(){return c}));var r={name:"Boolean",initial:function initial(e){return e||!1},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||!1}},i={name:"Number",initial:function initial(e){return e||0},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||0}},o={name:"String",initial:function initial(e){return e||""},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||""}},s={name:"Ref",initial:function initial(e){return e||null},toJSON:function toJSON(e){return null},fromJSON:function fromJSON(e,t){return e||null}},a="undefined"==typeof window?e.JSON:window.JSON,c={name:"JSON",initial:function initial(e){return e?a.parse(a.stringify(e)):null},toJSON:function toJSON(e){return e&&a.stringify(e)},fromJSON:function fromJSON(e,t){return e&&a.parse(e)}}}).call(this,n(1))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.r(t),n.d(t,"World",(function(){return p})),n.d(t,"System",(function(){return d})),n.d(t,"Component",(function(){return c})),n.d(t,"LocalComponent",(function(){return m})),n.d(t,"StateComponent",(function(){return u})),n.d(t,"BooleanType",(function(){return v.a})),n.d(t,"NumberType",(function(){return v.c})),n.d(t,"StringType",(function(){return v.e})),n.d(t,"RefType",(function(){return v.d})),n.d(t,"JSONType",(function(){return v.b})),n.d(t,"Groups",(function(){return y})),n.d(t,"Not",(function(){return Not})),n.d(t,"Modified",(function(){return Modified})),n.d(t,"createPlugin",(function(){return createPlugin}));var r=function(){function SystemManager(e){!function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,SystemManager),this.world=e,this.Systems=new Map,this.systems=[],this.systemsByName={},this.tick=0}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(SystemManager,[{key:"register",value:function register(e){if(!this.Systems.has(e)){var t=new e(this.world);this.Systems.set(e,t);for(var n=0,r=0;r<this.systems.length;r++){if(this.systems[r].order>t.order)break;n=r+1}return this.systems.splice(n,0,t),this.systemsByName[e.name]=t,this}console.warn("hecs: already registered system '".concat(e.name,"'"))}},{key:"init",value:function init(){for(var e=0;e<this.systems.length;e++){this.systems[e].init(this.world)}}},{key:"get",value:function get(e){return this.Systems.get(e)}},{key:"getByName",value:function getByName(e){return this.systemsByName[e]}},{key:"update",value:function update(e){for(var t=0;t<this.systems.length;t++){this.tick++;var n=this.systems[t];n.active&&n.update(e)}}},{key:"reset",value:function reset(){this.systems.forEach((function(e){e.reset()}))}}]),SystemManager}();function Query_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var i=function(){function Query(e,t){!function Query_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Query),this.world=e,this.Components=t,this.Modified=[],this.archetypes=[];for(var n=0;n<t.length;n++){var r=t[n];r.isModified&&this.Modified.push(r.Component)}for(var i in this.world.archetypes.archetypes){var o=this.world.archetypes.archetypes[i];this.matchesArchetype(o)&&this.archetypes.push(o)}}return function Query_createClass(e,t,n){return t&&Query_defineProperties(e.prototype,t),n&&Query_defineProperties(e,n),e}(Query,[{key:"isModified",value:function isModified(e){for(var t=0;t<this.Modified.length;t++){var n=this.Modified[t];if(e.get(n).modifiedUntilSystemTick>=this.world.systems.tick)return!0}return!1}},{key:"forEach",value:function forEach(e){this.Modified.length?this._forEachModified(e):this._forEach(e)}},{key:"_forEachModified",value:function _forEachModified(e){for(var t=this.archetypes.length-1;t>=0;--t)for(var n=this.archetypes[t].entities,r=n.length-1;r>=0;--r){var i=n[r];this.isModified(i)&&e(i)}}},{key:"_forEach",value:function _forEach(e){for(var t=this.archetypes.length-1;t>=0;--t)for(var n=this.archetypes[t].entities,r=n.length-1;r>=0;--r){e(n[r])}}},{key:"count",value:function count(){var count=0;return this.forEach((function(){return function _readOnlyError(e){throw new Error('"'+e+'" is read-only')}("count"),count++})),count}},{key:"onArchetypeCreated",value:function onArchetypeCreated(e){this.matchesArchetype(e)&&this.archetypes.push(e)}},{key:"matchesArchetype",value:function matchesArchetype(e){for(var t=!0,n=0;n<this.Components.length;n++){var r=this.Components[n],i=r.isNot,o=r.isModified;if((i||o)&&(r=r.Component),i){if(-1!==e.Components.indexOf(r)){t=!1;break}}else if(-1===e.Components.indexOf(r)){t=!1;break}}t&&this.archetypes.push(e)}}]),Query}();function QueryManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=function(){function QueryManager(e){!function QueryManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,QueryManager),this.world=e,this.queries=[]}return function QueryManager_createClass(e,t,n){return t&&QueryManager_defineProperties(e.prototype,t),n&&QueryManager_defineProperties(e,n),e}(QueryManager,[{key:"create",value:function create(e){var t=new i(this.world,e);return this.queries.push(t),t}},{key:"onArchetypeCreated",value:function onArchetypeCreated(e){for(var t=0;t<this.queries.length;t++){this.queries[t].onArchetypeCreated(e)}}}]),QueryManager}();var s=function Archetype(e,t,n){!function Archetype_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Archetype),this.world=e,this.id=t,this.Components=n,this.entities=[]};function ArchetypeManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var a=function(){function ArchetypeManager(e,t){!function ArchetypeManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,ArchetypeManager),this.world=e,this.archetypes={},this.initialId=null}return function ArchetypeManager_createClass(e,t,n){return t&&ArchetypeManager_defineProperties(e.prototype,t),n&&ArchetypeManager_defineProperties(e,n),e}(ArchetypeManager,[{key:"init",value:function init(){this.initialId="";for(var e=this.world.components.count;e;)this.initialId+="0",e--;console.log("hecs: using ".concat(this.world.components.count," bit archetype ids")),this.createArchetype(this.initialId,[])}},{key:"onEntityActive",value:function onEntityActive(e){this.addToArchetype(e)}},{key:"onEntityComponentChange",value:function onEntityComponentChange(e,t,n){e.active&&this.removeFromArchetype(e),e.archetypeId=e.archetypeId.substring(0,t.id)+(n?"1":"0")+e.archetypeId.substring(t.id+1),this.archetypes[e.archetypeId]||this.createArchetype(e.archetypeId,e.Components),e.active&&this.addToArchetype(e)}},{key:"onEntityInactive",value:function onEntityInactive(e){this.removeFromArchetype(e)}},{key:"addToArchetype",value:function addToArchetype(e){var t=this.archetypes[e.archetypeId];-1===t.entities.indexOf(e)&&t.entities.push(e)}},{key:"removeFromArchetype",value:function removeFromArchetype(e){var t=this.archetypes[e.archetypeId].entities,n=t.indexOf(e);-1!==n&&t.splice(n,1)}},{key:"createArchetype",value:function createArchetype(e,t){t=t.slice();var n=new s(this.world,e,t);return this.archetypes[n.id]=n,this.world.queries.onArchetypeCreated(n),n}}]),ArchetypeManager}();function Component_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Component_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var c=function(){function Component(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in Component_classCallCheck(this,Component),this.world=e,this.name=this.constructor.name,this.props=[],this.modifiedUntilSystemTick=0,this.constructor.props){var r=this.constructor.props[n],i=t[n];r.type||(r={type:r},this.constructor.props[n]=r),this[n]=r.type.initial(void 0===i?r.default:i),this.props.push(r)}}return function Component_createClass(e,t,n){return t&&Component_defineProperties(e.prototype,t),n&&Component_defineProperties(e,n),e}(Component,[{key:"toJSON",value:function toJSON(){var e={};for(var t in this.constructor.props){var n=this.constructor.props[t],r=n.type||n;e[t]=r.toJSON(this[t])}return e}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.constructor.props){var n=this.constructor.props[t],r=n.type||n;void 0!==e[t]&&(this[t]=r.fromJSON(e[t],this[t]))}return this}},{key:"modified",value:function modified(){this.modifiedUntilSystemTick=this.world.systems.tick+this.world.systems.systems.length}}]),Component}();function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function StateComponent_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var n,r=_getPrototypeOf(e);if(t){var i=_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _possibleConstructorReturn(this,n)}}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}c.props={},c.isComponent=!0;var u=function(e){!function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}(StateComponent,e);var t=_createSuper(StateComponent);function StateComponent(){return StateComponent_classCallCheck(this,StateComponent),t.apply(this,arguments)}return StateComponent}(c);function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Entity_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}u.isStateComponent=!0;var f=function(){function Entity(e,t,n,r){!function Entity_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Entity),this.world=e,this.id=n,this.name=t||null,this.meta=r||{},this.Components=[],this.components=new Map,this.parent=null,this.children=[],this.needsBind=!1,this.inactiveComponents=[],this.archetypeId=e.archetypes.initialId,this.active=!1}return function Entity_createClass(e,t,n){return t&&Entity_defineProperties(e.prototype,t),n&&Entity_defineProperties(e,n),e}(Entity,[{key:"add",value:function add(e,t,n){var r;e.isComponent?r=new e(this.world,t):(r=e,e=e.constructor);var i=this.components.has(e);return this.components.set(e,r),i?r.modified():(this.Components.push(e),this.world.archetypes.onEntityComponentChange(this,e,!0)),n?r:this}},{key:"get",value:function get(e){return this.components.get(e)}},{key:"has",value:function has(e){return!!this.components.get(e)}},{key:"remove",value:function remove(e){if(this.components.has(e)){this.components.delete(e);var t=this.Components.indexOf(e);return this.Components.splice(t,1),this.world.archetypes.onEntityComponentChange(this,e,!1),this.Components.length||!this.deactivating&&!this.destroying||(this.active=!1,this.deactivating=!1,this.destroying=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this}console.warn("Entity: cannot remove component as it doesnt have one")}},{key:"bind",value:function bind(){var e=this;this.needsBind&&(this.parent=this.parent?this.world.entities.getById(this.parent):null,this.children=this.children.map((function(t){return e.world.entities.getById(t)})),this.needsBind=!1)}},{key:"setParent",value:function setParent(e){if(this.bind(),this.parent){this.parent.bind();var t=this.parent.children.indexOf(this);this.parent.children.splice(t,1),this.parent=null}e&&(this.parent=e,this.parent.children.push(this))}},{key:"getParent",value:function getParent(){return this.bind(),this.parent}},{key:"getChildren",value:function getChildren(){return this.bind(),this.children}},{key:"traverse",value:function traverse(e){this.bind(),e(this);for(var t=0;t<this.children.length;t++)this.children[t].traverse(e)}},{key:"traverseAncestors",value:function traverseAncestors(e){this.bind();for(var t=this.parent;t;)e(t),t.bind(),t=t.parent}},{key:"activate",value:function activate(){if(!this.active){for(;this.inactiveComponents.length;){var e=this.inactiveComponents.pop(),t=e.constructor;this.components.set(t,e),this.Components.push(t),this.world.archetypes.onEntityComponentChange(this,t,!0)}return this.active=!0,this.deactivating=!1,this.destroying=!1,this.world.entities.onEntityActive(this),this.world.archetypes.onEntityActive(this),this}console.warn("Entity: cannot activate as entity is already active")}},{key:"deactivate",value:function deactivate(){for(var e=this.Components.length-1;e>=0;--e){var t=this.Components[e];if(t.__proto__===u)this.deactivating=!0;else{var n=this.components.get(t);this.components.delete(t),this.Components.splice(e,1),this.inactiveComponents.push(n),this.world.archetypes.onEntityComponentChange(this,t,!1)}}return this.deactivating||(this.active=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this}},{key:"destroy",value:function destroy(){for(var e=this.Components.length-1;e>=0;--e){var t=this.Components[e];t.__proto__===u?this.destroying=!0:(this.components.delete(t),this.Components.splice(e,1),this.world.archetypes.onEntityComponentChange(this,t,!1))}this.destroying||(this.active=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this));for(var n=0;n<this.children.length;n++)this.children[n].destroy();return this}},{key:"toJSON",value:function toJSON(){var e,t={id:this.id,name:this.name,parent:(null===(e=this.getParent())||void 0===e?void 0:e.id)||null,children:this.getChildren().map((function(e){return e.id})),meta:_objectSpread({},this.meta)};return this.components.forEach((function(e){e.constructor.__proto__===c&&(t[e.name]=e.toJSON())})),t}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.id=e.id,this.name=e.name,this.parent=e.parent,this.children=e.children,this.meta=e.meta,e)if("id"!==t&&"name"!==t&&"parent"!==t&&"children"!==t&&"meta"!==t){var n=this.world.components.getByName(t);this.add(n,void 0,!0).fromJSON(e[t])}return this.needsBind=!0,this}}]),Entity}();function EntityManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function EntityManager(e){!function EntityManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,EntityManager),this.world=e,this.entities=new Map,this.nextEntityId=0}return function EntityManager_createClass(e,t,n){return t&&EntityManager_defineProperties(e.prototype,t),n&&EntityManager_defineProperties(e,n),e}(EntityManager,[{key:"create",value:function create(e,t){return t||(t="".concat(this.world.id,":").concat(this.nextEntityId++)),new f(this.world,e,t)}},{key:"getById",value:function getById(e){return this.entities.get(e)}},{key:"onEntityActive",value:function onEntityActive(e){this.entities.set(e.id,e)}},{key:"onEntityInactive",value:function onEntityInactive(e){this.entities.delete(e.id)}},{key:"reset",value:function reset(){this.entities.forEach((function(e){e.destroy()}))}}]),EntityManager}();function ComponentManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var h=function(){function ComponentManager(e){!function ComponentManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,ComponentManager),this.world=e,this.count=0,this.lastComponentId=0,this.componentsByName={}}return function ComponentManager_createClass(e,t,n){return t&&ComponentManager_defineProperties(e.prototype,t),n&&ComponentManager_defineProperties(e,n),e}(ComponentManager,[{key:"register",value:function register(e){if(this.componentsByName[e.name])throw new Error("hecs: component already registered '".concat(e.name,"'"));return e.id=this.lastComponentId++,this.componentsByName[e.name]=e,this.count++,this}},{key:"getByName",value:function getByName(e){return this.componentsByName[e]}}]),ComponentManager}();function createPlugin(e){var t=e.name,n=e.plugins,r=void 0===n?[]:n,i=e.systems,o=void 0===i?[]:i,s=e.components,a=void 0===s?[]:s,c=e.decorate,u=void 0===c?function(){}:c;if(!t)throw new Error("hecs: createPlugin requires name");return{name:t,plugins:r,systems:o,components:a,decorate:u}}function World_ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function World_objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?World_ownKeys(Object(n),!0).forEach((function(t){World_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):World_ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function World_defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function World_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function World_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var p=function(){function World(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};World_classCallCheck(this,World),this.id=0,this.version=0,this.plugins=new Map,this.providers={},this.systems=new r(this),this.queries=new o(this),this.archetypes=new a(this),this.entities=new l(this),this.components=new h(this),this.registerPlugin(createPlugin(World_objectSpread({name:"root"},e))),this.archetypes.init(),this.systems.init()}return function World_createClass(e,t,n){return t&&World_defineProperties(e.prototype,t),n&&World_defineProperties(e,n),e}(World,[{key:"registerPlugin",value:function registerPlugin(e){var t=this;this.plugins.has(e)?console.warn("hecs: already registered plugin '".concat(e.name,"'")):(this.plugins.set(e,!0),e.plugins.forEach((function(e){t.registerPlugin(e)})),e.systems.forEach((function(e){t.systems.register(e)})),e.components.forEach((function(e){t.components.register(e)})),e.decorate&&e.decorate(this),console.log("hecs: registered plugin '".concat(e.name,"'")))}},{key:"update",value:function update(e){this.version++,this.systems.update(e)}},{key:"reset",value:function reset(){this.entities.reset(),this.update(1/60*2),this.systems.reset()}},{key:"toJSON",value:function toJSON(){var e={nextEntityId:this.entities.nextEntityId,entities:[]};return this.entities.entities.forEach((function(t){return e.entities.push(t.toJSON())})),e}},{key:"fromJSON",value:function fromJSON(e){var t=this;this.entities.nextEntityId=e.nextEntityId,e.entities.forEach((function(e){t.entities.create(e.name,e.id).fromJSON(e).activate()}))}}]),World}(),y={Initialization:1e3,Simulation:2e3,Presentation:3e3};function System_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var d=function(){function System(e){for(var t in function System_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,System),this.order=y.Simulation,this.world=e,this.queries={},this.active=!0,this.constructor.queries){var n=this.constructor.queries[t];this.queries[t]=this.world.queries.create(n)}}return function System_createClass(e,t,n){return t&&System_defineProperties(e.prototype,t),n&&System_defineProperties(e,n),e}(System,[{key:"init",value:function init(e){}},{key:"update",value:function update(){}},{key:"reset",value:function reset(){}}]),System}();function LocalComponent_typeof(e){return(LocalComponent_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function LocalComponent_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function LocalComponent_setPrototypeOf(e,t){return(LocalComponent_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,t){return e.__proto__=t,e})(e,t)}function LocalComponent_createSuper(e){var t=function LocalComponent_isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var n,r=LocalComponent_getPrototypeOf(e);if(t){var i=LocalComponent_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return LocalComponent_possibleConstructorReturn(this,n)}}function LocalComponent_possibleConstructorReturn(e,t){return!t||"object"!==LocalComponent_typeof(t)&&"function"!=typeof t?function LocalComponent_assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function LocalComponent_getPrototypeOf(e){return(LocalComponent_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var m=function(e){!function LocalComponent_inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&LocalComponent_setPrototypeOf(e,t)}(LocalComponent,e);var t=LocalComponent_createSuper(LocalComponent);function LocalComponent(){return LocalComponent_classCallCheck(this,LocalComponent),t.apply(this,arguments)}return LocalComponent}(c);m.isLocalComponent=!0;var v=n(0);function Not(e){return{Component:e,isNot:!0}}function Modified(e){return{Component:e,isModified:!0}}}])}));
!function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.hecs=t():e.HECS=t()}(this,(function(){return function(e){var t={};function __webpack_require__(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,n){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(e,t){if(1&t&&(e=__webpack_require__(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)__webpack_require__.d(n,r,function(t){return e[t]}.bind(null,r));return n},__webpack_require__.n=function(e){var t=e&&e.__esModule?function getDefault(){return e.default}:function getModuleExports(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=3)}([function(e,t,n){"use strict";(function(e){n.d(t,"a",(function(){return r})),n.d(t,"c",(function(){return o})),n.d(t,"e",(function(){return i})),n.d(t,"d",(function(){return s})),n.d(t,"b",(function(){return c}));var r={name:"Boolean",initial:function initial(e){return e||!1},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||!1}},o={name:"Number",initial:function initial(e){return e||0},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||0}},i={name:"String",initial:function initial(e){return e||""},toJSON:function toJSON(e){return e},fromJSON:function fromJSON(e,t){return e||""}},s={name:"Ref",initial:function initial(e){return e||null},toJSON:function toJSON(e){return null},fromJSON:function fromJSON(e,t){return e||null}},a="undefined"==typeof window?e.JSON:window.JSON,c={name:"JSON",initial:function initial(e){return e?a.parse(a.stringify(e)):null},toJSON:function toJSON(e){return e&&a.stringify(e)},fromJSON:function fromJSON(e,t){return e&&a.parse(e)}}}).call(this,n(2))},function(e,t,n){"use strict";var r=Object.prototype.hasOwnProperty,o="~";function Events(){}function EE(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function addListener(e,t,n,r,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new EE(n,r||e,i),a=o?o+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],s]:e._events[a].push(s):(e._events[a]=s,e._eventsCount++),e}function clearEvent(e,t){0==--e._eventsCount?e._events=new Events:delete e._events[t]}function EventEmitter(){this._events=new Events,this._eventsCount=0}Object.create&&(Events.prototype=Object.create(null),(new Events).__proto__||(o=!1)),EventEmitter.prototype.eventNames=function eventNames(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)r.call(e,t)&&n.push(o?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},EventEmitter.prototype.listeners=function listeners(e){var t=o?o+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,i=n.length,s=new Array(i);r<i;r++)s[r]=n[r].fn;return s},EventEmitter.prototype.listenerCount=function listenerCount(e){var t=o?o+e:e,n=this._events[t];return n?n.fn?1:n.length:0},EventEmitter.prototype.emit=function emit(e,t,n,r,i,s){var a=o?o+e:e;if(!this._events[a])return!1;var c,u,f=this._events[a],l=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,n),!0;case 4:return f.fn.call(f.context,t,n,r),!0;case 5:return f.fn.call(f.context,t,n,r,i),!0;case 6:return f.fn.call(f.context,t,n,r,i,s),!0}for(u=1,c=new Array(l-1);u<l;u++)c[u-1]=arguments[u];f.fn.apply(f.context,c)}else{var p,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),l){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,n);break;case 4:f[u].fn.call(f[u].context,t,n,r);break;default:if(!c)for(p=1,c=new Array(l-1);p<l;p++)c[p-1]=arguments[p];f[u].fn.apply(f[u].context,c)}}return!0},EventEmitter.prototype.on=function on(e,t,n){return addListener(this,e,t,n,!1)},EventEmitter.prototype.once=function once(e,t,n){return addListener(this,e,t,n,!0)},EventEmitter.prototype.removeListener=function removeListener(e,t,n,r){var i=o?o+e:e;if(!this._events[i])return this;if(!t)return clearEvent(this,i),this;var s=this._events[i];if(s.fn)s.fn!==t||r&&!s.once||n&&s.context!==n||clearEvent(this,i);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==t||r&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=1===c.length?c[0]:c:clearEvent(this,i)}return this},EventEmitter.prototype.removeAllListeners=function removeAllListeners(e){var t;return e?(t=o?o+e:e,this._events[t]&&clearEvent(this,t)):(this._events=new Events,this._eventsCount=0),this},EventEmitter.prototype.off=EventEmitter.prototype.removeListener,EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prefixed=o,EventEmitter.EventEmitter=EventEmitter,e.exports=EventEmitter},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t),n.d(t,"World",(function(){return d})),n.d(t,"System",(function(){return v})),n.d(t,"Component",(function(){return f})),n.d(t,"LocalComponent",(function(){return _})),n.d(t,"StateComponent",(function(){return l})),n.d(t,"BooleanType",(function(){return g.a})),n.d(t,"NumberType",(function(){return g.c})),n.d(t,"StringType",(function(){return g.e})),n.d(t,"RefType",(function(){return g.d})),n.d(t,"JSONType",(function(){return g.b})),n.d(t,"Groups",(function(){return m})),n.d(t,"Not",(function(){return Not})),n.d(t,"Modified",(function(){return Modified})),n.d(t,"createPlugin",(function(){return createPlugin}));var r=n(1),o=n.n(r);function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var i=function(){function SystemManager(e){!function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,SystemManager),this.world=e,this.Systems=new Map,this.systems=[],this.systemsByName={},this.tick=0}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(SystemManager,[{key:"register",value:function register(e){if(!this.Systems.has(e)){var t=new e(this.world);this.Systems.set(e,t);for(var n=0,r=0;r<this.systems.length;r++){if(this.systems[r].order>t.order)break;n=r+1}return this.systems.splice(n,0,t),this.systemsByName[e.name]=t,this}console.warn("hecs: already registered system '".concat(e.name,"'"))}},{key:"init",value:function init(){for(var e=0;e<this.systems.length;e++){this.systems[e].init(this.world)}}},{key:"get",value:function get(e){return this.Systems.get(e)}},{key:"getByName",value:function getByName(e){return this.systemsByName[e]}},{key:"update",value:function update(e){for(var t=0;t<this.systems.length;t++){this.tick++;var n=this.systems[t];n.active&&n.update(e)}}},{key:"reset",value:function reset(){this.systems.forEach((function(e){e.reset()}))}}]),SystemManager}();function Query_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var s=function(){function Query(e,t){!function Query_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Query),this.world=e,this.Components=t,this.Modified=[],this.archetypes=[];for(var n=0;n<t.length;n++){var r=t[n];r.isModified&&this.Modified.push(r.Component)}for(var o in this.world.archetypes.archetypes){var i=this.world.archetypes.archetypes[o];this.matchesArchetype(i)&&this.archetypes.push(i)}}return function Query_createClass(e,t,n){return t&&Query_defineProperties(e.prototype,t),n&&Query_defineProperties(e,n),e}(Query,[{key:"isModified",value:function isModified(e){for(var t=0;t<this.Modified.length;t++){var n=this.Modified[t];if(e.get(n).modifiedUntilSystemTick>=this.world.systems.tick)return!0}return!1}},{key:"forEach",value:function forEach(e){this.Modified.length?this._forEachModified(e):this._forEach(e)}},{key:"_forEachModified",value:function _forEachModified(e){for(var t=this.archetypes.length-1;t>=0;--t)for(var n=this.archetypes[t].entities,r=n.length-1;r>=0;--r){var o=n[r];this.isModified(o)&&e(o)}}},{key:"_forEach",value:function _forEach(e){for(var t=this.archetypes.length-1;t>=0;--t)for(var n=this.archetypes[t].entities,r=n.length-1;r>=0;--r){e(n[r])}}},{key:"count",value:function count(){var count=0;return this.forEach((function(){return function _readOnlyError(e){throw new Error('"'+e+'" is read-only')}("count"),count++})),count}},{key:"onArchetypeCreated",value:function onArchetypeCreated(e){this.matchesArchetype(e)&&this.archetypes.push(e)}},{key:"matchesArchetype",value:function matchesArchetype(e){for(var t=!0,n=0;n<this.Components.length;n++){var r=this.Components[n],o=r.isNot,i=r.isModified;if((o||i)&&(r=r.Component),o){if(-1!==e.Components.indexOf(r)){t=!1;break}}else if(-1===e.Components.indexOf(r)){t=!1;break}}t&&this.archetypes.push(e)}}]),Query}();function QueryManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var a=function(){function QueryManager(e){!function QueryManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,QueryManager),this.world=e,this.queries=[]}return function QueryManager_createClass(e,t,n){return t&&QueryManager_defineProperties(e.prototype,t),n&&QueryManager_defineProperties(e,n),e}(QueryManager,[{key:"create",value:function create(e){var t=new s(this.world,e);return this.queries.push(t),t}},{key:"onArchetypeCreated",value:function onArchetypeCreated(e){for(var t=0;t<this.queries.length;t++){this.queries[t].onArchetypeCreated(e)}}}]),QueryManager}();var c=function Archetype(e,t,n){!function Archetype_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Archetype),this.world=e,this.id=t,this.Components=n,this.entities=[]};function ArchetypeManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var u=function(){function ArchetypeManager(e,t){!function ArchetypeManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,ArchetypeManager),this.world=e,this.archetypes={},this.initialId=null}return function ArchetypeManager_createClass(e,t,n){return t&&ArchetypeManager_defineProperties(e.prototype,t),n&&ArchetypeManager_defineProperties(e,n),e}(ArchetypeManager,[{key:"init",value:function init(){this.initialId="";for(var e=this.world.components.count;e;)this.initialId+="0",e--;console.log("hecs: using ".concat(this.world.components.count," bit archetype ids")),this.createArchetype(this.initialId,[])}},{key:"onEntityActive",value:function onEntityActive(e){this.addToArchetype(e)}},{key:"onEntityComponentChange",value:function onEntityComponentChange(e,t,n){e.active&&this.removeFromArchetype(e),e.archetypeId=e.archetypeId.substring(0,t.id)+(n?"1":"0")+e.archetypeId.substring(t.id+1),this.archetypes[e.archetypeId]||this.createArchetype(e.archetypeId,e.Components),e.active&&this.addToArchetype(e)}},{key:"onEntityInactive",value:function onEntityInactive(e){this.removeFromArchetype(e)}},{key:"addToArchetype",value:function addToArchetype(e){var t=this.archetypes[e.archetypeId];-1===t.entities.indexOf(e)&&t.entities.push(e)}},{key:"removeFromArchetype",value:function removeFromArchetype(e){var t=this.archetypes[e.archetypeId].entities,n=t.indexOf(e);-1!==n&&t.splice(n,1)}},{key:"createArchetype",value:function createArchetype(e,t){t=t.slice();var n=new c(this.world,e,t);return this.archetypes[n.id]=n,this.world.queries.onArchetypeCreated(n),n}}]),ArchetypeManager}();function Component_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Component_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var f=function(){function Component(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in Component_classCallCheck(this,Component),this.world=e,this.name=this.constructor.name,this.props=[],this.modifiedUntilSystemTick=0,this.constructor.props){var r=this.constructor.props[n],o=t[n];r.type||(r={type:r},this.constructor.props[n]=r),this[n]=r.type.initial(void 0===o?r.default:o),this.props.push(r)}}return function Component_createClass(e,t,n){return t&&Component_defineProperties(e.prototype,t),n&&Component_defineProperties(e,n),e}(Component,[{key:"toJSON",value:function toJSON(){var e={};for(var t in this.constructor.props){var n=this.constructor.props[t],r=n.type||n;e[t]=r.toJSON(this[t])}return e}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.constructor.props){var n=this.constructor.props[t],r=n.type||n;void 0!==e[t]&&(this[t]=r.fromJSON(e[t],this[t]))}return this}},{key:"modified",value:function modified(){this.modifiedUntilSystemTick=this.world.systems.tick+this.world.systems.systems.length}}]),Component}();function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function StateComponent_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var n,r=_getPrototypeOf(e);if(t){var o=_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return _possibleConstructorReturn(this,n)}}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}f.props={},f.isComponent=!0;var l=function(e){!function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}(StateComponent,e);var t=_createSuper(StateComponent);function StateComponent(){return StateComponent_classCallCheck(this,StateComponent),t.apply(this,arguments)}return StateComponent}(f);function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Entity_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}l.isStateComponent=!0;var p=function(){function Entity(e,t,n,r){!function Entity_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,Entity),this.world=e,this.id=n,this.name=t||null,this.meta=r||{},this.Components=[],this.components=new Map,this.parent=null,this.children=[],this.needsBind=!1,this.inactiveComponents=[],this.archetypeId=e.archetypes.initialId,this.active=!1}return function Entity_createClass(e,t,n){return t&&Entity_defineProperties(e.prototype,t),n&&Entity_defineProperties(e,n),e}(Entity,[{key:"add",value:function add(e,t,n){var r;e.isComponent?r=new e(this.world,t):(r=e,e=e.constructor);var o=this.components.has(e);return this.components.set(e,r),o?r.modified():(this.Components.push(e),this.world.archetypes.onEntityComponentChange(this,e,!0)),n?r:this}},{key:"get",value:function get(e){return this.components.get(e)}},{key:"has",value:function has(e){return!!this.components.get(e)}},{key:"remove",value:function remove(e){if(this.components.has(e)){this.components.delete(e);var t=this.Components.indexOf(e);return this.Components.splice(t,1),this.world.archetypes.onEntityComponentChange(this,e,!1),this.Components.length||!this.deactivating&&!this.destroying||(this.active=!1,this.deactivating=!1,this.destroying=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this}console.warn("Entity: cannot remove component as it doesnt have one")}},{key:"bind",value:function bind(){var e=this;this.needsBind&&(this.parent=this.parent?this.world.entities.getById(this.parent):null,this.children=this.children.map((function(t){return e.world.entities.getById(t)})),this.needsBind=!1)}},{key:"setParent",value:function setParent(e){if(this.bind(),this.parent){this.parent.bind();var t=this.parent.children.indexOf(this);this.parent.children.splice(t,1),this.parent=null}return e&&(this.parent=e,this.parent.children.push(this)),this}},{key:"getParent",value:function getParent(){return this.bind(),this.parent}},{key:"getChildren",value:function getChildren(){return this.bind(),this.children}},{key:"traverse",value:function traverse(e){this.bind(),e(this);for(var t=0;t<this.children.length;t++)this.children[t].traverse(e)}},{key:"traverseAncestors",value:function traverseAncestors(e){this.bind();for(var t=this.parent;t;)e(t),t.bind(),t=t.parent}},{key:"activate",value:function activate(){if(!this.active){for(;this.inactiveComponents.length;){var e=this.inactiveComponents.pop(),t=e.constructor;this.components.set(t,e),this.Components.push(t),this.world.archetypes.onEntityComponentChange(this,t,!0)}return this.active=!0,this.deactivating=!1,this.destroying=!1,this.world.entities.onEntityActive(this),this.world.archetypes.onEntityActive(this),this}console.warn("Entity: cannot activate as entity is already active")}},{key:"deactivate",value:function deactivate(){for(var e=this.Components.length-1;e>=0;--e){var t=this.Components[e];if(t.__proto__===l)this.deactivating=!0;else{var n=this.components.get(t);this.components.delete(t),this.Components.splice(e,1),this.inactiveComponents.push(n),this.world.archetypes.onEntityComponentChange(this,t,!1)}}return this.deactivating||(this.active=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this}},{key:"destroy",value:function destroy(){for(var e=this.Components.length-1;e>=0;--e){var t=this.Components[e];t.__proto__===l?this.destroying=!0:(this.components.delete(t),this.Components.splice(e,1),this.world.archetypes.onEntityComponentChange(this,t,!1))}this.destroying||(this.active=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this.bind();for(var n=0;n<this.children.length;n++)this.children[n].destroy();return this}},{key:"toJSON",value:function toJSON(){var e,t={id:this.id,name:this.name,parent:(null===(e=this.getParent())||void 0===e?void 0:e.id)||null,children:this.getChildren().map((function(e){return e.id})),meta:_objectSpread({},this.meta)};return this.components.forEach((function(e){e.constructor.__proto__===f&&(t[e.name]=e.toJSON())})),t}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.id=e.id,this.name=e.name,this.parent=e.parent,this.children=e.children,this.meta=e.meta,e)if("id"!==t&&"name"!==t&&"parent"!==t&&"children"!==t&&"meta"!==t){var n=this.world.components.getByName(t);this.add(n,void 0,!0).fromJSON(e[t])}return this.needsBind=!0,this}}]),Entity}();function EntityManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var h=function(){function EntityManager(e){!function EntityManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,EntityManager),this.world=e,this.entities=new Map,this.nextEntityId=0}return function EntityManager_createClass(e,t,n){return t&&EntityManager_defineProperties(e.prototype,t),n&&EntityManager_defineProperties(e,n),e}(EntityManager,[{key:"create",value:function create(e,t){return t||(t="".concat(this.world.id,":").concat(this.nextEntityId++)),new p(this.world,e,t)}},{key:"getById",value:function getById(e){return this.entities.get(e)}},{key:"onEntityActive",value:function onEntityActive(e){this.entities.set(e.id,e),this.world.emit("entity-active",e)}},{key:"onEntityInactive",value:function onEntityInactive(e){this.entities.delete(e.id),this.world.emit("entity-inactive",e)}},{key:"reset",value:function reset(){this.entities.forEach((function(e){e.destroy()}))}}]),EntityManager}();function ComponentManager_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var y=function(){function ComponentManager(e){!function ComponentManager_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,ComponentManager),this.world=e,this.count=0,this.lastComponentId=0,this.componentsByName={}}return function ComponentManager_createClass(e,t,n){return t&&ComponentManager_defineProperties(e.prototype,t),n&&ComponentManager_defineProperties(e,n),e}(ComponentManager,[{key:"register",value:function register(e){if(this.componentsByName[e.name])throw new Error("hecs: component already registered '".concat(e.name,"'"));return e.id=this.lastComponentId++,this.componentsByName[e.name]=e,this.count++,this}},{key:"getByName",value:function getByName(e){return this.componentsByName[e]}}]),ComponentManager}();function createPlugin(e){var t=e.name,n=e.plugins,r=void 0===n?[]:n,o=e.systems,i=void 0===o?[]:o,s=e.components,a=void 0===s?[]:s,c=e.decorate,u=void 0===c?function(){}:c;if(!t)throw new Error("hecs: createPlugin requires name");return{name:t,plugins:r,systems:i,components:a,decorate:u}}function World_typeof(e){return(World_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function World_ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function World_objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?World_ownKeys(Object(n),!0).forEach((function(t){World_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):World_ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function World_defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function World_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function World_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function World_setPrototypeOf(e,t){return(World_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,t){return e.__proto__=t,e})(e,t)}function World_createSuper(e){var t=function World_isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var n,r=World_getPrototypeOf(e);if(t){var o=World_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return World_possibleConstructorReturn(this,n)}}function World_possibleConstructorReturn(e,t){return!t||"object"!==World_typeof(t)&&"function"!=typeof t?World_assertThisInitialized(e):t}function World_assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function World_getPrototypeOf(e){return(World_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var d=function(e){!function World_inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&World_setPrototypeOf(e,t)}(World,e);var t=World_createSuper(World);function World(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return World_classCallCheck(this,World),(e=t.call(this)).id=0,e.version=0,e.plugins=new Map,e.providers={},e.systems=new i(World_assertThisInitialized(e)),e.queries=new a(World_assertThisInitialized(e)),e.archetypes=new u(World_assertThisInitialized(e)),e.entities=new h(World_assertThisInitialized(e)),e.components=new y(World_assertThisInitialized(e)),e.registerPlugin(createPlugin(World_objectSpread({name:"root"},n))),e.archetypes.init(),e.systems.init(),e}return function World_createClass(e,t,n){return t&&World_defineProperties(e.prototype,t),n&&World_defineProperties(e,n),e}(World,[{key:"registerPlugin",value:function registerPlugin(e){var t=this;this.plugins.has(e)?console.warn("hecs: already registered plugin '".concat(e.name,"'")):(this.plugins.set(e,!0),e.plugins.forEach((function(e){t.registerPlugin(e)})),e.systems.forEach((function(e){t.systems.register(e)})),e.components.forEach((function(e){t.components.register(e)})),e.decorate&&e.decorate(this),console.log("hecs: registered plugin '".concat(e.name,"'")))}},{key:"update",value:function update(e){this.version++,this.systems.update(e)}},{key:"reset",value:function reset(){this.entities.reset(),this.update(1/60*2),this.systems.reset()}},{key:"toJSON",value:function toJSON(){var e={nextEntityId:this.entities.nextEntityId,entities:[]};return this.entities.entities.forEach((function(t){return e.entities.push(t.toJSON())})),e}},{key:"fromJSON",value:function fromJSON(e){var t=this;this.entities.nextEntityId=e.nextEntityId,e.entities.forEach((function(e){t.entities.create(e.name,e.id).fromJSON(e).activate()}))}}]),World}(o.a),m={Initialization:1e3,Simulation:2e3,Presentation:3e3};function System_defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var v=function(){function System(e){for(var t in function System_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,System),this.order=m.Simulation,this.world=e,this.queries={},this.active=!0,this.constructor.queries){var n=this.constructor.queries[t];this.queries[t]=this.world.queries.create(n)}}return function System_createClass(e,t,n){return t&&System_defineProperties(e.prototype,t),n&&System_defineProperties(e,n),e}(System,[{key:"init",value:function init(e){}},{key:"update",value:function update(){}},{key:"reset",value:function reset(){}}]),System}();function LocalComponent_typeof(e){return(LocalComponent_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function _typeof(e){return typeof e}:function _typeof(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function LocalComponent_classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function LocalComponent_setPrototypeOf(e,t){return(LocalComponent_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(e,t){return e.__proto__=t,e})(e,t)}function LocalComponent_createSuper(e){var t=function LocalComponent_isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var n,r=LocalComponent_getPrototypeOf(e);if(t){var o=LocalComponent_getPrototypeOf(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return LocalComponent_possibleConstructorReturn(this,n)}}function LocalComponent_possibleConstructorReturn(e,t){return!t||"object"!==LocalComponent_typeof(t)&&"function"!=typeof t?function LocalComponent_assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function LocalComponent_getPrototypeOf(e){return(LocalComponent_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var _=function(e){!function LocalComponent_inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&LocalComponent_setPrototypeOf(e,t)}(LocalComponent,e);var t=LocalComponent_createSuper(LocalComponent);function LocalComponent(){return LocalComponent_classCallCheck(this,LocalComponent),t.apply(this,arguments)}return LocalComponent}(f);_.isLocalComponent=!0;var g=n(0);function Not(e){return{Component:e,isNot:!0}}function Modified(e){return{Component:e,isModified:!0}}}])}));
{
"name": "hecs",
"version": "0.14.0",
"version": "0.15.0",
"main": "dist/hecs.js",

@@ -44,3 +44,5 @@ "scripts": {

"license": "MIT",
"gitHead": "c48ea36f82a2560d9fcbd7310be5ca9bfda1104c"
"dependencies": {
"eventemitter3": "^4.0.7"
}
}

@@ -89,2 +89,3 @@ import { Component } from './Component'

}
return this
}

@@ -191,2 +192,3 @@

}
this.bind()
for (let i = 0; i < this.children.length; i++) {

@@ -193,0 +195,0 @@ this.children[i].destroy()

@@ -22,2 +22,3 @@ import { Entity } from './Entity'

this.entities.set(entity.id, entity)
this.world.emit('entity-active', entity)
}

@@ -27,2 +28,3 @@

this.entities.delete(entity.id)
this.world.emit('entity-inactive', entity)
}

@@ -29,0 +31,0 @@

@@ -0,1 +1,2 @@

import EventEmitter from 'eventemitter3'
import { SystemManager } from './SystemManager'

@@ -8,4 +9,5 @@ import { QueryManager } from './QueryManager'

export class World {
export class World extends EventEmitter {
constructor(options = {}) {
super()
this.id = 0

@@ -12,0 +14,0 @@ this.version = 0

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc