-
Notifications
You must be signed in to change notification settings - Fork 0
/
darling.min.js
8 lines (7 loc) · 25.2 KB
/
darling.min.js
1
2
3
4
5
6
7
8
/**
* @license darlingjs v0.7.9 2015-06-20 by Eugene Krevenets.
* Component & Entity based javascript game engine. Decoupled from any visualization, physics, and so on. With injections and modules based on AngularJS.
* http://darlingjs.github.io/
*
*/
!function(a,b){"use strict";function c(a){return"undefined"!=typeof a}function d(a){return"undefined"==typeof a}function e(a){return null!==a&&"object"==typeof a}function f(a){return"[object Array]"===N.apply(a)}function g(a){return"string"==typeof a}function h(a){return a&&a.document&&a.location&&a.alert&&a.setInterval}function i(a){return"[object Date]"===N.apply(a)}function j(a){return"function"==typeof a}function k(a,b,c){if(h(a))throw new Error("Can't copy Window");if(b){if(a===b)throw new Error("Can't copy equivalent objects or arrays");if(f(a)){b.length=0;for(var d=0;d<a.length;d++)b.push(k(a[d]))}else{c&&m(b,function(a,c){delete b[c]});for(var g in a)a.hasOwnProperty(g)&&(b[g]=k(a[g]))}}else b=a,a&&(f(a)?b=k(a,[]):i(a)?b=new Date(a.getTime()):e(a)&&(b=k(a,{})));return b}function l(a){return a&&"number"==typeof a.length?"function"!=typeof a.hasOwnProperty&&"function"!=typeof a.constructor?!0:a instanceof JQLite||jQuery&&a instanceof jQuery||"[object Object]"!==N.call(a)||"function"==typeof a.callee:!1}function m(a,b,c){var d;if(a)if(j(a))for(d in a)"prototype"!==d&&"length"!==d&&"name"!==d&&a.hasOwnProperty(d)&&b.call(c,a[d],d);else if(a.forEach&&a.forEach!==m)a.forEach(b,c);else if(l(a))for(d=0;d<a.length;d++)b.call(c,a[d],d);else for(d in a)a.hasOwnProperty(d)&&b.call(c,a[d],d);return a}function n(a){var b,c,d,e;return"function"==typeof a?(b=a.$inject)||(b=[],c=a.toString().replace(R,""),d=c.match(O),m(d[1].split(P),function(a){a.replace(Q,function(a,c,d){b.push(d)})}),a.$inject=b):f(a)?(e=a.length-1,o(a[e],"fn"),b=a.slice(0,e)):o(a,"fn",!0),b}function o(a,b,c){return c&&f(a)&&(a=a[a.length-1]),p(j(a),b,"not a function, got "+(a&&"object"==typeof a?a.constructor.name||"Object":typeof a)),a}function p(a,b,c){if(!a)throw new Error("Argument '"+(b||"?")+"' is "+(c||"required"));return a}function q(){}function r(a,b){if(null===b||null===a)return a;for(var c in b)a[c]=b[c]}function s(a,b){if(null===b)return a;for(var c in b){var d=b[c];"object"!=typeof d?a[c]=d:(a[c]&&"object"==typeof a[c]||(a[c]={}),s(a[c],d))}return a}function t(a,b,c,d){return b.hasOwnProperty(d)?v(a,b,c,d):u(a,b,c)}function u(a,b,c){switch(c.length){case 0:return function(){return a.call(b)};case 1:return function(){return a.call(b,c[0])};case 2:return function(){return a.call(b,c[0],c[1])};case 3:return function(){return a.call(b,c[0],c[1],c[2])};case 4:return function(){return a.call(b,c[0],c[1],c[2],c[4])};default:return function(){return a.apply(b,c)}}}function v(a,b,c,d){switch(c.length){case 0:return function(){return b[d]()};case 1:return function(){return b[d](c[0])};case 2:return function(){return b[d](c[0],c[1])};case 3:return function(){return b[d](c[0],c[1],c[2])};case 4:return function(){return b[d](c[0],c[1],c[2],c[3])};default:return function(){return a.apply(b,c)}}}function w(a,b,c,d,e){return b.hasOwnProperty(e)?y(a,b,c,d,e):x(a,b,c,d)}function x(a,b,c,d){switch(c.length){case 0:return function(){return a.call(b)};case 1:return function(){return d(c,arguments),a.call(b,c[0])};case 2:return function(){return d(c,arguments),a.call(b,c[0],c[1])};case 3:return function(){return d(c,arguments),a.call(b,c[0],c[1],c[2])};default:return function(){return d(c,arguments),a.apply(b,c)}}}function y(a,b,c,d,e){switch(c.length){case 0:return function(){return b[e]()};case 1:return function(){return d(c,arguments),b[e](c[0])};case 2:return function(){return d(c,arguments),b[e](c[0],c[1])};case 3:return function(){return d(c,arguments),b[e](c[0],c[1],c[2])};case 4:return function(){return d(c,arguments),b[e](c[0],c[1],c[2],c[3])};default:return function(){return d(c,arguments),a.apply(b,c)}}}function z(a){return e(a)&&c(a.$name)}function A(){this.components=[],this.componentsString="",this.componentsHash={},this.nodes=new ca,this.$$marker=null}function B(){this.pool.dispose(this)}function C(a,b){for(var c in a)D(a,c,b)}function D(a,b,c){if(a.hasOwnProperty(b)&&"$"!==b.charAt(0)){var d=a[b];d===!1?c[b]=null:E(d)||null===d?c.$add(b,null):c.$add(b,d)}}function E(a){var b;for(b in a)return!1;return!0}function F(a,b){var c=a.indexOf(b);return c>=0?function(a,b){a[c]=b}:q}function G(a){var b=F(a,"$time"),c=F(a,"$entities");return function(a,d){b(a,d[0]),c(a,d[1])}}function H(a){for(var b=0,c=a.length;c>b;b++)if("$entity"===a[b])return function(a,c){a[b]=c[0]};return q}function I(a,b,c,e,f){d(a._matchingToFamily)&&(a._matchingToFamily={processing:!1,phases:{}});var g=a._matchingToFamily.phases[b];return d(g)&&(g=[],a._matchingToFamily.phases[b]=g),a._matchingToFamily.processing?(g.push({fn:e,ctx:c,args:f}),!1):(a._matchingToFamily.processing=!0,!0)}function J(a,b){a._matchingToFamily.processing=!1;var c=a._matchingToFamily.phases;for(var d in c)K(c,d,a)}function K(a,b,c){if(a.hasOwnProperty(b)){var d=c._matchingToFamily.phases[b];if(d.length>0){var e=d.pop();return void e.fn.apply(e.ctx,e.args)}}}!function(){for(var c=0,d=["ms","moz","webkit","o"],e=0;e<d.length&&!a.requestAnimationFrame;++e)a.requestAnimationFrame=a[d[e]+"RequestAnimationFrame"],a.cancelAnimationFrame=a[d[e]+"CancelAnimationFrame"]||a[d[e]+"CancelRequestAnimationFrame"];a.requestAnimationFrame===b&&(a.requestAnimationFrame=function(b,d){var e=Date.now(),f=Math.max(0,16-(e-c)),g=a.setTimeout(function(){b(e+f)},f);return c=e+f,g}),a.cancelAnimationFrame=a.cancelAnimationFrame||function(b){a.clearTimeout(b)}}();var L=a.darlingutil,M=a.darlingutil=a.darlingutil||{};M.version="0.0.0",M.noConflict=function(){var b=a.darlingutil;return a.darlingutil=L,b},function(){function b(a,b,c){var d=document.getElementById(a);if(null===d)throw new Error("Can't find DOM element with id: \""+a+'"');var e=document.createElement("div");e.style.position="absolute",e.style.top="0px",d.appendChild(e);var f=document.createElement("canvas");return f.width=b||d.clientWidth,f.height=c||d.clientHeight,e.appendChild(f),f}function c(a){a.parentNode&&(a.parentNode.parentNode&&a.parentNode.parentNode.removeChild(a.parentNode),a.parentNode.removeChild(a))}function d(){var a=-1;if("Microsoft Internet Explorer"==navigator.appName){var b=navigator.userAgent,c=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");null!=c.exec(b)&&(a=parseFloat(RegExp.$1))}return a}function e(){var b=0;if(a.opera){var c=a.opera.version();b=parseFloat(c)}return b}function f(a){var b=new Object;if(b.x=0,b.y=0,null!==a)if(a.getBoundingClientRect){var c=document.documentElement,d=a.getBoundingClientRect(),e=c.scrollLeft,f=c.scrollTop;b.x=d.left+e,b.y=d.top+f}else{b.x=a.offsetLeft,b.y=a.offsetTop;for(var g=a.parentNode,i=null;null!==offsetParent;){b.x+=offsetParent.offsetLeft,b.y+=offsetParent.offsetTop;var l=offsetParent.tagName.toLowerCase();if((k&&"table"!=l||(n||p)&&"td"==l)&&(i=kGetBorderWidth(offsetParent),b.x+=i.left,b.y+=i.top),offsetParent!=document.body&&offsetParent!=document.documentElement&&(b.x-=offsetParent.scrollLeft,b.y-=offsetParent.scrollTop),!h&&!s||j)for(;offsetParent!=g&&null!==g;)b.x-=g.scrollLeft,b.y-=g.scrollTop,(m||o)&&(i=kGetBorderWidth(g),b.x+=i.left,b.y+=i.top),g=g.parentNode;g=offsetParent.parentNode,offsetParent=offsetParent.offsetParent}}return b}M.getCanvas=function(a){var b=document.getElementById(a);if(null===b)throw new Error("Can't find DOM element with id: \""+a+'"');return M.isDefined(b.getContext)?b:null},M.placeCanvasInStack=b,M.removeCanvasFromStack=c;var g=navigator.userAgent,h=null!=navigator.appVersion.match(/MSIE/),i=d(),j=h&&i>=8,k=h&&!j,l=null!=g.match(/firefox/i),m=l&&(null!=g.match(/firefox\/2./i)||null!=g.match(/firefox\/1./i)),n=l&&!m,o=null!=navigator.appVersion.match(/WebKit/),p=null!=navigator.appVersion.match(/Chrome/),q=null!=a.opera,r=e(),s=q&&10>r,t=M;t.getElementAbsolutePlacement=function(a){var b=f(a);return b.width=a.offsetWidth,b.height=a.offsetHeight,b},t.getElementAbsolutePos=f}();var N=Object.prototype.toString;M.isDefined=c,M.isUndefined=d,M.isObject=e,M.isArray=f,M.isString=g,M.isWindow=h,M.isDate=i,M.isFunction=j;var O=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,P=/,/,Q=/^\s*(_?)(\S+?)\1\s*$/,R=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,S=[],T=S.slice,U={on:function(a,b,c){if(!W(this,"on",a,[b,c])||!b)return this;this._events||(this._events={});var d=this._events[a]||(this._events[a]=[]);return d.push({callback:b,context:c,ctx:c||this}),this},once:function(a,b,c){if(!W(this,"once",a,[b,c])||!b)return this;var d=this,e=_.once(function(){d.off(a,e),b.apply(this,arguments)});return e._callback=b,this.on(a,e,c)},off:function(a,b,c){var d,e,f,g,h,i,j,k;if(!this._events||!W(this,"off",a,[b,c]))return this;if(!a&&!b&&!c)return this._events={},this;for(g=a?[a]:_.keys(this._events),h=0,i=g.length;i>h;h++)if(a=g[h],f=this._events[a]){if(this._events[a]=d=[],b||c)for(j=0,k=f.length;k>j;j++)e=f[j],(b&&b!==e.callback&&b!==e.callback._callback||c&&c!==e.context)&&d.push(e);d.length||delete this._events[a]}return this},trigger:function(a){if(!this._events)return this;var b=T.call(arguments,1);if(!W(this,"trigger",a,b))return this;var c=this._events[a],d=this._events.all;return c&&X(c,b),d&&X(d,arguments),this},stopListening:function(a,b,c){var d=this._listeners;if(!d)return this;var e=!b&&!c;"object"==typeof b&&(c=this),a&&((d={})[a._listenerId]=a);for(var f in d)d[f].off(b,c,this),e&&delete this._listeners[f];return this}},V=/\s+/,W=function(a,b,c,d){if(!c)return!0;if("object"==typeof c){for(var e in c)a[b].apply(a,[e,c[e]].concat(d));return!1}if(V.test(c)){for(var f=c.split(V),g=0,h=f.length;h>g;g++)a[b].apply(a,[f[g]].concat(d));return!1}return!0},X=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++d<e;)(c=a[d]).callback.call(c.ctx);return;case 1:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f);return;case 2:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g);return;case 3:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g,h);return;default:for(;++d<e;)(c=a[d]).callback.apply(c.ctx,b)}};M.wipe=function(a){for(var b in a)a.hasOwnProperty(b)&&delete a[b]},M.clamp=function(a,b,c){return b>a?b:a>c?c:a},M.isConvexPolygonClockwise=function(a){if(!a)return b;if(a.length<3)return b;for(var c=0,d=a[c],e=null;++c<a.length&&(e=a[c],d.x===e.x&&d.y===e.y);)e=null;if(null===e)return b;for(var f=Math.atan2(e.y-d.y,e.x-d.x);++c<a.length;){var g=a[c];if(d.x!==g.x&&e.x!==g.x||d.y!==g.y&&e.y!==g.y){var h=Math.atan2(g.y-d.y,g.x-d.x),i=f-h;if(i>Math.PI?i-=2*Math.PI:i<-Math.PI&&(i+=2*Math.PI),0>i)return!1;if(i>0)return!0}}};var Y=a.darlingjs,Z=a.darlingjs||(a.darlingjs={});Z.version="0.0.0";var $={},aa={};Z.noConflict=function(){var b=a.darlingjs;return a.darlingjs=Y,b},Z.m=Z.module=function(a,b){if(c(aa[a]))throw new Error('Module "'+a+'" has already been defined.');var d=new ga;return d.$name=a,d.requires=b,aa[a]=d,d},Z.w=Z.world=function(a,b){if(c($[a]))throw new Error('World "'+a+'" has already been defined.');var e=new ia;if(e.$name=a,$[a]=e,f(b))for(var g=0,h=b.length;h>g;g++){var i=b[g],j=aa[i];if(d(j))throw new Error("Can't find module: \""+i+'"');e.$$injectedModules[i]=j;var k=j.$$components;for(var l in k)if(k.hasOwnProperty(l)){var m=j.$$components[l];if(d(m))throw new Error('Module: "'+i+'" has null component with name "'+l+'".');e.$$injectedComponents[m.$name]=m}var n=j.$$systems;for(var o in n)if(n.hasOwnProperty(o)){var p=n[o];if(d(p))throw new Error('Module: "'+i+'" has null system with name "'+o+'".');e.$$injectedSystems[p.$name]=p}}return e},Z.removeModule=function(a){delete aa[a]},Z.removeAllModules=function(){aa={}},Z.removeWorld=function(a){var b;if(g(a))b=a;else for(var c in $)if($[c]===a){b=c;break}var d=$[b];d.$removeAllSystems(),d.$stop(),delete $[b]},Z.removeAllWorlds=function(){$={}};var ba=function(){};s(ba.prototype,U),ba.prototype.$name="",ba.prototype.$$world=null,ba.prototype.$add=function(a,b){var c,e;if(g(a))c=this.$$world.$component(a,b),e=a;else{if(!z(a))throw d(a)?new Error("Can't add component with null name."):new Error("Can't add "+a+" to entity");c=a,e=c.$name}if(d(c))throw new Error("Can't add null component.");return this[e]&&this.$remove(e),this[e]=c,this.trigger("add",this,c),c},ba.prototype.$remove=function(a){var b,c;if(z(a))c=a.$name,b=a;else{if(!g(a))throw new Error("Can't remove from component "+a);c=a,b=this[a]}return this[c]?(this.trigger("remove",this,b),this[c]=null,b):null},ba.prototype.$has=function(a){return g(a)?!!this[a]:!!this[a.$name]},ba.prototype.$applyModifier=function(a){if(M.isFunction(a))this.$$applyModifierFunction(a);else if(M.isString(a))this.$add(a);else if(M.isArray(a))this.$applyModifierArray(a);else{if(!M.isObject(a))throw new Error("Unknown modifier");this.$applyModifierObject(a)}},ba.prototype.$$applyModifierFunction=function(a){a=a.call(this),M.isDefined(a)&&this.$applyModifier(a)},ba.prototype.$applyModifierArray=function(a){for(var b=0,c=a.length;c>b;b++)this.$applyModifier(a[b])},ba.prototype.$applyModifierObject=function(a){for(var b in a){var c=a[b];M.isFunction(c)&&(c=c.call(this)),this.$add(b,c)}},ba.prototype.$revertModifier=function(a){if(!M.isFunction(a))if(M.isString(a))this.$remove(a);else if(M.isArray(a))this.$revertModifierArray(a);else{if(!M.isObject(a))throw new Error("Unknown modifier");this.$revertModifierObject(a)}},ba.prototype.$revertModifierArray=function(a){for(var b=0,c=a.length;c>b;b++)this.$revertModifier(a[b])},ba.prototype.$revertModifierObject=function(a){for(var b in a)this.$remove(b)},A.prototype.$marker=function(){return null===this.$$marker&&(this.$$marker="$$family_"+this.componentsString,this.nodes.PROPERTY_LINK_TO_NODE="$$listNode_of_"+this.$$marker),this.$$marker},A.prototype.newEntity=function(a){this.addIfMatch(a)},A.prototype.addIfMatch=function(a){if(!this.isInList(a)){for(var b=0,c=this.components.length;c>b;b++){var d=this.components[b];if(!a.$has(d))return}a.$$familyMarker||(a.$$familyMarker={}),a.$$familyMarker[this.$marker()]=!0,this.nodes.add(a)}},A.prototype.removeIfMatch=function(a,b){c(b)&&!this.componentsHash[b.$name]||!this.isInList(a)||(a.$$familyMarker[this.$$marker]=!1,this.nodes.remove(a))},A.prototype.isInList=function(a){return a.$$familyMarker&&a.$$familyMarker[this.$$marker]};var ca=function(a){this.$head=this.$tail=null,this._length=0,a?this.PROPERTY_LINK_TO_NODE="$$listNode_"+a:this.PROPERTY_LINK_TO_NODE="$$listNode_"+Math.random()};M.List=ca,s(ca.prototype,U),ca.prototype.add=function(a){var b=fa.get();return b.init(a,this.PROPERTY_LINK_TO_NODE),this.$head?(this.$tail.$next=b,b.$prev=this.$tail,this.$tail=b):this.$head=this.$tail=b,a?this.trigger("add",a):this.trigger("add",b),this._length++,b},ca.prototype.addHead=function(a){var b=fa.get();return b.init(a,this.PROPERTY_LINK_TO_NODE),this.$head?(this.$head.$prev=b,b.$next=this.$head,this.$head=b):this.$head=this.$tail=b,a?this.trigger("add",a):this.trigger("add",b),this._length++,b},ca.prototype.remove=function(a){var b;if(a instanceof da)b=a;else{if(!a.$$linkNode||!a.$$linkNode[this.PROPERTY_LINK_TO_NODE])return!1;if(b=a.$$linkNode[this.PROPERTY_LINK_TO_NODE],null===b)return!1}return this.$tail===b&&(this.$tail=b.$prev),this.$head===b&&(this.$head=b.$next),null!==b.$prev&&(b.$prev.$next=b.$next),null!==b.$next&&(b.$next.$prev=b.$prev),b.dispose(a,this.PROPERTY_LINK_TO_NODE),this.trigger("remove",a),this._length--,!0},ca.prototype.length=function(){return this._length},ca.prototype.forEach=function(a,b,c){if(j(a)){var d,e=this.$head;if(b)for(;e;)d=e.$next,a.call(b,e.instance,c),e=d;else for(;e;)d=e.$next,a(e.instance,c),e=d}};var da=function(a,b){a&&this.init(a,b)};da.prototype.instance=null,da.prototype.$next=null,da.prototype.$prev=null,da.prototype.init=function(a,b){if(this.$prev=this.$next=null,a){if(this.instance=a,a.$$linkNode&&a.$$linkNode[b])throw new Error("Can't store \""+a+'" because it contains '+b+" property."+a.$$linkNode[b]);a.$$linkNode||(a.$$linkNode={}),a.$$linkNode[b]=this}},da.prototype.dispose=function(a,b){this.$prev=this.$next=null,this.instance=null,a.$$linkNode&&(a.$$linkNode[b]=null),this.onDispose()};var ea=function(a){function b(){var b=new a;return b.onDispose=B,b.pool=d,b}var c=[],d=this;this.get=function(){if(0===c.length){var a=b();return a}return c.pop()},this.dispose=function(a){c.push(a)},this.warmup=function(a){for(var c=0;a>c;c++)b().onDispose();return this}};M.PoolOfObjects=ea;var fa=new ea(da).warmup(1024),ga=function(){this.$$components={},this.$$systems={}};ga.prototype.$name="",ga.prototype.$has=function(a){return c(this.$$components[a])||c(this.$$systems[a])},ga.prototype.$c=ga.prototype.$component=function(a,b){return b=b||{},b.$name=b.$name||a,this.$$components[a]=b,this},ga.prototype.$s=ga.prototype.$system=function(a,b){if(d(a))throw new Error("System name must to be defined.");if(b=b||{},b.$name=a,c(this.$$systems[a]))throw new Error('Module "'+this.$name+'" already has system with name "'+a+'".');return this.$$systems[a]=b,this};var ha=function(){this.$$init()};s(ha.prototype,U),ha.prototype.$name="",ha.prototype.$$updateHandler=null,ha.prototype.$$beforeUpdateHandler=null,ha.prototype.$$afterUpdateHandler=null,ha.prototype.$$addedHandler=null,ha.prototype.$$removedHandler=null,ha.prototype.$$addEntityHandler=null,ha.prototype.$$removeEntityHandler=null,ha.prototype.$$init=function(){this.$$setNodes(new ca)},ha.prototype.$$setNodes=function(a){this.$nodes&&(this.$nodes.off("add"),this.$nodes.off("remove")),this.$nodes=a;var b=this;this.$nodes&&(this.$nodes.on("add",function(a){b.$$addEntityHandler(a)}),this.$nodes.on("remove",function(a){b.$$removeEntityHandler(a)}))},ha.prototype.$$updateEveryNode=function(a,b){return function(c){this.$nodes.forEach(a,b,c)}};var ia=function(){this.$$injectedComponents={},this.$$injectedModules={},this.$$injectedSystems={},this.$$systems=[],this.$$beforeUpdateHandledSystems=[],this.$$afterUpdateHandledSystem=[],this.$$updateHandledSystem=[],this.$$families={},this.$$interval=1,this.$$updating=!1,this.$playing=!1,this.$entities=new ca("World"),this.$name=""};ia.prototype.$has=function(a){return c(this.$$injectedComponents[a])||c(this.$$injectedModules[a])||c(this.$$injectedSystems[a])},ia.prototype.$isUse=function(a){return a instanceof ha?this.$$systems.indexOf(a)>=0:null!==this.$$getSystemByName(a)},ia.prototype.$add=function(a,b){var c;return a instanceof ba?c=this.$$addEntity(a):a instanceof ha?this.$$addSystem(a):c=this.$system(a,b),c},ia.prototype.$$addEntity=function(a){return this.$entities.add(a),a.$$world=this,a.on("add",this.$$onComponentAdd,this),a.on("remove",this.$$onComponentRemove,this),this.$$matchNewEntityToFamilies(a),a},ia.prototype.$$removeEntity=function(a){return a.$$world=null,this.$entities.remove(a),this.$$matchRemoveEntityToFamilies(a),a.off("add",this.$$onComponentAdd),a.off("remove",this.$$onComponentRemove),a},ia.prototype.$$getDependencyByAnnotation=function(a,b){b=b||[];for(var c=0,d=a.length;d>c;c++){var e=a[c];b[c]=this.$$getDependencyByName(e)}return b},ia.prototype.$$getDependencyByName=function(a){switch(a){case"$world":return this}return this.$$getSystemByName(a)},ia.prototype.$$getSystemByName=function(a){for(var b=0,c=this.$$systems.length;c>b;b++)if(this.$$systems[b].$name===a)return this.$$systems[b];return null},ia.prototype.$remove=function(a){if(a instanceof ba)this.$$removeEntity(a);else{if(!(a instanceof ha))throw new Error("can't remove \""+a+'" from world "'+this.$name+'"');this.$$removeSystem(a)}},ia.prototype.$$addSystem=function(a){return this.$$systems.push(a),a.$$addedHandler(),c(a.$require)&&a.$$setNodes(this.$queryByComponents(a.$require)),a},ia.prototype.$$removeSystem=function(a){var b=this.$$systems.indexOf(a);return this.$$systems.splice(b,1),a.$nodes.forEach(a.$$removeEntityHandler,a),a.$$init(),a.$$removedHandler(),b=this.$$beforeUpdateHandledSystems.indexOf(a),b>=0&&this.$$beforeUpdateHandledSystems.splice(b,1),b=this.$$afterUpdateHandledSystem.indexOf(a),b>=0&&this.$$afterUpdateHandledSystem.splice(b,1),b=this.$$updateHandledSystem.indexOf(a),b>=0&&this.$$updateHandledSystem.splice(b,1),a},ia.prototype.$removeAllSystems=function(){var a,b=this.$$systems.length;for(a=0;b>a;a++){var c=this.$$systems[a];c.$nodes.forEach(c.$$removeEntityHandler,c),c.$$init()}for(a=0;b>a;a++)this.$$systems[a].$$removedHandler();this.$$systems.length=0,this.$$beforeUpdateHandledSystems.length=0,this.$$afterUpdateHandledSystem.length=0,this.$$updateHandledSystem.length=0},ia.prototype.$removeAllEntities=function(){for(var a=this.$entities.$head;a;){var b=a.instance,c=a.$next;this.$$removeEntity(b),a=c}},ia.prototype.$getByName=function(a){for(var b=this.$entities.$head;b;){var c=b.instance;if(c.$name===a)return c;b=b.$next}return null},ia.prototype.$numEntities=function(){return this.$entities.length()},ia.prototype.$e=ia.prototype.$entity=function(){var a="",b=0;g(arguments[0])&&(a=arguments[0],b=1);var h=new ba;if(h.$name=a,h.$$world=this,f(arguments[b])){var i=arguments[b];b++;for(var j=0,k=i.length;k>j;j++)if(g(i[j])){var l,m=i[j],n=this.$$injectedComponents[m];if(d(n))throw new Error("World "+this.$name+" doesn't has component "+m+". Only "+this.$$injectedComponents);e(i[j+1])?(j++,l=i[j]):l=null,h.$add(m,l)}}else if(e(arguments[b])){var o=arguments[b];b++,C(o,h),c(o.$name)&&(h.$name=o.$name)}return arguments[b]||this.$$addEntity(h),h},ia.prototype.$c=ia.prototype.$component=function(a,b){var e,f;if(!g(a))throw new Error("1st argument must be [String]");if(e=this.$$injectedComponents[a],d(e)){if(!c(b)||null===b)throw new Error("Can't find component \""+a+'" definition. You need to add appropriate module to world.');this.$$injectedComponents[a]=b,f=b}else f=k(e),c(b)&&null!==b&&r(f,b);return f.$name=a,f},ia.prototype.$$annotatedFunctionFactory=function(a,b,e){var g=a[b];if(d(g))return null;if(f(g)){e=e||q;var h=g[g.length-1];a[b]=h;var i=n(g),j=this.$$getDependencyByAnnotation(i),k=e(i);return c(k)?w(h,a,j,k,b):t(h,a,j,b)}return g},ia.prototype.$s=ia.prototype.$system=function(a,b){var e=this.$$injectedSystems[a];if(d(e)&&d(b))throw new Error('Instance of system "'+a+'" doesn\'t injected in the world "'+this.$name+'".');var g=new ha;if(c(e)?k(e,g,!1):g.$name=g.$name||a,c(b)&&k(b,g,!1),g.$$beforeUpdateHandler=this.$$annotatedFunctionFactory(g,"$beforeUpdate",G),g.$$beforeUpdateHandler&&this.$$beforeUpdateHandledSystems.push(g),g.$$afterUpdateHandler=this.$$annotatedFunctionFactory(g,"$afterUpdate",G),g.$$afterUpdateHandler&&this.$$afterUpdateHandledSystem.push(g),c(g.$update)){if(f(g.$update)){var h=g.$update,i=h[h.length-1],j=n(h);g.$$update=i;var l=this.$$getDependencyByAnnotation(j),m=F(j,"$entity"),o=F(j,"$entities"),p=F(j,"$time"),r=F(j,"$world"),s=this,u=t(i,g,l,"$$update"),v=j.indexOf("$entity")>=0;v?g.$$updateHandler=g.$$updateEveryNode(function(a,b){p(l,b),m(l,a),o(l,g.$nodes),r(l,s),u()}):g.$$updateHandler=function(a){p(l,a),o(l,g.$nodes),r(l,s),u()}}else g.$$updateHandler=g.$update;this.$$updateHandledSystem.push(g)}return c(g.$added)?g.$$addedHandler=this.$$annotatedFunctionFactory(g,"$added",q):g.$$addedHandler=q,c(g.$removed)?g.$$removedHandler=this.$$annotatedFunctionFactory(g,"$removed",q):g.$$removedHandler=q,c(g.$addEntity)?g.$$addEntityHandler=this.$$annotatedFunctionFactory(g,"$addEntity",H):g.$$addEntityHandler=q,c(g.$removeEntity)?g.$$removeEntityHandler=this.$$annotatedFunctionFactory(g,"$removeEntity",H):g.$$removeEntityHandler=q,this.$$addSystem(g),g},ia.prototype.$$matchNewEntityToFamilies=function(a){if(I(a,"matchNewEntityToFamilies",this,this.$$matchNewEntityToFamilies,arguments)){for(var b in this.$$families)this.$$matchNewEntityToFamily(b,a);J(a,"matchNewEntityToFamilies")}},ia.prototype.$$matchNewEntityToFamily=function(a,b){var c=this.$$families[a];c.newEntity(b)},ia.prototype.$$matchRemoveEntityToFamilies=function(a){if(I(a,"matchRemoveEntityToFamilies",this,this.$$matchRemoveEntityToFamilies,arguments)){for(var b in this.$$families)this.$$matchRemoveEntityToFamily(b,a);J(a,"matchRemoveEntityToFamilies")}},ia.prototype.$$matchRemoveEntityToFamily=function(a,b){var c=this.$$families[a];c.removeIfMatch(b)},ia.prototype.$$onComponentAdd=function(a,b){if(I(a,"onComponentAdd",this,this.$$onComponentAdd,arguments)){for(var c in this.$$families)this.$$mapAddedComponentToFamily(c,a);J(a,"onComponentAdd")}},ia.prototype.$$mapAddedComponentToFamily=function(a,b){var c=this.$$families[a];c.addIfMatch(b)},ia.prototype.$$onComponentRemove=function(a,b){for(var c in this.$$families)this.$$mapRemovedComponentToFamily(c,a,b)},ia.prototype.$$mapRemovedComponentToFamily=function(a,b,c){var d=this.$$families[a];d.removeIfMatch(b,c)},ia.prototype.$queryByComponents=function(a){var b,c,d={};if(f(a))c=a.join(","),b=a;else{if(!g(a))throw new Error("Can't query entities by "+a);c=a,b=a.split(",")}if(this.$$families[c])return this.$$families[c].nodes;for(var e=0,h=b.length;h>e;e++)d[b[e]]=!0;var i=new A;return i.components=b,i.componentsHash=d,i.componentsString=c,this.$$families[c]=i,this.$entities.forEach(function(a){i.newEntity(a)}),i.nodes},ia.prototype.$update=function(a){this.$$updating=!0,a=a||this.$$interval;var b,c,d;for(b=0,c=this.$$beforeUpdateHandledSystems.length;c>b;b++)d=this.$$beforeUpdateHandledSystems[b],d.$$beforeUpdateHandler(a,d.$nodes);for(b=0,c=this.$$updateHandledSystem.length;c>b;b++)d=this.$$updateHandledSystem[b],d.$$updateHandler(a);for(b=0,c=this.$$afterUpdateHandledSystem.length;c>b;b++)d=this.$$afterUpdateHandledSystem[b],d.$$afterUpdateHandler(a,d.$nodes);this.$$updating=!1},ia.prototype.$start=function(){if(!this.$playing){this.$playing=!0;var b=this,c=0;!function d(e){var f=0;c&&(f=e-c),b.$update(f),c=e,b.$playing&&(b.$requestAnimationFrameId=a.requestAnimationFrame(d))}(0)}},ia.prototype.$stop=function(){this.$playing&&(this.$playing=!1,a.cancelAnimationFrame(this.$requestAnimationFrameId))}}(window);