Comparing version 0.11.0 to 0.12.0
@@ -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 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(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 h})),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 o=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 i=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 o(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],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)}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.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||(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:"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))}return this.destroying||(this.active=!1,this.world.entities.onEntityInactive(this),this.world.archetypes.onEntityInactive(this)),this}},{key:"toJSON",value:function toJSON(){var e={id:this.id,name:this.name,meta:_objectSpread({},this.meta)};return this.components.forEach((function(t){t.constructor.__proto__===c&&(e[t.name]=t.toJSON())})),e}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.id=e.id,this.name=e.name,this.meta=e.meta,e)if("id"!==t&&"name"!==t&&"meta"!==t){var n=this.world.components.getByName(t);this.add(n,void 0,!0).fromJSON(e[t])}return 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 p=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 l=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_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 h=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 i(this),this.archetypes=new a(this),this.entities=new p(this),this.components=new l(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 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 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=2)}([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(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 h})),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 o=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 i=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 o(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],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)}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.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:"setParent",value:function setParent(e){if(this.parent){var t=this.parent.children.indexOf(this);this.parent.children.splice(t,1),this.parent=null}e&&(this.parent=e,e.children.push(this))}},{key:"getParent",value:function getParent(){return this.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={id:this.id,name:this.name,meta:_objectSpread({},this.meta)};return this.components.forEach((function(t){t.constructor.__proto__===c&&(e[t.name]=t.toJSON())})),e}},{key:"fromJSON",value:function fromJSON(e){for(var t in this.id=e.id,this.name=e.name,this.meta=e.meta,e)if("id"!==t&&"name"!==t&&"meta"!==t){var n=this.world.components.getByName(t);this.add(n,void 0,!0).fromJSON(e[t])}return 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 p=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 l=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_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 h=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 i(this),this.archetypes=new a(this),this.entities=new p(this),this.components=new l(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 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 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}}}])})); |
{ | ||
"name": "hecs", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"main": "dist/hecs.js", | ||
@@ -44,3 +44,3 @@ "scripts": { | ||
"license": "MIT", | ||
"gitHead": "eae4767e2aefdd0c16315d7f3da60a696b70847a" | ||
"gitHead": "372f6b986a3a86d897ef13c64eb1706bb79f4862" | ||
} |
@@ -12,2 +12,4 @@ import { Component } from './Component' | ||
this.components = new Map() | ||
this.parent = null | ||
this.children = [] | ||
this.inactiveComponents = [] | ||
@@ -28,3 +30,5 @@ this.archetypeId = world.archetypes.initialId | ||
this.components.set(Component, component) | ||
if (!replacing) { | ||
if (replacing) { | ||
component.modified() | ||
} else { | ||
this.Components.push(Component) | ||
@@ -63,2 +67,20 @@ this.world.archetypes.onEntityComponentChange(this, Component, true) | ||
setParent(entity) { | ||
// remove current parent (if any) | ||
if (this.parent) { | ||
const idx = this.parent.children.indexOf(this) | ||
this.parent.children.splice(idx, 1) | ||
this.parent = null | ||
} | ||
// add new parent (if any) | ||
if (entity) { | ||
this.parent = entity | ||
entity.children.push(this) | ||
} | ||
} | ||
getParent() { | ||
return this.parent | ||
} | ||
activate() { | ||
@@ -135,2 +157,5 @@ if (this.active) { | ||
} | ||
for (let i = 0; i < this.children.length; i++) { | ||
this.children[i].destroy() | ||
} | ||
return this | ||
@@ -137,0 +162,0 @@ } |
@@ -44,3 +44,3 @@ import { | ||
expect(component.number).toBe(0) | ||
expect(component.text).toBe('') | ||
expect(component.string).toBe('') | ||
expect(component.json).toBe(null) | ||
@@ -56,3 +56,3 @@ }) | ||
expect(data.BaseTypes.number).toBe(0) | ||
expect(data.BaseTypes.text).toBe('') | ||
expect(data.BaseTypes.string).toBe('') | ||
expect(data.BaseTypes.json).toBe(null) | ||
@@ -67,3 +67,3 @@ entity.remove(BaseTypes) | ||
expect(component.number).toBe(0) | ||
expect(component.text).toBe('') | ||
expect(component.string).toBe('') | ||
expect(component.json).toBe(null) | ||
@@ -76,3 +76,3 @@ }) | ||
number: 5, | ||
text: 'Hello', | ||
string: 'Hello', | ||
json: { bar: 'baz' }, | ||
@@ -83,3 +83,3 @@ }) | ||
expect(component.number).toBe(5) | ||
expect(component.text).toBe('Hello') | ||
expect(component.string).toBe('Hello') | ||
expect(component.json.bar).toBe('baz') | ||
@@ -95,3 +95,3 @@ }) | ||
expect(data.BaseTypes.number).toBe(5) | ||
expect(data.BaseTypes.text).toBe('Hello') | ||
expect(data.BaseTypes.string).toBe('Hello') | ||
expect(data.BaseTypes.json).toBe(JSON.stringify({ bar: 'baz' })) | ||
@@ -106,3 +106,3 @@ entity.remove(BaseTypes) | ||
expect(component.number).toBe(5) | ||
expect(component.text).toBe('Hello') | ||
expect(component.string).toBe('Hello') | ||
expect(component.json.bar).toBe('baz') | ||
@@ -118,3 +118,3 @@ }) | ||
expect(component.number).toBe(5) | ||
expect(component.text).toBe('Hello') | ||
expect(component.string).toBe('Hello') | ||
expect(component.json.foo).toBe('bar') | ||
@@ -128,3 +128,3 @@ entity.remove(ConfiguredTypes) | ||
number: 2, | ||
text: 'Bye', | ||
string: 'Bye', | ||
json: { bar: 'baz' }, | ||
@@ -135,3 +135,3 @@ }) | ||
expect(component.number).toBe(2) | ||
expect(component.text).toBe('Bye') | ||
expect(component.string).toBe('Bye') | ||
expect(component.json.bar).toBe('baz') | ||
@@ -138,0 +138,0 @@ entity.remove(ConfiguredTypes) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76823
34
1337