Comparing version 0.16.0 to 0.17.0
@@ -5,4 +5,7 @@ module.exports = api => { | ||
presets: ['@babel/preset-env'], | ||
plugins: [['@babel/plugin-proposal-class-properties', { loose: true }]], | ||
plugins: [ | ||
['@babel/plugin-proposal-class-properties', { loose: true }], | ||
'@babel/plugin-transform-runtime' | ||
], | ||
} | ||
} |
@@ -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=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}}}])})); | ||
!function webpackUniversalModuleDefinition(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.hecs=e():t.HECS=e()}(this,(function(){return function(t){var e={};function __webpack_require__(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,__webpack_require__),r.l=!0,r.exports}return __webpack_require__.m=t,__webpack_require__.c=e,__webpack_require__.d=function(t,e,n){__webpack_require__.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},__webpack_require__.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,e){if(1&e&&(t=__webpack_require__(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(__webpack_require__.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)__webpack_require__.d(n,r,function(e){return t[e]}.bind(null,r));return n},__webpack_require__.n=function(t){var e=t&&t.__esModule?function getDefault(){return t.default}:function getModuleExports(){return t};return __webpack_require__.d(e,"a",e),e},__webpack_require__.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=13)}([function(t,e){t.exports=function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function _defineProperties(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}t.exports=function _createClass(t,e,n){return e&&_defineProperties(t.prototype,e),n&&_defineProperties(t,n),t}},function(t,e){function _getPrototypeOf(e){return t.exports=_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(e)}t.exports=_getPrototypeOf},function(t,e){t.exports=function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}},function(t,e,n){var r=n(10);t.exports=function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}},function(t,e,n){var r=n(11),i=n(3);t.exports=function _possibleConstructorReturn(t,e){return!e||"object"!==r(e)&&"function"!=typeof e?i(t):e}},function(t,e){t.exports=function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}},function(t,e,n){"use strict";(function(t){n.d(e,"a",(function(){return r})),n.d(e,"c",(function(){return i})),n.d(e,"e",(function(){return o})),n.d(e,"d",(function(){return s})),n.d(e,"b",(function(){return a}));var r={name:"Boolean",initial:function initial(t){return t||!1},toJSON:function toJSON(t){return t},fromJSON:function fromJSON(t,e){return t||!1}},i={name:"Number",initial:function initial(t){return t||0},toJSON:function toJSON(t){return t},fromJSON:function fromJSON(t,e){return t||0}},o={name:"String",initial:function initial(t){return t||""},toJSON:function toJSON(t){return t},fromJSON:function fromJSON(t,e){return t||""}},s={name:"Ref",initial:function initial(t){return t||null},toJSON:function toJSON(t){return null},fromJSON:function fromJSON(t,e){return t||null}},c="undefined"==typeof window?t.JSON:window.JSON,a={name:"JSON",initial:function initial(t){return t?c.parse(c.stringify(t)):null},toJSON:function toJSON(t){return t&&c.stringify(t)},fromJSON:function fromJSON(t,e){return t&&c.parse(t)}}}).call(this,n(12))},function(t,e,n){"use strict";var r=Object.prototype.hasOwnProperty,i="~";function Events(){}function EE(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function addListener(t,e,n,r,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new EE(n,r||t,o),c=i?i+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],s]:t._events[c].push(s):(t._events[c]=s,t._eventsCount++),t}function clearEvent(t,e){0==--t._eventsCount?t._events=new Events:delete t._events[e]}function EventEmitter(){this._events=new Events,this._eventsCount=0}Object.create&&(Events.prototype=Object.create(null),(new Events).__proto__||(i=!1)),EventEmitter.prototype.eventNames=function eventNames(){var t,e,n=[];if(0===this._eventsCount)return n;for(e in t=this._events)r.call(t,e)&&n.push(i?e.slice(1):e);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},EventEmitter.prototype.listeners=function listeners(t){var e=i?i+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,o=n.length,s=new Array(o);r<o;r++)s[r]=n[r].fn;return s},EventEmitter.prototype.listenerCount=function listenerCount(t){var e=i?i+t:t,n=this._events[e];return n?n.fn?1:n.length:0},EventEmitter.prototype.emit=function emit(t,e,n,r,o,s){var c=i?i+t:t;if(!this._events[c])return!1;var a,u,h=this._events[c],f=arguments.length;if(h.fn){switch(h.once&&this.removeListener(t,h.fn,void 0,!0),f){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,e),!0;case 3:return h.fn.call(h.context,e,n),!0;case 4:return h.fn.call(h.context,e,n,r),!0;case 5:return h.fn.call(h.context,e,n,r,o),!0;case 6:return h.fn.call(h.context,e,n,r,o,s),!0}for(u=1,a=new Array(f-1);u<f;u++)a[u-1]=arguments[u];h.fn.apply(h.context,a)}else{var p,l=h.length;for(u=0;u<l;u++)switch(h[u].once&&this.removeListener(t,h[u].fn,void 0,!0),f){case 1:h[u].fn.call(h[u].context);break;case 2:h[u].fn.call(h[u].context,e);break;case 3:h[u].fn.call(h[u].context,e,n);break;case 4:h[u].fn.call(h[u].context,e,n,r);break;default:if(!a)for(p=1,a=new Array(f-1);p<f;p++)a[p-1]=arguments[p];h[u].fn.apply(h[u].context,a)}}return!0},EventEmitter.prototype.on=function on(t,e,n){return addListener(this,t,e,n,!1)},EventEmitter.prototype.once=function once(t,e,n){return addListener(this,t,e,n,!0)},EventEmitter.prototype.removeListener=function removeListener(t,e,n,r){var o=i?i+t:t;if(!this._events[o])return this;if(!e)return clearEvent(this,o),this;var s=this._events[o];if(s.fn)s.fn!==e||r&&!s.once||n&&s.context!==n||clearEvent(this,o);else{for(var c=0,a=[],u=s.length;c<u;c++)(s[c].fn!==e||r&&!s[c].once||n&&s[c].context!==n)&&a.push(s[c]);a.length?this._events[o]=1===a.length?a[0]:a:clearEvent(this,o)}return this},EventEmitter.prototype.removeAllListeners=function removeAllListeners(t){var e;return t?(e=i?i+t:t,this._events[e]&&clearEvent(this,e)):(this._events=new Events,this._eventsCount=0),this},EventEmitter.prototype.off=EventEmitter.prototype.removeListener,EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prefixed=i,EventEmitter.EventEmitter=EventEmitter,t.exports=EventEmitter},function(t,e){t.exports=function _readOnlyError(t){throw new Error('"'+t+'" is read-only')}},function(t,e){function _setPrototypeOf(e,n){return t.exports=_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(t,e){return t.__proto__=e,t},_setPrototypeOf(e,n)}t.exports=_setPrototypeOf},function(t,e){function _typeof(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?t.exports=_typeof=function _typeof(t){return typeof t}:t.exports=_typeof=function _typeof(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(e)}t.exports=_typeof},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"World",(function(){return M})),n.d(e,"System",(function(){return A})),n.d(e,"Component",(function(){return k})),n.d(e,"LocalComponent",(function(){return I})),n.d(e,"StateComponent",(function(){return N})),n.d(e,"BooleanType",(function(){return q.a})),n.d(e,"NumberType",(function(){return q.c})),n.d(e,"StringType",(function(){return q.e})),n.d(e,"RefType",(function(){return q.d})),n.d(e,"JSONType",(function(){return q.b})),n.d(e,"Groups",(function(){return J})),n.d(e,"Not",(function(){return Not})),n.d(e,"Modified",(function(){return Modified})),n.d(e,"createPlugin",(function(){return createPlugin}));var r=n(6),i=n.n(r),o=n(0),s=n.n(o),c=n(1),a=n.n(c),u=n(3),h=n.n(u),f=n(4),p=n.n(f),l=n(5),y=n.n(l),d=n(2),v=n.n(d),m=n(8),_=n.n(m),g=function(){function SystemManager(t){s()(this,SystemManager),this.world=t,this.Systems=new Map,this.systems=[],this.systemsByName={},this.tick=0}return a()(SystemManager,[{key:"register",value:function register(t){if(!this.Systems.has(t)){var e=new t(this.world);this.Systems.set(t,e);for(var n=0,r=0;r<this.systems.length;r++){if(this.systems[r].order>e.order)break;n=r+1}return this.systems.splice(n,0,e),this.systemsByName[t.name]=e,this}console.warn("hecs: already registered system '".concat(t.name,"'"))}},{key:"init",value:function init(){for(var t=0;t<this.systems.length;t++){this.systems[t].init(this.world)}}},{key:"get",value:function get(t){return this.Systems.get(t)}},{key:"getByName",value:function getByName(t){return this.systemsByName[t]}},{key:"update",value:function update(t){for(var e=0;e<this.systems.length;e++){this.tick++;var n=this.systems[e];n.active&&n.update(t)}}},{key:"reset",value:function reset(){this.systems.forEach((function(t){t.reset()}))}}]),SystemManager}(),w=n(9),b=n.n(w),E=function(){function Query(t,e){s()(this,Query),this.world=t,this.Components=e,this.Modified=[],this.archetypes=[];for(var n=0;n<e.length;n++){var r=e[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 a()(Query,[{key:"isModified",value:function isModified(t){for(var e=0;e<this.Modified.length;e++){var n=this.Modified[e];if(t.get(n).modifiedUntilSystemTick>=this.world.systems.tick)return!0}return!1}},{key:"forEach",value:function forEach(t){this.Modified.length?this._forEachModified(t):this._forEach(t)}},{key:"_forEachModified",value:function _forEachModified(t){for(var e=this.archetypes.length-1;e>=0;--e)for(var n=this.archetypes[e].entities,r=n.length-1;r>=0;--r){var i=n[r];this.isModified(i)&&t(i)}}},{key:"_forEach",value:function _forEach(t){for(var e=this.archetypes.length-1;e>=0;--e)for(var n=this.archetypes[e].entities,r=n.length-1;r>=0;--r){t(n[r])}}},{key:"count",value:function count(){var count=0;return this.forEach((function(){return b()("count"),count++})),count}},{key:"onArchetypeCreated",value:function onArchetypeCreated(t){this.matchesArchetype(t)&&this.archetypes.push(t)}},{key:"matchesArchetype",value:function matchesArchetype(t){for(var e=!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!==t.Components.indexOf(r)){e=!1;break}}else if(-1===t.Components.indexOf(r)){e=!1;break}}e&&this.archetypes.push(t)}}]),Query}(),O=function(){function QueryManager(t){s()(this,QueryManager),this.world=t,this.queries=[]}return a()(QueryManager,[{key:"create",value:function create(t){var e=new E(this.world,t);return this.queries.push(e),e}},{key:"onArchetypeCreated",value:function onArchetypeCreated(t){for(var e=0;e<this.queries.length;e++){this.queries[e].onArchetypeCreated(t)}}}]),QueryManager}(),S=function Archetype(t,e,n){s()(this,Archetype),this.world=t,this.id=e,this.Components=n,this.entities=[]},C=function(){function ArchetypeManager(t,e){s()(this,ArchetypeManager),this.world=t,this.archetypes={},this.initialId=null}return a()(ArchetypeManager,[{key:"init",value:function init(){this.initialId="";for(var t=this.world.components.count;t;)this.initialId+="0",t--;console.log("hecs: using ".concat(this.world.components.count," bit archetype ids")),this.createArchetype(this.initialId,[])}},{key:"onEntityActive",value:function onEntityActive(t){this.addToArchetype(t)}},{key:"onEntityComponentChange",value:function onEntityComponentChange(t,e,n){t.active&&this.removeFromArchetype(t),t.archetypeId=t.archetypeId.substring(0,e.id)+(n?"1":"0")+t.archetypeId.substring(e.id+1),this.archetypes[t.archetypeId]||this.createArchetype(t.archetypeId,t.Components),t.active&&this.addToArchetype(t)}},{key:"onEntityInactive",value:function onEntityInactive(t){this.removeFromArchetype(t)}},{key:"addToArchetype",value:function addToArchetype(t){var e=this.archetypes[t.archetypeId];-1===e.entities.indexOf(t)&&e.entities.push(t)}},{key:"removeFromArchetype",value:function removeFromArchetype(t){var e=this.archetypes[t.archetypeId].entities,n=e.indexOf(t);-1!==n&&e.splice(n,1)}},{key:"createArchetype",value:function createArchetype(t,e){e=e.slice();var n=new S(this.world,t,e);return this.archetypes[n.id]=n,this.world.queries.onArchetypeCreated(n),n}}]),ArchetypeManager}(),k=function(){function Component(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};for(var n in s()(this,Component),this.world=t,this.name=this.constructor.name,this.props=[],this.modifiedUntilSystemTick=0,this.constructor.props){var r=this.constructor.props[n],i=e[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 a()(Component,[{key:"toJSON",value:function toJSON(){var t={};for(var e in this.constructor.props){var n=this.constructor.props[e],r=n.type||n;t[e]=r.toJSON(this[e])}return t}},{key:"fromJSON",value:function fromJSON(t){for(var e in this.constructor.props){var n=this.constructor.props[e],r=n.type||n;void 0!==t[e]&&(this[e]=r.fromJSON(t[e],this[e]))}return this}},{key:"modified",value:function modified(){this.modifiedUntilSystemTick=this.world.systems.tick+this.world.systems.systems.length}}]),Component}();function _createSuper(t){var e=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(t){return!1}}();return function _createSuperInternal(){var n,r=v()(t);if(e){var i=v()(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return y()(this,n)}}k.props={},k.isComponent=!0;var N=function(t){p()(StateComponent,t);var e=_createSuper(StateComponent);function StateComponent(){return s()(this,StateComponent),e.apply(this,arguments)}return StateComponent}(k);function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach((function(e){i()(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}N.isStateComponent=!0;var P=function(){function Entity(t,e,n,r){s()(this,Entity),this.world=t,this.id=n,this.name=e||null,this.meta=r||{},this.Components=[],this.components=new Map,this.parent=null,this.children=[],this.needsBind=!1,this.inactiveComponents=[],this.archetypeId=t.archetypes.initialId,this.active=!1}return a()(Entity,[{key:"add",value:function add(t,e,n){var r;t.isComponent?r=new t(this.world,e):(r=t,t=t.constructor);var i=this.components.has(t);return this.components.set(t,r),i?r.modified():(this.Components.push(t),this.world.archetypes.onEntityComponentChange(this,t,!0)),n?r:this}},{key:"get",value:function get(t){return this.components.get(t)}},{key:"has",value:function has(t){return!!this.components.get(t)}},{key:"remove",value:function remove(t){if(this.components.has(t)){this.components.delete(t);var e=this.Components.indexOf(t);return this.Components.splice(e,1),this.world.archetypes.onEntityComponentChange(this,t,!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 t=this;this.needsBind&&(this.parent=this.parent?this.world.entities.getById(this.parent):null,this.children=this.children.map((function(e){return t.world.entities.getById(e)})),this.needsBind=!1)}},{key:"setParent",value:function setParent(t){if(this.bind(),this.parent){this.parent.bind();var e=this.parent.children.indexOf(this);this.parent.children.splice(e,1),this.parent=null}return t&&(this.parent=t,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(t){this.bind(),t(this);for(var e=0;e<this.children.length;e++)this.children[e].traverse(t)}},{key:"traverseAncestors",value:function traverseAncestors(t){this.bind();for(var e=this.parent;e;)t(e),e.bind(),e=e.parent}},{key:"activate",value:function activate(){if(!this.active){for(;this.inactiveComponents.length;){var t=this.inactiveComponents.pop(),e=t.constructor;this.components.set(e,t),this.Components.push(e),this.world.archetypes.onEntityComponentChange(this,e,!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 t=this.Components.length-1;t>=0;--t){var e=this.Components[t];if(e.__proto__===N)this.deactivating=!0;else{var n=this.components.get(e);this.components.delete(e),this.Components.splice(t,1),this.inactiveComponents.push(n),this.world.archetypes.onEntityComponentChange(this,e,!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 t=this.Components.length-1;t>=0;--t){var e=this.Components[t];e.__proto__===N?this.destroying=!0:(this.components.delete(e),this.Components.splice(t,1),this.world.archetypes.onEntityComponentChange(this,e,!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 t,e={id:this.id,name:this.name,parent:(null===(t=this.getParent())||void 0===t?void 0:t.id)||null,children:this.getChildren().map((function(t){return t.id})),meta:_objectSpread({},this.meta)};return this.components.forEach((function(t){t.constructor.__proto__===k&&(e[t.name]=t.toJSON())})),e}},{key:"fromJSON",value:function fromJSON(t){for(var e in this.id=t.id,this.name=t.name,this.parent=t.parent,this.children=t.children,this.meta=t.meta,t)if("id"!==e&&"name"!==e&&"parent"!==e&&"children"!==e&&"meta"!==e){var n=this.world.components.getByName(e);this.add(n,void 0,!0).fromJSON(t[e])}return this.needsBind=!0,this}}]),Entity}(),x=function(){function EntityManager(t){s()(this,EntityManager),this.world=t,this.entities=new Map,this.nextEntityId=0}return a()(EntityManager,[{key:"create",value:function create(t,e){return e||(e="".concat(this.world.id,":").concat(this.nextEntityId++)),new P(this.world,t,e)}},{key:"getById",value:function getById(t){return this.entities.get(t)}},{key:"onEntityActive",value:function onEntityActive(t){this.entities.set(t.id,t),this.world.emit("entity-active",t)}},{key:"onEntityInactive",value:function onEntityInactive(t){this.entities.delete(t.id),this.world.emit("entity-inactive",t)}},{key:"reset",value:function reset(){this.entities.forEach((function(t){t.destroy()}))}}]),EntityManager}(),j=function(){function ComponentManager(t){s()(this,ComponentManager),this.world=t,this.count=0,this.lastComponentId=0,this.componentsByName={}}return a()(ComponentManager,[{key:"register",value:function register(t){if(this.componentsByName[t.name])throw new Error("hecs: component already registered '".concat(t.name,"'"));return t.id=this.lastComponentId++,this.componentsByName[t.name]=t,this.count++,this}},{key:"getByName",value:function getByName(t){return this.componentsByName[t]}}]),ComponentManager}();function createPlugin(t){var e=t.name,n=t.plugins,r=void 0===n?[]:n,i=t.systems,o=void 0===i?[]:i,s=t.components,c=void 0===s?[]:s,a=t.decorate,u=void 0===a?function(){}:a;if(!e)throw new Error("hecs: createPlugin requires name");return{name:e,plugins:r,systems:o,components:c,decorate:u}}function World_ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function World_objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?World_ownKeys(Object(n),!0).forEach((function(e){i()(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):World_ownKeys(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function World_createSuper(t){var e=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(t){return!1}}();return function _createSuperInternal(){var n,r=v()(t);if(e){var i=v()(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return y()(this,n)}}var M=function(t){p()(World,t);var e=World_createSuper(World);function World(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return s()(this,World),(t=e.call(this)).id=0,t.version=0,t.plugins=new Map,t.providers={},t.systems=new g(h()(t)),t.queries=new O(h()(t)),t.archetypes=new C(h()(t)),t.entities=new x(h()(t)),t.components=new j(h()(t)),t.registerPlugin(createPlugin(World_objectSpread({name:"root"},n))),t.archetypes.init(),t.systems.init(),t}return a()(World,[{key:"registerPlugin",value:function registerPlugin(t){var e=this;this.plugins.has(t)?console.warn("hecs: already registered plugin '".concat(t.name,"'")):(this.plugins.set(t,!0),t.plugins.forEach((function(t){e.registerPlugin(t)})),t.systems.forEach((function(t){e.systems.register(t)})),t.components.forEach((function(t){e.components.register(t)})),t.decorate&&t.decorate(this),console.log("hecs: registered plugin '".concat(t.name,"'")))}},{key:"update",value:function update(t){this.version++,this.systems.update(t)}},{key:"reset",value:function reset(){this.entities.reset(),this.update(1/60*2),this.systems.reset()}},{key:"toJSON",value:function toJSON(){var t={nextEntityId:this.entities.nextEntityId,entities:[]};return this.entities.entities.forEach((function(e){return t.entities.push(e.toJSON())})),t}},{key:"fromJSON",value:function fromJSON(t){var e=this;this.entities.nextEntityId=t.nextEntityId,t.entities.forEach((function(t){e.entities.create(t.name,t.id).fromJSON(t).activate()}))}}]),World}(_.a),J={Initialization:1e3,Simulation:2e3,Presentation:3e3},A=function(){function System(t){for(var e in s()(this,System),this.order=J.Simulation,this.world=t,this.queries={},this.active=!0,this.constructor.queries){var n=this.constructor.queries[e];this.queries[e]=this.world.queries.create(n)}}return a()(System,[{key:"init",value:function init(t){}},{key:"update",value:function update(){}},{key:"reset",value:function reset(){}}]),System}();function LocalComponent_createSuper(t){var e=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(t){return!1}}();return function _createSuperInternal(){var n,r=v()(t);if(e){var i=v()(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return y()(this,n)}}var I=function(t){p()(LocalComponent,t);var e=LocalComponent_createSuper(LocalComponent);function LocalComponent(){return s()(this,LocalComponent),e.apply(this,arguments)}return LocalComponent}(k);I.isLocalComponent=!0;var q=n(7);function Not(t){return{Component:t,isNot:!0}}function Modified(t){return{Component:t,isModified:!0}}}])})); |
{ | ||
"name": "hecs", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"main": "dist/hecs.js", | ||
@@ -12,9 +12,10 @@ "scripts": { | ||
"devDependencies": { | ||
"@babel/core": "^7.8.3", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"babel-jest": "^26.1.0", | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"babel-jest": "26.6.0", | ||
"babel-loader": "^8.0.6", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"jest": "^26.1.0", | ||
"jest": "26.6.0", | ||
"terser-webpack-plugin": "^4.1.0", | ||
@@ -48,3 +49,3 @@ "webpack": "^4.41.5", | ||
}, | ||
"gitHead": "7e5eaa3ea835f880779568778619e08ee3a124c2" | ||
"gitHead": "b2671b10cad2b057dbf463fed9578fc75979dbc3" | ||
} |
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
1471
80609
11