// 0.20.2 interpreter 2014-06-25T18:51:14 ed9ebcc362a059ef97f627a986f7fa2db56fa704 
/*
 * GameSalad, Inc.
 * http://gamesalad.com/
 *
 * Terms of Use: http://gamesalad.com/terms
 * Privacy Policy: http://gamesalad.com/privacy
 */
























































'use strict';
"use strict";(function(c){if(!c.console){c.console={}}var a=c.console;if(!a.log){a.log=function(d){}}if(!a.debug){a.debug=a.log}if(!a.info){a.info=a.log}if(!a.warn){a.warn=a.log}if(!a.error){a.error=a.log}if(!window.requestAnimationFrame){window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame;window.cancelAnimationFrame=window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame}try{c.Float32Array;if(!c.Float32Array){c.Float32Array=Array}}catch(b){c.Float32Array=WebGLFloatArray||Array}})(window);(function(b,a){b(["module"],function(c){var e,k,u,x,l,d;l=/^false$/i;x="WHEN_PARANOID";if(c&&typeof c.config==="function"){e=c.config().paranoid!==false}else{if(typeof process=="object"){e=!l.test(process.env[x])}else{if(typeof system=="object"){e=!l.test(system.env[x])}else{e=!(a&&a.when_config&&a.when_config.paranoid===false)}}}e=(e&&Object.freeze)||z;m.defer=g;m.resolve=v;m.reject=j;m.all=f;m.some=p;m.any=q;m.map=y;m.reduce=o;m.chain=s;m.isPromise=r;function m(B,D,C,A){return v(B).then(D,C,A)}function v(A){var C,B;if(A instanceof h){C=A}else{if(A!=null&&typeof A.valueOf==="function"){A=A.valueOf()}if(r(A)){B=g();A.then(B.resolve,B.reject,B.progress);C=B.promise}else{C=t(A)}}return C}function j(A){return m(A,function(B){return w(B)})}function h(A){this.then=A}h.prototype=e({always:function(A,B){return this.then(A,A,B)},otherwise:function(A){return this.then(d,A)}});function t(A){var B=new h(function(D){try{return v(D?D(A):A)}catch(C){return w(C)}});return e(B)}function w(B){var A=new h(function(E,C){try{return C?v(C(B)):w(B)}catch(D){return w(D)}});return e(A)}function g(){var J,K,G,E,C,B,H;K=new h(F);J={then:F,resolve:D,reject:I,progress:A,promise:e(K),resolver:e({resolve:D,reject:I,progress:A})};G=[];E=[];C=function(O,M,N){var L=g();G.push(function(P){P.then(O,M).then(L.resolve,L.reject,L.progress)});N&&E.push(N);return L.promise};B=function(N){var L,M=0;while(L=E[M++]){L(N)}};H=function(M){var N,L=0;M=v(M);C=M.then;H=v;B=i;while(N=G[L++]){N(M)}E=G=d;return M};return J;function F(N,L,M){return C(N,L,M)}function D(L){return H(L)}function I(L){return H(w(L))}function A(L){B(L)}}function r(A){return A&&typeof A.then==="function"}function p(D,C,E,B,A){n(2,arguments);return m(D,function(G){var K,I,M,L,N,F,J,H;J=G.length>>>0;K=Math.max(0,Math.min(C,J));I=[];M=g();if(!K){M.resolve(I)}else{N=M.reject;F=M.progress;L=function(O){I.push(O);if(!--K){L=i;M.resolve(I)}};for(H=0;H<J;++H){if(H in G){m(G[H],L,N,F)}}}return M.then(E,B,A)})}function f(C,D,B,A){n(1,arguments);return y(C,z).then(D,B,A)}function q(C,E,B,A){function D(F){return E?E(F[0]):F[0]}return p(C,1,D,B,A)}function y(B,A){return m(B,function(G){var D,F,I,J,K,E,H;I=F=G.length>>>0;D=[];H=g();if(!I){H.resolve(D)}else{K=H.reject;J=function C(M,L){m(M,A).then(function(N){D[L]=N;if(!--I){H.resolve(D)}},K)};for(E=0;E<F;E++){if(E in G){J(G[E],E)}else{--I}}}return H.promise})}function o(C,B){var A=u.call(arguments,1);return m(C,function(E){var D;D=E.length;A[0]=function(G,H,F){return m(G,function(I){return m(H,function(J){return B(I,J,F,D)})})};return k.apply(E,A)})}function s(A,D,C){var B=arguments.length>2;return m(A,function(E){return D.resolve(B?C:E)},D.reject,D.progress)}function n(D,C){var A,B=C.length;while(B>D){A=C[--B];if(A!=null&&typeof A!="function"){throw new Error("arg "+B+" must be a function")}}}function i(){}u=[].slice;k=[].reduce||function(F){var B,D,C,A,E;E=0;B=Object(this);A=B.length>>>0;D=arguments;if(D.length<=1){for(;;){if(E in B){C=B[E++];break}if(++E>=A){throw new TypeError()}}}else{C=D[1]}for(;E<A;++E){if(E in B){C=F(C,B[E],E,B)}}return C};function z(A){return A}return m})})(typeof define=="function"&&define.amd?define:function(b,a){typeof exports==="object"?(module.exports=a()):(window.when=a())},this);(function(b){function k(q,p){return(q<<p)|(q>>>(32-p))}function f(t,q){var v,p,s,u,r;s=(t&2147483648);u=(q&2147483648);v=(t&1073741824);p=(q&1073741824);r=(t&1073741823)+(q&1073741823);if(v&p){return(r^2147483648^s^u)}if(v|p){if(r&1073741824){return(r^3221225472^s^u)}else{return(r^1073741824^s^u)}}else{return(r^s^u)}}function o(p,r,q){return(p&r)|((~p)&q)}function n(p,r,q){return(p&q)|(r&(~q))}function j(p,r,q){return(p^r^q)}function i(p,r,q){return(r^(p|(~q)))}function c(r,q,w,v,p,t,u){r=f(r,f(f(o(q,w,v),p),u));return f(k(r,t),q)}function m(r,q,w,v,p,t,u){r=f(r,f(f(n(q,w,v),p),u));return f(k(r,t),q)}function e(r,q,w,v,p,t,u){r=f(r,f(f(j(q,w,v),p),u));return f(k(r,t),q)}function a(r,q,w,v,p,t,u){r=f(r,f(f(i(q,w,v),p),u));return f(k(r,t),q)}function g(t){var w;var s=t.length;var r=s+8;var q=(r-(r%64))/64;var v=(q+1)*16;var x=new Array(v-1);var p=0;var u=0;while(u<s){w=(u-(u%4))/4;p=(u%4)*8;x[w]=(x[w]|(t.charCodeAt(u)<<p));u++}w=(u-(u%4))/4;p=(u%4)*8;x[w]=x[w]|(128<<p);x[v-2]=s<<3;x[v-1]=s>>>29;return x}function d(r){var q="",s="",t,p;for(p=0;p<=3;p++){t=(r>>>(p*8))&255;s="0"+t.toString(16);q=q+s.substr(s.length-2,2)}return q}function l(q){q=q.replace(/\r\n/g,"\n");var p="";for(var s=0;s<q.length;s++){var r=q.charCodeAt(s);if(r<128){p+=String.fromCharCode(r)}else{if((r>127)&&(r<2048)){p+=String.fromCharCode((r>>6)|192);p+=String.fromCharCode((r&63)|128)}else{p+=String.fromCharCode((r>>12)|224);p+=String.fromCharCode(((r>>6)&63)|128);p+=String.fromCharCode((r&63)|128)}}}return p}function h(p){var H,v,G,R,u,Q,P,N,L;var E=7,C=12,A=17,y=22;var O=5,M=9,J=14,I=20;var t=4,s=11,r=16,q=23;var F=6,D=10,B=15,z=21;p=l(p);var w=g(p);Q=1732584193;P=4023233417;N=2562383102;L=271733878;for(H=0;H<w.length;H+=16){v=Q;G=P;R=N;u=L;Q=c(Q,P,N,L,w[H+0],E,3614090360);L=c(L,Q,P,N,w[H+1],C,3905402710);N=c(N,L,Q,P,w[H+2],A,606105819);P=c(P,N,L,Q,w[H+3],y,3250441966);Q=c(Q,P,N,L,w[H+4],E,4118548399);L=c(L,Q,P,N,w[H+5],C,1200080426);N=c(N,L,Q,P,w[H+6],A,2821735955);P=c(P,N,L,Q,w[H+7],y,4249261313);Q=c(Q,P,N,L,w[H+8],E,1770035416);L=c(L,Q,P,N,w[H+9],C,2336552879);N=c(N,L,Q,P,w[H+10],A,4294925233);P=c(P,N,L,Q,w[H+11],y,2304563134);Q=c(Q,P,N,L,w[H+12],E,1804603682);L=c(L,Q,P,N,w[H+13],C,4254626195);N=c(N,L,Q,P,w[H+14],A,2792965006);P=c(P,N,L,Q,w[H+15],y,1236535329);Q=m(Q,P,N,L,w[H+1],O,4129170786);L=m(L,Q,P,N,w[H+6],M,3225465664);N=m(N,L,Q,P,w[H+11],J,643717713);P=m(P,N,L,Q,w[H+0],I,3921069994);Q=m(Q,P,N,L,w[H+5],O,3593408605);L=m(L,Q,P,N,w[H+10],M,38016083);N=m(N,L,Q,P,w[H+15],J,3634488961);P=m(P,N,L,Q,w[H+4],I,3889429448);Q=m(Q,P,N,L,w[H+9],O,568446438);L=m(L,Q,P,N,w[H+14],M,3275163606);N=m(N,L,Q,P,w[H+3],J,4107603335);P=m(P,N,L,Q,w[H+8],I,1163531501);Q=m(Q,P,N,L,w[H+13],O,2850285829);L=m(L,Q,P,N,w[H+2],M,4243563512);N=m(N,L,Q,P,w[H+7],J,1735328473);P=m(P,N,L,Q,w[H+12],I,2368359562);Q=e(Q,P,N,L,w[H+5],t,4294588738);L=e(L,Q,P,N,w[H+8],s,2272392833);N=e(N,L,Q,P,w[H+11],r,1839030562);P=e(P,N,L,Q,w[H+14],q,4259657740);Q=e(Q,P,N,L,w[H+1],t,2763975236);L=e(L,Q,P,N,w[H+4],s,1272893353);N=e(N,L,Q,P,w[H+7],r,4139469664);P=e(P,N,L,Q,w[H+10],q,3200236656);Q=e(Q,P,N,L,w[H+13],t,681279174);L=e(L,Q,P,N,w[H+0],s,3936430074);N=e(N,L,Q,P,w[H+3],r,3572445317);P=e(P,N,L,Q,w[H+6],q,76029189);Q=e(Q,P,N,L,w[H+9],t,3654602809);L=e(L,Q,P,N,w[H+12],s,3873151461);N=e(N,L,Q,P,w[H+15],r,530742520);P=e(P,N,L,Q,w[H+2],q,3299628645);Q=a(Q,P,N,L,w[H+0],F,4096336452);L=a(L,Q,P,N,w[H+7],D,1126891415);N=a(N,L,Q,P,w[H+14],B,2878612391);P=a(P,N,L,Q,w[H+5],z,4237533241);Q=a(Q,P,N,L,w[H+12],F,1700485571);L=a(L,Q,P,N,w[H+3],D,2399980690);N=a(N,L,Q,P,w[H+10],B,4293915773);P=a(P,N,L,Q,w[H+1],z,2240044497);Q=a(Q,P,N,L,w[H+8],F,1873313359);L=a(L,Q,P,N,w[H+15],D,4264355552);N=a(N,L,Q,P,w[H+6],B,2734768916);P=a(P,N,L,Q,w[H+13],z,1309151649);Q=a(Q,P,N,L,w[H+4],F,4149444226);L=a(L,Q,P,N,w[H+11],D,3174756917);N=a(N,L,Q,P,w[H+2],B,718787259);P=a(P,N,L,Q,w[H+9],z,3951481745);Q=f(Q,v);P=f(P,G);N=f(N,R);L=f(L,u)}var K=d(Q)+d(P)+d(N)+d(L);return K.toLowerCase()}b.MD5=h})(window);var gs=gs||{};var gse=gs;var pgf=pgf||{};gs.debug={fps:false,profile:false,log:true,evaluate:true,physics:true,physicsHiFi:true,render:true,renderTextures:true,renderFlush:false,particles:true,text:true,audio:true};gs.globalOptions={useBehaviorStubs:false,uploadAnalytics:false,useDynamicOverlayLayer:false,actorPrototypeBatchSize:64,imageRequestPoolSize:8,audioPoolSize:8,spoofIOSScreenSize:true,forceViewportOrientationMatch:false,forceTexturePrimeFrames:false,forcePointerEvents:false,forceInputEventsOnCanvas:false};gs.subclass=function(b,a){for(var c in a){var d=a[c];a[c]={value:d,enumerable:false}}return Object.create(b.prototype,a)};gs.inherits=function(a,d){var c=a.prototype;for(var b in c){var e=c[b];c[b]={enumerable:false,value:e}}c.__class={enumerable:false,value:a};c.__superclass={enumerable:false,value:d};c.__super={enumerable:false,value:d.prototype};Object.defineProperty(a,"__class",c.__class);Object.defineProperty(a,"__superclass",c.__superclass);Object.defineProperty(a,"__super",c.__super);Object.defineProperty(a,"subclass",{enumerable:false,value:function(f,g){var h=function(){a.call(this)};h.prototype=g||{};gs.inherits(h,a);return h}});for(var b in gs){if(gs[b]===a){c.__classname={enumerable:false,value:b};Object.defineProperty(a,"__classname",c.__classname);break}}a.prototype=Object.create(d.prototype,c);if(!a.provide){a.provide=function(){return new a()}}};gs.singleton=function(a){Object.defineProperty(a,"__singleton",{enumerable:false,value:new a()});Object.defineProperty(a,"provide",{enumerable:false,value:function(){return a.__singleton}})};gs.getSystemTime=function(){return Date.now()/1000};gs.encodeURL=function(a){var b=a.lastIndexOf("/");return a.substring(0,b+1)+encodeURIComponent(a.substring(b+1,a.length))};gs.parseBoolean=function(a){if(typeof a==="boolean"){return a}if(typeof a==="string"){return a.toLowerCase()==="true"}return false};gs.parseInteger=function(a){return parseInt(a,10)};gs.TIME_STEP_MS=16;gs.TIME_STEP_S=gs.TIME_STEP_MS/1000;gs.FRAMERATE_FPS=1000/gs.TIME_STEP_MS;gs.g_tempVec2d=[0,0];gs.minAllowedUpdateTimestepMS=gs.TIME_STEP_MS/4;gs.keyMap={"38":"up","40":"down","37":"left","39":"right","32":"space","9":"tab","13":"return","27":"esc","8":"delete","46":"delete"};gs.mapKeyInput=function(b){var a=gs.keyMap[b.keyCode];if(a){return a}return String.fromCharCode(b.keyCode)};gs.getEngineContext=function(){return gs.EngineContext.current};gs.ready=function(b){var a=gs.EngineContext.instance();b&&b.call(null,a)};gs._yield=function(d){var c=10;var b=new gs.Promise();window.setTimeout(function a(){d&&d.call(null);b.resolve()},c);return b};gs.pause=function(){gs.EngineContext.current.pause()};gs.unpause=function(){gs.EngineContext.current.unpause()};gs.suspend=function(){gs.EngineContext.current.suspend()};gs.unsuspend=function(){gs.EngineContext.current.unsuspend()};gs.postEvent=function(a){var d=gs.Game.current.eventCenter;var b=gs.array.provide();b[0]=a;b[1]=null;for(var c=1;c<arguments.length;c++){b.push(arguments[c])}return d.postEvent.apply(d,b)};gs.ready=gs.ready;gs._yield=gs._yield;gs.pause=gs.pause;gs.unpause=gs.unpause;gs.suspend=gs.suspend;gs.unsuspend=gs.unsuspend;gs.postEvent=gs.postEvent;gs.analytics=gs.analytics||{};gs.api=gs.api||{};gs.Log={level:0,delegate:null,LogLevel:{ALL:7,DEBUG:6,INFO:5,WARN:4,STRICT:3,ERROR:2,FATAL:1,OFF:0},strings:{DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",STRICT:"STRICT",ERROR:"ERROR",FATAL:"FATAL"},write:function(g,f,a){try{var e="";var d=a.length;if(f){e=f+":";while(e.length<8){e+=" "}}if(d>0){e+=a[0]}for(var c=1;c<d;c++){e+=" "+a[c]}if(typeof g==="function"){g.call(console,e)}else{console.log(e)}if(this.delegate){this.delegate.onLogAll(e)}if(f==gs.Log.strings.FATAL){alert(e)}}catch(b){}},writeIf:function(d,c,b,a){if(gs.Log.level>=d){gs.Log.write(c,b,a)}},debug:function(){gs.Log.writeIf(gs.Log.LogLevel.DEBUG,console.debug,this.strings.DEBUG,arguments)},info:function(){gs.Log.writeIf(gs.Log.LogLevel.INFO,console.log,gs.Log.strings.INFO,arguments)},warn:function(){gs.Log.writeIf(gs.Log.LogLevel.WARN,console.warn,gs.Log.strings.WARN,arguments)},strict:function(){gs.Log.writeIf(gs.Log.LogLevel.STRICT,console.warn,gs.Log.strings.STRICT,arguments)},error:function(){gs.Log.writeIf(gs.Log.LogLevel.ERROR,console.error,gs.Log.strings.ERROR,arguments)},fatal:function(){gs.Log.writeIf(gs.Log.LogLevel.FATAL,console.error,gs.Log.strings.FATAL,arguments)},print:function(){gs.Log.write(console.log,null,arguments)}};gs.level=gs.Log.LogLevel.OFF;gs.util={getSecondsSinceUnixEpoch:function(){return Math.floor(Date.now()/1000)},randomInteger:function(a){return Math.floor(Math.random()*a)},randomIntegerRange:function(a,b){return Math.floor(a+Math.random()*(a-b))},pickRandomCharacter:function(a){var b=gs.util.randomInteger(a.length);return a.charAt(b)},generateRandomHexString:function(d){var c="";var a="0123456789abcdef";for(var b=0;b<d;b++){c+=gs.util.pickRandomCharacter(a)}return c},generateUUID:function(){var a="";a+=gs.util.generateRandomHexString(8);a+="-";a+=gs.util.generateRandomHexString(4);a+="-4";a+=gs.util.generateRandomHexString(3);a+="-"+gs.util.pickRandomCharacter("89ab");a+=gs.util.generateRandomHexString(3);a+="-";a+=gs.util.generateRandomHexString(12);return a},reverseMap:function(c){var d={};for(var a in c){var b=c[a];d[b]=a}return d},createObfuscationLookup:function(a){return gs.util.reverseMap(a)},createMapFromURLString:function(b,a){var d={};var e=b.indexOf("?")+1;if(e===0){e=b.indexOf("#")+1}if(b.length>e){var c=b.substring(e).split("&");c.forEach(function(g){var h=g.split("=");if(h.length===1){d[a]=h[0]}else{var f=h[0];if(/^gse-/.test(f)){f=f.substr(4)}d[f]=h[1]}})}return d},lazySingleton:function(a){if(!a.lazySingleton){a.lazySingleton=new a()}return a.lazySingleton}};gs.Promise=function(){this.deferred=when.defer()};gs.Promise.all=when.all;gs.Promise.prototype={then:function(c,b,a){return this.deferred.promise.then(c,b,a)},always:function(a,b){return this.then(a,a,b)},otherwise:function(a){return this.then(undefined,a)},resolve:function(a){return this.deferred.resolve(a)},reject:function(a){return this.deferred.reject(a)}};gs.Promise=gs.Promise;gs.dom={nodes:{CANVAS:"CANVAS",IMAGE:"IMG",AUDIO:"AUDIO"},getElement:function(a){if(typeof a==="string"){return document.getElementById(a)}else{return a}},resizeElement:function(b,c,a){b.style.width=c+"px";b.style.height=a+"px"},repositionElement:function(a,c,b){a.style.left=c+"px";a.style.top=b+"px"},getComputedStyle:function(a){return window.getComputedStyle(a)},getElementPosition:function(b){var a=0;var c=0;for(;b;b=b.offsetParent){a+=b.offsetLeft;c+=b.offsetTop}return[a,c]},setElementVisible:function(a,b){a.style.visibility=b?"visible":"hidden"},create:function(a){return document.createElement(a)},createFragment:function(){return document.createDocumentFragment()},createCanvas:function(){return gs.dom.create(gs.dom.nodes.CANVAS)},createImage:function(b){var a=gs.dom.create(gs.dom.nodes.IMAGE);if(b){a.src=b}return a},createAudio:function(){return gs.dom.create(gs.dom.nodes.AUDIO)}};gs.math={DEG2RAD:Math.PI/180,RAD2DEG:180/Math.PI,equalityEpsilon:0.1,clampf:function(a,b,c){a=(a!=null)?a:0;b=(b!=null)?b:0;c=(c!=null)?c:1;return Math.min(Math.max(a,b),c)},numberEquals:function(b,a){return(Math.abs(b-a)<gs.math.equalityEpsilon)}};var gsMath=gs.math;gs.Pool={allConstructors:[],init:function(b){var a=b;a._recyclePool=[];a._recyclePoolSize=0;gs.Pool.allConstructors.push(a);a.provide=function(){if(a._recyclePoolSize>0){var c=a._recyclePool[--a._recyclePoolSize];a.call(c);return c}return new b()};a.recycle=function(c){a._recyclePool[a._recyclePoolSize++]=c};a.primePool=function(d){if(a._recyclePoolSize<d){for(var c=a._recyclePoolSize;c<d;c++){a.recycle(new b())}}}},debugReport:function(){for(var b=0;b<gs.Pool.allConstructors.length;b++){var d=gs.Pool.allConstructors[b];if(d._recyclePoolSize>0){var a=gs.getTypeName(d._recyclePool[0]);if(a){gs.Pool.debugLine(d,a)}}}},debugLine:function(a,b){gs.Log.debug(a._recyclePoolSize,b)}};gs.array={insert:function(c,a,b){c.splice(a,0,b)},remove:function(d,a,c){c=c||1;var b=d[a];d.splice(a,c);return b},_pool:[],provide:function(){if(gs.array._pool.length>0){return Array.prototype.pop.call(gs.array._pool)}return[]},recycle:function(a){a.length=0;this._pool[this._pool.length]=a},primePool:function(b){if(this._pool.length<b){for(var a=this._pool.length;a<b;a++){this._pool[a]=[]}}},recycleJXONTree:function(c){if(Array.isArray(c)){for(var b=0;b<c.length;b++){gs.array.recycleJXONTree(c[b])}gs.array.recycle(c)}else{if(typeof c==="object"){for(var a in c){if(Array.isArray(c[a])){gs.array.recycleJXONTree(c[a]);delete c[a]}else{if(typeof c[a]==="object"){gs.array.recycleJXONTree(c[a])}}}}}},recycleJXONArraysAndMaps:function(c){if(Array.isArray(c)){for(var b=0;b<c.length;b++){gs.array.recycleJXONArraysAndMaps(c[b])}gs.array.recycle(c)}else{if(typeof c==="object"){for(var a in c){if(Array.isArray(c[a])){gs.array.recycleJXONArraysAndMaps(c[a])}else{if(typeof c[a]==="object"){gs.array.recycleJXONArraysAndMaps(c[a])}}}gs.Map.recycle(c)}}},recyclePrototypicalTree:function(d){if(Array.isArray(d._children)){var c=d._children;for(var b=0,a=c.length;b<a;b++){gs.array.recyclePrototypicalTree(c[b])}d.recycleArrays()}}};gs.Map={_pool:[],_poolMaxSize:128,provide:function(){if(this._pool.length>0){return this._pool.pop()}return{}},recycle:function(b){if(this._pool.length<this._poolMaxSize){for(var a in b){delete b[a]}this._pool[this._pool.length]=b}}};gs.MultiSet=function(){this.size=0};gs.MultiSet.prototype={addObject:function(a){if(a in this){this[a]++}else{this[a]=1}this.size++},countOfObject:function(a){return(a in this)?this[a]:0},removeObject:function(a){if(a in this){this[a]--;this.size--}}};gs.set={setWithObjects:function(a){var c={};for(var b in a){c[b]=true}return c},arrayToSet:function(d){var c={};var a=d.length;for(var b=0;b<a;++b){c[d[b]]=true}return c},setToArray:function(b){var a=gs.array.provide();for(var c in b){a.push(c)}return a},unionSet:function(a,d){var c={};var b;for(b in a){c[b]=a[b]}for(b in d){c[b]=d[b]}return c}};gs.sparseArray={addItem:function(c){var a=this.holes;var b;if(a.length){b=a.pop()}else{b=this.n;this.n=b+1}this[b]=c;return b},removeItemAtIndex:function(b){this[b]=null;var a=this.holes;a.push(b)},create:function(){var a=[];a.n=0;a.holes=[];a.addItem=gs.sparseArray.addItem;a.removeItemAtIndex=gs.sparseArray.removeItemAtIndex;return a}};String.prototype.endsWith=function(a){return this.indexOf(a,this.length-a.length)!==-1};String.prototype.trim=function(){return this.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")};String.prototype.pathExtension=function(){var a=this.split(".");return a[a.length-1]};gs.string={safe:function(a){return(typeof a==="string")?a:""},safeLowerCase:function(a){if(typeof a==="string"){return a.toLowerCase()}return""},beginsWith:function(b,a){return b.indexOf(a)===0},endsWith:function(b,a){return b.indexOf(a,b.length-a.length)!==-1},contains:function(b,a){return b.indexOf(a)!==-1}};gs.Vector2=function(){this.x=0;this.y=0};gs.Pool.init(gs.Vector2);gs.Vector2.ZERO_VECTOR=[0,0];gs.Vector2.EPSILON=5;gs.Vector2.X_COMPONENT=0;gs.Vector2.Y_COMPONENT=1;gs.Vector2.vectorRotate2D=function(b,c,e){var a=c[0];var g=c[1];var d=Math.cos(e);var f=Math.sin(e);b[0]=(a*d-g*f);b[1]=(a*f+g*d)};gs.Vector2.equals=function(b,a,c){return Math.abs(b[0]-a[0])<=c&&Math.abs(b[1]-a[1])<=c};gs.Rect={};gs.Rect.pointInRect=function(b,g,c){var a=c.x;var f=c.y;var e=a+c.width;var d=f+c.height;return(b>a&&b<e&&g>f&&g<d)};gs.Rect.nearestPointInRect=function(c,b,h,d){c[0]=d.x+(d.width*0.5);c[1]=d.y+(d.height*0.5);if(d.width>0){var a=d.x;var f=a+d.width;c[0]=gsMath.clampf(b,a,f)}if(d.height>0){var g=d.y;var e=g+d.height;c[1]=gsMath.clampf(h,g,e)}return c};var Box2D=Box2D||{Collision:{Shapes:{}},Common:{Math:{}},Consts:{},Dynamics:{Contacts:{},Controllers:{},Joints:{}}};var UsageTracker={map:{},get:function(a){if(!this.map[a]){this.map[a]={trackCreate:function(){console.log("create",a)},trackGet:function(){},trackFree:function(){}}}return this.map[a]}};Box2D.generateCallback=function(a,b){return function(){b.apply(a,arguments)}};Box2D.abstractMethod=function(){throw Error("unimplemented abstract method")};Box2D.inherits=function(b,a){function c(){}c.prototype=a.prototype;b.superClass_=a.prototype;b.prototype=new c();b.prototype.constructor=b};Box2D.Array={};Box2D.Array.remove=function(c,b){var a=c.indexOf(b);c.splice(a,1)};Box2D.Array._freeCache=[];Box2D.Array.Get=function(){return gs.array.provide()};Box2D.Array.Free=function(a){if(a!=null){gs.array.recycle(a)}};Box2D.Consts.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;Box2D.Common.b2Color=function(b,a,c){this._r=255*Box2D.Common.Math.b2Math.Clamp(b,0,1);this._g=255*Box2D.Common.Math.b2Math.Clamp(a,0,1);this._b=255*Box2D.Common.Math.b2Math.Clamp(c,0,1)};Box2D.Common.b2Color.prototype.Set=function(b,a,c){this._r=255*Box2D.Common.Math.b2Math.Clamp(b,0,1);this._g=255*Box2D.Common.Math.b2Math.Clamp(a,0,1);this._b=255*Box2D.Common.Math.b2Math.Clamp(c,0,1)};Box2D.Common.b2Color.prototype.GetColor=function(){return(this._r<<16)|(this._g<<8)|(this._b)};Box2D.Common.b2Settings={};Box2D.Common.b2Settings.b2MixFriction=function(b,a){return Math.sqrt(b*a)};Box2D.Common.b2Settings.b2MixRestitution=function(a,b){return a>b?a:b};Box2D.Common.b2Settings.b2Assert=function(b){if(!b){throw"Assertion Failed"}};Box2D.Common.b2Settings.VERSION="2.1alpha-illandril";Box2D.Common.b2Settings.USHRT_MAX=65535;Box2D.Common.b2Settings.b2_maxManifoldPoints=2;Box2D.Common.b2Settings.b2_aabbExtension=0.1;Box2D.Common.b2Settings.b2_aabbMultiplier=2;Box2D.Common.b2Settings.b2_polygonRadius=2*Box2D.Common.b2Settings.b2_linearSlop;Box2D.Common.b2Settings.b2_linearSlop=0.005;Box2D.Common.b2Settings.b2_angularSlop=2/180*Math.PI;Box2D.Common.b2Settings.b2_toiSlop=8*Box2D.Common.b2Settings.b2_linearSlop;Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland=32;Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland=32;Box2D.Common.b2Settings.b2_velocityThreshold=1;Box2D.Common.b2Settings.b2_maxLinearCorrection=0.2;Box2D.Common.b2Settings.b2_maxAngularCorrection=8/180*Math.PI;Box2D.Common.b2Settings.b2_maxTranslation=2;Box2D.Common.b2Settings.b2_maxTranslationSquared=Box2D.Common.b2Settings.b2_maxTranslation*Box2D.Common.b2Settings.b2_maxTranslation;Box2D.Common.b2Settings.b2_maxRotation=0.5*Math.PI;Box2D.Common.b2Settings.b2_maxRotationSquared=Box2D.Common.b2Settings.b2_maxRotation*Box2D.Common.b2Settings.b2_maxRotation;Box2D.Common.b2Settings.b2_contactBaumgarte=0.2;Box2D.Common.b2Settings.b2_timeToSleep=0.5;Box2D.Common.b2Settings.b2_linearSleepTolerance=0.01;Box2D.Common.b2Settings.b2_linearSleepToleranceSquared=Box2D.Common.b2Settings.b2_linearSleepTolerance*Box2D.Common.b2Settings.b2_linearSleepTolerance;Box2D.Common.b2Settings.b2_angularSleepTolerance=2/180*Math.PI;Box2D.Common.b2Settings.b2_angularSleepToleranceSquared=Box2D.Common.b2Settings.b2_angularSleepTolerance*Box2D.Common.b2Settings.b2_angularSleepTolerance;Box2D.Common.b2Settings.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;var __b2Vec2=function(a,b){this.x=a;this.y=b;this.__nextPooledObject=null};Box2D.Common.Math.b2Vec2=__b2Vec2;var __b2Vec2_FirstPooledObject;var b2Vec2Get=function(a,c){if(__b2Vec2_FirstPooledObject!=null){var b=__b2Vec2_FirstPooledObject;__b2Vec2_FirstPooledObject=b.__nextPooledObject;b.x=a;b.y=c;b.__nextPooledObject=null;return b}return new __b2Vec2(a,c)};__b2Vec2.Get=b2Vec2Get;var b2Vec2Free=function(a){if(a!=null){a.__nextPooledObject=__b2Vec2_FirstPooledObject;__b2Vec2_FirstPooledObject=a}};__b2Vec2.Free=b2Vec2Free;__b2Vec2.prototype.SetZero=function(){this.x=0;this.y=0};__b2Vec2.prototype.Set=function(a,b){this.x=a;this.y=b};__b2Vec2.prototype.SetV=function(a){this.x=a.x;this.y=a.y};__b2Vec2.prototype.GetNegative=function(){return __b2Vec2.Get((-this.x),(-this.y))};__b2Vec2.prototype.NegativeSelf=function(){this.x=(-this.x);this.y=(-this.y)};__b2Vec2.prototype.Copy=function(){return __b2Vec2.Get(this.x,this.y)};__b2Vec2.prototype.Add=function(a){this.x+=a.x;this.y+=a.y};__b2Vec2.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y};__b2Vec2.prototype.Multiply=function(b){this.x*=b;this.y*=b};__b2Vec2.prototype.MulM=function(b){var a=this.x;this.x=b.col1.x*a+b.col2.x*this.y;this.y=b.col1.y*a+b.col2.y*this.y};__b2Vec2.prototype.MulTM=function(b){var a=this.x*b.col1.x+this.y*b.col1.y;this.y=this.x*b.col2.x+this.y*b.col2.y;this.x=a};__b2Vec2.prototype.CrossVF=function(b){var a=this.x;this.x=b*this.y;this.y=(-b*a)};__b2Vec2.prototype.CrossFV=function(b){var a=this.x;this.x=(-b*this.y);this.y=b*a};__b2Vec2.prototype.MinV=function(a){this.x=Math.min(this.x,a.x);this.y=Math.min(this.y,a.y)};__b2Vec2.prototype.MaxV=function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y)};__b2Vec2.prototype.Abs=function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y)};__b2Vec2.prototype.Length=function(){return Math.sqrt(this.LengthSquared())};__b2Vec2.prototype.LengthSquared=function(){return(this.x*this.x+this.y*this.y)};__b2Vec2.prototype.Normalize=function(){var b=this.Length();if(b<Number.MIN_VALUE){return 0}var a=1/b;this.x*=a;this.y*=a;return b};__b2Vec2.prototype.IsValid=function(){return isFinite(this.x)&&isFinite(this.y)};Box2D.Common.Math.b2Vec3=function(a,c,b){this.x=a;this.y=c;this.z=b};Box2D.Common.Math.b2Vec3._freeCache=[];Box2D.Common.Math.b2Vec3.Get=function(a,d,c){if(Box2D.Common.Math.b2Vec3._freeCache.length>0){var b=Box2D.Common.Math.b2Vec3._freeCache.pop();b.Set(a,d,c);return b}return new Box2D.Common.Math.b2Vec3(a,d,c)};Box2D.Common.Math.b2Vec3.Free=function(a){if(a!=null){Box2D.Common.Math.b2Vec3._freeCache.push(a)}};Box2D.Common.Math.b2Vec3.prototype.SetZero=function(){this.x=0;this.y=0;this.z=0};Box2D.Common.Math.b2Vec3.prototype.Set=function(a,c,b){this.x=a;this.y=c;this.z=b};Box2D.Common.Math.b2Vec3.prototype.SetV=function(a){this.x=a.x;this.y=a.y;this.z=a.z};Box2D.Common.Math.b2Vec3.prototype.GetNegative=function(){return Box2D.Common.Math.b2Vec3.Get((-this.x),(-this.y),(-this.z))};Box2D.Common.Math.b2Vec3.prototype.NegativeSelf=function(){this.x=(-this.x);this.y=(-this.y);this.z=(-this.z)};Box2D.Common.Math.b2Vec3.prototype.Copy=function(){return Box2D.Common.Math.b2Vec3.Get(this.x,this.y,this.z)};Box2D.Common.Math.b2Vec3.prototype.Add=function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z};Box2D.Common.Math.b2Vec3.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z};Box2D.Common.Math.b2Vec3.prototype.Multiply=function(b){this.x*=b;this.y*=b;this.z*=b};Box2D.Common.Math.b2Mat22=function(){this.col1=b2Vec2Get(1,0);this.col2=b2Vec2Get(0,1)};Box2D.Common.Math.b2Mat22._freeCache=[];var b2Mat22GetUninitialized=function(){if(Box2D.Common.Math.b2Mat22._freeCache.length>0){return Box2D.Common.Math.b2Mat22._freeCache.pop()}else{return new Box2D.Common.Math.b2Mat22()}};Box2D.Common.Math.b2Mat22.Get=function(){if(Box2D.Common.Math.b2Mat22._freeCache.length>0){var a=Box2D.Common.Math.b2Mat22._freeCache.pop();a.SetIdentity();return a}return new Box2D.Common.Math.b2Mat22()};var b2Mat22GetAndInit=function(c,b,e,d){var a=b2Mat22GetUninitialized();var g=a.col1;var f=a.col2;g.x=c;g.y=b;f.x=e;f.y=d;return a};Box2D.Common.Math.b2Mat22.Free=function(a){if(a!=null){Box2D.Common.Math.b2Mat22._freeCache.push(a)}};Box2D.Common.Math.b2Mat22.FromAngle=function(b){var a=Box2D.Common.Math.b2Mat22.Get();a.Set(b);return a};Box2D.Common.Math.b2Mat22.FromVV=function(c,b){var a=Box2D.Common.Math.b2Mat22.Get();a.SetVV(c,b);return a};Box2D.Common.Math.b2Mat22.prototype.Set=function(e){var f=Math.cos(e);var a=Math.sin(e);var d=this.col1;d.x=f;d.y=a;var b=this.col2;b.x=-a;b.y=f};Box2D.Common.Math.b2Mat22.prototype.SetVV=function(b,a){this.col1.SetV(b);this.col2.SetV(a)};Box2D.Common.Math.b2Mat22.prototype.Copy=function(){var a=Box2D.Common.Math.b2Mat22.Get();a.SetM(this);return a};Box2D.Common.Math.b2Mat22.prototype.SetM=function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2)};Box2D.Common.Math.b2Mat22.prototype.AddM=function(a){this.col1.Add(a.col1);this.col2.Add(a.col2)};Box2D.Common.Math.b2Mat22.prototype.SetIdentity=function(){this.col1.Set(1,0);this.col2.Set(0,1)};Box2D.Common.Math.b2Mat22.prototype.SetZero=function(){this.col1.Set(0,0);this.col2.Set(0,0)};Box2D.Common.Math.b2Mat22.prototype.GetAngle=function(){return Math.atan2(this.col1.y,this.col1.x)};Box2D.Common.Math.b2Mat22.prototype.GetInverse=function(a){var b=this.col1.x*this.col2.y-this.col2.x*this.col1.y;if(b!==0){b=1/b}a.col1.x=b*this.col2.y;a.col2.x=-b*this.col2.x;a.col1.y=-b*this.col1.y;a.col2.y=b*this.col1.x;return a};Box2D.Common.Math.b2Mat22.prototype.Solve=function(a,d,c){var b=this.col1.x*this.col2.y-this.col2.x*this.col1.y;if(b!==0){b=1/b}a.x=b*(this.col2.y*d-this.col2.x*c);a.y=b*(this.col1.x*c-this.col1.y*d);return a};Box2D.Common.Math.b2Mat22.prototype.Abs=function(){this.col1.Abs();this.col2.Abs()};Box2D.Common.Math.b2Mat33=function(c,b,a){this.col1=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.col2=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.col3=Box2D.Common.Math.b2Vec3.Get(0,0,0);if(c){this.col1.SetV(c)}if(b){this.col2.SetV(b)}if(a){this.col3.SetV(a)}};Box2D.Common.Math.b2Mat33.prototype.SetVVV=function(c,b,a){this.col1.SetV(c);this.col2.SetV(b);this.col3.SetV(a)};Box2D.Common.Math.b2Mat33.prototype.Copy=function(){return new Box2D.Common.Math.b2Mat33(this.col1,this.col2,this.col3)};Box2D.Common.Math.b2Mat33.prototype.SetM=function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2);this.col3.SetV(a.col3)};Box2D.Common.Math.b2Mat33.prototype.AddM=function(a){this.col1.x+=a.col1.x;this.col1.y+=a.col1.y;this.col1.z+=a.col1.z;this.col2.x+=a.col2.x;this.col2.y+=a.col2.y;this.col2.z+=a.col2.z;this.col3.x+=a.col3.x;this.col3.y+=a.col3.y;this.col3.z+=a.col3.z};Box2D.Common.Math.b2Mat33.prototype.SetIdentity=function(){this.col1.Set(1,0,0);this.col2.Set(0,1,0);this.col3.Set(0,0,1)};Box2D.Common.Math.b2Mat33.prototype.SetZero=function(){this.col1.Set(0,0,0);this.col2.Set(0,0,0);this.col3.Set(0,0,0)};Box2D.Common.Math.b2Mat33.prototype.Solve22=function(e,h,g){var b=this.col1.x;var a=this.col2.x;var d=this.col1.y;var c=this.col2.y;var f=b*c-a*d;if(f!=0){f=1/f}e.x=f*(c*h-a*g);e.y=f*(b*g-d*h);return e};Box2D.Common.Math.b2Mat33.prototype.Solve33=function(f,b,a,n){var m=this.col1.x;var j=this.col1.y;var e=this.col1.z;var l=this.col2.x;var h=this.col2.y;var d=this.col2.z;var k=this.col3.x;var g=this.col3.y;var c=this.col3.z;var i=m*(h*c-d*g)+j*(d*k-l*c)+e*(l*g-h*k);if(i!=0){i=1/i}f.x=i*(b*(h*c-d*g)+a*(d*k-l*c)+n*(l*g-h*k));f.y=i*(m*(a*c-n*g)+j*(n*k-b*c)+e*(b*g-a*k));f.z=i*(m*(h*n-d*a)+j*(d*b-l*n)+e*(l*a-h*b));return f};Box2D.Common.Math.b2Sweep=function(){this.localCenter=Box2D.Common.Math.b2Vec2.Get(0,0);this.c0=Box2D.Common.Math.b2Vec2.Get(0,0);this.c=Box2D.Common.Math.b2Vec2.Get(0,0);this.a0=null;this.a=null;this.t0=null};Box2D.Common.Math.b2Sweep.prototype.Set=function(a){this.localCenter.SetV(a.localCenter);this.c0.SetV(a.c0);this.c.SetV(a.c);this.a0=a.a0;this.a=a.a;this.t0=a.t0};Box2D.Common.Math.b2Sweep.prototype.Copy=function(){var a=new Box2D.Common.Math.b2Sweep();a.localCenter.SetV(this.localCenter);a.c0.SetV(this.c0);a.c.SetV(this.c);a.a0=this.a0;a.a=this.a;a.t0=this.t0;return a};Box2D.Common.Math.b2Sweep.prototype.GetTransform=function(b,c){if(c===undefined){c=0}b.position.x=(1-c)*this.c0.x+c*this.c.x;b.position.y=(1-c)*this.c0.y+c*this.c.y;var d=(1-c)*this.a0+c*this.a;b.R.Set(d);var a=b.R;b.position.x-=(a.col1.x*this.localCenter.x+a.col2.x*this.localCenter.y);b.position.y-=(a.col1.y*this.localCenter.x+a.col2.y*this.localCenter.y)};Box2D.Common.Math.b2Sweep.prototype.Advance=function(a){if(a===undefined){a=0}if(this.t0<a&&1-this.t0>Number.MIN_VALUE){var b=(a-this.t0)/(1-this.t0);this.c0.x=(1-b)*this.c0.x+b*this.c.x;this.c0.y=(1-b)*this.c0.y+b*this.c.y;this.a0=(1-b)*this.a0+b*this.a;this.t0=a}};Box2D.Common.Math.b2Sweep._freeCache=[];Box2D.Common.Math.b2Sweep.Get=function(){if(Box2D.Common.Math.b2Sweep._freeCache.length>0){var a=Box2D.Common.Math.b2Sweep._freeCache.pop();return a}return new Box2D.Common.Math.b2Sweep()};Box2D.Common.Math.b2Sweep.Free=function(a){if(a!=null){Box2D.Common.Math.b2Sweep._freeCache.push(a)}};Box2D.Common.Math.b2Transform=function(b,a){this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.R=Box2D.Common.Math.b2Mat22.Get();if(b){this.position.SetV(b)}if(a){this.R.SetM(a)}};Box2D.Common.Math.b2Transform.prototype.Initialize=function(b,a){this.position.SetV(b);this.R.SetM(a)};Box2D.Common.Math.b2Transform.prototype.SetIdentity=function(){this.position.SetZero();this.R.SetIdentity()};Box2D.Common.Math.b2Transform.prototype.Set=function(a){this.position.SetV(a.position);this.R.SetM(a.R)};Box2D.Common.Math.b2Transform.prototype.GetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)};Box2D.Common.Math.b2Transform._freeCache=[];Box2D.Common.Math.b2Transform.Get=function(){if(Box2D.Common.Math.b2Transform._freeCache.length>0){var a=Box2D.Common.Math.b2Transform._freeCache.pop();a.SetIdentity();return a}return new Box2D.Common.Math.b2Transform()};Box2D.Common.Math.b2Transform.Free=function(a){if(a!=null){Box2D.Common.Math.b2Transform._freeCache.push(a)}};Box2D.Common.Math.b2Math={};var b2MathClamp=function(c,b,d){return c<b?b:c>d?d:c};Box2D.Common.Math.b2Math.Clamp=b2MathClamp;var b2MathDot=function(d,c){return d.x*c.x+d.y*c.y};Box2D.Common.Math.b2Math.Dot=b2MathDot;var b2MathCrossVV=function(d,c){return d.x*c.y-d.y*c.x};Box2D.Common.Math.b2Math.CrossVV=b2MathCrossVV;var b2MathDistanceSquared=function(d,c){var f=d.x-c.x;var e=d.y-c.y;return(f*f+e*e)};Box2D.Common.Math.b2Math.DistanceSquared=b2MathDistanceSquared;var b2MathDistance=function(d,c){var f=d.x-c.x;var e=d.y-c.y;return Math.sqrt(f*f+e*e)};Box2D.Common.Math.b2Math.Distance=b2MathDistance;var b2MathAddVVInPlace=function(d,c,e){e.x=d.x+c.y;e.y=d.y+c.y};var b2MathSubtractVVInPlace=function(d,c,e){e.x=d.x-c.x;e.y=d.y-c.y};var b2MathMulXInPlace=function(b,i,a){var c=b.R;var f=c.col1;var e=c.col2;var d=b.position;var h=i.x;var g=i.y;a.x=f.x*h+e.x*g+d.x;a.y=f.y*h+e.y*g+d.y};var b2MathCrossVFInPlace=function(b,c,d){d.x=c*b.y;d.y=-c*b.x};var b2dMathCrossFVInPlace=function(c,b,d){d.x=-c*b.y;d.y=c*b.x};var b2MathMulMVInPlace=function(a,b,e){var g=a.col1;var f=a.col2;var d=b.x;var c=b.y;e.x=g.x*d+f.x*c;e.y=g.y*d+f.y*c};var b2MathMulTMVInPlace=function(a,b,e){var d=b.x;var c=b.y;var g=a.col1;var f=a.col2;e.x=d*g.x+c*g.y;e.y=d*f.x+c*f.y};var b2MathAbsVInPlace=function(b,c){c.x=Math.abs(b.x);c.y=Math.abs(b.y)};var b2MathCrossVF=function(b,c){return b2Vec2Get(c*b.y,(-c*b.x))};Box2D.Common.Math.b2Math.CrossVF=b2MathCrossVF;var b2dMathCrossFV=function(c,b){return b2Vec2Get((-c*b.y),c*b.x)};Box2D.Common.Math.b2Math.CrossFV=b2dMathCrossFV;var b2MathMulMV=function(a,b){var f=a.col1;var e=a.col2;var d=b.x;var c=b.y;return b2Vec2Get(f.x*d+e.x*c,f.y*d+e.y*c)};Box2D.Common.Math.b2Math.MulMV=b2MathMulMV;var b2MathMulTMV=function(a,b){var d=b.x;var c=b.y;var f=a.col1;var e=a.col2;return b2Vec2Get(d*f.x+c*f.y,d*e.x+c*e.y)};Box2D.Common.Math.b2Math.MulTMV=b2MathMulTMV;Box2D.Common.Math.b2Math.MulX=function(b,a){var c=b2Vec2Get(0,0);b2MathMulXInPlace(b,a,c);return c};var b2MathAddVV=function(d,c){return b2Vec2Get(d.x+c.x,d.y+c.y)};Box2D.Common.Math.b2Math.AddVV=b2MathAddVV;var b2MathSubtractVV=function(d,c){return b2Vec2Get(d.x-c.x,d.y-c.y)};Box2D.Common.Math.b2Math.SubtractVV=b2MathSubtractVV;var b2MathMulFV=function(c,b){return b2Vec2Get(c*b.x,c*b.y)};Box2D.Common.Math.b2Math.MulFV=b2MathMulFV;Box2D.Common.Math.b2Math.MulXT=function(e,d){var c=b2MathSubtractVV(d,e.position);var b=(c.x*e.R.col1.x+c.y*e.R.col1.y);c.y=(c.x*e.R.col2.x+c.y*e.R.col2.y);c.x=b;return c};Box2D.Common.Math.b2Math.AddMM=function(a,f){var c=a.col1;var b=a.col2;var e=f.col1;var d=f.col2;return b2Mat22GetAndInit(c.x+e.x,c.y+e.y,b.x+d.x,b.y+d.y)};Box2D.Common.Math.b2Math.MulMM=function(b,e){var d=Box2D.Common.Math.b2Math.MulMV(b,e.col1);var c=Box2D.Common.Math.b2Math.MulMV(b,e.col2);var a=Box2D.Common.Math.b2Mat22.FromVV(d,c);b2Vec2Free(d);b2Vec2Free(c);return a};var b2MathMulTMM_c1=b2Vec2Get(0,0);var b2MathMulTMM_c2=b2Vec2Get(0,0);Box2D.Common.Math.b2Math.MulTMM=function(b,c){b2MathMulTMM_c1.x=b2MathDot(b.col1,c.col1);b2MathMulTMM_c1.y=b2MathDot(b.col2,c.col1);b2MathMulTMM_c2.x=b2MathDot(b.col1,c.col2);b2MathMulTMM_c2.y=b2MathDot(b.col2,c.col2);var a=Box2D.Common.Math.b2Mat22.FromVV(b2MathMulTMM_c1,b2MathMulTMM_c2);return a};var b2MathAbsV=function(b){return b2Vec2Get(Math.abs(b.x),Math.abs(b.y))};Box2D.Common.Math.b2Math.AbsV=b2MathAbsV;var b2MathAbsM_v1=b2Vec2Get(0,0);var b2MathAbsM_v2=b2Vec2Get(0,0);Box2D.Common.Math.b2Math.AbsM=function(b){b2MathAbsVInPlace(b.col1,b2MathAbsM_v1);b2MathAbsVInPlace(b.col2,b2MathAbsM_v2);var a=Box2D.Common.Math.b2Mat22.FromVV(b2MathAbsM_v1,b2MathAbsM_v2);return a};var b2MathClamp01=function(b){return b<0?0:b>1?1:b};Box2D.Common.Math.b2Math.Clamp01=b2MathClamp01;var b2MathClampV=function(d,c,e){var b=b2MathClamp(d.x,c.x,e.x);var f=b2MathClamp(d.y,c.y,e.y);return b2Vec2Get(b,f)};Box2D.Common.Math.b2Math.ClampV=b2MathClampV;Box2D.Collision.b2AABB=function(){this.lowerBound=Box2D.Common.Math.b2Vec2.Get(0,0);this.upperBound=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2AABB._freeCache=[];Box2D.Collision.b2AABB.Get=function(){if(Box2D.Collision.b2AABB._freeCache.length>0){var a=Box2D.Collision.b2AABB._freeCache.pop();a.SetZero();return a}return new Box2D.Collision.b2AABB()};Box2D.Collision.b2AABB.Free=function(a){if(a!=null){Box2D.Collision.b2AABB._freeCache.push(a)}};Box2D.Collision.b2AABB.prototype.Set=function(c,b,a,d){this.lowerBound.Set(c,b);this.upperBound.Set(a,d)};Box2D.Collision.b2AABB.prototype.SetVV=function(b,a){this.lowerBound.SetV(b);this.upperBound.SetV(a)};Box2D.Collision.b2AABB.prototype.SetZero=function(){this.lowerBound.Set(0,0);this.upperBound.Set(0,0)};Box2D.Collision.b2AABB.prototype.IsValid=function(){var b=this.upperBound.x-this.lowerBound.x;if(b<0){return false}var a=this.upperBound.y-this.lowerBound.y;if(a<0){return false}return this.lowerBound.IsValid()&&this.upperBound.IsValid()};Box2D.Collision.b2AABB.prototype.GetCenter=function(){return Box2D.Common.Math.b2Vec2.Get((this.lowerBound.x+this.upperBound.x)/2,(this.lowerBound.y+this.upperBound.y)/2)};Box2D.Collision.b2AABB.prototype.SetCenter=function(a){var b=this.GetCenter();this.lowerBound.Subtract(b);this.upperBound.Subtract(b);this.lowerBound.Add(a);this.upperBound.Add(a);Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Collision.b2AABB.prototype.GetExtents=function(){return Box2D.Common.Math.b2Vec2.Get((this.upperBound.x-this.lowerBound.x)/2,(this.upperBound.y-this.lowerBound.y)/2)};Box2D.Collision.b2AABB.prototype.Contains=function(b){var a=true;a=a&&this.lowerBound.x<=b.lowerBound.x;a=a&&this.lowerBound.y<=b.lowerBound.y;a=a&&b.upperBound.x<=this.upperBound.x;a=a&&b.upperBound.y<=this.upperBound.y;return a};Box2D.Collision.b2AABB.prototype.RayCast=function(b,l){var a=(-Number.MAX_VALUE);var i=Number.MAX_VALUE;var d=l.p2.x-l.p1.x;var j=Math.abs(d);if(j<Number.MIN_VALUE){if(l.p1.x<this.lowerBound.x||this.upperBound.x<l.p1.x){return false}}else{var f=1/d;var k=(this.lowerBound.x-l.p1.x)*f;var h=(this.upperBound.x-l.p1.x)*f;var m=(-1);if(k>h){var e=k;k=h;h=e;m=1}if(k>a){b.normal.x=m;b.normal.y=0;a=k}i=Math.min(i,h);if(a>i){return false}}var c=l.p2.y-l.p1.y;var g=Math.abs(c);if(g<Number.MIN_VALUE){if(l.p1.y<this.lowerBound.y||this.upperBound.y<l.p1.y){return false}}else{var f=1/c;var k=(this.lowerBound.y-l.p1.y)*f;var h=(this.upperBound.y-l.p1.y)*f;var m=(-1);if(k>h){var e=k;k=h;h=e;m=1}if(k>a){b.normal.y=m;b.normal.x=0;a=k}i=Math.min(i,h);if(a>i){return false}}b.fraction=a;return true};Box2D.Collision.b2AABB.prototype.TestOverlap=function(a){if(a.lowerBound.x-this.upperBound.x>0){return false}if(a.lowerBound.y-this.upperBound.y>0){return false}if(this.lowerBound.x-a.upperBound.x>0){return false}if(this.lowerBound.y-a.upperBound.y>0){return false}return true};Box2D.Collision.b2AABB.Combine=function(c,a){var b=Box2D.Collision.b2AABB.Get();b.Combine(c,a);return b};Box2D.Collision.b2AABB.prototype.Combine=function(b,a){this.lowerBound.x=Math.min(b.lowerBound.x,a.lowerBound.x);this.lowerBound.y=Math.min(b.lowerBound.y,a.lowerBound.y);this.upperBound.x=Math.max(b.upperBound.x,a.upperBound.x);this.upperBound.y=Math.max(b.upperBound.y,a.upperBound.y)};Box2D.Collision.b2AABB.prototype.GetMinX=function(){return this.lowerBound.x};Box2D.Collision.b2AABB.prototype.GetMaxX=function(){return this.upperBound.x};Box2D.Collision.b2AABB.prototype.GetMinY=function(){return this.lowerBound.y};Box2D.Collision.b2AABB.prototype.GetMaxY=function(){return this.upperBound.y};Box2D.Dynamics.iContactFilter=function(){};Box2D.Dynamics.iContactFilter.prototype.ShouldCollide=function(a,b){};Box2D.Dynamics.iContactListener=function(){};Box2D.Dynamics.iContactListener.prototype.BeginContact=function(a){};Box2D.Dynamics.iContactListener.prototype.EndContact=function(a){};Box2D.Dynamics.iContactListener.prototype.PreSolve=function(a,b){};Box2D.Dynamics.iContactListener.prototype.PostSolve=function(a,b){};Box2D.Dynamics.b2Body=function(b,a){this.ID=Box2D.Dynamics.b2Body.NEXT_ID++;if(!this.m_xf){this.m_xf=Box2D.Common.Math.b2Transform.Get()}this.m_xf.position.SetV(b.position);this.m_xf.R.Set(b.angle);if(!this.m_sweep){this.m_sweep=Box2D.Common.Math.b2Sweep.Get()}this.m_sweep.localCenter.SetZero();this.m_sweep.t0=1;this.m_sweep.a0=this.m_sweep.a=b.angle;this.m_sweep.c.x=(this.m_xf.R.col1.x*this.m_sweep.localCenter.x+this.m_xf.R.col2.x*this.m_sweep.localCenter.y);this.m_sweep.c.y=(this.m_xf.R.col1.y*this.m_sweep.localCenter.x+this.m_xf.R.col2.y*this.m_sweep.localCenter.y);this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;this.m_sweep.c0.SetV(this.m_sweep.c);if(!this.m_linearVelocity){this.m_linearVelocity=b.linearVelocity.Copy()}else{this.m_linearVelocity.SetV(b.linearVelocity)}if(!this.m_force){this.m_force=Box2D.Common.Math.b2Vec2.Get(0,0)}else{this.m_force.Set(0,0)}this.m_bullet=b.bullet;this.m_fixedRotation=b.fixedRotation;this.m_allowSleep=b.allowSleep;this.m_awake=b.awake;this.m_active=b.active;this.m_world=a;this.m_jointList=null;if(!this.contactList){this.contactList=new Box2D.Dynamics.Contacts.b2ContactList()}if(!this.controllerList){this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList()}this.m_controllerCount=0;this.m_angularVelocity=b.angularVelocity;this.m_linearDamping=b.linearDamping;this.m_angularDamping=b.angularDamping;this.m_torque=0;this.m_sleepTime=0;this.m_type=b.type;this.m_mass=this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_invMass=this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_I=0;this.m_invI=0;this.m_inertiaScale=b.inertiaScale;if(!this.fixtureList){this.fixtureList=Box2D.Dynamics.b2FixtureList.Get()}if(!this.m_lists){this.m_lists=Box2D.Array.Get()}};Box2D.Dynamics.b2Body._freeCache=[];Box2D.Dynamics.b2Body.Get=function(c,b){var a=this._freeCache;var d;if(a.length>0){d=a.pop();this.call(d,c,b)}else{d=new this(c,b)}return d};Box2D.Dynamics.b2Body.Free=function(a){this._freeCache.push(a)};Box2D.Dynamics.b2Body.prototype.CreateFixture=function(c){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());var b=Box2D.Dynamics.b2Fixture.Get(this,this.m_xf,c);if(this.m_active){var a=this.m_world.m_contactManager.m_broadPhase;b.CreateProxy(a,this.m_xf)}this.fixtureList.AddFixture(b);b.m_body=this;if(b.m_density>0){this.ResetMassData()}this.m_world.m_newFixture=true;return b};Box2D.Dynamics.b2Body.prototype.CreateFixture2=function(b,a){var c=new Box2D.Dynamics.b2FixtureDef();c.shape=b;c.density=a;return this.CreateFixture(c)};Box2D.Dynamics.b2Body.prototype.Destroy=function(){Box2D.Dynamics.b2Body.Free(this)};Box2D.Dynamics.b2Body.prototype.DestroyFixture=function(c){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());this.fixtureList.RemoveFixture(c);for(var b=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode()){if(c==b.contact.GetFixtureA()||c==b.contact.GetFixtureB()){this.m_world.m_contactManager.Destroy(b.contact)}}if(this.m_active){var a=this.m_world.m_contactManager.m_broadPhase;c.DestroyProxy(a)}c.Destroy();this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.SetPositionAndAngle=function(b,f){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());this.m_xf.R.Set(f);this.m_xf.position.SetV(b);var d=this.m_xf.R;var c=this.m_sweep.localCenter;this.m_sweep.c.x=(d.col1.x*c.x+d.col2.x*c.y);this.m_sweep.c.y=(d.col1.y*c.x+d.col2.y*c.y);this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;this.m_sweep.c0.SetV(this.m_sweep.c);this.m_sweep.a0=this.m_sweep.a=f;var a=this.m_world.m_contactManager.m_broadPhase;for(var e=this.fixtureList.GetFirstNode();e;e=e.GetNextNode()){e.fixture.Synchronize(a,this.m_xf,this.m_xf)}this.m_world.m_contactManager.FindNewContacts()};Box2D.Dynamics.b2Body.prototype.SetTransform=function(a){this.SetPositionAndAngle(a.position,a.GetAngle())};Box2D.Dynamics.b2Body.prototype.GetTransform=function(){return this.m_xf};Box2D.Dynamics.b2Body.prototype.GetPosition=function(){return this.m_xf.position};Box2D.Dynamics.b2Body.prototype.SetPosition=function(a){this.SetPositionAndAngle(a,this.GetAngle())};Box2D.Dynamics.b2Body.prototype.GetAngle=function(){return this.m_sweep.a};Box2D.Dynamics.b2Body.prototype.SetCalculatedAngle=function(a){this.m_sweep.a=a};Box2D.Dynamics.b2Body.prototype.SetAngle=function(a){this.SetPositionAndAngle(this.GetPosition(),a)};Box2D.Dynamics.b2Body.prototype.GetWorldCenter=function(){return this.m_sweep.c};Box2D.Dynamics.b2Body.prototype.GetLocalCenter=function(){return this.m_sweep.localCenter};Box2D.Dynamics.b2Body.prototype.SetLinearVelocity=function(a){if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody){return}this.m_linearVelocity.SetV(a)};Box2D.Dynamics.b2Body.prototype.GetLinearVelocity=function(){return this.m_linearVelocity};Box2D.Dynamics.b2Body.prototype.SetAngularVelocity=function(a){if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody){return}this.m_angularVelocity=a};Box2D.Dynamics.b2Body.prototype.GetAngularVelocity=function(){return this.m_angularVelocity};Box2D.Dynamics.b2Body.prototype.GetDefinition=function(){var a=new Box2D.Dynamics.b2BodyDef();a.type=this.GetType();a.allowSleep=this.m_allowSleep;a.angle=this.GetAngle();a.angularDamping=this.m_angularDamping;a.angularVelocity=this.m_angularVelocity;a.fixedRotation=this.m_fixedRotation;a.bullet=this.m_bullet;a.active=this.m_active;a.awake=this.m_awake;a.linearDamping=this.m_linearDamping;a.linearVelocity.SetV(this.GetLinearVelocity());a.position.SetV(this.GetPosition());return a};Box2D.Dynamics.b2Body.prototype.ApplyForce=function(b,a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){return}this.SetAwake(true);this.m_force.x+=b.x;this.m_force.y+=b.y;this.m_torque+=((a.x-this.m_sweep.c.x)*b.y-(a.y-this.m_sweep.c.y)*b.x)};Box2D.Dynamics.b2Body.prototype.ApplyTorque=function(a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){return}this.SetAwake(true);this.m_torque+=a};Box2D.Dynamics.b2Body.prototype.ApplyImpulse=function(b,a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){return}this.SetAwake(true);this.m_linearVelocity.x+=this.m_invMass*b.x;this.m_linearVelocity.y+=this.m_invMass*b.y;this.m_angularVelocity+=this.m_invI*((a.x-this.m_sweep.c.x)*b.y-(a.y-this.m_sweep.c.y)*b.x)};Box2D.Dynamics.b2Body.prototype.Split=function(o){var l=this.GetLinearVelocity().Copy();var g=this.GetAngularVelocity();var c=this.GetWorldCenter();var b=this;var q=this.m_world.CreateBody(this.GetDefinition());for(var h=b.fixtureList.GetFirstNode();h;h=h.GetNextNode()){var k=h.fixture;if(o(k)){b.fixtureList.RemoveFixture(k);q.fixtureList.AddFixture(k)}}b.ResetMassData();q.ResetMassData();var d=b.GetWorldCenter();var a=q.GetWorldCenter();var p=Box2D.Common.Math.b2Math.SubtractVV(d,c);var m=Box2D.Common.Math.b2Math.CrossFV(g,p);Box2D.Common.Math.b2Vec2.Free(p);var j=Box2D.Common.Math.b2Math.AddVV(l,m);Box2D.Common.Math.b2Vec2.Free(m);b.SetLinearVelocity(j);Box2D.Common.Math.b2Vec2.Free(j);var n=Box2D.Common.Math.b2Math.SubtractVV(a,c);var e=Box2D.Common.Math.b2Math.CrossFV(g,n);Box2D.Common.Math.b2Vec2.Free(n);var i=Box2D.Common.Math.b2Math.AddVV(l,e);Box2D.Common.Math.b2Vec2.Free(e);q.SetLinearVelocity(i);Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(l);b.SetAngularVelocity(g);q.SetAngularVelocity(g);b.SynchronizeFixtures();q.SynchronizeFixtures();return q};Box2D.Dynamics.b2Body.prototype.Merge=function(a){for(var b=a.fixtureList.GetFirstNode();b;b=b.GetNextNode()){this.fixtureList.AddFixture(b.fixture);a.fixtureList.RemoveFixture(b.fixture)}a.ResetMassData();this.ResetMassData();this.SynchronizeFixtures()};Box2D.Dynamics.b2Body.prototype.GetMass=function(){return this.m_mass};Box2D.Dynamics.b2Body.prototype.GetInverseMass=function(){return this.m_invMass};Box2D.Dynamics.b2Body.prototype.GetInertia=function(){return this.m_I};Box2D.Dynamics.b2Body.prototype.GetInverseInertia=function(){return this.m_invI};Box2D.Dynamics.b2Body.prototype.GetMassData=function(a){if(!a){a=Box2D.Collision.Shapes.b2MassData.Get()}a.mass=this.m_mass;a.I=this.m_I;a.center.SetV(this.m_sweep.localCenter);return a};Box2D.Dynamics.b2Body.prototype.SetMassData=function(a){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){return}this.m_invMass=0;this.m_I=0;this.m_invI=0;this.m_mass=a.mass;if(this.m_mass<=0){this.m_mass=1}this.m_invMass=1/this.m_mass;if(a.I>0&&!this.m_fixedRotation){this.m_I=a.I-this.m_mass*(a.center.x*a.center.x+a.center.y*a.center.y);this.m_invI=1/this.m_I}var b=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a.center);this.m_sweep.c0.SetV(Box2D.Common.Math.b2Math.MulX(this.m_xf,this.m_sweep.localCenter));this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=this.m_angularVelocity*(-(this.m_sweep.c.y-b.y));this.m_linearVelocity.y+=this.m_angularVelocity*(+(this.m_sweep.c.x-b.x));Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Dynamics.b2Body.prototype.ResetMassData=function(){this.m_mass=0;this.m_invMass=0;this.m_I=0;this.m_invI=0;this.m_sweep.localCenter.SetZero();if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody||this.m_type==Box2D.Dynamics.b2BodyDef.b2_kinematicBody){return}var a=Box2D.Common.Math.b2Vec2.Get(0,0);for(var d=this.fixtureList.GetFirstNode();d;d=d.GetNextNode()){var e=d.fixture;if(e.m_density==0){continue}var b=e.GetMassData();this.m_mass+=b.mass;a.x+=b.center.x*b.mass;a.y+=b.center.y*b.mass;this.m_I+=b.I;Box2D.Collision.Shapes.b2MassData.Free(b)}if(this.m_mass>0){this.m_invMass=1/this.m_mass;a.x*=this.m_invMass;a.y*=this.m_invMass}else{this.m_mass=1;this.m_invMass=1}if(this.m_I>0&&!this.m_fixedRotation){this.m_I-=this.m_mass*(a.x*a.x+a.y*a.y);this.m_I*=this.m_inertiaScale;Box2D.Common.b2Settings.b2Assert(this.m_I>0);this.m_invI=1/this.m_I}else{this.m_I=0;this.m_invI=0}var g=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a);var c=Box2D.Common.Math.b2Math.MulX(this.m_xf,this.m_sweep.localCenter);this.m_sweep.c0.SetV(c);this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=this.m_angularVelocity*(-(this.m_sweep.c.y-g.y));this.m_linearVelocity.y+=this.m_angularVelocity*(+(this.m_sweep.c.x-g.x));Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(g);Box2D.Common.Math.b2Vec2.Free(c)};Box2D.Dynamics.b2Body.prototype.GetWorldPoint=function(c){var a=this.m_xf.R;var b=Box2D.Common.Math.b2Vec2.Get(a.col1.x*c.x+a.col2.x*c.y,a.col1.y*c.x+a.col2.y*c.y);b.x+=this.m_xf.position.x;b.y+=this.m_xf.position.y;return b};Box2D.Dynamics.b2Body.prototype.GetWorldVector=function(a){return Box2D.Common.Math.b2Math.MulMV(this.m_xf.R,a)};Box2D.Dynamics.b2Body.prototype.GetLocalPoint=function(a){return Box2D.Common.Math.b2Math.MulXT(this.m_xf,a)};Box2D.Dynamics.b2Body.prototype.GetLocalVector=function(a){return Box2D.Common.Math.b2Math.MulTMV(this.m_xf.R,a)};Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromWorldPoint=function(a){return Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(a.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(a.x-this.m_sweep.c.x))};Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromLocalPoint=function(d){var a=this.m_xf.R;var b=Box2D.Common.Math.b2Vec2.Get(a.col1.x*d.x+a.col2.x*d.y,a.col1.y*d.x+a.col2.y*d.y);b.x+=this.m_xf.position.x;b.y+=this.m_xf.position.y;var c=Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(b.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(b.x-this.m_sweep.c.x));Box2D.Common.Math.b2Vec2.Free(b);return c};Box2D.Dynamics.b2Body.prototype.GetLinearDamping=function(){return this.m_linearDamping};Box2D.Dynamics.b2Body.prototype.SetLinearDamping=function(a){this.m_linearDamping=a};Box2D.Dynamics.b2Body.prototype.GetAngularDamping=function(){return this.m_angularDamping};Box2D.Dynamics.b2Body.prototype.SetAngularDamping=function(a){this.m_angularDamping=a};Box2D.Dynamics.b2Body.prototype.SetType=function(c){if(this.m_type==c){return}this.m_type=c;this.ResetMassData();if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody){this.m_linearVelocity.SetZero();this.m_angularVelocity=0}this.SetAwake(true);this.m_force.SetZero();this.m_torque=0;for(var a=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){a.contact.FlagForFiltering()}for(var b=0;b<this.m_lists.length;b++){this.m_lists[b].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.GetType=function(){return this.m_type};Box2D.Dynamics.b2Body.prototype.SetBullet=function(a){this.m_bullet=a};Box2D.Dynamics.b2Body.prototype.IsBullet=function(){return this.m_bullet};Box2D.Dynamics.b2Body.prototype.SetSleepingAllowed=function(a){this.m_allowSleep=a;if(!a){this.SetAwake(true)}};Box2D.Dynamics.b2Body.prototype.SetAwake=function(a){if(this.m_awake!=a){this.m_awake=a;this.m_sleepTime=0;if(!a){this.m_linearVelocity.SetZero();this.m_angularVelocity=0;this.m_force.SetZero();this.m_torque=0}for(var b=0;b<this.m_lists.length;b++){this.m_lists[b].UpdateBody(this)}}};Box2D.Dynamics.b2Body.prototype.IsAwake=function(){return this.m_awake};Box2D.Dynamics.b2Body.prototype.SetFixedRotation=function(a){this.m_fixedRotation=a;this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.IsFixedRotation=function(){return this.m_fixedRotation};Box2D.Dynamics.b2Body.prototype.SetActive=function(c){if(c==this.m_active){return}if(c){this.m_active=true;var a=this.m_world.m_contactManager.m_broadPhase;for(var e=this.fixtureList.GetFirstNode();e;e=e.GetNextNode()){e.fixture.CreateProxy(a,this.m_xf)}}else{this.m_active=false;var a=this.m_world.m_contactManager.m_broadPhase;for(var e=this.fixtureList.GetFirstNode();e;e=e.GetNextNode()){e.fixture.DestroyProxy(a)}for(var b=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode()){this.m_world.m_contactManager.Destroy(b.contact)}}for(var d=0;d<this.m_lists.length;d++){this.m_lists[d].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.IsActive=function(){return this.m_active};Box2D.Dynamics.b2Body.prototype.IsSleepingAllowed=function(){return this.m_allowSleep};Box2D.Dynamics.b2Body.prototype.GetFixtureList=function(){return this.fixtureList};Box2D.Dynamics.b2Body.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2Body.prototype.GetControllerList=function(){return this.controllerList};Box2D.Dynamics.b2Body.prototype.AddController=function(a){this.controllerList.AddController(a)};Box2D.Dynamics.b2Body.prototype.RemoveController=function(a){this.controllerList.RemoveController(a)};Box2D.Dynamics.b2Body.prototype.GetContactList=function(){return this.contactList};Box2D.Dynamics.b2Body.prototype.GetWorld=function(){return this.m_world};Box2D.Dynamics.b2Body.prototype.SynchronizeFixtures=function(){var d=Box2D.Dynamics.b2Body.s_xf1;d.R.Set(this.m_sweep.a0);var c=d.R;var b=this.m_sweep.localCenter;d.position.x=this.m_sweep.c0.x-(c.col1.x*b.x+c.col2.x*b.y);d.position.y=this.m_sweep.c0.y-(c.col1.y*b.x+c.col2.y*b.y);var a=this.m_world.m_contactManager.m_broadPhase;for(var e=this.fixtureList.GetFirstNode();e;e=e.GetNextNode()){e.fixture.Synchronize(a,d,this.m_xf)}};Box2D.Dynamics.b2Body.prototype.SynchronizeTransform=function(){this.m_xf.R.Set(this.m_sweep.a);var b=this.m_xf.R;var a=this.m_sweep.localCenter;this.m_xf.position.x=this.m_sweep.c.x-(b.col1.x*a.x+b.col2.x*a.y);this.m_xf.position.y=this.m_sweep.c.y-(b.col1.y*a.x+b.col2.y*a.y)};Box2D.Dynamics.b2Body.prototype.ShouldCollide=function(a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&a.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){return false}for(var b=this.m_jointList;b;b=b.next){if(b.other==a){if(b.joint.m_collideConnected==false){return false}}}return true};Box2D.Dynamics.b2Body.prototype.Advance=function(a){this.m_sweep.Advance(a);this.m_sweep.c.SetV(this.m_sweep.c0);this.m_sweep.a=this.m_sweep.a0;this.SynchronizeTransform()};Box2D.Dynamics.b2Body.NEXT_ID=0;Box2D.Dynamics.b2Body.s_xf1=new Box2D.Common.Math.b2Transform();Box2D.Dynamics.b2BodyDef=function(){this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearVelocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.angle=0;this.angularVelocity=0;this.linearDamping=0;this.angularDamping=0;this.allowSleep=true;this.awake=true;this.fixedRotation=false;this.bullet=false;this.type=Box2D.Dynamics.b2BodyDef.b2_staticBody;this.active=true;this.inertiaScale=1};Box2D.Dynamics.b2BodyDef.b2_staticBody=0;Box2D.Dynamics.b2BodyDef.b2_kinematicBody=1;Box2D.Dynamics.b2BodyDef.b2_dynamicBody=2;Box2D.Dynamics.b2BodyList=function(){this.bodyFirstNodes=Box2D.Array.Get();for(var a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++){this.bodyFirstNodes[a]=null}this.bodyLastNodes=Box2D.Array.Get();for(var a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++){this.bodyLastNodes[a]=null}this.bodyNodeLookup={};this.bodyCount=0};Box2D.Dynamics.b2BodyList.prototype.GetFirstNode=function(a){return this.bodyFirstNodes[a]};Box2D.Dynamics.b2BodyList.prototype.AddBody=function(a){var b=a.ID;if(this.bodyNodeLookup[b]==null){this.CreateNode(a,b,Box2D.Dynamics.b2BodyList.TYPES.allBodies);this.UpdateBody(a);a.m_lists.push(this);this.bodyCount++}};Box2D.Dynamics.b2BodyList.prototype.UpdateBody=function(a){var c=a.GetType();var d=a.ID;var b=a.IsAwake();var e=a.IsActive();if(c==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){this.CreateNode(a,d,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies)}else{this.RemoveNode(d,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies)}if(c!=Box2D.Dynamics.b2BodyDef.b2_staticBody){this.CreateNode(a,d,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies)}else{this.RemoveNode(d,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies)}if(c!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&e&&b){this.CreateNode(a,d,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies)}else{this.RemoveNode(d,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies)}if(b){this.CreateNode(a,d,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies)}else{this.RemoveNode(d,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies)}if(e){this.CreateNode(a,d,Box2D.Dynamics.b2BodyList.TYPES.activeBodies)}else{this.RemoveNode(d,Box2D.Dynamics.b2BodyList.TYPES.activeBodies)}};Box2D.Dynamics.b2BodyList.prototype.RemoveBody=function(a){var c=a.ID;if(this.bodyNodeLookup[c]!=null){Box2D.Array.remove(a.m_lists,this);for(var b=0;b<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;b++){this.RemoveNode(c,b)}delete this.bodyNodeLookup[c];this.bodyCount--}};Box2D.Dynamics.b2BodyList.prototype.RemoveNode=function(f,d){var c=this.bodyNodeLookup[f];if(c==null){return}var e=c[d];if(e==null){return}c[d]=null;var b=e.GetPreviousNode();var a=e.GetNextNode();if(b==null){this.bodyFirstNodes[d]=a}else{b.SetNextNode(a)}if(a==null){this.bodyLastNodes[d]=b}else{a.SetPreviousNode(b)}Box2D.Dynamics.b2BodyListNode.Free(e)};Box2D.Dynamics.b2BodyList.prototype.CreateNode=function(a,f,e){var c=this.bodyNodeLookup[f];if(c==null){c=Box2D.Array.Get();for(var d=0;d<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;d++){c[d]=null}this.bodyNodeLookup[f]=c}if(c[e]==null){c[e]=Box2D.Dynamics.b2BodyListNode.Get(a);var b=this.bodyLastNodes[e];if(b!=null){b.SetNextNode(c[e])}else{this.bodyFirstNodes[e]=c[e]}c[e].SetPreviousNode(b);this.bodyLastNodes[e]=c[e]}};Box2D.Dynamics.b2BodyList.prototype.GetBodyCount=function(){return this.bodyCount};Box2D.Dynamics.b2BodyList.TYPES={dynamicBodies:0,nonStaticBodies:1,activeBodies:2,nonStaticActiveAwakeBodies:3,awakeBodies:4,allBodies:5};Box2D.Dynamics.b2BodyListNode=function(a){this.body=a;this.next=null;this.previous=null};Box2D.Dynamics.b2BodyListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2BodyListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2BodyListNode.prototype.GetBody=function(){return this.body};Box2D.Dynamics.b2BodyListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.b2BodyListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.b2BodyListNode._freeCache=[];Box2D.Dynamics.b2BodyListNode.Get=function(a){if(Box2D.Dynamics.b2BodyListNode._freeCache.length>0){var b=Box2D.Dynamics.b2BodyListNode._freeCache.pop();b.body=a;b.next=null;b.previous=null;return b}return new Box2D.Dynamics.b2BodyListNode(a)};Box2D.Dynamics.b2BodyListNode.Free=function(a){if(a!=null){Box2D.Dynamics.b2BodyListNode._freeCache.push(a)}};Box2D.Dynamics.b2ContactFilter=function(){};Box2D.Dynamics.b2ContactFilter.prototype.ShouldCollide=function(a,d){var c=a.GetFilterData();var b=d.GetFilterData();if(c.groupIndex==b.groupIndex&&c.groupIndex!=0){return c.groupIndex>0}return(c.maskBits&b.categoryBits)!=0&&(c.categoryBits&b.maskBits)!=0};Box2D.Dynamics.b2ContactFilter.b2_defaultFilter=new Box2D.Dynamics.b2ContactFilter();Box2D.Dynamics.b2ContactImpulse=function(){this.normalImpulses=Box2D.Array.Get();this.tangentImpulses=Box2D.Array.Get()};Box2D.Dynamics.b2ContactImpulse.prototype.Reset=function(){this.normalImpulses.length=0;this.tangentImpulses.length=0};Box2D.Dynamics.b2ContactListener=function(){};Box2D.Dynamics.b2ContactListener.prototype.BeginContact=function(a){};Box2D.Dynamics.b2ContactListener.prototype.EndContact=function(a){};Box2D.Dynamics.b2ContactListener.prototype.PreSolve=function(a,b){};Box2D.Dynamics.b2ContactListener.prototype.PostSolve=function(a,b){};Box2D.Dynamics.b2ContactListener.b2_defaultListener=new Box2D.Dynamics.b2ContactListener();Box2D.Dynamics.b2DebugDraw=function(){this.m_drawScale=1;this.m_lineThickness=1;this.m_alpha=1;this.m_fillAlpha=1;this.m_xformScale=1;this.m_drawFlags=0;this.m_ctx=null};Box2D.Dynamics.b2DebugDraw.prototype.Clear=function(){this.m_ctx.clearRect(0,0,this.m_ctx.canvas.width,this.m_ctx.canvas.height)};Box2D.Dynamics.b2DebugDraw.prototype._color=function(a,b){return"rgba("+((a&16711680)>>16)+","+((a&65280)>>8)+","+(a&255)+","+b+")"};Box2D.Dynamics.b2DebugDraw.prototype.SetFlags=function(a){this.m_drawFlags=a};Box2D.Dynamics.b2DebugDraw.prototype.GetFlags=function(){return this.m_drawFlags};Box2D.Dynamics.b2DebugDraw.prototype.AppendFlags=function(a){this.m_drawFlags|=a};Box2D.Dynamics.b2DebugDraw.prototype.ClearFlags=function(a){this.m_drawFlags&=~a};Box2D.Dynamics.b2DebugDraw.prototype.SetSprite=function(a){this.m_ctx=a};Box2D.Dynamics.b2DebugDraw.prototype.GetSprite=function(){return this.m_ctx};Box2D.Dynamics.b2DebugDraw.prototype.SetDrawScale=function(a){this.m_drawScale=a};Box2D.Dynamics.b2DebugDraw.prototype.GetDrawScale=function(){return this.m_drawScale};Box2D.Dynamics.b2DebugDraw.prototype.SetLineThickness=function(a){this.m_lineThickness=a;this.m_ctx.strokeWidth=a};Box2D.Dynamics.b2DebugDraw.prototype.GetLineThickness=function(){return this.m_lineThickness};Box2D.Dynamics.b2DebugDraw.prototype.SetAlpha=function(a){this.m_alpha=a};Box2D.Dynamics.b2DebugDraw.prototype.GetAlpha=function(){return this.m_alpha};Box2D.Dynamics.b2DebugDraw.prototype.SetFillAlpha=function(a){this.m_fillAlpha=a};Box2D.Dynamics.b2DebugDraw.prototype.GetFillAlpha=function(){return this.m_fillAlpha};Box2D.Dynamics.b2DebugDraw.prototype.SetXFormScale=function(a){this.m_xformScale=a};Box2D.Dynamics.b2DebugDraw.prototype.GetXFormScale=function(){return this.m_xformScale};(function(a){a.prototype.DrawPolygon=function(c,f,b){if(!f){return}var e=this.m_ctx;var g=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(b.GetColor(),this.m_alpha);e.moveTo(c[0].x*g,c[0].y*g);for(var d=1;d<f;d++){e.lineTo(c[d].x*g,c[d].y*g)}e.lineTo(c[0].x*g,c[0].y*g);e.closePath();e.stroke()};a.prototype.DrawSolidPolygon=function(c,f,b){if(!f){return}var e=this.m_ctx;var g=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(b.GetColor(),this.m_alpha);e.fillStyle=this._color(b.GetColor(),this.m_fillAlpha);e.moveTo(c[0].x*g,c[0].y*g);for(var d=1;d<f;d++){e.lineTo(c[d].x*g,c[d].y*g)}e.lineTo(c[0].x*g,c[0].y*g);e.closePath();e.fill();e.stroke()};a.prototype.DrawCircle=function(c,b,d){if(!b){return}var e=this.m_ctx;var f=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(d.GetColor(),this.m_alpha);e.arc(c.x*f,c.y*f,b*f,0,Math.PI*2,true);e.closePath();e.stroke()};a.prototype.DrawSolidCircle=function(d,c,g,e){if(!c){return}var f=this.m_ctx,h=this.m_drawScale,b=d.x*h,i=d.y*h;f.moveTo(0,0);f.beginPath();f.strokeStyle=this._color(e.GetColor(),this.m_alpha);f.fillStyle=this._color(e.GetColor(),this.m_fillAlpha);f.arc(b,i,c*h,0,Math.PI*2,true);f.moveTo(b,i);f.lineTo((d.x+g.x*c)*h,(d.y+g.y*c)*h);f.closePath();f.fill();f.stroke()};a.prototype.DrawSegment=function(f,e,b){var c=this.m_ctx,d=this.m_drawScale;c.strokeStyle=this._color(b.GetColor(),this.m_alpha);c.beginPath();c.moveTo(f.x*d,f.y*d);c.lineTo(e.x*d,e.y*d);c.closePath();c.stroke()};a.prototype.DrawTransform=function(c){var b=this.m_ctx,d=this.m_drawScale;b.beginPath();b.strokeStyle=this._color(16711680,this.m_alpha);b.moveTo(c.position.x*d,c.position.y*d);b.lineTo((c.position.x+this.m_xformScale*c.R.col1.x)*d,(c.position.y+this.m_xformScale*c.R.col1.y)*d);b.strokeStyle=this._color(65280,this.m_alpha);b.moveTo(c.position.x*d,c.position.y*d);b.lineTo((c.position.x+this.m_xformScale*c.R.col2.x)*d,(c.position.y+this.m_xformScale*c.R.col2.y)*d);b.closePath();b.stroke()}})(Box2D.Dynamics.b2DebugDraw);Box2D.Dynamics.b2DebugDraw.e_shapeBit=1;Box2D.Dynamics.b2DebugDraw.e_jointBit=2;Box2D.Dynamics.b2DebugDraw.e_aabbBit=4;Box2D.Dynamics.b2DebugDraw.e_pairBit=8;Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit=16;Box2D.Dynamics.b2DebugDraw.e_controllerBit=32;Box2D.Dynamics.b2DestructionListener=function(){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeJoint=function(a){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeFixture=function(a){};Box2D.Dynamics.b2FilterData=function(){this.categoryBits=1;this.maskBits=65535;this.groupIndex=0};Box2D.Dynamics.b2FilterData.prototype.Copy=function(){var a=Box2D.Dynamics.b2FilterData.Get();a.categoryBits=this.categoryBits;a.maskBits=this.maskBits;a.groupIndex=this.groupIndex;return a};Box2D.Dynamics.b2FilterData.prototype.Set=function(a){this.categoryBits=a.categoryBits;this.maskBits=a.maskBits;this.groupIndex=a.groupIndex};Box2D.Dynamics.b2FilterData._freeCache=[];Box2D.Dynamics.b2FilterData.Get=function(){if(Box2D.Dynamics.b2FilterData._freeCache.length>0){var a=Box2D.Dynamics.b2FilterData._freeCache.pop();a.categoryBits=1;a.maskBits=65535;a.groupIndex=0;return a}return new Box2D.Dynamics.b2FilterData()};Box2D.Dynamics.b2FilterData.Free=function(a){if(a!=null){Box2D.Dynamics.b2FilterData._freeCache.push(a)}};Box2D.Dynamics.b2Fixture=function(a,b,c){this.ID=Box2D.Dynamics.b2Fixture.NEXT_ID++;this.m_filter=c.filter.Copy();this.m_aabb=Box2D.Collision.b2AABB.Get();this.m_body=a;this.m_shape=c.shape.Copy();this.m_density=c.density;this.m_friction=c.friction;this.m_restitution=c.restitution;this.m_isSensor=c.isSensor};Box2D.Dynamics.b2Fixture.s_aabb_temp=Box2D.Collision.b2AABB.Get();Box2D.Dynamics.b2Fixture._freeCache=[];Box2D.Dynamics.b2Fixture.Get=function(a,c,d){var b=this._freeCache;var e;if(b.length>0){e=b.pop();e.m_filter.Set(d.filter);e.m_body=a;e.m_shape=d.shape.Copy();e.m_density=d.density;e.m_friction=d.friction;e.m_restitution=d.restitution;e.m_isSensor=d.isSensor}else{e=new this(a,c,d)}return e};Box2D.Dynamics.b2Fixture.Free=function(a){this._freeCache.push(a)};Box2D.Dynamics.b2Fixture.prototype.GetShape=function(){return this.m_shape};Box2D.Dynamics.b2Fixture.prototype.SetSensor=function(c){if(this.m_isSensor==c){return}this.m_isSensor=c;if(this.m_body==null){return}for(var b=this.m_body.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode()){var a=b.contact.GetFixtureA();var d=b.contact.GetFixtureB();if(a==this||d==this){b.contact.SetSensor(a.IsSensor()||d.IsSensor())}}};Box2D.Dynamics.b2Fixture.prototype.IsSensor=function(){return this.m_isSensor};Box2D.Dynamics.b2Fixture.prototype.SetFilterData=function(b){this.m_filter=b.Copy();if(this.m_body==null){return}for(var a=this.m_body.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){if(a.contact.GetFixtureA()==this||a.contact.GetFixtureB()==this){a.contact.FlagForFiltering()}}};Box2D.Dynamics.b2Fixture.prototype.GetFilterData=function(){return this.m_filter};Box2D.Dynamics.b2Fixture.prototype.GetBody=function(){return this.m_body};Box2D.Dynamics.b2Fixture.prototype.TestPoint=function(a){return this.m_shape.TestPoint(this.m_body.GetTransform(),a)};Box2D.Dynamics.b2Fixture.prototype.RayCast=function(b,a){return this.m_shape.RayCast(b,a,this.m_body.GetTransform())};Box2D.Dynamics.b2Fixture.prototype.GetMassData=function(a){if(!a){a=Box2D.Collision.Shapes.b2MassData.Get()}this.m_shape.ComputeMass(a,this.m_density);return a};Box2D.Dynamics.b2Fixture.prototype.SetDensity=function(a){this.m_density=a};Box2D.Dynamics.b2Fixture.prototype.GetDensity=function(){return this.m_density};Box2D.Dynamics.b2Fixture.prototype.GetFriction=function(){return this.m_friction};Box2D.Dynamics.b2Fixture.prototype.SetFriction=function(a){this.m_friction=a};Box2D.Dynamics.b2Fixture.prototype.GetRestitution=function(){return this.m_restitution};Box2D.Dynamics.b2Fixture.prototype.SetRestitution=function(a){this.m_restitution=a};Box2D.Dynamics.b2Fixture.prototype.GetAABB=function(){return this.m_aabb};Box2D.Dynamics.b2Fixture.prototype.Destroy=function(){this.m_shape.Destroy();this.m_shape=null;Box2D.Dynamics.b2Fixture.Free(this)};Box2D.Dynamics.b2Fixture.prototype.CreateProxy=function(a,b){this.m_shape.ComputeAABB(this.m_aabb,b);this.m_proxy=a.CreateProxy(this.m_aabb,this)};Box2D.Dynamics.b2Fixture.prototype.DestroyProxy=function(a){if(this.m_proxy==null){return}a.DestroyProxy(this.m_proxy);this.m_proxy=null};Box2D.Dynamics.b2Fixture.prototype.Synchronize=function(a,e,d){if(!this.m_proxy){return}var c=Box2D.Dynamics.b2Fixture.s_aabb_temp;this.m_shape.ComputeAABB(this.m_aabb,e);this.m_shape.ComputeAABB(c,d);this.m_aabb.Combine(this.m_aabb,c);var b=Box2D.Common.Math.b2Math.SubtractVV(d.position,e.position);a.MoveProxy(this.m_proxy,this.m_aabb,b);Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Dynamics.b2Fixture.NEXT_ID=0;Box2D.Dynamics.b2FixtureDef=function(){this.filter=Box2D.Dynamics.b2FilterData.Get();this.filter.categoryBits=1;this.filter.maskBits=65535;this.filter.groupIndex=0;this.shape=null;this.friction=0.2;this.restitution=0;this.density=0;this.isSensor=false};Box2D.Dynamics.b2FixtureList=function(){this.fixtureFirstNode=null;this.fixtureLastNode=null;this.fixtureNodeLookup={};this.fixtureCount=0};Box2D.Dynamics.b2FixtureList.prototype.GetFirstNode=function(){return this.fixtureFirstNode};Box2D.Dynamics.b2FixtureList.prototype.AddFixture=function(d){var c=d.ID;if(this.fixtureNodeLookup[c]==null){var b=Box2D.Dynamics.b2FixtureListNode.Get(d);var a=this.fixtureLastNode;if(a!=null){a.SetNextNode(b)}else{this.fixtureFirstNode=b}b.SetPreviousNode(a);this.fixtureLastNode=b;this.fixtureNodeLookup[c]=b;this.fixtureCount++}};Box2D.Dynamics.b2FixtureList.prototype.RemoveFixture=function(e){var d=e.ID;var c=this.fixtureNodeLookup[d];if(c==null){return}var b=c.GetPreviousNode();var a=c.GetNextNode();if(b==null){this.fixtureFirstNode=a}else{b.SetNextNode(a)}if(a==null){this.fixtureLastNode=b}else{a.SetPreviousNode(b)}delete this.fixtureNodeLookup[d];this.fixtureCount--;Box2D.Dynamics.b2FixtureListNode.Free(c)};Box2D.Dynamics.b2FixtureList.prototype.GetFixtureCount=function(){return this.fixtureCount};Box2D.Dynamics.b2FixtureList._freeCache=[];Box2D.Dynamics.b2FixtureList.Get=function(){if(Box2D.Dynamics.b2FixtureList._freeCache.length>0){var a=Box2D.Dynamics.b2FixtureList._freeCache.pop();a.fixtureNodeLookup={};return a}return new Box2D.Dynamics.b2FixtureList()};Box2D.Dynamics.b2FixtureList.Free=function(a){if(a!=null){a.fixtureFirstNode=null;a.fixtureLastNode=null;a.fixtureNodeLookup=null;a.fixtureCount=0;Box2D.Dynamics.b2FixtureList._freeCache.push(a)}};Box2D.Dynamics.b2FixtureListNode=function(a){this.fixture=a;this.next=null;this.previous=null};Box2D.Dynamics.b2FixtureListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2FixtureListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2FixtureListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.b2FixtureListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.b2FixtureListNode._freeCache=[];Box2D.Dynamics.b2FixtureListNode.Get=function(a){if(Box2D.Dynamics.b2FixtureListNode._freeCache.length>0){var b=Box2D.Dynamics.b2FixtureListNode._freeCache.pop();b.fixture=a;return b}return new Box2D.Dynamics.b2FixtureListNode(a)};Box2D.Dynamics.b2FixtureListNode.Free=function(a){if(a!=null){a.fixture=null;a.next=null;a.previous=null;Box2D.Dynamics.b2FixtureListNode._freeCache.push(a)}};Box2D.Dynamics.b2Island=function(b,a){this.m_listener=b;this.m_contactSolver=a;this.m_bodies=Box2D.Array.Get();this.m_dynamicBodies=Box2D.Array.Get();this.m_nonStaticBodies=Box2D.Array.Get();this.m_contacts=Box2D.Array.Get();this.m_joints=Box2D.Array.Get();this.impulse=new Box2D.Dynamics.b2ContactImpulse()};Box2D.Dynamics.b2Island.prototype.Reset=function(b,a){this.m_listener=b;this.m_contactSolver=a};Box2D.Dynamics.b2Island.prototype.Clear=function(){this.m_bodies.length=0;this.m_dynamicBodies.length=0;this.m_nonStaticBodies.length=0;this.m_contacts.length=0;this.m_joints.length=0};Box2D.Dynamics.b2Island.prototype.Solve=function(a,c,b){this._InitializeVelocities(a,c);this.m_contactSolver.Initialize(a,this.m_contacts,this.m_contacts.length);this._SolveVelocityConstraints(a);this._SolveBodies(a);this._SolvePositionConstraints(a);if(b){this._SleepIfTired(a)}};Box2D.Dynamics.b2Island.prototype._InitializeVelocities=function(e,f){for(var c=0,d=this.m_dynamicBodies.length;c<d;c++){var a=this.m_dynamicBodies[c];a.m_linearVelocity.x+=e.dt*(f.x+a.m_invMass*a.m_force.x);a.m_linearVelocity.y+=e.dt*(f.y+a.m_invMass*a.m_force.y);a.m_angularVelocity+=e.dt*a.m_invI*a.m_torque;a.m_linearVelocity.Multiply(Box2D.Common.Math.b2Math.Clamp01(1-e.dt*a.m_linearDamping));a.m_angularVelocity*=Box2D.Common.Math.b2Math.Clamp01(1-e.dt*a.m_angularDamping)}};Box2D.Dynamics.b2Island.prototype._SolveVelocityConstraints=function(e){var c,d,b,a;this.m_contactSolver.InitVelocityConstraints(e);for(c=0,d=this.m_joints.length;c<d;c++){this.m_joints[c].InitVelocityConstraints(e)}for(c=0;c<e.velocityIterations;c++){for(b=0,a=this.m_joints.length;b<a;b++){this.m_joints[b].SolveVelocityConstraints(e)}this.m_contactSolver.SolveVelocityConstraints()}for(c=0,d=this.m_joints.length;c<d;c++){this.m_joints[c].FinalizeVelocityConstraints()}this.m_contactSolver.FinalizeVelocityConstraints()};Box2D.Dynamics.b2Island.prototype._SolveBodies=function(f){for(var d=0;d<this.m_nonStaticBodies.length;++d){var a=this.m_nonStaticBodies[d];var g=f.dt*a.m_linearVelocity.x;var e=f.dt*a.m_linearVelocity.y;if((g*g+e*e)>Box2D.Common.b2Settings.b2_maxTranslationSquared){a.m_linearVelocity.Normalize();a.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*f.inv_dt;a.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*f.inv_dt}var c=f.dt*a.m_angularVelocity;if(c*c>Box2D.Common.b2Settings.b2_maxRotationSquared){if(a.m_angularVelocity<0){a.m_angularVelocity=-Box2D.Common.b2Settings.b2_maxRotation*f.inv_dt}else{a.m_angularVelocity=Box2D.Common.b2Settings.b2_maxRotation*f.inv_dt}}a.m_sweep.c0.SetV(a.m_sweep.c);a.m_sweep.a0=a.m_sweep.a;a.m_sweep.c.x+=f.dt*a.m_linearVelocity.x;a.m_sweep.c.y+=f.dt*a.m_linearVelocity.y;a.m_sweep.a+=f.dt*a.m_angularVelocity;a.SynchronizeTransform()}};Box2D.Dynamics.b2Island.prototype._SolvePositionConstraints=function(f){for(var e=0;e<f.positionIterations;e++){var c=this.m_contactSolver.SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte);var b=true;for(var d=0;d<this.m_joints.length;d++){var a=this.m_joints[d].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte);b=b&&a}if(c&&b){break}}};Box2D.Dynamics.b2Island.prototype._SleepIfTired=function(f){var d=Number.MAX_VALUE;for(var c=0;c<this.m_nonStaticBodies.length;c++){var a=this.m_nonStaticBodies[c];if(!a.m_allowSleep||Math.abs(a.m_angularVelocity)>Box2D.Common.b2Settings.b2_angularSleepTolerance||Box2D.Common.Math.b2Math.Dot(a.m_linearVelocity,a.m_linearVelocity)>Box2D.Common.b2Settings.b2_linearSleepToleranceSquared){a.m_sleepTime=0;d=0}else{a.m_sleepTime+=f.dt;d=Math.min(d,a.m_sleepTime)}}if(d>=Box2D.Common.b2Settings.b2_timeToSleep){for(var e=0;e<this.m_bodies.length;e++){this.m_bodies[e].SetAwake(false)}}};Box2D.Dynamics.b2Island.prototype.SolveTOI=function(e){var f,d;var n=0.75;this.m_contactSolver.Initialize(e,this.m_contacts,this.m_contacts.length);var c=this.m_contactSolver;for(f=0;f<this.m_joints.length;++f){this.m_joints[f].InitVelocityConstraints(e)}for(f=0;f<e.velocityIterations;++f){c.SolveVelocityConstraints();for(d=0;d<this.m_joints.length;++d){this.m_joints[d].SolveVelocityConstraints(e)}}for(f=0;f<this.m_nonStaticBodies.length;++f){var m=this.m_nonStaticBodies[f];var k=e.dt*m.m_linearVelocity.x;var h=e.dt*m.m_linearVelocity.y;if((k*k+h*h)>Box2D.Common.b2Settings.b2_maxTranslationSquared){m.m_linearVelocity.Normalize();m.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*e.inv_dt;m.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*e.inv_dt}var o=e.dt*m.m_angularVelocity;if(o*o>Box2D.Common.b2Settings.b2_maxRotationSquared){if(m.m_angularVelocity<0){m.m_angularVelocity=(-Box2D.Common.b2Settings.b2_maxRotation*e.inv_dt)}else{m.m_angularVelocity=Box2D.Common.b2Settings.b2_maxRotation*e.inv_dt}}m.m_sweep.c0.SetV(m.m_sweep.c);m.m_sweep.a0=m.m_sweep.a;m.m_sweep.c.x+=e.dt*m.m_linearVelocity.x;m.m_sweep.c.y+=e.dt*m.m_linearVelocity.y;m.m_sweep.a+=e.dt*m.m_angularVelocity;m.SynchronizeTransform()}for(f=0;f<e.positionIterations;++f){var g=c.SolvePositionConstraints(n);var l=true;for(d=0;d<this.m_joints.length;++d){var a=this.m_joints[d].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte);l=l&&a}if(g&&l){break}}};Box2D.Dynamics.b2Island.prototype.Report=function(f){if(this.m_listener==null){return}for(var b=0;b<this.m_contacts.length;++b){var e=this.m_contacts[b];var d=f[b];this.impulse.Reset();for(var a=0;a<d.pointCount;++a){this.impulse.normalImpulses[a]=d.points[a].normalImpulse;this.impulse.tangentImpulses[a]=d.points[a].tangentImpulse}this.m_listener.PostSolve(e,this.impulse)}};Box2D.Dynamics.b2Island.prototype.AddBody=function(a){this.m_bodies.push(a);if(a.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody){this.m_nonStaticBodies.push(a);if(a.GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){this.m_dynamicBodies.push(a)}}};Box2D.Dynamics.b2Island.prototype.AddContact=function(a){this.m_contacts.push(a)};Box2D.Dynamics.b2Island.prototype.AddJoint=function(a){this.m_joints.push(a)};Box2D.Dynamics.b2TimeStep=function(b,a,d,e,c){this.Reset(b,a,d,e,c)};Box2D.Dynamics.b2TimeStep.prototype.Reset=function(c,b,e,f,d){this.dt=c;var a=0;if(c>0){a=1/c}this.inv_dt=a;this.dtRatio=b;this.positionIterations=e;this.velocityIterations=f;this.warmStarting=d};Box2D.Dynamics.Joints.b2JointDef=function(){this.type=Box2D.Dynamics.Joints.b2Joint.e_unknownJoint;this.bodyA=null;this.bodyB=null;this.collideConnected=false};Box2D.Dynamics.Joints.b2Joint=function(a){this.m_edgeA=new Box2D.Dynamics.Joints.b2JointEdge();this.m_edgeB=new Box2D.Dynamics.Joints.b2JointEdge();this.m_localCenterA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localCenterB=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Common.b2Settings.b2Assert(a.bodyA!=a.bodyB);this.m_type=a.type;this.m_prev=null;this.m_next=null;this.m_bodyA=a.bodyA;this.m_bodyB=a.bodyB;this.m_collideConnected=a.collideConnected};Box2D.Dynamics.Joints.b2Joint.prototype.GetType=function(){return this.m_type};Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorA=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorB=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return 0};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyA=function(){return this.m_bodyA};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyB=function(){return this.m_bodyB};Box2D.Dynamics.Joints.b2Joint.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Joints.b2Joint.prototype.IsActive=function(){return this.m_bodyA.IsActive()&&this.m_bodyB.IsActive()};Box2D.Dynamics.Joints.b2Joint.Create=function(a){return a.Create()};Box2D.Dynamics.Joints.b2Joint.prototype.InitVelocityConstraints=function(a){};Box2D.Dynamics.Joints.b2Joint.prototype.SolveVelocityConstraints=function(a){};Box2D.Dynamics.Joints.b2Joint.prototype.FinalizeVelocityConstraints=function(){};Box2D.Dynamics.Joints.b2Joint.prototype.SolvePositionConstraints=function(a){return false};Box2D.Dynamics.Joints.b2Joint.e_unknownJoint=0;Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint=1;Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint=2;Box2D.Dynamics.Joints.b2Joint.e_distanceJoint=3;Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint=4;Box2D.Dynamics.Joints.b2Joint.e_mouseJoint=5;Box2D.Dynamics.Joints.b2Joint.e_gearJoint=6;Box2D.Dynamics.Joints.b2Joint.e_lineJoint=7;Box2D.Dynamics.Joints.b2Joint.e_weldJoint=8;Box2D.Dynamics.Joints.b2Joint.e_frictionJoint=9;Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit=0;Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit=1;Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit=2;Box2D.Dynamics.Joints.b2Joint.e_equalLimits=3;Box2D.Dynamics.Joints.b2DistanceJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_length=a.length;this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_impulse=0;this.m_gamma=0;this.m_bias=0};Box2D.inherits(Box2D.Dynamics.Joints.b2DistanceJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionForce=function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u.x,a*this.m_impulse*this.m_u.y)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionTorque=function(a){return 0};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetLength=function(){return this.m_length};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetLength=function(a){this.m_length=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetFrequency=function(){return this.m_frequencyHz};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetFrequency=function(a){this.m_frequencyHz=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetDampingRatio=function(){return this.m_dampingRatio};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetDampingRatio=function(a){this.m_dampingRatio=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.InitVelocityConstraints=function(e){var i;var m=0;var t=this.m_bodyA;var s=this.m_bodyB;i=t.m_xf.R;var p=this.m_localAnchor1.x-t.m_sweep.localCenter.x;var o=this.m_localAnchor1.y-t.m_sweep.localCenter.y;m=(i.col1.x*p+i.col2.x*o);o=(i.col1.y*p+i.col2.y*o);p=m;i=s.m_xf.R;var c=this.m_localAnchor2.x-s.m_sweep.localCenter.x;var a=this.m_localAnchor2.y-s.m_sweep.localCenter.y;m=(i.col1.x*c+i.col2.x*a);a=(i.col1.y*c+i.col2.y*a);c=m;this.m_u.x=s.m_sweep.c.x+c-t.m_sweep.c.x-p;this.m_u.y=s.m_sweep.c.y+a-t.m_sweep.c.y-o;var b=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);if(b>Box2D.Common.b2Settings.b2_linearSlop){this.m_u.Multiply(1/b)}else{this.m_u.SetZero()}var u=(p*this.m_u.y-o*this.m_u.x);var g=(c*this.m_u.y-a*this.m_u.x);var r=t.m_invMass+t.m_invI*u*u+s.m_invMass+s.m_invI*g*g;this.m_mass=r!=0?1/r:0;if(this.m_frequencyHz>0){var j=b-this.m_length;var l=2*Math.PI*this.m_frequencyHz;var q=2*this.m_mass*this.m_dampingRatio*l;var n=this.m_mass*l*l;this.m_gamma=e.dt*(q+e.dt*n);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:0;this.m_bias=j*e.dt*n*this.m_gamma;this.m_mass=r+this.m_gamma;this.m_mass=this.m_mass!=0?1/this.m_mass:0}if(e.warmStarting){this.m_impulse*=e.dtRatio;var h=this.m_impulse*this.m_u.x;var f=this.m_impulse*this.m_u.y;t.m_linearVelocity.x-=t.m_invMass*h;t.m_linearVelocity.y-=t.m_invMass*f;t.m_angularVelocity-=t.m_invI*(p*f-o*h);s.m_linearVelocity.x+=s.m_invMass*h;s.m_linearVelocity.y+=s.m_invMass*f;s.m_angularVelocity+=s.m_invI*(c*f-a*h)}else{this.m_impulse=0}};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolveVelocityConstraints=function(b){var n=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x;var m=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y;var l=(this.m_bodyA.m_xf.R.col1.x*n+this.m_bodyA.m_xf.R.col2.x*m);m=(this.m_bodyA.m_xf.R.col1.y*n+this.m_bodyA.m_xf.R.col2.y*m);n=l;var h=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x;var g=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y;l=(this.m_bodyB.m_xf.R.col1.x*h+this.m_bodyB.m_xf.R.col2.x*g);g=(this.m_bodyB.m_xf.R.col1.y*h+this.m_bodyB.m_xf.R.col2.y*g);h=l;var k=this.m_bodyA.m_linearVelocity.x-this.m_bodyA.m_angularVelocity*m;var j=this.m_bodyA.m_linearVelocity.y+this.m_bodyA.m_angularVelocity*n;var f=this.m_bodyB.m_linearVelocity.x-this.m_bodyB.m_angularVelocity*g;var e=this.m_bodyB.m_linearVelocity.y+this.m_bodyB.m_angularVelocity*h;var i=(this.m_u.x*(f-k)+this.m_u.y*(e-j));var a=-this.m_mass*(i+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=a;var d=a*this.m_u.x;var c=a*this.m_u.y;this.m_bodyA.m_linearVelocity.x-=this.m_bodyA.m_invMass*d;this.m_bodyA.m_linearVelocity.y-=this.m_bodyA.m_invMass*c;this.m_bodyA.m_angularVelocity-=this.m_bodyA.m_invI*(n*c-m*d);this.m_bodyB.m_linearVelocity.x+=this.m_bodyB.m_invMass*d;this.m_bodyB.m_linearVelocity.y+=this.m_bodyB.m_invMass*c;this.m_bodyB.m_angularVelocity+=this.m_bodyB.m_invI*(h*c-g*d)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolvePositionConstraints=function(j){if(this.m_frequencyHz>0){return true}var m=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x;var l=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y;var k=(this.m_bodyA.m_xf.R.col1.x*m+this.m_bodyA.m_xf.R.col2.x*l);l=(this.m_bodyA.m_xf.R.col1.y*m+this.m_bodyA.m_xf.R.col2.y*l);m=k;var i=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x;var h=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y;k=(this.m_bodyB.m_xf.R.col1.x*i+this.m_bodyB.m_xf.R.col2.x*h);h=(this.m_bodyB.m_xf.R.col1.y*i+this.m_bodyB.m_xf.R.col2.y*h);i=k;var g=this.m_bodyB.m_sweep.c.x+i-this.m_bodyA.m_sweep.c.x-m;var f=this.m_bodyB.m_sweep.c.y+h-this.m_bodyA.m_sweep.c.y-l;var c=Math.sqrt(g*g+f*f);g/=c;f/=c;var a=Box2D.Common.Math.b2Math.Clamp(c-this.m_length,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection);var b=-this.m_mass*a;this.m_u.Set(g,f);var e=b*this.m_u.x;var d=b*this.m_u.y;this.m_bodyA.m_sweep.c.x-=this.m_bodyA.m_invMass*e;this.m_bodyA.m_sweep.c.y-=this.m_bodyA.m_invMass*d;this.m_bodyA.m_sweep.a-=this.m_bodyA.m_invI*(m*d-l*e);this.m_bodyB.m_sweep.c.x+=this.m_bodyB.m_invMass*e;this.m_bodyB.m_sweep.c.y+=this.m_bodyB.m_invMass*d;this.m_bodyB.m_sweep.a+=this.m_bodyB.m_invI*(i*d-h*e);this.m_bodyA.SynchronizeTransform();this.m_bodyB.SynchronizeTransform();return Math.abs(a)<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2DistanceJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_distanceJoint;this.length=1;this.frequencyHz=0;this.dampingRatio=0};Box2D.inherits(Box2D.Dynamics.Joints.b2DistanceJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Initialize=function(f,e,d,b){this.bodyA=f;this.bodyB=e;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(d));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(b));var c=b.x-d.x;var a=b.y-d.y;this.length=Math.sqrt(c*c+a*a);this.frequencyHz=0;this.dampingRatio=0};Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2DistanceJoint(this)};Box2D.Dynamics.Joints.b2FrictionJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_linearMass=Box2D.Common.Math.b2Mat22.Get();this.m_linearImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_linearMass.SetZero();this.m_angularMass=0;this.m_linearImpulse.SetZero();this.m_angularImpulse=0;this.m_maxForce=a.maxForce;this.m_maxTorque=a.maxTorque};Box2D.inherits(Box2D.Dynamics.Joints.b2FrictionJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return new Box2D.Common.Math.b2Vec2.Get(a*this.m_linearImpulse.x,a*this.m_linearImpulse.y)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return a*this.m_angularImpulse};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxForce=function(a){if(a===undefined){a=0}this.m_maxForce=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxForce=function(){return this.m_maxForce};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxTorque=function(a){if(a===undefined){a=0}this.m_maxTorque=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxTorque=function(){return this.m_maxTorque};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.InitVelocityConstraints=function(d){var k;var m=0;var b=this.m_bodyA;var a=this.m_bodyB;k=b.m_xf.R;var g=this.m_localAnchorA.x-b.m_sweep.localCenter.x;var f=this.m_localAnchorA.y-b.m_sweep.localCenter.y;m=(k.col1.x*g+k.col2.x*f);f=(k.col1.y*g+k.col2.y*f);g=m;k=a.m_xf.R;var o=this.m_localAnchorB.x-a.m_sweep.localCenter.x;var n=this.m_localAnchorB.y-a.m_sweep.localCenter.y;m=(k.col1.x*o+k.col2.x*n);n=(k.col1.y*o+k.col2.y*n);o=m;var e=b.m_invMass;var c=a.m_invMass;var j=b.m_invI;var i=a.m_invI;var l=new b2Mat22();l.col1.x=e+c;l.col2.x=0;l.col1.y=0;l.col2.y=e+c;l.col1.x+=j*f*f;l.col2.x+=(-j*g*f);l.col1.y+=(-j*g*f);l.col2.y+=j*g*g;l.col1.x+=i*n*n;l.col2.x+=(-i*o*n);l.col1.y+=(-i*o*n);l.col2.y+=i*o*o;l.GetInverse(this.m_linearMass);this.m_angularMass=j+i;if(this.m_angularMass>0){this.m_angularMass=1/this.m_angularMass}if(d.warmStarting){this.m_linearImpulse.x*=d.dtRatio;this.m_linearImpulse.y*=d.dtRatio;this.m_angularImpulse*=d.dtRatio;var h=this.m_linearImpulse;b.m_linearVelocity.x-=e*h.x;b.m_linearVelocity.y-=e*h.y;b.m_angularVelocity-=j*(g*h.y-f*h.x+this.m_angularImpulse);a.m_linearVelocity.x+=c*h.x;a.m_linearVelocity.y+=c*h.y;a.m_angularVelocity+=i*(o*h.y-n*h.x+this.m_angularImpulse)}else{this.m_linearImpulse.SetZero();this.m_angularImpulse=0}};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolveVelocityConstraints=function(h){var m;var p=0;var y=this.m_bodyA;var x=this.m_bodyB;var w=y.m_linearVelocity;var c=y.m_angularVelocity;var v=x.m_linearVelocity;var b=x.m_angularVelocity;var u=y.m_invMass;var t=x.m_invMass;var k=y.m_invI;var j=x.m_invI;m=y.m_xf.R;var i=this.m_localAnchorA.x-y.m_sweep.localCenter.x;var g=this.m_localAnchorA.y-y.m_sweep.localCenter.y;p=(m.col1.x*i+m.col2.x*g);g=(m.col1.y*i+m.col2.y*g);i=p;m=x.m_xf.R;var r=this.m_localAnchorB.x-x.m_sweep.localCenter.x;var q=this.m_localAnchorB.y-x.m_sweep.localCenter.y;p=(m.col1.x*r+m.col2.x*q);q=(m.col1.y*r+m.col2.y*q);r=p;var n=0;var o=b-c;var l=(-this.m_angularMass*o);var e=this.m_angularImpulse;n=h.dt*this.m_maxTorque;this.m_angularImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_angularImpulse+l,(-n),n);l=this.m_angularImpulse-e;c-=k*l;b+=j*l;var f=v.x-b*q-w.x+c*g;var d=v.y+b*r-w.y-c*i;var a=Box2D.Common.Math.b2Vec2.Get((-f),(-d));a.MulM(this.m_linearMass);var s=this.m_linearImpulse.Copy();this.m_linearImpulse.Add(a);Box2D.Common.Math.b2Vec2.Free(a);n=h.dt*this.m_maxForce;if(this.m_linearImpulse.LengthSquared()>n*n){this.m_linearImpulse.Normalize();this.m_linearImpulse.Multiply(n)}a=Box2D.Common.Math.b2Math.SubtractVV(this.m_linearImpulse,s);Box2D.Common.Math.b2Vec2.Free(s);w.x-=u*a.x;w.y-=u*a.y;c-=k*(i*a.y-g*a.x);v.x+=t*a.x;v.y+=t*a.y;b+=j*(r*a.y-q*a.x);Box2D.Common.Math.b2Vec2.Free(a);y.m_angularVelocity=c;x.m_angularVelocity=b};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolvePositionConstraints=function(a){return true};Box2D.Dynamics.Joints.b2FrictionJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_frictionJoint;this.maxForce=0;this.maxTorque=0};Box2D.inherits(Box2D.Dynamics.Joints.b2FrictionJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Initialize=function(c,b,a){this.bodyA=c;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(a));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(a))};Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2FrictionJoint(this)};Box2D.Dynamics.Joints.b2GearJoint=function(c){Box2D.Dynamics.Joints.b2Joint.call(this,c);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_J=new Box2D.Dynamics.Joints.b2Jacobian();var b=c.joint1.m_type;var a=c.joint2.m_type;this.m_revolute1=null;this.m_prismatic1=null;this.m_revolute2=null;this.m_prismatic2=null;var e=0;var d=0;this.m_ground1=c.joint1.GetBodyA();this.m_bodyA=c.joint1.GetBodyB();if(b==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint){this.m_revolute1=c.joint1;this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1);this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2);e=this.m_revolute1.GetJointAngle()}else{this.m_prismatic1=c.joint1;this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1);this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2);e=this.m_prismatic1.GetJointTranslation()}this.m_ground2=c.joint2.GetBodyA();this.m_bodyB=c.joint2.GetBodyB();if(a==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint){this.m_revolute2=c.joint2;this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1);this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2);d=this.m_revolute2.GetJointAngle()}else{this.m_prismatic2=c.joint2;this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1);this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2);d=this.m_prismatic2.GetJointTranslation()}this.m_ratio=c.ratio;this.m_constant=e+this.m_ratio*d;this.m_impulse=0};Box2D.inherits(Box2D.Dynamics.Joints.b2GearJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_J.linearB.x,a*this.m_impulse*this.m_J.linearB.y)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionTorque=function(e){if(e===undefined){e=0}var c=this.m_bodyB.m_xf.R;var g=this.m_localAnchor1.x-this.m_bodyB.m_sweep.localCenter.x;var f=this.m_localAnchor1.y-this.m_bodyB.m_sweep.localCenter.y;var a=c.col1.x*g+c.col2.x*f;f=c.col1.y*g+c.col2.y*f;g=a;var d=this.m_impulse*this.m_J.linearB.x;var b=this.m_impulse*this.m_J.linearB.y;return e*(this.m_impulse*this.m_J.angularB-g*b+f*d)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetRatio=function(){return this.m_ratio};Box2D.Dynamics.Joints.b2GearJoint.prototype.SetRatio=function(a){if(a===undefined){a=0}this.m_ratio=a};Box2D.Dynamics.Joints.b2GearJoint.prototype.InitVelocityConstraints=function(d){var b=this.m_ground1;var n=this.m_ground2;var c=this.m_bodyA;var a=this.m_bodyB;var k=0;var i=0;var f=0;var e=0;var g;var m;var j=0;var l=0;var h=0;this.m_J.SetZero();if(this.m_revolute1){this.m_J.angularA=(-1);h+=c.m_invI}else{g=b.m_xf.R;m=this.m_prismatic1.m_localXAxis1;k=g.col1.x*m.x+g.col2.x*m.y;i=g.col1.y*m.x+g.col2.y*m.y;g=c.m_xf.R;f=this.m_localAnchor1.x-c.m_sweep.localCenter.x;e=this.m_localAnchor1.y-c.m_sweep.localCenter.y;l=g.col1.x*f+g.col2.x*e;e=g.col1.y*f+g.col2.y*e;f=l;j=f*i-e*k;this.m_J.linearA.Set((-k),(-i));this.m_J.angularA=(-j);h+=c.m_invMass+c.m_invI*j*j}if(this.m_revolute2){this.m_J.angularB=(-this.m_ratio);h+=this.m_ratio*this.m_ratio*a.m_invI}else{g=n.m_xf.R;m=this.m_prismatic2.m_localXAxis1;k=g.col1.x*m.x+g.col2.x*m.y;i=g.col1.y*m.x+g.col2.y*m.y;g=a.m_xf.R;f=this.m_localAnchor2.x-a.m_sweep.localCenter.x;e=this.m_localAnchor2.y-a.m_sweep.localCenter.y;l=g.col1.x*f+g.col2.x*e;e=g.col1.y*f+g.col2.y*e;f=l;j=f*i-e*k;this.m_J.linearB.Set((-this.m_ratio*k),(-this.m_ratio*i));this.m_J.angularB=(-this.m_ratio*j);h+=this.m_ratio*this.m_ratio*(a.m_invMass+a.m_invI*j*j)}this.m_mass=h>0?1/h:0;if(d.warmStarting){c.m_linearVelocity.x+=c.m_invMass*this.m_impulse*this.m_J.linearA.x;c.m_linearVelocity.y+=c.m_invMass*this.m_impulse*this.m_J.linearA.y;c.m_angularVelocity+=c.m_invI*this.m_impulse*this.m_J.angularA;a.m_linearVelocity.x+=a.m_invMass*this.m_impulse*this.m_J.linearB.x;a.m_linearVelocity.y+=a.m_invMass*this.m_impulse*this.m_J.linearB.y;a.m_angularVelocity+=a.m_invI*this.m_impulse*this.m_J.angularB}else{this.m_impulse=0}};Box2D.Dynamics.Joints.b2GearJoint.prototype.SolveVelocityConstraints=function(a){var d=this.m_bodyA;var c=this.m_bodyB;var e=this.m_J.Compute(d.m_linearVelocity,d.m_angularVelocity,c.m_linearVelocity,c.m_angularVelocity);var b=(-this.m_mass*e);this.m_impulse+=b;d.m_linearVelocity.x+=d.m_invMass*b*this.m_J.linearA.x;d.m_linearVelocity.y+=d.m_invMass*b*this.m_J.linearA.y;d.m_angularVelocity+=d.m_invI*b*this.m_J.angularA;c.m_linearVelocity.x+=c.m_invMass*b*this.m_J.linearB.x;c.m_linearVelocity.y+=c.m_invMass*b*this.m_J.linearB.y;c.m_angularVelocity+=c.m_invI*b*this.m_J.angularB};Box2D.Dynamics.Joints.b2GearJoint.prototype.SolvePositionConstraints=function(a){if(a===undefined){a=0}var h=0;var g=this.m_bodyA;var d=this.m_bodyB;var f=0;var c=0;if(this.m_revolute1){f=this.m_revolute1.GetJointAngle()}else{f=this.m_prismatic1.GetJointTranslation()}if(this.m_revolute2){c=this.m_revolute2.GetJointAngle()}else{c=this.m_prismatic2.GetJointTranslation()}var e=this.m_constant-(f+this.m_ratio*c);var b=(-this.m_mass*e);g.m_sweep.c.x+=g.m_invMass*b*this.m_J.linearA.x;g.m_sweep.c.y+=g.m_invMass*b*this.m_J.linearA.y;g.m_sweep.a+=g.m_invI*b*this.m_J.angularA;d.m_sweep.c.x+=d.m_invMass*b*this.m_J.linearB.x;d.m_sweep.c.y+=d.m_invMass*b*this.m_J.linearB.y;d.m_sweep.a+=d.m_invI*b*this.m_J.angularB;g.SynchronizeTransform();d.SynchronizeTransform();return h<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2GearJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.type=Box2D.Dynamics.Joints.b2Joint.e_gearJoint;this.joint1=null;this.joint2=null;this.ratio=1};Box2D.inherits(Box2D.Dynamics.Joints.b2GearJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2GearJointDef.prototype.Initialize=function(a,c,b){this.joint1=a;this.bodyA=a.GetBodyA();this.joint2=c;this.bodyB=c.GetBodyA();this.ratio=b};Box2D.Dynamics.Joints.b2GearJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2GearJoint(this)};Box2D.Dynamics.Joints.b2Jacobian=function(){this.linearA=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearB=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.Joints.b2Jacobian.prototype.SetZero=function(){this.linearA.SetZero();this.angularA=0;this.linearB.SetZero();this.angularB=0};Box2D.Dynamics.Joints.b2Jacobian.prototype.Set=function(d,b,c,a){if(b===undefined){b=0}if(a===undefined){a=0}this.linearA.SetV(d);this.angularA=b;this.linearB.SetV(c);this.angularB=a};Box2D.Dynamics.Joints.b2Jacobian.prototype.Compute=function(d,b,c,a){if(b===undefined){b=0}if(a===undefined){a=0}return(this.linearA.x*d.x+this.linearA.y*d.y)+this.angularA*b+(this.linearB.x*c.x+this.linearB.y*c.y)+this.angularB*a};Box2D.Dynamics.Joints.b2JointEdge=function(){};Box2D.Dynamics.Joints.b2LineJoint=function(c){Box2D.Dynamics.Joints.b2Joint.call(this,c);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=Box2D.Common.Math.b2Mat22.Get();this.m_impulse=Box2D.Common.Math.b2Vec2.Get(0,0);var b;var a=0;var d=0;this.m_localAnchor1.SetV(c.localAnchorA);this.m_localAnchor2.SetV(c.localAnchorB);this.m_localXAxis1.SetV(c.localAxisA);this.m_localYAxis1.x=(-this.m_localXAxis1.y);this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_impulse.SetZero();this.m_motorMass=0;this.m_motorImpulse=0;this.m_lowerTranslation=c.lowerTranslation;this.m_upperTranslation=c.upperTranslation;this.m_maxMotorForce=c.maxMotorForce;this.m_motorSpeed=c.motorSpeed;this.m_enableLimit=c.enableLimit;this.m_enableMotor=c.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};Box2D.inherits(Box2D.Dynamics.Joints.b2LineJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y))};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return a*this.m_impulse.y};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointTranslation=function(){var c=this.m_bodyA;var b=this.m_bodyB;var g;var i=c.GetWorldPoint(this.m_localAnchor1);var h=b.GetWorldPoint(this.m_localAnchor2);var f=h.x-i.x;var e=h.y-i.y;var d=c.GetWorldVector(this.m_localXAxis1);var a=d.x*f+d.y*e;return a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointSpeed=function(){var t=this.m_bodyA;var s=this.m_bodyB;var j;j=t.m_xf.R;var r=this.m_localAnchor1.x-t.m_sweep.localCenter.x;var q=this.m_localAnchor1.y-t.m_sweep.localCenter.y;var m=(j.col1.x*r+j.col2.x*q);q=(j.col1.y*r+j.col2.y*q);r=m;j=s.m_xf.R;var i=this.m_localAnchor2.x-s.m_sweep.localCenter.x;var h=this.m_localAnchor2.y-s.m_sweep.localCenter.y;m=(j.col1.x*i+j.col2.x*h);h=(j.col1.y*i+j.col2.y*h);i=m;var p=t.m_sweep.c.x+r;var n=t.m_sweep.c.y+q;var c=s.m_sweep.c.x+i;var a=s.m_sweep.c.y+h;var g=c-p;var f=a-n;var e=t.GetWorldVector(this.m_localXAxis1);var d=t.m_linearVelocity;var b=s.m_linearVelocity;var l=t.m_angularVelocity;var k=s.m_angularVelocity;var o=(g*((-l*e.y))+f*(l*e.x))+(e.x*(((b.x+((-k*h)))-d.x)-((-l*q)))+e.y*(((b.y+(k*i))-d.y)-(l*r)));return o};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_enableLimit=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetUpperLimit=function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetLimits=function(a,b){if(a===undefined){a=0}if(b===undefined){b=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_enableMotor=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMotorSpeed=function(a){if(a===undefined){a=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMaxMotorForce=function(a){if(a===undefined){a=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMaxMotorForce=function(){return this.m_maxMotorForce};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorForce=function(){return this.m_motorImpulse};Box2D.Dynamics.Joints.b2LineJoint.prototype.InitVelocityConstraints=function(i){var v=this.m_bodyA;var u=this.m_bodyB;var l;var m=0;this.m_localCenterA.SetV(v.GetLocalCenter());this.m_localCenterB.SetV(u.GetLocalCenter());var d=v.GetTransform();var b=u.GetTransform();l=v.m_xf.R;var t=this.m_localAnchor1.x-this.m_localCenterA.x;var r=this.m_localAnchor1.y-this.m_localCenterA.y;m=(l.col1.x*t+l.col2.x*r);r=(l.col1.y*t+l.col2.y*r);t=m;l=u.m_xf.R;var h=this.m_localAnchor2.x-this.m_localCenterB.x;var g=this.m_localAnchor2.y-this.m_localCenterB.y;m=(l.col1.x*h+l.col2.x*g);g=(l.col1.y*h+l.col2.y*g);h=m;var f=u.m_sweep.c.x+h-v.m_sweep.c.x-t;var e=u.m_sweep.c.y+g-v.m_sweep.c.y-r;this.m_invMassA=v.m_invMass;this.m_invMassB=u.m_invMass;this.m_invIA=v.m_invI;this.m_invIB=u.m_invI;this.m_axis.SetV(Box2D.Common.Math.b2Math.MulMV(d.R,this.m_localXAxis1));this.m_a1=(f+t)*this.m_axis.y-(e+r)*this.m_axis.x;this.m_a2=h*this.m_axis.y-g*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2;this.m_motorMass=this.m_motorMass>Number.MIN_VALUE?1/this.m_motorMass:0;this.m_perp.SetV(Box2D.Common.Math.b2Math.MulMV(d.R,this.m_localYAxis1));this.m_s1=(f+t)*this.m_perp.y-(e+r)*this.m_perp.x;this.m_s2=h*this.m_perp.y-g*this.m_perp.x;var c=this.m_invMassA;var a=this.m_invMassB;var o=this.m_invIA;var n=this.m_invIB;this.m_K.col1.x=c+a+o*this.m_s1*this.m_s1+n*this.m_s2*this.m_s2;this.m_K.col1.y=o*this.m_s1*this.m_a1+n*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=c+a+o*this.m_a1*this.m_a1+n*this.m_a2*this.m_a2;if(this.m_enableLimit){var s=this.m_axis.x*f+this.m_axis.y*e;if(Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits}else{if(s<=this.m_lowerTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit;this.m_impulse.y=0}}else{if(s>=this.m_upperTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;this.m_impulse.y=0}}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_impulse.y=0}}}}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit}if(this.m_enableMotor==false){this.m_motorImpulse=0}if(i.warmStarting){this.m_impulse.x*=i.dtRatio;this.m_impulse.y*=i.dtRatio;this.m_motorImpulse*=i.dtRatio;var k=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x;var j=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y;var q=this.m_impulse.x*this.m_s1+(this.m_motorImpulse+this.m_impulse.y)*this.m_a1;var p=this.m_impulse.x*this.m_s2+(this.m_motorImpulse+this.m_impulse.y)*this.m_a2;v.m_linearVelocity.x-=this.m_invMassA*k;v.m_linearVelocity.y-=this.m_invMassA*j;v.m_angularVelocity-=this.m_invIA*q;u.m_linearVelocity.x+=this.m_invMassB*k;u.m_linearVelocity.y+=this.m_invMassB*j;u.m_angularVelocity+=this.m_invIB*p}else{this.m_impulse.SetZero();this.m_motorImpulse=0}};Box2D.Dynamics.Joints.b2LineJoint.prototype.SolveVelocityConstraints=function(h){var x=this.m_bodyA;var u=this.m_bodyB;var f=x.m_linearVelocity;var m=x.m_angularVelocity;var e=u.m_linearVelocity;var l=u.m_angularVelocity;var j=0;var i=0;var r=0;var q=0;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits){var o=this.m_axis.x*(e.x-f.x)+this.m_axis.y*(e.y-f.y)+this.m_a2*l-this.m_a1*m;var k=this.m_motorMass*(this.m_motorSpeed-o);var g=this.m_motorImpulse;var n=h.dt*this.m_maxMotorForce;this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+k,(-n),n);k=this.m_motorImpulse-g;j=k*this.m_axis.x;i=k*this.m_axis.y;r=k*this.m_a1;q=k*this.m_a2;f.x-=this.m_invMassA*j;f.y-=this.m_invMassA*i;m-=this.m_invIA*r;e.x+=this.m_invMassB*j;e.y+=this.m_invMassB*i;l+=this.m_invIB*q}var d=this.m_perp.x*(e.x-f.x)+this.m_perp.y*(e.y-f.y)+this.m_s2*l-this.m_s1*m;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var c=this.m_axis.x*(e.x-f.x)+this.m_axis.y*(e.y-f.y)+this.m_a2*l-this.m_a1*m;var p=this.m_impulse.Copy();var w=Box2D.Common.Math.b2Vec2.Get(0,0);var s=this.m_K.Solve(w,(-d),(-c));Box2D.Common.Math.b2Vec2.Free(w);this.m_impulse.Add(s);if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){this.m_impulse.y=Math.max(this.m_impulse.y,0)}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){this.m_impulse.y=Math.min(this.m_impulse.y,0)}}var t=(-d)-(this.m_impulse.y-p.y)*this.m_K.col2.x;var a=0;if(this.m_K.col1.x!=0){a=t/this.m_K.col1.x+p.x}else{a=p.x}this.m_impulse.x=a;s.x=this.m_impulse.x-p.x;s.y=this.m_impulse.y-p.y;Box2D.Common.Math.b2Vec2.Free(p);j=s.x*this.m_perp.x+s.y*this.m_axis.x;i=s.x*this.m_perp.y+s.y*this.m_axis.y;r=s.x*this.m_s1+s.y*this.m_a1;q=s.x*this.m_s2+s.y*this.m_a2;f.x-=this.m_invMassA*j;f.y-=this.m_invMassA*i;m-=this.m_invIA*r;e.x+=this.m_invMassB*j;e.y+=this.m_invMassB*i;l+=this.m_invIB*q}else{var v=0;if(this.m_K.col1.x!=0){v=((-d))/this.m_K.col1.x}else{v=0}this.m_impulse.x+=v;j=v*this.m_perp.x;i=v*this.m_perp.y;r=v*this.m_s1;q=v*this.m_s2;f.x-=this.m_invMassA*j;f.y-=this.m_invMassA*i;m-=this.m_invIA*r;e.x+=this.m_invMassB*j;e.y+=this.m_invMassB*i;l+=this.m_invIB*q}x.m_linearVelocity.SetV(f);x.m_angularVelocity=m;u.m_linearVelocity.SetV(e);u.m_angularVelocity=l};Box2D.Dynamics.Joints.b2LineJoint.prototype.SolvePositionConstraints=function(l){if(l===undefined){l=0}var a=0;var w=0;var j=this.m_bodyA;var i=this.m_bodyB;var e=j.m_sweep.c;var A=j.m_sweep.a;var d=i.m_sweep.c;var z=i.m_sweep.a;var B;var h=0;var H=0;var G=0;var g=0;var f=0;var c=0;var k=0;var D=false;var q=0;var v=Box2D.Common.Math.b2Mat22.FromAngle(A);var u=Box2D.Common.Math.b2Mat22.FromAngle(z);B=v;var F=this.m_localAnchor1.x-this.m_localCenterA.x;var E=this.m_localAnchor1.y-this.m_localCenterA.y;h=(B.col1.x*F+B.col2.x*E);E=(B.col1.y*F+B.col2.y*E);F=h;B=u;var p=this.m_localAnchor2.x-this.m_localCenterB.x;var o=this.m_localAnchor2.y-this.m_localCenterB.y;h=(B.col1.x*p+B.col2.x*o);o=(B.col1.y*p+B.col2.y*o);p=h;var n=d.x+p-e.x-F;var m=d.y+o-e.y-E;if(this.m_enableLimit){this.m_axis=Box2D.Common.Math.b2Math.MulMV(v,this.m_localXAxis1);this.m_a1=(n+F)*this.m_axis.y-(m+E)*this.m_axis.x;this.m_a2=p*this.m_axis.y-o*this.m_axis.x;var C=this.m_axis.x*n+this.m_axis.y*m;if(Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop){q=Box2D.Common.Math.b2Math.Clamp(C,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),Box2D.Common.b2Settings.b2_maxLinearCorrection);c=Math.abs(C);D=true}else{if(C<=this.m_lowerTranslation){q=Box2D.Common.Math.b2Math.Clamp(C-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);c=this.m_lowerTranslation-C;D=true}else{if(C>=this.m_upperTranslation){q=Box2D.Common.Math.b2Math.Clamp(C-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection);c=C-this.m_upperTranslation;D=true}}}}this.m_perp=Box2D.Common.Math.b2Math.MulMV(v,this.m_localYAxis1);this.m_s1=(n+F)*this.m_perp.y-(m+E)*this.m_perp.x;this.m_s2=p*this.m_perp.y-o*this.m_perp.x;var x=Box2D.Common.Math.b2Vec2.Get(0,0);var r=this.m_perp.x*n+this.m_perp.y*m;c=Math.max(c,Math.abs(r));k=0;if(D){H=this.m_invMassA;G=this.m_invMassB;g=this.m_invIA;f=this.m_invIB;this.m_K.col1.x=H+G+g*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2;this.m_K.col1.y=g*this.m_s1*this.m_a1+f*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=H+G+g*this.m_a1*this.m_a1+f*this.m_a2*this.m_a2;this.m_K.Solve(x,(-r),(-q))}else{H=this.m_invMassA;G=this.m_invMassB;g=this.m_invIA;f=this.m_invIB;var b=H+G+g*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2;var y=0;if(b!=0){y=((-r))/b}else{y=0}x.x=y;x.y=0}var J=x.x*this.m_perp.x+x.y*this.m_axis.x;var I=x.x*this.m_perp.y+x.y*this.m_axis.y;var t=x.x*this.m_s1+x.y*this.m_a1;var s=x.x*this.m_s2+x.y*this.m_a2;e.x-=this.m_invMassA*J;e.y-=this.m_invMassA*I;A-=this.m_invIA*t;d.x+=this.m_invMassB*J;d.y+=this.m_invMassB*I;z+=this.m_invIB*s;j.m_sweep.a=A;i.m_sweep.a=z;j.SynchronizeTransform();i.SynchronizeTransform();return c<=Box2D.Common.b2Settings.b2_linearSlop&&k<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2LineJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_lineJoint;this.localAxisA.Set(1,0);this.enableLimit=false;this.lowerTranslation=0;this.upperTranslation=0;this.enableMotor=false;this.maxMotorForce=0;this.motorSpeed=0};Box2D.inherits(Box2D.Dynamics.Joints.b2LineJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2LineJointDef.prototype.Initialize=function(d,c,a,b){this.bodyA=d;this.bodyB=c;this.localAnchorA=this.bodyA.GetLocalPoint(a);this.localAnchorB=this.bodyB.GetLocalPoint(a);this.localAxisA=this.bodyA.GetLocalVector(b)};Box2D.Dynamics.Joints.b2LineJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2LineJoint(this)};Box2D.Dynamics.Joints.b2MouseJoint=function(c){Box2D.Dynamics.Joints.b2Joint.call(this,c);this.K=Box2D.Common.Math.b2Mat22.Get();this.K1=Box2D.Common.Math.b2Mat22.Get();this.K2=Box2D.Common.Math.b2Mat22.Get();this.m_localAnchor=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_target=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_mass=Box2D.Common.Math.b2Mat22.Get();this.m_C=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_target.SetV(c.target);var a=this.m_target.x-this.m_bodyB.m_xf.position.x;var d=this.m_target.y-this.m_bodyB.m_xf.position.y;var b=this.m_bodyB.m_xf.R;this.m_localAnchor.x=(a*b.col1.x+d*b.col1.y);this.m_localAnchor.y=(a*b.col2.x+d*b.col2.y);this.m_maxForce=c.maxForce;this.m_impulse.SetZero();this.m_frequencyHz=c.frequencyHz;this.m_dampingRatio=c.dampingRatio;this.m_beta=0;this.m_gamma=0};Box2D.inherits(Box2D.Dynamics.Joints.b2MouseJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetAnchorA=function(){return Box2D.Common.Math.b2Vec2.Get(this.m_target.x,this.m_target.y)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return 0};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetTarget=function(){return this.m_target};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetTarget=function(a){if(this.m_bodyB.IsAwake()==false){this.m_bodyB.SetAwake(true)}this.m_target=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetMaxForce=function(){return this.m_maxForce};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetMaxForce=function(a){if(a===undefined){a=0}this.m_maxForce=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetFrequency=function(){return this.m_frequencyHz};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetFrequency=function(a){if(a===undefined){a=0}this.m_frequencyHz=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetDampingRatio=function(){return this.m_dampingRatio};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetDampingRatio=function(a){if(a===undefined){a=0}this.m_dampingRatio=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.InitVelocityConstraints=function(a){var m=this.m_bodyB;var j=m.GetMass();var o=2*Math.PI*this.m_frequencyHz;var i=2*j*this.m_dampingRatio*o;var f=j*o*o;this.m_gamma=a.dt*(i+a.dt*f);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:0;this.m_beta=a.dt*f*this.m_gamma;var l;l=m.m_xf.R;var h=this.m_localAnchor.x-m.m_sweep.localCenter.x;var g=this.m_localAnchor.y-m.m_sweep.localCenter.y;var n=(l.col1.x*h+l.col2.x*g);g=(l.col1.y*h+l.col2.y*g);h=n;var e=m.m_invMass;var c=m.m_invI;this.K1.col1.x=e;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=e;this.K2.col1.x=c*g*g;this.K2.col2.x=(-c*h*g);this.K2.col1.y=(-c*h*g);this.K2.col2.y=c*h*h;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.col1.x+=this.m_gamma;this.K.col2.y+=this.m_gamma;this.K.GetInverse(this.m_mass);this.m_C.x=m.m_sweep.c.x+h-this.m_target.x;this.m_C.y=m.m_sweep.c.y+g-this.m_target.y;m.m_angularVelocity*=0.98;this.m_impulse.x*=a.dtRatio;this.m_impulse.y*=a.dtRatio;m.m_linearVelocity.x+=e*this.m_impulse.x;m.m_linearVelocity.y+=e*this.m_impulse.y;m.m_angularVelocity+=c*(h*this.m_impulse.y-g*this.m_impulse.x)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SolveVelocityConstraints=function(e){var l=this.m_bodyB;var k;var n=0;var m=0;k=l.m_xf.R;var i=this.m_localAnchor.x-l.m_sweep.localCenter.x;var g=this.m_localAnchor.y-l.m_sweep.localCenter.y;n=(k.col1.x*i+k.col2.x*g);g=(k.col1.y*i+k.col2.y*g);i=n;var a=l.m_linearVelocity.x+((-l.m_angularVelocity*g));var o=l.m_linearVelocity.y+(l.m_angularVelocity*i);k=this.m_mass;n=a+this.m_beta*this.m_C.x+this.m_gamma*this.m_impulse.x;m=o+this.m_beta*this.m_C.y+this.m_gamma*this.m_impulse.y;var f=(-(k.col1.x*n+k.col2.x*m));var d=(-(k.col1.y*n+k.col2.y*m));var j=this.m_impulse.x;var h=this.m_impulse.y;this.m_impulse.x+=f;this.m_impulse.y+=d;var c=e.dt*this.m_maxForce;if(this.m_impulse.LengthSquared()>c*c){this.m_impulse.Multiply(c/this.m_impulse.Length())}f=this.m_impulse.x-j;d=this.m_impulse.y-h;l.m_linearVelocity.x+=l.m_invMass*f;l.m_linearVelocity.y+=l.m_invMass*d;l.m_angularVelocity+=l.m_invI*(i*d-g*f)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SolvePositionConstraints=function(a){return true};Box2D.Dynamics.Joints.b2MouseJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.target=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_mouseJoint;this.maxForce=0;this.frequencyHz=5;this.dampingRatio=0.7};Box2D.inherits(Box2D.Dynamics.Joints.b2MouseJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2MouseJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2MouseJoint(this)};Box2D.Dynamics.Joints.b2PrismaticJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=new Box2D.Common.Math.b2Mat33();this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=(-this.m_localXAxis1.y);this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_refAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorMass=0;this.m_motorImpulse=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};Box2D.inherits(Box2D.Dynamics.Joints.b2PrismaticJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y))};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return a*this.m_impulse.y};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointTranslation=function(){var g=this.m_bodyA;var e=this.m_bodyB;var f=g.GetWorldPoint(this.m_localAnchor1);var d=e.GetWorldPoint(this.m_localAnchor2);var b=d.x-f.x;var a=d.y-f.y;Box2D.Common.Math.b2Vec2.Free(f);Box2D.Common.Math.b2Vec2.Free(d);var c=g.GetWorldVector(this.m_localXAxis1);var h=c.x*b+c.y*a;Box2D.Common.Math.b2Vec2.Free(c);return h};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointSpeed=function(){var t=this.m_bodyA;var s=this.m_bodyB;var j;j=t.m_xf.R;var r=this.m_localAnchor1.x-t.m_sweep.localCenter.x;var q=this.m_localAnchor1.y-t.m_sweep.localCenter.y;var m=(j.col1.x*r+j.col2.x*q);q=(j.col1.y*r+j.col2.y*q);r=m;j=s.m_xf.R;var i=this.m_localAnchor2.x-s.m_sweep.localCenter.x;var h=this.m_localAnchor2.y-s.m_sweep.localCenter.y;m=(j.col1.x*i+j.col2.x*h);h=(j.col1.y*i+j.col2.y*h);i=m;var p=t.m_sweep.c.x+r;var n=t.m_sweep.c.y+q;var c=s.m_sweep.c.x+i;var a=s.m_sweep.c.y+h;var g=c-p;var f=a-n;var e=t.GetWorldVector(this.m_localXAxis1);var d=t.m_linearVelocity;var b=s.m_linearVelocity;var l=t.m_angularVelocity;var k=s.m_angularVelocity;var o=(g*((-l*e.y))+f*(l*e.x))+(e.x*(((b.x+((-k*h)))-d.x)-((-l*q)))+e.y*(((b.y+(k*i))-d.y)-(l*r)));Box2D.Common.Math.b2Vec2.Free(e);return o};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_enableLimit=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetUpperLimit=function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetLimits=function(a,b){if(a===undefined){a=0}if(b===undefined){b=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_enableMotor=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMotorSpeed=function(a){if(a===undefined){a=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMaxMotorForce=function(a){if(a===undefined){a=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorForce=function(){return this.m_motorImpulse};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.InitVelocityConstraints=function(h){var w=this.m_bodyA;var v=this.m_bodyB;var l;var n=0;this.m_localCenterA.SetV(w.GetLocalCenter());this.m_localCenterB.SetV(v.GetLocalCenter());var c=w.GetTransform();l=w.m_xf.R;var u=this.m_localAnchor1.x-this.m_localCenterA.x;var s=this.m_localAnchor1.y-this.m_localCenterA.y;n=(l.col1.x*u+l.col2.x*s);s=(l.col1.y*u+l.col2.y*s);u=n;l=v.m_xf.R;var g=this.m_localAnchor2.x-this.m_localCenterB.x;var f=this.m_localAnchor2.y-this.m_localCenterB.y;n=(l.col1.x*g+l.col2.x*f);f=(l.col1.y*g+l.col2.y*f);g=n;var e=v.m_sweep.c.x+g-w.m_sweep.c.x-u;var d=v.m_sweep.c.y+f-w.m_sweep.c.y-s;this.m_invMassA=w.m_invMass;this.m_invMassB=v.m_invMass;this.m_invIA=w.m_invI;this.m_invIB=v.m_invI;var m=Box2D.Common.Math.b2Math.MulMV(c.R,this.m_localXAxis1);this.m_axis.SetV(m);Box2D.Common.Math.b2Vec2.Free(m);this.m_a1=(e+u)*this.m_axis.y-(d+s)*this.m_axis.x;this.m_a2=g*this.m_axis.y-f*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2;if(this.m_motorMass>Number.MIN_VALUE){this.m_motorMass=1/this.m_motorMass}var k=Box2D.Common.Math.b2Math.MulMV(c.R,this.m_localYAxis1);this.m_perp.SetV(k);Box2D.Common.Math.b2Vec2.Free(k);this.m_s1=(e+u)*this.m_perp.y-(d+s)*this.m_perp.x;this.m_s2=g*this.m_perp.y-f*this.m_perp.x;var b=this.m_invMassA;var a=this.m_invMassB;var p=this.m_invIA;var o=this.m_invIB;this.m_K.col1.x=b+a+p*this.m_s1*this.m_s1+o*this.m_s2*this.m_s2;this.m_K.col1.y=p*this.m_s1+o*this.m_s2;this.m_K.col1.z=p*this.m_s1*this.m_a1+o*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=p+o;this.m_K.col2.z=p*this.m_a1+o*this.m_a2;this.m_K.col3.x=this.m_K.col1.z;this.m_K.col3.y=this.m_K.col2.z;this.m_K.col3.z=b+a+p*this.m_a1*this.m_a1+o*this.m_a2*this.m_a2;if(this.m_enableLimit){var t=this.m_axis.x*e+this.m_axis.y*d;if(Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits}else{if(t<=this.m_lowerTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit;this.m_impulse.z=0}}else{if(t>=this.m_upperTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;this.m_impulse.z=0}}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_impulse.z=0}}}}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit}if(this.m_enableMotor==false){this.m_motorImpulse=0}if(h.warmStarting){this.m_impulse.x*=h.dtRatio;this.m_impulse.y*=h.dtRatio;this.m_motorImpulse*=h.dtRatio;var j=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x;var i=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y;var r=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1;var q=this.m_impulse.x*this.m_s2+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a2;w.m_linearVelocity.x-=this.m_invMassA*j;w.m_linearVelocity.y-=this.m_invMassA*i;w.m_angularVelocity-=this.m_invIA*r;v.m_linearVelocity.x+=this.m_invMassB*j;v.m_linearVelocity.y+=this.m_invMassB*i;v.m_angularVelocity+=this.m_invIB*q}else{this.m_impulse.SetZero();this.m_motorImpulse=0}};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolveVelocityConstraints=function(e){var x=this.m_bodyA;var v=this.m_bodyB;var c=x.m_linearVelocity;var k=x.m_angularVelocity;var b=v.m_linearVelocity;var i=v.m_angularVelocity;var g=0;var f=0;var t=0;var s=0;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits){var n=this.m_axis.x*(b.x-c.x)+this.m_axis.y*(b.y-c.y)+this.m_a2*i-this.m_a1*k;var h=this.m_motorMass*(this.m_motorSpeed-n);var d=this.m_motorImpulse;var m=e.dt*this.m_maxMotorForce;this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+h,(-m),m);h=this.m_motorImpulse-d;g=h*this.m_axis.x;f=h*this.m_axis.y;t=h*this.m_a1;s=h*this.m_a2;c.x-=this.m_invMassA*g;c.y-=this.m_invMassA*f;k-=this.m_invIA*t;b.x+=this.m_invMassB*g;b.y+=this.m_invMassB*f;i+=this.m_invIB*s}var r=this.m_perp.x*(b.x-c.x)+this.m_perp.y*(b.y-c.y)+this.m_s2*i-this.m_s1*k;var p=i-k;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var a=this.m_axis.x*(b.x-c.x)+this.m_axis.y*(b.y-c.y)+this.m_a2*i-this.m_a1*k;var o=this.m_impulse.Copy();var u=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_K.Solve33(u,(-r),(-p),(-a));this.m_impulse.Add(u);if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){this.m_impulse.z=Math.max(this.m_impulse.z,0)}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){this.m_impulse.z=Math.min(this.m_impulse.z,0)}}var l=(-r)-(this.m_impulse.z-o.z)*this.m_K.col3.x;var j=(-p)-(this.m_impulse.z-o.z)*this.m_K.col3.y;var q=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K.Solve22(q,l,j);q.x+=o.x;q.y+=o.y;this.m_impulse.x=q.x;this.m_impulse.y=q.y;Box2D.Common.Math.b2Vec2.Free(q);u.x=this.m_impulse.x-o.x;u.y=this.m_impulse.y-o.y;u.z=this.m_impulse.z-o.z;g=u.x*this.m_perp.x+u.z*this.m_axis.x;f=u.x*this.m_perp.y+u.z*this.m_axis.y;t=u.x*this.m_s1+u.y+u.z*this.m_a1;s=u.x*this.m_s2+u.y+u.z*this.m_a2;Box2D.Common.Math.b2Vec3.Free(u);c.x-=this.m_invMassA*g;c.y-=this.m_invMassA*f;k-=this.m_invIA*t;b.x+=this.m_invMassB*g;b.y+=this.m_invMassB*f;i+=this.m_invIB*s}else{var w=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K.Solve22(w,(-r),(-p));this.m_impulse.x+=w.x;this.m_impulse.y+=w.y;g=w.x*this.m_perp.x;f=w.x*this.m_perp.y;t=w.x*this.m_s1+w.y;s=w.x*this.m_s2+w.y;Box2D.Common.Math.b2Vec2.Free(w);c.x-=this.m_invMassA*g;c.y-=this.m_invMassA*f;k-=this.m_invIA*t;b.x+=this.m_invMassB*g;b.y+=this.m_invMassB*f;i+=this.m_invIB*s}x.m_linearVelocity.SetV(c);x.m_angularVelocity=k;v.m_linearVelocity.SetV(b);v.m_angularVelocity=i};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolvePositionConstraints=function(n){if(n===undefined){n=0}var l=this.m_bodyA;var j=this.m_bodyB;var e=l.m_sweep.c;var B=l.m_sweep.a;var d=j.m_sweep.c;var A=j.m_sweep.a;var h=0;var H=0;var G=0;var g=0;var f=0;var c=0;var m=0;var D=false;var s=0;var w=Box2D.Common.Math.b2Mat22.FromAngle(B);var F=this.m_localAnchor1.x-this.m_localCenterA.x;var E=this.m_localAnchor1.y-this.m_localCenterA.y;h=(w.col1.x*F+w.col2.x*E);E=(w.col1.y*F+w.col2.y*E);Box2D.Common.Math.b2Mat22.Free(w);F=h;var v=Box2D.Common.Math.b2Mat22.FromAngle(A);var r=this.m_localAnchor2.x-this.m_localCenterB.x;var q=this.m_localAnchor2.y-this.m_localCenterB.y;h=(v.col1.x*r+v.col2.x*q);q=(v.col1.y*r+v.col2.y*q);Box2D.Common.Math.b2Mat22.Free(v);r=h;var p=d.x+r-e.x-F;var o=d.y+q-e.y-E;if(this.m_enableLimit){Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.MulMV(w,this.m_localXAxis1);this.m_a1=(p+F)*this.m_axis.y-(o+E)*this.m_axis.x;this.m_a2=r*this.m_axis.y-q*this.m_axis.x;var C=this.m_axis.x*p+this.m_axis.y*o;if(Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop){s=Box2D.Common.Math.b2Math.Clamp(C,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),Box2D.Common.b2Settings.b2_maxLinearCorrection);c=Math.abs(C);D=true}else{if(C<=this.m_lowerTranslation){s=Box2D.Common.Math.b2Math.Clamp(C-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);c=this.m_lowerTranslation-C;D=true}else{if(C>=this.m_upperTranslation){s=Box2D.Common.Math.b2Math.Clamp(C-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection);c=C-this.m_upperTranslation;D=true}}}}Box2D.Common.Math.b2Vec2.Free(this.m_perp);this.m_perp=Box2D.Common.Math.b2Math.MulMV(w,this.m_localYAxis1);this.m_s1=(p+F)*this.m_perp.y-(o+E)*this.m_perp.x;this.m_s2=r*this.m_perp.y-q*this.m_perp.x;var y=Box2D.Common.Math.b2Vec3.Get(0,0,0);var k=this.m_perp.x*p+this.m_perp.y*o;var i=A-B-this.m_refAngle;c=Math.max(c,Math.abs(k));m=Math.abs(i);if(D){H=this.m_invMassA;G=this.m_invMassB;g=this.m_invIA;f=this.m_invIB;this.m_K.col1.x=H+G+g*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2;this.m_K.col1.y=g*this.m_s1+f*this.m_s2;this.m_K.col1.z=g*this.m_s1*this.m_a1+f*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=g+f;this.m_K.col2.z=g*this.m_a1+f*this.m_a2;this.m_K.col3.x=this.m_K.col1.z;this.m_K.col3.y=this.m_K.col2.z;this.m_K.col3.z=H+G+g*this.m_a1*this.m_a1+f*this.m_a2*this.m_a2;this.m_K.Solve33(y,(-k),(-i),(-s))}else{H=this.m_invMassA;G=this.m_invMassB;g=this.m_invIA;f=this.m_invIB;var b=H+G+g*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2;var a=g*this.m_s1+f*this.m_s2;var x=g+f;this.m_K.col1.Set(b,a,0);this.m_K.col2.Set(a,x,0);var z=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K.Solve22(z,(-k),(-i));y.x=z.x;y.y=z.y;Box2D.Common.Math.b2Vec2.Free(z);y.z=0}var J=y.x*this.m_perp.x+y.z*this.m_axis.x;var I=y.x*this.m_perp.y+y.z*this.m_axis.y;var u=y.x*this.m_s1+y.y+y.z*this.m_a1;var t=y.x*this.m_s2+y.y+y.z*this.m_a2;Box2D.Common.Math.b2Vec3.Free(y);e.x-=this.m_invMassA*J;e.y-=this.m_invMassA*I;B-=this.m_invIA*u;d.x+=this.m_invMassB*J;d.y+=this.m_invMassB*I;A+=this.m_invIB*t;l.m_sweep.a=B;j.m_sweep.a=A;l.SynchronizeTransform();j.SynchronizeTransform();return c<=Box2D.Common.b2Settings.b2_linearSlop&&m<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2PrismaticJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint;this.localAxisA.Set(1,0);this.referenceAngle=0;this.enableLimit=false;this.lowerTranslation=0;this.upperTranslation=0;this.enableMotor=false;this.maxMotorForce=0;this.motorSpeed=0};Box2D.inherits(Box2D.Dynamics.Joints.b2PrismaticJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Initialize=function(d,c,a,b){this.bodyA=d;this.bodyB=c;this.localAnchorA=this.bodyA.GetLocalPoint(a);this.localAnchorB=this.bodyB.GetLocalPoint(a);this.localAxisA=this.bodyA.GetLocalVector(b);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PrismaticJoint(this)};Box2D.Dynamics.Joints.b2PulleyJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_ground=this.m_bodyA.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundAnchorA.x-this.m_ground.m_xf.position.x;this.m_groundAnchor1.y=a.groundAnchorA.y-this.m_ground.m_xf.position.y;this.m_groundAnchor2.x=a.groundAnchorB.x-this.m_ground.m_xf.position.x;this.m_groundAnchor2.y=a.groundAnchorB.y-this.m_ground.m_xf.position.y;this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_ratio=a.ratio;this.m_constant=a.lengthA+this.m_ratio*a.lengthB;this.m_maxLength1=Math.min(a.maxLengthA,this.m_constant-this.m_ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength);this.m_maxLength2=Math.min(a.maxLengthB,(this.m_constant-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.m_ratio);this.m_impulse=0;this.m_limitImpulse1=0;this.m_limitImpulse2=0};Box2D.inherits(Box2D.Dynamics.Joints.b2PulleyJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u2.x,a*this.m_impulse*this.m_u2.y)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return 0};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorA=function(){var b=this.m_ground.m_xf.position.Copy();b.Add(this.m_groundAnchor1);return b};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorB=function(){var b=this.m_ground.m_xf.position.Copy();b.Add(this.m_groundAnchor2);return b};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength1=function(){var d=this.m_bodyA.GetWorldPoint(this.m_localAnchor1);var e=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x;var c=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y;var b=d.x-e;var a=d.y-c;return Math.sqrt(b*b+a*a)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength2=function(){var d=this.m_bodyB.GetWorldPoint(this.m_localAnchor2);var e=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x;var c=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;var b=d.x-e;var a=d.y-c;return Math.sqrt(b*b+a*a)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetRatio=function(){return this.m_ratio};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.InitVelocityConstraints=function(g){var z=this.m_bodyA;var y=this.m_bodyB;var k;k=z.m_xf.R;var w=this.m_localAnchor1.x-z.m_sweep.localCenter.x;var v=this.m_localAnchor1.y-z.m_sweep.localCenter.y;var q=(k.col1.x*w+k.col2.x*v);v=(k.col1.y*w+k.col2.y*v);w=q;k=y.m_xf.R;var f=this.m_localAnchor2.x-y.m_sweep.localCenter.x;var e=this.m_localAnchor2.y-y.m_sweep.localCenter.y;q=(k.col1.x*f+k.col2.x*e);e=(k.col1.y*f+k.col2.y*e);f=q;var u=z.m_sweep.c.x+w;var s=z.m_sweep.c.y+v;var d=y.m_sweep.c.x+f;var c=y.m_sweep.c.y+e;var l=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x;var j=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y;var t=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x;var r=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;this.m_u1.Set(u-l,s-j);this.m_u2.Set(d-t,c-r);var p=this.m_u1.Length();var o=this.m_u2.Length();if(p>Box2D.Common.b2Settings.b2_linearSlop){this.m_u1.Multiply(1/p)}else{this.m_u1.SetZero()}if(o>Box2D.Common.b2Settings.b2_linearSlop){this.m_u2.Multiply(1/o)}else{this.m_u2.SetZero()}var n=this.m_constant-p-this.m_ratio*o;if(n>0){this.m_state=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_impulse=0}else{this.m_state=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit}if(p<this.m_maxLength1){this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_limitImpulse1=0}else{this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit}if(o<this.m_maxLength2){this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_limitImpulse2=0}else{this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit}var x=w*this.m_u1.y-v*this.m_u1.x;var m=f*this.m_u2.y-e*this.m_u2.x;this.m_limitMass1=z.m_invMass+z.m_invI*x*x;this.m_limitMass2=y.m_invMass+y.m_invI*m*m;this.m_pulleyMass=this.m_limitMass1+this.m_ratio*this.m_ratio*this.m_limitMass2;this.m_limitMass1=1/this.m_limitMass1;this.m_limitMass2=1/this.m_limitMass2;this.m_pulleyMass=1/this.m_pulleyMass;if(g.warmStarting){this.m_impulse*=g.dtRatio;this.m_limitImpulse1*=g.dtRatio;this.m_limitImpulse2*=g.dtRatio;var b=((-this.m_impulse)-this.m_limitImpulse1)*this.m_u1.x;var a=((-this.m_impulse)-this.m_limitImpulse1)*this.m_u1.y;var i=((-this.m_ratio*this.m_impulse)-this.m_limitImpulse2)*this.m_u2.x;var h=((-this.m_ratio*this.m_impulse)-this.m_limitImpulse2)*this.m_u2.y;z.m_linearVelocity.x+=z.m_invMass*b;z.m_linearVelocity.y+=z.m_invMass*a;z.m_angularVelocity+=z.m_invI*(w*a-v*b);y.m_linearVelocity.x+=y.m_invMass*i;y.m_linearVelocity.y+=y.m_invMass*h;y.m_angularVelocity+=y.m_invI*(f*h-e*i)}else{this.m_impulse=0;this.m_limitImpulse1=0;this.m_limitImpulse2=0}};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolveVelocityConstraints=function(h){var t=this.m_bodyA;var s=this.m_bodyB;var m;m=t.m_xf.R;var r=this.m_localAnchor1.x-t.m_sweep.localCenter.x;var q=this.m_localAnchor1.y-t.m_sweep.localCenter.y;var p=(m.col1.x*r+m.col2.x*q);q=(m.col1.y*r+m.col2.y*q);r=p;m=s.m_xf.R;var f=this.m_localAnchor2.x-s.m_sweep.localCenter.x;var e=this.m_localAnchor2.y-s.m_sweep.localCenter.y;p=(m.col1.x*f+m.col2.x*e);e=(m.col1.y*f+m.col2.y*e);f=p;var d=0;var b=0;var n=0;var k=0;var c=0;var a=0;var l=0;var j=0;var o=0;var i=0;var g=0;if(this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){d=t.m_linearVelocity.x+((-t.m_angularVelocity*q));b=t.m_linearVelocity.y+(t.m_angularVelocity*r);n=s.m_linearVelocity.x+((-s.m_angularVelocity*e));k=s.m_linearVelocity.y+(s.m_angularVelocity*f);o=(-(this.m_u1.x*d+this.m_u1.y*b))-this.m_ratio*(this.m_u2.x*n+this.m_u2.y*k);i=this.m_pulleyMass*((-o));g=this.m_impulse;this.m_impulse=Math.max(0,this.m_impulse+i);i=this.m_impulse-g;c=(-i*this.m_u1.x);a=(-i*this.m_u1.y);l=(-this.m_ratio*i*this.m_u2.x);j=(-this.m_ratio*i*this.m_u2.y);t.m_linearVelocity.x+=t.m_invMass*c;t.m_linearVelocity.y+=t.m_invMass*a;t.m_angularVelocity+=t.m_invI*(r*a-q*c);s.m_linearVelocity.x+=s.m_invMass*l;s.m_linearVelocity.y+=s.m_invMass*j;s.m_angularVelocity+=s.m_invI*(f*j-e*l)}if(this.m_limitState1==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){d=t.m_linearVelocity.x+((-t.m_angularVelocity*q));b=t.m_linearVelocity.y+(t.m_angularVelocity*r);o=(-(this.m_u1.x*d+this.m_u1.y*b));i=(-this.m_limitMass1*o);g=this.m_limitImpulse1;this.m_limitImpulse1=Math.max(0,this.m_limitImpulse1+i);i=this.m_limitImpulse1-g;c=(-i*this.m_u1.x);a=(-i*this.m_u1.y);t.m_linearVelocity.x+=t.m_invMass*c;t.m_linearVelocity.y+=t.m_invMass*a;t.m_angularVelocity+=t.m_invI*(r*a-q*c)}if(this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){n=s.m_linearVelocity.x+((-s.m_angularVelocity*e));k=s.m_linearVelocity.y+(s.m_angularVelocity*f);o=(-(this.m_u2.x*n+this.m_u2.y*k));i=(-this.m_limitMass2*o);g=this.m_limitImpulse2;this.m_limitImpulse2=Math.max(0,this.m_limitImpulse2+i);i=this.m_limitImpulse2-g;l=(-i*this.m_u2.x);j=(-i*this.m_u2.y);s.m_linearVelocity.x+=s.m_invMass*l;s.m_linearVelocity.y+=s.m_invMass*j;s.m_angularVelocity+=s.m_invI*(f*j-e*l)}};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolvePositionConstraints=function(q){if(q===undefined){q=0}var x=this.m_bodyA;var w=this.m_bodyB;var i;var j=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x;var h=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y;var r=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x;var o=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;var v=0;var u=0;var d=0;var c=0;var s=0;var p=0;var b=0;var a=0;var m=0;var l=0;var k=0;var g=0;var f=0;var t=0;var n=0;var e=0;if(this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){i=x.m_xf.R;v=this.m_localAnchor1.x-x.m_sweep.localCenter.x;u=this.m_localAnchor1.y-x.m_sweep.localCenter.y;n=(i.col1.x*v+i.col2.x*u);u=(i.col1.y*v+i.col2.y*u);v=n;i=w.m_xf.R;d=this.m_localAnchor2.x-w.m_sweep.localCenter.x;c=this.m_localAnchor2.y-w.m_sweep.localCenter.y;n=(i.col1.x*d+i.col2.x*c);c=(i.col1.y*d+i.col2.y*c);d=n;s=x.m_sweep.c.x+v;p=x.m_sweep.c.y+u;b=w.m_sweep.c.x+d;a=w.m_sweep.c.y+c;this.m_u1.Set(s-j,p-h);this.m_u2.Set(b-r,a-o);m=this.m_u1.Length();l=this.m_u2.Length();if(m>Box2D.Common.b2Settings.b2_linearSlop){this.m_u1.Multiply(1/m)}else{this.m_u1.SetZero()}if(l>Box2D.Common.b2Settings.b2_linearSlop){this.m_u2.Multiply(1/l)}else{this.m_u2.SetZero()}k=this.m_constant-m-this.m_ratio*l;e=Math.max(e,(-k));k=Box2D.Common.Math.b2Math.Clamp(k+Box2D.Common.b2Settings.b2_linearSlop,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);g=(-this.m_pulleyMass*k);s=(-g*this.m_u1.x);p=(-g*this.m_u1.y);b=(-this.m_ratio*g*this.m_u2.x);a=(-this.m_ratio*g*this.m_u2.y);x.m_sweep.c.x+=x.m_invMass*s;x.m_sweep.c.y+=x.m_invMass*p;x.m_sweep.a+=x.m_invI*(v*p-u*s);w.m_sweep.c.x+=w.m_invMass*b;w.m_sweep.c.y+=w.m_invMass*a;w.m_sweep.a+=w.m_invI*(d*a-c*b);x.SynchronizeTransform();w.SynchronizeTransform()}if(this.m_limitState1==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){i=x.m_xf.R;v=this.m_localAnchor1.x-x.m_sweep.localCenter.x;u=this.m_localAnchor1.y-x.m_sweep.localCenter.y;n=(i.col1.x*v+i.col2.x*u);u=(i.col1.y*v+i.col2.y*u);v=n;s=x.m_sweep.c.x+v;p=x.m_sweep.c.y+u;this.m_u1.Set(s-j,p-h);m=this.m_u1.Length();if(m>Box2D.Common.b2Settings.b2_linearSlop){this.m_u1.x*=1/m;this.m_u1.y*=1/m}else{this.m_u1.SetZero()}k=this.m_maxLength1-m;e=Math.max(e,(-k));k=Box2D.Common.Math.b2Math.Clamp(k+Box2D.Common.b2Settings.b2_linearSlop,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);g=(-this.m_limitMass1*k);s=(-g*this.m_u1.x);p=(-g*this.m_u1.y);x.m_sweep.c.x+=x.m_invMass*s;x.m_sweep.c.y+=x.m_invMass*p;x.m_sweep.a+=x.m_invI*(v*p-u*s);x.SynchronizeTransform()}if(this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){i=w.m_xf.R;d=this.m_localAnchor2.x-w.m_sweep.localCenter.x;c=this.m_localAnchor2.y-w.m_sweep.localCenter.y;n=(i.col1.x*d+i.col2.x*c);c=(i.col1.y*d+i.col2.y*c);d=n;b=w.m_sweep.c.x+d;a=w.m_sweep.c.y+c;this.m_u2.Set(b-r,a-o);l=this.m_u2.Length();if(l>Box2D.Common.b2Settings.b2_linearSlop){this.m_u2.x*=1/l;this.m_u2.y*=1/l}else{this.m_u2.SetZero()}k=this.m_maxLength2-l;e=Math.max(e,(-k));k=Box2D.Common.Math.b2Math.Clamp(k+Box2D.Common.b2Settings.b2_linearSlop,(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);g=(-this.m_limitMass2*k);b=(-g*this.m_u2.x);a=(-g*this.m_u2.y);w.m_sweep.c.x+=w.m_invMass*b;w.m_sweep.c.y+=w.m_invMass*a;w.m_sweep.a+=w.m_invI*(d*a-c*b);w.SynchronizeTransform()}return e<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength=1;Box2D.Dynamics.Joints.b2PulleyJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.groundAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.groundAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint;this.groundAnchorA.Set((-1),1);this.groundAnchorB.Set(1,1);this.localAnchorA.Set((-1),0);this.localAnchorB.Set(1,0);this.lengthA=0;this.maxLengthA=0;this.lengthB=0;this.maxLengthB=0;this.ratio=1;this.collideConnected=true};Box2D.inherits(Box2D.Dynamics.Joints.b2PulleyJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Initialize=function(d,a,k,i,f,e,b){if(b===undefined){b=0}this.bodyA=d;this.bodyB=a;this.groundAnchorA.SetV(k);this.groundAnchorB.SetV(i);this.localAnchorA=this.bodyA.GetLocalPoint(f);this.localAnchorB=this.bodyB.GetLocalPoint(e);var l=f.x-k.x;var j=f.y-k.y;this.lengthA=Math.sqrt(l*l+j*j);var h=e.x-i.x;var g=e.y-i.y;this.lengthB=Math.sqrt(h*h+g*g);this.ratio=b;var c=this.lengthA+this.ratio*this.lengthB;this.maxLengthA=c-this.ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength;this.maxLengthB=(c-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.ratio};Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PulleyJoint(this)};Box2D.Dynamics.Joints.b2RevoluteJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.K=Box2D.Common.Math.b2Mat22.Get();this.K1=Box2D.Common.Math.b2Mat22.Get();this.K2=Box2D.Common.Math.b2Mat22.Get();this.K3=Box2D.Common.Math.b2Mat22.Get();this.impulse3=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.impulse2=Box2D.Common.Math.b2Vec2.Get(0,0);this.reduced=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33();this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=0;this.m_lowerAngle=a.lowerAngle;this.m_upperAngle=a.upperAngle;this.m_maxMotorTorque=a.maxMotorTorque;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_motorMass=0};Box2D.inherits(Box2D.Dynamics.Joints.b2RevoluteJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionForce=function(a){if(a===undefined){a=0}return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionTorque=function(a){if(a===undefined){a=0}return a*this.m_impulse.z};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointAngle=function(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointSpeed=function(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableLimit=function(a){this.m_enableLimit=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetLowerLimit=function(){return this.m_lowerAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetUpperLimit=function(){return this.m_upperAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetLimits=function(a,b){if(a===undefined){a=0}if(b===undefined){b=0}this.m_lowerAngle=a;this.m_upperAngle=b};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsMotorEnabled=function(){this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);return this.m_enableMotor};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableMotor=function(a){this.m_enableMotor=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMotorSpeed=function(a){if(a===undefined){a=0}this.m_bodyA.SetAwake(true);this.m_bodyB.SetAwake(true);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMaxMotorTorque=function(a){if(a===undefined){a=0}this.m_maxMotorTorque=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorTorque=function(){return this.m_maxMotorTorque};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.InitVelocityConstraints=function(d){var b=this.m_bodyA;var a=this.m_bodyB;var k;var l=0;k=b.m_xf.R;var o=this.m_localAnchor1.x-b.m_sweep.localCenter.x;var m=this.m_localAnchor1.y-b.m_sweep.localCenter.y;l=(k.col1.x*o+k.col2.x*m);m=(k.col1.y*o+k.col2.y*m);o=l;k=a.m_xf.R;var j=this.m_localAnchor2.x-a.m_sweep.localCenter.x;var i=this.m_localAnchor2.y-a.m_sweep.localCenter.y;l=(k.col1.x*j+k.col2.x*i);i=(k.col1.y*j+k.col2.y*i);j=l;var p=b.m_invMass;var n=a.m_invMass;var h=b.m_invI;var f=a.m_invI;this.m_mass.col1.x=p+n+m*m*h+i*i*f;this.m_mass.col2.x=(-m*o*h)-i*j*f;this.m_mass.col3.x=(-m*h)-i*f;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=p+n+o*o*h+j*j*f;this.m_mass.col3.y=o*h+j*f;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=h+f;if(h+f==0){this.m_motorMass=0}else{this.m_motorMass=1/(h+f)}if(!this.m_enableMotor){this.m_motorImpulse=0}if(this.m_enableLimit){var c=a.m_sweep.a-b.m_sweep.a-this.m_referenceAngle;if(Math.abs(this.m_upperAngle-this.m_lowerAngle)<2*Box2D.Common.b2Settings.b2_angularSlop){this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits}else{if(c<=this.m_lowerAngle){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){this.m_impulse.z=0}this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit}else{if(c>=this.m_upperAngle){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){this.m_impulse.z=0}this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_impulse.z=0}}}}else{this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit}if(d.warmStarting){this.m_impulse.x*=d.dtRatio;this.m_impulse.y*=d.dtRatio;this.m_motorImpulse*=d.dtRatio;var g=this.m_impulse.x;var e=this.m_impulse.y;b.m_linearVelocity.x-=p*g;b.m_linearVelocity.y-=p*e;b.m_angularVelocity-=h*((o*e-m*g)+this.m_motorImpulse+this.m_impulse.z);a.m_linearVelocity.x+=n*g;a.m_linearVelocity.y+=n*e;a.m_angularVelocity+=f*((j*e-i*g)+this.m_motorImpulse+this.m_impulse.z)}else{this.m_impulse.SetZero();this.m_motorImpulse=0}};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolveVelocityConstraints=function(k){var A=this.m_bodyA;var z=this.m_bodyB;var m;var r=0;var y=0;var x=0;var w=0;var g=0;var f=0;var e=A.m_linearVelocity;var o=A.m_angularVelocity;var d=z.m_linearVelocity;var n=z.m_angularVelocity;var c=A.m_invMass;var a=z.m_invMass;var t=A.m_invI;var s=z.m_invI;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits){var q=n-o-this.m_motorSpeed;var l=this.m_motorMass*((-q));var i=this.m_motorImpulse;var p=k.dt*this.m_maxMotorTorque;this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+l,(-p),p);l=this.m_motorImpulse-i;o-=t*l;n+=s*l}if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){m=A.m_xf.R;x=this.m_localAnchor1.x-A.m_sweep.localCenter.x;w=this.m_localAnchor1.y-A.m_sweep.localCenter.y;r=(m.col1.x*x+m.col2.x*w);w=(m.col1.y*x+m.col2.y*w);x=r;m=z.m_xf.R;g=this.m_localAnchor2.x-z.m_sweep.localCenter.x;f=this.m_localAnchor2.y-z.m_sweep.localCenter.y;r=(m.col1.x*g+m.col2.x*f);f=(m.col1.y*g+m.col2.y*f);g=r;var v=d.x+((-n*f))-e.x-((-o*w));var u=d.y+(n*g)-e.y-(o*x);var b=n-o;this.m_mass.Solve33(this.impulse3,(-v),(-u),(-b));if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits){this.m_impulse.Add(this.impulse3)}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){y=this.m_impulse.z+this.impulse3.z;if(y<0){this.m_mass.Solve22(this.reduced,(-v),(-u));this.impulse3.x=this.reduced.x;this.impulse3.y=this.reduced.y;this.impulse3.z=(-this.m_impulse.z);this.m_impulse.x+=this.reduced.x;this.m_impulse.y+=this.reduced.y;this.m_impulse.z=0}}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){y=this.m_impulse.z+this.impulse3.z;if(y>0){this.m_mass.Solve22(this.reduced,(-v),(-u));this.impulse3.x=this.reduced.x;this.impulse3.y=this.reduced.y;this.impulse3.z=(-this.m_impulse.z);this.m_impulse.x+=this.reduced.x;this.m_impulse.y+=this.reduced.y;this.m_impulse.z=0}}}}e.x-=c*this.impulse3.x;e.y-=c*this.impulse3.y;o-=t*(x*this.impulse3.y-w*this.impulse3.x+this.impulse3.z);d.x+=a*this.impulse3.x;d.y+=a*this.impulse3.y;n+=s*(g*this.impulse3.y-f*this.impulse3.x+this.impulse3.z)}else{m=A.m_xf.R;x=this.m_localAnchor1.x-A.m_sweep.localCenter.x;w=this.m_localAnchor1.y-A.m_sweep.localCenter.y;r=(m.col1.x*x+m.col2.x*w);w=(m.col1.y*x+m.col2.y*w);x=r;m=z.m_xf.R;g=this.m_localAnchor2.x-z.m_sweep.localCenter.x;f=this.m_localAnchor2.y-z.m_sweep.localCenter.y;r=(m.col1.x*g+m.col2.x*f);f=(m.col1.y*g+m.col2.y*f);g=r;var j=d.x+((-n*f))-e.x-((-o*w));var h=d.y+(n*g)-e.y-(o*x);this.m_mass.Solve22(this.impulse2,(-j),(-h));this.m_impulse.x+=this.impulse2.x;this.m_impulse.y+=this.impulse2.y;e.x-=c*this.impulse2.x;e.y-=c*this.impulse2.y;o-=t*(x*this.impulse2.y-w*this.impulse2.x);d.x+=a*this.impulse2.x;d.y+=a*this.impulse2.y;n+=s*(g*this.impulse2.y-f*this.impulse2.x)}A.m_linearVelocity.SetV(e);A.m_angularVelocity=o;z.m_linearVelocity.SetV(d);z.m_angularVelocity=n};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolvePositionConstraints=function(w){if(w===undefined){w=0}var v=0;var p=0;var j;var H=this.m_bodyA;var G=this.m_bodyB;var z=0;var l=0;var r=0;var b=0;var a=0;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var x=G.m_sweep.a-H.m_sweep.a-this.m_referenceAngle;var s=0;if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits){p=Box2D.Common.Math.b2Math.Clamp(x-this.m_lowerAngle,(-Box2D.Common.b2Settings.b2_maxAngularCorrection),Box2D.Common.b2Settings.b2_maxAngularCorrection);s=(-this.m_motorMass*p);z=Math.abs(p)}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){p=x-this.m_lowerAngle;z=(-p);p=Box2D.Common.Math.b2Math.Clamp(p+Box2D.Common.b2Settings.b2_angularSlop,(-Box2D.Common.b2Settings.b2_maxAngularCorrection),0);s=(-this.m_motorMass*p)}else{if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit){p=x-this.m_upperAngle;z=p;p=Box2D.Common.Math.b2Math.Clamp(p-Box2D.Common.b2Settings.b2_angularSlop,0,Box2D.Common.b2Settings.b2_maxAngularCorrection);s=(-this.m_motorMass*p)}}}H.m_sweep.a-=H.m_invI*s;G.m_sweep.a+=G.m_invI*s;H.SynchronizeTransform();G.SynchronizeTransform()}j=H.m_xf.R;var A=this.m_localAnchor1.x-H.m_sweep.localCenter.x;var y=this.m_localAnchor1.y-H.m_sweep.localCenter.y;r=(j.col1.x*A+j.col2.x*y);y=(j.col1.y*A+j.col2.y*y);A=r;j=G.m_xf.R;var e=this.m_localAnchor2.x-G.m_sweep.localCenter.x;var d=this.m_localAnchor2.y-G.m_sweep.localCenter.y;r=(j.col1.x*e+j.col2.x*d);d=(j.col1.y*e+j.col2.y*d);e=r;var E=G.m_sweep.c.x+e-H.m_sweep.c.x-A;var B=G.m_sweep.c.y+d-H.m_sweep.c.y-y;var i=E*E+B*B;var h=Math.sqrt(i);l=h;var o=H.m_invMass;var n=G.m_invMass;var g=H.m_invI;var f=G.m_invI;var c=10*Box2D.Common.b2Settings.b2_linearSlop;if(i>c*c){var F=E/h;var D=B/h;var u=o+n;var t=1/u;b=t*((-E));a=t*((-B));var q=0.5;H.m_sweep.c.x-=q*o*b;H.m_sweep.c.y-=q*o*a;G.m_sweep.c.x+=q*n*b;G.m_sweep.c.y+=q*n*a;E=G.m_sweep.c.x+e-H.m_sweep.c.x-A;B=G.m_sweep.c.y+d-H.m_sweep.c.y-y}this.K1.col1.x=o+n;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=o+n;this.K2.col1.x=g*y*y;this.K2.col2.x=(-g*A*y);this.K2.col1.y=(-g*A*y);this.K2.col2.y=g*A*A;this.K3.col1.x=f*d*d;this.K3.col2.x=(-f*e*d);this.K3.col1.y=(-f*e*d);this.K3.col2.y=f*e*e;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse,(-E),(-B));b=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.x;a=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.y;H.m_sweep.c.x-=H.m_invMass*b;H.m_sweep.c.y-=H.m_invMass*a;H.m_sweep.a-=H.m_invI*(A*a-y*b);G.m_sweep.c.x+=G.m_invMass*b;G.m_sweep.c.y+=G.m_invMass*a;G.m_sweep.a+=G.m_invI*(e*a-d*b);H.SynchronizeTransform();G.SynchronizeTransform();return l<=Box2D.Common.b2Settings.b2_linearSlop&&z<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Dynamics.Joints.b2RevoluteJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint;this.localAnchorA.SetZero();this.localAnchorB.SetZero();this.referenceAngle=0;this.lowerAngle=0;this.upperAngle=0;this.maxMotorTorque=0;this.motorSpeed=0;this.enableLimit=false;this.enableMotor=false};Box2D.inherits(Box2D.Dynamics.Joints.b2RevoluteJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Initialize=function(c,b,a){this.bodyA=c;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(a);this.localAnchorB=this.bodyB.GetLocalPoint(a);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2RevoluteJoint(this)};Box2D.Dynamics.Joints.b2WeldJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33();this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle};Box2D.inherits(Box2D.Dynamics.Joints.b2WeldJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionForce=function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionTorque=function(a){return a*this.m_impulse.z};Box2D.Dynamics.Joints.b2WeldJoint.prototype.InitVelocityConstraints=function(d){var j;var k=0;var b=this.m_bodyA;var a=this.m_bodyB;j=b.m_xf.R;var g=this.m_localAnchorA.x-b.m_sweep.localCenter.x;var f=this.m_localAnchorA.y-b.m_sweep.localCenter.y;k=(j.col1.x*g+j.col2.x*f);f=(j.col1.y*g+j.col2.y*f);g=k;j=a.m_xf.R;var m=this.m_localAnchorB.x-a.m_sweep.localCenter.x;var l=this.m_localAnchorB.y-a.m_sweep.localCenter.y;k=(j.col1.x*m+j.col2.x*l);l=(j.col1.y*m+j.col2.y*l);m=k;var e=b.m_invMass;var c=a.m_invMass;var i=b.m_invI;var h=a.m_invI;this.m_mass.col1.x=e+c+f*f*i+l*l*h;this.m_mass.col2.x=(-f*g*i)-l*m*h;this.m_mass.col3.x=(-f*i)-l*h;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=e+c+g*g*i+m*m*h;this.m_mass.col3.y=g*i+m*h;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=i+h;if(d.warmStarting){this.m_impulse.x*=d.dtRatio;this.m_impulse.y*=d.dtRatio;this.m_impulse.z*=d.dtRatio;b.m_linearVelocity.x-=e*this.m_impulse.x;b.m_linearVelocity.y-=e*this.m_impulse.y;b.m_angularVelocity-=i*(g*this.m_impulse.y-f*this.m_impulse.x+this.m_impulse.z);a.m_linearVelocity.x+=c*this.m_impulse.x;a.m_linearVelocity.y+=c*this.m_impulse.y;a.m_angularVelocity+=h*(m*this.m_impulse.y-l*this.m_impulse.x+this.m_impulse.z)}else{this.m_impulse.SetZero()}};Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolveVelocityConstraints=function(e){var j;var k=0;var u=this.m_bodyA;var t=this.m_bodyB;var s=u.m_linearVelocity;var c=u.m_angularVelocity;var r=t.m_linearVelocity;var b=t.m_angularVelocity;var o=u.m_invMass;var n=t.m_invMass;var h=u.m_invI;var g=t.m_invI;j=u.m_xf.R;var f=this.m_localAnchorA.x-u.m_sweep.localCenter.x;var d=this.m_localAnchorA.y-u.m_sweep.localCenter.y;k=(j.col1.x*f+j.col2.x*d);d=(j.col1.y*f+j.col2.y*d);f=k;j=t.m_xf.R;var m=this.m_localAnchorB.x-t.m_sweep.localCenter.x;var l=this.m_localAnchorB.y-t.m_sweep.localCenter.y;k=(j.col1.x*m+j.col2.x*l);l=(j.col1.y*m+j.col2.y*l);m=k;var q=r.x-b*l-s.x+c*d;var p=r.y+b*m-s.y-c*f;var a=b-c;var i=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass.Solve33(i,(-q),(-p),(-a));this.m_impulse.Add(i);s.x-=o*i.x;s.y-=o*i.y;c-=h*(f*i.y-d*i.x+i.z);r.x+=n*i.x;r.y+=n*i.y;b+=g*(m*i.y-l*i.x+i.z);Box2D.Common.Math.b2Vec3.Free(i);u.m_angularVelocity=c;t.m_angularVelocity=b};Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolvePositionConstraints=function(o){if(o===undefined){o=0}var h;var i=0;var t=this.m_bodyA;var s=this.m_bodyB;h=t.m_xf.R;var c=this.m_localAnchorA.x-t.m_sweep.localCenter.x;var b=this.m_localAnchorA.y-t.m_sweep.localCenter.y;i=(h.col1.x*c+h.col2.x*b);b=(h.col1.y*c+h.col2.y*b);c=i;h=s.m_xf.R;var k=this.m_localAnchorB.x-s.m_sweep.localCenter.x;var j=this.m_localAnchorB.y-s.m_sweep.localCenter.y;i=(h.col1.x*k+h.col2.x*j);j=(h.col1.y*k+h.col2.y*j);k=i;var m=t.m_invMass;var l=s.m_invMass;var e=t.m_invI;var d=s.m_invI;var r=s.m_sweep.c.x+k-t.m_sweep.c.x-c;var q=s.m_sweep.c.y+j-t.m_sweep.c.y-b;var n=s.m_sweep.a-t.m_sweep.a-this.m_referenceAngle;var a=10*Box2D.Common.b2Settings.b2_linearSlop;var g=Math.sqrt(r*r+q*q);var p=Math.abs(n);if(g>a){e*=1;d*=1}this.m_mass.col1.x=m+l+b*b*e+j*j*d;this.m_mass.col2.x=(-b*c*e)-j*k*d;this.m_mass.col3.x=(-b*e)-j*d;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=m+l+c*c*e+k*k*d;this.m_mass.col3.y=c*e+k*d;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=e+d;var f=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass.Solve33(f,(-r),(-q),(-n));t.m_sweep.c.x-=m*f.x;t.m_sweep.c.y-=m*f.y;t.m_sweep.a-=e*(c*f.y-b*f.x+f.z);s.m_sweep.c.x+=l*f.x;s.m_sweep.c.y+=l*f.y;s.m_sweep.a+=d*(k*f.y-j*f.x+f.z);Box2D.Common.Math.b2Vec3.Free(f);t.SynchronizeTransform();s.SynchronizeTransform();return g<=Box2D.Common.b2Settings.b2_linearSlop&&p<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2WeldJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_weldJoint;this.referenceAngle=0};Box2D.inherits(Box2D.Dynamics.Joints.b2WeldJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Initialize=function(c,b,a){this.bodyA=c;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(a));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(a));this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2WeldJoint(this)};Box2D.Dynamics.Contacts.b2PositionSolverManifold=function(){this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_separations=Box2D.Array.Get();this.m_points=Box2D.Array.Get();for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++){this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)}};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype.Initialize=function(a){switch(a.type){case Box2D.Collision.b2Manifold.e_circles:this._InitializeCircles(a);break;case Box2D.Collision.b2Manifold.e_faceA:this._InitializeFaceA(a);break;case Box2D.Collision.b2Manifold.e_faceB:this._InitializeFaceB(a);break}};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeCircles=function(b){var k=b.bodyA.m_xf.R;var l=b.localPoint;var j=b.bodyA.m_xf.position.x+(k.col1.x*l.x+k.col2.x*l.y);var i=b.bodyA.m_xf.position.y+(k.col1.y*l.x+k.col2.y*l.y);k=b.bodyB.m_xf.R;l=b.points[0].localPoint;var f=b.bodyB.m_xf.position.x+(k.col1.x*l.x+k.col2.x*l.y);var c=b.bodyB.m_xf.position.y+(k.col1.y*l.x+k.col2.y*l.y);var g=f-j;var e=c-i;var a=g*g+e*e;if(a>Box2D.Common.b2Settings.MIN_VALUE_SQUARED){var h=Math.sqrt(a);this.m_normal.x=g/h;this.m_normal.y=e/h}else{this.m_normal.x=1;this.m_normal.y=0}this.m_points[0].x=0.5*(j+f);this.m_points[0].y=0.5*(i+c);this.m_separations[0]=g*this.m_normal.x+e*this.m_normal.y-b.radius};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceA=function(f){this.m_normal.x=f.bodyA.m_xf.R.col1.x*f.localPlaneNormal.x+f.bodyA.m_xf.R.col2.x*f.localPlaneNormal.y;this.m_normal.y=f.bodyA.m_xf.R.col1.y*f.localPlaneNormal.x+f.bodyA.m_xf.R.col2.y*f.localPlaneNormal.y;var e=f.bodyA.m_xf.position.x+(f.bodyA.m_xf.R.col1.x*f.localPoint.x+f.bodyA.m_xf.R.col2.x*f.localPoint.y);var d=f.bodyA.m_xf.position.y+(f.bodyA.m_xf.R.col1.y*f.localPoint.x+f.bodyA.m_xf.R.col2.y*f.localPoint.y);for(var a=0;a<f.pointCount;a++){var c=f.bodyB.m_xf.position.x+(f.bodyB.m_xf.R.col1.x*f.points[a].localPoint.x+f.bodyB.m_xf.R.col2.x*f.points[a].localPoint.y);var b=f.bodyB.m_xf.position.y+(f.bodyB.m_xf.R.col1.y*f.points[a].localPoint.x+f.bodyB.m_xf.R.col2.y*f.points[a].localPoint.y);this.m_separations[a]=(c-e)*this.m_normal.x+(b-d)*this.m_normal.y-f.radius;this.m_points[a].x=c;this.m_points[a].y=b}};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceB=function(f){this.m_normal.x=f.bodyB.m_xf.R.col1.x*f.localPlaneNormal.x+f.bodyB.m_xf.R.col2.x*f.localPlaneNormal.y;this.m_normal.y=f.bodyB.m_xf.R.col1.y*f.localPlaneNormal.x+f.bodyB.m_xf.R.col2.y*f.localPlaneNormal.y;var e=f.bodyB.m_xf.position.x+(f.bodyB.m_xf.R.col1.x*f.localPoint.x+f.bodyB.m_xf.R.col2.x*f.localPoint.y);var d=f.bodyB.m_xf.position.y+(f.bodyB.m_xf.R.col1.y*f.localPoint.x+f.bodyB.m_xf.R.col2.y*f.localPoint.y);for(var a=0;a<f.pointCount;a++){var c=f.bodyA.m_xf.position.x+(f.bodyA.m_xf.R.col1.x*f.points[a].localPoint.x+f.bodyA.m_xf.R.col2.x*f.points[a].localPoint.y);var b=f.bodyA.m_xf.position.y+(f.bodyA.m_xf.R.col1.y*f.points[a].localPoint.x+f.bodyA.m_xf.R.col2.y*f.points[a].localPoint.y);this.m_separations[a]=(c-e)*this.m_normal.x+(b-d)*this.m_normal.y-f.radius;this.m_points[a].Set(c,b)}this.m_normal.x*=-1;this.m_normal.y*=-1};Box2D.Dynamics.Controllers.b2Controller=function(){this.ID=Box2D.Dynamics.Controllers.b2Controller.NEXT_ID++;this.m_world=null;this.bodyList=new Box2D.Dynamics.b2BodyList()};Box2D.Dynamics.Controllers.b2Controller.prototype.Step=function(a){};Box2D.Dynamics.Controllers.b2Controller.prototype.Draw=function(a){};Box2D.Dynamics.Controllers.b2Controller.prototype.AddBody=function(a){this.bodyList.AddBody(a);a.AddController(this)};Box2D.Dynamics.Controllers.b2Controller.prototype.RemoveBody=function(a){this.bodyList.RemoveBody(a);a.RemoveController(this)};Box2D.Dynamics.Controllers.b2Controller.prototype.Clear=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);a;a=a.GetNextNode()){this.RemoveBody(a.body)}};Box2D.Dynamics.Controllers.b2Controller.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.Controllers.b2Controller.NEXT_ID=0;Box2D.Dynamics.Controllers.b2BuoyancyController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.normal=Box2D.Common.Math.b2Vec2.Get(0,-1);this.offset=0;this.density=0;this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearDrag=2;this.angularDrag=1;this.useDensity=false;this.useWorldGravity=true;this.gravity=null};Box2D.inherits(Box2D.Dynamics.Controllers.b2BuoyancyController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2BuoyancyController.prototype.Step=function(c){if(this.useWorldGravity){this.gravity=this.m_world.GetGravity()}var j=Box2D.Common.Math.b2Vec2.Get(0,0);var m=Box2D.Common.Math.b2Vec2.Get(0,0);var i=Box2D.Common.Math.b2Vec2.Get(0,0);for(var d=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);d;d=d.GetNextNode()){m.Set(0,0);j.Set(0,0);var g=d.body;var b=0;var h=0;for(var l=g.GetFixtureList().GetFirstNode();l;l=l.GetNextNode()){i.Set(0,0);var a=l.fixture.GetShape().ComputeSubmergedArea(this.normal,this.offset,g.GetTransform(),i);b+=a;j.x+=a*i.x;j.y+=a*i.y;var e=0;if(this.useDensity){e=1}else{e=1}h+=a*e;m.x+=a*i.x*e;m.y+=a*i.y*e}if(b<Number.MIN_VALUE){continue}j.x/=b;j.y/=b;m.x/=h;m.y/=h;var f=this.gravity.GetNegative();f.Multiply(this.density*b);g.ApplyForce(f,m);Box2D.Common.Math.b2Vec2.Free(f);var k=g.GetLinearVelocityFromWorldPoint(j);k.Subtract(this.velocity);k.Multiply((-this.linearDrag*b));g.ApplyForce(k,j);Box2D.Common.Math.b2Vec2.Free(k);g.ApplyTorque((-g.GetInertia()/g.GetMass()*b*g.GetAngularVelocity()*this.angularDrag))}Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(m);Box2D.Common.Math.b2Vec2.Free(j)};Box2D.Dynamics.Controllers.b2BuoyancyController.prototype.Draw=function(d){var a=1000;var c=Box2D.Common.Math.b2Vec2.Get(this.normal.x*this.offset+this.normal.y*a,this.normal.y*this.offset-this.normal.x*a);var b=Box2D.Common.Math.b2Vec2.Get(this.normal.x*this.offset-this.normal.y*a,this.normal.y*this.offset+this.normal.x*a);d.DrawSegment(c,b,Box2D.Dynamics.Controllers.b2BuoyancyController.color);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Dynamics.Controllers.b2BuoyancyController.color=new Box2D.Common.b2Color(0,0,1);Box2D.Dynamics.Controllers.b2ConstantAccelController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.A=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.inherits(Box2D.Dynamics.Controllers.b2ConstantAccelController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2ConstantAccelController.prototype.Step=function(f){var c=Box2D.Common.Math.b2Vec2.Get(this.A.x*f.dt,this.A.y*f.dt);for(var e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);e;e=e.GetNextNode()){var a=e.body;var d=a.GetLinearVelocity();var b=Box2D.Common.Math.b2Vec2.Get(d.x+c.x,d.y+c.y);a.SetLinearVelocity(b);Box2D.Common.Math.b2Vec2.Free(b)}Box2D.Common.Math.b2Vec2.Free(c)};Box2D.Dynamics.Controllers.b2ConstantForceController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.F=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.inherits(Box2D.Dynamics.Controllers.b2ConstantForceController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2ConstantForceController.prototype.Step=function(c){for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);b;b=b.GetNextNode()){var a=b.body;a.ApplyForce(this.F,a.GetWorldCenter())}};Box2D.Dynamics.Controllers.b2ControllerList=function(){this.controllerFirstNode=null;this.controllerLastNode=null;this.controllerNodeLookup={};this.controllerCount=0};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetFirstNode=function(){return this.controllerFirstNode};Box2D.Dynamics.Controllers.b2ControllerList.prototype.AddController=function(b){var d=b.ID;if(this.controllerNodeLookup[d]==null){var c=new Box2D.Dynamics.Controllers.b2ControllerListNode(b);var a=this.controllerLastNode;if(a!=null){a.SetNextNode(c)}else{this.controllerFirstNode=c}c.SetPreviousNode(a);this.controllerLastNode=c;this.controllerNodeLookup[d]=c;this.controllerCount++}};Box2D.Dynamics.Controllers.b2ControllerList.prototype.RemoveController=function(c){var e=c.ID;var d=this.controllerNodeLookup[e];if(d==null){return}var b=d.GetPreviousNode();var a=d.GetNextNode();if(b==null){this.controllerFirstNode=a}else{b.SetNextNode(a)}if(a==null){this.controllerLastNode=b}else{a.SetPreviousNode(b)}delete this.controllerNodeLookup[e];this.controllerCount--};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetControllerCount=function(){return this.controllerCount};Box2D.Dynamics.Controllers.b2ControllerListNode=function(a){this.controller=a;this.next=null;this.previous=null};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.Controllers.b2GravityController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.G=1;this.invSqr=true};Box2D.inherits(Box2D.Dynamics.Controllers.b2GravityController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2GravityController.prototype.Step=function(g){var k=null;var a=null;var n=null;var c=0;var h=null;var q=null;var m=null;var p=0;var o=0;var e=0;var l=null;if(this.invSqr){for(var d=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);d;d=d.GetNextNode()){var a=d.body;var n=a.GetWorldCenter();var c=a.GetMass();for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);b;b=b.GetNextNode()){var q=b.body;if(!a.IsAwake()&&!q.IsAwake()){continue}var m=q.GetWorldCenter();var p=m.x-n.x;var o=m.y-n.y;var e=p*p+o*o;if(e<Number.MIN_VALUE){continue}var l=Box2D.Common.Math.b2Vec2.Get(p,o);l.Multiply(this.G/e/Math.sqrt(e)*c*q.GetMass());if(a.IsAwake()){a.ApplyForce(l,n)}l.Multiply(-1);if(q.IsAwake()){q.ApplyForce(l,m)}Box2D.Common.Math.b2Vec2.Free(l)}}}else{for(var d=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);d;d=d.GetNextNode()){var a=bodyNode.body;var n=a.GetWorldCenter();var c=a.GetMass();for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);b;b=b.GetNextNode()){var q=bodyNode.body;if(!a.IsAwake()&&!q.IsAwake()){continue}var m=q.GetWorldCenter();var p=m.x-n.x;var o=m.y-n.y;var e=p*p+o*o;if(e<Number.MIN_VALUE){continue}var l=Box2D.Common.Math.b2Vec2.Get(p,o);l.Multiply(this.G/e*c*q.GetMass());if(a.IsAwake()){a.ApplyForce(l,n)}l.Multiply(-1);if(q.IsAwake()){q.ApplyForce(l,m)}Box2D.Common.Math.b2Vec2.Free(l)}}}};Box2D.Dynamics.Controllers.b2TensorDampingController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.T=Box2D.Common.Math.b2Mat22.Get();this.maxTimestep=0};Box2D.inherits(Box2D.Dynamics.Controllers.b2TensorDampingController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.SetAxisAligned=function(b,a){this.T.col1.x=(-b);this.T.col1.y=0;this.T.col2.x=0;this.T.col2.y=(-a);if(b>0||a>0){this.maxTimestep=1/Math.max(b,a)}else{this.maxTimestep=0}};Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.Step=function(g){var c=g.dt;if(c<=Number.MIN_VALUE){return}if(c>this.maxTimestep&&this.maxTimestep>0){c=this.maxTimestep}for(var f=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);f;f=f.GetNextNode()){var b=f.body;var h=b.GetLocalVector(b.GetLinearVelocity());var d=Box2D.Common.Math.b2Math.MulMV(this.T,h);Box2D.Common.Math.b2Vec2.Free(h);var e=b.GetWorldVector(d);Box2D.Common.Math.b2Vec2.Free(d);var a=Box2D.Common.Math.b2Vec2.Get(b.GetLinearVelocity().x+e.x*c,b.GetLinearVelocity().y+e.y*c);Box2D.Common.Math.b2Vec2.Free(e);b.SetLinearVelocity(a);Box2D.Common.Math.b2Vec2.Free(a)}};Box2D.Collision.ClipVertex=function(){this.v=Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID()};Box2D.Collision.ClipVertex.prototype.Set=function(a){this.v.SetV(a.v);this.id.Set(a.id)};Box2D.Collision.IBroadPhase="Box2D.Collision.IBroadPhase";Box2D.Collision.b2ContactID=function(){this._key=0;this._referenceEdge=0;this._incidentEdge=0;this._incidentVertex=0};Box2D.Collision.b2ContactID.prototype.GetKey=function(){return this._key};Box2D.Collision.b2ContactID.prototype.SetKey=function(a){this._key=a;this._referenceEdge=this._key&255;this._incidentEdge=((this._key&65280)>>8)&255;this._incidentVertex=((this._key&16711680)>>16)&255;this._flip=((this._key&4278190080)>>24)&255};Box2D.Collision.b2ContactID.prototype.Set=function(a){this.SetKey(a._key)};Box2D.Collision.b2ContactID.prototype.SetReferenceEdge=function(a){this._referenceEdge=a;this._key=(this._key&4294967040)|(this._referenceEdge&255)};Box2D.Collision.b2ContactID.prototype.SetIncidentEdge=function(a){this._incidentEdge=a;this._key=(this._key&4294902015)|((this._incidentEdge<<8)&65280)};Box2D.Collision.b2ContactID.prototype.SetIncidentVertex=function(a){this._incidentVertex=a;this._key=(this._key&4278255615)|((this._incidentVertex<<16)&16711680)};Box2D.Collision.b2ContactID.prototype.SetFlip=function(a){this._flip=a;this._key=(this._key&16777215)|((this._flip<<24)&4278190080)};Box2D.Collision.b2ContactID.prototype.Copy=function(){var a=new Box2D.Collision.b2ContactID();a.Set(this);return a};Box2D.Collision.b2ContactPoint=function(){this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID()};Box2D.Collision.b2Collision={};Box2D.Collision.b2Collision.s_maxSeparationA={};Box2D.Collision.b2Collision.s_maxSeparationB={};Box2D.Collision.b2Collision.ClipSegmentToLine=function(f,b,e,a){var c=0;var i=b[0].v;var h=b[1].v;var g=e.x*i.x+e.y*i.y-a;var d=e.x*h.x+e.y*h.y-a;if(g<=0){f[c++].Set(b[0])}if(d<=0){f[c++].Set(b[1])}if(g*d<0){var j=g/(g-d);var k=f[c].v;k.x=i.x+j*(h.x-i.x);k.y=i.y+j*(h.y-i.y);if(g>0){f[c].id=b[0].id}else{f[c].id=b[1].id}c++}return c};Box2D.Collision.b2Collision.EdgeSeparation=function(o,c,p,m,a){var g=(c.R.col1.x*o.GetNormal(p).x+c.R.col2.x*o.GetNormal(p).y);var f=(c.R.col1.y*o.GetNormal(p).x+c.R.col2.y*o.GetNormal(p).y);var q=(a.R.col1.x*g+a.R.col1.y*f);var n=(a.R.col2.x*g+a.R.col2.y*f);var e=0;var l=Number.MAX_VALUE;for(var s=0;s<m.m_vertexCount;s++){var r=m.GetVertex(s).x*q+m.GetVertex(s).y*n;if(r<l){l=r;e=s}}var d=c.position.x+(c.R.col1.x*o.GetVertex(p).x+c.R.col2.x*o.GetVertex(p).y);var b=c.position.y+(c.R.col1.y*o.GetVertex(p).x+c.R.col2.y*o.GetVertex(p).y);var k=a.position.x+(a.R.col1.x*m.GetVertex(e).x+a.R.col2.x*m.GetVertex(e).y);var h=a.position.y+(a.R.col1.y*m.GetVertex(e).x+a.R.col2.y*m.GetVertex(e).y);var j=(k-d)*g+(h-b)*f;return j};Box2D.Collision.b2Collision.FindMaxSeparation=function(o,c,n,b,m){var f=b.position.x+(b.R.col1.x*n.GetCentroid().x+b.R.col2.x*n.GetCentroid().y);var e=b.position.y+(b.R.col1.y*n.GetCentroid().x+b.R.col2.y*n.GetCentroid().y);f-=c.position.x+(c.R.col1.x*o.GetCentroid().x+c.R.col2.x*o.GetCentroid().y);e-=c.position.y+(c.R.col1.y*o.GetCentroid().x+c.R.col2.y*o.GetCentroid().y);var h=(f*c.R.col1.x+e*c.R.col1.y);var g=(f*c.R.col2.x+e*c.R.col2.y);var k=0;var a=(-Number.MAX_VALUE);for(var r=0;r<o.m_vertexCount;++r){var q=(o.GetNormal(r).x*h+o.GetNormal(r).y*g);if(q>a){a=q;k=r}}var p=Box2D.Collision.b2Collision.EdgeSeparation(o,c,k,n,b);var j=k-1;if(j<0){j=o.m_vertexCount-1}var u=Box2D.Collision.b2Collision.EdgeSeparation(o,c,j,n,b);var t=k+1;if(t>=o.m_vertexCount){t=0}var v=Box2D.Collision.b2Collision.EdgeSeparation(o,c,t,n,b);var d=0;var l=0;if(u>p&&u>v){d=j;l=u;while(true){k=d-1;if(k<0){k=o.m_vertexCount-1}p=Box2D.Collision.b2Collision.EdgeSeparation(o,c,k,n,b);if(p>l){d=k;l=p}else{break}}}else{if(v>p){d=t;l=v;while(true){k=d+1;if(k>=o.m_vertexCount){k=0}p=Box2D.Collision.b2Collision.EdgeSeparation(o,c,k,n,b);if(p>l){d=k;l=p}else{break}}}else{d=k;l=p}}m.bestEdge=d;m.separation=l;return m};Box2D.Collision.b2Collision.FindIncidentEdge=function(n,m,k,e,l,j){var d=(k.R.col1.x*m.GetNormal(e).x+k.R.col2.x*m.GetNormal(e).y);var b=(k.R.col1.y*m.GetNormal(e).x+k.R.col2.y*m.GetNormal(e).y);var p=(j.R.col1.x*d+j.R.col1.y*b);b=(j.R.col2.x*d+j.R.col2.y*b);d=p;var g=0;var o=Number.MAX_VALUE;for(var h=0;h<l.m_vertexCount;h++){var a=(d*l.GetNormal(h).x+b*l.GetNormal(h).y);if(a<o){o=a;g=h}}var f=g+1;if(f>=l.m_vertexCount){f=0}n[0].v.x=j.position.x+(j.R.col1.x*l.GetVertex(g).x+j.R.col2.x*l.GetVertex(g).y);n[0].v.y=j.position.y+(j.R.col1.y*l.GetVertex(g).x+j.R.col2.y*l.GetVertex(g).y);n[0].id.SetReferenceEdge(e);n[0].id.SetIncidentEdge(g);n[0].id.SetIncidentVertex(0);n[1].v.x=j.position.x+(j.R.col1.x*l.GetVertex(f).x+j.R.col2.x*l.GetVertex(f).y);n[1].v.y=j.position.y+(j.R.col1.y*l.GetVertex(f).x+j.R.col2.y*l.GetVertex(f).y);n[1].id.SetReferenceEdge(e);n[1].id.SetIncidentEdge(f);n[1].id.SetIncidentVertex(1)};Box2D.Collision.b2Collision.MakeClipPointVector=function(){return[new Box2D.Collision.ClipVertex(),new Box2D.Collision.ClipVertex()]};Box2D.Collision.b2Collision.CollidePolygons=function(r,f,u,e,s){r.SetPointCount(0);var n=f.GetRadius()+e.GetRadius();var k=Box2D.Collision.b2Collision.FindMaxSeparation(f,u,e,s,Box2D.Collision.b2Collision.s_maxSeparationA);if(k.separation>n){return}var j=Box2D.Collision.b2Collision.FindMaxSeparation(e,s,f,u,Box2D.Collision.b2Collision.s_maxSeparationB);if(j.separation>n){return}var m=f;var l=e;var c=u;var b=s;var g=0;var o=k.bestEdge;r.SetType(Box2D.Collision.b2Manifold.e_faceA);if(j.separation>0.98*k.separation+0.001){m=e;l=f;c=s;b=u;o=j.bestEdge;r.SetType(Box2D.Collision.b2Manifold.e_faceB);g=1}var d=Box2D.Collision.b2Collision.s_incidentEdge;Box2D.Collision.b2Collision.FindIncidentEdge(d,m,c,o,l,b);var a=m.GetVertex(o);var z;if(o+1<m.m_vertexCount){z=m.GetVertex(o+1)}else{z=m.GetVertex(0)}Box2D.Collision.b2Collision.s_localTangent.Set(z.x-a.x,z.y-a.y);Box2D.Collision.b2Collision.s_localTangent.Normalize();Box2D.Collision.b2Collision.s_localNormal.x=Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_localNormal.y=(-Box2D.Collision.b2Collision.s_localTangent.x);Box2D.Collision.b2Collision.s_planePoint.Set(0.5*(a.x+z.x),0.5*(a.y+z.y));Box2D.Collision.b2Collision.s_tangent.x=(c.R.col1.x*Box2D.Collision.b2Collision.s_localTangent.x+c.R.col2.x*Box2D.Collision.b2Collision.s_localTangent.y);Box2D.Collision.b2Collision.s_tangent.y=(c.R.col1.y*Box2D.Collision.b2Collision.s_localTangent.x+c.R.col2.y*Box2D.Collision.b2Collision.s_localTangent.y);Box2D.Collision.b2Collision.s_tangent2.x=(-Box2D.Collision.b2Collision.s_tangent.x);Box2D.Collision.b2Collision.s_tangent2.y=(-Box2D.Collision.b2Collision.s_tangent.y);Box2D.Collision.b2Collision.s_normal.x=Box2D.Collision.b2Collision.s_tangent.y;Box2D.Collision.b2Collision.s_normal.y=(-Box2D.Collision.b2Collision.s_tangent.x);Box2D.Collision.b2Collision.s_v11.x=c.position.x+(c.R.col1.x*a.x+c.R.col2.x*a.y);Box2D.Collision.b2Collision.s_v11.y=c.position.y+(c.R.col1.y*a.x+c.R.col2.y*a.y);Box2D.Collision.b2Collision.s_v12.x=c.position.x+(c.R.col1.x*z.x+c.R.col2.x*z.y);Box2D.Collision.b2Collision.s_v12.y=c.position.y+(c.R.col1.y*z.x+c.R.col2.y*z.y);var v=(-Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v11.x)-Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v11.y+n;if(Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints1,d,Box2D.Collision.b2Collision.s_tangent2,v)<2){return}var t=Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v12.x+Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v12.y+n;if(Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints2,Box2D.Collision.b2Collision.s_clipPoints1,Box2D.Collision.b2Collision.s_tangent,t)<2){return}r.m_localPlaneNormal.SetV(Box2D.Collision.b2Collision.s_localNormal);r.m_localPoint.SetV(Box2D.Collision.b2Collision.s_planePoint);var x=Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_v11.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_v11.y;var y=0;for(var w=0;w<Box2D.Common.b2Settings.b2_maxManifoldPoints;++w){var h=Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_clipPoints2[w].v.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_clipPoints2[w].v.y-x;if(h<=n){var q=Box2D.Collision.b2Collision.s_clipPoints2[w].v.x-b.position.x;var p=Box2D.Collision.b2Collision.s_clipPoints2[w].v.y-b.position.y;r.m_points[y].m_localPoint.x=(q*b.R.col1.x+p*b.R.col1.y);r.m_points[y].m_localPoint.y=(q*b.R.col2.x+p*b.R.col2.y);r.m_points[y].m_id.Set(Box2D.Collision.b2Collision.s_clipPoints2[w].id);r.m_points[y].m_id.SetFlip(g);y++}}r.SetPointCount(y)};Box2D.Collision.b2Collision.CollideCircles=function(f,g,j,e,h){f.SetPointCount(0);var k=j.position.x+(j.R.col1.x*g.GetLocalPosition().x+j.R.col2.x*g.GetLocalPosition().y);var i=j.position.y+(j.R.col1.y*g.GetLocalPosition().x+j.R.col2.y*g.GetLocalPosition().y);var b=h.position.x+(h.R.col1.x*e.GetLocalPosition().x+h.R.col2.x*e.GetLocalPosition().y);var a=h.position.y+(h.R.col1.y*e.GetLocalPosition().x+h.R.col2.y*e.GetLocalPosition().y);var d=b-k;var c=a-i;var m=d*d+c*c;var l=g.GetRadius()+e.GetRadius();if(m>l*l){return}f.SetType(Box2D.Collision.b2Manifold.e_circles);f.m_localPoint.SetV(g.GetLocalPosition());f.m_localPlaneNormal.SetZero();f.SetPointCount(1);f.m_points[0].m_localPoint.SetV(e.GetLocalPosition());f.m_points[0].m_id.SetKey(0)};Box2D.Collision.b2Collision.CollidePolygonAndCircle=function(r,n,c,j,b){r.SetPointCount(0);var g=b.position.x+(b.R.col1.x*j.GetLocalPosition().x+b.R.col2.x*j.GetLocalPosition().y)-c.position.x;var f=b.position.y+(b.R.col1.y*j.GetLocalPosition().x+b.R.col2.y*j.GetLocalPosition().y)-c.position.y;var q=(g*c.R.col1.x+f*c.R.col1.y);var p=(g*c.R.col2.x+f*c.R.col2.y);var w=0;var m=(-Number.MAX_VALUE);var h=n.GetRadius()+j.GetRadius();for(var u=0;u<n.m_vertexCount;++u){var o=n.GetNormal(u).x*(q-n.GetVertex(u).x)+n.GetNormal(u).y*(p-n.GetVertex(u).y);if(o>h){return}if(o>m){m=o;w=u}}var a=w+1;if(a>=n.m_vertexCount){a=0}var e=n.GetVertex(w);var d=n.GetVertex(a);if(m<Number.MIN_VALUE){r.SetPointCount(1);r.SetType(Box2D.Collision.b2Manifold.e_faceA);r.m_localPlaneNormal.SetV(n.GetNormal(w));r.m_localPoint.x=0.5*(e.x+d.x);r.m_localPoint.y=0.5*(e.y+d.y);r.m_points[0].m_localPoint.SetV(j.GetLocalPosition());r.m_points[0].m_id.SetKey(0)}else{var v=(q-e.x)*(d.x-e.x)+(p-e.y)*(d.y-e.y);if(v<=0){if((q-e.x)*(q-e.x)+(p-e.y)*(p-e.y)>h*h){return}r.SetPointCount(1);r.SetType(Box2D.Collision.b2Manifold.e_faceA);r.m_localPlaneNormal.x=q-e.x;r.m_localPlaneNormal.y=p-e.y;r.m_localPlaneNormal.Normalize();r.m_localPoint.SetV(e);r.m_points[0].m_localPoint.SetV(j.GetLocalPosition());r.m_points[0].m_id.SetKey(0)}else{var t=(q-d.x)*(e.x-d.x)+(p-d.y)*(e.y-d.y);if(t<=0){if((q-d.x)*(q-d.x)+(p-d.y)*(p-d.y)>h*h){return}r.SetPointCount(1);r.SetType(Box2D.Collision.b2Manifold.e_faceA);r.m_localPlaneNormal.x=q-d.x;r.m_localPlaneNormal.y=p-d.y;r.m_localPlaneNormal.Normalize();r.m_localPoint.SetV(d);r.m_points[0].m_localPoint.SetV(j.GetLocalPosition());r.m_points[0].m_id.SetKey(0)}else{var l=0.5*(e.x+d.x);var k=0.5*(e.y+d.y);m=(q-l)*n.GetNormal(w).x+(p-k)*n.GetNormal(w).y;if(m>h){return}r.SetPointCount(1);r.SetType(Box2D.Collision.b2Manifold.e_faceA);r.m_localPlaneNormal.x=n.GetNormal(w).x;r.m_localPlaneNormal.y=n.GetNormal(w).y;r.m_localPlaneNormal.Normalize();r.m_localPoint.Set(l,k);r.m_points[0].m_localPoint.SetV(j.GetLocalPosition());r.m_points[0].m_id.SetKey(0)}}}};Box2D.Collision.b2Collision.s_incidentEdge=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints1=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints2=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_localTangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_localNormal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_planePoint=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_normal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent2=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_v11=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_v12=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Distance={};Box2D.Collision.b2Distance.s_save=[];Box2D.Collision.b2Distance.s_saveCapacity=0;var b2Distance_d=b2Vec2Get(0,0);var b2Distance_negD=b2Vec2Get(0,0);var b2Distance_aNegD=b2Vec2Get(0,0);var b2Distance_bD=b2Vec2Get(0,0);var b2Distance_distanceV=b2Vec2Get(0,0);var b2Distance_temp=b2Vec2Get(0,0);Box2D.Collision.b2Distance.Distance=function(c,a,m){var l=Box2D.Collision.b2Simplex.Get();l.ReadCache(a,m.proxyA,m.transformA,m.proxyB,m.transformB);if(l.m_count<1||l.m_count>3){Box2D.Common.b2Settings.b2Assert(false)}var k=0;while(k<20){var j=Box2D.Collision.b2Distance.s_save;while(l.m_count>Box2D.Collision.b2Distance.s_saveCapacity){j.push({});Box2D.Collision.b2Distance.s_saveCapacity++}for(var d=0;d<l.m_count;d++){j[d].indexA=l.m_vertices[d].indexA;j[d].indexB=l.m_vertices[d].indexB}var b=l.m_count;if(l.m_count==2){l.Solve2()}else{if(l.m_count==3){l.Solve3()}}if(l.m_count==3){break}l.GetSearchDirectionInPlace(b2Distance_d);if(b2Distance_d.LengthSquared()<Box2D.Common.b2Settings.MIN_VALUE_SQUARED){break}var f=l.m_vertices[l.m_count];b2Distance_negD.x=-b2Distance_d.x;b2Distance_negD.y=-b2Distance_d.y;b2MathMulTMVInPlace(m.transformA.R,b2Distance_negD,b2Distance_aNegD);f.indexA=m.proxyA.GetSupport(b2Distance_aNegD);b2MathMulXInPlace(m.transformA,m.proxyA.GetVertex(f.indexA),f.wA);b2MathMulTMVInPlace(m.transformB.R,b2Distance_d,b2Distance_bD);f.indexB=m.proxyB.GetSupport(b2Distance_bD);b2MathMulXInPlace(m.transformB,m.proxyB.GetVertex(f.indexB),f.wB);b2MathSubtractVVInPlace(f.wB,f.wA,f.w);k++;var h=false;for(var d=0;d<b;d++){if(f.indexA==j[d].indexA&&f.indexB==j[d].indexB){h=true;break}}if(h){break}l.m_count++}l.GetWitnessPoints(c.pointA,c.pointB);b2MathSubtractVVInPlace(c.pointA,c.pointB,b2Distance_distanceV);c.distance=b2Distance_distanceV.Length();l.WriteCache(a);Box2D.Collision.b2Simplex.Free(l);if(m.useRadii){var g=m.proxyA.GetRadius();var e=m.proxyB.GetRadius();if(c.distance>g+e&&c.distance>Number.MIN_VALUE){c.distance-=g+e;b2MathSubtractVVInPlace(c.pointB,c.pointA,b2Distance_temp);b2Distance_temp.Normalize();c.pointA.x+=g*b2Distance_temp.x;c.pointA.y+=g*b2Distance_temp.y;c.pointB.x-=e*b2Distance_temp.x;c.pointB.y-=e*b2Distance_temp.y}else{b2Distance_temp.x=0.5*(c.pointA.x+c.pointB.x);b2Distance_temp.y=0.5*(c.pointA.y+c.pointB.y);c.pointA.x=c.pointB.x=b2Distance_temp.x;c.pointA.y=c.pointB.y=b2Distance_temp.y;c.distance=0}}};Box2D.Collision.b2DistanceInput=function(){this.useRadii=false;this.proxyA=null;this.proxyB=null;this.transformA=null;this.transformB=null};Box2D.Collision.b2DistanceInput._freeCache=[];Box2D.Collision.b2DistanceInput.Get=function(){if(Box2D.Collision.b2DistanceInput._freeCache.length>0){var a=Box2D.Collision.b2DistanceInput._freeCache.pop();a.useRadii=false;a.proxyA=null;a.proxyB=null;a.transformA=null;a.transformB=null;return a}return new Box2D.Collision.b2DistanceInput()};Box2D.Collision.b2DistanceInput.Free=function(a){if(a!=null){Box2D.Collision.b2DistanceInput._freeCache.push(a)}};Box2D.Collision.b2DistanceOutput=function(){this.pointA=Box2D.Common.Math.b2Vec2.Get(0,0);this.pointB=Box2D.Common.Math.b2Vec2.Get(0,0);this.distance=0};Box2D.Collision.b2DistanceOutput._freeCache=[];Box2D.Collision.b2DistanceOutput.Get=function(){if(Box2D.Collision.b2DistanceOutput._freeCache.length>0){var a=Box2D.Collision.b2DistanceOutput._freeCache.pop();a.pointA.Set(0,0);a.pointB.Set(0,0);a.distance=0;return a}return new Box2D.Collision.b2DistanceOutput()};Box2D.Collision.b2DistanceOutput.Free=function(a){if(a!=null){Box2D.Collision.b2DistanceOutput._freeCache.push(a)}};Box2D.Collision.b2DistanceProxy=function(){this.m_count=0;this.m_radius=0;this.m_vertices=null};Box2D.Collision.b2DistanceProxy.prototype.SetValues=function(c,a,b){this.m_count=c;this.m_radius=a;this.m_vertices=b};Box2D.Collision.b2DistanceProxy.prototype.Set=function(a){a.SetDistanceProxy(this)};Box2D.Collision.b2DistanceProxy.prototype.GetSupport=function(f){var b=0;var e=this.m_vertices[0].x*f.x+this.m_vertices[0].y*f.y;for(var a=1;a<this.m_count;a++){var c=this.m_vertices[a].x*f.x+this.m_vertices[a].y*f.y;if(c>e){b=a;e=c}}return b};Box2D.Collision.b2DistanceProxy.prototype.GetSupportVertex=function(a){return this.m_vertices[this.GetSupport(a)]};Box2D.Collision.b2DistanceProxy.prototype.GetVertexCount=function(){return this.m_count};Box2D.Collision.b2DistanceProxy.prototype.GetVertex=function(a){if(a===undefined){a=0}return this.m_vertices[a]};Box2D.Collision.b2DistanceProxy.prototype.GetRadius=function(){return this.m_radius};Box2D.Collision.b2DistanceProxy._freeCache=[];Box2D.Collision.b2DistanceProxy.Get=function(){if(Box2D.Collision.b2DistanceProxy._freeCache.length>0){var a=Box2D.Collision.b2DistanceProxy._freeCache.pop();a.m_count=0;a.m_radius=0;a.m_vertices=null;return a}return new Box2D.Collision.b2DistanceProxy()};Box2D.Collision.b2DistanceProxy.Free=function(a){if(a!=null){Box2D.Collision.b2DistanceProxy._freeCache.push(a);a.m_vertices=null}};Box2D.Collision.b2DynamicTree=function(){this.m_root=null;this.m_path=0;this.m_insertionCount=0};Box2D.Collision.b2DynamicTree.s_queryStack=[];Box2D.Collision.b2DynamicTree.prototype.CreateProxy=function(c,e){var d=Box2D.Collision.b2DynamicTreeNode.Get(e);var b=Box2D.Common.b2Settings.b2_aabbExtension;var a=Box2D.Common.b2Settings.b2_aabbExtension;d.GetAABB().Set(c.GetMinX()-b,c.GetMinY()-a,c.GetMaxX()+b,c.GetMaxY()+a);this.InsertLeaf(d);return d};Box2D.Collision.b2DynamicTree.prototype.DestroyProxy=function(a){this.RemoveLeaf(a);a.Destroy()};Box2D.Collision.b2DynamicTree.prototype.MoveProxy=function(e,c,d){Box2D.Common.b2Settings.b2Assert(e.IsLeaf());if(e.GetAABB().Contains(c)){return false}this.RemoveLeaf(e);var b=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*Math.abs(d.x);var a=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*Math.abs(d.y);e.GetAABB().Set(c.GetMinX()-b,c.GetMinY()-a,c.GetMaxX()+b,c.GetMaxY()+a);this.InsertLeaf(e);return true};Box2D.Collision.b2DynamicTree.prototype.Rebalance=function(c){if(this.m_root!==null){for(var a=0;a<c;a++){var b=this.m_root;var d=0;while(!b.IsLeaf()){b=(this.m_path>>d)&1?b.GetChild2():b.GetChild1();d=(d+1)&31}this.m_path++;this.RemoveLeaf(b);this.InsertLeaf(b)}}};Box2D.Collision.b2DynamicTree.prototype.GetFatAABB=function(a){return a.GetAABB()};Box2D.Collision.b2DynamicTree.prototype.Query=function(e,b,d){if(this.m_root!==null){var a=Box2D.Collision.b2DynamicTree.s_queryStack;a.length=0;a.push(this.m_root);while(a.length>0){var c=a.pop();if(c.GetAABB().TestOverlap(b)){if(c.IsLeaf()){if(!e.call(d,c.fixture)){return}}else{a.push(c.GetChild1());a.push(c.GetChild2())}}}}};Box2D.Collision.b2DynamicTree.prototype.RayCast=function(p,l){if(this.m_root===null){return}var a=Box2D.Common.Math.b2Math.SubtractVV(l.p1,l.p2);a.Normalize();var o=Box2D.Common.Math.b2Math.CrossFV(1,a);Box2D.Common.Math.b2Vec2.Free(a);var m=Box2D.Common.Math.b2Math.AbsV(o);var q=l.maxFraction;var n=l.p1.x+q*(l.p2.x-l.p1.x);var k=l.p1.y+q*(l.p2.y-l.p1.y);var b=Box2D.Collision.b2AABB.Get();b.Set(Math.min(l.p1.x,n),Math.min(l.p1.y,k),Math.max(l.p1.x,n),Math.max(l.p1.y,k));var j=Box2D.Array.Get();j.push(this.m_root);while(j.length>0){var d=j.pop();if(!d.GetAABB().TestOverlap(b)){continue}var i=d.GetAABB().GetCenter();var f=d.GetAABB().GetExtents();var e=Math.abs(o.x*(l.p1.x-i.x)+o.y*(l.p1.y-i.y))-m.x*f.x-m.y*f.y;Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(f);if(e>0){continue}if(d.IsLeaf()){var g=new Box2D.Collision.b2RayCastInput(l.p1,l.p2,l.maxFraction);q=p(l,d.GetFixture());if(q==0){break}if(q>0){n=l.p1.x+q*(l.p2.x-l.p1.x);k=l.p1.y+q*(l.p2.y-l.p1.y);b.Set(Math.min(l.p1.x,n),Math.min(l.p1.y,k),Math.max(l.p1.x,n),Math.max(l.p1.y,k))}}else{j.push(d.GetChild1());j.push(d.GetChild2())}}Box2D.Common.Math.b2Vec2.Free(o);Box2D.Common.Math.b2Vec2.Free(m);Box2D.Collision.b2AABB.Free(b);Box2D.Array.Free(j)};Box2D.Collision.b2DynamicTree.prototype.InsertLeaf=function(b){this.m_insertionCount++;if(this.m_root===null){this.m_root=b;this.m_root.SetParent(null);return}var d=this.GetBestSibling(b);var c=d.GetParent();var a=Box2D.Collision.b2DynamicTreeNode.Get();a.SetParent(c);a.GetAABB().Combine(b.GetAABB(),d.GetAABB());if(c){if(d.GetParent().GetChild1()==d){c.SetChild1(a)}else{c.SetChild2(a)}a.SetChild1(d);a.SetChild2(b);d.SetParent(a);b.SetParent(a);while(c){if(c.GetAABB().Contains(a.GetAABB())){break}c.GetAABB().Combine(c.GetChild1().GetAABB(),c.GetChild2().GetAABB());a=c;c=c.GetParent()}}else{a.SetChild1(d);a.SetChild2(b);d.SetParent(a);b.SetParent(a);this.m_root=a}};Box2D.Collision.b2DynamicTree.prototype.GetBestSibling=function(b){var a=b.GetAABB().GetCenter();var d=this.m_root;while(!d.IsLeaf()){var g=d.GetChild1();var f=d.GetChild2();var e=Math.abs((g.GetAABB().GetMinX()+g.GetAABB().GetMaxX())/2-a.x)+Math.abs((g.GetAABB().GetMinY()+g.GetAABB().GetMaxY())/2-a.y);var c=Math.abs((f.GetAABB().GetMinX()+f.GetAABB().GetMaxX())/2-a.x)+Math.abs((f.GetAABB().GetMinY()+f.GetAABB().GetMaxY())/2-a.y);if(e<c){d=g}else{d=f}}Box2D.Common.Math.b2Vec2.Free(a);return d};Box2D.Collision.b2DynamicTree.prototype.RemoveLeaf=function(c){if(c==this.m_root){this.m_root=null;return}var b=c.GetParent();var d=b.GetParent();var e;if(b.GetChild1()==c){e=b.GetChild2()}else{e=b.GetChild1()}if(d){if(d.GetChild1()==b){d.SetChild1(e)}else{d.SetChild2(e)}e.SetParent(d);while(d){var a=d.GetAABB();d.GetAABB().Combine(d.GetChild1().GetAABB(),d.GetChild2().GetAABB());if(a.Contains(d.GetAABB())){break}d=d.GetParent()}}else{this.m_root=e;e.SetParent(null)}b.Destroy()};Box2D.Collision.b2DynamicTreeBroadPhase=function(){this.m_tree=new Box2D.Collision.b2DynamicTree();this.m_moveBuffer=[];this.lastQueryFixtureA=null;this.lastQueryFixtureB=null;this.updatePairsCallback=null;this.queryProxy=null};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.CreateProxy=function(a,c){var b=this.m_tree.CreateProxy(a,c);this.BufferMove(b);return b};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.DestroyProxy=function(a){this.UnBufferMove(a);this.m_tree.DestroyProxy(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.MoveProxy=function(d,b,c){var a=this.m_tree.MoveProxy(d,b,c);if(a){this.BufferMove(d)}};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.TestOverlap=function(b,a){var d=this.m_tree.GetFatAABB(b);var c=this.m_tree.GetFatAABB(a);return d.TestOverlap(c)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.GetFatAABB=function(a){return this.m_tree.GetFatAABB(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.GetProxyCount=function(){return this.m_tree.length};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UpdatePairs=function(a){this.lastQueryFixtureA=null;this.lastQueryFixtureB=null;this.updatePairsCallback=a;while(this.m_moveBuffer.length>0){this.queryProxy=this.m_moveBuffer.pop();this.m_tree.Query(this.QueryCallback,this.m_tree.GetFatAABB(this.queryProxy),this)}this.lastQueryFixtureA=null;this.lastQueryFixtureB=null;this.updatePairsCallback=null;this.queryProxy=null};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.QueryCallback=function(a){if(a!=this.queryProxy.fixture){if(!(this.queryProxy.fixture==this.lastQueryFixtureA&&a==this.lastQueryFixtureB)&&!(this.queryProxy.fixture==this.lastQueryFixtureB&&a==this.lastQueryFixtureA)){this.updatePairsCallback(this.queryProxy.fixture,a);this.lastQueryFixtureA=this.queryProxy.fixture;this.lastQueryFixtureB=a}}return true};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Query=function(b,a){this.m_tree.Query(b,a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.RayCast=function(b,a){this.m_tree.RayCast(b,a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Rebalance=function(a){this.m_tree.Rebalance(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.BufferMove=function(a){this.m_moveBuffer.push(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UnBufferMove=function(a){Box2D.Array.remove(this.m_moveBuffer,a)};Box2D.Collision.b2DynamicTreeBroadPhase.__implements={};Box2D.Collision.b2DynamicTreeBroadPhase.__implements[Box2D.Collision.IBroadPhase]=true;Box2D.Collision.b2DynamicTreeNode=function(a){this.aabb=Box2D.Collision.b2AABB.Get();this.child1=null;this.child2=null;this.parent=null;this.fixture=a};Box2D.Collision.b2DynamicTreeNode._freeCache=[];Box2D.Collision.b2DynamicTreeNode.Get=function(b){if(typeof(b)=="undefined"){b=null}if(Box2D.Collision.b2DynamicTreeNode._freeCache.length>0){var a=Box2D.Collision.b2DynamicTreeNode._freeCache.pop();a.fixture=b;a.aabb.SetZero();return a}return new Box2D.Collision.b2DynamicTreeNode(b)};Box2D.Collision.b2DynamicTreeNode.prototype.Destroy=function(){this.child1=null;this.child2=null;this.parent=null;this.fixture=null;Box2D.Collision.b2DynamicTreeNode._freeCache.push(this)};Box2D.Collision.b2DynamicTreeNode.prototype.IsLeaf=function(){return this.child1===null};Box2D.Collision.b2DynamicTreeNode.prototype.SetChild1=function(a){this.child1=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetChild1=function(){return this.child1};Box2D.Collision.b2DynamicTreeNode.prototype.SetChild2=function(a){this.child2=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetChild2=function(){return this.child2};Box2D.Collision.b2DynamicTreeNode.prototype.SetParent=function(a){this.parent=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetParent=function(){return this.parent};Box2D.Collision.b2DynamicTreeNode.prototype.GetAABB=function(){return this.aabb};Box2D.Collision.b2DynamicTreeNode.prototype.GetFixture=function(){return this.fixture};Box2D.Collision.b2DynamicTreePair=function(a,b){this.fixtureA=a;this.fixtureB=b};Box2D.Collision.b2DynamicTreePair._freeCache=[];Box2D.Collision.b2DynamicTreePair.Get=function(a,c){if(Box2D.Collision.b2DynamicTreePair._freeCache.length>0){var b=Box2D.Collision.b2DynamicTreePair._freeCache.pop();b.fixtureA=a;b.fixtureB=c;return b}return new Box2D.Collision.b2DynamicTreePair(a,c)};Box2D.Collision.b2DynamicTreePair.Free=function(a){if(a!=null){Box2D.Collision.b2DynamicTreePair._freeCache.push(a)}};Box2D.Collision.b2Manifold=function(){this.m_pointCount=0;this.m_type=0;this.m_points=Box2D.Array.Get();for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++){this.m_points[a]=new Box2D.Collision.b2ManifoldPoint()}this.m_localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Manifold.prototype.Reset=function(){for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++){this.m_points[a].Reset()}this.m_localPlaneNormal.SetZero();this.m_localPoint.SetZero();this.m_type=0;this.m_pointCount=0};Box2D.Collision.b2Manifold.prototype.Set=function(a){this.m_pointCount=a.m_pointCount;for(var b=0;b<Box2D.Common.b2Settings.b2_maxManifoldPoints;b++){this.m_points[b].Set(a.m_points[b])}this.m_localPlaneNormal.SetV(a.m_localPlaneNormal);this.m_localPoint.SetV(a.m_localPoint);this.m_type=a.m_type};Box2D.Collision.b2Manifold.prototype.Copy=function(){var a=new Box2D.Collision.b2Manifold();a.Set(this);return a};Box2D.Collision.b2Manifold.prototype.SetPointCount=function(a){this.m_pointCount=a};Box2D.Collision.b2Manifold.prototype.SetType=function(a){this.m_type=a};Box2D.Collision.b2Manifold.e_circles=1;Box2D.Collision.b2Manifold.e_faceA=2;Box2D.Collision.b2Manifold.e_faceB=4;Box2D.Collision.b2ManifoldPoint=function(){this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_id=new Box2D.Collision.b2ContactID();this.m_normalImpulse=0;this.m_tangentImpulse=0};Box2D.Collision.b2ManifoldPoint.prototype.Reset=function(){this.m_localPoint.SetZero();this.m_normalImpulse=0;this.m_tangentImpulse=0;this.m_id.SetKey(0)};Box2D.Collision.b2ManifoldPoint.prototype.Set=function(a){this.m_localPoint.SetV(a.m_localPoint);this.m_normalImpulse=a.m_normalImpulse;this.m_tangentImpulse=a.m_tangentImpulse;this.m_id.Set(a.m_id)};Box2D.Collision.b2RayCastInput=function(c,b,a){this.p1=Box2D.Common.Math.b2Vec2.Get(c.x,c.y);this.p2=Box2D.Common.Math.b2Vec2.Get(b.x,b.y);this.maxFraction=a};Box2D.Collision.b2RayCastOutput=function(){this.normal=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Segment=function(){this.p1=Box2D.Common.Math.b2Vec2.Get(0,0);this.p2=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Segment.prototype.TestSegment=function(j,r,d,n){var k=d.p1;var q=d.p2.x-k.x;var o=d.p2.y-k.y;var f=this.p2.x-this.p1.x;var e=this.p2.y-this.p1.y;var m=e;var l=(-f);var t=100*Number.MIN_VALUE;var c=(-(q*m+o*l));if(c>t){var i=k.x-this.p1.x;var h=k.y-this.p1.y;var p=(i*m+h*l);if(0<=p&&p<=n*c){var b=(-q*h)+o*i;if((-t*c)<=b&&b<=c*(1+t)){p/=c;var g=Math.sqrt(m*m+l*l);m/=g;l/=g;j[0]=p;r.Set(m,l);return true}}}return false};Box2D.Collision.b2Segment.prototype.Extend=function(a){this.ExtendForward(a);this.ExtendBackward(a)};Box2D.Collision.b2Segment.prototype.ExtendForward=function(c){var b=this.p2.x-this.p1.x;var a=this.p2.y-this.p1.y;var d=Math.min(b>0?(c.upperBound.x-this.p1.x)/b:b<0?(c.lowerBound.x-this.p1.x)/b:Number.POSITIVE_INFINITY,a>0?(c.upperBound.y-this.p1.y)/a:a<0?(c.lowerBound.y-this.p1.y)/a:Number.POSITIVE_INFINITY);this.p2.x=this.p1.x+b*d;this.p2.y=this.p1.y+a*d};Box2D.Collision.b2Segment.prototype.ExtendBackward=function(c){var b=(-this.p2.x)+this.p1.x;var a=(-this.p2.y)+this.p1.y;var d=Math.min(b>0?(c.upperBound.x-this.p2.x)/b:b<0?(c.lowerBound.x-this.p2.x)/b:Number.POSITIVE_INFINITY,a>0?(c.upperBound.y-this.p2.y)/a:a<0?(c.lowerBound.y-this.p2.y)/a:Number.POSITIVE_INFINITY);this.p1.x=this.p2.x+b*d;this.p1.y=this.p2.y+a*d};Box2D.Collision.b2SeparationFunction=function(){this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_proxyA=null;this.m_proxyB=null};Box2D.Collision.b2SeparationFunction.prototype.Initialize=function(z,H,u,G,q){this.m_proxyA=H;this.m_proxyB=G;var l=z.count;Box2D.Common.b2Settings.b2Assert(0<l&&l<3);var w;var k;var j;var v;var C;var B;var O=0;var N=0;var o=0;var m=0;var i=0;var h=0;var p;var g;var y=0;var n=0;if(l==1){this.m_type=Box2D.Collision.b2SeparationFunction.e_points;w=this.m_proxyA.GetVertex(z.indexA[0]);v=this.m_proxyB.GetVertex(z.indexB[0]);g=w;p=u.R;O=u.position.x+(p.col1.x*g.x+p.col2.x*g.y);N=u.position.y+(p.col1.y*g.x+p.col2.y*g.y);g=v;p=q.R;o=q.position.x+(p.col1.x*g.x+p.col2.x*g.y);m=q.position.y+(p.col1.y*g.x+p.col2.y*g.y);this.m_axis.x=o-O;this.m_axis.y=m-N;this.m_axis.Normalize()}else{if(z.indexB[0]==z.indexB[1]){this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA;k=this.m_proxyA.GetVertex(z.indexA[0]);j=this.m_proxyA.GetVertex(z.indexA[1]);v=this.m_proxyB.GetVertex(z.indexB[0]);this.m_localPoint.x=0.5*(k.x+j.x);this.m_localPoint.y=0.5*(k.y+j.y);var E=Box2D.Common.Math.b2Math.SubtractVV(j,k);Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.CrossVF(E,1);Box2D.Common.Math.b2Vec2.Free(E);this.m_axis.Normalize();g=this.m_axis;p=u.R;i=p.col1.x*g.x+p.col2.x*g.y;h=p.col1.y*g.x+p.col2.y*g.y;g=this.m_localPoint;p=u.R;O=u.position.x+(p.col1.x*g.x+p.col2.x*g.y);N=u.position.y+(p.col1.y*g.x+p.col2.y*g.y);g=v;p=q.R;o=q.position.x+(p.col1.x*g.x+p.col2.x*g.y);m=q.position.y+(p.col1.y*g.x+p.col2.y*g.y);y=(o-O)*i+(m-N)*h;if(y<0){this.m_axis.NegativeSelf()}}else{if(z.indexA[0]==z.indexA[0]){this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB;C=this.m_proxyB.GetVertex(z.indexB[0]);B=this.m_proxyB.GetVertex(z.indexB[1]);w=this.m_proxyA.GetVertex(z.indexA[0]);this.m_localPoint.x=0.5*(C.x+B.x);this.m_localPoint.y=0.5*(C.y+B.y);var E=Box2D.Common.Math.b2Math.SubtractVV(B,C);Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.CrossVF(E,1);Box2D.Common.Math.b2Vec2.Free(E);this.m_axis.Normalize();g=this.m_axis;p=q.R;i=p.col1.x*g.x+p.col2.x*g.y;h=p.col1.y*g.x+p.col2.y*g.y;g=this.m_localPoint;p=q.R;o=q.position.x+(p.col1.x*g.x+p.col2.x*g.y);m=q.position.y+(p.col1.y*g.x+p.col2.y*g.y);g=w;p=u.R;O=u.position.x+(p.col1.x*g.x+p.col2.x*g.y);N=u.position.y+(p.col1.y*g.x+p.col2.y*g.y);y=(O-o)*i+(N-m)*h;if(y<0){this.m_axis.NegativeSelf()}}else{k=this.m_proxyA.GetVertex(z.indexA[0]);j=this.m_proxyA.GetVertex(z.indexA[1]);C=this.m_proxyB.GetVertex(z.indexB[0]);B=this.m_proxyB.GetVertex(z.indexB[1]);var E=Box2D.Common.Math.b2Math.SubtractVV(j,k);var F=Box2D.Common.Math.b2Math.MulMV(u.R,E);Box2D.Common.Math.b2Vec2.Free(E);E=Box2D.Common.Math.b2Math.SubtractVV(B,C);var D=Box2D.Common.Math.b2Math.MulMV(q.R,E);Box2D.Common.Math.b2Vec2.Free(E);var M=F.x*F.x+F.y*F.y;var J=D.x*D.x+D.y*D.y;var A=Box2D.Common.Math.b2Math.SubtractVV(D,F);var K=F.x*A.x+F.y*A.y;var I=D.x*A.x+D.y*A.y;Box2D.Common.Math.b2Vec2.Free(A);var L=F.x*D.x+F.y*D.y;var d=M*J-L*L;y=0;if(d!=0){y=Box2D.Common.Math.b2Math.Clamp01((L*I-K*J)/d)}var x=(L*y+I)/J;if(x<0){x=0;y=Box2D.Common.Math.b2Math.Clamp01((L-K)/M)}w=Box2D.Common.Math.b2Vec2.Get(0,0);w.x=k.x+y*(j.x-k.x);w.y=k.y+y*(j.y-k.y);v=Box2D.Common.Math.b2Vec2.Get(0,0);v.x=C.x+y*(B.x-C.x);v.y=C.y+y*(B.y-C.y);if(y==0||y==1){this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB;E=Box2D.Common.Math.b2Math.SubtractVV(B,C);Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.CrossVF(E,1);Box2D.Common.Math.b2Vec2.Free(E);this.m_axis.Normalize();this.m_localPoint=v;g=this.m_axis;p=q.R;i=p.col1.x*g.x+p.col2.x*g.y;h=p.col1.y*g.x+p.col2.y*g.y;g=this.m_localPoint;p=q.R;o=q.position.x+(p.col1.x*g.x+p.col2.x*g.y);m=q.position.y+(p.col1.y*g.x+p.col2.y*g.y);g=w;p=u.R;O=u.position.x+(p.col1.x*g.x+p.col2.x*g.y);N=u.position.y+(p.col1.y*g.x+p.col2.y*g.y);n=(O-o)*i+(N-m)*h;if(y<0){this.m_axis.NegativeSelf()}}else{this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA;E=Box2D.Common.Math.b2Math.SubtractVV(j,k);Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.CrossVF(E,1);Box2D.Common.Math.b2Vec2.Free(E);this.m_localPoint=w;g=this.m_axis;p=u.R;i=p.col1.x*g.x+p.col2.x*g.y;h=p.col1.y*g.x+p.col2.y*g.y;g=this.m_localPoint;p=u.R;O=u.position.x+(p.col1.x*g.x+p.col2.x*g.y);N=u.position.y+(p.col1.y*g.x+p.col2.y*g.y);g=v;p=q.R;o=q.position.x+(p.col1.x*g.x+p.col2.x*g.y);m=q.position.y+(p.col1.y*g.x+p.col2.y*g.y);n=(o-O)*i+(m-N)*h;if(y<0){this.m_axis.NegativeSelf()}}Box2D.Common.Math.b2Vec2.Free(w);Box2D.Common.Math.b2Vec2.Free(v)}}}};Box2D.Collision.b2SeparationFunction.prototype.Evaluate=function(k,j){var e=0;switch(this.m_type){case Box2D.Collision.b2SeparationFunction.e_points:var d=Box2D.Common.Math.b2Math.MulTMV(k.R,this.m_axis);var h=this.m_axis.GetNegative();var c=Box2D.Common.Math.b2Math.MulTMV(j.R,h);Box2D.Common.Math.b2Vec2.Free(h);var g=this.m_proxyA.GetSupportVertex(d);Box2D.Common.Math.b2Vec2.Free(d);var f=this.m_proxyB.GetSupportVertex(c);Box2D.Common.Math.b2Vec2.Free(c);var a=Box2D.Common.Math.b2Math.MulX(k,g);var l=Box2D.Common.Math.b2Math.MulX(j,f);e=(l.x-a.x)*this.m_axis.x+(l.y-a.y)*this.m_axis.y;Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(l);break;case Box2D.Collision.b2SeparationFunction.e_faceA:var i=Box2D.Common.Math.b2Math.MulMV(k.R,this.m_axis);var b=i.GetNegative();var c=Box2D.Common.Math.b2Math.MulTMV(j.R,b);Box2D.Common.Math.b2Vec2.Free(b);var f=this.m_proxyB.GetSupportVertex(c);Box2D.Common.Math.b2Vec2.Free(c);var a=Box2D.Common.Math.b2Math.MulX(k,this.m_localPoint);var l=Box2D.Common.Math.b2Math.MulX(j,f);e=(l.x-a.x)*i.x+(l.y-a.y)*i.y;Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(l);break;case Box2D.Collision.b2SeparationFunction.e_faceB:var i=Box2D.Common.Math.b2Math.MulMV(j.R,this.m_axis);var b=i.GetNegative();var d=Box2D.Common.Math.b2Math.MulTMV(k.R,b);Box2D.Common.Math.b2Vec2.Free(b);var g=this.m_proxyA.GetSupportVertex(d);Box2D.Common.Math.b2Vec2.Free(d);var a=Box2D.Common.Math.b2Math.MulX(k,g);var l=Box2D.Common.Math.b2Math.MulX(j,this.m_localPoint);e=(a.x-l.x)*i.x+(a.y-l.y)*i.y;Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(l);break;default:Box2D.Common.b2Settings.b2Assert(false);break}return e};Box2D.Collision.b2SeparationFunction.e_points=1;Box2D.Collision.b2SeparationFunction.e_faceA=2;Box2D.Collision.b2SeparationFunction.e_faceB=4;Box2D.Collision.b2Simplex=function(){this.m_v1=new Box2D.Collision.b2SimplexVertex();this.m_v2=new Box2D.Collision.b2SimplexVertex();this.m_v3=new Box2D.Collision.b2SimplexVertex();this.m_vertices=[this.m_v1,this.m_v2,this.m_v3]};Box2D.Collision.b2Simplex._freeCache=[];Box2D.Collision.b2Simplex.Get=function(){if(Box2D.Collision.b2Simplex._freeCache.length>0){var c=Box2D.Collision.b2Simplex._freeCache.pop();var e=c.m_vertices;var b=e.length;for(var f=0;f<b;f++){var d=e[f];var h=d.wA;if(h!=null){h.x=0;h.y=0}var g=d.wB;if(g!=null){g.x=0;g.y=0}var a=d.w;if(a!=null){a.x=0;a.y=0}d.indexA=0;d.indexB=0;d.a=0}return c}return new Box2D.Collision.b2Simplex()};Box2D.Collision.b2Simplex.Free=function(a){if(a!=null){Box2D.Collision.b2Simplex._freeCache.push(a)}};Box2D.Collision.b2Simplex.prototype.ReadCache=function(a,j,o,h,m){var b;var c;this.m_count=a.count;var g=this.m_vertices;for(var d=0;d<this.m_count;d++){var p=g[d];p.indexA=a.indexA[d];p.indexB=a.indexB[d];b=j.GetVertex(p.indexA);c=h.GetVertex(p.indexB);var l=p.wA;var k=p.wB;var n=p.w;b2MathMulXInPlace(o,b,l);b2MathMulXInPlace(m,c,k);b2MathSubtractVVInPlace(k,l,n);p.a=0}if(this.m_count>1){var f=a.metric;var e=this.GetMetric();if(e<0.5*f||2*f<e||e<Number.MIN_VALUE){this.m_count=0}}if(this.m_count==0){p=g[0];p.indexA=0;p.indexB=0;b=j.GetVertex(0);c=h.GetVertex(0);b2MathMulXInPlace(o,b,p.wA);b2MathMulXInPlace(m,c,p.wB);b2MathSubtractVVInPlace(p.wB,p.wA,p.w);this.m_count=1}};Box2D.Collision.b2Simplex.prototype.WriteCache=function(a){a.metric=this.GetMetric();a.count=this.m_count;var b=this.m_vertices;for(var c=0;c<this.m_count;c++){a.indexA[c]=b[c].indexA;a.indexB[c]=b[c].indexB}};Box2D.Collision.b2Simplex.prototype.GetSearchDirection=function(){if(this.m_count==1){return this.m_v1.w.GetNegative()}else{if(this.m_count==2){var e=this.m_v1.w;var d=this.m_v2.w;var b=b2Vec2Get(d.x-e.x,d.y-e.y);var c=(b.x*-e.y)-(b.y*-e.x);if(c>0){var a=b.x;b.x=-1*b.y;b.y=a}else{var a=b.y;b.y=-1*b.x;b.x=a}return b}else{Box2D.Common.b2Settings.b2Assert(false);return b2Vec2Get(0,0)}}};Box2D.Collision.b2Simplex.prototype.GetSearchDirectionInPlace=function(b){if(this.m_count==1){var e=this.m_v1.w;b.x=-e.x;b.y=-e.y}else{if(this.m_count==2){var e=this.m_v1.w;var d=this.m_v2.w;b.x=d.x-e.x;b.y=d.y-e.y;var c=(b.x*-e.y)-(b.y*-e.x);if(c>0){var a=b.x;b.x=-1*b.y;b.y=a}else{var a=b.y;b.y=-1*b.x;b.x=a}}else{Box2D.Common.b2Settings.b2Assert(false);b.x=0;b.y=0}}};Box2D.Collision.b2Simplex.prototype.GetClosestPoint=function(){if(this.m_count==1){return this.m_v1.w}else{if(this.m_count==2){return Box2D.Common.Math.b2Vec2.Get(this.m_v1.a*this.m_v1.w.x+this.m_v2.a*this.m_v2.w.x,this.m_v1.a*this.m_v1.w.y+this.m_v2.a*this.m_v2.w.y)}else{Box2D.Common.b2Settings.b2Assert(false);return Box2D.Common.Math.b2Vec2.Get(0,0)}}};Box2D.Collision.b2Simplex.prototype.GetWitnessPoints=function(b,a){if(this.m_count==1){b.SetV(this.m_v1.wA);a.SetV(this.m_v1.wB)}else{if(this.m_count==2){b.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x;b.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y;a.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x;a.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y}else{if(this.m_count==3){a.x=b.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x+this.m_v3.a*this.m_v3.wA.x;a.y=b.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y+this.m_v3.a*this.m_v3.wA.y}else{Box2D.Common.b2Settings.b2Assert(false)}}}};Box2D.Collision.b2Simplex.prototype.GetMetric=function(){if(this.m_count==1){return 0}else{if(this.m_count==2){var a=Box2D.Common.Math.b2Math.SubtractVV(this.m_v1.w,this.m_v2.w);var b=a.Length();Box2D.Common.Math.b2Vec2.Free(a);return b}else{if(this.m_count==3){var d=Box2D.Common.Math.b2Math.SubtractVV(this.m_v2.w,this.m_v1.w);var c=Box2D.Common.Math.b2Math.SubtractVV(this.m_v3.w,this.m_v1.w);var b=Box2D.Common.Math.b2Math.CrossVV(d,c);Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(c);return b}else{Box2D.Common.b2Settings.b2Assert(false);return 0}}}};Box2D.Collision.b2Simplex.prototype.Solve2=function(){var b=this.m_v1.w;var a=this.m_v2.w;var d=Box2D.Common.Math.b2Math.SubtractVV(a,b);var e=(-(b.x*d.x+b.y*d.y));if(e<=0){Box2D.Common.Math.b2Vec2.Free(d);this.m_v1.a=1;this.m_count=1;return}var f=(a.x*d.x+a.y*d.y);Box2D.Common.Math.b2Vec2.Free(d);if(f<=0){this.m_v2.a=1;this.m_count=1;this.m_v1.Set(this.m_v2);return}var c=1/(f+e);this.m_v1.a=f*c;this.m_v2.a=e*c;this.m_count=2};Box2D.Collision.b2Simplex.prototype.Solve3=function(){var o=this.m_v1.w;var m=this.m_v2.w;var j=this.m_v3.w;var p=Box2D.Common.Math.b2Math.SubtractVV(m,o);var d=Box2D.Common.Math.b2Math.Dot(o,p);var f=Box2D.Common.Math.b2Math.Dot(m,p);var z=f;var y=(-d);var n=Box2D.Common.Math.b2Math.SubtractVV(j,o);var c=Box2D.Common.Math.b2Math.Dot(o,n);var r=Box2D.Common.Math.b2Math.Dot(j,n);var k=Box2D.Common.Math.b2Math.CrossVV(p,n);Box2D.Common.Math.b2Vec2.Free(p);Box2D.Common.Math.b2Vec2.Free(n);var s=r;var q=(-c);var w=Box2D.Common.Math.b2Math.SubtractVV(j,m);var v=Box2D.Common.Math.b2Math.Dot(m,w);var x=Box2D.Common.Math.b2Math.Dot(j,w);Box2D.Common.Math.b2Vec2.Free(w);var u=x;var t=(-v);var i=k*Box2D.Common.Math.b2Math.CrossVV(m,j);var h=k*Box2D.Common.Math.b2Math.CrossVV(j,o);var e=k*Box2D.Common.Math.b2Math.CrossVV(o,m);if(y<=0&&q<=0){this.m_v1.a=1;this.m_count=1;return}if(z>0&&y>0&&e<=0){var b=1/(z+y);this.m_v1.a=z*b;this.m_v2.a=y*b;this.m_count=2;return}if(s>0&&q>0&&h<=0){var a=1/(s+q);this.m_v1.a=s*a;this.m_v3.a=q*a;this.m_count=2;this.m_v2.Set(this.m_v3);return}if(z<=0&&t<=0){this.m_v2.a=1;this.m_count=1;this.m_v1.Set(this.m_v2);return}if(s<=0&&u<=0){this.m_v3.a=1;this.m_count=1;this.m_v1.Set(this.m_v3);return}if(u>0&&t>0&&i<=0){var l=1/(u+t);this.m_v2.a=u*l;this.m_v3.a=t*l;this.m_count=2;this.m_v1.Set(this.m_v3);return}var g=1/(i+h+e);this.m_v1.a=i*g;this.m_v2.a=h*g;this.m_v3.a=e*g;this.m_count=3};Box2D.Collision.b2SimplexCache=function(){this.count=0;this.indexA=[0,0,0];this.indexB=[0,0,0]};Box2D.Collision.b2SimplexCache._freeCache=[];Box2D.Collision.b2SimplexCache.Get=function(){if(Box2D.Collision.b2SimplexCache._freeCache.length>0){var b=Box2D.Collision.b2SimplexCache._freeCache.pop();for(var a=0;a<3;a++){b.indexA[a]=0;b.indexB[a]=0}b.count=0;return b}return new Box2D.Collision.b2SimplexCache()};Box2D.Collision.b2SimplexCache.Free=function(a){if(a!=null){Box2D.Collision.b2SimplexCache._freeCache.push(a)}};Box2D.Collision.b2SimplexVertex=function(){this.wA=Box2D.Common.Math.b2Vec2.Get(0,0);this.wB=Box2D.Common.Math.b2Vec2.Get(0,0);this.w=Box2D.Common.Math.b2Vec2.Get(0,0);this.a=0;this.indexA=0;this.indexB=0};Box2D.Collision.b2SimplexVertex.prototype.Set=function(a){this.wA.SetV(a.wA);this.wB.SetV(a.wB);this.w.SetV(a.w);this.a=a.a;this.indexA=a.indexA;this.indexB=a.indexB};Box2D.Collision.b2TOIInput=function(){this.proxyA=Box2D.Collision.b2DistanceProxy.Get();this.proxyB=Box2D.Collision.b2DistanceProxy.Get();this.sweepA=new Box2D.Common.Math.b2Sweep();this.sweepB=new Box2D.Common.Math.b2Sweep()};Box2D.Collision.b2TimeOfImpact={};Box2D.Collision.b2TimeOfImpact.TimeOfImpact=function(i){Box2D.Collision.b2TimeOfImpact.b2_toiCalls++;var r=i.proxyA;var p=i.proxyB;var c=i.sweepA;var b=i.sweepB;Box2D.Common.b2Settings.b2Assert(c.t0==b.t0);Box2D.Common.b2Settings.b2Assert(1-c.t0>Number.MIN_VALUE);var d=r.m_radius+p.m_radius;var o=i.tolerance;var e=0;var j=1000;var n=0;var u=0;Box2D.Collision.b2TimeOfImpact.s_cache.count=0;Box2D.Collision.b2TimeOfImpact.s_distanceInput.useRadii=false;for(;;){c.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,e);b.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,e);Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyA=r;Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyB=p;Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformA=Box2D.Collision.b2TimeOfImpact.s_xfA;Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformB=Box2D.Collision.b2TimeOfImpact.s_xfB;Box2D.Collision.b2Distance.Distance(Box2D.Collision.b2TimeOfImpact.s_distanceOutput,Box2D.Collision.b2TimeOfImpact.s_cache,Box2D.Collision.b2TimeOfImpact.s_distanceInput);if(Box2D.Collision.b2TimeOfImpact.s_distanceOutput.distance<=0){e=1;break}Box2D.Collision.b2TimeOfImpact.s_fcn.Initialize(Box2D.Collision.b2TimeOfImpact.s_cache,r,Box2D.Collision.b2TimeOfImpact.s_xfA,p,Box2D.Collision.b2TimeOfImpact.s_xfB);var g=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(g<=0){e=1;break}if(n==0){if(g>d){u=Math.max(d-o,0.75*d)}else{u=Math.max(g-o,0.02*d)}}if(g-u<0.5*o){if(n==0){e=1;break}break}var a=e;var s=e;var q=1;var m=g;c.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,q);b.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,q);var l=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(l>=u){e=1;break}var k=0;for(;;){var h=0;if(k&1){h=s+(u-m)*(q-s)/(l-m)}else{h=0.5*(s+q)}c.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,h);b.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,h);var t=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(Math.abs(t-u)<0.025*o){a=h;break}if(t>u){s=h;m=t}else{q=h;l=t}k++;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters++;if(k==50){break}}Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters,k);if(a<(1+100*Number.MIN_VALUE)*e){break}e=a;n++;Box2D.Collision.b2TimeOfImpact.b2_toiIters++;if(n==j){break}}Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters,n);return e};Box2D.Collision.b2TimeOfImpact.b2_toiCalls=0;Box2D.Collision.b2TimeOfImpact.b2_toiIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=0;Box2D.Collision.b2TimeOfImpact.s_cache=new Box2D.Collision.b2SimplexCache();Box2D.Collision.b2TimeOfImpact.s_distanceInput=new Box2D.Collision.b2DistanceInput();Box2D.Collision.b2TimeOfImpact.s_xfA=new Box2D.Common.Math.b2Transform();Box2D.Collision.b2TimeOfImpact.s_xfB=new Box2D.Common.Math.b2Transform();Box2D.Collision.b2TimeOfImpact.s_fcn=new Box2D.Collision.b2SeparationFunction();Box2D.Collision.b2TimeOfImpact.s_distanceOutput=new Box2D.Collision.b2DistanceOutput();Box2D.Collision.b2WorldManifold=function(){this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_points=[];this.m_pointCount=0;for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++){this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)}};Box2D.Collision.b2WorldManifold.prototype.Initialize=function(o,q,t,p,s){if(o.m_pointCount==0){return}var r=0;var c;var n;var h=0;var f=0;var b=0;var B=0;var w=0;var v=0;switch(o.m_type){case Box2D.Collision.b2Manifold.e_circles:n=q.R;c=o.m_localPoint;var A=q.position.x+n.col1.x*c.x+n.col2.x*c.y;var y=q.position.y+n.col1.y*c.x+n.col2.y*c.y;n=p.R;c=o.m_points[0].m_localPoint;var l=p.position.x+n.col1.x*c.x+n.col2.x*c.y;var j=p.position.y+n.col1.y*c.x+n.col2.y*c.y;var g=l-A;var e=j-y;var x=g*g+e*e;if(x>Box2D.Common.b2Settings.MIN_VALUE_SQUARED){var u=Math.sqrt(x);this.m_normal.x=g/u;this.m_normal.y=e/u}else{this.m_normal.x=1;this.m_normal.y=0}var a=A+t*this.m_normal.x;var z=y+t*this.m_normal.y;var m=l-s*this.m_normal.x;var k=j-s*this.m_normal.y;this.m_points[0].x=0.5*(a+m);this.m_points[0].y=0.5*(z+k);break;case Box2D.Collision.b2Manifold.e_faceA:n=q.R;c=o.m_localPlaneNormal;h=n.col1.x*c.x+n.col2.x*c.y;f=n.col1.y*c.x+n.col2.y*c.y;n=q.R;c=o.m_localPoint;b=q.position.x+n.col1.x*c.x+n.col2.x*c.y;B=q.position.y+n.col1.y*c.x+n.col2.y*c.y;this.m_normal.x=h;this.m_normal.y=f;for(r=0;r<o.m_pointCount;r++){n=p.R;c=o.m_points[r].m_localPoint;w=p.position.x+n.col1.x*c.x+n.col2.x*c.y;v=p.position.y+n.col1.y*c.x+n.col2.y*c.y;this.m_points[r].x=w+0.5*(t-(w-b)*h-(v-B)*f-s)*h;this.m_points[r].y=v+0.5*(t-(w-b)*h-(v-B)*f-s)*f}break;case Box2D.Collision.b2Manifold.e_faceB:n=p.R;c=o.m_localPlaneNormal;h=n.col1.x*c.x+n.col2.x*c.y;f=n.col1.y*c.x+n.col2.y*c.y;n=p.R;c=o.m_localPoint;b=p.position.x+n.col1.x*c.x+n.col2.x*c.y;B=p.position.y+n.col1.y*c.x+n.col2.y*c.y;this.m_normal.x=(-h);this.m_normal.y=(-f);for(r=0;r<o.m_pointCount;r++){n=q.R;c=o.m_points[r].m_localPoint;w=q.position.x+n.col1.x*c.x+n.col2.x*c.y;v=q.position.y+n.col1.y*c.x+n.col2.y*c.y;this.m_points[r].x=w+0.5*(s-(w-b)*h-(v-B)*f-t)*h;this.m_points[r].y=v+0.5*(s-(w-b)*h-(v-B)*f-t)*f}break}};Box2D.Collision.Shapes.b2Shape=function(){this.m_radius=Box2D.Common.b2Settings.b2_linearSlop};Box2D.Collision.Shapes.b2Shape.prototype.GetTypeName=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.Copy=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.Set=function(a){this.m_radius=a.m_radius};Box2D.Collision.Shapes.b2Shape.prototype.Destroy=function(){};Box2D.Collision.Shapes.b2Shape.prototype.TestPoint=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.RayCast=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.ComputeAABB=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.ComputeMass=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.ComputeSubmergedArea=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.prototype.SetDistanceProxy=Box2D.abstractMethod;Box2D.Collision.Shapes.b2Shape.TestOverlap=function(b,g,a,f){var e=Box2D.Collision.b2DistanceInput.Get();e.proxyA=Box2D.Collision.b2DistanceProxy.Get();e.proxyA.Set(b);e.proxyB=Box2D.Collision.b2DistanceProxy.Get();e.proxyB.Set(a);e.transformA=g;e.transformB=f;e.useRadii=true;var d=Box2D.Collision.b2SimplexCache.Get();d.count=0;var c=Box2D.Collision.b2DistanceOutput.Get();Box2D.Collision.b2Distance.Distance(c,d,e);Box2D.Collision.b2SimplexCache.Free(d);Box2D.Collision.b2DistanceProxy.Free(e.proxyA);Box2D.Collision.b2DistanceProxy.Free(e.proxyB);Box2D.Collision.b2DistanceInput.Free(e);Box2D.Collision.b2DistanceOutput.Free(c);return c.distance<10*Number.MIN_VALUE};Box2D.Collision.Shapes.b2Shape.prototype.GetRadius=function(){return this.m_radius};Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide=-1;Box2D.Collision.Shapes.b2Shape.e_missCollide=0;Box2D.Collision.Shapes.b2Shape.e_hitCollide=1;Box2D.Collision.Shapes.b2CircleShape=function(a){Box2D.Collision.Shapes.b2Shape.call(this);this.m_radius=a;this.m_radiusSquared=a*a;this.m_p=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_vertices=Box2D.Array.Get();this.m_vertices[0]=this.m_p};Box2D.inherits(Box2D.Collision.Shapes.b2CircleShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2CircleShape._freeCache=[];Box2D.Collision.Shapes.b2CircleShape.Get=function(a){var b=this._freeCache;var c;if(b.length>0){c=b.pop();c.SetRadius(a)}else{c=new this(a)}return c};Box2D.Collision.Shapes.b2CircleShape.Free=function(a){this._freeCache.push(a)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2CircleShape.NAME};Box2D.Collision.Shapes.b2CircleShape.prototype.Copy=function(){var a=Box2D.Collision.Shapes.b2CircleShape.Get(this.m_radius);a.Set(this);return a};Box2D.Collision.Shapes.b2CircleShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,a);if(a instanceof Box2D.Collision.Shapes.b2CircleShape){this.m_p.SetV(a.m_p)}};Box2D.Collision.Shapes.b2CircleShape.prototype.Destroy=function(){Box2D.Collision.Shapes.b2CircleShape.Free(this)};Box2D.Collision.Shapes.b2CircleShape.prototype.TestPoint=function(c,d){var b=d.x-(c.position.x+(c.R.col1.x*this.m_p.x+c.R.col2.x*this.m_p.y));var a=d.y-(c.position.y+(c.R.col1.y*this.m_p.x+c.R.col2.y*this.m_p.y));return(b*b+a*a)<=this.m_radiusSquared};Box2D.Collision.Shapes.b2CircleShape.prototype.RayCast=function(g,q,f){var n=f.R;var l=f.position.x+(n.col1.x*this.m_p.x+n.col2.x*this.m_p.y);var k=f.position.y+(n.col1.y*this.m_p.x+n.col2.y*this.m_p.y);var e=q.p1.x-l;var d=q.p1.y-k;var o=(e*e+d*d)-this.m_radiusSquared;var j=q.p2.x-q.p1.x;var i=q.p2.y-q.p1.y;var m=(e*j+d*i);var h=(j*j+i*i);var r=m*m-h*o;if(r<0||h<Number.MIN_VALUE){return false}var p=(-(m+Math.sqrt(r)));if(0<=p&&p<=q.maxFraction*h){p/=h;g.fraction=p;g.normal.x=e+p*j;g.normal.y=d+p*i;g.normal.Normalize();return true}return false};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeAABB=function(f,d){var j=d.R;var n=d.position;var i=j.col1;var h=j.col2;var a=this.m_p;var l=a.x;var k=a.y;var c=n.x+(i.x*l+h.x*k);var b=n.y+(i.y*l+h.y*k);var m=f.lowerBound;var e=f.upperBound;var g=this.m_radius;m.x=c-g;m.y=b-g;e.x=c+g;e.y=b+g};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeMass=function(b,a){var c=a*Math.PI*this.m_radiusSquared;b.SetV(c,this.m_p,c*(0.5*this.m_radiusSquared+(this.m_p.x*this.m_p.x+this.m_p.y*this.m_p.y)))};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeSubmergedArea=function(h,g,j,i){var a=Box2D.Common.Math.b2Math.MulX(j,this.m_p);var f=(-(Box2D.Common.Math.b2Math.Dot(h,a)-g));if(f<(-this.m_radius)+Number.MIN_VALUE){Box2D.Common.Math.b2Vec2.Free(a);return 0}if(f>this.m_radius){Box2D.Common.Math.b2Vec2.Free(a);i.SetV(a);return Math.PI*this.m_radiusSquared}var e=f*f;var b=this.m_radiusSquared*(Math.asin(f/this.m_radius)+Math.PI/2)+f*Math.sqrt(this.m_radiusSquared-e);var d=(-2/3*Math.pow(this.m_radiusSquared-e,1.5)/b);i.x=a.x+h.x*d;i.y=a.y+h.y*d;Box2D.Common.Math.b2Vec2.Free(a);return b};Box2D.Collision.Shapes.b2CircleShape.prototype.SetDistanceProxy=function(a){a.SetValues(1,this.m_radius,this.m_vertices)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetLocalPosition=function(){return this.m_p};Box2D.Collision.Shapes.b2CircleShape.prototype.SetLocalPosition=function(a){this.m_p.SetV(a)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetRadius=function(){return this.m_radius};Box2D.Collision.Shapes.b2CircleShape.prototype.SetRadius=function(a){this.m_radius=a;this.m_radiusSquared=a*a};Box2D.Collision.Shapes.b2CircleShape.NAME="b2CircleShape";Box2D.Collision.Shapes.b2EdgeChainDef=function(){this.vertexCount=0;this.isALoop=true;this.vertices=Box2D.Array.Get()};Box2D.Collision.Shapes.b2EdgeShape=function(b,a){Box2D.Collision.Shapes.b2Shape.call(this);this.m_prevEdge=null;this.m_nextEdge=null;this.m_v1=b;this.m_v2=a;this.m_direction=Box2D.Common.Math.b2Vec2.Get(this.m_v2.x-this.m_v1.x,this.m_v2.y-this.m_v1.y);this.m_length=this.m_direction.Normalize();this.m_normal=Box2D.Common.Math.b2Vec2.Get(this.m_direction.y,-this.m_direction.x);this.m_coreV1=Box2D.Common.Math.b2Vec2.Get((-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.x-this.m_direction.x))+this.m_v1.x,(-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.y-this.m_direction.y))+this.m_v1.y);this.m_coreV2=Box2D.Common.Math.b2Vec2.Get((-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.x+this.m_direction.x))+this.m_v2.x,(-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.y+this.m_direction.y))+this.m_v2.y);this.m_cornerDir1=this.m_normal;this.m_cornerDir2=Box2D.Common.Math.b2Vec2.Get(-this.m_normal.x,-this.m_normal.y);this.m_cornerConvex1=false;this.m_cornerConvex2=false};Box2D.inherits(Box2D.Collision.Shapes.b2EdgeShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2EdgeShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2EdgeShape.NAME};Box2D.Collision.Shapes.b2EdgeShape.prototype.TestPoint=function(a,b){return false};Box2D.Collision.Shapes.b2EdgeShape.prototype.RayCast=function(e,n,d){var h=n.p2.x-n.p1.x;var f=n.p2.y-n.p1.y;var j=d.R;var m=d.position.x+(j.col1.x*this.m_v1.x+j.col2.x*this.m_v1.y);var k=d.position.y+(j.col1.y*this.m_v1.x+j.col2.y*this.m_v1.y);var r=d.position.y+(j.col1.y*this.m_v2.x+j.col2.y*this.m_v2.y)-k;var p=(-(d.position.x+(j.col1.x*this.m_v2.x+j.col2.x*this.m_v2.y)-m));var i=100*Number.MIN_VALUE;var g=(-(h*r+f*p));if(g>i){var c=n.p1.x-m;var b=n.p1.y-k;var l=(c*r+b*p);if(0<=l&&l<=n.maxFraction*g){var o=(-h*b)+f*c;if((-i*g)<=o&&o<=g*(1+i)){l/=g;e.fraction=l;var q=Math.sqrt(r*r+p*p);e.normal.x=r/q;e.normal.y=p/q;return true}}}return false};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeAABB=function(c,d){var e=d.R;var g=d.position.x+(e.col1.x*this.m_v1.x+e.col2.x*this.m_v1.y);var f=d.position.y+(e.col1.y*this.m_v1.x+e.col2.y*this.m_v1.y);var b=d.position.x+(e.col1.x*this.m_v2.x+e.col2.x*this.m_v2.y);var a=d.position.y+(e.col1.y*this.m_v2.x+e.col2.y*this.m_v2.y);if(g<b){c.lowerBound.x=g;c.upperBound.x=b}else{c.lowerBound.x=b;c.upperBound.x=g}if(f<a){c.lowerBound.y=f;c.upperBound.y=a}else{c.lowerBound.y=a;c.upperBound.y=f}};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeMass=function(b,a){b.mass=0;b.center.SetV(this.m_v1);b.I=0};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeSubmergedArea=function(e,d,i,f){if(d===undefined){d=0}var j=Box2D.Common.Math.b2Vec2.Get(e.x*d,e.y*d);var h=Box2D.Common.Math.b2Math.MulX(i,this.m_v1);var g=Box2D.Common.Math.b2Math.MulX(i,this.m_v2);var b=Box2D.Common.Math.b2Math.Dot(e,h)-d;var a=Box2D.Common.Math.b2Math.Dot(e,g)-d;if(b>0){if(a>0){return 0}else{h.x=(-a/(b-a)*h.x)+b/(b-a)*g.x;h.y=(-a/(b-a)*h.y)+b/(b-a)*g.y}}else{if(a>0){g.x=(-a/(b-a)*h.x)+b/(b-a)*g.x;g.y=(-a/(b-a)*h.y)+b/(b-a)*g.y}}f.x=(j.x+h.x+g.x)/3;f.y=(j.y+h.y+g.y)/3;return 0.5*((h.x-j.x)*(g.y-j.y)-(h.y-j.y)*(g.x-j.x))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetLength=function(){return this.m_length};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex1=function(){return this.m_v1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex2=function(){return this.m_v2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex1=function(){return this.m_coreV1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex2=function(){return this.m_coreV2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNormalVector=function(){return this.m_normal};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetDirectionVector=function(){return this.m_direction};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner1Vector=function(){return this.m_cornerDir1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner2Vector=function(){return this.m_cornerDir2};Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner1IsConvex=function(){return this.m_cornerConvex1};Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner2IsConvex=function(){return this.m_cornerConvex2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetFirstVertex=function(b){var a=b.R;return Box2D.Common.Math.b2Vec2.Get(b.position.x+(a.col1.x*this.m_coreV1.x+a.col2.x*this.m_coreV1.y),b.position.y+(a.col1.y*this.m_coreV1.x+a.col2.y*this.m_coreV1.y))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNextEdge=function(){return this.m_nextEdge};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetPrevEdge=function(){return this.m_prevEdge};Box2D.Collision.Shapes.b2EdgeShape.prototype.Support=function(f,d,b){var e=f.R;var h=f.position.x+(e.col1.x*this.m_coreV1.x+e.col2.x*this.m_coreV1.y);var g=f.position.y+(e.col1.y*this.m_coreV1.x+e.col2.y*this.m_coreV1.y);var c=f.position.x+(e.col1.x*this.m_coreV2.x+e.col2.x*this.m_coreV2.y);var a=f.position.y+(e.col1.y*this.m_coreV2.x+e.col2.y*this.m_coreV2.y);if((h*d+g*b)>(c*d+a*b)){return Box2D.Common.Math.b2Vec2.Get(h,g)}else{return Box2D.Common.Math.b2Vec2.Get(c,a)}};Box2D.Collision.Shapes.b2EdgeShape.prototype.SetPrevEdge=function(d,a,c,b){this.m_prevEdge=d;this.m_coreV1=a;this.m_cornerDir1=c;this.m_cornerConvex1=b};Box2D.Collision.Shapes.b2EdgeShape.prototype.SetNextEdge=function(d,a,c,b){this.m_nextEdge=d;this.m_coreV2=a;this.m_cornerDir2=c;this.m_cornerConvex2=b};Box2D.Collision.Shapes.b2EdgeShape.NAME="b2EdgeShape";Box2D.Collision.Shapes.b2MassData=function(){this.mass=0;this.center=Box2D.Common.Math.b2Vec2.Get(0,0);this.I=0};Box2D.Collision.Shapes.b2MassData._freeCache=[];Box2D.Collision.Shapes.b2MassData.Get=function(){if(Box2D.Collision.Shapes.b2MassData._freeCache.length>0){var a=Box2D.Collision.Shapes.b2MassData._freeCache.pop();a.mass=0;a.center.SetZero();a.I=0;return a}return new Box2D.Collision.Shapes.b2MassData()};Box2D.Collision.Shapes.b2MassData.Free=function(a){if(a!=null){Box2D.Collision.Shapes.b2MassData._freeCache.push(a)}};Box2D.Collision.Shapes.b2MassData.prototype.SetV=function(c,a,b){this.mass=c;this.center.SetV(a);this.I=b};Box2D.Collision.Shapes.b2MassData.prototype.Set=function(c,a,d,b){this.mass=c;this.center.Set(a,d);this.I=b};Box2D.Collision.Shapes.b2PolygonShape=function(){Box2D.Collision.Shapes.b2Shape.call(this);this.m_centroid=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_vertices=Box2D.Array.Get();this.m_normals=Box2D.Array.Get()};Box2D.inherits(Box2D.Collision.Shapes.b2PolygonShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2PolygonShape._freeCache=[];Box2D.Collision.Shapes.b2PolygonShape.Get=function(){var a=this._freeCache;var b;if(a.length>0){b=a.pop()}else{b=new this}return b};Box2D.Collision.Shapes.b2PolygonShape.Free=function(a){this._freeCache.push(a)};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2PolygonShape.NAME};Box2D.Collision.Shapes.b2PolygonShape.prototype.Copy=function(){var a=Box2D.Collision.Shapes.b2PolygonShape.Get();a.Set(this);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,a);if(a instanceof Box2D.Collision.Shapes.b2PolygonShape){this.m_centroid.SetV(a.m_centroid);this.m_vertexCount=a.m_vertexCount;this.Reserve(this.m_vertexCount);for(var b=0;b<this.m_vertexCount;b++){this.m_vertices[b].SetV(a.m_vertices[b]);this.m_normals[b].SetV(a.m_normals[b])}}};Box2D.Collision.Shapes.b2PolygonShape.prototype.Destroy=function(){Box2D.Collision.Shapes.b2PolygonShape.Free(this)};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsArray=function(a){this.SetAsVector(a)};Box2D.Collision.Shapes.b2PolygonShape.AsArray=function(b){var a=new Box2D.Collision.Shapes.b2PolygonShape();a.SetAsArray(b);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsVector=function(b){var e=b.length;Box2D.Common.b2Settings.b2Assert(2<=e);this.m_vertexCount=e;this.Reserve(e);var c=0;for(c=0;c<this.m_vertexCount;c++){this.m_vertices[c].SetV(b[c])}for(c=0;c<this.m_vertexCount;++c){var g=c;var d=c+1<this.m_vertexCount?c+1:0;var f=Box2D.Common.Math.b2Math.SubtractVV(this.m_vertices[d],this.m_vertices[g]);Box2D.Common.b2Settings.b2Assert(f.LengthSquared()>Number.MIN_VALUE);var a=Box2D.Common.Math.b2Math.CrossVF(f,1);Box2D.Common.Math.b2Vec2.Free(f);this.m_normals[c].SetV(a);Box2D.Common.Math.b2Vec2.Free(a);this.m_normals[c].Normalize()}this.m_centroid=Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid(this.m_vertices,this.m_vertexCount)};Box2D.Collision.Shapes.b2PolygonShape.AsVector=function(b){var a=new Box2D.Collision.Shapes.b2PolygonShape();a.SetAsVector(b);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsBox=function(b,a){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set((-b),(-a));this.m_vertices[1].Set(b,(-a));this.m_vertices[2].Set(b,a);this.m_vertices[3].Set((-b),a);this.m_normals[0].Set(0,(-1));this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set((-1),0);this.m_centroid.SetZero()};Box2D.Collision.Shapes.b2PolygonShape.AsBox=function(c,b){var a=new Box2D.Collision.Shapes.b2PolygonShape();a.SetAsBox(c,b);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsOrientedBox=function(g,f,a,e){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set((-g),(-f));this.m_vertices[1].Set(g,(-f));this.m_vertices[2].Set(g,f);this.m_vertices[3].Set((-g),f);this.m_normals[0].Set(0,(-1));this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set((-1),0);this.m_centroid=a;var c=Box2D.Common.Math.b2Mat22.Get();c.Set(e);var d=new Box2D.Common.Math.b2Transform(a,c);for(var b=0;b<this.m_vertexCount;++b){this.m_vertices[b]=Box2D.Common.Math.b2Math.MulX(d,this.m_vertices[b]);this.m_normals[b]=Box2D.Common.Math.b2Math.MulMV(d.R,this.m_normals[b])}};Box2D.Collision.Shapes.b2PolygonShape.AsOrientedBox=function(e,d,b,c){var a=new Box2D.Collision.Shapes.b2PolygonShape();a.SetAsOrientedBox(e,d,b,c);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsEdge=function(e,b){this.m_vertexCount=2;this.Reserve(2);this.m_vertices[0].SetV(e);this.m_vertices[1].SetV(b);this.m_centroid.x=0.5*(e.x+b.x);this.m_centroid.y=0.5*(e.y+b.y);var a=Box2D.Common.Math.b2Math.SubtractVV(b,e);var c=Box2D.Common.Math.b2Math.CrossVF(a,1);Box2D.Common.Math.b2Vec2.Free(a);this.m_normals[0]=c;this.m_normals[0].Normalize();this.m_normals[1].x=(-this.m_normals[0].x);this.m_normals[1].y=(-this.m_normals[0].y)};Box2D.Collision.Shapes.b2PolygonShape.AsEdge=function(c,b){var a=new Box2D.Collision.Shapes.b2PolygonShape();a.SetAsEdge(c,b);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.TestPoint=function(h,b){var k;var f=h.R;var j=b.x-h.position.x;var g=b.y-h.position.y;var d=(j*f.col1.x+g*f.col1.y);var c=(j*f.col2.x+g*f.col2.y);for(var e=0;e<this.m_vertexCount;++e){k=this.m_vertices[e];j=d-k.x;g=c-k.y;k=this.m_normals[e];var a=(k.x*j+k.y*g);if(a>0){return false}}return true};Box2D.Collision.Shapes.b2PolygonShape.prototype.RayCast=function(h,k,l){var s=0;var r=k.maxFraction;var n=0;var m=0;var j;var d;n=k.p1.x-l.position.x;m=k.p1.y-l.position.y;j=l.R;var p=(n*j.col1.x+m*j.col1.y);var o=(n*j.col2.x+m*j.col2.y);n=k.p2.x-l.position.x;m=k.p2.y-l.position.y;j=l.R;var c=(n*j.col1.x+m*j.col1.y);var b=(n*j.col2.x+m*j.col2.y);var f=c-p;var e=b-o;var g=-1;for(var q=0;q<this.m_vertexCount;++q){d=this.m_vertices[q];n=d.x-p;m=d.y-o;d=this.m_normals[q];var t=(d.x*n+d.y*m);var a=(d.x*f+d.y*e);if(a==0){if(t<0){return false}}else{if(a<0&&t<s*a){s=t/a;g=q}else{if(a>0&&t<r*a){r=t/a}}}if(r<s-Number.MIN_VALUE){return false}}if(g>=0){h.fraction=s;j=l.R;d=this.m_normals[g];h.normal.x=(j.col1.x*d.x+j.col2.x*d.y);h.normal.y=(j.col1.y*d.x+j.col2.y*d.y);return true}return false};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeAABB=function(f,h){var g=h.R;var l=this.m_vertices[0];var k=h.position.x+(g.col1.x*l.x+g.col2.x*l.y);var j=h.position.y+(g.col1.y*l.x+g.col2.y*l.y);var d=k;var c=j;for(var e=1;e<this.m_vertexCount;++e){l=this.m_vertices[e];var b=h.position.x+(g.col1.x*l.x+g.col2.x*l.y);var a=h.position.y+(g.col1.y*l.x+g.col2.y*l.y);k=k<b?k:b;j=j<a?j:a;d=d>b?d:b;c=c>a?c:a}f.lowerBound.x=k-this.m_radius;f.lowerBound.y=j-this.m_radius;f.upperBound.x=d+this.m_radius;f.upperBound.y=c+this.m_radius};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeMass=function(m,j){if(this.m_vertexCount==2){m.center.x=0.5*(this.m_vertices[0].x+this.m_vertices[1].x);m.center.y=0.5*(this.m_vertices[0].y+this.m_vertices[1].y);m.mass=0;m.I=0;return}var k=0;var h=0;var y=0;var l=0;var w=0;var v=0;var g=1/3;for(var x=0;x<this.m_vertexCount;++x){var d=this.m_vertices[x];var c=x+1<this.m_vertexCount?this.m_vertices[x+1]:this.m_vertices[0];var u=d.x-w;var s=d.y-v;var b=c.x-w;var A=c.y-v;var p=u*A-s*b;var f=0.5*p;y+=f;k+=f*g*(w+d.x+c.x);h+=f*g*(v+d.y+c.y);var q=w;var o=v;var t=u;var a=s;var r=b;var z=A;var e=g*(0.25*(t*t+r*t+r*r)+(q*t+q*r))+0.5*q*q;var n=g*(0.25*(a*a+z*a+z*z)+(o*a+o*z))+0.5*o*o;l+=p*(e+n)}k*=1/y;h*=1/y;m.Set(j*y,k,h,j*l)};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeSubmergedArea=function(B,m,t,x){var q=Box2D.Common.Math.b2Math.MulTMV(t.R,B);var e=m-Box2D.Common.Math.b2Math.Dot(B,t.position);var o=Box2D.Array.Get();var n=0;var f=-1;var b=-1;var l=false;var v=0;for(v=0;v<this.m_vertexCount;++v){o[v]=Box2D.Common.Math.b2Math.Dot(q,this.m_vertices[v])-e;var h=o[v]<(-Number.MIN_VALUE);if(v>0){if(h){if(!l){f=v-1;n++}}else{if(l){b=v-1;n++}}}l=h}Box2D.Common.Math.b2Vec2.Free(q);switch(n){case 0:if(l){var A=Box2D.Collision.Shapes.b2MassData.Get();this.ComputeMass(A,1);var z=Box2D.Common.Math.b2Math.MulX(t,A.center);x.SetV(z);Box2D.Common.Math.b2Vec2.Free(z);var r=A.mass;Box2D.Collision.Shapes.b2MassData.Free(A);return r}else{return 0}break;case 1:if(f==(-1)){f=this.m_vertexCount-1}else{b=this.m_vertexCount-1}break}var p=((f+1)%this.m_vertexCount);var s=((b+1)%this.m_vertexCount);var u=(0-o[f])/(o[p]-o[f]);var C=(0-o[b])/(o[s]-o[b]);var j=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[f].x*(1-u)+this.m_vertices[p].x*u,this.m_vertices[f].y*(1-u)+this.m_vertices[p].y*u);var g=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[b].x*(1-C)+this.m_vertices[s].x*C,this.m_vertices[b].y*(1-C)+this.m_vertices[s].y*C);var w=0;var y=Box2D.Common.Math.b2Vec2.Get(0,0);var d=this.m_vertices[p];var a;v=p;while(v!=s){v=(v+1)%this.m_vertexCount;if(v==s){a=g}else{a=this.m_vertices[v]}var k=0.5*((d.x-j.x)*(a.y-j.y)-(d.y-j.y)*(a.x-j.x));w+=k;y.x+=k*(j.x+d.x+a.x)/3;y.y+=k*(j.y+d.y+a.y)/3;d=a}Box2D.Common.Math.b2Vec2.Free(j);Box2D.Common.Math.b2Vec2.Free(g);y.Multiply(1/w);var z=Box2D.Common.Math.b2Math.MulX(t,y);Box2D.Common.Math.b2Vec2.Free(y);x.SetV(z);Box2D.Common.Math.b2Vec2.Free(z);return w};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetDistanceProxy=function(a){a.SetValues(this.m_vertexCount,this.m_radius,this.m_vertices)};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertexCount=function(){return this.m_vertexCount};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertices=function(){return this.m_vertices};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertex=function(a){return this.m_vertices[a]};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetNormals=function(){return this.m_normals};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetNormal=function(a){return this.m_normals[a]};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetCentroid=function(){return this.m_centroid};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupport=function(f){var b=0;var e=this.m_vertices[0].x*f.x+this.m_vertices[0].y*f.y;for(var a=1;a<this.m_vertexCount;++a){var c=this.m_vertices[a].x*f.x+this.m_vertices[a].y*f.y;if(c>e){b=a;e=c}}return b};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupportVertex=function(f){var b=0;var e=this.m_vertices[0].x*f.x+this.m_vertices[0].y*f.y;for(var a=1;a<this.m_vertexCount;++a){var c=this.m_vertices[a].x*f.x+this.m_vertices[a].y*f.y;if(c>e){b=a;e=c}}return this.m_vertices[b]};Box2D.Collision.Shapes.b2PolygonShape.prototype.Reserve=function(b){for(var a=0;a<this.m_vertices.length;a++){Box2D.Common.Math.b2Vec2.Free(this.m_vertices[a]);Box2D.Common.Math.b2Vec2.Free(this.m_normals[a])}this.m_vertices.length=0;this.m_normals.length=0;for(var a=0;a<b;a++){this.m_vertices[a]=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_normals[a]=Box2D.Common.Math.b2Vec2.Get(0,0)}};Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid=function(r,k){var m=Box2D.Common.Math.b2Vec2.Get(0,0);var e=0;var j=0;var h=0;var f=1/3;for(var g=0;g<k;++g){var q=r[g];var o=g+1<k?r[g+1]:r[0];var d=q.x-j;var b=q.y-h;var n=o.x-j;var l=o.y-h;var a=(d*l-b*n);var p=0.5*a;e+=p;m.x+=p*f*(j+q.x+o.x);m.y+=p*f*(h+q.y+o.y)}m.x*=1/e;m.y*=1/e;return m};Box2D.Collision.Shapes.b2PolygonShape.s_mat=Box2D.Common.Math.b2Mat22.Get();Box2D.Collision.Shapes.b2PolygonShape.NAME="b2PolygonShape";Box2D.Dynamics.Contacts.b2Contact=function(a,d){this.ID=Box2D.Dynamics.Contacts.b2Contact.NEXT_ID++;this.m_manifold=new Box2D.Collision.b2Manifold();this.m_oldManifold=new Box2D.Collision.b2Manifold();this.touching=false;var c=a.GetBody();var b=d.GetBody();this.continuous=(c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)||c.IsBullet()||(b.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)||b.IsBullet();this.sensor=a.IsSensor()||d.IsSensor();this.filtering=false;this.m_fixtureA=a;this.m_fixtureB=d;this.enabled=true;this.bodyAList=c.GetContactList();this.bodyBList=b.GetContactList();this.worldList=b.GetWorld().GetContactList();this.AddToLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.Reset=function(a,d){this.m_manifold.Reset();this.m_oldManifold.Reset();this.touching=false;var c=a.GetBody();var b=d.GetBody();this.continuous=(c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)||c.IsBullet()||(b.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)||b.IsBullet();this.sensor=a.IsSensor()||d.IsSensor();this.filtering=false;this.m_fixtureA=a;this.m_fixtureB=d;this.enabled=true;this.bodyAList=c.GetContactList();this.bodyBList=b.GetContactList();this.worldList=b.GetWorld().GetContactList();this.AddToLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.AddToLists=function(){this.bodyAList.AddContact(this);this.bodyBList.AddContact(this);this.worldList.AddContact(this);this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.UpdateLists=function(){var a=false;var b=false;if(!this.IsSensor()&&this.IsEnabled()){if(this.IsTouching()){a=true}if(this.IsContinuous()){b=true}}this.bodyAList.UpdateContact(this,a,b);this.bodyBList.UpdateContact(this,a,b);this.worldList.UpdateContact(this,a,b)};Box2D.Dynamics.Contacts.b2Contact.prototype.RemoveFromLists=function(){this.bodyAList.RemoveContact(this);this.bodyBList.RemoveContact(this);this.worldList.RemoveContact(this)};Box2D.Dynamics.Contacts.b2Contact.prototype.GetManifold=function(){return this.m_manifold};Box2D.Dynamics.Contacts.b2Contact.prototype.GetWorldManifold=function(d){var e=this.m_fixtureA.GetBody();var c=this.m_fixtureB.GetBody();var b=this.m_fixtureA.GetShape();var a=this.m_fixtureB.GetShape();d.Initialize(this.m_manifold,e.GetTransform(),b.m_radius,c.GetTransform(),a.m_radius)};Box2D.Dynamics.Contacts.b2Contact.prototype.IsTouching=function(){return this.touching};Box2D.Dynamics.Contacts.b2Contact.prototype.IsContinuous=function(){return this.continuous};Box2D.Dynamics.Contacts.b2Contact.prototype.SetSensor=function(a){this.sensor=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsSensor=function(){return this.sensor};Box2D.Dynamics.Contacts.b2Contact.prototype.SetEnabled=function(a){this.enabled=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsEnabled=function(){return this.enabled};Box2D.Dynamics.Contacts.b2Contact.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureA=function(){return this.m_fixtureA};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureB=function(){return this.m_fixtureB};Box2D.Dynamics.Contacts.b2Contact.prototype.GetOther=function(a){var b=this.m_fixtureA.GetBody();if(b!=a){return b}else{return this.m_fixtureB.GetBody()}};Box2D.Dynamics.Contacts.b2Contact.prototype.FlagForFiltering=function(){this.filtering=true};Box2D.Dynamics.Contacts.b2Contact.prototype.ClearFiltering=function(){this.filtering=false};Box2D.Dynamics.Contacts.b2Contact.prototype.IsFiltering=function(){return this.filtering};Box2D.Dynamics.Contacts.b2Contact.prototype.Update=function(b){var a=this.m_oldManifold;this.m_oldManifold=this.m_manifold;this.m_manifold=a;this.enabled=true;var k=false;var m=this.IsTouching();var d=this.m_fixtureA.m_body;var c=this.m_fixtureB.m_body;var l=this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);if(this.sensor){if(l){k=Box2D.Collision.Shapes.b2Shape.TestOverlap(this.m_fixtureA.GetShape(),d.GetTransform(),this.m_fixtureB.GetShape(),c.GetTransform())}this.m_manifold.m_pointCount=0}else{if(d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet()||c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||c.IsBullet()){this.continuous=true}else{this.continuous=false}if(l){this.Evaluate();k=this.m_manifold.m_pointCount>0;for(var f=0;f<this.m_manifold.m_pointCount;f++){var g=this.m_manifold.m_points[f];g.m_normalImpulse=0;g.m_tangentImpulse=0;for(var e=0;e<this.m_oldManifold.m_pointCount;e++){var h=this.m_oldManifold.m_points[e];if(h.m_id.GetKey()==g.m_id.GetKey()){g.m_normalImpulse=h.m_normalImpulse;g.m_tangentImpulse=h.m_tangentImpulse;break}}}}else{this.m_manifold.m_pointCount=0}if(k!=m){d.SetAwake(true);c.SetAwake(true)}}this.touching=k;if(k!=m){this.UpdateLists()}if(!m&&k){b.BeginContact(this)}if(m&&!k){b.EndContact(this)}if(!this.sensor){b.PreSolve(this,this.m_oldManifold)}};Box2D.Dynamics.Contacts.b2Contact.prototype.Evaluate=function(){};Box2D.Dynamics.Contacts.b2Contact.prototype.ComputeTOI=function(b,a){Box2D.Dynamics.Contacts.b2Contact.s_input.proxyA.Set(this.m_fixtureA.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.proxyB.Set(this.m_fixtureB.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.sweepA=b;Box2D.Dynamics.Contacts.b2Contact.s_input.sweepB=a;Box2D.Dynamics.Contacts.b2Contact.s_input.tolerance=Box2D.Common.b2Settings.b2_linearSlop;return Box2D.Collision.b2TimeOfImpact.TimeOfImpact(Box2D.Dynamics.Contacts.b2Contact.s_input)};Box2D.Dynamics.Contacts.b2Contact.s_input=new Box2D.Collision.b2TOIInput();Box2D.Dynamics.Contacts.b2Contact.NEXT_ID=0;Box2D.Dynamics.Contacts.b2CircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};Box2D.inherits(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2CircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2CircleContact.prototype.Evaluate=function(){var b=(this.m_fixtureA.GetShape());var a=(this.m_fixtureB.GetShape());Box2D.Collision.b2Collision.CollideCircles(this.m_manifold,b,this.m_fixtureA.GetBody().GetTransform(),a,this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2ContactConstraint=function(){this.localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.normalMass=Box2D.Common.Math.b2Mat22.Get();this.K=Box2D.Common.Math.b2Mat22.Get();this.points=Box2D.Array.Get();for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++){this.points[a]=new Box2D.Dynamics.Contacts.b2ContactConstraintPoint()}};Box2D.Dynamics.Contacts.b2ContactConstraintPoint=function(){this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.rA=Box2D.Common.Math.b2Vec2.Get(0,0);this.rB=Box2D.Common.Math.b2Vec2.Get(0,0);this.normalImpulse=0;this.tangentImpulse=0};Box2D.Dynamics.Contacts.b2ContactConstraintPoint.prototype.Reset=function(){this.localPoint.Set(0,0);this.rA.Set(0,0);this.rB.Set(0,0);this.normalImpulse=0;this.tangentImpulse=0};Box2D.Dynamics.Contacts.b2ContactList=function(){this.contactFirstNodes=Box2D.Array.Get();for(var a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++){this.contactFirstNodes[a]=null}this.contactLastNodes=Box2D.Array.Get();for(var a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++){this.contactLastNodes[a]=null}this.contactNodeLookup={};this.contactCount=0};Box2D.Dynamics.Contacts.b2ContactList.prototype.GetFirstNode=function(a){return this.contactFirstNodes[a]};Box2D.Dynamics.Contacts.b2ContactList.prototype.AddContact=function(a){var c=a.ID;if(this.contactNodeLookup[c]==null){this.contactNodeLookup[c]=Box2D.Array.Get();for(var b=0;b<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;b++){this.contactNodeLookup[c][b]=null}this.CreateNode(a,c,Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);this.contactCount++}};Box2D.Dynamics.Contacts.b2ContactList.prototype.UpdateContact=function(a,b,c){if(b){this.CreateNode(a,a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts)}else{this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts)}if(c){this.CreateNode(a,a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts)}else{this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts)}};Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveContact=function(a){var c=a.ID;if(this.contactNodeLookup[c]!=null){for(var b=0;b<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;b++){this.RemoveNode(c,b)}Box2D.Array.Free(this.contactNodeLookup[c]);delete this.contactNodeLookup[c];this.contactCount--}};Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveNode=function(f,d){var c=this.contactNodeLookup[f];if(c==null){return}var e=c[d];if(e==null){return}c[d]=null;var b=e.GetPreviousNode();var a=e.GetNextNode();if(b==null){this.contactFirstNodes[d]=a}else{b.SetNextNode(a)}if(a==null){this.contactLastNodes[d]=b}else{a.SetPreviousNode(b)}Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode(e)};Box2D.Dynamics.Contacts.b2ContactList.prototype.CreateNode=function(a,e,d){var c=this.contactNodeLookup[e];if(c[d]==null){c[d]=Box2D.Dynamics.Contacts.b2ContactListNode.GetNode(a);var b=this.contactLastNodes[d];if(b!=null){b.SetNextNode(c[d]);c[d].SetPreviousNode(b)}else{this.contactFirstNodes[d]=c[d]}this.contactLastNodes[d]=c[d]}};Box2D.Dynamics.Contacts.b2ContactList.prototype.GetContactCount=function(){return this.contactCount};Box2D.Dynamics.Contacts.b2ContactList.TYPES={nonSensorEnabledTouchingContacts:0,nonSensorEnabledContinuousContacts:1,allContacts:2};Box2D.Dynamics.Contacts.b2ContactListNode=function(a){this.contact=a;this.next=null;this.previous=null};Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes=[];Box2D.Dynamics.Contacts.b2ContactListNode.GetNode=function(a){if(Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.length>0){var b=Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.pop();b.next=null;b.previous=null;b.contact=a;return b}else{return new Box2D.Dynamics.Contacts.b2ContactListNode(a)}};Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode=function(a){Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.push(a)};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetContact=function(){return this.contact};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.Contacts.b2ContactRegister=function(){this.pool=null;this.poolCount=0};Box2D.Dynamics.Contacts.b2ContactSolver=function(){this.m_constraints=Box2D.Array.Get()};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.Initialize=function(T,C,D){this.m_constraintCount=D;while(this.m_constraints.length<this.m_constraintCount){this.m_constraints[this.m_constraints.length]=new Box2D.Dynamics.Contacts.b2ContactConstraint()}var Y=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold;for(var ah=0;ah<D;ah++){var x=C[ah];var R=x.m_fixtureA;var O=x.m_fixtureB;var g=R.m_shape;var e=O.m_shape;var A=g.m_radius;var y=e.m_radius;var al=R.GetBody();var aj=O.GetBody();var N=al.m_sweep.c;var P=aj.m_sweep.c;var M=x.GetManifold();var H=Box2D.Common.b2Settings.b2MixFriction(R.GetFriction(),O.GetFriction());var a=Box2D.Common.b2Settings.b2MixRestitution(R.GetRestitution(),O.GetRestitution());var n=al.m_linearVelocity.x;var m=al.m_linearVelocity.y;var af=aj.m_linearVelocity.x;var ae=aj.m_linearVelocity.y;var J=al.m_angularVelocity;var I=aj.m_angularVelocity;Y.Initialize(M,al.GetTransform(),A,aj.GetTransform(),y);var Z=Y.m_normal.x;var X=Y.m_normal.y;var U=this.m_constraints[ah];U.bodyA=al;U.bodyB=aj;U.manifold=M;U.normal.x=Z;U.normal.y=X;U.pointCount=M.m_pointCount;U.friction=H;U.restitution=a;U.localPlaneNormal.x=M.m_localPlaneNormal.x;U.localPlaneNormal.y=M.m_localPlaneNormal.y;U.localPoint.x=M.m_localPoint.x;U.localPoint.y=M.m_localPoint.y;U.radius=A+y;U.type=M.m_type;for(var ag=0;ag<U.pointCount;++ag){var K=M.m_points[ag];var c=U.points[ag];c.normalImpulse=K.m_normalImpulse;c.tangentImpulse=K.m_tangentImpulse;c.localPoint.SetV(K.m_localPoint);var ai=Y.m_points[ag];var W=c.rA.x=ai.x-N.x;var V=c.rA.y=ai.y-N.y;var B=c.rB.x=ai.x-P.x;var z=c.rB.y=ai.y-P.y;var s=W*X-V*Z;var p=B*X-z*Z;s*=s;p*=p;var L=al.m_invMass+aj.m_invMass+al.m_invI*s+aj.m_invI*p;c.normalMass=1/L;var r=al.m_mass*al.m_invMass+aj.m_mass*aj.m_invMass;r+=al.m_mass*al.m_invI*s+aj.m_mass*aj.m_invI*p;c.equalizedMass=1/r;var ac=X;var ab=(-Z);var w=W*ab-V*ac;var v=B*ab-z*ac;w*=w;v*=v;var ak=al.m_invMass+aj.m_invMass+al.m_invI*w+aj.m_invI*v;c.tangentMass=1/ak;c.velocityBias=0;var q=af+((-I*z))-n-((-J*V));var o=ae+(I*B)-m-(J*W);var ad=U.normal.x*q+U.normal.y*o;if(ad<(-Box2D.Common.b2Settings.b2_velocityThreshold)){c.velocityBias+=(-U.restitution*ad)}}if(U.pointCount==2){var l=U.points[0];var j=U.points[1];var S=al.m_invMass;var u=al.m_invI;var Q=aj.m_invMass;var t=aj.m_invI;var F=l.rA.x*X-l.rA.y*Z;var E=l.rB.x*X-l.rB.y*Z;var d=j.rA.x*X-j.rA.y*Z;var b=j.rB.x*X-j.rB.y*Z;var h=S+Q+u*F*F+t*E*E;var aa=S+Q+u*d*d+t*b*b;var f=S+Q+u*F*d+t*E*b;var G=100;if(h*h<G*(h*aa-f*f)){U.K.col1.Set(h,f);U.K.col2.Set(f,aa);U.K.GetInverse(U.normalMass)}else{U.pointCount=1}}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.InitVelocityConstraints=function(m){for(var s=0;s<this.m_constraintCount;++s){var u=this.m_constraints[s];var d=u.bodyA;var b=u.bodyB;var h=d.m_invMass;var w=d.m_invI;var f=b.m_invMass;var v=b.m_invI;var g=u.normal.x;var e=u.normal.y;var l=e;var k=(-g);var q=0;var r=0;var t=0;if(m.warmStarting){t=u.pointCount;for(r=0;r<t;++r){var a=u.points[r];a.normalImpulse*=m.dtRatio;a.tangentImpulse*=m.dtRatio;var o=a.normalImpulse*g+a.tangentImpulse*l;var n=a.normalImpulse*e+a.tangentImpulse*k;d.m_angularVelocity-=w*(a.rA.x*n-a.rA.y*o);d.m_linearVelocity.x-=h*o;d.m_linearVelocity.y-=h*n;b.m_angularVelocity+=v*(a.rB.x*n-a.rB.y*o);b.m_linearVelocity.x+=f*o;b.m_linearVelocity.y+=f*n}}else{t=u.pointCount;for(r=0;r<t;++r){var p=u.points[r];p.normalImpulse=0;p.tangentImpulse=0}}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;a++){this.SolveVelocityConstraints_Constraint(this.m_constraints[a])}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_Constraint=function(z){var k=z.normal.x;var g=z.normal.y;for(var v=0;v<z.pointCount;v++){Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint(z,z.points[v])}if(z.pointCount==1){var d=z.points[0];var u=z.bodyB.m_linearVelocity.x-(z.bodyB.m_angularVelocity*d.rB.y)-z.bodyA.m_linearVelocity.x+(z.bodyA.m_angularVelocity*d.rA.y);var t=z.bodyB.m_linearVelocity.y+(z.bodyB.m_angularVelocity*d.rB.x)-z.bodyA.m_linearVelocity.y-(z.bodyA.m_angularVelocity*d.rA.x);var x=u*k+t*g;var A=d.normalImpulse-(d.normalMass*(x-d.velocityBias));A=A>0?A:0;var C=A-d.normalImpulse;var o=C*k;var n=C*g;z.bodyA.m_linearVelocity.x-=z.bodyA.m_invMass*o;z.bodyA.m_linearVelocity.y-=z.bodyA.m_invMass*n;z.bodyA.m_angularVelocity-=z.bodyA.m_invI*(d.rA.x*n-d.rA.y*o);z.bodyB.m_linearVelocity.x+=z.bodyB.m_invMass*o;z.bodyB.m_linearVelocity.y+=z.bodyB.m_invMass*n;z.bodyB.m_angularVelocity+=z.bodyB.m_invI*(d.rB.x*n-d.rB.y*o);d.normalImpulse=A}else{var y=z.points[0];var w=z.points[1];var h=y.normalImpulse;var e=w.normalImpulse;var D=z.bodyB.m_linearVelocity.x-z.bodyB.m_angularVelocity*y.rB.y-z.bodyA.m_linearVelocity.x+z.bodyA.m_angularVelocity*y.rA.y;var B=z.bodyB.m_linearVelocity.y+z.bodyB.m_angularVelocity*y.rB.x-z.bodyA.m_linearVelocity.y-z.bodyA.m_angularVelocity*y.rA.x;var m=z.bodyB.m_linearVelocity.x-z.bodyB.m_angularVelocity*w.rB.y-z.bodyA.m_linearVelocity.x+z.bodyA.m_angularVelocity*w.rA.y;var l=z.bodyB.m_linearVelocity.y+z.bodyB.m_angularVelocity*w.rB.x-z.bodyA.m_linearVelocity.y-z.bodyA.m_angularVelocity*w.rA.x;var s=(D*k+B*g)-y.velocityBias;var r=(m*k+l*g)-w.velocityBias;s-=z.K.col1.x*h+z.K.col2.x*e;r-=z.K.col1.y*h+z.K.col2.y*e;for(;;){var q=(-(z.normalMass.col1.x*s+z.normalMass.col2.x*r));if(q>=0){var p=(-(z.normalMass.col1.y*s+z.normalMass.col2.y*r));if(p>=0){var i=q-h;var f=p-e;this.SolveVelocityConstraints_ConstraintPointUpdate(z,y,w,q-h,p-e);y.normalImpulse=q;w.normalImpulse=p;break}}var b=(-y.normalMass*s);if(b>=0){if((z.K.col1.y*b+r)>=0){var i=b-h;var f=-e;this.SolveVelocityConstraints_ConstraintPointUpdate(z,y,w,b-h,-e);y.normalImpulse=b;w.normalImpulse=0;break}}var a=(-w.normalMass*r);if(a>=0){if((z.K.col2.x*a+s)>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(z,y,w,-h,a-e);y.normalImpulse=0;w.normalImpulse=a;break}}if(s>=0&&r>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(z,y,w,-h,-e);y.normalImpulse=0;w.normalImpulse=0;break}break}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint=function(h,a){var m=h.normal.y;var j=-h.normal.x;var k=h.bodyB.m_linearVelocity.x-h.bodyB.m_angularVelocity*a.rB.y-h.bodyA.m_linearVelocity.x+h.bodyA.m_angularVelocity*a.rA.y;var i=h.bodyB.m_linearVelocity.y+h.bodyB.m_angularVelocity*a.rB.x-h.bodyA.m_linearVelocity.y-h.bodyA.m_angularVelocity*a.rA.x;var l=k*m+i*j;var e=h.friction*a.normalImpulse;var g=Box2D.Common.Math.b2Math.Clamp(a.tangentImpulse-a.tangentMass*l,-e,e);var f=g-a.tangentImpulse;var d=f*m;var b=f*j;h.bodyA.m_linearVelocity.x-=h.bodyA.m_invMass*d;h.bodyA.m_linearVelocity.y-=h.bodyA.m_invMass*b;h.bodyA.m_angularVelocity-=h.bodyA.m_invI*(a.rA.x*b-a.rA.y*d);h.bodyB.m_linearVelocity.x+=h.bodyB.m_invMass*d;h.bodyB.m_linearVelocity.y+=h.bodyB.m_invMass*b;h.bodyB.m_angularVelocity+=h.bodyB.m_invI*(a.rB.x*b-a.rB.y*d);a.tangentImpulse=g};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPointUpdate=function(j,g,e,f,d){var i=f*j.normal.x;var h=f*j.normal.y;var b=d*j.normal.x;var a=d*j.normal.y;j.bodyA.m_linearVelocity.x-=j.bodyA.m_invMass*(i+b);j.bodyA.m_linearVelocity.y-=j.bodyA.m_invMass*(h+a);j.bodyA.m_angularVelocity-=j.bodyA.m_invI*(g.rA.x*h-g.rA.y*i+e.rA.x*a-e.rA.y*b);j.bodyB.m_linearVelocity.x+=j.bodyB.m_invMass*(i+b);j.bodyB.m_linearVelocity.y+=j.bodyB.m_invMass*(h+a);j.bodyB.m_angularVelocity+=j.bodyB.m_invI*(g.rB.x*h-g.rB.y*i+e.rB.x*a-e.rB.y*b);g.normalImpulse=0;e.normalImpulse=0};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.FinalizeVelocityConstraints=function(){for(var e=0;e<this.m_constraintCount;++e){var g=this.m_constraints[e];var a=g.manifold;for(var b=0;b<g.pointCount;++b){var f=a.m_points[b];var d=g.points[b];f.m_normalImpulse=d.normalImpulse;f.m_tangentImpulse=d.tangentImpulse}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints=function(w){if(w===undefined){w=0}var m=0;var y=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm;for(var x=0;x<this.m_constraintCount;x++){var z=this.m_constraints[x];var e=z.bodyA;var d=z.bodyB;var g=e.m_mass*e.m_invMass;var B=e.m_mass*e.m_invI;var f=d.m_mass*d.m_invMass;var A=d.m_mass*d.m_invI;var a=e.m_sweep.c;var q=d.m_sweep.c;var E=false;y.Initialize(z);var D=y.m_normal;for(var v=0;v<z.pointCount;v++){var b=z.points[v];var u=y.m_points[v];var p=y.m_separations[v];var k=u.x-a.x;var h=u.y-a.y;var t=u.x-q.x;var s=u.y-q.y;m=m<p?m:p;var r=Box2D.Common.Math.b2Math.Clamp(w*(p+Box2D.Common.b2Settings.b2_linearSlop),(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0);var o=(-b.equalizedMass*r);var n=o*D.x;var l=o*D.y;a.x-=g*n;a.y-=g*l;e.SetCalculatedAngle(e.GetAngle()-B*(k*l-h*n));q.x+=f*n;q.y+=f*l;d.SetCalculatedAngle(d.GetAngle()+A*(t*l-s*n));E=true}if(E){e.SynchronizeTransform();d.SynchronizeTransform()}}return m>(-1.5*Box2D.Common.b2Settings.b2_linearSlop)};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints_NEW=function(u){if(u===undefined){u=0}var l=0;for(var v=0;v<this.m_constraintCount;v++){var w=this.m_constraints[v];var d=w.bodyA;var b=w.bodyB;var f=d.m_mass*d.m_invMass;var y=d.m_mass*d.m_invI;var e=b.m_mass*b.m_invMass;var x=b.m_mass*b.m_invI;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.Initialize(w);var z=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_normal;for(var t=0;t<w.pointCount;t++){var a=w.points[t];var s=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_points[t];var o=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_separations[t];var h=s.x-d.GetWorldCenter().x;var g=s.y-d.GetWorldCenter().y;var r=s.x-b.GetWorldCenter().x;var q=s.y-b.GetWorldCenter().y;if(o<l){l=o}var p=0;if(u!=0){Box2D.Common.Math.b2Math.Clamp(u*(o+Box2D.Common.b2Settings.b2_linearSlop),(-Box2D.Common.b2Settings.b2_maxLinearCorrection),0)}var n=(-a.equalizedMass*p);var m=n*z.x;var k=n*z.y;d.GetWorldCenter().x-=f*m;d.GetWorldCenter().y-=f*k;d.SetAngle(d.GetAngle()-y*(h*k-g*m));d.SynchronizeTransform();b.GetWorldCenter().x+=e*m;b.GetWorldCenter().y+=e*k;b.SetAngle(b.GetAngle()+x*(r*k-q*m));b.SynchronizeTransform()}}return l>(-1.5*Box2D.Common.b2Settings.b2_linearSlop)};Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold=new Box2D.Collision.b2WorldManifold();Box2D.Dynamics.Contacts.b2ContactSolver.s_psm=new Box2D.Dynamics.Contacts.b2PositionSolverManifold();Box2D.Dynamics.Contacts.b2ContactSolver.singleton=new Box2D.Dynamics.Contacts.b2ContactSolver();Box2D.Dynamics.Contacts.b2EdgeAndCircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};Box2D.inherits(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Evaluate=function(){var b=this.m_fixtureA.GetBody();var a=this.m_fixtureB.GetBody();this.b2CollideEdgeAndCircle(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().GetTransform(),this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.b2CollideEdgeAndCircle=function(a,d,c,e,b){};Box2D.Dynamics.Contacts.b2PolyAndCircleContact=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape() instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape() instanceof Box2D.Collision.Shapes.b2CircleShape);Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};Box2D.inherits(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Reset=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape() instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape() instanceof Box2D.Collision.Shapes.b2CircleShape);Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Evaluate=function(){var b=(this.m_fixtureA.GetShape());var a=(this.m_fixtureB.GetShape());Box2D.Collision.b2Collision.CollidePolygonAndCircle(this.m_manifold,b,this.m_fixtureA.GetBody().GetTransform(),a,this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape() instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape() instanceof Box2D.Collision.Shapes.b2EdgeShape);Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};Box2D.inherits(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Reset=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape() instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape() instanceof Box2D.Collision.Shapes.b2EdgeShape);Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Evaluate=function(){this.b2CollidePolyAndEdge(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().GetTransform(),this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.b2CollidePolyAndEdge=function(a,d,c,e,b){};Box2D.Dynamics.Contacts.b2PolygonContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};Box2D.inherits(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Evaluate=function(){var b=(this.m_fixtureA.GetShape());var a=(this.m_fixtureB.GetShape());Box2D.Collision.b2Collision.CollidePolygons(this.m_manifold,b,this.m_fixtureA.GetBody().GetTransform(),a,this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2ContactFactory=function(){this.m_registers={};this.m_freeContacts={};this.AddType(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Collision.Shapes.b2CircleShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2PolygonShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Collision.Shapes.b2EdgeShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2EdgeShape.NAME)};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.AddType=function(c,b,a){this.m_freeContacts[b]=this.m_freeContacts[b]||{};this.m_freeContacts[b][a]=this.m_freeContacts[b][a]||Box2D.Array.Get();this.m_registers[b]=this.m_registers[b]||{};this.m_registers[b][a]=new Box2D.Dynamics.Contacts.b2ContactRegister();this.m_registers[b][a].ctor=c;this.m_registers[b][a].primary=true;if(b!=a){this.m_registers[a]=this.m_registers[a]||{};this.m_registers[a][b]=new Box2D.Dynamics.Contacts.b2ContactRegister();this.m_registers[a][b].ctor=c;this.m_registers[a][b].primary=false}};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Create=function(a,h){var d=a.GetShape().GetTypeName();var b=h.GetShape().GetTypeName();var e=this.m_registers[d][b];var f=e.ctor;if(f!=null){if(e.primary){if(this.m_freeContacts[d][b].length>0){var g=this.m_freeContacts[d][b].pop();g.Reset(a,h);return g}return new f(a,h)}else{if(this.m_freeContacts[b][d].length>0){var g=this.m_freeContacts[b][d].pop();g.Reset(h,a);return g}return new f(h,a)}}else{return null}};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Destroy=function(a){var c=a.GetFixtureA().GetShape().GetTypeName();var b=a.GetFixtureB().GetShape().GetTypeName();this.m_freeContacts[c][b].push(a)};Box2D.Dynamics.Contacts.b2ContactFactory.singleton=new Box2D.Dynamics.Contacts.b2ContactFactory();Box2D.Dynamics.b2ContactManager=function(b){this.m_world=b;this.m_contactFilter=Box2D.Dynamics.b2ContactFilter.b2_defaultFilter;this.m_contactListener=Box2D.Dynamics.b2ContactListener.b2_defaultListener;this.m_contactFactory=Box2D.Dynamics.Contacts.b2ContactFactory.singleton;this.m_broadPhase=new Box2D.Collision.b2DynamicTreeBroadPhase();var a=this;this.m_addPairCallback=function(c,d){a.AddPair(c,d)}};Box2D.Dynamics.b2ContactManager.prototype.AddPair=function(a,i){var g=a.GetBody();var f=i.GetBody();if(g==f){return}if(!f.ShouldCollide(g)){return}if(!this.m_contactFilter.ShouldCollide(a,i)){return}for(var b=f.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode()){var e=b.contact.GetFixtureA();if(e==a){var d=b.contact.GetFixtureB();if(d==i){return}}else{if(e==i){var d=b.contact.GetFixtureB();if(d==a){return}}}}var h=this.m_contactFactory.Create(a,i)};Box2D.Dynamics.b2ContactManager.prototype.FindNewContacts=function(){this.m_broadPhase.UpdatePairs(this.m_addPairCallback)};Box2D.Dynamics.b2ContactManager.prototype.Destroy=function(f){var a=f.GetFixtureA();var e=f.GetFixtureB();var d=a.GetBody();var b=e.GetBody();if(f.IsTouching()){this.m_contactListener.EndContact(f)}if(f.m_manifold.m_pointCount>0){d.SetAwake(true);b.SetAwake(true)}f.RemoveFromLists();this.m_contactFactory.Destroy(f)};Box2D.Dynamics.b2ContactManager.prototype.Collide=function(){for(var a=this.m_world.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){var i=a.contact;var g=i.GetFixtureA();var e=i.GetFixtureB();var d=g.m_body;var b=e.m_body;if(!d.IsAwake()&&!b.IsAwake()){continue}if(i.IsFiltering()){if(!b.ShouldCollide(d)){this.Destroy(i);continue}if(!this.m_contactFilter.ShouldCollide(g,e)){this.Destroy(i);continue}i.ClearFiltering()}var h=g.m_proxy;var f=e.m_proxy;var j=this.m_broadPhase.TestOverlap(h,f);if(!j){this.Destroy(i);continue}i.Update(this.m_contactListener)}};Box2D.Dynamics.b2ContactManager.s_evalCP=new Box2D.Collision.b2ContactPoint();Box2D.Dynamics.b2World=function(b,a){if(!this.m_contactManager){this.m_contactManager=new Box2D.Dynamics.b2ContactManager(this)}if(!this.m_contactSolver){this.m_contactSolver=Box2D.Dynamics.Contacts.b2ContactSolver.singleton}this.m_isLocked=false;this.m_newFixture=false;this.m_destructionListener=null;this.m_debugDraw=null;if(!this.bodyList){this.bodyList=new Box2D.Dynamics.b2BodyList()}if(!this.contactList){this.contactList=new Box2D.Dynamics.Contacts.b2ContactList()}this.m_jointList=null;if(!this.controllerList){this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList()}this.m_jointCount=0;this.m_warmStarting=true;this.m_continuousPhysics=true;this.m_allowSleep=a;if(!this.m_gravity){this.m_gravity=Box2D.Common.Math.b2Vec2.Get(0,0)}this.m_gravity.SetV(b);this.m_inv_dt0=0;if(!this.m_groundBody){this.m_groundBody=this.CreateBody(new Box2D.Dynamics.b2BodyDef())}if(!this.mainTimeStep){this.mainTimeStep=new Box2D.Dynamics.b2TimeStep(0,0,0,0,this.m_warmStarting)}this.mainTimeStep.Reset(0,0,0,0,this.m_warmStarting);if(!this.islandTimeStep){this.islandTimeStep=new Box2D.Dynamics.b2TimeStep(0,0,0,0,this.m_warmStarting)}this.islandTimeStep.Reset(0,0,0,0,this.m_warmStarting);if(!this.island){this.island=new Box2D.Dynamics.b2Island(this.m_contactManager.m_contactListener,this.m_contactSolver)}};Box2D.Dynamics.b2World.MAX_TOI=1-100*Number.MIN_VALUE;Box2D.Dynamics.b2World.s_solveStack=[];Box2D.Dynamics.b2World.s_solveQueue=[];Box2D.Dynamics.b2World.s_solveTOI2Result={};Box2D.Dynamics.b2World.prototype.SetDestructionListener=function(a){this.m_destructionListener=a};Box2D.Dynamics.b2World.prototype.SetContactFilter=function(a){this.m_contactManager.m_contactFilter=a};Box2D.Dynamics.b2World.prototype.SetContactListener=function(a){this.m_contactManager.m_contactListener=a};Box2D.Dynamics.b2World.prototype.SetDebugDraw=function(a){this.m_debugDraw=a};Box2D.Dynamics.b2World.prototype.SetBroadPhase=function(a){var b=this.m_contactManager.m_broadPhase;this.m_contactManager.m_broadPhase=a;for(var d=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);d;d=d.GetNextNode()){for(var c=d.body.GetFixtureList().GetFirstNode();c;c=c.GetNextNode()){var e=c.fixture;e.m_proxy=a.CreateProxy(b.GetFatAABB(e.m_proxy),e)}}};Box2D.Dynamics.b2World.prototype.GetProxyCount=function(){return this.m_contactManager.m_broadPhase.GetProxyCount()};Box2D.Dynamics.b2World.prototype.CreateBody=function(c){Box2D.Common.b2Settings.b2Assert(!this.IsLocked());var a=Box2D.Dynamics.b2Body.Get(c,this);this.bodyList.AddBody(a);return a};Box2D.Dynamics.b2World.prototype.DestroyBody=function(c){Box2D.Common.b2Settings.b2Assert(!this.IsLocked());var e=c.m_jointList;while(e){var a=e;e=e.next;if(this.m_destructionListener){this.m_destructionListener.SayGoodbyeJoint(a.joint)}this.DestroyJoint(a.joint)}for(var g=c.GetControllerList().GetFirstNode();g;g=g.GetNextNode()){g.controller.RemoveBody(c)}for(var d=c.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);d;d=d.GetNextNode()){this.m_contactManager.Destroy(d.contact)}for(var f=c.GetFixtureList().GetFirstNode();f;f=f.GetNextNode()){if(this.m_destructionListener){this.m_destructionListener.SayGoodbyeFixture(f.fixture)}c.DestroyFixture(f.fixture)}c.Destroy();this.bodyList.RemoveBody(c)};Box2D.Dynamics.b2World.prototype.CreateJoint=function(c){var b=Box2D.Dynamics.Joints.b2Joint.Create(c);b.m_prev=null;b.m_next=this.m_jointList;if(this.m_jointList){this.m_jointList.m_prev=b}this.m_jointList=b;this.m_jointCount++;b.m_edgeA.joint=b;b.m_edgeA.other=b.m_bodyB;b.m_edgeA.prev=null;b.m_edgeA.next=b.m_bodyA.m_jointList;if(b.m_bodyA.m_jointList){b.m_bodyA.m_jointList.prev=b.m_edgeA}b.m_bodyA.m_jointList=b.m_edgeA;b.m_edgeB.joint=b;b.m_edgeB.other=b.m_bodyA;b.m_edgeB.prev=null;b.m_edgeB.next=b.m_bodyB.m_jointList;if(b.m_bodyB.m_jointList){b.m_bodyB.m_jointList.prev=b.m_edgeB}b.m_bodyB.m_jointList=b.m_edgeB;var e=c.bodyA;var d=c.bodyB;if(!c.collideConnected){for(var a=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){if(a.contact.GetOther(d)==e){a.contact.FlagForFiltering()}}}return b};Box2D.Dynamics.b2World.prototype.DestroyJoint=function(b){var c=b.m_collideConnected;if(b.m_prev){b.m_prev.m_next=b.m_next}if(b.m_next){b.m_next.m_prev=b.m_prev}if(b==this.m_jointList){this.m_jointList=b.m_next}b.m_next=null;b.m_prev=null;var e=b.m_bodyA;var d=b.m_bodyB;e.SetAwake(true);d.SetAwake(true);if(b.m_edgeA.prev){b.m_edgeA.prev.next=b.m_edgeA.next}if(b.m_edgeA.next){b.m_edgeA.next.prev=b.m_edgeA.prev}if(b.m_edgeA==e.m_jointList){e.m_jointList=b.m_edgeA.next}b.m_edgeA.prev=null;b.m_edgeA.next=null;if(b.m_edgeB.prev){b.m_edgeB.prev.next=b.m_edgeB.next}if(b.m_edgeB.next){b.m_edgeB.next.prev=b.m_edgeB.prev}if(b.m_edgeB==d.m_jointList){d.m_jointList=b.m_edgeB.next}b.m_edgeB.prev=null;b.m_edgeB.next=null;this.m_jointCount--;if(!c){for(var a=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){if(a.contact.GetOther(d)==e){a.contact.FlagForFiltering()}}}};Box2D.Dynamics.b2World.prototype.GetControllerList=function(){return this.controllerList};Box2D.Dynamics.b2World.prototype.AddController=function(a){if(a.m_world!==null&&a.m_world!=this){throw new Error("Controller can only be a member of one world")}this.controllerList.AddController(a);a.m_world=this;return a};Box2D.Dynamics.b2World.prototype.RemoveController=function(a){this.controllerList.RemoveController(a);a.m_world=null;a.Clear()};Box2D.Dynamics.b2World.prototype.CreateController=function(a){return this.AddController(a)};Box2D.Dynamics.b2World.prototype.DestroyController=function(a){this.RemoveController(a)};Box2D.Dynamics.b2World.prototype.SetWarmStarting=function(a){this.m_warmStarting=a};Box2D.Dynamics.b2World.prototype.SetContinuousPhysics=function(a){this.m_continuousPhysics=a};Box2D.Dynamics.b2World.prototype.GetBodyCount=function(){return this.bodyList.GetBodyCount()};Box2D.Dynamics.b2World.prototype.GetJointCount=function(){return this.m_jointCount};Box2D.Dynamics.b2World.prototype.GetContactCount=function(){return this.contactList.GetContactCount()};Box2D.Dynamics.b2World.prototype.SetGravity=function(a){this.m_gravity=a};Box2D.Dynamics.b2World.prototype.GetGravity=function(){return this.m_gravity};Box2D.Dynamics.b2World.prototype.GetGroundBody=function(){return this.m_groundBody};Box2D.Dynamics.b2World.prototype.Step=function(a,c,b){if(this.m_newFixture){this.m_contactManager.FindNewContacts();this.m_newFixture=false}this.m_isLocked=true;this.mainTimeStep.Reset(a,this.m_inv_dt0*a,c,b,this.m_warmStarting);this.m_contactManager.Collide();if(this.mainTimeStep.dt>0){this.Solve(this.mainTimeStep);if(this.m_continuousPhysics){this.SolveTOI(this.mainTimeStep)}this.m_inv_dt0=this.mainTimeStep.inv_dt}this.m_isLocked=false};Box2D.Dynamics.b2World.prototype.ClearForces=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies);a;a=a.GetNextNode()){a.body.m_force.SetZero();a.body.m_torque=0}};Box2D.Dynamics.b2World.prototype.DrawDebugData=function(){if(this.m_debugDraw===null){return}this.m_debugDraw.Clear();var i=this.m_debugDraw.GetFlags();if(i&Box2D.Dynamics.b2DebugDraw.e_shapeBit){var r=Box2D.Dynamics.b2World.s_color_inactive;var e=Box2D.Dynamics.b2World.s_color_static;var a=Box2D.Dynamics.b2World.s_color_kinematic;var q=Box2D.Dynamics.b2World.s_color_dynamic_sleeping;var d=Box2D.Dynamics.b2World.s_color_dynamic_awake;for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode()){var w=c.body;for(var m=w.GetFixtureList().GetFirstNode();m;m=m.GetNextNode()){var v=m.fixture;var n=v.GetShape();if(!w.IsActive()){this.DrawShape(n,w.m_xf,r)}else{if(w.GetType()==Box2D.Dynamics.b2BodyDef.b2_staticBody){this.DrawShape(n,w.m_xf,e)}else{if(w.GetType()==Box2D.Dynamics.b2BodyDef.b2_kinematicBody){this.DrawShape(n,w.m_xf,a)}else{if(!w.IsAwake()){this.DrawShape(n,w.m_xf,q)}else{this.DrawShape(n,w.m_xf,d)}}}}}}}if(i&Box2D.Dynamics.b2DebugDraw.e_jointBit){for(var u=this.m_jointList;u;u=u.m_next){this.DrawJoint(u)}}if(i&Box2D.Dynamics.b2DebugDraw.e_controllerBit){for(var o=this.controllerList.GetFirstNode();o;o=o.GetNextNode()){o.controller.Draw(this.m_debugDraw)}}if(i&Box2D.Dynamics.b2DebugDraw.e_pairBit){var z=Box2D.Dynamics.b2World.s_pairColor;for(var p=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);p;p=p.GetNextNode()){var y=p.contact.GetFixtureA();var x=p.contact.GetFixtureB();var k=y.GetAABB().GetCenter();var h=x.GetAABB().GetCenter();this.m_debugDraw.DrawSegment(k,h,z);Box2D.Common.Math.b2Vec2.Free(k);Box2D.Common.Math.b2Vec2.Free(h)}}if(i&Box2D.Dynamics.b2DebugDraw.e_aabbBit){var g=Box2D.Dynamics.b2World.s_aabbColor;for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.activeBodies);c;c=c.GetNextNode()){var w=c.body;for(var m=w.GetFixtureList().GetFirstNode();m;m=m.GetNextNode()){var v=m.fixture;var l=this.m_contactManager.m_broadPhase.GetFatAABB(v.m_proxy);var t=[Box2D.Common.Math.b2Vec2.Get(l.lowerBound.x,l.lowerBound.y),Box2D.Common.Math.b2Vec2.Get(l.upperBound.x,l.lowerBound.y),Box2D.Common.Math.b2Vec2.Get(l.upperBound.x,l.upperBound.y),Box2D.Common.Math.b2Vec2.Get(l.lowerBound.x,l.upperBound.y)];this.m_debugDraw.DrawPolygon(t,4,g);Box2D.Common.Math.b2Vec2.Free(t[0]);Box2D.Common.Math.b2Vec2.Free(t[1]);Box2D.Common.Math.b2Vec2.Free(t[2]);Box2D.Common.Math.b2Vec2.Free(t[3])}}}if(i&Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit){for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode()){var w=c.body;Box2D.Dynamics.b2World.s_xf.R=w.m_xf.R;Box2D.Dynamics.b2World.s_xf.position=w.GetWorldCenter();this.m_debugDraw.DrawTransform(Box2D.Dynamics.b2World.s_xf)}}};Box2D.Dynamics.b2World.prototype.QueryAABB=function(b,a){this.m_contactManager.m_broadPhase.Query(b,a)};Box2D.Dynamics.b2World.prototype.QueryPoint=function(d,c){var b=function(e){if(e.TestPoint(c)){return d(e)}else{return true}};var a=Box2D.Collision.b2AABB.Get();a.lowerBound.Set(c.x-Box2D.Common.b2Settings.b2_linearSlop,c.y-Box2D.Common.b2Settings.b2_linearSlop);a.upperBound.Set(c.x+Box2D.Common.b2Settings.b2_linearSlop,c.y+Box2D.Common.b2Settings.b2_linearSlop);this.m_contactManager.m_broadPhase.Query(b,a);Box2D.Collision.b2AABB.Free(a)};Box2D.Dynamics.b2World.prototype.RayCast=function(g,f,e){var a=this.m_contactManager.m_broadPhase;var d=new Box2D.Collision.b2RayCastOutput();var c=function(i,j){var k=j.RayCast(d,i);if(k){var m=1-d.fraction;var h=Box2D.Common.Math.b2Vec2.Get(m*f.x+d.fraction*e.x,m*f.y+d.fraction*e.y);var l=g(j,h,d.normal,d.fraction);Box2D.Common.Math.b2Vec2.Free(h);return l}else{return i.maxFraction}};var b=new Box2D.Collision.b2RayCastInput(f,e,1);a.RayCast(c,b)};Box2D.Dynamics.b2World.prototype.RayCastOne=function(d,b){var a=null;var c=function(g,e,h,f){a=g;return f};this.RayCast(c,d,b);return a};Box2D.Dynamics.b2World.prototype.RayCastAll=function(d,c){var a=Box2D.Array.Get();var b=function(g,e,h,f){a.push(g);return 1};this.RayCast(b,d,c);return a};Box2D.Dynamics.b2World.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.b2World.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2World.prototype.GetContactList=function(){return this.contactList};Box2D.Dynamics.b2World.prototype.IsLocked=function(){return this.m_isLocked};Box2D.Dynamics.b2World.prototype.Solve=function(d){for(var c=this.controllerList.GetFirstNode();c;c=c.GetNextNode()){c.controller.Step(d)}var k=this.island;k.Reset(this.m_contactManager.m_contactListener,this.m_contactSolver);for(var e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);e;e=e.GetNextNode()){e.body.m_islandFlag=false}for(var a=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){a.contact.m_islandFlag=false}for(var g=this.m_jointList;g;g=g.m_next){g.m_islandFlag=false}var n=Box2D.Dynamics.b2World.s_solveStack;for(var e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);e;e=e.GetNextNode()){var h=e.body;if(h.m_islandFlag){continue}k.Clear();n.length=0;n.push(h);h.m_islandFlag=true;while(n.length>0){var m=n.pop();k.AddBody(m);if(!m.IsAwake()){m.SetAwake(true)}if(m.GetType()===Box2D.Dynamics.b2BodyDef.b2_staticBody){continue}for(var a=m.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);a;a=a.GetNextNode()){var i=a.contact;if(i.m_islandFlag){continue}k.AddContact(i);i.m_islandFlag=true;var l=i.GetOther(m);if(l.m_islandFlag){continue}n.push(l);l.m_islandFlag=true}for(var f=m.m_jointList;f;f=f.next){if(f.joint.m_islandFlag||!f.other.IsActive()){continue}k.AddJoint(f.joint);f.joint.m_islandFlag=true;if(f.other.m_islandFlag){continue}n.push(f.other);f.other.m_islandFlag=true}}k.Solve(d,this.m_gravity,this.m_allowSleep)}for(var e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);e;e=e.GetNextNode()){e.body.SynchronizeFixtures()}this.m_contactManager.FindNewContacts()};Box2D.Dynamics.b2World.prototype.SolveTOI=function(e){var q=this.island;q.Reset(this.m_contactManager.m_contactListener,this.m_contactSolver);for(var g=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);g;g=g.GetNextNode()){var t=g.body;t.m_islandFlag=false;t.m_sweep.t0=0}for(var a=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){a.contact.m_islandFlag=false;a.contact.m_toi=null}for(var k=this.m_jointList;k;k=k.m_next){k.m_islandFlag=false}while(true){var c=this._SolveTOI2(e);var s=c.minContact;var d=c.minTOI;if(s===null||Box2D.Dynamics.b2World.MAX_TOI<d){break}var m=s.m_fixtureA.GetBody();var h=s.m_fixtureB.GetBody();Box2D.Dynamics.b2World.s_backupA.Set(m.m_sweep);Box2D.Dynamics.b2World.s_backupB.Set(h.m_sweep);m.Advance(d);h.Advance(d);s.Update(this.m_contactManager.m_contactListener);s.m_toi=null;if(s.IsSensor()||!s.IsEnabled()){m.m_sweep.Set(Box2D.Dynamics.b2World.s_backupA);h.m_sweep.Set(Box2D.Dynamics.b2World.s_backupB);m.SynchronizeTransform();h.SynchronizeTransform();continue}if(!s.IsTouching()){continue}var n=m;if(n.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){n=h}q.Clear();var o=Box2D.Dynamics.b2World.s_solveQueue;o.length=0;o.push(n);n.m_islandFlag=true;while(o.length>0){var t=(o.shift());q.AddBody(t);if(!t.IsAwake()){t.SetAwake(true)}if(t.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){continue}for(var a=t.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);a;a=a.GetNextNode()){if(q.m_contactCount==Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland){break}var p=a.contact;if(p.m_islandFlag){continue}q.AddContact(p);p.m_islandFlag=true;var r=p.GetOther(t);if(r.m_islandFlag){continue}if(r.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody){r.Advance(d);r.SetAwake(true);o.push(r)}r.m_islandFlag=true}for(var f=t.m_jointList;f;f=f.next){if(q.m_jointCount==Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland){continue}if(f.joint.m_islandFlag||!f.other.IsActive()){continue}q.AddJoint(f.joint);f.joint.m_islandFlag=true;if(f.other.m_islandFlag){continue}if(f.other.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody){f.other.Advance(d);f.other.SetAwake(true);o.push(f.other)}f.other.m_islandFlag=true}}this.islandTimeStep.Reset((1-d)*e.dt,0,e.velocityIterations,e.positionIterations,false);q.SolveTOI(this.islandTimeStep);for(var l=0;l<q.m_bodies.length;l++){q.m_bodies[l].m_islandFlag=false;if(!q.m_bodies[l].IsAwake()||q.m_bodies[l].GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody){continue}q.m_bodies[l].SynchronizeFixtures();for(var a=q.m_bodies[l].contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){a.contact.m_toi=null}}for(var l=0;l<q.m_contactCount;l++){q.m_contacts[l].m_islandFlag=false;q.m_contacts[l].m_toi=null}for(var l=0;l<q.m_jointCount;l++){q.m_joints[l].m_islandFlag=false}this.m_contactManager.FindNewContacts()}};Box2D.Dynamics.b2World.prototype._SolveTOI2=function(e){var j=null;var d=1;for(var b=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts);b;b=b.GetNextNode()){var i=b.contact;if(this._SolveTOI2SkipContact(e,i)){continue}var a=1;if(i.m_toi!=null){a=i.m_toi}else{if(i.IsTouching()){a=1;i.m_toi=a}else{var g=i.m_fixtureA.GetBody();var f=i.m_fixtureB.GetBody();var h=g.m_sweep.t0;if(g.m_sweep.t0<f.m_sweep.t0){h=f.m_sweep.t0;g.m_sweep.Advance(h)}else{if(f.m_sweep.t0<g.m_sweep.t0){h=g.m_sweep.t0;f.m_sweep.Advance(h)}}a=i.ComputeTOI(g.m_sweep,f.m_sweep);Box2D.Common.b2Settings.b2Assert(0<=a&&a<=1);if(a>0&&a<1){a=(1-a)*h+a}i.m_toi=a}}if(Number.MIN_VALUE<a&&a<d){j=i;d=a}}var k=Box2D.Dynamics.b2World.s_solveTOI2Result;k.minContact=j;k.minTOI=d;return k};Box2D.Dynamics.b2World.prototype._SolveTOI2SkipContact=function(b,e){var a=e.m_fixtureA.GetBody();var d=e.m_fixtureB.GetBody();if((a.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||!a.IsAwake())&&(d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||!d.IsAwake())){return true}return false};Box2D.Dynamics.b2World.prototype.DrawJoint=function(e){if(e instanceof Box2D.Dynamics.Joints.b2DistanceJoint||e instanceof Box2D.Dynamics.Joints.b2MouseJoint){var c=e.GetAnchorA();var a=e.GetAnchorB();this.m_debugDraw.DrawSegment(c,a,Box2D.Dynamics.b2World.s_jointColor);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(a)}else{if(e instanceof Box2D.Dynamics.Joints.b2PulleyJoint){var c=e.GetAnchorA();var a=e.GetAnchorB();var d=e.GetGroundAnchorA();var b=e.GetGroundAnchorB();this.m_debugDraw.DrawSegment(d,c,Box2D.Dynamics.b2World.s_jointColor);this.m_debugDraw.DrawSegment(b,a,Box2D.Dynamics.b2World.s_jointColor);this.m_debugDraw.DrawSegment(d,b,Box2D.Dynamics.b2World.s_jointColor);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(b)}else{var c=e.GetAnchorA();var a=e.GetAnchorB();if(e.GetBodyA()!=this.m_groundBody){this.m_debugDraw.DrawSegment(e.GetBodyA().m_xf.position,c,Box2D.Dynamics.b2World.s_jointColor)}this.m_debugDraw.DrawSegment(c,a,Box2D.Dynamics.b2World.s_jointColor);if(e.GetBodyB()!=this.m_groundBody){this.m_debugDraw.DrawSegment(e.GetBodyB().m_xf.position,a,Box2D.Dynamics.b2World.s_jointColor)}Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(a)}}};Box2D.Dynamics.b2World.prototype.DrawShape=function(l,o,g){if(l instanceof Box2D.Collision.Shapes.b2CircleShape){var d=l;var b=Box2D.Common.Math.b2Math.MulX(o,d.m_p);var j=d.m_radius;var f=o.R.col1;this.m_debugDraw.DrawSolidCircle(b,j,f,g);Box2D.Common.Math.b2Vec2.Free(b)}else{if(l instanceof Box2D.Collision.Shapes.b2PolygonShape){var h=0;var c=l;var a=c.GetVertexCount();var p=c.GetVertices();var k=Box2D.Array.Get();for(h=0;h<a;h++){k[h]=Box2D.Common.Math.b2Math.MulX(o,p[h])}this.m_debugDraw.DrawSolidPolygon(k,a,g);for(h=0;h<a;h++){Box2D.Common.Math.b2Vec2.Free(k[h])}}else{if(l instanceof Box2D.Collision.Shapes.b2EdgeShape){var e=l;var n=Box2D.Common.Math.b2Math.MulX(o,e.GetVertex1());var m=Box2D.Common.Math.b2Math.MulX(o,e.GetVertex2());this.m_debugDraw.DrawSegment(n,m,g);Box2D.Common.Math.b2Vec2.Free(n);Box2D.Common.Math.b2Vec2.Free(m)}}}};Box2D.Dynamics.b2World._freeCache=[];Box2D.Dynamics.b2World.Get=function(d,c){var a=this._freeCache;var b;if(a.length>0){b=a.pop();this.call(b,d,c)}else{b=new this(d,c)}return b};Box2D.Dynamics.b2World.Free=function(a){this._freeCache.push(a)};Box2D.Dynamics.b2World.s_xf=new Box2D.Common.Math.b2Transform();Box2D.Dynamics.b2World.s_backupA=new Box2D.Common.Math.b2Sweep();Box2D.Dynamics.b2World.s_backupB=new Box2D.Common.Math.b2Sweep();Box2D.Dynamics.b2World.s_jointColor=new Box2D.Common.b2Color(0.5,0.8,0.8);Box2D.Dynamics.b2World.s_color_inactive=new Box2D.Common.b2Color(0.5,0.5,0.3);Box2D.Dynamics.b2World.s_color_static=new Box2D.Common.b2Color(0.5,0.9,0.5);Box2D.Dynamics.b2World.s_color_kinematic=new Box2D.Common.b2Color(0.5,0.5,0.9);Box2D.Dynamics.b2World.s_color_dynamic_sleeping=new Box2D.Common.b2Color(0.6,0.6,0.6);Box2D.Dynamics.b2World.s_color_dynamic_awake=new Box2D.Common.b2Color(0.9,0.7,0.7);Box2D.Dynamics.b2World.s_pairColor=new Box2D.Common.b2Color(0.3,0.9,0.9);Box2D.Dynamics.b2World.s_aabbColor=new Box2D.Common.b2Color(0,0,0.8);Box2D.Dynamics.b2Body.prototype.SetUserData=function(a){this.userData=a};Box2D.Dynamics.b2Body.prototype.GetUserData=function(){return this.userData};Box2D.Dynamics.b2Fixture.prototype.SetUserData=function(a){this.userData=a};Box2D.Dynamics.b2Fixture.prototype.GetUserData=function(){return this.userData};Box2D.Dynamics.b2Fixture.prototype.ResizeShapeAsBox=function(b,a){this.m_shape.SetAsBox(b,a)};Box2D.Dynamics.b2Fixture.prototype.ResizeShapeAsCircle=function(a){this.m_shape.SetRadius(a)};Box2D.Dynamics.b2Body.prototype.ResizeFixtureShapesAsBox=function(c,b){for(var a=this.fixtureList.GetFirstNode();a;a=a.GetNextNode()){a.fixture.ResizeShapeAsBox(c,b)}this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.ResizeFixtureShapesAsCircle=function(a){for(var b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode()){b.fixture.ResizeShapeAsCircle(a)}this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.ChangeFixtureDensities=function(b){for(var a=this.fixtureList.GetFirstNode();a;a=a.GetNextNode()){a.fixture.SetDensity(b)}this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.ChangeFixtureFrictions=function(b){for(var a=this.fixtureList.GetFirstNode();a;a=a.GetNextNode()){a.fixture.SetFriction(b)}this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.ChangeFixtureRestitutions=function(b){for(var a=this.fixtureList.GetFirstNode();a;a=a.GetNextNode()){a.fixture.SetRestitution(b)}this.ResetMassData()};gs.platform={};gs.html5={};gs.html5.text={};gs.LocalStorage={prefix:"",isAvailable:function(){return typeof(localStorage)!=="undefined"},setPrefix:function(a){gs.LocalStorage.prefix=a},formatRealKey:function(a){return gs.LocalStorage.prefix+a},getString:function(a){var d=gs.LocalStorage.formatRealKey(a);var b=null;if(gs.LocalStorage.isAvailable()){try{b=localStorage.getItem(d)}catch(c){gs.Log.error("LocalStorage read failed:",a)}}return b},setString:function(a,c){try{var d=gs.LocalStorage.formatRealKey(a);localStorage.removeItem(d);localStorage.setItem(d,c)}catch(b){gs.Log.error("LocalStorage write failed:",a)}},getObject:function(a){var c=gs.LocalStorage.getString(a);var b=null;if(c!==null){try{b=JSON.parse(c)}catch(d){gs.Log.error("LocalStorage object parsing failed:",a)}}return b},setObject:function(a,d){try{var b=JSON.stringify(d);gs.LocalStorage.setString(a,b)}catch(c){gs.Log.error("LocalStorage object serialization failed:",a)}},getAll:function(){var b={};var a=gs.LocalStorage.prefix;Object.keys(localStorage).forEach(function(c){if(c.substr(0,a.length)===a){b[c.substr(a.length)]=localStorage.getItem(c)}});return b}};gs.html5.Audio={createAudioElement:function(){return document.createElement("AUDIO")},isWebAudioExtensionSupported:function(){var a=gs.html5.Audio.createAudioContext();return a!==null},createAudioContext:function(){if(typeof AudioContext!=="undefined"){return new AudioContext()}if(typeof webkitAudioContext!=="undefined"){var a=new webkitAudioContext();if(typeof a.createGain==="function"){return a}}return null},canPlayExtension:function(d){if(!d){return false}var b=null;var c=d.toLowerCase();switch(c){case"m4a":b="mp4";break;default:b=c;break}var a="audio/"+b;return this.canPlayType(a)},canPlayType:function(a){if(!this.canPlayTypeCache){this.canPlayTypeCache={}}if(a in this.canPlayTypeCache){return this.canPlayTypeCache[a]}var b=false;var d=this.createAudioElement();try{b=!!(d.canPlayType&&d.canPlayType(a).replace(/no/,""))}catch(c){b=false}this.canPlayTypeCache[a]=b;return b}};gs.html5.ExternalAudioHandle=function(a){this.key=a;this.externalHandle=null};gs.html5.ExternalAudioHandle.prototype={clone:function(){return new gs.html5.ExternalAudioHandle(this.key)}};gs.html5.ExternalAudioPlayer=function(){this.host=window.external;this.inUse=false;this.isAvailable=false;if(/\b(Firefox|Chrome)\b/.test(navigator.userAgent)){this.isAvailable=false}else{try{this.host.setMasterMusicVolume(1);this.isAvailable=true}catch(a){this.isAvailable=false}}};gs.html5.ExternalAudioPlayer.prototype={newHandle:function(a){return new gs.html5.ExternalAudioHandle(a)},setMasterMusicVolume:function(b){if(this.isAvailable){try{this.host.setMasterMusicVolume(b)}catch(a){this.logError(a)}}},setMasterSoundVolume:function(b){if(this.isAvailable){try{this.host.setMasterSoundVolume(b)}catch(a){this.logError(a)}}},createMusicInstance:function(b){if(!this.isAvailable){return b}try{var c=this.host.createMusicInstance(b.key);b.externalHandle=c;this.inUse=true}catch(a){this.logError(a)}return b},createSoundInstance:function(b,d){if(!this.isAvailable){return b}try{var c=this.host.createSoundInstance(b.key,d);b.externalHandle=c;this.inUse=true}catch(a){this.logError(a)}return b},setAudioInstanceLoop:function(c,a){if(!this.isAvailable){return false}try{return this.host.setAudioInstanceLoop(c.externalHandle,a)}catch(b){this.logError(b);return false}},setAudioInstanceVolume:function(b,c){if(!this.isAvailable){return false}try{return this.host.setAudioInstanceVolume(b.externalHandle,c)}catch(a){this.logError(a);return false}},setAudioInstancePitch:function(b,c){if(!this.isAvailable){return false}try{return this.host.setAudioInstancePitch(b.externalHandle,c)}catch(a){this.logError(a);return false}},setAudioInstancePosition:function(c,a,d){if(!this.isAvailable){return false}try{return this.host.setAudioInstancePosition(c.externalHandle,a,d)}catch(b){this.logError(b);return false}},setAudioInstanceVelocity:function(d,b,a){if(!this.isAvailable){return false}try{return this.host.setAudioInstanceVelocity(d.externalHandle,b,a)}catch(c){this.logError(c);return false}},playAudioInstance:function(b){if(!this.isAvailable){return false}try{return this.host.playAudioInstance(b.externalHandle)}catch(a){this.logError(a);return false}},stopAudioInstance:function(b){if(!this.isAvailable){return false}try{return this.host.stopAudioInstance(b.externalHandle)}catch(a){this.logError(a);return false}},replayAudioInstance:function(b){if(!this.isAvailable){return false}try{return this.host.replayAudioInstance(b.externalHandle)}catch(a){this.logError(a);return false}},pauseAudioInstance:function(b){if(!this.isAvailable){return false}try{return this.host.pauseAudioInstance(b.externalHandle)}catch(a){this.logError(a);return false}},resumeAudioInstance:function(b){if(!this.isAvailable){return false}try{return this.host.resumeAudioInstance(b.externalHandle)}catch(a){this.logError(a);return false}},stopAllAudioInstances:function(){if(this.isAvailable&&this.inUse){try{this.host.stopAllAudioInstances()}catch(a){this.logError(a)}}},pauseAllAudioInstances:function(){if(this.isAvailable&&this.inUse){try{this.host.pauseAllAudioInstances()}catch(a){this.logError(a)}}},resumeAllAudioInstances:function(){if(this.isAvailable&&this.inUse){try{this.host.resumeAllAudioInstances()}catch(a){this.logError(a)}}},logError:function(a){gs.Log.warn("ExternalAudioPlayer: "+a.message)}};gs.html5.GraphicsBuffer=function(b,a,c){this.canvas=null;this.context=null;this.width=b||0;this.height=a||0;this.canvas=gs.dom.createCanvas();this.canvas.width=this.width;this.canvas.height=this.height;this.canvas.style.backgroundColor="transparent";if(c!==false){this.context=this.canvas.getContext("2d")}};gs.html5.GraphicsBuffer.acquire=function(b){var a=new gs.html5.GraphicsBuffer(0,0,false);a.acquire(b);return a};gs.html5.GraphicsBuffer.prototype={acquire:function(a){this.releaseContext();this.canvas=a;this.width=a.width;this.height=a.height},resize:function(b,a){if(this.width!==b||this.height!==a){this.canvas.width=b;this.canvas.height=a;this.width=b;this.height=a}},releaseContext:function(){this.context=null}};gs.html5.Canvas={createCanvasElement:function(c,a){var b=document.createElement("CANVAS");b.style.backgroundColor="transparent";if(c!==undefined&&a!==undefined){b.width=c;b.height=a}return b},createCanvasBuffer:function(b,a){return new gs.html5.GraphicsBuffer(b,a)},createTintedImage:function(i,h,f,c){var e=i.width;var a=i.height;var d=gs.html5.Canvas.createCanvasBuffer(e,a);d.context.drawImage(i,0,0,e,a);var j=d.context.getImageData(0,0,e,a);gs.html5.Canvas.tintImageData(j,e,a,h,f,c);d.context.putImageData(j,0,0);return d.canvas},tintImageData:function(a,d,t,c,n,q){var m,k;var h=[];var e=h[c]=[];for(m=0,k=0;m<256;++m){e[m]=k|0;k+=c}var p=h[n]||[];if(!h[n]){h[n]=p;k=0;for(m=0,k=0;m<256;++m){p[m]=k|0;k+=n}}var s=h[q]||[];if(!h[q]){h[q]=s;k=0;for(m=0,k=0;m<256;++m){s[m]=k|0;k+=q}}var l=a.data;var f=d*t*4;for(var o=0;o!==f;o+=2){l[o]=e[l[o]];o++;l[o]=p[l[o]];o++;l[o]=s[l[o]]}},createCroppedImage:function(g,f,b,e,d){var a=0;var h=0;switch(e){case"left":break;case"center":a=Math.floor((g.width-f)/2);break;case"right":a=g.width-f;break}switch(d){case"top":break;case"center":h=Math.floor((g.height-b)/2);break;case"bottom":h=g.height-b;break}var c=gs.html5.Canvas.createCanvasBuffer(f,b);c.context.drawImage(g,-a,-h);return c.canvas},createPaddedImage:function(e,d,b){var a=Math.floor((d-e.width)/2);var f=Math.floor((b-e.height)/2);var c=gs.html5.Canvas.createCanvasBuffer(d,b);c.context.drawImage(e,a,f);return c.canvas},createTiledImage:function(g,e,a,h,c,f){if(!f){f="repeat"}if(g.width===0||g.height===0){return gs.html5.createCanvasElement(e,a)}var d=gs.html5.Canvas.createCanvasBuffer(h,c);d.context.drawImage(g,0,0,h,c);if(e%h!==0){e=Math.ceil(e/h)*h}if(a%c!==0){a=Math.ceil(a/c)*c}var b=gs.html5.Canvas.createCanvasBuffer(e,a);b.context.fillStyle=b.context.createPattern(d.canvas,f);b.context.fillRect(0,0,e,a);return b.canvas},createTiledImageHorizontal:function(b,a,c){return gs.html5.Canvas.createTiledImage(b,a,b.height,c,b.height,"repeat-x")},createTiledImageVertical:function(c,a,b){return gs.html5.Canvas.createTiledImage(c,c.width,a,c.width,b,"repeat-y")}};gs.AspectRatio={ASPECT_INVALID:0,ASPECT_1_1:100,ASPECT_4_3:133,ASPECT_3_2:150,ASPECT_16_10:160,ASPECT_15_9:167,ASPECT_16_9:178};gs.AspectRatio.approximate=function(f,b){if(f===0||b===0){return gs.ASPECT_INVALID}var e=f/b;if(e<1){e=1/e}var a=Math.round(e*100);for(var d in gs.AspectRatio){var c=gs.AspectRatio[d];if(Math.abs(c-a)<2){return c}}return a};gs.ViewportFit={NONE:"NONE",CENTER:"CENTER",FILL:"FILL",LETTERBOX:"LETTERBOX",OVERSCAN:"OVERSCAN",STRETCH:"STRETCH"};gs.ViewportReference={GAME:"GAME",FRAME:"FRAME",WINDOW:"WINDOW",SCREEN:"SCREEN"};gs.ViewportScale={STRETCH:"STRETCH",RESIZE:"RESIZE",QUALITY:"QUALITY",WHOLE_MULTIPLE_PERFORMANCE:"WHOLE_MULTIPLE_PERFORMANCE",WHOLE_MULTIPLE_QUALITY:"WHOLE_MULTIPLE_QUALITY"};gs.html5.Viewport=function(){this.frame=null;this.frameWidth=0;this.frameHeight=0;this.drawBuffer=new gs.html5.GraphicsBuffer(0,0,false);this.drawWidth=0;this.drawHeightCSS=0;this.drawWidthPixel=0;this.drawHeightPixel=0;this.input=gs.dom.create("DIV");this.inputWidth=0;this.inputHeight=0;this.designWidth=0;this.designHeight=0;this.overlay=gs.dom.create("DIV");this.overlayWidth=0;this.overlayHeight=0;this.overlayCount=0;this.overlayLayer=null;this.overlayParent=null;this.overlayRequestCount=1;this.gameWidth=0;this.gameHeight=0;this.gameAspect=gs.AspectRatio.ASPECT_INVALID;this.gameIsPortrait=false;this.windowWidth=0;this.windowHeight=0;this.screenWidth=window.screen.width;this.screenHeight=window.screen.height;this.reportWidth=0;this.reportHeight=0;this.reportAspect=gs.AspectRatio.ASPECT_INVALID;this.reference=gs.ViewportReference.FRAME;this.scale=gs.ViewportScale.QUALITY;this.fit=gs.ViewportFit.LETTERBOX;this.factor=1;this.zoom=1;var a=window.devicePixelRatio||1;this.cssFactor=a;if(gs.platform===gs.firefox){this.cssFactor=1}};gs.html5.Viewport.prototype={setFrame:function(a){this.frame=a;this.updateFrameSize()},setCanvas:function(a){this.drawBuffer.acquire(a);this.frame=a.parentNode;var b=gs.dom.getComputedStyle(this.frame);this.frameWidth=parseInt(b.width,10);this.frameHeight=parseInt(b.height,10)},shouldReportTrueSize:function(){return this.fit===gs.ViewportFit.OVERSCAN},setReportSize:function(b,a){this.reportWidth=b;this.reportHeight=a;this.reportAspect=gs.AspectRatio.approximate(b,a)},appendOverlay:function(a){this.overlay.appendChild(a);this.overlayCount++;if(this.frame){this.frame.appendChild(this.overlay)}},resizeFrame:function(c,b){if(gs.globalOptions.forceViewportOrientationMatch){var a=(b>c);if(a!==this.gameIsPortrait){var d=c;c=b;b=d}}gs.dom.resizeElement(this.frame,c,b);this.frameWidth=c;this.frameHeight=b},resizeInput:function(b,a){gs.dom.resizeElement(this.input,b,a);this.inputWidth=b;this.inputHeight=a},resizeOverlay:function(b,a){gs.dom.resizeElement(this.overlay,b,a);this.overlayWidth=b;this.overlayHeight=a},resizeBuffer:function(i,l){var e=i*this.cssFactor;var k=l*this.cssFactor;var p=e/this.gameWidth;var n=k/this.gameHeight;var a=Math.min(p,n);var b=Math.max(p,n);var s;var d;var c;var m;switch(this.scale){case gs.ViewportScale.STRETCH:c=this.gameWidth;m=this.gameHeight;break;case gs.ViewportScale.RESIZE:c=e;m=k;break;case gs.ViewportScale.QUALITY:var f=this.gameWidth*this.gameHeight;var o=e*k;if(f>o){c=this.gameWidth;m=this.gameHeight}else{c=e;m=k}break;case gs.ViewportScale.WHOLE_MULTIPLE_PERFORMANCE:if(a>=1){s=a;d=Math.floor(s)}else{if(b<1){s=b;d=1/Math.floor(1/s)}}c=this.gameWidth*d;m=this.gameHeight*d;break;case gs.ViewportScale.WHOLE_MULTIPLE_QUALITY:if(a>=1){s=a;d=Math.ceil(s)}else{if(b<1){s=b;d=1/Math.floor(1/s)}}c=this.gameWidth*d;m=this.gameHeight*d;break;default:gs.Log.error("Unrecognized viewport scale:",this.scale)}var j=1/Math.sqrt(this.factor);c=Math.ceil(c*j);m=Math.ceil(m*j);var r=i/c;var q=l/m;var h="0 0";var g="scale3d("+r+","+q+",1)";gs.dom.resizeElement(this.drawBuffer.canvas,c,m);this.drawBuffer.canvas.style.transformOrigin=h;this.drawBuffer.canvas.style.transform=g;this.drawBuffer.canvas.style.webkitTransformOrigin=h;this.drawBuffer.canvas.style.webkitTransform=g;this.drawBuffer.resize(c,m)},refitBuffer:function(b,l){if(gs.globalOptions.forceViewportOrientationMatch){var g=(l>b);if(g!==this.gameIsPortrait){var d=b;b=l;l=d}}var a=this.gameWidth/this.gameHeight;var k=b/this.gameWidth;var j=l/this.gameHeight;var e=Math.min(k,j);var i=Math.max(k,j);var m;var f;var c,h;switch(this.fit){case gs.ViewportFit.NONE:m=this.gameWidth;f=this.gameHeight;c=0;h=0;break;case gs.ViewportFit.CENTER:m=this.gameWidth;f=this.gameHeight;c=Math.floor(0.5*(this.frameWidth-m));h=Math.floor(0.5*(this.frameHeight-f));break;case gs.ViewportFit.FILL:case gs.ViewportFit.STRETCH:m=b;f=l;c=0;h=0;break;case gs.ViewportFit.LETTERBOX:if(e===k){m=b;f=Math.floor(m/a);c=0;h=Math.floor(0.5*(this.frameHeight-f))}else{f=l;m=Math.floor(f*a);c=Math.floor(0.5*(this.frameWidth-m));h=0}break;case gs.ViewportFit.OVERSCAN:if(i===k){m=b;f=Math.floor(b/a);c=0;h=Math.floor(0.5*(this.frameHeight-f))}else{f=l;m=Math.floor(l*a);c=Math.floor(0.5*(this.frameWidth-m));h=0}break;default:gs.Log.error("Unrecognized viewport fit:",this.fit);break}this.resizeBuffer(m,f);this.resizeInput(m,f);this.resizeOverlay(m,f);gs.dom.repositionElement(this.input,c,h);gs.dom.repositionElement(this.drawBuffer.canvas,0,0);gs.dom.repositionElement(this.overlay,0,0)},updateGameSize:function(b,a){this.gameWidth=b;this.gameHeight=a;this.gameIsPortrait=(a>b);this.gameAspect=gs.AspectRatio.approximate(b,a)},updateWindowSize:function(b,a){this.windowWidth=b;this.windowHeight=a},updateFrameSize:function(){if(this.frame){var a=gs.dom.getComputedStyle(this.frame);if(a){this.frameWidth=parseInt(a.width,10);this.frameHeight=parseInt(a.height,10)}else{this.frameWidth=this.gameWidth;this.frameHeight=this.gameHeight}}},relayout:function(){switch(this.reference){case gs.ViewportReference.GAME:this.resizeFrame(this.gameWidth,this.gameHeight);this.refitBuffer(this.gameWidth,this.gameHeight);this.setReportSize(this.gameWidth,this.gameHeight);break;case gs.ViewportReference.FRAME:this.updateFrameSize();this.refitBuffer(this.frameWidth,this.frameHeight);if(this.shouldReportTrueSize()){this.setReportSize(this.frameWidth,this.frameHeight)}else{this.setReportSize(this.gameWidth,this.gameHeight)}break;case gs.ViewportReference.WINDOW:this.resizeFrame(this.windowWidth,this.windowHeight);this.refitBuffer(this.windowWidth,this.windowHeight);if(this.shouldReportTrueSize()){this.setReportSize(this.windowWidth,this.windowHeight)}else{this.setReportSize(this.gameWidth,this.gameHeight)}break;case gs.ViewportReference.SCREEN:this.screenWidth=window.screen.width;this.screenHeight=window.screen.height;var b=this.screenWidth/this.cssFactor;var a=this.screenHeight/this.cssFactor;this.resizeFrame(b,a);this.refitBuffer(b,a);if(this.shouldReportTrueSize()){this.setReportSize(this.screenWidth,this.screenHeight)}else{this.setReportSize(this.gameWidth,this.gameHeight)}break;default:gs.Log.error("Unrecognized viewport reference:",this.reference);break}},show:function(){if(this.drawBuffer.parentNode!==this.frame){this.drawBuffer.canvas.style.position="absolute";if(!gs.globalOptions.forceInputEventsOnCanvas){this.drawBuffer.canvas.style.pointerEvents="none"}this.drawBuffer.canvas.mozOpaque=true;this.input.style.position="absolute";this.input.style.backgroundColor="transparent";if(this.frame.hasChildNodes()){this.frame.insertBefore(this.input,this.frame.firstChild)}else{this.frame.appendChild(this.input)}this.input.appendChild(this.drawBuffer.canvas);this.overlay.style.position="absolute";this.overlay.style.pointerEvents="none";if(this.overlayCount>0){this.frame.appendChild(this.overlay)}}if(!this.overlayLayer){var a=document.getElementsByClassName("gse-overlay");if(a&&a.length>0){this.overlayLayer=a[0];if(this.overlayLayer){this.overlayParent=this.overlayLayer.parentNode;if(this.overlayRequestCount===0&&this.overlayParent){if(gs.globalOptions.useDynamicOverlayLayer){this.overlayParent.removeChild(this.overlayLayer)}}}}}},setZoom:function(a){this.zoom=a;this.frame.style.zoom=a},showOverlayLayer:function(){if(!gs.globalOptions.useDynamicOverlayLayer){return}this.overlayRequestCount++;if(this.overlayRequestCount===1&&this.overlayLayer&&this.overlayParent){this.overlayParent.appendChild(this.overlayLayer)}},hideOverlayLayer:function(){if(!gs.globalOptions.useDynamicOverlayLayer){return}if(this.overlayRequestCount>0){this.overlayRequestCount--}if(this.overlayRequestCount===0&&this.overlayLayer&&this.overlayParent){this.overlayParent.removeChild(this.overlayLayer)}}};gs.html5.text.Font=function(a,b){this.family=a;this.sizePx=b};gs.html5.text.Font.toCSS=function(a,b){return b.toString()+"px "+a};gs.html5.text.Font.prototype={toCSS:function(){return gs.html5.text.Font.toCSS(this.family,this.sizePx)}};gs.html5.text.FontPicker=function(){this.fontMap={};this.familyMap={};this.testBuffer=new gs.html5.GraphicsBuffer();this.testSizePx=20;this.testString="abcdefghijklmnopqrstuvwxyz 0123456789";this.fallbackFamily="sans-serif";var a="sans-serif";this.invalidWidth=this.measureTestWidth(a)};gs.html5.text.FontPicker.prototype={measureTestWidth:function(c){var a=this.testBuffer.context;a.font=gs.html5.text.Font.toCSS(c,this.testSizePx);var b=a.measureText(this.testString);return b.width},pickBestFont:function(c,f){var a=gs.html5.text.Font.toCSS(c,f);var b=this.fontMap[a];if(b){return b}var e=this.familyMap[c];if(e){b=new gs.html5.text.Font(e,f);this.fontMap[a]=b;return b}var d=this.measureTestWidth(c);if(d!==this.invalidWidth){b=new gs.html5.text.Font(c,f)}else{b=new gs.html5.text.Font(this.fallbackFamily,f)}this.fontMap[a]=b;this.familyMap[c]=b.family;return b}};gs.html5.Text={normalizeString:function(a){a=a.replace(/\\32/g," ");a=a.replace(/\r|\\r/g,"");a=a.replace(/\\n|\u2028|\u2029/g,"\n");a=a.replace(/\\t/g,"\t");return a}};gs.webgl={contextNames:["webgl","experimental-webgl"],contextOptions:{alpha:false,depth:false,stencil:false,antialias:false},supportedContextName:null,isSupported:function(){var a=gs.dom.createCanvas();var b=gs.webgl.getContext(a);return b!==null},getContext:function(a){if(gs.webgl.supportedContextName){return a.getContext(gs.webgl.supportedContextName)}var e=gs.webgl.contextNames;for(var c=0;c<e.length;++c){try{var d=a.getContext(e[c],gs.webgl.contextOptions);if(d){gs.webgl.supportedContextName=e[c];return d}}catch(b){}}return null},createTextureFromImage:function(e,d){var c=e.getParameter(e.ACTIVE_TEXTURE);e.activeTexture(c+1);var b=e.createTexture();try{e.bindTexture(e.TEXTURE_2D,b);e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,true);e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,true);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,d);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);b.previousWrapS=e.CLAMP_TO_EDGE;b.previousWrapT=e.CLAMP_TO_EDGE}catch(a){gs.Log.error(a)}e.activeTexture(c);return b},createTextureFromImageSize:function(e,d,c,a){var b=new gs.html5.GraphicsBuffer(c,a);b.context.drawImage(d,0,0,d.width,d.height,0,0,c,a);return this.createTextureFromImage(e,b.canvas)}};gs.html5.AccelerometerService=function(){this.game=null;this.gravity=9.80665;this.inverseGravity=1/this.gravity;this.orientation="portrait";this.rotateAxes=false;this.flipAxes=false;this.negateGravityXY=false;this.negateGravityZ=false;this.setRotateAxes(true);this.setNegateGravityZ(true)};gs.html5.AccelerometerService.instance=function(){return gs.util.lazySingleton(this)};gs.html5.AccelerometerService.onDeviceMotion=function(a){gs.platform.AccelerometerService.instance().onDeviceMotion(a)};gs.html5.AccelerometerService.prototype={init:function(a){this.game=a;window.addEventListener("devicemotion",gs.html5.AccelerometerService.onDeviceMotion)},setOrientation:function(a){this.orientation=a},setRotateAxes:function(a){this.rotateAxes=a},setFlipAxes:function(a){this.flipAxes=a},setNegateGravityXY:function(a){this.negateGravityXY=a},setNegateGravityZ:function(a){this.negateGravityZ=a},onDeviceMotion:function(a){this.setAccelerationV(a.accelerationIncludingGravity)},setAccelerationV:function(c){var e=this.game.devices.accelerometer;var b=c.x*this.inverseGravity;var g=c.y*this.inverseGravity;var f=c.z*this.inverseGravity;if(this.rotateAxes){var d=b;b=g;g=-d}if(this.flipAxes){b=-b;g=-g}if(this.negateGravityXY){b=-b;g=-g}if(this.negateGravityZ){f=-f}e.x.setValue(b);e.y.setValue(g);e.z.setValue(f)}};gs.html5.AnalyticsService=function(){var a=gs.api.ExternalDelegate.instance();this.sessionManager=new gs.analytics.SessionManager(a);this.currentSession=null};gs.html5.AnalyticsService.instance=function(){return gs.util.lazySingleton(this)};gs.html5.AnalyticsService.prototype={beginSession:function(){this.currentSession=this.sessionManager.openNewSession()},endSession:function(){this.currentSession.close()},trackSceneChange:function(a,b){this.beginSceneChange(a);this.endSceneChange(b)},beginSceneChange:function(a){this.currentSession.beginSceneChange(a)},endSceneChange:function(a){this.currentSession.endSceneChange(a)}};gs.html5.BrowserService=function(){};gs.html5.BrowserService.instance=function(){return gs.util.lazySingleton(this)};gs.html5.BrowserService.prototype={isInternalBrowserAllowed:function(a){return true},platformHasBlocker:function(){return true},openBrowser:function(b,a){var c=false;if(a){c=this.openInternalBrowser(b)}if(!c){this.openExternalBrowser(b)}},openInternalBrowser:function(a){try{gs.EngineContext.current.getRenderContext().viewport.showOverlayLayer();this.rootElement=gs.dom.getElement("gse-browser");this.browserFrame=gs.dom.getElement("gse-browser-frame");this.closeButton=gs.dom.getElement("gse-browser-close");var c=this;this.onCloseButtonClicked=function(){c.closeInternalBrowser()};this.closeButton.addEventListener("click",this.onCloseButtonClicked,false);gs.EngineContext.current.pause();this.browserFrame.src=a;gs.dom.setElementVisible(this.rootElement,true);return true}catch(b){gs.Log.warn(b);gs.Log.warn("Internal Browser dialog not available");return false}},closeInternalBrowser:function(){this.closeButton.removeEventListener("click",this.onCloseButtonClicked,false);gs.dom.setElementVisible(this.rootElement,false);gs.EngineContext.current.getRenderContext().viewport.hideOverlayLayer();gs.Game.current.clearTouchState();gs.EngineContext.current.unpause()},openExternalBrowser:function(a){function b(){window.removeEventListener("mouseup",b,false);window.removeEventListener("mousedown",b,false);window.open(a)}if(this.platformHasBlocker()){window.addEventListener("mouseup",b,false);window.addEventListener("mousedown",b,false)}else{window.open(a)}}};gs.html5.PurchaseService=function(){};gs.html5.PurchaseService.instance=function(){return gs.util.lazySingleton(this)};gs.html5.PurchaseService.prototype={purchaseItem:function(a){gs.Log.debug("PurchaseService.purchaseItem("+a+")");gs.Game.current.eventCenter.postEvent("InAppFailure")},restoreItems:function(){gs.Log.debug("PurchaseService.restoreItems()");var a=gs.array.provide();gs.Game.current.eventCenter.postEvent("InAppRestore",null,a)}};gs.html5.TextService=function(){};gs.html5.TextService.instance=function(){return gs.util.lazySingleton(this)};gs.html5.TextService.prototype={openTextPrompt:function(a,b,e){try{gs.EngineContext.current.getRenderContext().viewport.showOverlayLayer();this.rootElement=gs.dom.getElement("gse-text");this.textPrompt=gs.dom.getElement("gse-text-prompt");this.textInput=gs.dom.getElement("gse-text-input");this.doneButton=gs.dom.getElement("gse-text-done");this.cancelButton=gs.dom.getElement("gse-text-cancel");var d=this;this.onDoneButtonClicked=function(){d.closeTextPrompt();e&&e.call(null,d.textInput.value)};this.onCancelButtonClicked=function(){d.closeTextPrompt();e&&e.call(null,null)};this.doneButton.addEventListener("click",this.onDoneButtonClicked,false);this.cancelButton.addEventListener("click",this.onCancelButtonClicked,false);this.textPrompt.textContent=a;this.textInput.value=b;gs.dom.setElementVisible(this.rootElement,true);this.textInput.focus()}catch(c){gs.Log.warn(c);gs.Log.warn("Text Input dialog not available");e&&e.call(null,b)}},closeTextPrompt:function(){this.doneButton.removeEventListener("click",this.onDoneButtonClicked,false);this.cancelButton.removeEventListener("click",this.onCancelButtonClicked,false);gs.dom.setElementVisible(this.rootElement,false);gs.EngineContext.current.getRenderContext().viewport.hideOverlayLayer()}};gs.device={};gs.device.AccelerometerService=gs.html5.AccelerometerService;gs.device.AnalyticsService=function(){this.sessionManager=new gs.analytics.SessionManager();this.sessionManager.enableUploading();this.currentSession=null};gs.device.AnalyticsService.instance=function(){return gs.util.lazySingleton(this)};gs.device.AnalyticsService.prototype={beginSession:function(){this.sessionManager.flush();this.currentSession=this.sessionManager.openNewSession()},endSession:function(){this.currentSession.close()},trackSceneChange:function(a,b){this.beginSceneChange(a);this.endSceneChange(b)},beginSceneChange:function(a){this.currentSession.beginSceneChange(a)},endSceneChange:function(a){this.currentSession.endSceneChange(a)}};gs.device.BrowserService=gs.html5.BrowserService;gs.device.TextService=gs.html5.TextService;gs.firefox={};gs.firefox.AccelerometerService=gs.device.AccelerometerService;gs.firefox.AnalyticsService=gs.device.AnalyticsService;gs.firefox.BrowserService=function(){};gs.firefox.BrowserService.instance=function(){return gs.util.lazySingleton(this)};gs.firefox.BrowserService.prototype={isInternalBrowserAllowed:function(a){return false},openInternalBrowser:function(a){gs.Log.error("Not Implemented")},openExternalBrowser:function(a){gs.EngineContext.current.delegate.onBrowserOpen(a)}};gs.firefox.TextService=gs.device.TextService;gs.tizen={};gs.tizen.AccelerometerService=function(){gs.html5.AccelerometerService.call(this);this.setRotateAxes(false);this.setNegateGravityXY(true);this.setNegateGravityZ(true)};gs.tizen.AccelerometerService.instance=function(){return gs.util.lazySingleton(this)};gs.tizen.AccelerometerService.prototype={};gs.inherits(gs.tizen.AccelerometerService,gs.html5.AccelerometerService);gs.tizen.AnalyticsService=gs.device.AnalyticsService;gs.tizen.BrowserService=function(){};gs.tizen.BrowserService.instance=function(){return gs.util.lazySingleton(this)};gs.tizen.BrowserService.prototype={isInternalBrowserAllowed:function(a){return false},openInternalBrowser:function(a){gs.Log.error("Not Implemented")},openExternalBrowser:function(a){gs.EngineContext.current.delegate.onBrowserOpen(a)}};gs.inherits(gs.tizen.BrowserService,gs.device.BrowserService);gs.tizen.PurchaseService=function(){this.nextTransactionId=1;this.mode=0;this.mcc="";this.mnc="";this.deviceModel="";this.delimiter=":"};gs.tizen.PurchaseService.instance=function(){return gs.util.lazySingleton(this)};gs.tizen.PurchaseService.prototype={purchaseItem:function(d){var b=undefined;var a=d.split(this.delimiter);if(a.length==2){b=a[0];d=a[1]}var c={};c._mode=this.mode;c._itemId=d;c._itemGroupId=b;c._transactionId=this.nextTransactionId++;this.requestPurchaseItem(c)},restoreItems:function(a){var c=undefined;var b=a[0].split(this.delimiter);if(b.length==2){c=b[0]}var d={};d._mode=this.mode;d._transactionId=this.nextTransactionId++;d._itemGroupId=c;this.requestPurchasedItemInformationList(d,0,9999)},requestPurchaseItem:function(b){var a=[new tizen.ApplicationControlData("_mode",[b._mode]),new tizen.ApplicationControlData("_itemId",[b._itemId]),new tizen.ApplicationControlData("_itemGroupId",[b._itemGroupId]),new tizen.ApplicationControlData("_transactionId",[b._transactionId])];this.sendAppControl("http://tizen.org/appcontrol/operation/iap/purchase","tizeninapp.IapClient",a,this)},requestPurchasedItemInformationList:function(c,d,a){var b=[new tizen.ApplicationControlData("_mode",[c._mode]),new tizen.ApplicationControlData("_transactionId",[c._transactionId]),new tizen.ApplicationControlData("_startNumber",[d]),new tizen.ApplicationControlData("_endNumber",[a]),new tizen.ApplicationControlData("_itemGroupId",[c._itemGroupId])];this.sendAppControl("http://tizen.org/appcontrol/operation/iap/get_purchased_item_list","tizeninapp.IapService",b,this)},sendAppControl:function(a,e,c,d){var b=new tizen.ApplicationControl(a,null,null,null,c);tizen.application.launchAppControl(b,e,function(){gs.Log.debug("success")},function(){gs.Log.debug("fail")},d)},onPurchaseItemInitialized:function(c){var a=parseInt(c._result,10);switch(a){case 0:var b=[new tizen.ApplicationControlData("_transactionId",[c._transactionId]),new tizen.ApplicationControlData("_purchaseResume",[1]),new tizen.ApplicationControlData("_itemId",[c._itemId]),new tizen.ApplicationControlData("_ticketPurchaseId",[c._ticketPurchaseId]),new tizen.ApplicationControlData("_ticketVerifyUrl",[c._ticketVerifyUrl]),new tizen.ApplicationControlData("_ticketParam1",[c._ticketParam1]),new tizen.ApplicationControlData("_ticketParam2",[c._ticketParam2]),new tizen.ApplicationControlData("__ticketParam3",[c._ticketParam3])];this.sendAppControl("http://tizen.org/appcontrol/operation/iap/purchase","tizeninapp.IapClient",b,this);break;case 100:gs.Game.current.eventCenter.postEvent("InAppCancelled");break;default:gs.Log.error(a);gs.Game.current.eventCenter.postEvent("InAppFailure");break}},onPurchaseItemFinished:function(b){var a=parseInt(b._result,10);switch(a){case 0:gs.Game.current.eventCenter.postEvent("InAppSuccess");break;case 100:gs.Game.current.eventCenter.postEvent("InAppCancelled");break;default:gs.Log.error(a);gs.Game.current.eventCenter.postEvent("InAppFailure");break}},onPurchasedItemInformationListReceived:function(c){var b=parseInt(c._result,10);switch(b){case 0:var a=this.parsePurchasedItemIds(c);gs.Game.current.eventCenter.postEvent("InAppRestore",null,a);break;default:gs.Log.error(b);gs.Game.current.eventCenter.postEvent("InAppFailure");break}},parsePurchasedItemIds:function(e){var b=gs.array.provide();var f=parseInt(e._startNumber,10);var a=parseInt(e._endNumber,10);for(var d=f;d<=a;d++){var c=e[d+"_itemGroupId"];var g=e[d+"_itemId"];b.push(c+this.delimiter+g)}return b},onsuccess:function(c){var a=gs.tizen.PurchaseService.instance();if(c!=null){var d={};for(var b=0;b<c.length;b++){d[c[b].key]=c[b].value}var e=d._method;"";if(e==="OnPurchaseItemInitialized"){gs.Log.debug(e);a.onPurchaseItemInitialized(d)}else{if(e==="OnPurchaseItemFinished"){gs.Log.debug(e);a.onPurchaseItemFinished(d)}else{if(e==="OnItemInformationListReceived"){gs.Log.debug(e);a.onItemInformationListReceived(d)}else{if(e==="OnPurchasedItemInformationListReceived"){gs.Log.debug(e);a.onPurchasedItemInformationListReceived(d)}else{if(e==="OnCountryListReceived"){gs.Log.debug(e);a.onCountryListReceived(d)}else{gs.Log.debug("error: "+e)}}}}}}},onfailure:function(){gs.Log.debug("onfailure");gs.Game.current.eventCenter.postEvent("InAppFailure")}};gs.tizen.TextService=gs.device.TextService;gs.winjs={};gs.winjs.AccelerometerService=function(){gs.html5.AccelerometerService.call(this);this.accelerometer=null;this.a={x:0,y:0,z:0};this.setRotateAxes(true);this.setNegateGravityXY(false);this.setNegateGravityZ(false)};gs.winjs.AccelerometerService.instance=function(){return gs.util.lazySingleton(this)};gs.winjs.AccelerometerService.onReadingChanged=function(a){gs.platform.AccelerometerService.instance().onReadingChanged(a)};gs.winjs.AccelerometerService.prototype={init:function(a){this.game=a;try{this.accelerometer=Windows.Devices.Sensors.Accelerometer.getDefault();if(this.accelerometer){var c=this.accelerometer.minimumReportInterval;var d=c>16?c:16;this.accelerometer.reportInterval=d;this.accelerometer.addEventListener("readingchanged",gs.winjs.AccelerometerService.onReadingChanged)}}catch(b){gs.Log.error(b)}},onReadingChanged:function(a){this.a.x=a.reading.accelerationX*this.gravity;this.a.y=a.reading.accelerationY*this.gravity;this.a.z=a.reading.accelerationZ*this.gravity;this.setAccelerationV(this.a)}};gs.inherits(gs.winjs.AccelerometerService,gs.html5.AccelerometerService);gs.winjs.AnalyticsService=gs.device.AnalyticsService;gs.winjs.BrowserService=function(){};gs.winjs.BrowserService.instance=function(){return gs.util.lazySingleton(this)};gs.winjs.BrowserService.prototype={platformHasBlocker:function(){return false}};gs.inherits(gs.winjs.BrowserService,gs.html5.BrowserService);gs.winjs.TextService=gs.device.TextService;if(typeof WinJS!=="undefined"){gs.platform=gs.winjs;gs.globalOptions.forcePointerEvents=true;gs.globalOptions.forceInputEventsOnCanvas=true}else{if(typeof tizen!=="undefined"){gs.platform=gs.tizen;gs.globalOptions.forceTexturePrimeFrames=20;gs.globalOptions.forceViewportOrientationMatch=true}else{if(typeof MozActivity!=="undefined"){gs.platform=gs.firefox}else{gs.platform=gs.html5;var userAgent=navigator.userAgent;if(/MSIE/.test(userAgent)){gs.globalOptions.forceInputEventsOnCanvas=true}}}}gs.GameLoop=function(a){this.isRunning=false;this.isSpinning=false;this.callback=null;this.element=null;this.requestID=null;this.intervalID=null;this.intervalMS=a!==0?Math.floor(1000/a):16;this.useRequestAnimationFrame=a!==0?false:(typeof window.requestAnimationFrame==="function");gs.GameLoop.instance=this};gs.GameLoop.instance=null;gs.GameLoop.tick=function(){gs.GameLoop.instance.tick()};gs.GameLoop.prototype={start:function(){this.isRunning=true;if(!this.isSpinning){if(this.useRequestAnimationFrame){this.requestID=window.requestAnimationFrame(gs.GameLoop.tick,this.element)}else{this.intervalID=window.setInterval(gs.GameLoop.tick,this.intervalMS)}this.isSpinning=true}},stop:function(){this.isRunning=false;this.isSpinning=false;if(this.requestID){window.cancelAnimationFrame(this.requestID);this.requestID=null}if(this.intervalID){window.clearInterval(this.intervalID)}},tick:function(){this.requestID=null;if(this.isSpinning&&this.useRequestAnimationFrame){this.requestID=window.requestAnimationFrame(gs.GameLoop.tick,this.element)}if(this.isRunning){try{this.callback&&this.callback.call(null)}catch(a){gs.Log.error(a)}}},setCallback:function(a){this.callback=a},setDOMElement:function(a){this.element=a}};gs.JXON={_type:"@",_text:"$",_children:"#",detect:function(a){if(a&&a["@"]){gs.JXON._type="@";gs.JXON._text="$";gs.JXON._children="#"}else{gs.JXON._type="_type";gs.JXON._text="_text";gs.JXON._children="_children"}},tag:function(a){return a[gs.JXON._type]},content:function(a){return a[gs.JXON._text]},id:function(a){return a.id},children:function(a){return a[gs.JXON._children]},childrenWithTag:function(d,b){var a=[];var c=gs.JXON.children(d);if(c){c.forEach(function(e){if(gs.JXON.tag(e)===b){a.push(e)}})}return a},childWithTag:function(c,a){var b=gs.JXON.childrenWithTag(c,a);return b.length>0?b[0]:undefined},childWithID:function(d,c){var a=undefined;var b=gs.JXON.children(d);if(b){b.forEach(function(e){if(gs.JXON.id(e)===c){a=e}})}return a}};gs.PGF={attributes:function(b){var a=gs.JXON.childWithTag(b,"attributes");if(!a){return undefined}return gs.JXON.children(a)},attributesWithType:function(d,c){var b=[];var a=gs.PGF.attributes(d);if(a){a.forEach(function(e){if(gs.JXON.tag(e)===c){b.push(e)}})}return b},attributeWithID:function(d,c){var a=null;var b=gs.PGF.attributes(d);if(b){b.forEach(function(e){if(gs.JXON.id(e)===c){a=e}})}return a}};gs.XML={parse:function(b){gs.JXON.detect(b);var a=gs.XML.XMLStringToJXON(b);return gs.Prototypical.convertJXONLite(a)},XMLStringToJXON:function(b){var a=gs.XML.XMLStringToPlatformXML(b);return gs.XML.platformXMLToJXON(a)},XMLStringToPlatformXML:function(a){var e=new DOMParser();var d="text/xml";var b=e.parseFromString(a,d);var c=b.childNodes.item(0);return c},platformXMLToJXON:function(e){var f={},d,j,a;f[gs.JXON._type]=e.nodeName;Array.prototype.forEach.call(e.attributes,function(k){var i=k.nodeName;f[i]=k.nodeValue},gs.XML);var g=e.childNodes.length;if(g===0){f[gs.JXON._text]="";f[gs.JXON._children]=[]}else{if(g===1){var h=e.firstChild;if(h.nodeType===Node.TEXT_NODE){f[gs.JXON._text]=String(h.nodeValue);return f}}f._children=[];var c=0;for(d=0;d<g;d++){a=gs.XML.getChildNode(e,d);if(a.nodeType===Node.ELEMENT_NODE){c++;j=a.nodeName;var b=gs.XML.platformXMLToJXON(a);f[gs.JXON._children].push(b)}}if(c===0){delete f[gs.JXON._children]}}return f},getChildNode:function(b,a){return NodeList.prototype.item.call(b.childNodes,a)}};gs.Prototypical={convertJXONLite:function(d,c){var a=d._type;var b=d._children;var f=(b&&b.length>0);var e=d.hasOwnProperty("name");switch(a){case"scenes":case"actors":case"prototypes":case"layers":case"images":case"sounds":case"behaviors":case"elseBehaviors":case"conditions":case"expression":case"tags":case"rows":case"columns":case"array":return gs.Prototypical.convertJXONLiteList(d,c);case"aspects":case"graphics":case"motion":case"physics":return gs.Prototypical.convertJXONLiteMap(d,c);case"info":case"game":case"scene":case"assets":return gs.Prototypical.convertJXONLiteEntity(d,c,true);case"layer":case"actor":case"behavior":case"condition":case"file":case"reference":case"row":case"column":case"pair":return gs.Prototypical.convertJXONLiteEntity(d,c,false);case"image":case"sound":case"music":if(f||e){return gs.Prototypical.convertJXONLiteAsset(d,c)}else{return gs.Prototypical.convertJXONLiteOther(d,c)}case"string":return gs.Prototypical.convertJXONLiteString(d,c);case"plugins":return d;case"attributes":if(d.id==="autorotate"){return gs.Prototypical.convertJXONLiteOther(d,c)}else{return gs.Prototypical.convertJXONLiteMap(d,c)}case"table":if(f){return gs.Prototypical.convertJXONLiteEntity(d,c)}else{return gs.Prototypical.convertJXONLiteOther(d,c)}case"predicate":case"subjectPredicate":return gs.Prototypical.convertJXONLitePredicate(d,c);default:return gs.Prototypical.convertJXONLiteOther(d,c)}},convertJXONLiteList:function(e,d){var a=e._type;var f=e.id;var b=e._children;if(b){if(a==="array"){d[f]=b}else{d[a]=b}for(var c=0;c<b.length;c++){b[c]=gs.Prototypical.convertJXONLite(b[c])}}else{d[a]=[]}return b},convertJXONLiteMap:function(e,d){var a=e._type;var b=e._children;var f={};d[a]=f;if(b&&b.length>0){for(var c=0;c<b.length;c++){gs.Prototypical.convertJXONLite(b[c],f)}}return f},convertJXONLiteString:function(b,a){return b._text},convertJXONLiteEntity:function(g,e,f){var a=g._type;delete g._type;if(f){g["@"]=a}if(a==="column"){var c=g._text;if(typeof c==="string"){c=gs.Prototypical.parseCSV(c)}g["$"]=c}delete g._text;var b=g._children;delete g._children;if(b){for(var d=0;d<b.length;d++){gs.Prototypical.convertJXONLite(b[d],g)}}return g},convertJXONLiteAsset:function(d,c){var a=d._children;delete d._type;delete d._children;delete d._text;if(a){d.files=a;for(var b=0;b<a.length;b++){a[b]=gs.Prototypical.convertJXONLite(a[b],d)}}else{d.files=[]}return d},convertJXONLitePredicate:function(e,d){var a=e._type;var b=e._children;delete e._type;delete e._children;delete e._text;d[a]=e;if(b){for(var c=0;c<b.length;c++){gs.Prototypical.convertJXONLite(b[c],e)}}return e},convertJXONLiteOther:function(e,j){var l=e._type;var c=e.id;var b=e._children;var d=(b&&b.length>0);var h=e._text;var f=(h!==undefined);var k=c||l;delete e._type;delete e.id;delete e._children;delete e._text;if(l==="tablecolumnassignment"){for(var g=0;g<b.length;g++){gs.Prototypical.convertJXONLite(b[g],e)}return e}if(d){j[k]=e;for(var g=0;g<b.length;g++){gs.Prototypical.convertJXONLite(b[g],e)}}else{var a=Object.keys(e).length;if(a===0){j[k]=gs.Prototypical.formatContent(h)}else{if(c){j[c]=e}e["@"]=l;if(f){e["$"]=gs.Prototypical.formatContent(h)}}}},formatContent:function(a){if(typeof a==="number"){if(isNaN(a)){return"nan"}if(a===Number.POSITIVE_INFINITY){return"inf"}if(a===Number.NEGATIVE_INFINITY){return"-inf"}}return a},parseCSV:function(e){var b=/\r\n|\r|\n/g;var k=",";var c="\\u002C";var h=/\\u002C/g;var n=e.split(b);for(var g in n){n[g]=n[g].replace(/\\,/g,c);for(var l=n[g].split(k),m=l.length-1,o;m>=0;m--){if(l[m].replace(/"\s+$/,'"').charAt(l[m].length-1)=='"'){if((o=l[m].replace(/^\s+"/,'"')).length>1&&o.charAt(0)=='"'){l[m]=l[m].replace(/^\s*"|"\s*$/g,"").replace(/""/g,'"')}else{if(m){l.splice(m-1,2,[l[m-1],l[m]].join(k))}else{l=l.shift().split(k).concat(l)}}}else{l[m]=l[m].replace(/""/g,'"')}}for(var d=0;d<l.length;d++){l[d]=l[d].replace(h,",")}n[g]=l}return n[0]}};gs.api.ExternalDelegate=function(){this.delegate=null};gs.api.ExternalDelegate.instance=function(){return gs.util.lazySingleton(this)};gs.api.ExternalDelegate.prototype={setDelegate:function(a){this.delegate=a},readExternalValueSync:function(a){if(!this.delegate){return null}return this.delegate.readExternalValueSync(a)},registerOptions:function(b,a){if(!this.delegate){return}this.delegate.registerOptions(b,a)}};gs.api.Delegate=function(){this.delegates=[]};gs.api.Delegate.prototype={appendDelegate:function(a){this.delegates.push(a)},onGameDimensionsKnown:function(b,a){return this.invoke("onGameDimensionsKnown",b,a)},onGameReady:function(){return this.invoke("onGameReady")},onCurrentSceneChanged:function(b,a){return this.invoke("onCurrentSceneChanged",b,a)},onLoadingBegin:function(){return this.invoke("onLoadingBegin")},onLoadingEnd:function(){return this.invoke("onLoadingEnd")},onTerminate:function(){return this.invoke("onTerminate")},onFrameRendered:function(){return this.invoke("onFrameRendered")},onProfilerFrame:function(d,c,b,a){return this.invoke("onProfilerFrame",d,c,b,a)},onExternalReadSync:function(a){return this.invoke("onExternalReadSync",a)},onBrowserOpen:function(a){return this.invoke("onBrowserOpen",a)},onShowBannerShow:function(a){return this.invoke("onShowBannerShow",a)},onShowBannerHide:function(){return this.invoke("onShowBannerHide")},onShowMoreGames:function(){return this.invoke("onShowMoreGames")},onLaunchService:function(a){return this.invoke("onLaunchService",a)},onGameCenterLogin:function(){return this.invoke("onGameCenterLogin")},onGameCenterPostScore:function(){return this.invoke("onGameCenterPostScore")},onGameCenterShowLeaderboard:function(){return this.invoke("onGameCenterShowLeaderboard")},onGameCenterShowAchievements:function(){return this.invoke("onGameCenterShowAchievements")},onGameCenterResetAchievements:function(){return this.invoke("onGameCenterResetAchievements")},onGameCenterUpdateAchievement:function(){return this.invoke("onGameCenterUpdateAchievement")},onTweetSheet:function(a){return this.invoke("onTweetSheet",a)},onLogDebuggingStatement:function(b,a){return this.invoke("onLogDebuggingStatement",b,a)},onLogDebug:function(a){return this.invoke("onLogDebug",a)},onLogInfo:function(a){return this.invoke("onLogInfo",a)},onLogWarn:function(a){return this.invoke("onLogWarn",a)},onLogStrict:function(a){return this.invoke("onLogStrict",a)},onLogError:function(a){return this.invoke("onLogError",a)},onLogFatal:function(a){return this.invoke("onLogFatal",a)},onLogAll:function(a){return this.invoke("onLogAll",a)},invoke:function(a){var f=0,g=this.delegates,e=this.delegates.length,m=null;var k=undefined;var b=undefined;var h=arguments.length-1;switch(h){case 0:for(;f<e;++f){m=g[f];if(typeof m[a]==="function"){try{b=m[a]()}catch(d){}if(b!==undefined){k=b}}}break;case 1:var n=arguments[1];for(;f<e;++f){m=g[f];if(typeof m[a]==="function"){try{b=m[a](n)}catch(d){}if(b!==undefined){k=b}}}break;case 2:var l=arguments[1];var j=arguments[2];for(;f<e;++f){m=g[f];if(typeof m[a]==="function"){try{b=m[a](l,j)}catch(d){}if(b!==undefined){k=b}}}break;default:var c=[];for(;f<h;f++){c.push(arguments[f+1])}for(f=0;f<e;++f){m=g[f];if(typeof m[a]==="function"){try{b=m[a].apply(m,c)}catch(d){}if(b!==undefined){k=b}}}break}return k}};gs.LegacyDelegate={getListeners:function(a,b){if(!this.actionListeners){this.actionListeners={}}if(!this.actionListeners[a]){this.actionListeners[a]={}}if(!this.actionListeners[a][b]){this.actionListeners[a][b]=[]}return this.actionListeners[a][b]},addActionListener:function(a,c,b){gs.Log.strict("registered legacy action listener:",a,c);this.getListeners(a,c).push(b)},dispatchAction:function(f,g,b){var e=this.getListeners(f,g);for(var d=0,a=e.length;d<a;d++){try{e[d].call(null,b)}catch(c){gs.Log.error(c)}}},onGameDimensionsKnown:function(b,a){this.dispatchAction("screen","size",{width:b,height:a})},onCurrentSceneChanged:function(b,a){this.dispatchAction("scene","start",{id:b,name:a})},onProfilerFrame:function(f,e,a,d){this.dispatchAction("profiler","frame",f);this.dispatchAction("profiler","entities",e);this.dispatchAction("profiler","game",a);this.dispatchAction("profiler","scene",d);var b=f.frame||16;var c=1000/b;this.dispatchAction("debug","updateFPS",c)},onBannerShow:function(a){this.dispatchAction("showBanner","show",{position:a})},onBannerHide:function(){this.dispatchAction("showBanner","hide",null)},onLaunchService:function(a){this.dispatchAction("launchService","launchService",{page:a})},onGameCenterLogin:function(){this.dispatchAction("GameCenter","login",null)},onGameCenterPostScore:function(){this.dispatchAction("GameCenter","postScore",null)},onGameCenterShowLeaderboard:function(){this.dispatchAction("GameCenter","showLeaderboard",null)},onGameCenterShowAchievements:function(){this.dispatchAction("GameCenter","showAchievements",null)},onGameCenterResetAchievements:function(){this.dispatchAction("GameCenter","resetAchievements",null)},onGameCenterUpdateAchievement:function(){this.dispatchAction("GameCenter","updateAchievement",null)},onTweetSheet:function(a){this.dispatchAction("Twitter","tweetSheet",null)}};gs.LogVisualizer=function(){this.root=null;this.createDOM()};gs.LogVisualizer.prototype={createDOM:function(){this.root=gs.dom.create("DIV");this.root.className="gse-debug gse-log"},append:function(a,b){var c=gs.dom.create("P");c.textContent=a;if(b){c.style.color=b}this.root.appendChild(c)},onLogAll:function(a){this.append(a)}};gs.PerformanceCounter=function(){this.count=0};gs.PerformanceCounter.prototype={getReading:function(){return this.count},reset:function(){this.count=0},set:function(a){this.count=a},add:function(a){this.count+=a},increment:function(){this.count++}};gs.PerformanceTimer=function(c,a){if(a===undefined){a=0}this.timeProvider=(window.performance&&window.performance.now)?window.performance:Date;this.count=c;this.sum=a*this.count;this.average=a;this.index=0;this.enterTime=this.getTime();this.exitTime=this.getTime();this.buffer=[];for(var b=0;b<this.count;b++){this.buffer[b]=a}};gs.PerformanceTimer.prototype={getReading:function(){this.average=this.sum/this.count;return this.average},getTime:function(){return this.timeProvider.now()},enter:function(){this.enterTime=this.getTime()},exit:function(){this.exitTime=this.getTime();var a=this.exitTime-this.enterTime;this.sum-=this.buffer[this.index];this.sum+=a;this.buffer[this.index]=a;this.index=(this.index+1)%this.count},tick:function(){this.exit();this.enter()}};gs.FrameProfiler=function(){var a=60;this.frame=new gs.PerformanceTimer(a,1000/60);this.engine=new gs.PerformanceTimer(a,1000/100);this.simulate=new gs.PerformanceTimer(a,1);this.physics=new gs.PerformanceTimer(a,1);this.render=new gs.PerformanceTimer(a,1);this.profile=new gs.PerformanceTimer(a,1);this.input=new gs.PerformanceTimer(a,1);this.reading={frame:0,engine:0,simulate:0,physics:0,render:0,profile:0,input:0};this.getReading()};gs.FrameProfiler.prototype={getReading:function(){this.reading.frame=this.frame.getReading();this.reading.engine=this.engine.getReading();this.reading.simulate=this.simulate.getReading();this.reading.physics=this.physics.getReading();this.reading.render=this.render.getReading();this.reading.profile=this.profile.getReading();this.reading.input=this.input.getReading();return this.reading}};gs.EntityCounter=function(){this.layers=new gs.PerformanceCounter();this.actors=new gs.PerformanceCounter();this.sprites=new gs.PerformanceCounter();this.particles=new gs.PerformanceCounter();this.textures=new gs.PerformanceCounter();this.awake=new gs.PerformanceCounter();this.contacts=new gs.PerformanceCounter();this.reading={layers:0,actors:0,sprites:0,particles:0,textures:0,awake:0,contacts:0};this.getReading()};gs.EntityCounter.prototype={reset:function(){this.layers.reset();this.actors.reset();this.sprites.reset();this.particles.reset();this.textures.reset();this.awake.reset();this.contacts.reset()},getReading:function(){this.reading.layers=this.layers.getReading();this.reading.actors=this.actors.getReading();this.reading.sprites=this.sprites.getReading();this.reading.particles=this.particles.getReading();this.reading.textures=this.textures.getReading();this.reading.awake=this.awake.getReading();this.reading.contacts=this.contacts.getReading();return this.reading}};gs.LoadProfiler=function(){this.time=new gs.PerformanceTimer(1);this.load=new gs.PerformanceTimer(1);this.parse=new gs.PerformanceTimer(1);this.assets=new gs.PerformanceTimer(1);this.images=new gs.PerformanceCounter();this.sounds=new gs.PerformanceCounter();this.reading={time:0,load:0,parse:0,assets:0,images:0,sounds:0};this.getReading()};gs.LoadProfiler.prototype={reset:function(){this.images.reset();this.sounds.reset()},getReading:function(){this.reading.time=this.time.getReading();this.reading.load=this.load.getReading();this.reading.parse=this.parse.getReading();this.reading.assets=this.assets.getReading();this.reading.images=this.images.getReading();this.reading.sounds=this.sounds.getReading();return this.reading}};gs.FrameRateVisualizer=function(){this.root=null;this.span=null;this.trueDeltaMS=1;this.deltaMS=1;this.hitchMS=0;this.hitchCounter=0;this.didDraw=false;this.createDOM()};gs.FrameRateVisualizer.prototype={createDOM:function(){this.root=gs.dom.create("DIV");this.root.className="gse-debug gse-profiler";this.span=gs.dom.create("SPAN");this.root.appendChild(this.span)},onProfilerFrame:function(f,e,b,a){var c="";var d=f.frame;if(this.hitchCounter<=0&&d<18){if(this.didDraw){this.span.textContent="";this.didDraw=false}this.hitchMS=0;return}if(this.hitchCounter>0){this.hitchCounter--;c+="-"+this.hitchMS.toFixed(0)+"! "}else{this.hitchMS=0}c+=this.trueDeltaMS.toFixed(0)+" "+this.deltaMS.toFixed(0)+" "+d.toFixed(1);this.span.textContent=c;this.didDraw=true},hitch:function(a,b){this.hitchMS+=a;this.hitchCounter=Math.floor((b/1000)*60)}};gs.ProfilerVisualizer=function(){this.setEntityProfilerRowMax={};this.setProfilerCellCache={};this.frameCount=0;this.root=null;this.frame=null;this.counters=null;this.createDOM()};gs.ProfilerVisualizer.prototype={createDOM:function(){this.root=gs.dom.create("DIV");this.root.className="gse-debug gse-profiler";this.frame=this.createTable("frame","1/s","ms","%");this.addRow(this.frame,"frame");this.addRow(this.frame,"- engine");this.addRow(this.frame,"-- evaluate");this.addRow(this.frame,"-- physics");this.addRow(this.frame,"-- render");this.addRow(this.frame,"- profile");this.addRow(this.frame,"- idle");this.addRow(this.frame,"input");this.root.appendChild(this.frame);this.counters=this.createTable("counters","now","max");this.addRow(this.counters,"layers");this.addRow(this.counters,"actors");this.addRow(this.counters,"sprites");this.addRow(this.counters,"particles");this.addRow(this.counters,"textures");this.addRow(this.counters,"awake");this.addRow(this.counters,"contacts");this.root.appendChild(this.counters)},createTable:function(f){var d=gs.dom.create("TABLE");d.gseColumnCount=arguments.length;d.gseRows=[];var a=gs.dom.create("CAPTION");a.textContent=f;d.appendChild(a);var e=gs.dom.create("TR");e.gseCells=[];var c=gs.dom.create("TH");c.textContent=" ";e.appendChild(c);e.gseCells.push(c);for(var b=1;b<arguments.length;b++){c=gs.dom.create("TH");c.textContent=arguments[b];e.appendChild(c);e.gseCells.push(c)}d.appendChild(e);d.gseRows.push(e);return d},addRow:function(c,a){var d=gs.dom.create("TR");d.gseCells=[];var e=gs.dom.create("TD");e.textContent=a;d.appendChild(e);d.gseCells.push(e);for(var b=1;b<c.gseColumnCount;b++){e=gs.dom.create("TD");d.appendChild(e);d.gseCells.push(e);if(arguments[b+1]){th.textContent=arguments[b+1]}}c.appendChild(d);c.gseRows.push(d)},setCell:function(e,d,f,b){var a=e.gseRows[d].gseCells[f];a.textContent=b},setProfilerCell:function(d,a,g){var f=this.setProfilerCellCache[d];if(!f){f=[];this.setProfilerCellCache[d]=f}var b=f[a];if(!b){b={previous:"",map:{},element:null};f[a]=b}if(g===b.previous){return}var e=b.map[g];if(!e){e=document.createTextNode(g);b.map[g]=e}b.previous=g;if(!b.element){var c=null;$("#developer-profiler tr").each(function(){if(c){return}if($(this).attr("data-field")===d){c=$(this)[0]}});b.element=$(c).find("td")[a]}var h=b.element;if(h.firstChild){h.replaceChild(e,h.firstChild)}else{h.appendChild(e)}},setFrameProfilerRow:function(d,f,a,e){var g=a===0?0:1000/a;if(d==="frame"){this.setCell(this.frame,f,1,Math.ceil(g).toString())}else{if(d==="engine"){var c=Math.ceil(g).toString();if(g>99){c="99"}this.setCell(this.frame,f,1,c)}}var b=e===0?0:a/e;this.setCell(this.frame,f,2,a.toFixed(1));this.setCell(this.frame,f,3,Math.ceil(100*b).toString())},setEntityProfilerRow:function(c,d,b){var a=this.setEntityProfilerRowMax[c];if(a===undefined||a<b){a=b;this.setEntityProfilerRowMax[c]=a}this.setCell(this.counters,d,1,b);this.setCell(this.counters,d,2,a)},setSceneProfilerTimerRow:function(c,a,d){var b=d===0?0:a/d;this.setProfilerCell(c,1,a.toFixed(0));this.setProfilerCell(c,2,Math.ceil(100*b).toString())},setGameProfilerTimerRow:function(c,a,d){var b=d===0?0:a/d;this.setProfilerCell(c,1,a.toFixed(0));this.setProfilerCell(c,2,Math.ceil(100*b).toString())},setSceneProfilerCounterRow:function(b,a){this.setProfilerCell(b,1,a.toFixed(0))},onProfilerFrame:function(f,e,b,a){var d=1;this.setEntityProfilerRow("layers",d++,e.layers);this.setEntityProfilerRow("actors",d++,e.actors);this.setEntityProfilerRow("sprites",d++,e.sprites);this.setEntityProfilerRow("particles",d++,e.particles);this.setEntityProfilerRow("textures",d++,e.textures);this.setEntityProfilerRow("awake",d++,e.awake);this.setEntityProfilerRow("contacts",d++,e.contacts);if(this.frameCount++%5!==0){return}d=1;this.setFrameProfilerRow("frame",d++,f.frame,f.frame);this.setFrameProfilerRow("engine",d++,f.engine,f.frame);this.setFrameProfilerRow("evaluate",d++,f.simulate,f.frame);this.setFrameProfilerRow("physics",d++,f.physics,f.frame);this.setFrameProfilerRow("render",d++,f.render,f.frame);this.setFrameProfilerRow("profile",d++,f.profile,f.frame);var c=f.frame-f.engine-f.profile;this.setFrameProfilerRow("idle",d++,c,f.frame);this.setFrameProfilerRow("input",d++,f.input,f.frame)}};gs.analytics.DataType={HEADER:"h",ATTRIBUTES:"a",SESSION_OPEN:"s",SESSION_CLOSE:"c",EVENT:"e",UNKNOWN:"x"};gs.analytics.Attribute={DATA_TYPE:"dt",LIBRARY_VERSION:"lv",APP_UNIQUE_KEY:"au",APP_DISPLAY_NAME:"adn",APP_VERSION:"av",APP_DEVELOPER_ID:"devid",APP_UNIQUE_ID:"APP_UNIQUE_ID",APP_CREATOR_VERSION:"pcv",APP_RELEASE_ID:"ari",APP_LICENSE_TYPE:"alt",APP_INSTALL_ID:"iu",APP_DEVELOPER_USERNAME:"devun",DEVICE_UNIQUE_ID:"du",DEVICE_UNIQUE_ID_HASH:"udid",DEVICE_PLATFORM:"dp",DEVICE_OS_VERSION:"dov",DEVICE_COUNTRY:"dc",DEVICE_LOCALE_LANGUAGE:"dll",DEVICE_LOCALE_COUNTRY:"dlc",PREVIOUS_SCENE:"ps",NEXT_SCENE:"ns",UNKNOWN:""};gs.analytics.EventName={SCENE_CHANGE:"sceneChange"};gs.analytics.Blob=function(a){this["dt"]=a;this["u"]=gs.util.generateUUID();this["ct"]=gs.util.getSecondsSinceUnixEpoch()};gs.analytics.Blob.prototype={setAttribute:function(a,b){if(!this["attrs"]){this["attrs"]={dt:gs.analytics.DataType.ATTRIBUTES}}this["attrs"][a]=b}};gs.analytics.Header=function(a,b){gs.analytics.Blob.call(this,gs.analytics.DataType.HEADER);this["seq"]=a;this["pa"]=b;this.setAttribute(gs.analytics.Attribute.LIBRARY_VERSION,gs.analytics.Header.Constants.LIBRARY_VERSION)};gs.analytics.Header.Constants={LIBRARY_VERSION:"html5_1.0"};gs.analytics.Header.prototype=Object.create(gs.analytics.Blob.prototype,{});gs.analytics.SessionBlob=function(a,b){gs.analytics.Blob.call(this,a);this["su"]=b};gs.analytics.SessionBlob.prototype=Object.create(gs.analytics.Blob.prototype,{});gs.analytics.SessionOpen=function(a,b){gs.analytics.Blob.call(this,gs.analytics.DataType.SESSION_OPEN);this["u"]=a;this["nth"]=b};gs.analytics.SessionOpen.prototype=Object.create(gs.analytics.Blob.prototype,{});gs.analytics.SessionClose=function(b,a){gs.analytics.SessionBlob.call(this,gs.analytics.DataType.SESSION_CLOSE,b);this["ctl"]=a};gs.analytics.SessionClose.prototype=Object.create(gs.analytics.SessionBlob.prototype,{});gs.analytics.Event=function(b,a){gs.analytics.SessionBlob.call(this,gs.analytics.DataType.EVENT,b);this["n"]=a};gs.analytics.Event.prototype=Object.create(gs.analytics.SessionBlob.prototype,{});gs.analytics.Session=function(b,a){this.sessionIndex=b;this.sessionManager=a;this.blobs=[];this.sessionUUID=gs.util.generateUUID();this.isOpen=false;this.openTime=null;this.closeTime=null;this.unloadEventListener=null;this.previousScene=gs.analytics.Session.Constants.NO_SCENE};gs.analytics.Session.Constants={NO_SCENE:" "};gs.analytics.Session.prototype={open:function(){if(!this.isOpen){this.isOpen=true;this.openTime=gs.util.getSecondsSinceUnixEpoch();this.appendSessionOpen();var a=this;this.unloadEventListener=window.addEventListener("unload",function(b){a.close()},false)}},close:function(){if(this.isOpen){this.closeTime=gs.util.getSecondsSinceUnixEpoch();this.appendSessionClose();this.isOpen=false;window.removeEventListener("unload",this.unloadEventListener,false);this.unloadEventListener=null;this.sessionManager.appendSession(this)}},appendBlob:function(a){this.blobs.push(a)},appendSessionOpen:function(){var a=new gs.analytics.SessionOpen(this.sessionUUID,this.sessionIndex);this.appendBlob(a)},appendSessionClose:function(){var b=this.closeTime-this.openTime;var a=new gs.analytics.SessionClose(this.sessionUUID,b);this.appendBlob(a)},newEvent:function(b){var a=new gs.analytics.Event(this.sessionUUID,b);a[gs.analytics.Attribute.APP_UNIQUE_KEY]=this.sessionManager.getAppUniqueKey();return a},beginSceneChange:function(a){if(a!==null){this.previousScene=a}else{this.previousScene=gs.analytics.Session.Constants.NO_SCENE}},endSceneChange:function(b){var a=gs.analytics.Attribute;var c=this.newEvent(gs.analytics.EventName.SCENE_CHANGE);c.setAttribute(a.PREVIOUS_SCENE,this.previousScene);c.setAttribute(a.NEXT_SCENE,b);this.appendBlob(c);this.previousScene=gs.analytics.Session.Constants.NO_SCENE}};gs.analytics.SessionManager=function(a){this.uploadingIsEnabled=false;this.storedSessionCount=null;this.blobs=null;this.sessionCount=null;this.uploadSequence=null;this.persistedAt=null;this.externalDelegate=a};gs.analytics.SessionManager.prototype={keys:{sessionCount:"engine/gs.analytics.nth",uploadSequence:"engine/gs.analytics.seq",persistedAt:"engine/gs.analytics.pa",storedSessionCount:"engine/gs.analytics.storedSessionCount",storedSessionsPrefix:"engine/gs.analytics.storedSessions/",externalPrefix:"analytics/",uploadUrls:"UPLOAD_URLS"},enableUploading:function(){this.uploadingIsEnabled=true},flush:function(){this.readStateFromStorage();this.readBlobsFromStorage();if(this.uploadingIsEnabled){if(this.blobs.length>0){this.uploadSequence++;var d=this.createHeader();var a=this.formatUploadContent(d,this.blobs);var c=this.readExternalValue(this.keys.uploadUrls);if(c){if(c.forEach){var b=this;c.forEach(function(e){b.upload(e,a)})}else{this.upload(c,a)}}}}this.clearBlobsFromStorage();this.writeStateToStorage()},clearBlobsFromStorage:function(){for(var a=0;a<this.storedSessionCount;a++){var b=this.keys.storedSessionsPrefix+a;this.writeObjectToStorage(b,null)}this.storedSessionCount=0},upload:function(a,b){var c=new XMLHttpRequest();c.open("POST",a,true);c.send(b);gs.Log.info("Posted analytics to:",a)},createHeader:function(){var g=new gs.analytics.Header(this.uploadSequence,this.persistedAt);var b=gs.analytics.Attribute;var a=gs.util.reverseMap(b);var e=this;var c=function(i){var h=a[i];return e.readExternalValue(h)};var d=function(h){var i=c(h);if(i!==null){g.setAttribute(h,i)}};var f=this.getAppUniqueKey();g.setAttribute(b.APP_UNIQUE_KEY,f);d(b.APP_DISPLAY_NAME);d(b.APP_VERSION);d(b.APP_DEVELOPER_ID);d(b.APP_CREATOR_VERSION);d(b.APP_RELEASE_ID);d(b.APP_LICENSE_TYPE);d(b.APP_INSTALL_ID);d(b.APP_DEVELOPER_USERNAME);d(b.DEVICE_UNIQUE_ID);d(b.DEVICE_UNIQUE_ID_HASH);d(b.DEVICE_PLATFORM);d(b.DEVICE_OS_VERSION);d(b.DEVICE_COUNTRY);d(b.DEVICE_LOCALE_LANGUAGE);d(b.DEVICE_LOCALE_COUNTRY);return g},getAppUniqueKey:function(){var b=gs.analytics.Attribute;var a=gs.util.reverseMap(b);var d=this.readExternalValue(a[gs.analytics.Attribute.APP_DEVELOPER_ID]);var c=this.readExternalValue(a[gs.analytics.Attribute.APP_UNIQUE_ID]);return d+"-"+c},formatUploadContent:function(b,c){var a=[];a.push(b);c.forEach(function(d){a.push(d)});return JSON.stringify(a)},appendSession:function(a){this.readStateFromStorage();var b=this.keys.storedSessionsPrefix+this.storedSessionCount;this.writeObjectToStorage(b,a.blobs);this.storedSessionCount++;this.writeStateToStorage()},openNewSession:function(){this.readStateFromStorage();var b=++this.sessionCount;this.writeStateToStorage();var a=new gs.analytics.Session(b,this);a.open();return a},readStateFromStorage:function(){this.sessionCount=this.readObjectFromStorage(this.keys.sessionCount);if(this.sessionCount===null){this.sessionCount=0}this.uploadSequence=this.readObjectFromStorage(this.keys.uploadSequence);if(this.uploadSequence===null){this.uploadSequence=0}this.persistedAt=this.readObjectFromStorage(this.keys.persistedAt);if(this.persistedAt===null){this.persistedAt=gs.util.getSecondsSinceUnixEpoch()}this.storedSessionCount=this.readObjectFromStorage(this.keys.storedSessionCount);if(this.storedSessionCount===null){this.storedSessionCount=0}},readBlobsFromStorage:function(){var d=[];for(var a=0;a<this.storedSessionCount;a++){var c=this.keys.storedSessionsPrefix+a;var b=this.readObjectFromStorage(c);if(b){b.forEach(function(e){d.push(e)})}}this.blobs=d},writeStateToStorage:function(){this.writeObjectToStorage(this.keys.sessionCount,this.sessionCount);this.writeObjectToStorage(this.keys.uploadSequence,this.uploadSequence);this.writeObjectToStorage(this.keys.persistedAt,this.persistedAt);this.writeObjectToStorage(this.keys.storedSessionCount,this.storedSessionCount)},readObjectFromStorage:function(a){return gs.LocalStorage.getObject(a)},writeObjectToStorage:function(a,b){return gs.LocalStorage.setObject(a,b)},readExternalValue:function(a){var b=this.keys.externalPrefix+a;if(this.externalDelegate){return this.externalDelegate.readExternalValueSync(b)}else{return gs.EngineContext.current.delegate.onExternalReadSync(b)}}};gs.file={getExtension:function(c){var b=/\.(\w+)$/;var a=b.exec(c);if(a){return a[1]}else{return null}},replaceExtension:function(c,a){a="."+a;var b=/\.(\w+)$/;if(b.test(c)){return c.replace(b,a)}else{return c+a}},removeExtension:function(b){var a=/\.(\w+)$/;if(a.test(b)){return b.replace(a,"")}else{return b}},joinPath:function(d,f){var b=/^(.*?)\/*$/;var e=b.exec(String(d));d=e[1];var a=/^\/*(.*)$/;var c=a.exec(String(f));f=c[1];return d+"/"+f}};gs.file.Format={XML:"XML",JSON:"JSON",JSONP:"JSONP"};gs.file.Format.getFileExtension=function(a){switch(a){case gs.file.Format.XML:return"xml";case gs.file.Format.JSON:return"json";case gs.file.Format.JSONP:return"js";default:gs.Log.error("Unrecognized format:",a);return""}};gs.file.File=function(){this.cacheKey=null;this.text=null;this.data=null;this.format=null};gs.file.File.prototype={getText:function(){return this.text},setText:function(a){this.text=a},clearText:function(){this.setText(null)},getData:function(){gs.JXON.detect(this.data);return this.data},setData:function(a){this.data=a},hasData:function(){return this.data!==null},getFormat:function(){return this.format},setFormat:function(a){this.format=a}};gs.file.FileFetcher=function(){};gs.file.FileFetcher.onRequestLoad=function(b){var a=this;a.fetcher.onRequestLoad(a,b)};gs.file.FileFetcher.onRequestError=function(b){var a=this;a.fetcher.onRequestError(a,b)};gs.file.FileFetcher.onScriptLoad=function(b){var a=this;a.fetcher.onScriptLoad(a,b)};gs.file.FileFetcher.onScriptError=function(b){var a=this;a.fetcher.onScriptError(a,b)};gs.file.FileFetcher.prototype={extensions:{JSON:"JSON",XML:"XML",JS:"JS"},fetch:function(a){var c=gs.file.getExtension(a).toUpperCase();switch(c){case this.extensions.JSON:return this.fetchJSON(a);case this.extensions.XML:return this.fetchText(a);case this.extensions.JS:return this.fetchJSONP(a);default:var b=new gs.Promise();b.reject("Unexpected file extension: "+c);return b}},fetchText:function(c){var b=new XMLHttpRequest();b.fetcher=this;b.promise=new gs.Promise();b.path=c;b.addEventListener("load",gs.file.FileFetcher.onRequestLoad,false);b.addEventListener("error",gs.file.FileFetcher.onRequestError,false);try{b.open("GET",c,true);b.send(null)}catch(a){gs.file.FileFetcher.onRequestError.call(b,a)}return b.promise},fetchJSON:function(c){var b=new XMLHttpRequest();b.fetcher=this;b.promise=new gs.Promise();b.path=c;b.addEventListener("load",gs.file.FileFetcher.onRequestLoad,false);b.addEventListener("error",gs.file.FileFetcher.onRequestError,false);try{b.open("GET",c,true);b.send(null)}catch(a){gs.file.FileFetcher.onRequestError.call(b,a)}return b.promise},fetchJSONP:function(c){var a=document.createElement("SCRIPT");a.fetcher=this;a.promise=new gs.Promise();a.src=c;a.async=true;a.onload=gs.file.FileFetcher.onScriptLoad;a.onerror=gs.file.FileFetcher.onScriptError;var b=document.getElementsByTagName("HEAD")[0];b.appendChild(a);return a.promise},onRequestLoad:function(e,d){var c=(e.status===200)||(e.status===0&&e.response);if(!c){return this.onRequestError(e,d)}var g=e.promise;var f=e.path;var b=new gs.file.File();var a=e.response||e.responseText;var h=gs.file.getExtension(f);if(h===gs.file.Format.getFileExtension(gs.file.Format.XML)){b.setFormat(gs.file.Format.XML);b.setText(a)}else{b.setFormat(gs.file.Format.JSON);if(typeof a==="string"){b.setData(JSON.parse(a))}else{b.setData(a)}}this.deserialize(b);g.resolve(b)},onRequestError:function(b,a){var c=b.promise;c.reject(a)},onScriptLoad:function(a,c){a.parentNode.removeChild(a);for(var b in a){delete a[b]}},onScriptError:function(a,c){a.parentNode.removeChild(a);var d=a.promise;d.reject(c);for(var b in a){delete a[b]}},deserializeJSON:function(a){var b;if(!a.hasData()){var c=a.getText();a.clearText();b=JSON.parse(c);a.setData(b)}b=a.getData();if(b&&b._type){b=gs.Prototypical.convertJXONLite(b);a.setData(b)}},deserializeXML:function(a){if(!a.hasData()){var c=a.getText();a.clearText();var b=gs.XML.parse(c);a.setData(b)}},deserialize:function(a){if(a.getFormat()===gs.file.Format.XML){this.deserializeXML(a)}else{this.deserializeJSON(a)}}};gs.file.FileCache=function(){this.fileMap={};this.requestMap={};this.jsonpMap={};this.fetcher=new gs.file.FileFetcher();if(!pgf.jsonp){var a=this;pgf.jsonp=function(d,f,e){if(e===undefined){e=f}var b=a.jsonpMap[d];if(b){var c=new gs.file.File();c.setData(e);a.setFile(d,c);b.promise.resolve(c);delete a.jsonpMap[d];delete a.requestMap[b.path]}}}};gs.file.FileCache.prototype={fetch:function(c,b){if(gs.file.getExtension(c)===gs.file.Format.getFileExtension(gs.file.Format.JSONP)){var d=new gs.Promise();this.jsonpMap[b]={path:c,promise:d};this.fetchFile(c,b).otherwise(function a(e){d.reject(e)});return d}else{return this.fetchFile(c,b)}},fetchFile:function(i,g){var h=new gs.Promise();var f=this;var a=this.getFile(i);if(a){h.resolve(a);return h}var d=this.requestMap[i];if(d){d.then(function c(j){h.resolve(j)},function e(j){h.reject(j)})}else{var b=this.fetcher.fetch(i);this.requestMap[i]=b;b.then(function c(j){f.setFile(g,j);delete f.requestMap[i];h.resolve(j)},function e(j){delete f.requestMap[i];h.reject(j)})}return h},setFile:function(b,a){a.cacheKey=b;this.fileMap[b]=a},getFile:function(a){if(a in this.fileMap){return this.fileMap[a]}else{return null}},deleteFile:function(a){delete this.fileMap[a.cacheKey]},deleteFileKey:function(a){delete this.fileMap[a]}};gs.file.VirtualFileCache=function(){this.cache=new gs.file.FileCache();this.prefix=null;this.retainSceneByIndexMap={};this.setFormats([gs.file.Format.JSON,gs.file.Format.XML,gs.file.Format.JSONP]);gs.file.VirtualFileCache.instance=this;gs.file.VirtualFileCache.current=this};gs.file.VirtualFileCache.prototype={strings:{game:"game",object:"object",assets:"assets",actors:"actors",scenes:"scenes",tables:"tables",images:"images"},setPrefix:function(a){this.prefix=a},setFormats:function(a){this.formats=a;this.extensions=[];for(var b=0;b<a.length;b++){this.extensions[b]=gs.file.Format.getFileExtension(a[b])}},setDefaultExtension:function(c){var a=this.extensions.indexOf(c);if(a>0){var b=this.formats[a];this.extensions.splice(a,1);this.extensions.unshift(c);this.formats.splice(a,1);this.formats.unshift(b)}},getRealPath:function(a){var c=gs.file.joinPath(this.prefix,a);var d=gs.file.getExtension(a);if(d===null){var b=gs.file.Format.getFileExtension(this.formats[0]);c+="."+b}return c},fetch:function(c){var h=new gs.Promise();var f=this;var e=gs.file.removeExtension(c);var d=this.cache.getFile(e);if(d){h.resolve(d);return h}var g=this.getRealPath(c);this.cache.fetch(g,e).then(function b(i){f.cache.deleteFile(i);f.cache.setFile(e,i);h.resolve(i)},function a(i){h.reject(i)});return h},fetchData:function(d){var g=new gs.Promise();var b=gs.file.getExtension(d);var c=this.extensions.indexOf(b);if(c===-1){c=0;b=this.extensions[c]}var f=this;this.fetch(d).then(function a(h){f.setDefaultExtension(b);g.resolve(h)}).otherwise(function e(l){var i=c+1;if(i<f.extensions.length){var j=gs.file.replaceExtension(d,f.extensions[i]);f.fetchData(j).then(function h(m){g.resolve(m)}).otherwise(function k(m){g.reject(m)})}else{g.reject(l)}});return g},deserializeJSON:function(a){var b;if(!a.hasData()){var c=a.getText();a.clearText();b=JSON.parse(c);a.setData(b)}b=a.getData();if(b._type){b=gs.Prototypical.convertJXONLite(b);a.setData(b)}},deserializeXML:function(a){if(!a.hasData()){var c=a.getText();a.clearText();var b=gs.XML.parse(c);a.setData(b)}},deserialize:function(a){if(a.getFormat()===gs.file.Format.XML){this.deserializeXML(a)}else{this.deserializeJSON(a)}},fetchGame:function(){var e=new gs.Promise();var c=this;var a=this.cache.getFile(this.strings.game);if(a){e.resolve(a)}else{this.fetchData(c.strings.object).then(function b(f){c.cache.setFile(c.strings.game,f);e.resolve(f)},function d(f){e.reject(f)})}return e},loadGame:function(){var d=new gs.Promise();var b=this;this.fetchGame().then(function c(e){b.deserialize(e);d.resolve(e)},function a(e){d.reject(e)});return d},deleteGame:function(){this.cache.deleteFileKey(this.strings.object);this.cache.deleteFileKey(this.strings.game)},fetchSceneByIndex:function(a){var b=gs.file.joinPath(this.strings.scenes,a);return this.fetchData(b)},loadSceneByIndex:function(a){var e=new gs.Promise();var c=this;this.fetchSceneByIndex(a).then(function b(f){c.deserialize(f);if(!c.retainSceneByIndexMap[a]){c.cache.deleteFile(f)}e.resolve(f)},function d(f){e.reject(f)});return e},retainSceneByIndex:function(a){this.retainSceneByIndexMap[a]=true},isSceneRetainedByIndex:function(a){return this.retainSceneByIndexMap[a]},fetchActorPrototypeByIndex:function(a){var b=gs.file.joinPath(this.strings.actors,a);return this.fetchData(b)},loadActorPrototypeByIndex:function(a){var e=new gs.Promise();var b=this;this.fetchActorPrototypeByIndex(a).then(function c(f){b.deserialize(f);b.cache.deleteFile(f);e.resolve(f)},function d(f){e.reject(f)});return e},fetchAllActorPrototypes:function(){var b=new gs.Promise();var a=this;this.loadGame().then(function(j){var h=null;var f=[];var d=j.getData();h=d.prototypes;if(h){if(!Array.isArray(h)){h=[h]}for(var e=1;e<=h.length;e++){var g=h[e-1];var c=gs.file.joinPath(a.strings.actors,e.toString());if(g.attributes){var i=new gs.file.File();i.setData(g);a.cache.setFile(c,i)}else{f.push(a.fetchData(c))}}}if(f.length>0){gs.Promise.all(f,function(){b.resolve()},function(k){b.reject(k)})}else{b.resolve()}});return b},fetchAssetsManifest:function(){return this.fetchData(this.strings.assets)},loadAssetsManifest:function(){var d=new gs.Promise();var b=this;this.fetchAssetsManifest().then(function a(e){b.deserialize(e);b.cache.deleteFile(e);d.resolve(e)},function c(e){d.reject(e)});return d},fetchTableById:function(b){var a=gs.file.joinPath(this.strings.tables,b);return this.fetchData(a)},loadTableById:function(e){var d=new gs.Promise();var c=this;this.fetchTableById(e).then(function a(f){c.deserialize(f);c.cache.deleteFile(f);d.resolve(f)},function b(f){d.reject(f)});return d}};gs.tables={getKeypath:function(a){if(!/^game\.attributes\./.test(a)){a="game.attributes."+a}return a},saveToPersistence:function(c,b){var a=c.serialize();gs.LocalStorage.setObject(b,a)},loadFromPersistence:function(c,b){var a=gs.LocalStorage.getObject(b);if(a===null){return false}c.parseFromJXON(a);return true}};gs.tables.Table=function(){this.id="";this.name="";this.rowCount=0;this.columnCount=0;this.rowNames=[];this.rowNamesLower=[];this.columnNames=[];this.columnNamesLower=[];this.columnTypes=[];this.data=[];this.tempCell={row:0,column:0}};gs.tables.Table.prototype={setId:function(a){this.id=a},clear:function(){this.rowCount=0;this.columnCount=0;this.rowNames.length=0;this.rowNamesLower.length=0;this.columnNames.length=0;this.columnNamesLower.length=0;this.columnTypes.length=0;this.data.length=0},appendColumn:function(b,c){this.columnNames.push(b);this.columnNamesLower.push(b.toLowerCase());this.columnTypes.push(c);var a=this.defaultValueForType(c);for(var d=0;d<this.rowCount;d++){var e=this.data[d];e.push(a)}this.columnCount++},insertRow:function(f,c){if(c===undefined){c=""}f=this.lookupRow(f);var e=f-1;gs.array.insert(this.rowNames,e,c);gs.array.insert(this.rowNamesLower,e,c.toLowerCase());gs.array.insert(this.data,e,gs.array.provide());for(var b=0;b<this.columnCount;b++){var d=this.columnTypes[b];var a=this.defaultValueForType(d);this.data[e][b]=a}this.rowCount++},insertRowAtEnd:function(a){this.insertRow(this.rowCount+1,a)},insertRowAtBegin:function(a){this.insertRow(1,a)},getColumnType:function(a){a=this.lookupColumn(a);return this.columnTypes[a-1]},getCellType:function(b,a){return this.getColumnType(a)},removeRow:function(b){var a=this.lookupRow(b)-1;gs.array.remove(this.rowNames,a);gs.array.remove(this.rowNamesLower,a);gs.array.remove(this.data,a);this.rowCount--},getCell:function(c,b){var a=this.lookupCell(c,b);return this.getCellByIndex(a.row,a.column)},getCellByIndex:function(b,a){if(this.isInBounds(b,a)){return this.data[b-1][a-1]}else{gs.Log.warn("set out of bounds",this.id,this.name,b,a);return""}},setCell:function(d,b,c){var a=this.lookupCell(d,b);this.setCellByIndex(a.row,a.column,c)},setCellByIndex:function(e,b,c){if(this.isInBounds(e,b)){var a=this.data[e-1][b-1];var d=this.coerceType(c,this.columnTypes[b-1]);this.data[e-1][b-1]=d;return a}else{gs.Log.warn("set out of bounds",this.id,this.name,e,b);return c}},isInBounds:function(c,b){var a=1<=c&&c<=this.rowCount;var d=1<=b&&b<=this.columnCount;return a&&d},lookupRow:function(c){if(typeof c==="number"){return c}if(typeof c==="string"){var d=c.toLowerCase();var a=this.rowNamesLower.indexOf(d);if(a!==-1){return a+1}var b=gs.parseInteger(c);if(!isNaN(b)){return b}}gs.Log.error("bad row",c);return 0},lookupColumn:function(c){if(typeof c==="number"){return c}if(typeof c==="string"){var b=c.toLowerCase();var a=this.columnNamesLower.indexOf(b);if(a!==-1){return a+1}var d=gs.parseInteger(c);if(!isNaN(d)){return d}}gs.Log.error("bad column",c);return 0},lookupCell:function(b,a){this.tempCell.row=this.lookupRow(b);this.tempCell.column=this.lookupColumn(a);return this.tempCell},getTypeByEnum:function(a){switch(a){case 0:case 1:return"text";case 2:return"integer";case 3:return"real";case 4:return"boolean";case 5:return"angle";case 6:return"image";case 7:return"sound";default:gs.Log.error("bad type enum",a);return null}},getEnumByType:function(a){switch(a){case"text":return 1;case"integer":return 2;case"real":return 3;case"boolean":return 4;case"angle":return 5;case"image":return 6;case"sound":return 7;default:gs.Log.error("bad type string",a);return 0}},defaultValueForType:function(a){switch(a){case"boolean":return false;case"text":case"image":case"sound":return"";default:return 0}},coerceType:function(b,a){var c=typeof b;switch(a){case"boolean":return c==="boolean"?b:gs.parseBoolean(b);case"text":case"image":case"sound":return c==="string"?b:String(b);case"real":return c==="number"?b:parseFloat(b);default:return c==="number"?b:gs.parseInteger(b)}},parseFromLite:function(b){this.name=b.name;var c,g;var d,h;var i=gs.parseInteger(b.numRows);var f=gs.parseInteger(b.numCols);var a=b.columns;if(!Array.isArray(a)){a=[a]}for(g=0;g<f;g++){h=a[g];var k=gs.parseInteger(h.type);this.appendColumn(h.name,this.getTypeByEnum(k))}var l=b.rows;if(!Array.isArray(l)){l=[l]}for(c=0;c<i;c++){d=l[c];this.insertRowAtEnd(d.name)}for(g=0;g<f;g++){h=a[g];var e=h["$"];if(e){var j=this.columnTypes[g];for(c=0;c<i;c++){this.data[c][g]=this.coerceType(e[c],j)}}}},parseFromJXON:function(b){gs.JXON.detect(b);this.name=b.name;var c,h;var d,i;var j=gs.parseInteger(b.numRows);var g=gs.parseInteger(b.numCols);var m=gs.JXON.childWithTag(b,"columns");var a=gs.JXON.childrenWithTag(m,"column");for(h=0;h<g;h++){i=a[h];var l=gs.parseInteger(i.type);this.appendColumn(i.name,this.getTypeByEnum(l))}var f=gs.JXON.childWithTag(b,"rows");var n=gs.JXON.childrenWithTag(f,"row");for(c=0;c<j;c++){d=n[c];this.insertRowAtEnd(d.name)}for(h=0;h<g;h++){i=a[h];var e=i[gs.JXON._text];if(e){var k=this.columnTypes[h];for(c=0;c<j;c++){this.data[c][h]=this.coerceType(e[c],k)}}}},copyFromOtherTable:function(c){this.clear();var d,b;var a=c.rowCount;var e=c.columnCount;for(b=0;b<e;b++){this.appendColumn(c.columnNames[b],c.columnTypes[b])}for(d=0;d<a;d++){this.insertRowAtEnd(c.rowNames[d])}for(d=0;d<a;d++){for(b=0;b<e;b++){this.data[d][b]=c.data[d][b]}}},serialize:function(){var a={serializationFormat:"file",serializationVersion:"1",_type:"table",name:this.name,numRows:this.rowCount,numCols:this.columnCount,_children:[]};var d={_type:"rows",_children:[]};for(var e=0;e<this.rowCount;e++){d._children.push({_type:"row",id:e,name:this.rowNames[e]})}a._children.push(d);var b={_type:"columns",_children:[]};for(var c=0;c<this.columnCount;c++){b._children.push({_type:"column",id:c,name:this.columnNames[c],type:this.getEnumByType(this.columnTypes[c]),_text:this.serializeColumn(c+1)})}a._children.push(b);return a},serializeColumn:function(b){var a=[];for(var d=1;d<=this.rowCount;d++){var c=this.getCell(d,b);a.push(String(c))}return a}};gs.lua={mod:function(a,b){return a-Math.floor(a/b)*b}};gs.NOOP_FUNCTION=function(){};gs.GameSaladObject=(function(){var a={};a.__class=a;a.__superclass=null;a.__classname="GameSaladObject";a.__classSet={GameSaladObject:true};a.__tostring=function(){return this.__classname};a.superclass=function(){return this.__superclass};a.getClass=function(){return this.__class};a.classname=function(){return this.__classname};a.isAClass=function(){return(this===this.__class)};a.subclass=function(f,e){var b=Object.create(this);b.__superclass=this;b.__class=b;b.__classname=f;var c={};c[f]=true;b.__classSet=gs.set.unionSet(this.__classSet,c);if(e){for(var d in e){b[d]=e[d]}}return b};a.create=function(){var b=Object.create(this);b._parent=null;b._objectKey=null;b._children=gs.array.provide();return b};a.createNoChildren=function(){var b=Object.create(this);b._parent=null;b._objectKey=null;return b};a.provide=function(){return this.__class.create()};a.init=function(){return this};a.initPrime=function(){return this};a.clone=function(){return this.__class.provide()};a.recycleArrays=function(){if(this._children){gs.array.recycle(this._children)}};a.addAccessor=function(c,b){Object.defineProperty(this,c,{configurable:true,get:function(){return this[b]()}})};a.addAccessors=function(f,b){var e=f.length;for(var c=0;c<e;++c){var g=f[c];var d=b[c];this.addAccessor(g,d)}};a.addMutator=function(b,c){Object.defineProperty(this,b,{configurable:true,set:function(d){return this[c](d)}})};a.addMutators=function(f,c){var e=f.length;for(var d=0;d<e;++d){var g=f[d];var b=c[d];this.addMutator(g,b)}};a.valueForKey=function(b){return this[b]};a.setValueForKey=function(c,b){this[b]=c;this.notifyObserversOfChange(b,c)};a.valueForKeypath=function(b){var c=b.split(".");return this.valueForKeypathArray(c)};a.valueForKeypathArray=function(g){var f=this;var b=gs.CompoundAttribute.obfuscationLookupTable;for(var d=0,e=g.length;f&&d<e;++d){var c=g[d];c=b[c]||c;f=f[c]}return f};a.addObserver=function(b){if(!this._observers){this._observers=gs.array.provide()}var c=this._observers;var d=c.length;c.push(b);if(d===0){this.setObservable(true)}};a.notifyObserversOfChange=function(){};a.hasObserver=function(b){var e=this._observers;var d=e.length;for(var c=0;c<d;++c){if(e[c]===b){return true}}return false};a.removeObserver=function(b){if(this._observers){var d=this._observers;var c=d.indexOf(b);if(c===-1){return}if(d.length===1){this.setObservable(false);gs.array.recycle(this._observers);this._observers=null}else{d.splice(c,1)}}};a.observeChange=function(c,b,d){};a.observeValueChange=function(c,b,d){};a.generateRandomObjectKey=function(){var b;do{b="rid"+Math.floor(Math.random()*1000000)}while(this[b]);return b};a.generateUniqueObjectKey=function(){return gs.ObjectBase.generateUniqueObjectKey()};a.getParent=function(){return this._parent};a.setParent=function(b){this._parent=b};a.getObjectKey=function(){return this._objectKey};a.setObjectKey=function(b){this._objectKey=b};a.setObjectForKey=function(b,d){var c=this._children;if(d&&this.hasOwnProperty(d)){this.removeObjectForKey(d)}if(!b){return}b._objectKey=d;b._parent=this;this[d]=b;if(c.indexOf(b)===-1){c.push(b)}};a.removeObjectForKey=function(c){var d=null;if(c&&this.hasOwnProperty(c)){d=this[c];if(d){var b=this._children.indexOf(d);this._children.splice(b,1);delete this[c];if((d)&&(d._parent===this)){d.setParent(null)}}}return d};a.addAccessors(["objectKey","parent"],["getObjectKey","getParent"]);a.addMutators(["objectKey","parent"],["setObjectKey","setParent"]);return a})();gs.instanceOfClassType=function(a,b){return(a.__classSet&&a.__classSet[b])};gs.isInstanceOf=function(a,b){var c=typeof(a);if(c===b){return true}else{if(c==="object"&&a&&a.__class){if(gs.instanceOfClassType(a,b)){return true}}}return false};gs.makeEqualityPredicate=function(a){return function(b){return(b==a)}};gs.getTypeName=function(b){var a=gs.getTypeHelper(b);return a?a.name:null};gs.getTypeHelper=function(d){if(d===undefined||d===null){return d}if(!gs.classPrototypes){gs.classPrototypes=[];gs.classDescriptions=[]}var f=Object.getPrototypeOf(d);var b=gs.classPrototypes.indexOf(f);if(b!==-1){return gs.classDescriptions[b]}for(var a in gs){var e=gs[a];if(typeof e==="function"){if(f===e.prototype){var c={name:a,constructor:e};gs.classPrototypes.push(f);gs.classDescriptions.push(c);return c}}}return null};gs.ObjectBase=function(){};gs.ObjectBase.nextUniqueObjectKey=1;gs.ObjectBase.generateUniqueObjectKey=function(){return"uid"+(this.nextUniqueObjectKey++)};gs.ObjectBase.prototype={clone:function(){return this.__class.provide()}};gs.inherits(gs.ObjectBase,Object);gs.ObjectWithImmutableAttributes=function(){if(!this.attributes){this.attributes=new gs.ImmutableAttributeCollection()}this.attributes._parent=this};gs.ObjectWithImmutableAttributes.prototype={init:function(){this.declareAttributes(this.attributes);return this},declareAttributes:function(a){},clone:function(){var a=this.__class.provide();a.attributes=this.attributes.clone();a.attributes._parent=a;return a},loadFromLite:function(c,a){var b=c.attributes;if(b){this.attributes.loadFromLite(b,a)}}};gs.inherits(gs.ObjectWithImmutableAttributes,gs.ObjectBase);gs.ObjectList=function(){};gs.ObjectList.prototype={clear:function(){this.length=0},loadFromLite:function(b,e,a){var d;if(Array.isArray(e)){for(var c=0;c<e.length;c++){d=b(e[c],a);this[c]=d}}else{d=b(e,a);this[0]=d}},makeChildrenPerformFunction:function(c,a){for(var b=0;b<this.length;b++){c.call(this[b],a)}}};gs.inherits(gs.ObjectList,gs.ObjectBase);gs.ObjectListWithKeys=function(){};gs.ObjectListWithKeys.prototype={clear:function(){this.length=0;for(var a in this){delete this[a]}},loadFromLite:function(b,e,a){var d;if(Array.isArray(e)){for(var c=0;c<e.length;c++){d=b(e[c],a);this[c]=d;d._objectKey=d._objectKey||gs.ObjectBase.generateUniqueObjectKey();this[d._objectKey]=d}}else{d=b(e,a);this[0]=d;d._objectKey=d._objectKey||gs.ObjectBase.generateUniqueObjectKey();this[d._objectKey]=d}},makeChildrenPerformFunction:function(c,a){for(var b=0;b<this.length;b++){c.call(this[b],a)}}};gs.inherits(gs.ObjectListWithKeys,gs.ObjectList);gs.Timebase=function(){this.base=0;this.paused=false;if(!this.currentTimeStamp){this.currentTimeStamp={}}this.currentTimeStamp.time=0;this.currentTimeStamp.dt=0;this.currentTimeStamp.base=this.base};gs.Pool.init(gs.Timebase);gs.Timebase.prototype={init:function(){var a=gs.EngineContext.current.getSimulationTimeS();return this.initWithBase(a)},initWithBase:function(a){this.base=a;this.paused=false;this.currentTimeStamp.time=0;this.currentTimeStamp.dt=0;this.currentTimeStamp.base=this.base;return this},initWithTime:function(a){return this.initWithBase(a.time)},pause:function(){if(!this.paused){this.paused=true;this.pausedAtTime=gs.EngineContext.current.getSimulationTimeS()-this.base}},resume:function(){if(this.paused){this.base=gs.EngineContext.current.getSimulationTimeS()-this.pausedAtTime;this.finishTimebaseResume()}},pauseRelativeToTimestamp:function(a){if(!this.paused){this.paused=true;this.pausedAtTime=a.time-this.base}},resumeRelativeToTimestamp:function(a){if(this.paused){this.base=a.time-this.pausedAtTime;this.finishTimebaseResume()}},finishTimebaseResume:function(){this.currentTimeStamp.base=this.base;this.pausedAtTime=null;this.paused=false},nextTimestamp:function(a){this.currentTimeStamp.time+=a;this.currentTimeStamp.dt=a;return this.currentTimeStamp},convertTimeStamp:function(a){this.currentTimeStamp.time=Math.max(0,a.time-this.base);this.currentTimeStamp.dt=a.dt},getTimeStamp:function(){return this.currentTimeStamp}};gs.PrototypicalDictionary=gs.GameSaladObject.subclass("PrototypicalDictionary");gs.PrototypicalDictionary.clone=function(){var a=this.__class.provide();var f=this._children;var h=a._children;for(var c=0,d=f.length;c<d;c++){var e=f[c];var b=e._objectKey;var g=e.clone();g._objectKey=b;g._parent=a;a[b]=g;h[c]=g}return a};gs.PrototypicalDictionary.releaseExpressionInputs=function(){var a=this._children;for(var b=0,c=a.length;b<c;b++){var d=a[b];if(d.releaseExpressionInputs){d.releaseExpressionInputs()}}};gs.PrototypicalObject=gs.PrototypicalDictionary.subclass("PrototypicalObject");gs.PrototypicalObject.addAccessors(["displayName"],["getDisplayName"]);gs.PrototypicalObject.addMutators(["displayName"],["setDisplayName"]);gs.PrototypicalObject.init=function(){gs.PrototypicalDictionary.init.call(this);this.setObjectForKey(gs.CompoundAttribute.provide().init(),"attributes");return this};gs.PrototypicalObject.initPrime=function(){this.attributes=null;return this};gs.PrototypicalObject.getDisplayName=function(){if(this.attributes.name){return this.attributes.name.getValue()}else{return""}};gs.PrototypicalObject.setDisplayName=function(a){};gs.PrototypicalObject.releaseExpressionInputs=function(){this.attributes.releaseExpressionInputs()};gs.PrototypicalObject.loadFromLite=function(c,a){var d=c.id;var b=c.attributes;if(d){this._objectKey=d}if(b){this.attributes.loadFromLite(b)}};gs.PrototypicalObject.loadFromTable=function(e,a){var d=e.id;if(d){this._objectKey=d}var g=e[gs.JXON._children];if(!g){return}var h=g.length;for(var c=0;c<h;++c){var f=g[c];var b=gs.Project.nodeTypeNameMap[f[gs.JXON._type]];if(b==="attributes"){if(f[gs.JXON._children]){this.attributes.loadFromTable(f[gs.JXON._children],a)}break}}};gs.PrototypicalImmutableObject=gs.PrototypicalDictionary.subclass("PrototypicalImmutableObject",{init:function(){gs.PrototypicalDictionary.init.call(this);this.setObjectForKey(new gs.ImmutableAttributeCollection(),"attributes");return this},initPrime:function(){this.attributes=null;return this},releaseExpressionInputs:function(){this.attributes.releaseExpressionInputs()},loadFromLite:function(c,a){var d=c.id;var b=c.attributes;if(d){this._objectKey=d}if(b){this.attributes.loadFromLite(b,a)}},loadFromTable:function(k,c){var l=gs.JXON;var e=l._children;var f=gs.Project.nodeTypeNameMap;var g=k.id;if(g){this._objectKey=g}var b=k[e];if(b){for(var d=0,j=b.length;d<j;d++){var a=b[d];var m=f[a[l._type]];if(m==="attributes"){var h=a[e];if(h&&h.length>0){this.attributes.loadFromTable(h,c)}break}}}}});gs.PrototypicalKeylessArray=gs.PrototypicalDictionary.subclass("PrototypicalKeylessArray");gs.PrototypicalKeylessArray.create=function(){var a=gs.PrototypicalDictionary.create.call(this);a.array=a._children;return a};gs.PrototypicalKeylessArray.init=function(a){gs.PrototypicalDictionary.init.call(this);this.entityType=a;return this};gs.PrototypicalKeylessArray.initPrime=function(){this.array=this._children;return this};gs.PrototypicalKeylessArray.length=function(){return this.array.length};gs.PrototypicalKeylessArray.clone=function(){var a=this.__class.provide();var f=this._children;var h=a._children;for(var c=0,d=f.length;c<d;c++){var e=f[c];var b=e._objectKey;var g=e.clone();g._objectKey=b;g._parent=a;h[c]=g}return a};gs.PrototypicalKeylessArray.setObjectForKey=function(a,b){if(!a){return}a.setObjectKey(b);a.setParent(this);this.array.push(a)};gs.PrototypicalKeylessArray.addObjectAtIndex=function(b,a,c){if(this.array[a]){this.removeObjectAtIndex(a)}if((a===null)||(a===undefined)){a=this.array.length}this.array.splice(a,0,b);c=c||this.generateUniqueObjectKey();b.setObjectKey(c);b.setParent(this)};gs.PrototypicalKeylessArray.addObjectAtEnd=function(a,b){if(this.hasOwnProperty(b)){this.removeObjectForKey(b)}a._objectKey=b;a._parent=this;this.array.push(a)};gs.PrototypicalKeylessArray.removeObjectAtIndex=function(a){var b=this.array[a];this.array.splice(a,1);b.setParent(null)};gs.PrototypicalKeylessArray.makeChildrenPerformFunction=function(c,a){for(var b=0;b<this.array.length;b++){c.call(this.array[b],a)}};gs.PrototypicalKeylessArray.loadFromLite=function(d,a){var e;switch(this.entityType){case"condition":e=gs.Parser.parseCondition}if(Array.isArray(d)){for(var c=0;c<d.length;c++){var b=e(d[c],a);b._objectKey=d[c].id;b._parent=this;this.array[c]=b}}else{var b=e(d,a);b._objectKey=d.id;b._parent=this;this.array[0]=b}};gs.PrototypicalKeylessArray.loadFromTable=function(e,a){var d,b;var g=this.array;for(d=0,b=g.length;d<b;++d){g[d].setParent(null)}g.length=0;if(e){for(d=0,b=e.length;d<b;++d){var f=e[d];var c=gs.Parser.parse(f,a);c._objectKey=f.id;c._parent=this;this.array.push(c)}}};gs.PrototypicalArray=gs.PrototypicalDictionary.subclass("PrototypicalArray");gs.PrototypicalArray.create=function(){var a=gs.PrototypicalDictionary.create.call(this);a.array=a._children;return a};gs.PrototypicalArray.init=function(){gs.PrototypicalDictionary.init.call(this);return this};gs.PrototypicalArray.initPrime=function(){this.array=this._children;return this};gs.PrototypicalArray.releaseExpressionInputs=function(){var a=this.array;for(var b=0,c=a.length;b<c;b++){var d=a[b];if(d.releaseExpressionInputs){d.releaseExpressionInputs()}}};gs.PrototypicalArray.setObjectForKey=function(a,b){if(!a){return}a._objectKey=b;a._parent=this;this[b]=a};gs.PrototypicalArray.addObjectAtIndex=function(b,a,d){if(d&&this.hasOwnProperty(d)){this.removeObjectForKey(d)}d=d||this.generateUniqueObjectKey();var c=this.array;if(a===c.length){c.push(b)}else{if((a===null)||(a===undefined)){c.push(b)}else{c.splice(a,0,b)}}this.setObjectForKey(b,d)};gs.PrototypicalArray.addObjectAtEnd=function(a,b){if(this.hasOwnProperty(b)){this.removeObjectForKey(b)}a._objectKey=b;a._parent=this;this[b]=a;this.array.push(a)};gs.PrototypicalArray.removeObjectAtIndex=function(a){var b=this.array[a]._objectKey;this.removeObjectForKey(b)};gs.PrototypicalArray.removeObject=function(a){this.removeObjectForKey(a._objectKey)};gs.PrototypicalArray.indexOfObjectWithKey=function(b){var a=this[b];return this.array.indexOf(a)};gs.PrototypicalArray.makeChildrenPerformFunction=function(c,a){for(var b=0;b<this.array.length;++b){c.call(this.array[b],a)}};gs.PrototypicalArray.loadFromLite=function(d,a){if(Array.isArray(d)){for(var c=0;c<d.length;c++){var b=gs.Parser.parse(d[c],a);this.addObjectAtIndex(b,c,d[c].id)}}else{var b=gs.Parser.parse(d,a);this.addObjectAtIndex(b,0,d.id)}};gs.PrototypicalArray.loadFromTable=function(e,b){var g=this.array.length;for(var d=g-1;d>=0;--d){this.removeObjectAtIndex(d)}var a=0;if(e){a=e.length}for(var d=0;d<a;++d){var f=e[d];var h=f.id;var c=gs.Parser.parse(f,b);this.addObjectAtIndex(c,d,h)}};gs.TextConstraint=gs.GameSaladObject.subclass("TextConstraint");gs.TextConstraint.returnVec=[0,0];gs.TextConstraint.init=function(){gs.GameSaladObject.init.call(this);this.minCharacters=0;return this};gs.TextConstraint.defaultValue=function(){var a="";while(a.length<this._minCharacters){a+=" "}return a};gs.TextConstraint.initWithParameters=function(b,a){gs.GameSaladObject.init.call(this);this._minCharacters=b;this._maxCharacters=a;return this};gs.TextConstraint.constrainValue=function(c){var f=false;var d="";if(c!==undefined){f=true;c=gs.Attribute.convertValueToString(c);var b=c.length;var e=(this._minCharacters!=null)?this._minCharacters:0;if(b>=e){if(this._maxCharacters){b=Math.min(b,this._maxCharacters)}f=true;d=c.substr(0,b)}}var a=gs.TextConstraint.returnVec;a[0]=f;a[1]=d;return a};gs.TextConstraint.Default=gs.TextConstraint.provide().init();gs.NumberConstraint=gs.GameSaladObject.subclass("NumberConstraint");gs.NumberConstraint.returnVec=[0,0];gs.NumberConstraint.init=function(){gs.GameSaladObject.init.call(this);this._minValue=null;this._maxValue=null;this._step=null;this._circular=null;return this};gs.NumberConstraint.initWithParameters=function(c,d,b,a){gs.GameSaladObject.init.call(this);this._minValue=c;this._maxValue=d;this._step=b;this._circular=a;return this};gs.NumberConstraint.defaultValue=function(){return(this._minValue!=null)?this._minValue:0};gs.NumberConstraint.constrainValue=function(i){var a=false;var b=null;var d=Number(i);a=(d!=null);var j=d;var h=this._minValue;var e=this._maxValue;var c=this._step;if(this._circular&&(h!==null)&&(e!==null)){var f=(e-h);while(j<h){j+=f}while(j>e){j-=f}}if(c){j=j-j%c+Math.floor((j%c)/c+0.5)*c}if((h!==null)&&(j<h)){j=h}if((e!==null)&&(j>e)){j=e}if(j===Infinity){j=0}b=j;var g=gs.NumberConstraint.returnVec;g[0]=a;g[1]=b;return g};gs.NumberConstraint.Real=gs.NumberConstraint.provide().init();gs.NumberConstraint.Integer=gs.NumberConstraint.provide().initWithParameters(null,null,1);gs.NumberConstraint.Index=gs.NumberConstraint.provide().initWithParameters(0,null,1);gs.NumberConstraint.Angle=gs.NumberConstraint.provide().initWithParameters(0,360,null,true);gs.NumberConstraint.PositiveReal=gs.NumberConstraint.provide().initWithParameters(0);gs.NumberConstraint.PositiveInteger=gs.NumberConstraint.provide().initWithParameters(0,null,1);gs.NumberConstraint.ZeroToOneInclusiveRange=gs.NumberConstraint.provide().initWithParameters(0,1);gs.NumberConstraint.Real.constrainValue=function(c){var a=gs.NumberConstraint.returnVec;var b=true;if(typeof c!=="number"){c=Number(c);b=!isNaN(c);if(!b){b=true;c=1}}a[0]=b;a[1]=c;return a};gs.BooleanConstraint=gs.GameSaladObject.subclass("BooleanConstraint");gs.BooleanConstraint.returnVec=[0,0];gs.BooleanConstraint.defaultValue=function(){return false};gs.BooleanConstraint.constrainValue=function(b){var c=null;switch(b){case"true":case"1":c=true;break;case"false":case"0":c=false;break;default:c=Boolean(b);break}var d=(c!=null);var a=gs.BooleanConstraint.returnVec;a[0]=d;a[1]=c;return a};gs.BooleanConstraint.Default=gs.BooleanConstraint.provide().init();gs.KeycodeConstraint=gs.TextConstraint.subclass("KeycodeConstraint");gs.KeycodeConstraint.constrainValue=function(b){var a=gs.TextConstraint.constrainValue.call(this,b);var d=a[0];var c=a[1];if(b===" "){a[0]=true;a[1]="space"}return a};gs.KeycodeConstraint.Default=gs.KeycodeConstraint.provide().init();gs.Attribute=gs.PrototypicalDictionary.subclass("Attribute");gs.Attribute.addAccessors(["displayName","value","type"],["getDisplayName","getValue","getType"]);gs.Attribute.addMutators(["displayName","value"],["setDisplayName","setValue"]);gs.Attribute.create=function(){return this.createNoChildren()};gs.Attribute.init=function(){gs.PrototypicalDictionary.init.call(this);this._observed=false;this._initialValue=null;return this};gs.Attribute.initPrime=function(){this._value=null;this._type=null;this._constraint=null;this._initialValue=null;this._node=null;this._observers=null;this._observed=false;return this};gs.Attribute.clone=function(){var a=this.__class.provide();a._value=this._initialValue;a._initialValue=this._initialValue;a._type=this._type;a._constraint=this._constraint;return a};gs.Attribute.initWithTypeAndValue=function(a,b){this.init();this.setType(a);if((b==null)&&(this._constraint)){this.setValue(this._constraint.defaultValue())}else{this.setValue(b)}this._initialValue=this._value;return this};gs.Attribute.getDisplayName=function(){var a=this._displayName;if(!a){a=this.getObjectKey()}return a};gs.Attribute.setDisplayName=function(a){};gs.Attribute.setReserved=gs.NOOP_FUNCTION;gs.Attribute.getValue=function(){return this._value};gs.Attribute.booleanValue=function(){var a=this.getValue();return a};gs.Attribute.stringValue=function(){var a=this.getValue();return gs.Attribute.convertValueToString(a)};gs.Attribute.numberValue=function(){var a=this.getValue();if(isNaN(a)){return 0}return a};gs.Attribute.intValue=function(){return this.numberValue()|0};gs.Attribute.setValue=function(b){if(this._value!==b){var d=this._constraint;if(d){var a=d.constrainValue(b);var e=a[0];var c=a[1];if(e){this._value=c;this.notifyObserversOfValueChange(c)}}else{this._value=b;this.notifyObserversOfValueChange(b)}}};gs.Attribute.fastSetValue=function(a){if(this._value!==a){this._value=a;this.notifyObserversOfValueChange(a)}};gs.Attribute.getType=function(){if(this._type){return this._type}else{var a=typeof(this._value);switch(a){case"number":return"real";case"string":return"text";default:return a}}};gs.Attribute.setType=function(a){this._type=a;this.setConstraint(gs.DefaultConstraints[a])};gs.Attribute.setConstraint=function(a){this._constraint=a};gs.Attribute.getNode=function(){var a=this._node;if(!a){var a=gs.SGAttributeNode.provide();a.setValue(this.getValue());this._node=a;this._observed=true}return a};gs.Attribute.connectToSprite=function(a,b,c){this.sprite=a;this.spriteValueKey=b;this.spriteDirtyKey=c;a[b]=this.getValue();a[c]=true;this._observed=true};gs.Attribute.disconnectFromSprite=function(){this.sprite=null};gs.Attribute.notifyNodeOfValueChangeMethod=function(c){var b=this._node;if(b){b.setValue(c)}var a=this.sprite;if(a){a[this.spriteValueKey]=c;a[this.spriteDirtyKey]=true}};gs.Attribute.notifyObserversOfValueChange=gs.Attribute.notifyNodeOfValueChangeMethod;gs.Attribute.notifyObserversOfValueChangeMethod=function(d){this.notifyNodeOfValueChangeMethod(d);var e=this._observers;if(e){for(var b=0,c=e.length;b<c;b++){var a=e[b];a.observeValueChange(this,d)}}};gs.Attribute.setObservable=function(a){this._observed=a;if(a){this.notifyObserversOfValueChange=gs.Attribute.notifyObserversOfValueChangeMethod}else{this.notifyObserversOfValueChange=gs.Attribute.notifyNodeOfValueChangeMethod}};gs.Attribute.releaseExpressionInputs=function(){this._node=null;this._observed=false};gs.Attribute.loadFromLite=function(c,a){if(!this._type&&c["@"]){this.setType(c["@"])}var b=typeof c==="object"?c["$"]:c;this.setValue(b);if(a){this._initialValue=this._value}};gs.Attribute.loadFromTable=function(c,a){if(!this._type){var d=c[gs.JXON._type];this.setType(d)}var b=c[gs.JXON._text];this.setValue(b);if(a){this._initialValue=this._value}};gs.Attribute.restoreInitialState=function(){this._value=this._initialValue};gs.Attribute.loadFromTableStatic=function(i,c){var a=null;var f=gs.JXON.tag(i);var b=gs.JXON.children(i);var h="expression";if(b&&b.length===1&&gs.JXON.tag(b[0])===h){a=gs.ExpressionAttribute.provide().init();a.loadFromTable(i,c)}else{var d=gs.Parser.compoundAttributeClassMap;var e=gs.CompoundAttribute.obfuscationLookupTable;var g=d[e[f]];if(g){a=g.provide().init();if(b){a.loadFromTable(b,c)}}else{a=gs.Attribute.provide().init();a.loadFromTable(i,c)}}return a};gs.Attribute.convertValueToString=function(a){if(a===undefined||a===null){return a}var e=String(a);if(typeof a==="number"){var d=6;var c=e.indexOf(".");if(c!==-1){if(e===a.toExponential()){if(/e-\d/.test(e)){return"0"}return e}var b=c;if(b>=d){return Math.floor(a).toString()}var f=e.length-c-1;if(b+f>d){e=a.toPrecision(d);return Number(e).toString()}}}return e};gs.CompoundAttribute=gs.PrototypicalArray.subclass("CompoundAttribute");gs.CompoundAttribute.addAccessors(["displayName","type"],["getDisplayName","getType"]);gs.CompoundAttribute.initWithValues=function(b,a){this.init();return this};gs.CompoundAttribute.addReservedCompoundAttribute=function(d,b,f,c){var a=gs.CompoundAttribute;if(b){a=gs.Parser.compoundAttributeClassMap[b]}var e=a.provide();e.initWithValues(f,c);this.addObjectAtEnd(e,d);return e};gs.CompoundAttribute.addReservedAttribute=function(d,a,c,b){var e=gs.Attribute.provide().initWithTypeAndValue(c,a);if(b){e.setConstraint(b)}this.addObjectAtEnd(e,d);return e};gs.CompoundAttribute.addExpressionAttribute=function(d,a,c,b){var e=gs.ExpressionAttribute.provide().initWithTypeAndValue(c,a);if(b){e.setConstraint(b)}this.addObjectAtEnd(e,d);return e};gs.CompoundAttribute.addBooleanImmutableAttribute=function(a,c){var b=new gs.BooleanImmutableAttribute(a,c);this[a]=b;this.array.push(b)};gs.CompoundAttribute.addIntegerImmutableAttribute=function(a,c){var b=new gs.IntegerImmutableAttribute(a,c);this[a]=b;this.array.push(b)};gs.CompoundAttribute.addRealImmutableAttribute=function(a,c){var b=new gs.RealImmutableAttribute(a,c);this[a]=b;this.array.push(b)};gs.CompoundAttribute.addStringImmutableAttribute=function(a,c){var b=new gs.StringImmutableAttribute(a,c);this[a]=b;this.array.push(b)};gs.CompoundAttribute.addPointMutableAttribute=function(b,a,d){var c=new gs.PointMutableAttribute();c.x.setValue(a);c.y.setValue(d);this.addObjectAtEnd(c,b)};gs.CompoundAttribute.getType=function(){return"attributes"};gs.CompoundAttribute.restoreInitialState=function(){var a=this.array;for(var b=0,c=a.length;b<c;b++){a[b].restoreInitialState()}};gs.CompoundAttribute.obfuscationLookupTable=gs.util.createObfuscationLookup({acceleration:"acceleration",accelerometer:"accelerometer",actors:"actors",actorTag:"actorTag",actorTags:"actorTags",affectedByGravity:"affectedByGravity",alignment:"alignment",alpha:"alpha",angle:"angle",angularDrag:"angularDrag",angularVelocity:"angularVelocity",applyMaxSpeed:"applyMaxSpeed",array:"array",assignments:"assignments",aspects:"aspects",at:"at",at_index:"at_index",audio:"audio",autorotate:"autorotate",blendingMode:"blendingMode",blue:"blue",bundleName:"bundleName",button:"button",camera:"camera",collisionShape:"collisionShape",color:"color",colorChange:"colorChange",colorTarget:"colorTarget",colorTransitionTime:"colorTransitionTime",column:"column",command:"command",compound:"compound",compoundConditionKind:"compoundConditionKind",conditionType:"conditionType",continuousMovement:"continuousMovement",copies:"copies",count:"count",density:"density",destinationTableID:"destinationTableID",deviceOrientation:"deviceOrientation",deviceRotation:"deviceRotation",devices:"devices",direction:"direction",directionRelativity:"directionRelativity",directionSpace:"directionSpace",displaySize:"displaySize",dopplerShift:"dopplerShift",drag:"drag",duration:"duration",easing:"easing",emitterOffsetX:"emitterOffsetX",emitterOffsetY:"emitterOffsetY",enableAdvertisement:"enableAdvertisement",endCell:"endCell",endCellExpression:"endCellExpression",event:"event",finalValue:"finalValue",fixedRotation:"fixedRotation",font:"font",friction:"friction",functionName:"functionName",game:"game",gravity:"gravity",graphics:"graphics",green:"green",growthRate:"growthRate",haltWhenBehaviorStops:"haltWhenBehaviorStops",height:"height",horizontalAnchor:"horizontalAnchor",horizontalWrap:"horizontalWrap",image:"image",images:"images",index:"index",input1:"input1",input2:"input2",input3:"input3",input4:"input4",input5:"input5",input6:"input6",input7:"input7",input8:"input8",input9:"input9",input10:"input10",interfaceOrientation:"interfaceOrientation",interval:"interval",item:"item",key:"key",keyboardPrompt:"keyboardPrompt",keyString:"keyString",landscapeLeft:"landscapeLeft",landscapeRight:"landscapeRight",layerOrder:"layerOrder",lifetime:"lifetime",linearVelocity:"linearVelocity",location:"location",loop:"loop",loopAttribute:"loopAttribute",loopType:"loopType",maxSpeed:"maxSpeed",mode:"mode",motion:"motion",mouse:"mouse",movable:"movable",moveType:"moveType",musicName:"musicName",musicVolume:"musicVolume",name:"name",numParticles:"numParticles",numberOfInputs:"numberOfInputs",note:"note",notes:"notes",offsetAngle:"offsetAngle",offsetx:"offsetx",offsety:"offsety",operator:"operator",origin:"origin",page:"page",pair:"pair",pitch:"pitch",physics:"physics",portrait:"portrait",portraitUpsideDown:"portraitUpsideDown",position:"position",positional:"positional",positionSpace:"positionSpace",preloadArt:"preloadArt",preserveCurrentScene:"preserveCurrentScene",protocol:"protocol",prototypeKey:"prototypeKey",purchase:"purchase",purchases:"purchases",red:"red",restitution:"restitution",restoreActorImage:"restoreActorImage",returnAttribute:"returnAttribute",RHS:"RHS",rotation:"rotation",row:"row",rowNumber:"rowNumber",runToCompletion:"runToCompletion",scene:"scene",sceneKey:"sceneKey",screen:"screen",scrollable:"scrollable",services:"services",size:"size",sizeChange:"sizeChange",sizeTarget:"sizeTarget",sizeTransitionTime:"sizeTransitionTime",soundName:"soundName",soundVolume:"soundVolume",space:"space",spacing:"spacing",speed:"speed",startCell:"startCell",startCellExpression:"startCellExpression",startupTime:"startupTime",status:"status",subjectAttribute:"subjectAttribute",table:"table",tablecolumnassignment:"tablecolumnassignment",tableID:"tableID",tags:"tags",targetAttribute:"targetAttribute",text:"text",tileHeight:"tileHeight",tileWidth:"tileWidth",time:"time",timerType:"timerType",touch1:"touch1",touch10:"touch10",touch11:"touch11",touch2:"touch2",touch3:"touch3",touch4:"touch4",touch5:"touch5",touch6:"touch6",touch7:"touch7",touch8:"touch8",touch9:"touch9",touches:"touches",trackingArea:"trackingArea",useExternalBrowser:"useExternalBrowser",usePositionalSound:"usePositionalSound",URL:"URL",verticalAnchor:"verticalAnchor",verticalWrap:"verticalWrap",visible:"visible",volume:"volume",width:"width",wrap:"wrap",wrapX:"wrapX",wrapY:"wrapY",x:"x",y:"y",z:"z",flipHorizontally:"flipHorizontally",flipVertically:"flipVertically",attributes:"attributes",point:"point",rect:"rect",collision:"collision",mousePosition:"mousePosition",touch:"touch",auto:"auto-rotation",number:"number",string:"string",enumeration:"enumeration",clock:"clock",year:"year",month:"month",day:"day","boolean":"boolean"});gs.CompoundAttribute.loadFromLite=function(f,a){var b=gs.CompoundAttribute.obfuscationLookupTable;for(var c in f){var g=f[c];var d=b[c]||c;if(!d){d=g.id}var e=this[d];if(!e){e=gs.Attribute.provide().init();this.addObjectAtEnd(e,d)}e.loadFromLite(g,a)}};gs.CompoundAttribute.loadFromTable=function(k,b){var c=gs.Parser.compoundAttributeClassMap;var e=gs.CompoundAttribute.obfuscationLookupTable;for(var g=0,h=k.length;g<h;++g){var d=k[g];var l=d[gs.JXON._type];var j=e[d.id];if(!j){j=d.id;if(!d.name&&l!=="compound"&&l!=="array"){}}var i=c[e[l]];if(!i){var a=this[j];if(!a){a=gs.Attribute.provide().init();this.addObjectAtEnd(a,j)}a.loadFromTable(d,b)}else{var f=this[j];if(typeof(f)!="object"){f=i.provide().init();this.addObjectAtEnd(f,j);if(d[gs.JXON._children]){f.loadFromTable(d[gs.JXON._children],b)}else{f.loadFromTable(d,b)}}else{if(d[gs.JXON._children]){f.loadFromTable(d[gs.JXON._children],b)}}}}};gs.ColorAttribute=gs.CompoundAttribute.subclass("ColorAttribute");gs.ColorAttribute.defaultColor={red:1,green:1,blue:1,alpha:1};gs.ColorAttribute.init=function(){gs.CompoundAttribute.init.call(this);return this};gs.ColorAttribute.initWithValues=function(e){e=e||gs.ColorAttribute.defaultColor;var d=e.red;var b=e.green;var a=e.blue;var c=e.alpha;this.addReservedAttribute("red",d,"real",gs.NumberConstraint.ZeroToOneInclusiveRange);this.addReservedAttribute("green",b,"real",gs.NumberConstraint.ZeroToOneInclusiveRange);this.addReservedAttribute("blue",a,"real",gs.NumberConstraint.ZeroToOneInclusiveRange);this.addReservedAttribute("alpha",c,"real",gs.NumberConstraint.ZeroToOneInclusiveRange);return this};gs.ColorAttribute.getType=function(){return"color"};gs.ColorAttribute.getValue=function(){return({red:this.red._value,green:this.green._value,blue:this.blue._value,alpha:this.alpha._value})};gs.ColorAttribute.setValue=function(a){this.red.setValue(a.red);this.green.setValue(a.green);this.blue.setValue(a.blue);this.alpha.setValue(a.alpha)};gs.ColorAttribute.fastSetValue=function(a){this.red.fastSetValue(a.red);this.green.fastSetValue(a.green);this.blue.fastSetValue(a.blue);this.alpha.fastSetValue(a.alpha)};gs.ColorAttribute.setComponentValue=function(f,e,c,d){this.red.setValueForKey(f,"value");this.green.setValueForKey(e,"value");this.blue.setValueForKey(c,"value");this.alpha.setValueForKey(d,"value")};gs.ExpressionAttribute=gs.Attribute.subclass("ExpressionAttribute");gs.ExpressionAttribute.create=gs.PrototypicalDictionary.create;gs.ExpressionAttribute.init=function(){gs.Attribute.init.call(this);this._expression=null;this._hasExpression=false;return this};gs.ExpressionAttribute.initPrime=function(){gs.Attribute.initPrime.call(this);this._expression=null;this._hasExpression=false;return this};gs.ExpressionAttribute.clone=function(){var a=gs.PrototypicalDictionary.clone.call(this);a._value=this._initialValue;a._type=this._type;a._constraint=this._constraint;a._initialValue=this._initialValue;a._hasExpression=this._hasExpression;return a};gs.ExpressionAttribute.expression=function(){return this._expression};gs.ExpressionAttribute.setExpression=function(a){this.setObjectForKey(a,"_expression");this.setHasExpression(!!a)};gs.ExpressionAttribute.setHasExpression=function(a){this._hasExpression=a;this.notifyObserversOfChange("hasExpression",a)};gs.ExpressionAttribute.hasExpression=function(){return this._hasExpression};gs.ExpressionAttribute.clearExpression=function(){this.removeObjectForKey("_expression");this.setHasExpression(false)};gs.ExpressionAttribute.getValue=function(){if(this._hasExpression){var c=this._expression;if(c.delegate!==this){c.delegate=this;var a=this._parent;while(!a._entity){a=a._parent}this._entity=a._entity}if(c.needsUpdate){var b=c.evaluateForEntity(this._entity);if(this._value!==b){this._value=b;this.notifyObserversOfValueChange(b)}}}return this._value};gs.ExpressionAttribute.expressionInputsChanged=function(){if(this._observed){var a=this._expression.evaluateForEntity(this._entity);this.fastSetValue(a)}};gs.ExpressionAttribute.releaseExpressionInputs=function(){if(this._hasExpression){var a=this._expression;a.releaseInputs();a.delegate=null;this._entity=null}this._node=null;this._observed=false};gs.ExpressionAttribute.loadFromLite=function(b,a){if(typeof b==="object"){var c=gs.Parser.parseExpression(b.expression);if(c.expressionTree.useConstant){this.setValue(c.expressionTree.evaluateRoot())}else{this.setExpression(c)}}else{this.setValue(b)}if(a){this._initialValue=this._value}};gs.ExpressionAttribute.loadFromTable=function(d,a){var e=d[gs.JXON._type];if(e!=="attribute"&&!this._type){this.setType(e)}var b=d[gs.JXON._text];var g=typeof(b);if(g==="undefined"){var c=d[gs.JXON._children][0];var f=gs.Parser.parseExpression(c);this.setExpression(f)}else{this.setValue(b)}if(a){this._initialValue=this._value}};gs.ExpressionAttribute.restoreInitialState=function(){this._value=this._initialValue;if(this._expression){this._expression.needsUpdate=true}};gs.PointAttribute=gs.CompoundAttribute.subclass("PointAttribute");gs.PointAttribute.defaultPoint={x:0,y:0};gs.PointAttribute.init=function(){gs.CompoundAttribute.init.call(this);return this};gs.PointAttribute.returnVec=[0,0];gs.PointAttribute.initWithValues=function(d,b){d=d||gs.PointAttribute.defaultPoint;var a=d.x;var c=d.y;if(b){this.addExpressionAttribute("x",a,"real");this.addExpressionAttribute("y",c,"real")}else{this.addReservedAttribute("x",a,"real");this.addReservedAttribute("y",c,"real")}return this};gs.PointAttribute.getType=function(){return"point"};gs.PointAttribute.getValue=function(){var a=gs.PointAttribute.returnVec;a[0]=this.x.getValue();a[1]=this.y.getValue();return a};gs.PointAttribute.setValue=function(a){this.x.setValue(a[0]);this.y.setValue(a[1])};gs.PointAttribute.fastSetValue=function(a){this.x.fastSetValue(a[0]);this.y.fastSetValue(a[1])};gs.RectAttribute=gs.CompoundAttribute.subclass("RectAttribute");gs.RectAttribute.defaultOrigin={x:0,y:0};gs.RectAttribute.defaultSize={width:1,height:1};gs.RectAttribute.init=function(){gs.CompoundAttribute.init.call(this);return this};gs.RectAttribute.initWithValues=function(c){var a=c||gs.RectAttribute.defaultOrigin;var b=c||gs.RectAttribute.defaultSize;this.addReservedCompoundAttribute("origin","point",a);this.addReservedCompoundAttribute("size","size",b);return this};gs.RectAttribute.getType=function(){return"rect"};gs.RectAttribute.getValue=function(a){a.x=this.origin.x.getValue();a.y=this.origin.y.getValue();a.width=this.size.width.getValue();a.height=this.size.height.getValue()};gs.RectAttribute.setValue=function(a){this.origin.x.setValue(a.x);this.origin.y.setValue(a.y);this.size.width.setValue(a.width);this.size.height.setValue(a.height)};gs.RectAttribute.fastSetValue=function(a){this.origin.x.fastSetValue(a.x);this.origin.y.fastSetValue(a.y);this.size.width.fastSetValue(a.width);this.size.height.fastSetValue(a.height)};gs.SizeAttribute=gs.CompoundAttribute.subclass("SizeAttribute");gs.SizeAttribute.defaultSize={width:1,height:1};gs.SizeAttribute.init=function(){gs.CompoundAttribute.init.call(this);return this};gs.SizeAttribute.initWithValues=function(c){c=c||gs.SizeAttribute;var b=c.width;var a=c.height;this.addReservedAttribute("width",b,"real",gs.NumberConstraint.PositiveReal);this.addReservedAttribute("height",a,"real",gs.NumberConstraint.PositiveReal);this.returnVec=[b,a];return this};gs.SizeAttribute.getType=function(){return"size"};gs.SizeAttribute.getValue=function(){var a=this.returnVec;a[0]=this.width.getValue();a[1]=this.height.getValue();return a};gs.SizeAttribute.setValue=function(a){this.width.setValue(a[0]);this.height.setValue(a[1])};gs.SizeAttribute.fastSetValue=function(a){this.width.fastSetValue(a[0]);this.height.fastSetValue(a[1])};gs.TableAttribute=gs.Attribute.subclass("TableAttribute",{init:function(a){gs.Attribute.init.call(this);this.setType("table");this.id=a;this._tableData=new gs.tables.Table();this.rowOffsetLookup=gs.Map.provide();this.columnOffsetLookup=gs.Map.provide();return this},getValue:function(){return this},getType:function(){return"table"},hasCell:function(d,b){var c=String(d);var a=String(b);return this._tableData.hasCell(c,a)},getCellSafe:function(d,b){var a=this.lookupRow(d);var c=this.lookupColumn(b);return this._tableData.getCellByIndex(a,c)},getRowCount:function(){return this._tableData.rowCount},getColumnCount:function(){return this._tableData.columnCount},lookupRow:function(c){var a=this.rowOffsetLookup;var b=a[c];if(b===undefined){b=this._tableData.lookupRow(c);a[c]=b}return b},lookupColumn:function(a){var b=this.columnOffsetLookup;var c=b[a];if(c===undefined){c=this._tableData.lookupColumn(a);b[a]=c}return c},getName:function(){return this._tableData.name},setCell:function(d,b,c){var a=this._tableData.setCellByIndex(d,b,c);if(c!==a){this.notifyObserversOfValueChange(this)}},setCellSafe:function(f,c,e){var b=this.lookupRow(f);var d=this.lookupColumn(c);var a=this._tableData.setCellByIndex(b,d,e);if(e!==a){this.notifyObserversOfValueChange(this)}},addRow:function(a){if(a===-1){this._tableData.insertRowAtEnd()}else{this._tableData.insertRow(a)}this.notifyObserversOfValueChange(this)},removeRow:function(a){this._tableData.removeRow(a);this.notifyObserversOfValueChange(this)},getTableData:function(){return this._tableData},copyTable:function(a){this._tableData.copyFromOtherTable(a.getTableData());this.notifyObserversOfValueChange(this)},sumColumn:function(e,d,a){d=this.lookupColumn(d);a=this.lookupColumn(a);var c=0;for(var b=d;b<a;b++){c+=this.getCellSafe(b,e)}return c},mergeRowValues:function(h,e,b,g){e=this.lookupColumn(e);b=this.lookupColumn(b);var f=e>b?-1:1;b+=f;var d="";var a=false;for(var c=e;c!==b;c+=f){if(a){d+=g}d+=this.getCellSafe(h,c);a=true}return d},mergeColumnValues:function(f,e,b,h){e=this.lookupRow(e);b=this.lookupRow(b);var g=e>b?-1:1;b+=g;var d="";var a=false;for(var c=e;c!==b;c+=g){if(a){d+=h}d+=this.getCellSafe(c,f);a=true}return d},searchRow:function(d,h,e,b,a){d=this.ensureString(d);e=this.lookupColumn(e);b=this.lookupColumn(b);var g=e>b?-1:1;b+=g;for(var c=e;c!==b;c+=g){var f=this.getCellSafe(h,c);f=this.ensureString(f);if(this.matchPredicate(d,f,a)){return c}}return 0},searchColumn:function(d,f,e,b,a){d=this.ensureString(d);e=this.lookupRow(e);b=this.lookupRow(b);var h=e>b?-1:1;b+=h;for(var c=e;c!==b;c+=h){var g=this.getCellSafe(c,f);g=this.ensureString(g);if(this.matchPredicate(d,g,a)){return c}}return 0},ensureString:function(a){if(typeof a!=="string"){return String(a)}return a},matchPredicate:function(b,c,a){switch(a){case"exact":return c===b;case"not exact":return c!==b;case"beginsWith":return gs.string.beginsWith(c,b);case"not beginsWith":return !gs.string.beginsWith(c,b);case"endsWith":return gs.string.endsWith(c,b);case"not endsWith":return !gs.string.endsWith(c,b);case"contains":return gs.string.contains(c,b);case"not contains":return !gs.string.contains(c,b)}},loadFromLite:function(b,a){var c=b.id;if(c){this.id=c}this._tableData.setId(this.id)},loadFromTable:function(a){this.id=gs.JXON.id(a);this._tableData.setId(this.id)},loadTableData:function(c){var b=this._tableData;var d=this.id;var a=gs.tables.loadFromPersistence(b,d);if(!a){c.loadTableById(this.id).then(function(e){var f=e.getData();if(f){b.parseFromLite(f)}})}}});gs.PairAttribute=gs.CompoundAttribute.subclass("PairAttribute",{init:function(){gs.CompoundAttribute.init.call(this);this.addExpressionAttribute("first","");this.addExpressionAttribute("second","");return this},getType:function(){return"pair"},loadFromLite:function(b,a){this.addExpressionAttribute("first","");this.addExpressionAttribute("second","");this.first.loadFromLite(b.column);this.second.loadFromLite(b.rhsvalue)},loadFromTable:function(c,a){var d=gs.Attribute.loadFromTableStatic(c[0],a);this.addObjectAtIndex(d,null,"first");var b=gs.Attribute.loadFromTableStatic(c[1],a);this.addObjectAtIndex(b,null,"second")}});gs.ArrayAttribute=gs.CompoundAttribute.subclass("ArrayAttribute",{init:function(){gs.CompoundAttribute.init.call(this);return this},getType:function(){return"array"},size:function(){return this.array.length},at:function(a){return this.array[a-1]},loadFromLite:function(e,a){if(Array.isArray(e)){for(var d=0;d<e.length;d++){var f=e[d];var c=f.id||this.generateUniqueObjectKey();var b=new gs.PairExpressionAttribute();b.loadFromLite(f,a);this.addObjectAtEnd(b,c)}}else{var c=e.id||this.generateUniqueObjectKey();var b=new gs.PairExpressionAttribute();b.loadFromLite(e,a);this.addObjectAtEnd(b,c)}},loadFromTable:function(f,a){for(var e=0;e<f.length;e++){var b=f[e];var d=b.id||this.generateUniqueObjectKey();var c=gs.Attribute.loadFromTableStatic(b,a);this.addObjectAtEnd(c,d)}}});gs.AttributeBase=function(){};gs.AttributeBase.prototype={};gs.AttributeCollectionBase=function(){this._isConstant=false;this._objectKey=null;this._parent=null};gs.AttributeCollectionBase.ignoreAttributeKey={name:true,bundleName:true,note:true,conditionType:true};gs.AttributeCollectionBase.prototype=gs.subclass(Object,{addReservedCompoundAttribute:function(d,b,f,c){this._isConstant=false;var a=gs.CompoundAttribute;if(b){a=gs.Parser.compoundAttributeClassMap[b]}var e=a.provide();e.initWithValues(f,c);this.addAttribute(d,e);e._parent=this;return e},addReservedAttribute:function(d,a,c,b){this._isConstant=false;var e=gs.Attribute.provide().initWithTypeAndValue(c,a);if(b){e.setConstraint(b)}this.addAttribute(d,e);return e},addExpressionAttribute:function(d,a,c,b){this._isConstant=false;var e=gs.ExpressionAttribute.provide().initWithTypeAndValue(c,a);if(b){e.setConstraint(b)}this.addAttribute(d,e);e._parent=this;return e},addTableAttribute:function(a){this._isConstant=false;var b=gs.TableAttribute.provide().init(a);this.addAttribute(a,b);b._parent=this},addImmutableAttributeCollection:function(a){this._isConstant=false;var b=new gs.ImmutableAttributeCollection();this.addAttribute(a,b)},addBooleanImmutableAttribute:function(a,c){var b=new gs.BooleanImmutableAttribute(c);this.addAttribute(a,b)},addIntegerImmutableAttribute:function(a,c){var b=new gs.IntegerImmutableAttribute(c);this.addAttribute(a,b)},addRealImmutableAttribute:function(a,c){var b=new gs.RealImmutableAttribute(c);this.addAttribute(a,b)},addReferenceImmutableAttribute:function(a){var b=new gs.ReferenceImmutableAttribute();this.addAttribute(a,b)},addStringImmutableAttribute:function(a,c){var b=new gs.StringImmutableAttribute(c);this.addAttribute(a,b)},addColorImmutableAttribute:function(e,i,h,c,d){this._isConstant=false;var f=new gs.ColorImmutableAttribute();f.red.changeDefaultValue(i);f.green.changeDefaultValue(h);f.blue.changeDefaultValue(c);f.alpha.changeDefaultValue(d);this.addAttribute(e,f);f._parent=this},addBooleanMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.BooleanMutableAttribute(c);this.addAttribute(a,b)},addIntegerMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.IntegerMutableAttribute(c);this.addAttribute(a,b)},addIntegerPositiveMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.IntegerPositiveMutableAttribute(c);this.addAttribute(a,b)},addRealMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.RealMutableAttribute(c);this.addAttribute(a,b)},addRealAngleMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.RealAngleMutableAttribute(c);this.addAttribute(a,b)},addRealPositiveMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.RealPositiveMutableAttribute(c);this.addAttribute(a,b)},addRealNormalizedMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.RealNormalizedMutableAttribute(c);this.addAttribute(a,b)},addRealConstrainedMutableAttribute:function(c,e,b,a){this._isConstant=false;var d=new gs.RealConstrainedMutableAttribute(e,b,a);this.addAttribute(c,d)},addStringMutableAttribute:function(a,c){this._isConstant=false;var b=new gs.StringMutableAttribute(c);this.addAttribute(a,b)},addPointMutableAttribute:function(b,a,d){this._isConstant=false;var c=new gs.PointMutableAttribute();c.x.setValue(a);c.y.setValue(d);this.addAttribute(b,c)},addSizeMutableAttribute:function(b,c,a){this._isConstant=false;var d=new gs.SizeMutableAttribute();d.width.setValue(c);d.height.setValue(a);this.addAttribute(b,d);d._parent=this},addColorMutableAttribute:function(e,i,h,c,d){this._isConstant=false;var f=new gs.ColorMutableAttribute();f.red.setValue(i);f.green.setValue(h);f.blue.setValue(c);f.alpha.setValue(d);this.addAttribute(e,f);f._parent=this},addIntegerExpressionAttribute:function(a,c){this._isConstant=false;var b=new gs.IntegerExpressionAttribute(c);this.addAttribute(a,b);b._parent=this},addRealExpressionAttribute:function(a,c){this._isConstant=false;var b=new gs.RealExpressionAttribute(c);this.addAttribute(a,b);b._parent=this},addStringExpressionAttribute:function(a,c){this._isConstant=false;var b=new gs.StringExpressionAttribute(c);this.addAttribute(a,b);b._parent=this},addVariantExpressionAttribute:function(a,c){this._isConstant=false;var b=new gs.VariantExpressionAttribute(c);this.addAttribute(a,b);b._parent=this},addPointExpressionAttribute:function(b,a,d){this._isConstant=false;var c=new gs.PointExpressionAttribute();c.x.setValue(a);c.y.setValue(d);this.addAttribute(b,c);c._parent=this},addAttribute:function(a,b){this[a]=b},clone:function(){if(this._isConstant){return this}var a=new gs.ImmutableAttributeCollection();a._isConstant=this._isConstant;for(var b in this){if(this.hasOwnProperty(b)){var c=this[b];if(c&&typeof c==="object"&&c!==this._parent){var d=c.clone();if(c._parent===this){d._parent=a}a[b]=d}}}return a},restoreInitialState:function(){for(var a in this){if(this.hasOwnProperty(a)){var b=this[a];if(b&&typeof b==="object"&&b!==this._parent){b.restoreInitialState()}}}},releaseExpressionInputs:function(){for(var a in this){if(this.hasOwnProperty(a)){var b=this[a];if(b&&typeof b==="object"&&b!==this._parent){if(b.releaseExpressionInputs){b.releaseExpressionInputs()}}}}},valueForKeypathArray:function(f){var e=this;var a=gs.CompoundAttribute.obfuscationLookupTable;for(var c=0,d=f.length;e&&c<d;c++){var b=f[c];b=a[b]||b;e=e[b]}return e},loadFromLite:function(d,a){for(var b in d){var c=this[b];if(c){if(typeof d[b]==="object"&&d[b].hasOwnProperty("$")){d[b]=d[b]["$"]}c.loadFromLite(d[b],a)}else{if(!gs.AttributeCollectionBase.ignoreAttributeKey[b]){gs.Log.debug("Unrecognized attribute:",b)}}}},loadFromTable:function(m,b){var d=gs.Parser.compoundAttributeClassMap;var e=gs.CompoundAttribute.obfuscationLookupTable;var n=gs.JXON;var j=n._type;var g=n._children;for(var f=0,l=m.length;f<l;f++){var c=m[f];var o=c[j];var k=e[c.id];if(!k){k=c.id}var a=this[k];if(!a){}else{var h=d[e[o]];if(!h){a.loadFromTable(c,b)}else{if(c[g]){a.loadFromTable(c[g],b)}}}}}});gs.ImmutableAttributeCollection=function(){gs.AttributeCollectionBase.call(this);this._isConstant=true};gs.ImmutableAttributeCollection.prototype=gs.subclass(gs.AttributeCollectionBase,{clone:function(){if(this._isConstant){return this}var a=new gs.ImmutableAttributeCollection();a._isConstant=this._isConstant;for(var b in this){if(this.hasOwnProperty(b)){var c=this[b];if(c&&typeof c==="object"&&c!==this._parent){var d=c.clone();if(c._parent===this){d._parent=a}a[b]=d}}}return a},loadFromLite:function(f,a){var b=gs.CompoundAttribute.obfuscationLookupTable;for(var c in f){var g=f[c];var d=b[c]||c;var e=this[d];if(e){if(typeof g==="object"&&g.hasOwnProperty("$")){g=g["$"]}e.loadFromLite(g,a)}else{if(!gs.AttributeCollectionBase.ignoreAttributeKey[c]){gs.Log.debug("Unrecognized attribute:",c)}}}}});gs.MutableAttributeCollection=function(){gs.AttributeCollectionBase.call(this)};gs.MutableAttributeCollection.prototype=gs.subclass(gs.AttributeCollectionBase,{clone:function(){var a=new gs.MutableAttributeCollection();for(var b in this){if(this.hasOwnProperty(b)){var c=this[b];if(c&&typeof c==="object"&&c!==this._parent){var d=c.clone();if(c._parent===this){d._parent=a}a[b]=d}}}return a},loadFromLite:function(g,a){var b=gs.CompoundAttribute.obfuscationLookupTable;for(var c in g){var h=g[c];var d=b[c]||c;var f=this[d];if(!f){var e=h["@"];d=c;switch(e){case"boolean":this.addBooleanMutableAttribute(d,false);break;case"integer":this.addIntegerMutableAttribute(d,0);break;case"index":this.addIntegerPositiveMutableAttribute(d,0);break;case"real":this.addRealMutableAttribute(d,0);break;case"angle":this.addRealAngleMutableAttribute(d,0);break;case"table":this.addTableAttribute(d);break;default:this.addStringMutableAttribute(d,"")}f=this[d]}if(typeof h==="object"&&h.hasOwnProperty("$")&&e!=="table"){h=h["$"]}f.loadFromLite(h,a)}}});gs.ImmutableAttribute=function(){};gs.ImmutableAttribute.prototype={getValue:function(){return this._value},getValueForEntity:function(a){return this._value},getValueForEntityStateless:function(a){return this._value},loadFromLite:function(b,a){},loadFromTable:function(a){},clone:function(){return this},changeDefaultValue:function(a){this._value=a},connectToSprite:function(a,b,c){a[b]=this._value;a[c]=true},disconnectFromSprite:function(){},hasExpression:function(){return false},addObserver:function(a){},removeObserver:function(a){},releaseExpressionInputs:function(){}};gs.inherits(gs.ImmutableAttribute,gs.AttributeBase);gs.BooleanImmutableAttribute=function(a){this._value=a};gs.BooleanImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttribute,{getValue:function(){return this._value},loadFromLite:function(b,a){switch(b){case"true":case"1":this._value=true;break;case"false":case"0":this._value=false;break;default:this._value=Boolean(b);break}},loadFromTable:function(a){var b=a[gs.JXON._text];switch(b){case"true":case"1":this._value=true;break;case"false":case"0":this._value=false;break;default:this._value=Boolean(b);break}}});gs.IntegerImmutableAttribute=function(a){this._value=a};gs.IntegerImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttribute,{getValue:function(){return this._value},loadFromLite:function(b,a){this._value=Math.round(Number(b))},loadFromTable:function(a){this._value=Math.round(Number(a[gs.JXON._text]))}});gs.RealImmutableAttribute=function(a){this._value=a};gs.RealImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttribute,{getValue:function(){return this._value},loadFromLite:function(b,a){this._value=Number(b)},loadFromTable:function(a){this._value=Number(a[gs.JXON._text])}});gs.ReferenceImmutableAttribute=function(){this._value=null};gs.ReferenceImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttribute,{getValue:function(){return this._value},loadFromLite:function(c,a){var b=typeof c==="object"?c["$"]:c;if(b){this._value=gs.Reference.lookup(b)}else{this._value=null}},loadFromTable:function(b){var a=b[gs.JXON._text];if(a){this._value=gs.Reference.lookup(a)}else{this._value=null}}});gs.StringImmutableAttribute=function(a){this._value=a};gs.StringImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttribute,{getValue:function(){return this._value},loadFromLite:function(b,a){this._value=String(b)},loadFromTable:function(a){this._value=String(a[gs.JXON._text])}});gs.ColorImmutableAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addRealImmutableAttribute("red",0);this.addRealImmutableAttribute("green",0);this.addRealImmutableAttribute("blue",0);this.addRealImmutableAttribute("alpha",0)};gs.ColorImmutableAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){return this}});gs.MutableAttribute=function(){this._observed=false;this._observer=null;this._observers=null;this.sprite=null;this.spriteValueKey=null;this.spriteDirtyKey=null};gs.MutableAttribute.prototype={constrainValue:function(a){return a},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},notifyObserversOfValueChange:function(b){if(this.sprite){this.sprite[this.spriteValueKey]=b;this.sprite[this.spriteDirtyKey]=true}var c=this._observers;if(c){for(var a=0;a<c.length;a++){c[a].observeValueChange(this,b)}}else{if(this._observer){this._observer.observeValueChange(this,b)}}},loadFromLite:function(b,a){this.setValue(typeof b==="object"?b["$"]:b);if(a){this._initialValue=this._value}},loadFromTable:function(c,a){var b=c[gs.JXON._text];this.setValue(b);if(a){this._initialValue=this._value}},restoreInitialState:function(){this._value=this._initialValue},clone:function(){return new gs.MutableAttribute()},addObserver:function(a){this._observed=true;var b=this._observers;if(b){b.push(a)}else{if(this._observer){b=gs.array.provide();b.push(this._observer);this._observer=null;b.push(a);this._observers=b}else{this._observer=a}}},removeObserver:function(a){var c=this._observers;if(c){var b=c.indexOf(a);if(b!==-1){c.splice(b,1)}this._observed=this.sprite||this.node||c.length>0;if(c.length===0){gs.array.recycle(c);this._observers=null}}else{if(a===this._observer){this._observer=null;this._observed=this.sprite||this.node}}},connectToSprite:function(a,b,c){this.sprite=a;this.spriteValueKey=b;this.spriteDirtyKey=c;a[b]=this.getValue();a[c]=true;this._observed=true},disconnectFromSprite:function(){this.sprite=null;this.spriteValueKey=null;this.spriteDirtyKey=null;this._observed=this._observers&&this._observers.length>0}};gs.inherits(gs.MutableAttribute,gs.AttributeBase);gs.BooleanMutableAttribute=function(a){gs.MutableAttribute.call(this);this._value=a;this._initialValue=a};gs.BooleanMutableAttribute.prototype=gs.subclass(gs.MutableAttribute,{constrainValue:function(a){switch(a){case"true":case"1":return true;case"false":case"0":return false;default:return Boolean(a)}},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.BooleanMutableAttribute(this._initialValue)}});gs.IntegerMutableAttribute=function(a){gs.MutableAttribute.call(this);this._value=a;this._initialValue=a};gs.IntegerMutableAttribute.prototype=gs.subclass(gs.MutableAttribute,{constrainValue:function(a){if(typeof a==="number"){return Math.round(a)}var b=Number(a);if(!isNaN(b)){return Math.round(b)}if(typeof a==="string"&&a==="true"){return 1}return 0},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.IntegerMutableAttribute(this._initialValue)}});gs.IntegerPositiveMutableAttribute=function(a){gs.IntegerMutableAttribute.call(this,a)};gs.IntegerPositiveMutableAttribute.prototype=gs.subclass(gs.IntegerMutableAttribute,{constrainValue:function(b){var a=gs.IntegerMutableAttribute.prototype.constrainValue.call(this,b);return a<0?0:a},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.IntegerPositiveMutableAttribute(this._initialValue)}});gs.RealMutableAttribute=function(a){gs.MutableAttribute.call(this);this._value=a;this._initialValue=a;this._node=null};gs.RealMutableAttribute.prototype=gs.subclass(gs.MutableAttribute,{constrainValue:function(a){if(typeof a==="number"){return a}var b=Number(a);if(!isNaN(b)){return b}if(typeof a==="string"&&a==="true"){return 1}return 0},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.RealMutableAttribute(this._initialValue)},getNode:function(){var a=this._node;if(!a){var a=gs.SGAttributeNode.provide();this._node=a;this._observed=true}a.setValue(this.getValue());return a},notifyObserversOfValueChange:function(b){var a=this._node;if(a){a.setValue(b)}gs.MutableAttribute.prototype.notifyObserversOfValueChange.call(this,b)}});gs.RealAngleMutableAttribute=function(a){gs.RealMutableAttribute.call(this,a)};gs.RealAngleMutableAttribute.prototype=gs.subclass(gs.RealMutableAttribute,{constrainValue:function(a){var b=gs.RealMutableAttribute.prototype.constrainValue.call(this,a);if(b<0){b=(b%360)+360}return b%360},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.RealAngleMutableAttribute(this._initialValue)}});gs.RealPositiveMutableAttribute=function(a){gs.RealMutableAttribute.call(this,a)};gs.RealPositiveMutableAttribute.prototype=gs.subclass(gs.RealMutableAttribute,{constrainValue:function(a){var b=gs.RealMutableAttribute.prototype.constrainValue.call(this,a);return b<0?0:b},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.RealPositiveMutableAttribute(this._initialValue)}});gs.RealNormalizedMutableAttribute=function(a){gs.RealMutableAttribute.call(this,a)};gs.RealNormalizedMutableAttribute.prototype=gs.subclass(gs.RealMutableAttribute,{constrainValue:function(a){var b=gs.RealMutableAttribute.prototype.constrainValue.call(this,a);return b<0?0:b>1?1:b},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.RealNormalizedMutableAttribute(this._initialValue)}});gs.RealConstrainedMutableAttribute=function(c,b,a){gs.RealMutableAttribute.call(this,c);this.min=b;this.max=a};gs.RealConstrainedMutableAttribute.prototype=gs.subclass(gs.RealMutableAttribute,{constrainValue:function(a){var b=gs.RealMutableAttribute.prototype.constrainValue.call(this,a);return b>this.max?this.max:b<this.min?this.min:b},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.RealConstrainedMutableAttribute(this._initialValue,this.min,this.max)}});gs.StringMutableAttribute=function(a){gs.MutableAttribute.call(this);this._value=a;this._initialValue=a};gs.StringMutableAttribute.prototype=gs.subclass(gs.MutableAttribute,{constrainValue:function(a){return gs.Attribute.convertValueToString(a)},getValue:function(){return this._value},setValue:function(a){if(this._value!==a){a=this.constrainValue(a);this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},fastSetValue:function(a){if(this._value!==a){this._value=a;if(this._observed){this.notifyObserversOfValueChange(a)}}},clone:function(){return new gs.StringMutableAttribute(this._initialValue)}});gs.PointMutableAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addRealMutableAttribute("x",0);this.addRealMutableAttribute("y",0)};gs.PointMutableAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){var a=new gs.PointMutableAttribute();a._objectKey=this._objectKey;a._isConstant=this._isConstant;a.addAttribute("x",this.x.clone());a.addAttribute("y",this.y.clone());return a}});gs.SizeMutableAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addRealMutableAttribute("width",0);this.addRealMutableAttribute("height",0)};gs.SizeMutableAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){var a=new gs.SizeMutableAttribute();a._objectKey=this._objectKey;a._isConstant=this._isConstant;a.addAttribute("width",this.width.clone());a.addAttribute("height",this.height.clone());return a}});gs.ColorMutableAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addRealNormalizedMutableAttribute("red",0);this.addRealNormalizedMutableAttribute("green",0);this.addRealNormalizedMutableAttribute("blue",0);this.addRealNormalizedMutableAttribute("alpha",0)};gs.ColorMutableAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){var a=new gs.ColorMutableAttribute();a._objectKey=this._objectKey;a._isConstant=this._isConstant;a.addAttribute("red",this.red.clone());a.addAttribute("green",this.green.clone());a.addAttribute("blue",this.blue.clone());a.addAttribute("alpha",this.alpha.clone());return a}});gs.ExpressionAttributeBase=function(){gs.MutableAttribute.call(this);this._parent=null;this._entity=null;this.expression=null};gs.ExpressionAttributeBase.prototype=gs.subclass(gs.MutableAttribute,{setValue:function(a){this._value=a},setExpression:function(a){this.expression=a;a._parent=this;a.delegate=this},getValue:function(){var a=this.expression;if(a&&a.needsUpdate){this.update()}return this._value},getValueForEntity:function(a){var b=this.expression;if(b&&b.needsUpdate){this.update(a)}return this._value},getValueForEntityStateless:function(a){var b=this.expression;if(b){return b.evaluateForEntityStateless(a)}return this._value},update:function(a){if(!this._entity||this._entity!==a){if(a){this._entity=a}else{var b=this._parent;while(!b._entity){b=b._parent}this._entity=b._entity}}var c=this.expression.evaluateForEntity(this._entity);if(this._value!==c){this._value=c;this.notifyObserversOfValueChange(c)}},loadFromLite:function(b,a){if(typeof b==="object"){if(b.expression){var c=gs.Parser.parseExpression(b.expression);if(c.expressionTree.useConstant){this._value=c.expressionTree.evaluateRoot()}else{this.setExpression(c)}}else{if(b["$"]!==undefined){this._value=b["$"]}}}else{this._value=b}},loadFromTable:function(c){var b=c[gs.JXON._text];if(typeof b==="undefined"){var a=c[gs.JXON._children][0];var d=gs.Parser.parseExpression(a);if(d.expressionTree.useConstant){this._value=d.expressionTree.evaluateRoot()}else{this.setExpression(d)}}else{this._value=Number(b)}},expressionInputsChanged:function(){if(this._observed){var a=this.expression.evaluateForEntity(this._entity);if(this._value!==a){this._value=a;this.notifyObserversOfValueChange(a)}}},releaseExpressionInputs:function(){var a=this.expression;if(a){a.releaseInputs()}},hasExpression:function(){return this.expression!==null},clone:function(){if(!this.expression){return new gs.RealImmutableAttribute(this._value)}else{var a=new gs.RealExpressionAttribute(this._value);if(this.expression){a.setExpression(this.expression.clone())}return a}}});gs.IntegerExpressionAttribute=function(a){gs.ExpressionAttributeBase.call(this);this._value=a};gs.IntegerExpressionAttribute.prototype=gs.subclass(gs.ExpressionAttributeBase,{setValue:function(a){this._value=a},getValue:function(){var a=this.expression;if(a&&a.needsUpdate){this.update()}return this._value},getValueForEntity:function(a){var b=this.expression;if(b&&b.needsUpdate){this.update(a)}return this._value},getValueForEntityStateless:function(a){var b=this.expression;if(b){return b.evaluateForEntityStateless(a)}return this._value},loadFromLite:function(b,a){if(typeof b==="object"){var c=gs.Parser.parseExpression(b.expression);if(c.expressionTree.useConstant){this._value=Math.round(Number(c.expressionTree.evaluateRoot()))}else{this.setExpression(c)}}else{this._value=Math.round(Number(b))}},loadFromTable:function(c){var b=c[gs.JXON._text];if(typeof b==="undefined"){var a=c[gs.JXON._children][0];var d=gs.Parser.parseExpression(a);if(d.expressionTree.useConstant){this._value=d.expressionTree.evaluateRoot()}else{this.setExpression(d)}}else{this._value=Math.round(Number(b))}},clone:function(){if(!this.expression){return new gs.IntegerImmutableAttribute(this._value)}else{var a=new gs.IntegerExpressionAttribute(this._value);a.setExpression(this.expression.clone());return a}}});gs.RealExpressionAttribute=function(a){gs.ExpressionAttributeBase.call(this);this._value=a};gs.RealExpressionAttribute.prototype=gs.subclass(gs.ExpressionAttributeBase,{setValue:function(a){this._value=a},getValue:function(){var a=this.expression;if(a&&a.needsUpdate){this.update()}return this._value},getValueForEntity:function(a){var b=this.expression;if(b&&b.needsUpdate){this.update(a)}return this._value},getValueForEntityStateless:function(a){var b=this.expression;if(b){return b.evaluateForEntityStateless(a)}return this._value},loadFromLite:function(b,a){if(typeof b==="object"){var c=gs.Parser.parseExpression(b.expression);if(c.expressionTree.useConstant){this._value=Number(c.expressionTree.evaluateRoot())}else{this.setExpression(c)}}else{this._value=Number(b)}},loadFromTable:function(c){var b=c[gs.JXON._text];if(typeof b==="undefined"){var a=c[gs.JXON._children][0];var d=gs.Parser.parseExpression(a);if(d.expressionTree.useConstant){this._value=d.expressionTree.evaluateRoot()}else{this.setExpression(d)}}else{this._value=Number(b)}},clone:function(){if(!this.expression){return new gs.RealImmutableAttribute(this._value)}else{var a=new gs.RealExpressionAttribute(this._value);a.setExpression(this.expression.clone());return a}}});gs.StringExpressionAttribute=function(a){gs.ExpressionAttributeBase.call(this);this._value=a};gs.StringExpressionAttribute.prototype=gs.subclass(gs.ExpressionAttributeBase,{setValue:function(a){this._value=a},getValue:function(){var a=this.expression;if(a&&a.needsUpdate){this.update()}return this._value},getValueForEntity:function(a){var b=this.expression;if(b&&b.needsUpdate){this.update(a)}return this._value},getValueForEntityStateless:function(a){var b=this.expression;if(b){return b.evaluateForEntityStateless(a)}return this._value},loadFromLite:function(b,a){if(typeof b==="object"){var c=gs.Parser.parseExpression(b.expression);if(c.expressionTree.useConstant){this._value=String(c.expressionTree.evaluateRoot())}else{this.setExpression(c)}}else{this._value=String(b)}},loadFromTable:function(c){var b=c[gs.JXON._text];if(typeof b==="undefined"){var a=c[gs.JXON._children][0];var d=gs.Parser.parseExpression(a);if(d.expressionTree.useConstant){this._value=d.expressionTree.evaluateRoot()}else{this.setExpression(d)}}else{this._value=String(b)}},clone:function(){if(!this.expression){return new gs.StringImmutableAttribute(this._value)}else{var a=new gs.StringExpressionAttribute(this._value);a.setExpression(this.expression.clone());return a}}});gs.VariantExpressionAttribute=function(a){gs.ExpressionAttributeBase.call(this);this._value=a};gs.VariantExpressionAttribute.prototype=gs.subclass(gs.ExpressionAttributeBase,{});gs.PointExpressionAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addRealExpressionAttribute("x",0);this.addRealExpressionAttribute("y",0)};gs.PointExpressionAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){var a=new gs.PointExpressionAttribute();a._objectKey=this._objectKey;a._isConstant=this._isConstant;a.addAttribute("x",this.x.clone());a.addAttribute("y",this.y.clone());a.x._parent=a;a.y._parent=a;return a}});gs.PairExpressionAttribute=function(){gs.ImmutableAttributeCollection.call(this);this.addVariantExpressionAttribute("first","");this.addVariantExpressionAttribute("second","")};gs.PairExpressionAttribute.prototype=gs.subclass(gs.ImmutableAttributeCollection,{clone:function(){var a=new gs.PairExpressionAttribute();a._objectKey=this._objectKey;a._isConstant=this._isConstant;a.addAttribute("first",this.first.clone());a.addAttribute("second",this.second.clone());a.first._parent=a;a.second._parent=a;return a},loadFromLite:function(c,a){delete c["id;"];var b=Object.keys(c);this.first.loadFromLite(c[b[0]]);this.second.loadFromLite(c[b[1]]);gs.array.recycle(b)}});gs.Aspect=gs.PrototypicalImmutableObject.subclass("Aspect");gs.Aspect.actor=function(){var a=this._parent._parent;return a};gs.Aspect.start=function(a,b){};gs.Aspect.stop=function(a,b){};gs.Aspect.evaluate=function(a,b){};gs.Aspect.restoreInitialState=function(){this.attributes.restoreInitialState()};gs.GraphicsAspect=gs.Aspect.subclass("GraphicsAspect");gs.GraphicsAspect.init=function(){gs.Aspect.init.call(this);this.attributes.addBooleanMutableAttribute("visible",false);this.attributes.addIntegerMutableAttribute("blendingMode",0);this.attributes.addIntegerMutableAttribute("horizontalWrap",0);this.attributes.addIntegerMutableAttribute("verticalWrap",0);this.attributes.addIntegerMutableAttribute("horizontalAnchor",0);this.attributes.addIntegerMutableAttribute("verticalAnchor",0);this.attributes.addBooleanMutableAttribute("flipHorizontally",false);this.attributes.addBooleanMutableAttribute("flipVertically",false);this.attributes.addIntegerMutableAttribute("tileWidth",0);this.attributes.addIntegerMutableAttribute("tileHeight",0);return this};gs.MotionAspect=gs.Aspect.subclass("MotionAspect");gs.MotionAspect.init=function(){gs.Aspect.init.call(this);this.attributes.addPointMutableAttribute("linearVelocity",0,0);this.attributes.addRealMutableAttribute("angularVelocity",0);this.attributes.addRealMutableAttribute("maxSpeed",0);this.attributes.addBooleanMutableAttribute("applyMaxSpeed",false);return this};gs.MotionAspect.start=function(b,a){var p=b.scene;var h=b.aspects.physics.attributes;var c=h.movable.getValue();var r=b.attributes.position.x.getValue();var q=b.attributes.position.y.getValue();var l=b.attributes.rotation.getValue();var e=h.angularDrag.getValue();var d=gs.physicsLib.GetBodyDef();d.setPosition(r,q);d.setAngle(l*gsMath.DEG2RAD);d.setFixedRotation(h.fixedRotation.getValue());if(c){d.setType(gs.physicsLib.DYNAMIC_BODY)}else{d.setType(gs.physicsLib.STATIC_BODY)}var k=p._collisionController;this.actorID=k.addCollidableActor(b);this.updateHalfDiagonalFunction=gs.NOOP_FUNCTION;this.calculatedVelocity=gs.array.provide();this.calculatedVelocity[0]=1;this.calculatedVelocity[1]=0;var j=p._world;var f=this._body;if(!f){f=j.createBody(d);this._body=f;if(!f){this.evaluate=gs.NOOP_FUNCTION;return}f.setActorID(this.actorID);var s=b.game();f.addCollisionCategory(s.collisionCategoryManager.categoryIndexForObject(b._prototypeID));var g=b.tags();var o=g.length;for(var n=0;n<o;++n){f.addCollisionCategory(s.collisionCategoryManager.categoryIndexForObject(g[n]))}}this.actor=b;this._updatingself=false;this.wasAwake=true;b.attributes.position.x.addObserver(this);b.attributes.position.y.addObserver(this);b.attributes.rotation.addObserver(this);this._bodyPosition=gs.array.provide();this._bodyPosition[0]=0;this._bodyPosition[1]=0;var m=f.getPosition(this._bodyPosition);this.currentPosition=gs.array.provide();this.currentPosition[0]=m[0];this.currentPosition[1]=m[1];this.currentRotation=f.angle();this.lastRotation=this.currentRotation;this.drag=b.aspects.physics.attributes.drag.getValue();f.setAngularDamping(e);if(!c){this.evaluate=gs.NOOP_FUNCTION;return}this.sceneWidth=p.attributes.size.width.getValue();this.sceneHeight=p.attributes.size.height.getValue();var p=b.scene;if(p.wrappingEnabled()){this.updateHalfDiagonal();this.updateHalfDiagonalFunction=this.updateHalfDiagonal;this.maxDimension=0;this.wrapAxis=gs.Vector2.X_COMPONENT}this.sceneWrapX=p.attributes.wrapX.getValue();if(this.sceneWrapX){this.checkWrappingXMethod=this.checkStartWrappingBodyX;this.destroyXFunction=this.returnFalseFunction;this.checkWrapPositionX(b,f);this.checkWrappingXMethod(b,f)}else{this.checkWrappingXMethod=this.returnFalseFunction;this.destroyXFunction=this.checkDestroyX}this.sceneWrapY=p.attributes.wrapY.getValue();if(this.sceneWrapY){this.checkWrappingYMethod=this.checkStartWrappingBodyY;this.destroyYFunction=this.returnFalseFunction;this.checkWrapPositionY(b,f);this.checkWrappingYMethod(b,f)}else{this.checkWrappingYMethod=this.returnFalseFunction;this.destroyYFunction=this.checkDestroyY}b.attributes.position.x.fastSetValue(this.currentPosition[0]);b.attributes.position.y.fastSetValue(this.currentPosition[1]);if(this.destroyXFunction(b)||this.destroyYFunction(b)){return}f.setLinearVelocity(this.attributes.linearVelocity.x.getValue(),this.attributes.linearVelocity.y.getValue());f.setAngularVelocity(this.attributes.angularVelocity.getValue()*gsMath.DEG2RAD);this.attributes.linearVelocity.x.addObserver(this);this.attributes.linearVelocity.y.addObserver(this);this.attributes.angularVelocity.addObserver(this);this.attributes.maxSpeed.addObserver(this);h.drag.addObserver(this);h.angularDrag.addObserver(this);this.currentStackedVelocityBehavior=0;if(this.attributes.applyMaxSpeed.getValue()){this.limitMaxSpeedFunction=this.capVelocity}else{this.limitMaxSpeedFunction=gs.NOOP_FUNCTION}this.applyCalculatedVelocityFunction=gs.NOOP_FUNCTION};gs.MotionAspect.stop=function(a,d){var c=a.aspects.physics.attributes;var f=a.scene;var b=f._world;var e=f._collisionController;if(this._body){b.destroyBody(this._body);this._body=null}e.removeCollidableActorForIndex(this.actorID);this.actorID=null;this._updatingself=null;a.attributes.position.x.removeObserver(this);a.attributes.position.y.removeObserver(this);a.attributes.rotation.removeObserver(this);this.attributes.linearVelocity.x.removeObserver(this);this.attributes.linearVelocity.y.removeObserver(this);this.attributes.angularVelocity.removeObserver(this);this.attributes.maxSpeed.removeObserver(this);c.drag.removeObserver(this);c.angularDrag.removeObserver(this);a.attributes.position.x.restoreInitialState();a.attributes.position.y.restoreInitialState();a.attributes.rotation.restoreInitialState();this.attributes.linearVelocity.x.restoreInitialState();this.attributes.linearVelocity.y.restoreInitialState();this.attributes.angularVelocity.restoreInitialState();this.attributes.maxSpeed.restoreInitialState();this.evaluate=gs.MotionAspect.evaluate;gs.array.recycle(this.calculatedVelocity);gs.array.recycle(this._bodyPosition);gs.array.recycle(this.currentPosition);this.actor=null;this.halfActorDiagonal=null;this.sceneWidth=null;this.sceneHeight=null;this.maxDimension=null;this.wrapAxis=null;this.checkWrappingXMethod=null;this.destroyXFunction=null;this.checkWrappingYMethod=null;this.destroyYFunction=null;this._bodyPosition=null;this.currentPosition=null;this.currentRotation=null;this.lastRotation=null};gs.MotionAspect.updateHalfDiagonal=function(){var a=this.actor.attributes.size;var c=a.width._value;var d=a.height._value;var b=Math.sqrt(c*c+d*d);this.halfActorDiagonal=Math.min(b*0.5,gs.physicsLib.SIMULATION_BORDER)};gs.MotionAspect.observeValueChange=function(b,g){if(this._updatingself||!this._body){return}this._updatingself=true;this._body.setAwake(true);this.wasAwake=true;var a=false;var f=this.actor.attributes.position;var e=this.currentPosition;if(b===f.x){e[0]=g;a=true}if(b===f.y){e[1]=g;a=true}if(b===this.actor.attributes.rotation){this.currentRotation=g*gsMath.DEG2RAD;this.lastRotation=this.currentRotation;a=true}if(a){this._body.setPositionAndAngle(e[0],e[1],this.currentRotation);this._updatingself=false;return}var d=this.attributes.linearVelocity;if(b===d.x||b===d.y){this._body.setLinearVelocity(d.x._value,d.y._value);this._updatingself=false;return}if(b===this.attributes.angularVelocity){this._body.setAngularVelocity(g*gsMath.DEG2RAD);this._updatingself=false;return}var c=this.actor.aspects.physics.attributes;if(b===c.angularDrag){this._body.setAngularDamping(g)}if(b===c.drag){this.drag=g}this._updatingself=false};gs.MotionAspect.evaluate=function(a,c){this._updatingself=true;var b=this._body.isAwake();if(b||this.wasAwake){gs.Game.profiler.entityCounter.awake.increment();this.wasAwake=b;this.evaluateBody(a)}if(this.drag>0){this.evaluateDrag()}this._updatingself=false};gs.MotionAspect.evaluateBody=function(e){var b=this._body;this.currentRotation=b.angle();if(this.currentRotation!==this.lastRotation){e.attributes.rotation.fastSetValue(this.currentRotation*gsMath.RAD2DEG);this.lastRotation=this.currentRotation}this.applyCalculatedVelocityFunction();this.limitMaxSpeedFunction();var a=b.getLinearVelocity(this.calculatedVelocity);var f=this.attributes.linearVelocity;f.x.fastSetValue(a[0]);f.y.fastSetValue(a[1]);var d=b.angularVelocity();var h=this.attributes.angularVelocity;h.fastSetValue(d);var g=this.currentPosition;var c=b.getPosition(this._bodyPosition);if(g[0]!==c[0]||g[1]!==c[1]){g[0]=c[0];g[1]=c[1];e.attributes.position.x.fastSetValue(g[0]);e.attributes.position.y.fastSetValue(g[1]);if(this.sceneWrapX){this.checkWrappingXMethod(e,b)}else{this.destroyXFunction(e)}if(this.sceneWrapY){this.checkWrappingYMethod(e,b)}else{this.destroyYFunction(e)}}};gs.MotionAspect.evaluateDrag=function(){var d=this.attributes.linearVelocity.x.getValue();var c=this.attributes.linearVelocity.y.getValue();if(Math.abs(d)>0||Math.abs(c)>0){var b=this._body;var g=Math.sqrt(d*d+c*c);var h=gs.g_tempVec2d;var f=b.getMass();var e=f*-this.drag;h[0]=(d/g)*e;h[1]=(c/g)*e;var a=this._body.getWorldCenter();b.applyForce(h,a);this.wasAwake=true}};gs.MotionAspect.capVelocity=function(){var c=this._body.getLinearVelocity(this.calculatedVelocity);var a=c[0]*c[0]+c[1]*c[1];var e=this.attributes.maxSpeed._value;var d=e*e;if(a>=d){var b=Math.sqrt(c[0]*c[0]+c[1]*c[1]);if(b>2){c[0]=(c[0]/b);c[1]=(c[1]/b)}else{c[0]=0;c[0]=0}c[0]=c[0]*e;c[1]=c[1]*e;this._body.setLinearVelocity(c[0],c[1])}};gs.MotionAspect.checkStartWrappingBodyX=function(c,a){var d=this.halfActorDiagonal;var b=this.currentPosition[0];if(b<d||b>=this.sceneWidth-d){this.checkWrappingXMethod=this.checkFinishWrappingBodyX;c.game().eventCenter.postEvent("startedWrap",c,gs.Vector2.X_COMPONENT,this.sceneWidth)}};gs.MotionAspect.checkStartWrappingBodyY=function(c,a){var d=this.halfActorDiagonal;var b=this.currentPosition[1];if((b<d)||b>=(this.sceneHeight-d)){this.checkWrappingYMethod=this.checkFinishWrappingBodyY;c.game().eventCenter.postEvent("startedWrap",c,gs.Vector2.Y_COMPONENT,this.sceneHeight)}};gs.MotionAspect.checkFinishWrappingBodyX=function(b,a){this.checkWrapPositionX(b,a);if((this.currentPosition[0]>this.halfActorDiagonal)&&this.currentPosition[0]<(this.sceneWidth-this.halfActorDiagonal)){b.game().eventCenter.postEvent("finishedWrap",b,gs.Vector2.X_COMPONENT);this.checkWrappingXMethod=this.checkStartWrappingBodyX}};gs.MotionAspect.checkFinishWrappingBodyY=function(b,a){this.checkWrapPositionY(b,a);if((this.currentPosition[1]>this.halfActorDiagonal)&&this.currentPosition[1]<(this.sceneHeight-this.halfActorDiagonal)){b.game().eventCenter.postEvent("finishedWrap",b,gs.Vector2.Y_COMPONENT);this.checkWrappingYMethod=this.checkStartWrappingBodyY}};gs.MotionAspect.checkWrapPositionX=function(b,a){if((this.currentPosition[0]<0)||(this.currentPosition[0]>this.sceneWidth)){while(this.currentPosition[0]<0){this.currentPosition[0]+=this.sceneWidth}while(this.currentPosition[0]>this.sceneWidth){this.currentPosition[0]-=this.sceneWidth}b.attributes.position.x.setValue(this.currentPosition[0]);a.setPositionAndAngle(this.currentPosition[0],this.currentPosition[1],this.currentRotation);b.game().eventCenter.postEvent("wrap",null,b,gs.Vector2.X_COMPONENT,this.sceneWidth,0)}};gs.MotionAspect.checkWrapPositionY=function(b,a){if((this.currentPosition[1]<0)||(this.currentPosition[1]>this.sceneHeight)){while(this.currentPosition[1]<0){this.currentPosition[1]+=this.sceneHeight}while(this.currentPosition[1]>this.sceneHeight){this.currentPosition[1]-=this.sceneHeight}b.attributes.position.y.setValue(this.currentPosition[1]);a.setPositionAndAngle(this.currentPosition[0],this.currentPosition[1],this.currentRotation);b.game().eventCenter.postEvent("wrap",null,b,gs.Vector2.Y_COMPONENT,this.sceneHeight,0)}};gs.MotionAspect.checkDestroyX=function(a){if(this.currentPosition[0]<-500||this.currentPosition[0]>(this.sceneWidth+500)){a.scene.markActorForDestruction(a)}};gs.MotionAspect.checkDestroyY=function(a){if(this.currentPosition[1]<-500||this.currentPosition[1]>(this.sceneHeight+500)){a.scene.markActorForDestruction(a)}};gs.MotionAspect.returnFalseFunction=function(){return false};gs.MotionAspect.modifyAdditiveVelocity=function(a,b){if(!this._additiveVelocities){this._additiveVelocities=gs.Map.provide();this._additiveVelocitiesCount=0}if(!this._additiveVelocities[b]){this._additiveVelocities[b]=gs.array.provide();this._additiveVelocitiesCount++}this._additiveVelocities[b][0]=a[0];this._additiveVelocities[b][1]=a[1];this.modifyTotalVelocity();this.applyCalculatedVelocityFunction=this.applyCalculatedVelocity};gs.MotionAspect.removeAdditiveVelocity=function(a){if(this._additiveVelocities&&this._additiveVelocities[a]){gs.array.recycle(this._additiveVelocities[a]);delete this._additiveVelocities[a];if(--this._additiveVelocitiesCount===0){gs.Map.recycle(this._additiveVelocities);this._additiveVelocities=null;if(!this._stackedVelocities){this.attributes.linearVelocity.x.setValue(0);this.attributes.linearVelocity.y.setValue(0);this._body.setLinearVelocity(0,0);this.applyCalculatedVelocityFunction=gs.NOOP_FUNCTION}}this.modifyTotalVelocity()}};gs.MotionAspect.modifyStackedVelocity=function(a,b){if(!this._stackedVelocities){this._stackedVelocities=gs.array.provide();this.stackedVelocityBehaviors=gs.array.provide()}var c=this.stackedVelocityBehaviors.indexOf(b);if(this.stackedVelocityBehaviors.indexOf(b)===-1){c=this.stackedVelocityBehaviors.length;this.stackedVelocityBehaviors.push(b);this.currentStackedVelocityBehavior=c}this._stackedVelocities[c]=gs.array.provide();this._stackedVelocities[c][0]=a[0];this._stackedVelocities[c][1]=a[1];this.modifyTotalVelocity();this.applyCalculatedVelocityFunction=this.applyCalculatedVelocity};gs.MotionAspect.removeStackedVelocity=function(b){if(this._stackedVelocities){var a=this.stackedVelocityBehaviors.indexOf(b);if(a!==-1){gs.array.recycle(this._stackedVelocities[a]);this._stackedVelocities.splice(a,1);this.stackedVelocityBehaviors.splice(a,1)}if(this._stackedVelocities.length===0){gs.array.recycle(this._stackedVelocities);gs.array.recycle(this.stackedVelocityBehaviors);this._stackedVelocities=null;this.stackedVelocityBehaviors=null;if(!this._additiveVelocities){this.attributes.linearVelocity.x.setValue(0);this.attributes.linearVelocity.y.setValue(0);this._body.setLinearVelocity(0,0);this.applyCalculatedVelocityFunction=gs.NOOP_FUNCTION}}else{this.currentStackedVelocityBehavior=this.stackedVelocityBehaviors.length-1}this.modifyTotalVelocity()}};gs.MotionAspect.modifyTotalVelocity=function(){var a=this.calculatedVelocity;a[0]=0;a[1]=0;if(this._additiveVelocitiesCount>0){for(var b in this._additiveVelocities){a[0]+=this._additiveVelocities[b][0];a[1]+=this._additiveVelocities[b][1]}}if(this._stackedVelocities&&this._stackedVelocities.length>0){a[0]+=this._stackedVelocities[this.currentStackedVelocityBehavior][0];a[1]+=this._stackedVelocities[this.currentStackedVelocityBehavior][1]}this._body.setAwake(true);this.wasAwake=true};gs.MotionAspect.applyCalculatedVelocity=function(){this._body.setLinearVelocity(this.calculatedVelocity[0],this.calculatedVelocity[1])};gs.PhysicsAspect=gs.Aspect.subclass("PhysicsAspect");gs.PhysicsAspect.RECTANGLE_SHAPE=0;gs.PhysicsAspect.CIRCLE_SHAPE=1;gs.PhysicsAspect.RestitutionConstraint=gs.NumberConstraint.provide().initWithParameters(0,2);gs.PhysicsAspect.init=function(){gs.Aspect.init.call(this);this.attributes.addRealPositiveMutableAttribute("density",0);this.attributes.addRealPositiveMutableAttribute("friction",0);this.attributes.addRealConstrainedMutableAttribute("restitution",0,0,2);this.attributes.addBooleanMutableAttribute("fixedRotation",false);this.attributes.addBooleanMutableAttribute("movable",false);this.attributes.addIntegerMutableAttribute("collisionShape",0);this.attributes.addRealPositiveMutableAttribute("drag",0);this.attributes.addRealPositiveMutableAttribute("angularDrag",0);return this};gs.PhysicsAspect.makeFixtureDefinition=function(c,j){var i=c.attributes.size;var d=Math.max((i.width.getValue()*0.5)-j,0.5);var h=Math.max((i.height.getValue()*0.5)-j,0.5);var a=this.attributes;var b=a.collisionShape.getValue();var g=gs.physicsLib.GetFixtureDef();var f=null;if(b===gs.PhysicsAspect.CIRCLE_SHAPE){var e=Math.min(d,h);f=gs.physicsLib.GetCircleShape(e)}else{f=gs.physicsLib.GetPolygonShapeAsBox(d,h)}g.setShape(f);g.setDensity(a.density.getValue());g.setFriction(a.friction.getValue());g.setRestitution(a.restitution.getValue());return g};gs.ShapeAspect=gs.Aspect.subclass("ShapeAspect",{start:function(b,c){var a=b.aspects.motion._body;if(!a){gs.Log.warn("ShapeAspect.start, physics body is null");return}this.createFixtures(a,b);b.attributes.size.width.addObserver(this);b.attributes.size.height.addObserver(this);b.aspects.physics.attributes.density.addObserver(this);b.aspects.physics.attributes.friction.addObserver(this);b.aspects.physics.attributes.restitution.addObserver(this)},observeValueChange:function(a,j){var c=this.actor();var f=c.aspects.motion._body;var e=c.aspects.physics.attributes;if(a===e.density){f.changeFixtureDensities(j)}else{if(a===e.friction){f.changeFixtureFrictions(j)}else{if(a===e.restitution){f.changeFixtureRestitutions(j)}else{var k=this.shapeInset(c);var i=c.attributes.size;var d=Math.max((i.width.getValue()*0.5)-k,0.5);var h=Math.max((i.height.getValue()*0.5)-k,0.5);var b=c.aspects.physics.attributes.collisionShape.getValue();if(b===gs.PhysicsAspect.CIRCLE_SHAPE){var g=Math.min(d,h);f.resizeFixtureShapesAsCircle(g)}else{f.resizeFixtureShapesAsBox(d,h)}}}}},shapeInset:function(a){if(a.aspects.physics.attributes.movable.getValue()){return(0.5)}else{return(0)}},stop:function(b,c){var a=b.aspects.motion._body;if(a){a.destroyFixture(this.fixture);this.fixture=null}b.attributes.size.width.removeObserver(this);b.attributes.size.height.removeObserver(this);b.aspects.physics.attributes.density.removeObserver(this);b.aspects.physics.attributes.friction.removeObserver(this);b.aspects.physics.attributes.restitution.removeObserver(this)},addCollisionMaskCategory:function(a){this.fixture.addCollisionMaskCategory(a)},removeCollisionMaskCategory:function(a){this.fixture.removeCollisionMaskCategory(a)},testPoint:function(b){var a=b[0];var c=b[1];return this.fixture.testPoint(a,c)}});gs.CollisionShapeAspect=gs.ShapeAspect.subclass("CollisionShapeAspect",{createFixtures:function(a,d){var b=d.aspects.physics;var c=b.makeFixtureDefinition(d,this.shapeInset(d));c.setIsSensor(false);this.fixture=a.createFixture(c);this.fixture.setFixtureID(gs.GS_COLLISION_SHAPE_ID)}});gs.CollisionSensorAspect=gs.ShapeAspect.subclass("CollisionSensorAspect",{createFixtures:function(a,d){var b=d.aspects.physics;var c=b.makeFixtureDefinition(d,this.shapeInset(d));c.setIsSensor(true);this.fixture=a.createFixture(c);this.fixture.setFixtureID(gs.GS_SENSOR_SHAPE_ID)}});gs.AspectList=gs.PrototypicalArray.subclass("AspectList");gs.AspectList.aspectClassMap={graphics:gs.GraphicsAspect,motion:gs.MotionAspect,physics:gs.PhysicsAspect,collisionShape:gs.CollisionShapeAspect,collisionSensor:gs.CollisionSensorAspect};gs.AspectList.initPrime=function(){this.graphics=null;this.motion=null;this.physics=null;this.collisionShape=null;this.collisionSensor=null;return this};gs.AspectList.hasAspect=function(a){return(!!this[a])};gs.AspectList.addAspect=function(b){if(!this.hasAspect(b)){var d=gs.AspectList.aspectClassMap[b];if(d){var a=d.provide().init();this.addObjectAtIndex(a,null,b);if(this._started){var c=this.getParent();a.start(c,c.actorTime)}}}return this[b]};gs.AspectList.removeAspect=function(b){var a=this[b];if(a){if(this._started){var c=this.getParent();a.stop(c,c.actorTime)}this.removeObject(a)}};gs.AspectList.start=function(c,d){var e=this.array;for(var a=0,b=e.length;a<b;a++){e[a].start(c,d)}this._started=true};gs.AspectList.stop=function(c,d){for(var b=(this.array.length-1);b>=0;b=b-1){var a=this.array[b];a.stop(c,d)}this._started=false};gs.AspectList.loadFromLite=function(f,a){var b=gs.CompoundAttribute.obfuscationLookupTable;for(var d in f){var g=f[d];var e=b[d]||d;var c=this[e];if(!c){c=this.addAspect(e)}c.loadFromLite(g,a)}};gs.AspectList.loadFromTable=function(e,b){var a=0;if(e){a=e.length}for(var d=0;d<a;++d){var g=e[d];var f=gs.Project.nodeTypeNameMap[g[gs.JXON._type]];this.addAspect(f);var c=this[f];if(c){c.loadFromTable(g,b)}}};gs.AspectList.restoreInitialState=function(){this.graphics.restoreInitialState();this.motion.restoreInitialState();this.physics.restoreInitialState();this.collisionShape&&this.collisionShape.restoreInitialState();this.collisionSensor&&this.collisionSensor.restoreInitialState()};gs.EventCenter=function(){this.eventRegistrations={};this.objectsQueuedForDeregister=[];this.eventBeingHandled=null;this.eventQueue=[]};gs.EventCenterRegistration=function(){this.observer=null;this.eventHandler=null;this.predicates=null};gs.Pool.init(gs.EventCenterRegistration);gs.EventCenter.prototype={globalEvents:["systemPause","behaviorPause","resume","keyDown","keyUp","mouseDown","mouseMoved","mouseUp","accelerated","touchDown","touchMoved","touchUp","touchCancel","collision","wrap","destroyed","changeToScene","sceneWillStart","sceneWillEnd","behaviorWasAdded","resetScene","resetGame","startedWrap","finishedWrap","autorotationStarted","autorotationEnded","startPauseScene","endPauseScene","sceneWillPause","sceneWillResume","keyboardInputEntered","keyboardInputCancelled","purchaseItemSuccess","purchaseItemFailure","purchaseItemCancel"],registerForEvent:function(a,e,f,d,c){var b=gs.EventCenterRegistration.provide();b.observer=e;b.eventHandler=f;b.predicates=d;var g=null;if(c){if(!c.eventRegistrations){c.eventRegistrations=gs.Map.provide()}g=c.eventRegistrations[a];if(!g){c.eventRegistrations[a]=gs.array.provide();g=c.eventRegistrations[a]}}else{g=this.eventRegistrations[a];if(!g){this.eventRegistrations[a]=gs.array.provide();g=this.eventRegistrations[a]}}g.push(b)},deregisterForEvent:function(a,c,b){var d=null;if(b){if(b.eventRegistrations){d=b.eventRegistrations[a]}}else{if(this.eventRegistrations){d=this.eventRegistrations[a]}}if(d){if(this.eventBeingHandled!==a){this.removeObjectFromEventTable(d,c)}else{this.objectsQueuedForDeregister.push(c);c.queuedForDeregister=true}if(d.length===0){if(b){gs.array.recycle(b.eventRegistrations[a]);delete b.eventRegistrations[a]}else{gs.array.recycle(this.eventRegistrations[a]);delete this.eventRegistrations[a]}}}},removeObjectFromEventTable:function(e,a){var b=e.length;for(var d=0;d<b;++d){var c=e[d];if(c.observer===a){gs.EventCenterRegistration.recycle(c);e.splice(d,1);break}}a.queuedForDeregister=false},postEvent:function(h,l){var e=0;var s=false;var p;var c=null;if(arguments.length>2){c=gs.array.provide()}for(p=2;p<arguments.length;p++){c.push(arguments[p])}var d=c?c.length:0;var q=null;if(l){if(l.eventRegistrations){q=l.eventRegistrations[h]}else{q=null}}else{q=this.eventRegistrations[h]}var n=0;if(q){n=q.length;this.eventBeingHandled=h;for(var j=n-1;j>=0;--j){var g=q[j];var o=g.observer;var k=true;var b=g.predicates;if(!o.queuedForDeregister){if(b){for(p=0;p<d;p++){var m=c[p];var a=b[p];if((a)&&(a(m)===false)){k=false;break}}}if(k){e++;var r=g.eventHandler;var t=null;switch(d){case 0:t=o[r]();break;case 1:t=o[r](c[0]);break;case 2:t=o[r](c[0],c[1]);break;case 3:t=o[r](c[0],c[1],c[2]);break;default:t=o[r].apply(o,c)}s=s||t}}}if(c){gs.array.recycle(c)}this.eventBeingHandled=null;var f=this.objectsQueuedForDeregister.length;for(p=0;p<f;p++){this.deregisterForEvent(h,this.objectsQueuedForDeregister[p])}this.objectsQueuedForDeregister.length=0}return s},postDelayedEvent:function(a,e){var b=[];for(var c=2;c<arguments.length;++c){b.push(arguments[c])}var d={eventName:a,objectOfInterest:e,args:b};this.eventQueue.push(d)},checkEventQueue:function(){var a=this.eventQueue;var f=a.length;for(var d=0;d<f;++d){var e=a[d];var g=e.args.length;switch(g){case 0:this.postEvent(e.eventName,e.objectOfInterest);break;case 1:this.postEvent(e.eventName,e.objectOfInterest,e.args[0]);break;case 2:this.postEvent(e.eventName,e.objectOfInterest,e.args[0],e.args[1]);break;case 3:this.postEvent(e.eventName,e.objectOfInterest,e.args[0],e.args[1],e.args[2]);break;default:var c=[e.eventName,e.objectOfInterest];for(var b=0;b<g;++b){c.push(e.args[b])}this.postEvent.apply(this,c)}}a.length=0},registrationsForEvent:function(a){return((this.eventRegistrations[a]!=null)?this.eventRegistrations[a]:[])}};gs.AllocationHintCache=function(){this.scenes=gs.Map.provide();this.storageKeyPrefix="engine/gs.AllocationHintCache/scenes/";gs.AllocationHintCache.current=this};gs.AllocationHintCache.instance=function(){return gs.util.lazySingleton(this)};gs.AllocationHintCache.prototype={getScene:function(a){var b=this.scenes[a];if(!b){b=gs.Map.provide();b.actors=gs.Map.provide();this.scenes[a]=b}return b},recordActorCount:function(a,b,d){var e=this.getScene(a);var c=e.actors[b];if(!c||d>c){e.actors[b]=d}},recordActorCounts:function(a,b){for(var c in b){this.recordActorCount(a,c,b[c])}},getActorCount:function(a,b){var d=this.getScene(a);var c=d.actors[b];return c||0},readFromStorage:function(a){var b=this.storageKeyPrefix+a;this.scenes[a]=gs.LocalStorage.getObject(b)},writeToStorage:function(a){var b=this.storageKeyPrefix+a;var d=this.scenes[a];if(d){for(var c in d.actors){if(d.actors[c]<=1){delete d.actors[c]}}gs.LocalStorage.setObject(b,this.scenes[a])}}};gs.ActorFactory=function(){this.prototypeIDs=gs.array.provide();this.prototypeByID={};this.poolMap={};this.rawDataByID={};this.sceneID=null;this.outMap={};this.maxMap={};this.maxPoolSize=8;gs.ActorFactory.current=this};gs.ActorFactory.instance=function(){return gs.util.lazySingleton(this)};gs.ActorFactory.prototype={getPrototypeIDs:function(){return this.prototypeIDs},preloadActorPrototypeByIndex:function(c){var e=new gs.Promise();var d=this;gs.Project.instance.virtualFileCache.loadActorPrototypeByIndex(c).then(function b(f){var h=f.getData();var g=h.id;d.rawDataByID[g]=h;d.prototypeIDs.push(g);d.poolMap[g]=gs.array.provide();d.outMap[g]=0;d.maxMap[g]=0;d.loadActorPrototype(g)},function a(){gs.Log.error("failed to load actor by index:",c)});return e},loadActorPrototype:function(c){try{var d=this.rawDataByID[c];if(!d){return false}var a=gs.Actor.provide().init();a._prototypeID=c;a.loadFromLite(d,true);this.prototypeByID[c]=a;gs.array.recycleJXONTree(d);delete this.rawDataByID[c];this.poolMap[c].push(a)}catch(b){gs.Log.error(b)}return true},ensureActorPrototype:function(a){if(this.prototypeByID[a]){return true}return this.loadActorPrototype(a)},getActorPrototype:function(a){this.ensureActorPrototype(a);return this.prototypeByID[a]},provideActorInstance:function(d,c){this.ensureActorPrototype(d);var e;var b=this.poolMap[d];if(!b){gs.Log.warn("Cannot provide instance of missing prototype:",d);return null}if(b.length>0){e=b.pop()}else{e=this.allocateActorInstance(d)}if(c){e.loadFromLite(c,false)}var a=++this.outMap[d];this.maxMap[d]=Math.max(a,this.maxMap[d]);return e},spawnActorInstance:function(a){var b=this.provideActorInstance(a,null);if(b){b._objectKey=gs.ObjectBase.generateUniqueObjectKey()}return b},recycleActorInstance:function(c){var b=c._prototypeID;c.restoreInitialState();var a=this.poolMap[b];a.push(c);this.outMap[b]--},allocateActorInstance:function(b){var a=this.prototypeByID[b];var c=a.clone();return c},clearOutMax:function(){for(var a in this.prototypeByID){this.outMap[a]=0;this.maxMap[a]=0}},primePool:function(b,c){this.ensureActorPrototype(b);var a=this.poolMap[b];while(a.length<c){a.push(this.allocateActorInstance(b))}},primeSpawnPools:function(a){for(var c in a){var d=a[c];this.ensureActorPrototype(c);var b=this.poolMap[c];while(b.length<d){b.push(this.allocateActorInstance(c))}}},managePools:function(a,b){var c=gs.AllocationHintCache.instance();this.sceneID=a;c.readFromStorage(a);this.primeSpawnPools(b);for(var e in this.prototypeByID){var f=c.getActorCount(a,e);var d=this.poolMap[e];if(f&&f>this.outMap[e]){this.primePool(e,f-this.outMap[e])}else{if(d.length>this.maxPoolSize){d.length=this.maxPoolSize}}}},onSceneStop:function(a){if(a===this.sceneID){var b=gs.AllocationHintCache.instance();b.recordActorCounts(this.sceneID,this.maxMap);b.writeToStorage(this.sceneID);this.clearOutMax()}}};gs.LOCAL_STORAGE_KEY_PREFIX="";gs.update=function(a){gs.EngineContext.current.update()};gs.loadGame=function(b,d,c){var e=gs.EngineContext.instance();var a=e.getRenderContext();a.setCanvas(d.canvas);e.load(b);var f=e.project;f.setLoaderProgress(c);return f};gs.playGame=function(a){gs.EngineContext.current.play()};gs.pauseGame=function(a){gs.EngineContext.current.pause()};gs.stopGame=function(a){gs.EngineContext.current.halt()};gs.resetGame=function(a){gs.EngineContext.current.reset()};gs.getCurrentSceneKey=function(a){return gs.EngineContext.current.getCurrentSceneKey()};gs.changeScene=function(a,b){gs.EngineContext.current.changeScene(b)};gs.getScenes=function(a,b){gs.EngineContext.current.getMetadataForAllScenes().then(b)};gs.setGameVolume=function(b,a){return gs.EngineContext.current.setVolume(a)};gs.getGameVolume=function(a){return gs.EngineContext.current.getVolume()};gs.addActionListener=function(d,a,c,b){gs.LegacyDelegate.addActionListener(a,c,b)};gs.clearTouchState=function(a){gs.Game.current.clearTouchState()};gs.registerSocialConsoleCallback=function(b,a,c){if(!b.socialConsoleCallbacks){b.socialConsoleCallbacks={}}b.socialConsoleCallbacks[a]=c};gs.callSocialConsole=function(c,b){if(!c.socialConsoleCallbacks){c.socialConsoleCallbacks={}}try{var d=c.socialConsoleCallbacks[b];if(d){d(c)}else{gs.Log.info("Social Console didn't registered action:",b)}}catch(a){gs.Log.error(a.message)}};gs.afterNextFrame=function(a){gs.EngineContext.current.waitAfterNextFrame().then(a)};gs.setExternalDelegate=function(a){if(!gs.externalDelegate){gs.externalDelegate=new gs.api.ExternalDelegate()}gs.externalDelegate.setDelegate(a)};gs.beginSession=function(){gs.EngineContext.current.beginSession()};gs.endSession=function(){gs.EngineContext.current.endSession()};gs.writeGameAttribute=function(b,c){var a=gs.Game.instance;a.eventCenter.postDelayedEvent("externalWriteGameAttribute",null,b,c)};gs.getTableRowCount=function(c){var a=gs.Reference.lookup(c);var b=a.resolveRelativeTo(gs.Game.instance);return b.getRowCount()};gs.readTableCell=function(e,d,b){var a=gs.Reference.lookup(e);var c=a.resolveRelativeTo(gs.Game.instance);return c.getCellSafe(d,b)};gs.writeTableCell=function(f,e,b,d){var a=gs.Reference.lookup(f);var c=a.resolveRelativeTo(gs.Game.instance);c.setCellSafe(e,b,d)};gs.setLoaderProgress=function(b){var a=gs.EngineContext.current.project;a.setLoaderProgress(b)};gs.addActionListener=gs.addActionListener;gs.afterNextFrame=gs.afterNextFrame;gs.beginSession=gs.beginSession;gs.callSocialConsole=gs.callSocialConsole;gs.clearTouchState=gs.clearTouchState;gs.endSession=gs.endSession;gs.getGameVolume=gs.getGameVolume;gs.getTableRowCount=gs.getTableRowCount;gs.loadGame=gs.loadGame;gs.pauseGame=gs.pauseGame;gs.playGame=gs.playGame;gs.readTableCell=gs.readTableCell;gs.registerSocialConsoleCallback=gs.registerSocialConsoleCallback;gs.resetGame=gs.resetGame;gs.setExternalDelegate=gs.setExternalDelegate;gs.setGameVolume=gs.setGameVolume;gs.setLoaderProgress=gs.setLoaderProgress;gs.writeGameAttribute=gs.writeGameAttribute;gs.writeTableCell=gs.writeTableCell;gs.devices={start:function(a){a.devices.mouse.button.fastSetValue(false);a.devices.touches.count.fastSetValue(0);a.eventCenter.registerForEvent("mouseMoved",a,"updateMousePosition");a.eventCenter.registerForEvent("mouseDown",a,"mouseButtonDown");a.eventCenter.registerForEvent("mouseUp",a,"mouseButtonUp");a.eventCenter.registerForEvent("accelerated",a,"updateAccelerometer");a.eventCenter.registerForEvent("touchMoved",a,"updateTouchPosition");a.eventCenter.registerForEvent("touchDown",a,"touchDown");a.eventCenter.registerForEvent("touchUp",a,"touchUp")},stop:function(a){a.eventCenter.deregisterForEvent("mouseMoved",a);a.eventCenter.deregisterForEvent("mouseDown",a);a.eventCenter.deregisterForEvent("mouseUp",a);a.eventCenter.deregisterForEvent("accelerated",a);a.eventCenter.deregisterForEvent("touchMoved",a);a.eventCenter.deregisterForEvent("touchDown",a);a.eventCenter.deregisterForEvent("touchUp",a)},deviceRotationForInterfaceOrientation:function(a){if(a===0){return -90}else{if(a===1){return 90}else{if(a===2){return 0}else{return 180}}}}};gs.orientSize=function(e,b,c){var a=Math.max(e,b);var d=Math.min(e,b);if(gs.isPortrait(c)){return[d,a]}else{if(gs.isLandscape(c)){return[a,d]}else{return[e,b]}}};gs.isLandscape=function(a){return(a===0||a===1)};gs.isPortrait=function(a){return(a===2||a===3)};gs.Resolution={LEGACY_IPHONE_LANDSCAPE:0,LEGACY_IPHONE_PORTRAIT:1,LEGACY_WEB:2,IPAD_LANDSCAPE:3,IPAD_PORTRAIT:4,HD_720:5,MACBOOK:6,ARCADE:7,NOOK_LANDSCAPE:8,NOOK_PORTRAIT:9,KINDLE_FIRE_LANDSCAPE:10,KINDLE_FIRE_PORTRAIT:11,IPHONE_LANDSCAPE:12,IPHONE_PORTRAIT:13};gs.sizeAndOrientationForResolution=function(c){var b=1;var d;var a;switch(c){case gs.Resolution.LEGACY_IPHONE_LANDSCAPE:d=480;a=320;break;case gs.Resolution.LEGACY_IPHONE_PORTRAIT:b=2;d=320;a=480;break;case gs.Resolution.LEGACY_WEB:d=720;a=480;break;case gs.Resolution.IPAD_LANDSCAPE:d=1024;a=768;break;case gs.Resolution.IPAD_PORTRAIT:b=2;d=768;a=1024;break;case gs.Resolution.HD_720:d=1280;a=720;break;case gs.Resolution.MACBOOK:d=1280;a=800;break;case gs.Resolution.ARCADE:d=480;a=320;break;case gs.Resolution.NOOK_LANDSCAPE:d=1024;a=600;break;case gs.Resolution.NOOK_PORTRAIT:b=2;d=600;a=1024;break;case gs.Resolution.KINDLE_FIRE_LANDSCAPE:d=1024;a=580;break;case gs.Resolution.KINDLE_FIRE_PORTRAIT:b=2;d=600;a=1004;break;case gs.Resolution.IPHONE_LANDSCAPE:d=568;a=320;break;case gs.Resolution.IPHONE_PORTRAIT:b=2;d=320;a=568;break;default:gs.Log.error("Unrecognized resolution:",c);d=480;a=320;break}return[d,a,b]};gs.AudioManagerBase=function(){this.masterVolume=1;this.musicVolume=1;this.soundVolume=1;this.actualMusicVolume=1;this.actualSoundVolume=1;this.musicIsActive=false;this.musicIsPlaying=false;this.isAllPaused=false};gs.AudioManagerBase.prototype={initWithGame:function(a){},getAssetPath:function(a){return gs.Project.current.pathForSound(a)},getMasterVolume:function(){return this.masterVolume},getMusicVolume:function(){return this.musicVolume},getSoundVolume:function(){return this.soundVolume},setMasterVolume:function(a){this.masterVolume=gsMath.clampf(a,0,1);this.actualMusicVolume=this.masterVolume*this.musicVolume;this.actualSoundVolume=this.masterVolume*this.soundVolume;this.updateMusicVolume(this.actualMusicVolume);this.updateSoundVolume(this.actualSoundVolume)},setMusicVolume:function(a){this.musicVolume=gsMath.clampf(a,0,1);this.actualMusicVolume=this.masterVolume*this.musicVolume;this.updateMusicVolume(this.actualMusicVolume)},setSoundVolume:function(a){this.soundVolume=gsMath.clampf(a,0,1);this.actualSoundVolume=this.masterVolume*this.soundVolume;this.updateSoundVolume(this.actualSoundVolume)},updateMusicVolume:function(a){},updateSoundVolume:function(a){},playMusic:function(b,a){if(b){if(this.musicIsActive){this.stopMusic()}this.startMusic(b,a)}else{if(this.musicIsActive&&!this.musicIsPlaying){this.unpauseMusic()}}},startMusic:function(b,a){this.musicIsActive=true;this.musicIsPlaying=true},stopMusic:function(){this.musicIsActive=false;this.musicIsPlaying=false},pauseMusic:function(){this.musicIsPlaying=false},unpauseMusic:function(){if(this.musicIsActive){this.musicIsPlaying=true}},playSound:function(c,b,a){return null},stopInstance:function(a){},pauseInstance:function(a){},unpauseInstance:function(a){},setInstanceVolume:function(a,b){},setInstancePitch:function(a,b){},pauseAll:function(){if(!this.isAllPaused){this.isAllPaused=true}},unpauseAll:function(){if(this.isAllPaused){this.isAllPaused=false}}};gs.StandardAudioManager=function(){gs.AudioManagerBase.call(this);this.currentMusic=this.createAudioElement();this.currentMusic.isMusic=true;this.activeSounds=gs.array.provide();this.inactiveSounds=gs.array.provide();var b=gs.globalOptions.audioPoolSize;for(var a=0;a<b;a++){this.inactiveSounds[a]=this.createAudioElement()}};gs.StandardAudioManager.onAudioError=function(a){gs.AudioManager.current.onAudioError(this,a)};gs.StandardAudioManager.onAudioEnded=function(a){gs.AudioManager.current.onAudioEnded(this,a)};gs.StandardAudioManager.prototype=gs.subclass(gs.AudioManagerBase,{startMusic:function(d,a){try{var c=this.getAssetPath(d);if(c){this.currentMusic.src=c;this.currentMusic.assetID=d;this.currentMusic.autoplay=true;this.currentMusic.load();this.currentMusic.volume=this.actualMusicVolume;this.currentMusic.loop=a;this.currentMusic.play()}}catch(b){gs.Log.error(b)}gs.AudioManagerBase.prototype.startMusic.call(this,d,a)},stopMusic:function(){if(this.musicIsActive){if(this.musicIsPlaying){this.currentMusic.pause()}}gs.AudioManagerBase.prototype.stopMusic.call(this)},pauseMusic:function(){if(this.musicIsActive&&this.musicIsPlaying){this.currentMusic.pause()}gs.AudioManagerBase.prototype.pauseMusic.call(this)},unpauseMusic:function(){if(this.musicIsActive&&!this.musicIsPlaying){this.currentMusic.play()}gs.AudioManagerBase.prototype.unpauseMusic.call(this)},updateMusicVolume:function(a){this.currentMusic.volume=a},playSound:function(d,c,b){var a=this.provideInstance(d);if(!a){return null}a.assetID=d;a.instanceVolume=c;a.volume=this.actualSoundVolume*c;a.loop=b;a.play();this.activeSounds.push(a);return a},stopInstance:function(a){if(a){a.pause();this.recycleInstance(a)}},pauseInstance:function(a){if(a){a.pause()}},unpauseInstance:function(a){if(a){a.play()}},setInstanceVolume:function(a,b){if(a){a.instanceVolume=b;a.volume=this.actualSoundVolume*b}},setInstancePitch:function(a,b){},updateSoundVolume:function(d){for(var b=0,c=this.activeSounds.length;b<c;b++){var a=this.activeSounds[b];a.volume=d*a.instanceVolume}},pauseAll:function(){if(!this.isAllPaused){if(this.musicIsActive&&this.musicIsPlaying){this.currentMusic.pause()}for(var b=0,c=this.activeSounds.length;b<c;b++){var a=this.activeSounds[b];a.pause()}}gs.AudioManagerBase.prototype.pauseAll.call(this)},unpauseAll:function(){if(this.isAllPaused){if(this.musicIsActive&&this.musicIsPlaying){this.currentMusic.play()}for(var b=0,c=this.activeSounds.length;b<c;b++){var a=this.activeSounds[b];a.play()}}gs.AudioManagerBase.prototype.unpauseAll.call(this)},createAudioElement:function(){var a=gs.html5.Audio.createAudioElement();a.autobuffer=true;a.preload="auto";a.addEventListener("error",gs.StandardAudioManager.onAudioError,false);a.addEventListener("ended",gs.StandardAudioManager.onAudioEnded,false);a.assetID=null;a.isMusic=false;a.instanceVolume=1;return a},onAudioError:function(b,a){gs.Log.error(a)},onAudioEnded:function(b,a){if(!b.isMusic){this.recycleInstance(b)}},provideInstance:function(f){var e=this.getAssetPath(f);if(!e){return null}var d=this.inactiveSounds.length;if(d<1){return null}var a=null;for(var b=0;b<d;b++){var c=this.inactiveSounds[b];if(c.assetID===f){a=c;a.currentTime=0;this.inactiveSounds.splice(b,1);break}}if(!a){a=this.inactiveSounds.shift();a.src=e;a.load()}return a},recycleInstance:function(a){var b=this.activeSounds.indexOf(a);if(b!==-1){this.activeSounds.splice(b,1);this.inactiveSounds.push(a)}},loadAssets:function(a){var f=0;for(var b=0,c=a.length;b<c;b++){var e=this.getAssetPath(a[b]);if(e){var d=this.createAudioElement();d.src=e;d.load();this.inactiveSounds[f++]=d}}}});gs.ExtensionAudioManager=function(){gs.StandardAudioManager.call(this);this.context=null;this.masterGain=null;this.soundGain=null;this.bufferMap={};this.instanceMap={};this.waitQueue=[];this.activeInstances=gs.array.provide();this.initContext()};gs.ExtensionAudioManager.onRequestLoad=function(a){gs.AudioManager.current.onRequestLoad(this,a)};gs.ExtensionAudioManager.onRequestError=function(b){var a=this;gs.Log.error("gs.ExtensionAudioManager.onRequestError",a.assetID,b)};gs.ExtensionAudioManager.onDecodeError=function(a){gs.Log.error("gs.ExtensionAudioManager.onDecodeError")};gs.ExtensionAudioManager.onBufferSourceEnded=function(a){gs.AudioManager.current.onSourceBufferEnded(this,a)};gs.ExtensionAudioManager.prototype={initContext:function(){var a=gs.html5.Audio.createAudioContext();this.context=a;this.masterGain=a.createGain();this.masterGain.connect(a.destination);this.soundGain=a.createGain();this.soundGain.connect(this.masterGain)},setMasterVolume:function(a){this.masterGain.gain.value=a;this.__super.setMasterVolume.call(this,a)},setSoundVolume:function(a){if(a===0){this.soundGain.disconnect()}else{this.soundGain.connect(this.masterGain)}this.soundGain.gain.value=a;this.__super.setSoundVolume.call(this,a)},playSound:function(d,c,b){var a=this.createSoundInstance(d,c,b);if(!a){return null}if(a.ready){a.sourceNode.start(0)}else{this.waitQueue.push(a)}this.activeInstances.push(a);return a},createSoundInstance:function(d,c,b){var a=this.instanceMap[d];if(a){this.instanceMap[d]=null;this.prepareSoundForNextPlay(d)}else{this.prepareSoundForNextPlay(d);a=this.instanceMap[d];this.instanceMap[d]=null;this.loadAsset(d)}if(!a){return null}a.gainNode.gain.value=c;a.volume=c;a.loop=b;return a},stopInstance:function(a){if(a){var b=this.activeInstances.indexOf(a);if(b!==-1){this.activeInstances.splice(b,1);try{if(a.ready){a.sourceNode.stop()}a.sourceNode.disconnect();a.gainNode.disconnect()}catch(c){gs.Log.error("gs.ExtensionAudioManager.stopInstance",a.assetID,c)}}b=this.waitQueue.indexOf(a);if(b!==-1){this.waitQueue.splice(b,1)}}},pauseInstance:function(a){if(a){if(a.loop){try{if(a.ready){a.sourceNode.stop()}a.sourceNode.disconnect();a.gainNode.disconnect()}catch(b){gs.Log.error("gs.ExtensionAudioManager.pauseInstance",a.assetID,b)}var c=this.createSoundInstance(a.assetID,a.volume,a.loop);a.sourceNode=c;a.gainNode=c.gainNode}else{this.stopInstance(a)}}},unpauseInstance:function(a){if(a){if(a.loop){a.sourceNode.start(0)}}},setInstanceVolume:function(a,b){if(a){a.gainNode.gain.value=b;a.volume=b}},setInstancePitch:function(a,b){},pauseAll:function(){for(var a=0,b=this.activeInstances.length;a<b;a++){this.pauseInstance(this.activeInstances[a])}gs.StandardAudioManager.prototype.pauseAll.call(this)},unpauseAll:function(){for(var a=0,b=this.activeInstances.length;a<b;a++){this.unpauseInstance(this.activeInstances[a])}gs.StandardAudioManager.prototype.unpauseAll.call(this)},stopAllSounds:function(){while(this.activeInstances.length>0){this.stopInstance(this.activeInstances[0])}this.removeAllWaitingInstances()},startWaitingInstances:function(d,b){for(var c=0;c<this.waitQueue.length;c++){var a=this.waitQueue[c];if(a.assetID===d){a.buffer=b;a.sourceNode.start(0)}}this.removeWaitingInstances(d)},removeWaitingInstances:function(c){for(var b=0;b<this.waitQueue.length;b++){var a=this.waitQueue[b];if(a.assetID===c){this.waitQueue.splice(b,1);b--}}},removeAllWaitingInstances:function(a){this.waitQueue.length=0},prepareSoundForNextPlay:function(e){try{var a=this.context.createBufferSource();a.assetID=e;a.sourceNode=a;var b=this.bufferMap[e];if(b){a.buffer=b;a.ready=true}if(a.addEventListener){a.addEventListener("ended",gs.ExtensionAudioManager.onBufferSourceEnded,false)}else{a.onended=gs.ExtensionAudioManager.onBufferSourceEnded}var d=this.context.createGain();a.sourceNode.connect(d);a.gainNode=d;d.connect(this.soundGain);this.instanceMap[e]=a}catch(c){gs.Log.error("gs.ExtensionAudioManager.prepareSoundForNextPlay",c)}},initWithGame:function(a){this.__super.initWithGame.call(this,a);gs.Game.current.eventCenter.registerForEvent("sceneWillEnd",this,"removeAllWaitingInstances",null)},loadAssets:function(a){for(var b=0,c=a.length;b<c;b++){var d=a[b];if(!this.bufferMap.hasOwnProperty(d)){this.loadAsset(d)}}},loadAsset:function(c){if(this.bufferMap[c]||this.bufferMap[c]===null){return}this.bufferMap[c]=null;var b=this.getAssetPath(c);var a=new XMLHttpRequest();a.open("GET",b,true);a.assetID=c;a.responseType="arraybuffer";a.addEventListener("load",gs.ExtensionAudioManager.onRequestLoad,false);a.addEventListener("error",gs.ExtensionAudioManager.onRequestError,false);a.send()},onRequestLoad:function(e,d){var b=(e.status===200||e.status===0);if(!b||!e.response){gs.Log.error("Sound load failed:",e.assetID);return}var c=this;this.context.decodeAudioData(e.response,function a(g){c.bufferMap[e.assetID]=g;c.startWaitingInstances(e.assetID,g);c.prepareSoundForNextPlay(e.assetID)},function f(){gs.ExtensionAudioManager.onDecodeError()})},onSourceBufferEnded:function(b,a){this.stopInstance(b)}};gs.inherits(gs.ExtensionAudioManager,gs.StandardAudioManager);gs.ExternalAudioManager=function(){gs.AudioManagerBase.call(this);this.external=new gs.html5.ExternalAudioPlayer();this.currentMusic=null;this.soundInstances=[]};gs.ExternalAudioManager.prototype={setMasterVolume:function(a){this.external.setMasterMusicVolume(a);this.external.setMasterSoundVolume(a);this.__super.setMasterVolume.call(this,a)},setMusicVolume:function(a){this.external.setMasterMusicVolume(a);this.__super.setSoundVolume.call(this,a)},setSoundVolume:function(a){this.external.setMasterSoundVolume(a);this.__super.setSoundVolume.call(this,a)},playMusic:function(b,a){if(b&&b!=="undefined"){if(this.musicIsActive){this.stopMusic()}this.startMusic(b,a)}else{if(this.musicIsActive&&!this.musicIsPlaying){this.unpauseMusic()}}},startMusic:function(c,a){var b=this.external.newHandle(c);this.currentMusic=this.external.createMusicInstance(b);this.external.setAudioInstanceLoop(this.currentMusic,a);this.external.playAudioInstance(this.currentMusic);this.__super.startMusic.call(this)},stopMusic:function(){if(this.currentMusic){this.external.stopAudioInstance(this.currentMusic);this.currentMusic=null}this.__super.stopMusic.call(this)},pauseMusic:function(){if(this.currentMusic&&this.musicIsPlaying){this.external.pauseAudioInstance(this.currentMusic)}this.__super.pauseMusic.call(this)},unpauseMusic:function(){if(this.currentMusic&&this.musicIsActive&&!this.musicIsPlaying){this.external.resumeAudioInstance(this.currentMusic)}this.__super.unpauseMusic.call(this)},playSound:function(e,c,b){var d=this.external.newHandle(e);var a=this.external.createSoundInstance(d,false);this.external.setAudioInstanceVolume(a,c);this.external.setAudioInstanceLoop(a,b);this.external.playAudioInstance(a);this.soundInstances.push(a);return a},stopInstance:function(a){if(a){this.external.stopAudioInstance(a)}},pauseInstance:function(a){if(a){this.external.pauseAudioInstance(a)}},unpauseInstance:function(a){if(a){this.external.resumeAudioInstance(a)}},setInstanceVolume:function(a,b){if(a){this.external.setAudioInstanceVolume(a,b)}},setInstancePitch:function(a,b){},pauseAll:function(){this.external.pauseAllAudioInstances()},unpauseAll:function(){this.external.resumeAllAudioInstances()},stopAllSounds:function(){for(var a=0;a<this.soundInstances.length;a++){this.external.stopAudioInstance(this.soundInstances[a])}this.soundInstances.length=0},initWithGame:function(a){this.__super.initWithGame.call(this,a);gs.Game.current.eventCenter.registerForEvent("sceneWillEnd",this,"stopAllSounds",null)},loadAssets:function(a){}};gs.inherits(gs.ExternalAudioManager,gs.AudioManagerBase);gs.AudioManager={current:null,init:function(a){gs.AudioManager.current=gs.AudioManager.create(a)},create:function(a){if(a!==gs.AudioOption.STANDARD){if(/\bGameSalad\b/.test(navigator.userAgent)){return new gs.ExternalAudioManager()}if(gs.html5.Audio.isWebAudioExtensionSupported()){return new gs.ExtensionAudioManager()}}return new gs.StandardAudioManager()}};gs.Condition=function(){this.__superclass.call(this);this.rule=null;this.ruleIndex=0;this.predicate=null;this.subjectPredicate=null;this.subjectAttribute=null;this.testMethod=gs.Condition.prototype.nullTest;this._parent=null};gs.Condition.EVENT_TYPE=0;gs.Condition.ATTRIBUTE_TYPE=1;gs.Condition.NUMERIC_EXPRESSION_TYPE=2;gs.Condition.STRING_EXPRESSION_TYPE=3;gs.Condition.prototype={declareAttributes:function(a){a.addReferenceImmutableAttribute("subjectAttribute")},clone:function(){var a=this.__class.provide();a.attributes=this.attributes.clone();a.testMethod=this.testMethod;if(this.predicate){a.predicate=this.predicate.clone();a.predicate._parent=a}if(this.subjectPredicate){a.subjectPredicate=this.subjectPredicate.clone();a.subjectPredicate._parent=a}return a},start:function(a){if(this.predicate){this.predicate.start(a)}if(this.subjectPredicate){this.subjectPredicate.start(a);this.subjectPredicate.attributes.RHS.addObserver(this)}if(this.subjectAttribute){this.subjectAttribute.addObserver(this)}},stop:function(a){if(this.subjectAttribute){this.subjectAttribute.removeObserver(this)}if(this.predicate){this.predicate.stop(a)}if(this.subjectPredicate){this.subjectPredicate.attributes.RHS.removeObserver(this);this.subjectPredicate.stop(a)}},didEnter:function(a,e,d,b){this.rule=d;this.ruleIndex=b;var c=this.attributes.subjectAttribute.getValue();if(c){this.subjectAttribute=c.resolveRelativeTo(a);if(!this.subjectAttribute){this.testMethod=this.nullTest}}if(this.predicate){this.predicate.didEnter(a,e)}if(this.subjectPredicate){this.subjectPredicate.didEnter(a,e)}},willExit:function(a){if(this.predicate){this.predicate.willExit(a)}if(this.subjectPredicate){this.subjectPredicate.willExit(a)}this.subjectAttribute=null;this.rule=null},testAttribute:function(){var a=this.subjectAttribute.getValue();return this.predicate.testValue(a)},testEvent:function(){return this.predicate.test()},testExpression:function(){return this.predicate.testValue(this.subjectPredicate._RHS)},nullTest:function(){return false},test:function(){return this.testMethod.call(this)},predicateChangedState:function(a){if(!this.rule){return false}return this.rule.conditionChangedState(this.ruleIndex,a)},observeValueChange:function(a,b){if(this.predicate){this.predicate.valueChanged(b)}},loadFromLite:function(g,c){this.__super.loadFromLite.call(this,g,c);var d=g.attributes;var b=g.predicate;var e=g.subjectPredicate;if(b){this.predicate=gs.Parser.parsePredicate(b,c);this.predicate._parent=this}else{gs.Log.warn("Condition missing predicate");this.testMethod=this.nullTest;return}if(e){this.subjectPredicate=gs.Parser.parsePredicate(e,c);this.subjectPredicate._parent=this}var f=gs.Condition.EVENT_TYPE;if(d){var h=gs.Parser.parseAttributeValue(d,"conditionType");if(h){f=parseInt(h,10)}}if(f===gs.Condition.ATTRIBUTE_TYPE){var a=this.attributes.subjectAttribute.getValue();if(a){this.testMethod=this.testAttribute}else{gs.Log.warn("Condition subject reference not found");this.testMethod=this.nullTest}}else{this.attributes.subjectAttribute.changeDefaultValue(null);switch(f){case gs.Condition.EVENT_TYPE:this.testMethod=this.testEvent;break;default:this.testMethod=this.testExpression;break}}}};gs.inherits(gs.Condition,gs.ObjectWithImmutableAttributes);gs.Predicate=gs.PrototypicalImmutableObject.subclass("Predicate",{initPrime:function(){this.attributes=null;this.state=null},start:function(a){},stop:function(a){},didEnter:function(a,b){},willExit:function(a){this.state=false},setState:function(a){if(a!==this.state){this.state=a;this._parent.predicateChangedState(a)}}});gs.EventPredicate=gs.Predicate.subclass("EventPredicate",{test:function(){return this.state},willExit:function(){this.state=false}});gs.AutorotatePredicate=gs.EventPredicate.subclass("AutorotatePredicate");gs.AutorotatePredicate.init=function(){gs.EventPredicate.init.call(this);this.attributes.addIntegerImmutableAttribute("mode",0);return this};gs.AutorotatePredicate.didEnter=function(b,c){var a=gs.Game.current;a.eventCenter.registerForEvent("autorotationStarted",this,"autorotationStarted");a.eventCenter.registerForEvent("autorotationEnded",this,"autorotationEnded");this.state=false};gs.AutorotatePredicate.willExit=function(b){var a=gs.Game.current;a.eventCenter.deregisterForEvent("autorotationStarted",this);a.eventCenter.deregisterForEvent("autorotationEnded",this);gs.EventPredicate.willExit.call(this)};gs.AutorotatePredicate.autorotationStarted=function(){this.state=(this.attributes.mode.getValue()===0);this._parent.predicateChangedState(this.state)};gs.AutorotatePredicate.autorotationEnded=function(){this.state=(this.attributes.mode.getValue()===1);this._parent.predicateChangedState(this.state)};gs.ValuePredicate=gs.Predicate.subclass("ValuePredicate");gs.ValuePredicate.convertValue=function(a){return a};gs.ValuePredicate.testValue=function(a){this._LHS=this.convertValue(a);this.state=this.test(this._LHS,this._RHS);return this.state};gs.ValuePredicate.start=function(a){this._RHS=this.attributes.RHS.getValue();this.attributes.RHS.addObserver(this)};gs.ValuePredicate.stop=function(a){this.attributes.RHS.removeObserver(this)};gs.ValuePredicate.valueChanged=function(b){this._LHS=this.convertValue(b);var a=this.test(this._LHS,this._RHS);this.setState(a)};gs.ValuePredicate.observeValueChange=function(a,c){this._RHS=c;var b=this.test(this._LHS,c);this.setState(b)};gs.EnumerationPredicate=gs.ValuePredicate.subclass("EnumerationPredicate");gs.EnumerationPredicate.init=function(){gs.ValuePredicate.init.call(this);this.attributes.addStringImmutableAttribute("operator","is");this.attributes.addIntegerExpressionAttribute("RHS",0);return this};gs.EnumerationPredicate.willExit=function(a){this.attributes.RHS.releaseExpressionInputs();this.state=false};gs.EnumerationPredicate.test=function(c,b){var a=this.attributes.operator.getValue();if(a==="is"){return(c===b)}else{return(c!==b)}};gs.HibernatePredicate=gs.EventPredicate.subclass("HibernatePredicate",{init:function(){gs.EventPredicate.init.call(this);this.recievedStartEvent=false;return this},didEnter:function(a,b){gs.EventPredicate.didEnter.call(this,a,b);var c=gs.Game.current.eventCenter;c.registerForEvent("AppHibernateStart",this,"appHibernateStart");c.registerForEvent("AppHibernateResume",this,"appHibernateResume");this.state=false},willExit:function(a){var b=gs.Game.current.eventCenter;b.deregisterForEvent("AppHibernateStart",this);b.deregisterForEvent("AppHibernateResume",this);gs.EventPredicate.willExit.call(this,a)},appHibernateStart:function(){if(!this.recievedStartEvent){this.recievedStartEvent=true;this.state=true;this._parent.predicateChangedState(this.state);this._parent.ruleBehavior().everyFrame()}},appHibernateResume:function(){if(this.recievedStartEvent){this.recievedStartEvent=false;this.state=false;this._parent.predicateChangedState(this.state)}}});gs.MousePredicate=gs.EventPredicate.subclass("MousePredicate");gs.MousePredicate.init=function(){gs.EventPredicate.init.call(this);this.mouseState="down";return this};gs.MousePredicate.clone=function(){var a=gs.EventPredicate.clone.call(this);a.mouseState=this.mouseState;return a};gs.MousePredicate.start=function(b){var a=gs.Game.current;a.eventCenter.registerForEvent("mouseDown",this,"mouseDown");a.eventCenter.registerForEvent("mouseUp",this,"mouseUp")};gs.MousePredicate.stop=function(b){var a=gs.Game.current;a.eventCenter.deregisterForEvent("mouseDown",this);a.eventCenter.deregisterForEvent("mouseUp",this)};gs.MousePredicate.test=function(){var a=gs.Game.current;return a.devices.mouse.button.getValue()};gs.MousePredicate.mouseDown=function(a,c){var b=(this.mouseState==="down");this._parent.predicateChangedState(b)};gs.MousePredicate.mouseUp=function(a,c){var b=(this.mouseState==="up");this._parent.predicateChangedState(b)};gs.MousePredicate.loadFromLite=function(b,a){gs.EventPredicate.loadFromLite.call(this,b,a);this.mouseState=b.mouseState};gs.MousePredicate.loadFromTable=function(b,a){gs.EventPredicate.loadFromTable.call(this,b,a);this.mouseState=b.mouseState};gs.MousePositionPredicate=gs.EventPredicate.subclass("MousePositionPredicate");gs.MousePositionPredicate.OVER_ACTOR=0;gs.MousePositionPredicate.NOT_OVER_ACTOR=1;gs.MousePositionPredicate.init=function(){gs.EventPredicate.init.call(this);this.conditionType=gs.MousePositionPredicate.OVER_ACTOR;return this};gs.MousePositionPredicate.clone=function(){var a=gs.EventPredicate.clone.call(this);a.conditionType=this.conditionType;return a};gs.MousePositionPredicate.start=function(b){this._entity=b;var a=gs.Game.current;a.eventCenter.registerForEvent("mouseMoved",this,"mousePositionChanged");a.eventCenter.registerForEvent("mouseDown",this,"mousePositionChanged");b.attributes.position.x.addObserver(this);b.attributes.position.y.addObserver(this);b.attributes.size.width.addObserver(this);b.attributes.size.height.addObserver(this);b.attributes.rotation.addObserver(this)};gs.MousePositionPredicate.stop=function(b){var a=gs.Game.current;a.eventCenter.deregisterForEvent("mouseDown",this);a.eventCenter.deregisterForEvent("mouseMoved",this);b.attributes.position.x.removeObserver(this);b.attributes.position.y.removeObserver(this);b.attributes.size.width.removeObserver(this);b.attributes.size.height.removeObserver(this);b.attributes.rotation.removeObserver(this);this._entity=null};gs.MousePositionPredicate.observeValueChange=function(d,f){var a=gs.Game.current;var c=this._entity;var b=c.layer;var g=gs.g_tempVec2d;g[0]=a.devices.mouse.position.x.getValue();g[1]=a.devices.mouse.position.y.getValue();if(b.scrollable()){g=b.scene.convertViewToScene(g)}var e=c.testPoint(g);this.setState(e)};gs.MousePositionPredicate.mousePositionChanged=function(b,g){var d=this._entity;var c=d.layer;var a=gs.g_tempVec2d;a[0]=b;a[1]=g;if(c.scrollable()){a=c.scene.convertViewToScene(a)}var f=d.testPoint(a);var e;if(f){e=(this.conditionType===gs.MousePositionPredicate.OVER_ACTOR)}else{e=(this.conditionType===gs.MousePositionPredicate.NOT_OVER_ACTOR)}this.setState(e)};gs.MousePositionPredicate.test=function(){var a=gs.Game.current;var c=this._entity;var b=c.layer;var d=gs.g_tempVec2d;d[0]=a.devices.mouse.position.x.getValue();d[1]=a.devices.mouse.position.y.getValue();if(b.scrollable()){d=b.scene.convertViewToScene(d)}this.state=c.testPoint(d);return this.state};gs.MousePositionPredicate.loadFromLite=function(b,a){gs.EventPredicate.loadFromLite.call(this,b,a);if(b.conditionType==="over actor"){this.conditionType=gs.MousePositionPredicate.OVER_ACTOR}else{this.conditionType=gs.MousePositionPredicate.NOT_OVER_ACTOR}};gs.MousePositionPredicate.loadFromTable=function(b,a){gs.EventPredicate.loadFromTable.call(this,b,a);if(b.conditionType==="over actor"){this.conditionType=gs.MousePositionPredicate.OVER_ACTOR}else{this.conditionType=gs.MousePositionPredicate.NOT_OVER_ACTOR}};gs.NullPredicate=gs.Predicate.subclass("NullPredicate",{init:function(){gs.Predicate.init.call(this);return this},test:function(){return false}});gs.TouchPredicate=gs.EventPredicate.subclass("TouchPredicate",{PRESSED:0,RELEASED:1,INSIDE:2,OUTSIDE:3,MAX_TOUCH_COUNT:5,init:function(){gs.EventPredicate.init.call(this);this.conditionType=gs.TouchPredicate.PRESSED;return this},clone:function(){var a=gs.EventPredicate.clone.call(this);a.conditionType=this.conditionType;return a},didEnter:function(c,d){this._entity=c;this._isActive=true;if(!this.touchStates){this.touchStates=gs.array.provide()}this.trackingTouch=null;var a=gs.Game.current;a.eventCenter.registerForEvent("touchDown",this,"touchDown");a.eventCenter.registerForEvent("touchUp",this,"touchUp");a.eventCenter.registerForEvent("touchCancel",this,"touchCancel");a.eventCenter.registerForEvent("sceneWillPause",this,"sceneWillPause");a.eventCenter.registerForEvent("sceneWillResume",this,"sceneWillResume");if(this.conditionType===gs.TouchPredicate.INSIDE||this.conditionType===gs.TouchPredicate.OUTSIDE){a.eventCenter.registerForEvent("touchMoved",this,"touchMoved");for(var b=0;b<gs.TouchPredicate.MAX_TOUCH_COUNT;b++){this.touchStates[b]=false}}this.state=false},willExit:function(b){gs.EventPredicate.willExit.call(this,b);this._isActive=false;this.touchStates.length=0;var a=gs.Game.current;a.eventCenter.deregisterForEvent("touchDown",this);a.eventCenter.deregisterForEvent("touchUp",this);a.eventCenter.deregisterForEvent("touchCancel",this);a.eventCenter.deregisterForEvent("sceneWillPause",this);a.eventCenter.deregisterForEvent("sceneWillResume",this);if(this.conditionType===gs.TouchPredicate.INSIDE||this.conditionType===gs.TouchPredicate.OUTSIDE){a.eventCenter.deregisterForEvent("touchMoved",this);this.touchStates.length=0}this.trackingTouch=null;this._entity=null},updateStateForTouch:function(c,f){var g=c-1;var e=this.touchStates;if(e[g]!==f){e[g]=f;var b=false;for(var d=0,a=e.length;d<a;d++){b=b||e[d]}this.setState(b)}},touchDown:function(c,b,h){var e=this._entity;var d=e.layer;var a=gs.g_tempVec2d;a[0]=b;a[1]=h;if(d.scrollable()){a=d.scene.convertViewToScene(a)}var g=e.testPoint(a);var f=this.conditionType;if(f===gs.TouchPredicate.PRESSED||f===gs.TouchPredicate.RELEASED){if(g){this.trackingTouch=c;this.setState(this.conditionType===gs.TouchPredicate.PRESSED)}}else{if(f===gs.TouchPredicate.INSIDE){this.updateStateForTouch(c,g)}else{this.updateStateForTouch(c,!g)}}},touchUp:function(c,b,h){var e=this._entity;var d=e.layer;var a=gs.g_tempVec2d;a[0]=b;a[1]=h;if(d.scrollable()){a=d.scene.convertViewToScene(a)}var g=e.testPoint(a);var f=this.conditionType;if(f===gs.TouchPredicate.PRESSED||f===gs.TouchPredicate.RELEASED){if(c===this.trackingTouch){this.setState(g&&this.conditionType===gs.TouchPredicate.RELEASED);this.trackingTouch=null}}else{this.updateStateForTouch(c,false)}},touchCancel:function(){var b=this.touchStates.length;for(var a=1;a<=b;a++){this.updateStateForTouch(a,false)}},touchMoved:function(c,b,g){var e=this._entity;var d=e.layer;var a=gs.g_tempVec2d;a[0]=b;a[1]=g;if(d.scrollable()){a=d.scene.convertViewToScene(a)}var f=e.testPoint(a);if(this.conditionType===gs.TouchPredicate.INSIDE){this.updateStateForTouch(c,f)}else{this.updateStateForTouch(c,!f)}},sceneWillPause:function(c){var b=this._entity;if(this._isActive&&c===b.scene){var a=gs.Game.current;a.eventCenter.deregisterForEvent("touchDown",this);a.eventCenter.deregisterForEvent("touchUp",this)}},sceneWillResume:function(c){var b=this._entity;if(this._isActive&&c===b.scene){var a=gs.Game.current;a.eventCenter.registerForEvent("touchDown",this,"touchDown");a.eventCenter.registerForEvent("touchUp",this,"touchUp");if(this.conditionType===gs.TouchPredicate.PRESSED&&this.trackingTouch!==null){this.setState(false);this.trackingTouch=null}}},loadFromLite:function(b,a){gs.EventPredicate.loadFromLite.call(this,b,a);switch(b.conditionType){case"released":this.conditionType=gs.TouchPredicate.RELEASED;break;case"inside":this.conditionType=gs.TouchPredicate.INSIDE;break;case"outside":this.conditionType=gs.TouchPredicate.OUTSIDE;break;default:this.conditionType=gs.TouchPredicate.PRESSED;break}},loadFromTable:function(b,a){gs.EventPredicate.loadFromTable.call(this,b,a);switch(b.conditionType){case"released":this.conditionType=gs.TouchPredicate.RELEASED;break;case"inside":this.conditionType=gs.TouchPredicate.INSIDE;break;case"outside":this.conditionType=gs.TouchPredicate.OUTSIDE;break;default:this.conditionType=gs.TouchPredicate.PRESSED;break}}});gs.KeyPredicate=gs.EventPredicate.subclass("KeyPredicate");gs.KeyPredicate.init=function(){gs.EventPredicate.init.call(this);this.attributes.addStringImmutableAttribute("mode","down");this.attributes.addStringImmutableAttribute("keyString","");return this};gs.KeyPredicate.didEnter=function(b,c){var a=gs.Game.current;a.eventCenter.registerForEvent("keyDown",this,"keyDown");a.eventCenter.registerForEvent("keyUp",this,"keyUp");this.keyString=this.attributes.keyString.getValue();this.state=(this.attributes.mode.getValue()==="up")};gs.KeyPredicate.willExit=function(b){var a=gs.Game.current;a.eventCenter.deregisterForEvent("keyDown",this);a.eventCenter.deregisterForEvent("keyUp",this);this.keyString=null};gs.KeyPredicate.keyEvent=function(b,e){var c=false;if(this.keyString===b.toUpperCase()||this.keyString===b.toLowerCase()){var a=this.state;var d=(this.attributes.mode.getValue()===e);if(a!==d){this.state=d;var f=this._parent;c=f.predicateChangedState(d)}}return c};gs.KeyPredicate.keyDown=function(a){return this.keyEvent(a,"down")};gs.KeyPredicate.keyUp=function(a){return this.keyEvent(a,"up")};gs.CollisionPredicate=gs.EventPredicate.subclass("CollisionPredicate");gs.CollisionPredicate.PROTOTYPE_MODE=0;gs.CollisionPredicate.TAG_MODE=1;gs.CollisionPredicate.init=function(){gs.EventPredicate.init.call(this);this.attributes.addStringImmutableAttribute("prototypeKey","");this.attributes.addStringImmutableAttribute("actorTag","");this.attributes.addIntegerImmutableAttribute("mode",gs.CollisionPredicate.PROTOTYPE_MODE);this._numCollisions=0;return this};gs.CollisionPredicate.clone=function(){var a=this.__class.provide();a._category=this._category;return a};gs.CollisionPredicate.didEnter=function(a,d){var b=this._category;this._numCollisions=0;this.state=false;if(b){var c=a.scene;c._collisionController.addActorSensor(a,b,this)}};gs.CollisionPredicate.willExit=function(a){var b=this._category;if(b){var c=a.scene;c._collisionController.removeActorSensor(a,b,this)}gs.EventPredicate.willExit.call(this)};gs.CollisionPredicate.collisionBegan=function(b,a){this._numCollisions++;if(this._numCollisions===1){this.state=true;this._parent.predicateChangedState(true)}};gs.CollisionPredicate.collisionEnded=function(b,a){this._numCollisions--;if(this._numCollisions===0){this.state=false;this._parent.predicateChangedState(false)}};gs.CollisionPredicate.loadFromLite=function(b,a){gs.EventPredicate.loadFromLite.call(this,b,a);this.didLoad(a)};gs.CollisionPredicate.loadFromTable=function(b,a){gs.EventPredicate.loadFromTable.call(this,b,a);this.didLoad(a)};gs.CollisionPredicate.didLoad=function(a){var c=this.attributes.mode.getValue();if(c===gs.CollisionPredicate.PROTOTYPE_MODE){var b=this.attributes.prototypeKey.getValue();if(b&&(b.length>0)){this._category=b}}else{this._category=this.attributes.actorTag.getValue()}};gs.NumberPredicate=gs.ValuePredicate.subclass("NumberPredicate");gs.NumberPredicate.init=function(){gs.ValuePredicate.init.call(this);this.attributes.addStringImmutableAttribute("operator","=");this.attributes.addRealExpressionAttribute("RHS",0);return this};gs.NumberPredicate.clone=function(){var a=gs.ValuePredicate.clone.call(this);a.test=this.test;return a};gs.NumberPredicate.willExit=function(a){this.attributes.RHS.releaseExpressionInputs();this.state=false};gs.NumberPredicate.testEquality=function(b,a){return(Math.abs(b-a)<0.1)};gs.NumberPredicate.testInequality=function(b,a){return(Math.abs(b-a)>=0.1)};gs.NumberPredicate.testGreaterThan=function(b,a){return(b>a)};gs.NumberPredicate.testLessThan=function(b,a){return(b<a)};gs.NumberPredicate.testGreaterThanOrEqual=function(b,a){return(b>=a)};gs.NumberPredicate.testLessThanOrEqual=function(b,a){return(b<=a)};gs.NumberPredicate.convertValue=function(a){return typeof a==="number"?a:Number(a)};gs.NumberPredicate.loadFromLite=function(b,a){gs.ValuePredicate.loadFromLite.call(this,b,a);this.didLoad(a)};gs.NumberPredicate.loadFromTable=function(b,a){gs.ValuePredicate.loadFromTable.call(this,b,a);this.didLoad(a)};gs.NumberPredicate.didLoad=function(a){var b=this.attributes.operator.getValue();if(b==="="){this.test=this.testEquality}else{if(b==="!="){this.test=this.testInequality}else{if(b===">"){this.test=this.testGreaterThan}else{if(b==="<"){this.test=this.testLessThan}else{if(b===">="){this.test=this.testGreaterThanOrEqual}else{if(b==="<="){this.test=this.testLessThanOrEqual}}}}}}};gs.BooleanPredicate=gs.ValuePredicate.subclass("BooleanPredicate");gs.BooleanPredicate.init=function(){gs.ValuePredicate.init.call(this);this.attributes.addIntegerImmutableAttribute("RHS",true);return this};gs.BooleanPredicate.didEnter=function(a,b){this._RHS=this.convertValue(this.attributes.RHS.getValue())};gs.BooleanPredicate.start=gs.NOOP_FUNCTION;gs.BooleanPredicate.stop=gs.NOOP_FUNCTION;gs.BooleanPredicate.convertValue=function(a){return !(a===false||a===0||a==="false")};gs.BooleanPredicate.test=function(b,a){return(b==a)};gs.PurchasePredicate=gs.EventPredicate.subclass("PurchasePredicate",{ITEM_ANY:0,EVENT:{ANY:0,SUCCESS:1,FAILURE:2,CANCEL:3},init:function(){gs.EventPredicate.init.call(this);this.attributes.addIntegerImmutableAttribute("item",0);this.attributes.addIntegerImmutableAttribute("conditionType",0);return this},didEnter:function(b,c){gs.EventPredicate.didEnter.call(this,b,c);this._conditionType=this.attributes.conditionType.getValue();this._itemIndex=this.attributes.item.getValue();var a=gs.Game.current;if(this._conditionType==gs.PurchasePredicate.EVENT.ANY||this._conditionType==gs.PurchasePredicate.EVENT.SUCCESS){a.eventCenter.registerForEvent("purchaseItemSuccess",this,"purchaseItemSuccess")}if(this._conditionType==gs.PurchasePredicate.EVENT.ANY||this._conditionType==gs.PurchasePredicate.EVENT.FAILURE){a.eventCenter.registerForEvent("purchaseItemFailure",this,"purchaseItemFailure")}if(this._conditionType==gs.PurchasePredicate.EVENT.ANY||this._conditionType==gs.PurchasePredicate.EVENT.CANCEL){a.eventCenter.registerForEvent("purchaseItemCancel",this,"purchaseItemCancel")}this.state=false},willExit:function(b){var a=gs.Game.current;a.eventCenter.deregisterForEvent("purchaseItemSuccess",this,"purchaseItemSuccess");a.eventCenter.deregisterForEvent("purchaseItemFailure",this,"purchaseItemFailure");a.eventCenter.deregisterForEvent("purchaseItemCancel",this,"purchaseItemCancel");gs.EventPredicate.willExit.call(this,b)},purchaseItemSuccess:function(a){a=parseInt(a,10);if(this._itemIndex===gs.PurchasePredicate.ITEM_ANY||this._itemIndex===a){this.setState((this._conditionType===gs.PurchasePredicate.EVENT.SUCCESS)||(this._conditionType===gs.PurchasePredicate.EVENT.ANY));this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.SUCCESS)}},purchaseItemFailure:function(a){a=parseInt(a,10);if(this._itemIndex===gs.PurchasePredicate.ITEM_ANY||this._itemIndex===a){this.setState((this._conditionType===gs.PurchasePredicate.EVENT.FAILURE)||(this._conditionType===gs.PurchasePredicate.EVENT.ANY));this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.FAILURE)}},purchaseItemCancel:function(a){a=parseInt(a,10);if(this._itemIndex===gs.PurchasePredicate.ITEM_ANY||this._itemIndex===a){this.setState((this._conditionType===gs.PurchasePredicate.EVENT.CANCEL)||(this._conditionType===gs.PurchasePredicate.EVENT.ANY));this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.CANCEL)}},updateGameServiceStatus:function(c,a){var b=gs.Game.current;b.services.purchases.item.setValue(c);b.services.purchases.status.setValue(a)}});gs.StringPredicate=gs.ValuePredicate.subclass("StringPredicate");gs.StringPredicate.init=function(){gs.ValuePredicate.init.call(this);this.attributes.addStringImmutableAttribute("operator","contains");this.attributes.addStringExpressionAttribute("RHS","");return this};gs.StringPredicate.willExit=function(a){gs.ValuePredicate.willExit.call(this,a);this.attributes.RHS.releaseExpressionInputs()};gs.StringPredicate.test=function(d,c){var b=d;if(b===null||b===undefined){return false}if(typeof b!=="string"){b=String(b)}var a=this.attributes.operator.getValue();switch(a){case"is":return(b===c);case"contains":return gs.string.contains(b,c);case"beginsWith":return gs.string.beginsWith(b,c);case"endsWith":return gs.string.endsWith(b,c);case"isNot":return(b!==c);case"doesNotContain":return !gs.string.contains(b,c);case"doesNotBeginWith":return !gs.string.beginsWith(b,c);case"doesNotEndWith":return !gs.string.endsWith(b,c);default:gs.Log.strict("Unrecognized text predicate operator:",a);return false}};gs.Reference=function(){this.keypath=null;this.components=null;this.game=false;this.scene=false;this.attributes=false;this.leaf=null};gs.Reference.cache={};gs.Reference.lookup=function(c){var a=gs.Reference.cache[c];if(!a){a=new gs.Reference();a.keypath=c;var d=c.split(".");var b=d.shift();if(b==="game"){a.game=true}else{if(b==="scene"){a.scene=true}}if(d[0]==="attributes"){a.attributes=true;d.shift()}if(d.length===1){a.leaf=d[0];gs.array.recycle(d)}else{a.components=d}gs.Reference.cache[c]=a}return a};gs.Reference.loadFromLiteStatic=function(a){};gs.Reference.loadFromTableStatic=function(b){var a=b.keypath;return gs.Reference.lookup(a)};gs.Reference.prototype={sourceRoot:function(a){if(this.game){a=gs.Game.current}else{if(this.scene){a=gs.Game.current.getCurrentScene()}}if(this.attributes){a=a.attributes}return a},resolveRelativeTo:function(b){var c=this.sourceRoot(b);var a;if(this.leaf){a=c[this.leaf]}else{a=c.valueForKeypathArray(this.components)}if(!a){gs.Log.strict("Could not resolve keypath:",this.keypath)}return a}};gs.Expression=gs.GameSaladObject.subclass("Expression");gs.Expression._sharedLoadArray=[];gs.FAILURE_EXPRESSION=function(a){return"Invalid Expression"};gs.Expression.init=function(){this.expressionTree=null;this.inputReferences=null;this.inputReferenceCount=0;this.entity=null;this.inputAttributes=null;this.needsUpdate=true;this.alwaysNeedsUpdate=false;this.delegate=null;this.isObservingAttributes=false;return this};gs.Expression.clone=function(){var a=this.__class.provide();a.expressionTree=this.expressionTree;a.inputReferenceCount=this.inputReferenceCount;a.inputReferences=this.inputReferences;a.entity=null;a.inputAttributes=null;a.needsUpdate=true;a.alwaysNeedsUpdate=this.alwaysNeedsUpdate;a.delegate=null;a.hasResolvedAttributes=false;a.isObservingAttributes=false;return a};gs.Expression.evaluateForEntity=function(c){if(c!==this.entity){this.resolveInputAttributesForEntity(c);this.entity=c;this.needsUpdate=true}if(!this.isObservingAttributes){this.observeInputs(this.inputAttributes)}var a=this.inputAttributes;var f=this.expressionTree;for(var b in a){var e=a[b];var d=e.getValue();f.setVariable(b,d)}this.needsUpdate=this.alwaysNeedsUpdate;return f.evaluateRoot()};gs.Expression.evaluateForEntityStateless=function(c){var f=this.expressionTree;var d=this.inputReferences;if(d){for(var b in d){var a=d[b];var e=a.resolveRelativeTo(c);if(e){f.setVariable(b,e.getValue())}}}return f.evaluateRoot()};gs.Expression.resolveInputAttributesForEntity=function(d){var e=this.inputReferences;if(e){var b=this.inputAttributes;if(!b){b=gs.Map.provide();this.inputAttributes=b}for(var c in e){var a=e[c];var f=a.resolveRelativeTo(d);if(f){b[c]=f}else{gs.Log.warn("Expression could not resolve reference ",c);delete b[c]}}}};gs.Expression.toExpressionString=function(a){var b="";for(var d=0,e=a.length;d<e;d++){var c=a[d];if(typeof(c)==="object"){b+=c.keypath}else{b+=c;if(/random/.test(c)){this.alwaysNeedsUpdate=true}}}return b};gs.Expression.observeInputs=function(a){for(var c in a){var b=a[c];b.addObserver(this)}this.isObservingAttributes=true};gs.Expression.releaseInputs=function(){var a=this.inputAttributes;for(var c in a){var b=a[c];b.removeObserver(this)}this.entity=null;this.isObservingAttributes=false;this.needsUpdate=true};gs.Expression.setDelegate=function(a){this.delegate=a};gs.Expression.observeValueChange=function(a,c){var b=this.delegate;this.needsUpdate=true;if(b){b.expressionInputsChanged()}};gs.Expression.loadFromLite=function(b,a){var k=gs.Expression._sharedLoadArray;k.length=0;var h=this.inputReferences;var g=gs.Reference.lookup;var l=0;if(Array.isArray(b)){for(var e=0;e<b.length;e++){var j=b[e];var f=j.keypath;if(f){if(!h){h=gs.Map.provide();this.inputReferences=h}var d=g(f);h[f]=d;l++;k[e]=d}else{k[e]=j}}}else{var j=b;var f=j.keypath;if(f){if(!h){h=gs.Map.provide();this.inputReferences=h}var d=g(f);h[f]=d;l++;k[0]=d}else{k[0]=j}}this.inputReferenceCount+=l;var c=this.toExpressionString(k);this.expressionTree=gs.SafeExpression.provide().init(c)};gs.Expression.loadFromTable=function(o){var l=gs.Expression._sharedLoadArray;l.length=0;var c=gs.JXON._type;var b=gs.JXON._text;var k=this.inputReferences;var j=gs.Reference.lookup;var m=0;var a=o[gs.JXON._children];for(var g=0,n=a.length;g<n;g++){var f=a[g];var p=f[c];if(p==="string"){l[g]=f[b]}else{if(!k){k=gs.Map.provide();this.inputReferences=k}var h=f.keypath;var e=j(h);k[h]=e;m++;l[g]=e}}this.inputReferenceCount+=m;var d=this.toExpressionString(l);this.expressionTree=gs.SafeExpression.provide().init(d)};var parser=(function(){var f={trace:function c(){},yy:{},symbols_:{error:2,start:3,expression:4,CONCATENATE:5,"+":6,"-":7,"*":8,"/":9,"%":10,"^":11,functionCall:12,"(":13,")":14,term:15,FUNCTION_NAME:16,argumentList:17,IDENTIFIER:18,expressionList:19,LIST_SEPARATOR:20,reference:21,NUMERIC_LITERAL:22,BOOLEAN_LITERAL:23,STRING_LITERAL:24,KEYWORD:25,KEYPATH_SEPARATOR:26,keypath:27,"$accept":0,"$end":1},terminals_:{2:"error",5:"CONCATENATE",6:"+",7:"-",8:"*",9:"/",10:"%",11:"^",13:"(",14:")",16:"FUNCTION_NAME",18:"IDENTIFIER",20:"LIST_SEPARATOR",22:"NUMERIC_LITERAL",23:"BOOLEAN_LITERAL",24:"STRING_LITERAL",25:"KEYWORD",26:"KEYPATH_SEPARATOR"},productions_:[0,[3,1],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,2],[4,2],[4,3],[4,1],[4,3],[4,1],[12,2],[12,2],[17,2],[17,3],[19,1],[19,3],[15,1],[15,1],[15,1],[15,1],[15,1],[21,1],[21,3],[27,1],[27,3]],performAction:function b(g,j,k,n,m,i,l){var h=i.length-1;switch(m){case 1:this.$=i[h];return this.$;break;case 2:this.$={kind:"operation",type:"string",operation:"concatenate",operands:[i[h-2],i[h]]};break;case 3:this.$={kind:"operation",type:"number",operation:i[h-1],operands:[i[h-2],i[h]]};break;case 4:this.$={kind:"operation",type:"number",operation:i[h-1],operands:[i[h-2],i[h]]};break;case 5:this.$={kind:"operation",type:"number",operation:i[h-1],operands:[i[h-2],i[h]]};break;case 6:this.$={kind:"operation",type:"number",operation:i[h-1],operands:[i[h-2],i[h]]};break;case 7:this.$={kind:"operation",type:"number",operation:"mod",operands:[i[h-2],i[h]]};break;case 8:this.$={kind:"operation",type:"number",operation:"negate",operands:[i[h]]};break;case 9:this.$=i[h];break;case 10:this.$={kind:"operation",type:"number",operation:"pow",operands:[i[h-2],i[h]]};break;case 11:this.$=i[h];break;case 12:this.$=i[h-1];break;case 13:this.$=i[h];break;case 14:this.$={kind:"operation",type:"infer",operation:i[h-1],operands:i[h]};break;case 15:this.$={error:true,kind:"operation",type:"error",operation:i[h-1],operands:i[h]};break;case 16:this.$=[];break;case 17:this.$=i[h-1];break;case 18:this.$=[i[h]];break;case 19:this.$=i[h-2];this.$.push(i[h]);break;case 20:this.$={kind:"reference",type:"infer",reference:i[h]};break;case 21:this.$={kind:"literal",type:"number",literal:parseFloat(i[h])};break;case 22:this.$={kind:"literal",type:"boolean",literal:(i[h]==="true")};break;case 23:this.$={kind:"literal",type:"string",literal:i[h].substr(1,i[h].length-2)};break;case 24:this.$={error:true,kind:"reference",type:"error",reference:i[h]};break;case 25:this.$=i[h];break;case 26:this.$=[i[h-2],i[h-1],i[h]].join("");break;case 27:this.$=i[h];break;case 28:this.$=[i[h-2],i[h-1],i[h]].join("");break}},table:[{3:1,4:2,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{1:[3]},{1:[2,1],5:[1,15],6:[1,16],7:[1,17],8:[1,18],9:[1,19],10:[1,20],11:[1,21]},{4:22,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:23,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{1:[2,11],5:[2,11],6:[2,11],7:[2,11],8:[2,11],9:[2,11],10:[2,11],11:[2,11],14:[2,11],20:[2,11]},{4:24,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{1:[2,13],5:[2,13],6:[2,13],7:[2,13],8:[2,13],9:[2,13],10:[2,13],11:[2,13],14:[2,13],20:[2,13]},{13:[1,26],17:25},{1:[2,24],5:[2,24],6:[2,24],7:[2,24],8:[2,24],9:[2,24],10:[2,24],11:[2,24],13:[1,26],14:[2,24],17:27,20:[2,24]},{1:[2,20],5:[2,20],6:[2,20],7:[2,20],8:[2,20],9:[2,20],10:[2,20],11:[2,20],14:[2,20],20:[2,20]},{1:[2,21],5:[2,21],6:[2,21],7:[2,21],8:[2,21],9:[2,21],10:[2,21],11:[2,21],14:[2,21],20:[2,21]},{1:[2,22],5:[2,22],6:[2,22],7:[2,22],8:[2,22],9:[2,22],10:[2,22],11:[2,22],14:[2,22],20:[2,22]},{1:[2,23],5:[2,23],6:[2,23],7:[2,23],8:[2,23],9:[2,23],10:[2,23],11:[2,23],14:[2,23],20:[2,23]},{1:[2,25],5:[2,25],6:[2,25],7:[2,25],8:[2,25],9:[2,25],10:[2,25],11:[2,25],14:[2,25],20:[2,25],26:[1,28]},{4:29,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:30,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:31,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:32,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:33,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:34,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{4:35,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{1:[2,8],5:[2,8],6:[2,8],7:[2,8],8:[2,8],9:[2,8],10:[2,8],11:[1,21],14:[2,8],20:[2,8]},{1:[2,9],5:[2,9],6:[2,9],7:[2,9],8:[2,9],9:[2,9],10:[2,9],11:[1,21],14:[2,9],20:[2,9]},{5:[1,15],6:[1,16],7:[1,17],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[1,36]},{1:[2,14],5:[2,14],6:[2,14],7:[2,14],8:[2,14],9:[2,14],10:[2,14],11:[2,14],14:[2,14],20:[2,14]},{4:39,6:[1,4],7:[1,3],12:5,13:[1,6],14:[1,37],15:7,16:[1,8],18:[1,9],19:38,21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{1:[2,15],5:[2,15],6:[2,15],7:[2,15],8:[2,15],9:[2,15],10:[2,15],11:[2,15],14:[2,15],20:[2,15]},{18:[1,41],27:40},{1:[2,2],5:[1,15],6:[1,16],7:[1,17],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[2,2],20:[2,2]},{1:[2,3],5:[2,3],6:[2,3],7:[2,3],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[2,3],20:[2,3]},{1:[2,4],5:[2,4],6:[2,4],7:[2,4],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[2,4],20:[2,4]},{1:[2,5],5:[2,5],6:[2,5],7:[2,5],8:[2,5],9:[2,5],10:[2,5],11:[1,21],14:[2,5],20:[2,5]},{1:[2,6],5:[2,6],6:[2,6],7:[2,6],8:[2,6],9:[2,6],10:[2,6],11:[1,21],14:[2,6],20:[2,6]},{1:[2,7],5:[2,7],6:[2,7],7:[2,7],8:[2,7],9:[2,7],10:[2,7],11:[1,21],14:[2,7],20:[2,7]},{1:[2,10],5:[2,10],6:[2,10],7:[2,10],8:[2,10],9:[2,10],10:[2,10],11:[1,21],14:[2,10],20:[2,10]},{1:[2,12],5:[2,12],6:[2,12],7:[2,12],8:[2,12],9:[2,12],10:[2,12],11:[2,12],14:[2,12],20:[2,12]},{1:[2,16],5:[2,16],6:[2,16],7:[2,16],8:[2,16],9:[2,16],10:[2,16],11:[2,16],14:[2,16],20:[2,16]},{14:[1,42],20:[1,43]},{5:[1,15],6:[1,16],7:[1,17],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[2,18],20:[2,18]},{1:[2,26],5:[2,26],6:[2,26],7:[2,26],8:[2,26],9:[2,26],10:[2,26],11:[2,26],14:[2,26],20:[2,26],26:[1,44]},{1:[2,27],5:[2,27],6:[2,27],7:[2,27],8:[2,27],9:[2,27],10:[2,27],11:[2,27],14:[2,27],20:[2,27],26:[2,27]},{1:[2,17],5:[2,17],6:[2,17],7:[2,17],8:[2,17],9:[2,17],10:[2,17],11:[2,17],14:[2,17],20:[2,17]},{4:45,6:[1,4],7:[1,3],12:5,13:[1,6],15:7,16:[1,8],18:[1,9],21:10,22:[1,11],23:[1,12],24:[1,13],25:[1,14]},{18:[1,46]},{5:[1,15],6:[1,16],7:[1,17],8:[1,18],9:[1,19],10:[1,20],11:[1,21],14:[2,19],20:[2,19]},{1:[2,28],5:[2,28],6:[2,28],7:[2,28],8:[2,28],9:[2,28],10:[2,28],11:[2,28],14:[2,28],20:[2,28],26:[2,28]}],defaultActions:{},parseError:function d(h,g){throw new Error(h)},parse:function e(o){var x=this,l=[0],G=[null],s=[],H=this.table,h="",q=0,E=0,j=0,n=2,u=1;this.lexer.setInput(o);this.lexer.yy=this.yy;this.yy.lexer=this.lexer;if(typeof this.lexer.yylloc=="undefined"){this.lexer.yylloc={}}var i=this.lexer.yylloc;s.push(i);if(typeof this.yy.parseError==="function"){this.parseError=this.yy.parseError}function w(p){l.length=l.length-2*p;G.length=G.length-p;s.length=s.length-p}function v(){var p;p=x.lexer.lex()||1;if(typeof p!=="number"){p=x.symbols_[p]||p}return p}var D,z,k,C,I,t,B={},y,F,g,m;while(true){k=l[l.length-1];if(this.defaultActions[k]){C=this.defaultActions[k]}else{if(D==null){D=v()}C=H[k]&&H[k][D]}if(typeof C==="undefined"||!C.length||!C[0]){if(!j){m=[];for(y in H[k]){if(this.terminals_[y]&&y>2){m.push("'"+this.terminals_[y]+"'")}}var A="";if(this.lexer.showPosition){A="Parse error on line "+(q+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+m.join(", ")+", got '"+this.terminals_[D]+"'"}else{A="Parse error on line "+(q+1)+": Unexpected "+(D==1?"end of input":("'"+(this.terminals_[D]||D)+"'"))}this.parseError(A,{text:this.lexer.match,token:this.terminals_[D]||D,line:this.lexer.yylineno,loc:i,expected:m})}if(j==3){if(D==u){throw new Error(A||"Parsing halted.")}E=this.lexer.yyleng;h=this.lexer.yytext;q=this.lexer.yylineno;i=this.lexer.yylloc;D=v()}while(1){if((n.toString()) in H[k]){break}if(k==0){throw new Error(A||"Parsing halted.")}w(1);k=l[l.length-1]}z=D;D=n;k=l[l.length-1];C=H[k]&&H[k][n];j=3}if(C[0] instanceof Array&&C.length>1){throw new Error("Parse Error: multiple actions possible at state: "+k+", token: "+D)}switch(C[0]){case 1:l.push(D);G.push(this.lexer.yytext);s.push(this.lexer.yylloc);l.push(C[1]);D=null;if(!z){E=this.lexer.yyleng;h=this.lexer.yytext;q=this.lexer.yylineno;i=this.lexer.yylloc;if(j>0){j--}}else{D=z;z=null}break;case 2:F=this.productions_[C[1]][1];B.$=G[G.length-F];B._$={first_line:s[s.length-(F||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(F||1)].first_column,last_column:s[s.length-1].last_column};t=this.performAction.call(B,h,E,q,this.yy,C[1],G,s);if(typeof t!=="undefined"){return t}if(F){l=l.slice(0,-1*F*2);G=G.slice(0,-1*F);s=s.slice(0,-1*F)}l.push(this.productions_[C[1]][0]);G.push(B.$);s.push(B._$);g=H[l[l.length-2]][l[l.length-1]];l.push(g);break;case 3:return true}}return true}};var a=(function(){var j=({EOF:1,parseError:function l(o,n){if(this.yy.parseError){this.yy.parseError(o,n)}else{throw new Error(o)}},setInput:function(n){this._input=n;this._more=this._less=this.done=false;this.yylineno=this.yyleng=0;this.yytext=this.matched=this.match="";this.conditionStack=["INITIAL"];this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0};return this},input:function(){var o=this._input[0];this.yytext+=o;this.yyleng++;this.match+=o;this.matched+=o;var n=o.match(/\n/);if(n){this.yylineno++}this._input=this._input.slice(1);return o},unput:function(n){this._input=n+this._input;return this},more:function(){this._more=true;return this},pastInput:function(){var n=this.matched.substr(0,this.matched.length-this.match.length);return(n.length>20?"...":"")+n.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var n=this.match;if(n.length<20){n+=this._input.substr(0,20-n.length)}return(n.substr(0,20)+(n.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var n=this.pastInput();var o=new Array(n.length+1).join("-");return n+this.upcomingInput()+"\n"+o+"^"},next:function(){if(this.done){return this.EOF}if(!this._input){this.done=true}var r,p,o,n;if(!this._more){this.yytext="";this.match=""}var s=this._currentRules();for(var q=0;q<s.length;q++){p=this._input.match(this.rules[s[q]]);if(p){n=p[0].match(/\n.*/g);if(n){this.yylineno+=n.length}this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:n?n[n.length-1].length-1:this.yylloc.last_column+p[0].length};this.yytext+=p[0];this.match+=p[0];this.matches=p;this.yyleng=this.yytext.length;this._more=false;this._input=this._input.slice(p[0].length);this.matched+=p[0];r=this.performAction.call(this,this.yy,this,s[q],this.conditionStack[this.conditionStack.length-1]);if(r){return r}else{return}}}if(this._input===""){return this.EOF}else{this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})}},lex:function g(){var n=this.next();if(typeof n!=="undefined"){return n}else{return this.lex()}},begin:function h(n){this.conditionStack.push(n)},popState:function m(){return this.conditionStack.pop()},_currentRules:function k(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules}});j.performAction=function i(r,o,q,n){var p=n;switch(q){case 0:return"KEYWORD";break;case 1:return"FUNCTION_NAME";break;case 2:return"FUNCTION_NAME";break;case 3:return"FUNCTION_NAME";break;case 4:return"FUNCTION_NAME";break;case 5:return"BOOLEAN_LITERAL";break;case 6:return"IDENTIFIER";break;case 7:return"NUMERIC_LITERAL";break;case 8:return"STRING_LITERAL";break;case 9:return"STRING_LITERAL";break;case 10:return"+";break;case 11:return"-";break;case 12:return"*";break;case 13:return"/";break;case 14:return"%";break;case 15:return"^";break;case 16:return"CONCATENATE";break;case 17:return"KEYPATH_SEPARATOR";break;case 18:return"LIST_SEPARATOR";break;case 19:return"(";break;case 20:return")";break;case 21:break}};j.rules=[/^\b(self|scene|game)\b/,/^\b(random|abs|max|min|sqrt|sin|cos|tan|asin|acos|atan|vectorToAngle|magnitude|ceil|floor|round|roundTo|log10|ln|exp|pow|mod)\b/,/^\b(prec|padInt|padReal|textFind|textLength|textRepeat|textReplace|textReplaceAll|textSubStr)\b/,/^\b(tableCellValue|tableRowCount|tableColCount|tableColNumber|tableColSum|tableMergeValues|tableRowNumber|tableSearch)\b/,/^\b(networkPlayerTableForId|networkPlayerIdForTable|networkPlayerNumberForId|networkPlayerIdForNumber)\b/,/^\b(true|false)\b/,/^[_a-zA-Z][_a-zA-Z0-9]*/,/^[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/,/^'[^']*'/,/^"[^\"]*"/,/^\+/,/^-/,/^\*/,/^\//,/^%/,/^\^/,/^\.\./,/^\./,/^,/,/^\(/,/^\)/,/^\s+/];j.conditions={INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21],inclusive:true}};return j})();f.lexer=a;return f})();gs.SafeExpressionCache={};gs.SafeExpression=function(){this.original=null;this.vars=null;this.root=null};gs.Pool.init(gs.SafeExpression);gs.SafeExpression.prototype={defaultValue:0,constantPattern:/^[-+]?[.\d]+$/,useConstant:false,constantValue:0,referencePattern:/^(self|scene|game)(\.\w+)*$/,useFastReference:false,fastReference:null,fastReferenceValue:0,randomPattern:/^\s*random\(\s*(-?\d+)\s*,\s*(-?\d+)\s*\)\s*$/,useFastRandom:false,fastRandomA:0,fastRandomB:0,init:function(g){this.original=g;var f=this.constantPattern.test(g);if(f){this.useConstant=true;this.constantValue=parseFloat(g,10);return this}var d=this.referencePattern.test(g);if(d){this.useFastReference=true;this.fastReference=g;this.fastReferenceValue=0;return this}var e=this.randomPattern.test(g);if(e){var b=this.randomPattern.exec(g);this.useFastRandom=true;this.fastRandomA=b[1]|0;this.fastRandomB=b[2]|0;if(this.fastRandomA>this.fastRandomB){this.fastRandomA=b[2]|0;this.fastRandomB=b[1]|0}gs.array.recycle(b);return this}this.vars=gs.Map.provide();var a=gs.SafeExpressionCache[g];if(!a){try{a=parser.parse(g);this.normalize(a);a=this.reduce(a);gs.SafeExpressionCache[g]=a}catch(c){gs.Log.strict("Expression syntax error in:",g,"\n"+c.message);this.root=parser.parse(String(this.defaultValue))}}this.root=a;return this},ensureString:function(a){if(typeof a!=="string"){return String(a)}return a},padInt:function(b,c,a){if(a===undefined){a=true}var d=((a)?Math.floor(b):b)+"";while(d.length<c){d="0"+d}return d},prec:function(b,a){return b.toFixed(a)},padReal:function(c,b,a){return this.padInt(this.prec(c,a),b,false)},textFind:function(d,c,b){d=this.ensureString(d);c=this.ensureString(c);var a=d.indexOf(c,b-1);return a!==-1?a+1:-1},textLength:function(a){a=this.ensureString(a);return a.length},textRepeat:function(c,d){var b="";c=this.ensureString(c);for(var a=0;a<d;a++){b+=c}return b},textReplace:function(c,b,a){c=this.ensureString(c);b=this.ensureString(b);return c.replace(b,a)},textReplaceAll:function(d,c,a){d=this.ensureString(d);c=this.ensureString(c);var b=new RegExp(c,"g");return d.replace(b,a)},textSubStr:function(c,b,a){c=this.ensureString(c);return c.substring(b-1,a)},sin:function(a){return Math.sin(a*gsMath.DEG2RAD)},cos:function(a){return Math.cos(a*gsMath.DEG2RAD)},tan:function(a){return Math.tan(a*gsMath.DEG2RAD)},asin:function(a){return Math.asin(a)*gsMath.RAD2DEG},acos:function(a){return Math.acos(a)*gsMath.RAD2DEG},atan:function(a){return Math.atan(a)*gsMath.RAD2DEG},vectorToAngle:function(a,b){return Math.atan2(b,a)*gsMath.RAD2DEG},magnitude:function(a,b){return Math.sqrt(a*a+b*b)},lua_mod:function(d,c){return d-Math.floor(d/c)*c},legacy_mod:function(a,b){a=a|0;b=b|0;return a-Math.floor(a/b)*b},random:function(d,c){if(d>=c){return d}d=d|0;c=c|0;var e=Math.random();return(d+e*(c-d+1))|0},fastRandom:function(d,c){var e=Math.random();return(d+e*(c-d+1))|0},log10:function(a){return Math.log(a)/Math.log(10)},roundTo:function(a,c){var b=Math.pow(10,c);return Math.floor(a*b+0.5)/b},tableCellValue:function(b,c,a){if(!b||!b.getCellSafe){return 0}return b.getCellSafe(c,a)},tableRowCount:function(a){return a.getRowCount()},tableColCount:function(a){return a.getColumnCount()},tableRowNumber:function(b,a){return b.lookupRow(a)},tableColNumber:function(b,a){return b.lookupColumn(a)},tableColSum:function(d,c,b,a){return d.sumColumn(c,b,a)},tableMergeValues:function(c,a,f,e,b,d){if(a==="row"){return c.mergeRowValues(f,e,b,d)}else{return c.mergeColumnValues(f,e,b,d)}},tableSearch:function(e,c,b,g,f,d,a){if(b==="row"){return e.searchRow(c,g,f,d,a)}else{return e.searchColumn(c,g,f,d,a)}},setVariable:function(a,b){if(this.useFastReference){this.fastReferenceValue=b}else{this.vars[a]=b}},reduce:function(a){if(typeof a!=="object"){return a}switch(a.kind){case"operation":var b=a.operands;for(var c=0;c<b.length;c++){if(this.canReduce(b[c])){a.operands[c]=this.evaluate(b[c])}else{a.operands[c]=this.reduce(b[c])}}if(this.canReduce(a)){return this.evaluate(a)}return a;case"reference":return a;case"literal":return a.literal;default:gs.Log.strict("Expression evaluation error in:",this.original,"\nNode kind unknown");return this.defaultValue}},canReduce:function(a){if(typeof a!=="object"){return true}switch(a.kind){case"operation":if(a.operation==="random"){return false}var b=a.operands;for(var c=0;c<b.length;c++){if(!this.canReduce(b[c])){return false}}return true;case"reference":return false;case"literal":return true;default:gs.Log.strict("Expression evaluation error in:",this.original,"\nNode kind unknown");return false}},assertOperandCount:function(a,b,c){var d=b.length;if(d!==c){gs.Log.strict("Expression evaluation error in:",this.original,"\nWrong number of arguments to",a,"\nExpected",c,"but received",d)}},evaluate:function(t){if(t===undefined){gs.Log.strict("Expression evaluation error in:",this.original,"\nA value was undefined");return this.defaultValue}else{if(typeof t!=="object"){return t}else{switch(t.kind){case"operation":var j=t.operation;var n=t.operands;var h=t.operandCount;var s=t.operandIsObject;var q,p,o,m,l,k,i;q=s[0]?this.evaluate(n[0]):n[0];if(h>1){p=s[1]?this.evaluate(n[1]):n[1];if(h>2){o=s[2]?this.evaluate(n[2]):n[2];if(h>3){m=s[3]?this.evaluate(n[3]):n[3];if(h>4){l=s[4]?this.evaluate(n[4]):n[4];if(h>5){k=s[5]?this.evaluate(n[5]):n[5];if(h>6){i=s[6]?this.evaluate(n[6]):n[6]}}}}}}switch(j){case"negate":return 0-q;case"abs":return Math.abs(q);case"sqrt":return Math.sqrt(q);case"sin":return this.sin(q);case"cos":return this.cos(q);case"tan":return this.tan(q);case"asin":return this.asin(q);case"acos":return this.acos(q);case"atan":return this.atan(q);case"ceil":return Math.ceil(q);case"floor":return Math.floor(q);case"round":return Math.floor(q+0.5);case"roundTo":return this.roundTo(q,p);case"log10":return this.log10(q);case"ln":return Math.log(q);case"exp":return Math.exp(q);case"+":return q+p;case"-":return q-p;case"*":return q*p;case"/":return q/p;case"^":return Math.pow(q,p);case"concatenate":return""+q+p;case"random":return this.random(q,p);case"max":return q<p?p:q;case"min":return q<p?q:p;case"vectorToAngle":return this.vectorToAngle(q,p);case"magnitude":return this.magnitude(q,p);case"pow":return Math.pow(q,p);case"mod":return this.lua_mod(q,p);case"legacy_mod":return this.legacy_mod(q,p);case"prec":return this.prec(q,p);case"padReal":return this.padReal(q,p,o);case"padInt":return this.padInt(q,p,o);case"tableCellValue":return this.tableCellValue(q,p,o);case"tableColCount":return this.tableColCount(q);case"tableColNumber":return this.tableColNumber(q,p);case"tableRowCount":return this.tableRowCount(q);case"tableRowNumber":return this.tableRowNumber(q,p);case"tableColSum":return this.tableColSum(q,p,o,m);case"tableMergeValues":return this.tableMergeValues(q,p,o,m,l,k);case"tableSearch":return this.tableSearch(q,p,o,m,l,k,i);case"textFind":return this.textFind(q,p,o);case"textLength":return this.textLength(q);case"textRepeat":return this.textRepeat(q,p);case"textReplace":return this.textReplace(q,p,o);case"textReplaceAll":return this.textReplaceAll(q,p,o);case"textSubStr":return this.textSubStr(q,p,o);default:gs.Log.strict("Expression evaluation error in:",this.original,"\nUnrecognized operation",j);return this.defaultValue}case"reference":var r=this.vars[t.reference];if(r===undefined){gs.Log.strict("Expression reference error in:",this.original,"\nThe variable ",t.reference," has no value");return this.defaultValue}return r;case"literal":return t.literal;default:gs.Log.strict("Expression evaluation error in:",this.original,"\nUnrecognized kind",t.kind);return this.defaultValue}}}},evaluateRoot:function(){if(this.useConstant){return this.constantValue}if(this.useFastReference){return this.fastReferenceValue}if(this.useFastRandom){return this.fastRandom(this.fastRandomA,this.fastRandomB)}return this.evaluate(this.root)},normalize:function(a){if(typeof a==="object"&&a.kind==="operation"){var c=a.operands.length;a.operandCount=c;a.operandIsObject=gs.array.provide();for(var b=0;b<c;b++){this.normalize(a.operands[b]);a.operandIsObject[b]=(typeof a.operands[b]==="object")}}}};gs.BehaviorBase=function(){gs.ObjectWithImmutableAttributes.call(this)};gs.BehaviorBase.prototype={isImmutable:function(){return false},start:function(a,b){},stop:function(a,b){},didEnter:function(a,b){},willExit:function(a){},everyFrame:function(a){},registerForEveryFrame:function(a){a.registerForEveryFrame(this)},deregisterForEveryFrame:function(a){a.deregisterForEveryFrame(this)},getRequiredAssets:function(c,a,b){},getRequiredActors:function(b,a){},resolveTableReferenceAttribute:function(a){return gs.Game.current.getTableAttribute(a.getValue())},doStub:function(b,c,a){if(a===undefined){a=null}gs.Game.current.project.deferAction(b,c,a)},loadFromLite:function(c,a){var b=c.attributes;if(b){this.attributes.loadFromLite(b,a)}}};gs.inherits(gs.BehaviorBase,gs.ObjectWithImmutableAttributes);gs.ImmutableBehavior=function(){gs.ImmutableAttributeCollection.call(this);this.attributes=this};gs.ImmutableBehavior.prototype={isImmutable:function(){return true},init:function(){this.declareAttributes(this);return this},declareAttributes:function(a){},clone:function(){return this},start:function(a,b){},stop:function(a,b){},didEnter:function(a,b){},willExit:function(a){},everyFrame:function(a){},registerForEveryFrame:function(a){a.registerForEveryFrame(this)},deregisterForEveryFrame:function(a){a.deregisterForEveryFrame(this)},getRequiredAssets:function(c,a,b){},getRequiredActors:function(b,a){},loadFromLite:function(c,a){var b=c.attributes;if(b){var d=gs.ImmutableAttributeCollection.prototype;d.loadFromLite.call(this,b,a)}},resolveTableReferenceAttribute:function(b){var a=b.getValue();if(!a){return null}return gs.Game.current.getTableAttribute(a)},doStub:function(b,c,a){if(a===undefined){a=null}gs.Game.current.project.deferAction(b,c,a)}};gs.inherits(gs.ImmutableBehavior,gs.ImmutableAttributeCollection);gs.SingletonBehavior=function(){gs.ImmutableBehavior.call(this)};gs.SingletonBehavior.prototype={loadFromLite:function(b,a){}};gs.inherits(gs.SingletonBehavior,gs.ImmutableBehavior);gs.StatelessBehavior=function(){gs.ImmutableBehavior.call(this)};gs.StatelessBehavior.prototype={};gs.inherits(gs.StatelessBehavior,gs.ImmutableBehavior);gs.MutableBehavior=function(){gs.BehaviorBase.call(this)};gs.MutableBehavior.prototype={isImmutable:function(){return false}};gs.inherits(gs.MutableBehavior,gs.BehaviorBase);gs.KeyValuePair=gs.PrototypicalImmutableObject.subclass("KeyValuePair");gs.KeyValuePair.init=function(){gs.PrototypicalImmutableObject.init.call(this);this.attributes.addVariantExpressionAttribute("key","");this.attributes.addVariantExpressionAttribute("value","");return this};gs.KeyValuePair.entity=function(){return this.tableBehavior()._entity};gs.KeyValuePair.tableBehavior=function(){return this._parent._parent};gs.Behavior=gs.PrototypicalImmutableObject.subclass("Behavior");gs.Behavior.isImmutable=function(){return false};gs.Behavior.start=function(a,b){};gs.Behavior.stop=function(a,b){};gs.Behavior.didEnter=function(a,b){this._entity=a};gs.Behavior.willExit=function(a){if(this.attributes){this.attributes.releaseExpressionInputs()}this._entity=null};gs.Behavior.registerForEveryFrame=function(){this._entity.registerForEveryFrame(this)};gs.Behavior.deregisterForEveryFrame=function(){this._entity.deregisterForEveryFrame(this)};gs.Behavior.everyFrame=function(a,b){};gs.Behavior.getRequiredAssets=gs.NOOP_FUNCTION;gs.Behavior.getRequiredActors=gs.NOOP_FUNCTION;gs.Behavior.getUniqueKey=function(){if(!this._uniqueKey){this._uniqueKey=gs.ObjectBase.generateUniqueObjectKey()}return this._uniqueKey};gs.Behavior.resolveTableReferenceAttribute=function(a){return gs.Game.current.getTableAttribute(a.getValue())};gs.Behavior.doStub=function(b,c,a){if(a===undefined){a=null}gs.Game.current.project.deferAction(b,c,a)};gs.CompoundBehavior=gs.Behavior.subclass("CompoundBehavior");gs.CompoundBehavior.init=function(){gs.Behavior.init.call(this);this.behaviors=new gs.BehaviorList();return this};gs.CompoundBehavior.initPrime=function(){this.attributes=null;this.behaviors=null;return this};gs.CompoundBehavior.clone=function(){var a=gs.Behavior.clone.call(this);a.behaviors=this.behaviors.clone();a.behaviors._parent=a;return a};gs.CompoundBehavior.start=function(a,b){this.behaviors.start(a,b)};gs.CompoundBehavior.stop=function(a,b){this.behaviors.stop(a,b)};gs.CompoundBehavior.didEnter=function(a,b){gs.Behavior.didEnter.call(this,a,b);this.behaviors.didEnter(a,b)};gs.CompoundBehavior.willExit=function(a){this.behaviors.willExit(a);gs.Behavior.willExit.call(this,a)};gs.CompoundBehavior.loadFromLite=function(c,b){gs.Behavior.loadFromLite.call(this,c,b);var a=c.behaviors;if(a){this.behaviors.loadFromLite(a,b)}};gs.CompoundBehavior.loadFromTable=function(h,c){gs.Behavior.loadFromTable.call(this,h,c);var j=gs.JXON;var e=j._children;var f=gs.Project.nodeTypeNameMap;var b=h[e];if(b){for(var d=0,g=b.length;d<g;d++){var a=b[d];var k=f[a[j._type]];if(k==="behaviors"){this.behaviors.loadFromTable(a[e],c);break}}}};gs.CompoundBehavior.getRequiredAssets=function(c,a,b){return this.behaviors.getRequiredAssets(c,a,b)};gs.CompoundBehavior.getRequiredActors=function(b,a){this.behaviors.getRequiredActors(b,a)};gs.CompletingBehavior=gs.Behavior.subclass("CompletingBehavior");gs.CompletingBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addBooleanImmutableAttribute("runToCompletion",false);this._running=false;this._completed=false;return this};gs.CompletingBehavior.completed=function(){return this._completed};gs.CompletingBehavior.setCompleted=function(a){this._completed=a};gs.CompletingBehavior.completeStart=function(a,b){this.registerForEveryFrame()};gs.CompletingBehavior.completeEvaluate=function(a,b){};gs.CompletingBehavior.completeStop=function(a,b){this._running=false};gs.CompletingBehavior.start=function(a,b){if(!this._running){this._completed=false;this.completeStart(a,b);this._running=true;this.completeEvaluate(a,b)}};gs.CompletingBehavior.everyFrame=function(a,b){if(this._completed){this.completeStop(a,b);this.deregisterForEveryFrame()}else{this.completeEvaluate(a,b)}};gs.CompletingBehavior.stop=function(a,b){if(this._running&&!this.attributes.runToCompletion.getValue()){this.completeStop(a,b);this.deregisterForEveryFrame()}};gs.CompletingBehavior.willExit=function(a){if(this._running){this.completeStop(a);this.deregisterForEveryFrame()}gs.Behavior.willExit.call(this,a)};gs.BehaviorList=function(){this.count=0;this.immutable=true};gs.BehaviorList.prototype={clone:function(){if(this.immutable){return this}var a=new gs.BehaviorList();a.count=this.count;for(var b=0;b<this.count;b++){a[b]=this[b].clone();a[b]._parent=a}return a},start:function(b,c){for(var a=0;a<this.count;a++){this[a].start(b,c)}},stop:function(b,c){for(var a=0;a<this.count;a++){this[a].stop(b,c)}},didEnter:function(b,c){for(var a=0;a<this.count;a++){this[a].didEnter(b,c)}},willExit:function(b){for(var a=0;a<this.count;a++){this[a].willExit(b)}},getRequiredAssets:function(d,b,c){for(var a=0;a<this.count;a++){this[a].getRequiredAssets(d,b,c)}},getRequiredActors:function(c,b){for(var a=0;a<this.count;a++){this[a].getRequiredActors(c,b)}},loadFromLite:function(d,a){var e=gs.Parser.parseBehaviorClass;var c;if(Array.isArray(d)){this.count=d.length;for(var b=0;b<d.length;b++){c=e(d[b]);c.loadFromLite(d[b],a);c._objectKey=d[b]["id"];c._parent=this;this[b]=c;this.immutable=this.immutable&&c.isImmutable()}}else{this.count=1;c=e(d);c.loadFromLite(d,a);c._objectKey=d.id;c._parent=this;this[0]=c;this.immutable=this.immutable&&c.isImmutable()}}};gs.inherits(gs.BehaviorList,Object);gs.AccelerateBehavior=gs.Behavior.subclass("AccelerateBehavior",{init:function(){gs.Behavior.init.call(this);this.attributes.addRealExpressionAttribute("direction",0);this.attributes.addIntegerImmutableAttribute("space",gs.MoveBehavior.SPACE_ACTOR);this.attributes.addRealExpressionAttribute("acceleration",100);return this},start:function(a,b){this.registerForEveryFrame();this.actor=a;this.attributes.direction.addObserver(this);this.attributes.acceleration.addObserver(this)},stop:function(a,b){this.deregisterForEveryFrame();this.attributes.direction.removeObserver(this);this.attributes.acceleration.removeObserver(this)},everyFrame:function(f,h){var g=f.aspects.motion._body;if(g){var b=this.attributes.space.getValue();var i=this.attributes.direction.getValue();if(b===gs.MoveBehavior.SPACE_ACTOR){i+=this.actor.attributes.rotation.getValue()}var e=i*gsMath.DEG2RAD;var l=Math.cos(e);var k=Math.sin(e);var d=this.attributes.acceleration.getValue();var j=g.getMass()*d;var c=gs.g_tempVec2d;c[0]=l*j;c[1]=k*j;var a=g.getWorldCenter();g.applyForce(c,a)}}});gs.AccelerateTowardBehavior=gs.Behavior.subclass("AccelerateTowardBehavior");gs.AccelerateTowardBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addPointExpressionAttribute("position",0,0);this.attributes.addIntegerImmutableAttribute("space",gs.MoveBehavior.SPACE_SCENE);this.attributes.addRealExpressionAttribute("acceleration",100);return this};gs.AccelerateTowardBehavior.start=function(a,b){this.registerForEveryFrame()};gs.AccelerateTowardBehavior.stop=function(a,b){this.deregisterForEveryFrame()};gs.AccelerateTowardBehavior.everyFrame=function(h,l){var h=this._entity;var i=h.aspects.motion._body;if(i){var b=this.attributes.space.getValue();var m=this.attributes.position.x.getValue();var j=this.attributes.position.y.getValue();var k=gs.g_tempVec2d;k[0]=m;k[1]=j;if(b===gs.MoveBehavior.SPACE_ACTOR){var o=h.attributes.rotation.getValue();gs.Vector2.vectorRotate2D(k,k,o*Math.PI/180)}else{var f=h.attributes.position.x.getValue();var e=h.attributes.position.y.getValue();k[0]=k[0]-f;k[1]=k[1]-e}var d=Math.sqrt(k[0]*k[0]+k[1]*k[1]);if(d>0){k[0]=(k[0]/d);k[1]=(k[1]/d)}else{k[0]=0;k[1]=0}var n=i.getMass();var g=this.attributes.acceleration.getValue();var c=n*g;k[0]=k[0]*c;k[1]=k[1]*c;var a=i.getWorldCenter();i.applyForce(k,a)}};gs.AddRemoveRowAction=function(){gs.StatelessBehavior.call(this)};gs.AddRemoveRowAction.Command={ADD_ROW:0,REMOVE_ROW:1};gs.AddRemoveRowAction.Location={AT_BEGINNING:0,AT_END:1,AT_INDEX:2};gs.AddRemoveRowAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("tableID","");a.addIntegerImmutableAttribute("command",0);a.addIntegerImmutableAttribute("location",0);a.addStringExpressionAttribute("index","")},start:function(c,d){if(!this.targetTable){this.targetTable=this.resolveTableReferenceAttribute(this.attributes.tableID)}var e=this.attributes.command.getValue();var a=this.attributes.location.getValue();var b;switch(a){case gs.AddRemoveRowAction.Location.AT_BEGINNING:b=1;break;case gs.AddRemoveRowAction.Location.AT_END:b=-1;break;case gs.AddRemoveRowAction.Location.AT_INDEX:b=this.attributes.index.getValueForEntityStateless(c);break;default:break}switch(e){case gs.AddRemoveRowAction.Command.ADD_ROW:this.targetTable.addRow(b);break;case gs.AddRemoveRowAction.Command.REMOVE_ROW:this.targetTable.removeRow(b);break;default:break}}};gs.inherits(gs.AddRemoveRowAction,gs.StatelessBehavior);gs.AnimateBehavior=function(){this.__superclass.call(this)};gs.AnimateBehavior.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("images","");a.addIntegerImmutableAttribute("speed",10);a.addBooleanImmutableAttribute("loop",true);a.addBooleanImmutableAttribute("restoreActorImage",true)},clone:function(){var a=this.__super.clone.call(this);a._imagesArray=this._imagesArray;a._timePerFrame=this._timePerFrame;return a},nextFrame:function(a){this._currentImageIndex++;if(this._currentImageIndex===this._imagesArray.length){if(this._loop){this._currentImageIndex=0}else{this.stop(a,null);return}}var b=this._imagesArray[this._currentImageIndex];a.attributes.image.fastSetValue(b)},start:function(a,b){if(this._imagesArray.length===0){return}if(!this._timebase){this._timebase=gs.Timebase.provide()}this._timebase.initWithTime(b);this._timebase.convertTimeStamp(b);this._animationTime=this._timebase.getTimeStamp();this._savedActorImage=a.attributes.image.getValue();this._loop=this.attributes.loop.getValue();this._currentImageIndex=-1;this._timeOfLastFrame=this._animationTime.time;this.nextFrame(a);this.registerForEveryFrame(a)},stop:function(a,b){this.deregisterForEveryFrame(a);if(!this._imagesArray){return}if(this.attributes.restoreActorImage.getValue()&&this._savedActorImage){a.attributes.image.fastSetValue(this._savedActorImage)}this._animationTime=null;if(this._timebase){gs.Timebase.recycle(this._timebase);this._timebase=null}this._loop=null;this._timeOfLastFrame=null;this._currentImageIndex=null;this._savedActorImage=null},everyFrame:function(b,c){if(!this._imagesArray){return}this._timebase.convertTimeStamp(c);var a=this._animationTime.time-this._timeOfLastFrame;if(a>=this._timePerFrame){this._timeOfLastFrame=this._animationTime.time;this.nextFrame(b)}},getRequiredAssets:function(g,c,f){var a=this._imagesArray;for(var b=0,d=a.length;b<d;b++){var e=a[b];g[e]=true}},loadFromLite:function(c,b){this.__super.loadFromLite.call(this,c,b);var a=this.attributes.images.getValue();this._imagesArray=a.split("\t");this._timePerFrame=1/this.attributes.speed.getValue()}};gs.inherits(gs.AnimateBehavior,gs.MutableBehavior);gs.CallExternalFunctionAction=gs.Behavior.subclass("CallExternalFunctionAction",{inputAttributeKeys:["input1","input2","input3","input4","input5","input6","input7","input8","input9","input10"],init:function(){gs.Behavior.init.call(this);this.attributes.addStringImmutableAttribute("functionName","");this.attributes.addIntegerImmutableAttribute("numberOfInputs",0);this.attributes.addStringImmutableAttribute("returnAttribute","");this.attributes.addVariantExpressionAttribute("input1","");this.attributes.addVariantExpressionAttribute("input2","");this.attributes.addVariantExpressionAttribute("input3","");this.attributes.addVariantExpressionAttribute("input4","");this.attributes.addVariantExpressionAttribute("input5","");this.attributes.addVariantExpressionAttribute("input6","");this.attributes.addVariantExpressionAttribute("input7","");this.attributes.addVariantExpressionAttribute("input8","");this.attributes.addVariantExpressionAttribute("input9","");this.attributes.addVariantExpressionAttribute("input10","");this.attributes.addStringImmutableAttribute("notes","");return this},start:function(c,f){var h=this.attributes.functionName.getValue();var e=this.attributes.numberOfInputs.getValue();var m=[];for(var d=0;d<e;d++){var j=this.inputAttributeKeys[d];var k=this.attributes[j];m.push(k.getValue())}switch(h){case"registerOptions":var b=m[0];if(typeof b!=="string"){b=gs.tables.getKeypath(b._objectKey)}var g=this.attributes.returnAttribute.getValue();var l=gs.Game.instance;l.eventCenter.registerForEvent("externalWriteGameAttribute",l,"externalWriteGameAttribute");try{gs.externalDelegate.registerOptions(b,g)}catch(a){gs.Log.warn("ExternalFunctionCall ignored:",h)}break}}});gs.ChangeAttributeAction=function(){gs.StatelessBehavior.call(this)};gs.ChangeAttributeAction.prototype={declareAttributes:function(a){a.addReferenceImmutableAttribute("targetAttribute");a.addVariantExpressionAttribute("RHS","")},start:function(b,c){var e=this.attributes.targetAttribute.getValue();if(e){var d=e.resolveRelativeTo(b);if(d){var a=this.attributes.RHS.getValueForEntityStateless(b);d.setValue(a)}}}};gs.inherits(gs.ChangeAttributeAction,gs.StatelessBehavior);gs.ChangeImageAction=function(){gs.StatelessBehavior.call(this)};gs.ChangeImageAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("image","")},start:function(a,c){var b=this.attributes.image.getValue();a.attributes.image.setValue(b)},getRequiredAssets:function(d,a,c){var b=this.attributes.image.getValue();if(b&&b.length>0){d[b]=true}}};gs.inherits(gs.ChangeImageAction,gs.StatelessBehavior);gs.ChangeRowAction=gs.Behavior.subclass("ChangeRowAction",{init:function(){gs.Behavior.init.call(this);this.attributes.addStringImmutableAttribute("table","");this.attributes.addIntegerImmutableAttribute("row",0);this.setObjectForKey(gs.PrototypicalArray.provide().init(),"tableColumns");this.tableColumns.addObjectAtIndex(gs.KeyValuePair.provide().init());return this},start:function(f,k){var e=this.attributes.table.getValue();if(!e){return}var d=gs.Reference.lookup(e);var j=d.resolveRelativeTo(this._entity);if(!j){gs.Log.warn("Table does not exist:",this.attributes.table.getValue());return}if(j._type==="table"){var l=String(this.attributes.row.getValue());var c=this.tableColumns;for(var g=0;g<c.array.length;g++){var b=c.array[g];var a=String(b.attributes.key.getValue());var h=String(b.attributes.value.getValue());j.setCell(l,a,h)}}},loadFromLite:function(b,a){},loadFromTable:function(d,a){gs.Behavior.loadFromTable.call(this,d,a);if(this.tableColumns.array[0]!=null){this.tableColumns.removeObjectAtIndex(0)}var f=gs.JXON.children(d);if(!f){return}var g=f.length;for(var c=0;c<g;++c){var e=f[c];var b=gs.Project.nodeTypeNameMap[gs.JXON.tag(e)];if(b==="tablecolumns"){this.tableColumns.loadFromTable(gs.JXON.children(e),a)}}}});gs.ChangeSceneAction=function(){gs.StatelessBehavior.call(this)};gs.ChangeSceneAction.NEXT="next";gs.ChangeSceneAction.PREVIOUS="prev";gs.ChangeSceneAction.INDEX="index";gs.ChangeSceneAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("sceneKey",gs.ChangeSceneAction.NEXT);a.addBooleanImmutableAttribute("enableAdvertisement",false);a.addIntegerExpressionAttribute("index",1)},start:function(c,f){var a=this.attributes.sceneKey.getValue();var g=this.attributes.enableAdvertisement.getValue();var i=gs.Game.current;var e=i.getCurrentScene();var d=i.scenes.indexAndKey(e._objectKey);var b=i.scenes.numberOfScenes();var h;if(a===gs.ChangeSceneAction.NEXT){h=d+1;if(h>=b){h=0}a=i.scenes.keyForScene(h)}else{if(a===gs.ChangeSceneAction.PREVIOUS){h=d-1;if(h<0){h=b-1}a=i.scenes.keyForScene(h)}else{if(a===gs.ChangeSceneAction.INDEX){h=this.attributes.index.getValueForEntityStateless(c)-1;a=i.scenes.keyForScene(h)}}}i.eventCenter.postEvent("changeToScene",null,a,g)}};gs.inherits(gs.ChangeSceneAction,gs.StatelessBehavior);gs.ChangeTableValueAction=function(){gs.StatelessBehavior.call(this)};gs.ChangeTableValueAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("tableID","");a.addVariantExpressionAttribute("tableExpression",null);a.addStringExpressionAttribute("rowNumber","");a.addReservedCompoundAttribute("assignments","array",null,true)},start:function(e,h){var k=this.targetTable;if(!k){var i=this.attributes.tableID.getValue();if(i){k=this.resolveTableReferenceAttribute(this.attributes.tableID)}else{k=this.attributes.tableExpression.getValueForEntityStateless(e)}this.targetTable=k;if(!k){return}}var l=this.attributes.rowNumber.getValueForEntityStateless(e);var f=k.lookupRow(l);var a=this.attributes.assignments;var m=a.size();for(var g=1;g<=m;g++){var d=a.at(g);var c=d.first.getValueForEntityStateless(e);var b=k.lookupColumn(c);var j=d.second.getValueForEntityStateless(e);k.setCell(f,b,j)}}};gs.inherits(gs.ChangeTableValueAction,gs.StatelessBehavior);gs.ChangeVelocityAction=gs.Behavior.subclass("ChangeVelocityAction");gs.ChangeVelocityAction.SPACE_ACTOR=0;gs.ChangeVelocityAction.SPACE_SCENE=1;gs.ChangeVelocityAction.init=function(){gs.Behavior.init.call(this);this.attributes.addRealExpressionAttribute("direction",0);this.attributes.addIntegerImmutableAttribute("space",gs.ChangeVelocityAction.SPACE_ACTOR);this.attributes.addRealExpressionAttribute("speed",300);return this};gs.ChangeVelocityAction.start=function(a,c){var b=this.attributes.speed.getValue();var d=this.attributes.direction.getValue();this.calculateVelocity(b,d)};gs.ChangeVelocityAction.calculateVelocity=function(f,g){var d=this._entity;var a=this.attributes.space.getValue();var c=gs.g_tempVec2d;if(a===gs.ChangeVelocityAction.SPACE_ACTOR){var h=d.attributes.rotation.getValue();var i=(g+h);while(i<0){i+=360}while(i>360){i-=360}var b=i*(Math.PI/180);c[0]=Math.cos(b);c[1]=Math.sin(b)}else{if(a===gs.ChangeVelocityAction.SPACE_SCENE){var b=g*(Math.PI/180);c[0]=Math.cos(b);c[1]=Math.sin(b)}}var e=d.aspects.motion;c[0]=c[0]*f;c[1]=c[1]*f;e.attributes.linearVelocity.x.setValue(c[0]);e.attributes.linearVelocity.y.setValue(c[1])};gs.CollideBehavior=function(){gs.StatelessBehavior.call(this)};gs.CollideBehavior.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("prototypeKey","");a.addStringImmutableAttribute("actorTag","");a.addIntegerImmutableAttribute("mode",gs.CollisionPredicate.PROTOTYPE_MODE)},filterCategory:function(){var b=this.attributes.mode.getValue();if(b===gs.CollisionPredicate.PROTOTYPE_MODE){var a=this.attributes.prototypeKey.getValue();return a}else{return this.attributes.actorTag.getValue()}},start:function(a,c){var b=this.filterCategory();if(!b){return}var d=a.scene;d._collisionController.addActorCollision(a,b)},stop:function(a,c){var b=this.filterCategory();if(!b){return}var d=a.scene;d._collisionController.removeActorCollision(a,b)}};gs.inherits(gs.CollideBehavior,gs.StatelessBehavior);gs.ConstrainAttributeBehavior=gs.Behavior.subclass("ConstrainAttributeBehavior",{init:function(){gs.Behavior.init.call(this);this.attributes.addReferenceImmutableAttribute("targetAttribute");this.attributes.addVariantExpressionAttribute("RHS","");return this},start:function(b,d){if(!this.targetAttribute){var a=this.attributes.targetAttribute.getValue();if(!a){return}this.targetAttribute=a.resolveRelativeTo(b)}if(!this.targetAttribute){gs.Log.debug("Degenerate ConstrainAttributeBehavior");return}var c=this.attributes.RHS.getValue();this.targetAttribute.setValue(c);this.registerForEveryFrame(b)},stop:function(a,b){this.deregisterForEveryFrame(a)},everyFrame:function(a,c){var b=this.attributes.RHS.getValue();this.targetAttribute.setValue(b)}});gs.ControlCameraBehavior=gs.Behavior.subclass("ControlCameraBehavior");gs.ControlCameraBehavior.start=function(a,b){if(a.layer.scrollable()){gs.ControlCameraBehavior.cameraControl=this;var c=a.scene;this.scene=c;this.trackingAreaWidth=c.attributes.camera.trackingArea.width.getValue();this.trackingAreaHeight=c.attributes.camera.trackingArea.height.getValue();this.cameraRect={x:c.attributes.camera.origin.x.getValue(),y:c.attributes.camera.origin.y.getValue(),width:c.attributes.camera.size.width.getValue(),height:c.attributes.camera.size.height.getValue()};this.sceneRect={x:0,y:0,width:Math.max(c.attributes.size.width.getValue()-this.cameraRect.width,0),height:Math.max(c.attributes.size.height.getValue()-this.cameraRect.height,0)};c.attributes.camera.size.width.addObserver(this);c.attributes.camera.size.height.addObserver(this);this.trackingRect={x:0,y:0,width:0,height:0};this.registerForEveryFrame()}};gs.ControlCameraBehavior.observeValueChange=function(b,c){var d=this.scene;var a=d.attributes.camera;this.cameraRect.x=a.origin.x.getValue();this.cameraRect.y=a.origin.y.getValue();this.cameraRect.width=a.size.width.getValue();this.cameraRect.height=a.size.height.getValue();this.sceneRect.width=Math.max(d.attributes.size.width.getValue()-this.cameraRect.width,0);this.sceneRect.height=Math.max(d.attributes.size.height.getValue()-this.cameraRect.height,0)};gs.ControlCameraBehavior.stop=function(a,b){var c=a.scene;c.attributes.camera.size.width.removeObserver(this);c.attributes.camera.size.height.removeObserver(this);if(gs.ControlCameraBehavior.cameraControl===this){gs.ControlCameraBehavior.cameraControl=null}this.cameraRect=null;this.sceneRect=null;this.trackingRect=null;this.deregisterForEveryFrame()};gs.ControlCameraBehavior.everyFrame=function(c,i){if(gs.ControlCameraBehavior.cameraControl!==this){this.deregisterForEveryFrame();return}var f=c.scene;var g=c.attributes.position;var l=g.x.getValue();var k=g.y.getValue();var a=f.attributes.camera.origin;var j=this.cameraRect;j.x=a.x.getValue();j.y=a.y.getValue();var b=this.trackingRect;b.width=this.trackingAreaWidth;b.height=this.trackingAreaHeight;var e=j.x+(j.width*0.5);var d=j.y+(j.height*0.5);b.x=e-this.trackingAreaWidth*0.5;b.y=d-this.trackingAreaHeight*0.5;if(!gs.Rect.pointInRect(l,k,b)){var m=gs.Rect.nearestPointInRect(gs.g_tempVec2d,l,k,b);m[0]=l-m[0];m[1]=k-m[1];var o=j.x+m[0];var n=j.y+m[1];var h=gs.Rect.nearestPointInRect(gs.g_tempVec2d,o,n,this.sceneRect);a.x.fastSetValue(h[0]);a.y.fastSetValue(h[1])}};gs.CopyTableAction=gs.Behavior.subclass("CopyTableAction");gs.CopyTableAction.init=function(){gs.Behavior.init.call(this);this.attributes.addStringImmutableAttribute("tableID","");this.attributes.addStringImmutableAttribute("destinationTableID","");return this};gs.CopyTableAction.start=function(b,d){var a=this.resolveTableReferenceAttribute(this.attributes.tableID);var c=this.resolveTableReferenceAttribute(this.attributes.destinationTableID);if(!a||!c){return}c.copyTable(a)};gs.DestroyAction=function(){gs.SingletonBehavior.call(this)};gs.DestroyAction.prototype={start:function(a,b){a.hideActor();var c=a.scene;c.markActorForDestruction(a)}};gs.inherits(gs.DestroyAction,gs.SingletonBehavior);gs.singleton(gs.DestroyAction);gs.DisplayTextBehavior=gs.Behavior.subclass("DisplayTextBehavior");gs.DisplayTextBehavior.LEFT=0;gs.DisplayTextBehavior.CENTER=1;gs.DisplayTextBehavior.RIGHT=2;gs.DisplayTextBehavior.SPACE_ACTOR=0;gs.DisplayTextBehavior.SPACE_SCENE=1;gs.DisplayTextBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addStringExpressionAttribute("text","Hello world!");this.attributes.addStringImmutableAttribute("font","Arial");this.attributes.addRealImmutableAttribute("size",30);this.attributes.addBooleanImmutableAttribute("wrap",false);this.attributes.addIntegerImmutableAttribute("alignment",gs.DisplayTextBehavior.CENTER);this.attributes.addColorImmutableAttribute("color",1,1,1,1);this.attributes.addRealExpressionAttribute("offsetx",0);this.attributes.addRealExpressionAttribute("offsety",0);this.attributes.addIntegerImmutableAttribute("space",gs.DisplayTextBehavior.SPACE_ACTOR);this.attributes.addIntegerImmutableAttribute("directionSpace",gs.DisplayTextBehavior.SPACE_ACTOR);this.attributes.addRealExpressionAttribute("direction",0);return this};gs.DisplayTextBehavior.createNodesInSpace=function(b,e){var d=b.createNode(gs.SGSpace.NodeType.SGText);this._textNode=d;var c=this._entity.attributes;d.x=c.position.x.getValue();d.y=c.position.y.getValue();d.angleDeg=c.rotation.getValue();d.width=c.size.width.getValue();d.height=c.size.height.getValue();this.updatePosition();var a=this.attributes;d.text=a.text.getValue();d.fontFamily=a.font.getValue();d.sizePx=a.size.getValue();d.alignment=a.alignment.getValue();d.wrap=a.wrap.getValue();d.colorR=a.color.red.getValue();d.colorG=a.color.green.getValue();d.colorB=a.color.blue.getValue();d.colorA=a.color.alpha.getValue();if(a.text.hasExpression()){d.textAttribute=a.text}d.setLayer(e);return 1};gs.DisplayTextBehavior.removeNodesFromSpace=function(a){a.removeNode(this._textNode);this._textNode=null};gs.DisplayTextBehavior.start=function(a,b){if(!this._entity.visible()){return}a.addNodeSource(this);if(this._textNode){this._textNode.init()}this.attributes.text.addObserver(this);this.attributes.offsetx.addObserver(this);this.attributes.offsety.addObserver(this);this.attributes.direction.addObserver(this);a.attributes.position.x.addObserver(this);a.attributes.position.y.addObserver(this);a.attributes.rotation.addObserver(this);a.attributes.size.width.addObserver(this);a.attributes.size.height.addObserver(this)};gs.DisplayTextBehavior.stop=function(a,b){if(!a.visible()){return}a.removeNodeSource(this);this.attributes.text.removeObserver(this);this.attributes.offsetx.removeObserver(this);this.attributes.offsety.removeObserver(this);this.attributes.direction.removeObserver(this);a.attributes.position.x.removeObserver(this);a.attributes.position.y.removeObserver(this);a.attributes.rotation.removeObserver(this);a.attributes.size.width.removeObserver(this);a.attributes.size.height.removeObserver(this)};gs.DisplayTextBehavior.updatePosition=function(){var d=this.attributes;var j=this._entity.attributes;var b=this._textNode;var i=d.offsetx.getValue();var h=d.offsety.getValue();if(d.space.getValue()===gs.DisplayTextBehavior.SPACE_ACTOR){if(i!==0||h!==0){var e=j.rotation.getValue();var a=e*gsMath.DEG2RAD;var f=Math.atan2(h,i);var g=Math.sqrt(i*i+h*h);f+=a;i=g*Math.cos(f);h=g*Math.sin(f)}i+=j.position.x.getValue();h+=j.position.y.getValue()}b.x=i;b.y=h;var c=d.direction.getValue();if(d.directionSpace.getValue()===gs.DisplayTextBehavior.SPACE_ACTOR){c+=j.rotation.getValue()}b.angleDeg=c;b.dirtyTransform=true};gs.DisplayTextBehavior.observeValueChange=function(a,b){var d=this._entity.attributes;var c=this._textNode;if(!c){return}if(a===d.position.x){this.updatePosition()}else{if(a===d.position.y){this.updatePosition()}else{if(a===d.rotation){this.updatePosition()}else{if(a===d.size.width){c.width=b;c.dirtyTransform=true}else{if(a===d.size.height){c.height=b;c.dirtyTransform=true}else{if(a===this.attributes.offsetx){this.updatePosition()}else{if(a===this.attributes.offsety){this.updatePosition()}else{if(a===this.attributes.direction){this.updatePosition()}}}}}}}}};gs.EndGameAction=function(){gs.SingletonBehavior.call(this)};gs.EndGameAction.prototype={start:function(b,c){var a=gs.Game.instance;a.setNeedsToEndGame()}};gs.inherits(gs.EndGameAction,gs.SingletonBehavior);gs.singleton(gs.EndGameAction);gs.GrowShrinkBehavior=gs.Behavior.subclass("GrowShrinkBehavior");gs.GrowShrinkBehavior.MINDIMENSION=1;gs.GrowShrinkBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addRealExpressionAttribute("growthRate",1);return this};gs.GrowShrinkBehavior.start=function(a,b){this._initialActorHeight=a.attributes.size.height.getValue();this._initialActorWidth=a.attributes.size.width.getValue();this.recalculateIncrementalChange();this._active=true;this._updatingSelf=false;this.attributes.growthRate.addObserver(this);this.registerForEveryFrame()};gs.GrowShrinkBehavior.recalculateIncrementalChange=function(){this._growthIncrementHeight=this.attributes.growthRate.getValue()/100*this._initialActorHeight;this._growthIncrementWidth=this.attributes.growthRate.getValue()/100*this._initialActorWidth};gs.GrowShrinkBehavior.observeValueChange=function(a,b){if(this._updatingSelf){return}this._updatingSelf=true;if(a===this.attributes.growthRate){this.recalculateIncrementalChange()}this._updatingSelf=false};gs.GrowShrinkBehavior.everyFrame=function(c,e){if(!this._active){return}var b=c.attributes.size.height.getValue()+this._growthIncrementHeight;var d=c.attributes.size.width.getValue()+this._growthIncrementWidth;var a=false;if((b<=gs.GrowShrinkBehavior.MINDIMENSION)||(d<=gs.GrowShrinkBehavior.MINDIMENSION)){if(this._initialActorHeight<this._initialActorWidth){b=gs.GrowShrinkBehavior.MINDIMENSION;d=this._initialActorWidth/this._initialActorHeight}else{d=gs.GrowShrinkBehavior.MINDIMENSION;b=this._initialActorHeight/this._initialActorWidth}this._active=false;a=true}c.attributes.size.height.fastSetValue(b);c.attributes.size.width.fastSetValue(d)};gs.GrowShrinkBehavior.stop=function(a,b){this.deregisterForEveryFrame();this._initialActorHeight=null;this._initialActorWidth=null;this._growthIncrementHeight=null;this._growthIncrementWidth=null;this._active=false;this.attributes.growthRate.removeObserver(this);this._updatingSelf=null};gs.InsertRowAction=gs.Behavior.subclass("InsertRowAction",{init:function(){gs.Behavior.init.call(this);this.attributes.addStringImmutableAttribute("table","");this.attributes.addIntegerImmutableAttribute("at",0);this.attributes.addIntegerImmutableAttribute("at_index",0);this.setObjectForKey(gs.PrototypicalArray.provide().init(),"tableColumns");this.tableColumns.addObjectAtIndex(gs.KeyValuePair.provide.init());return this},start:function(d,j){var h=this.resolveTableReferenceAttribute(this.attributes.table);if(!h){gs.Log.warn("Table does not exist:",this.attributes.table.getValue());return}var k=1;var f=this.attributes.at.getValue();switch(f){case 0:k=-1;break;case 1:k=1;break;case 2:k=this.attributes.at_index.getValue();break;default:return}var l=String(k);h.addRow(l);var c=this.tableColumns;for(var e=0;e<c.array.length;e++){var b=c.array[e];var a=String(b.attributes.key.getValue());var g=String(b.attributes.value.getValue());h.setCellSafe(l,a,g)}},loadFromLite:function(b,a){},loadFromTable:function(d,a){gs.Behavior.loadFromTable.call(this,d,a);if(this.tableColumns.array[0]!=null){this.tableColumns.removeObjectAtIndex(0)}var f=gs.JXON.children(d);if(!f){return}var g=f.length;for(var c=0;c<g;++c){var e=f[c];var b=gs.Project.nodeTypeNameMap[gs.JXON.tag(e)];if(b==="tablecolumns"){this.tableColumns.loadFromTable(gs.JXON.children(e),a)}}}});gs.InterpolateBehavior=gs.CompletingBehavior.subclass("InterpolateBehavior");gs.InterpolateBehavior.init=function(){gs.CompletingBehavior.init.call(this);this.attributes.addReferenceImmutableAttribute("targetAttribute");this.attributes.addRealExpressionAttribute("finalValue",0);this.attributes.addRealExpressionAttribute("duration",1);this.attributes.addIntegerExpressionAttribute("easing",0);this.attributes.runToCompletion.changeDefaultValue(true);return this};gs.interpolateLinear=function(a){return a};gs.interpolateEaseIn=function(a){return a*a};gs.interpolateEaseOut=function(a){a=1-a;return(1-(a*a))};gs.interpolateEaseInOut=function(a){if(a<0.5){return gs.interpolateEaseIn(a*2)*0.5}else{return(0.5+gs.interpolateEaseOut(a*2-1)*0.5)}};gs.InterpolateBehavior.start=function(b,c){this.startTime=c.time;this.duration=this.attributes.duration.getValue();this.finalValue=this.attributes.finalValue.getValue();this.didSetFinalValue=false;if(!this.targetAttribute){var a=this.attributes.targetAttribute.getValue();if(!a){return}this.targetAttribute=a.resolveRelativeTo(this._entity)}this.initialValue=this.targetAttribute.getValue();gs.CompletingBehavior.start.call(this,b,c)};gs.InterpolateBehavior.completeStart=function(a,b){gs.CompletingBehavior.completeStart.call(this,a,b);var c=this.attributes.easing.getValue();if(c===0){this.easingFunction=gs.interpolateLinear}else{if(c===1){this.easingFunction=gs.interpolateEaseIn}else{if(c===2){this.easingFunction=gs.interpolateEaseOut}else{this.easingFunction=gs.interpolateEaseInOut}}}this.attributes.finalValue.addObserver(this);this.attributes.duration.addObserver(this)};gs.InterpolateBehavior.observeValueChange=function(a,b){if(!this._completed){if(a===this.attributes.finalValue){this.finalValue=b}else{if(a===this.attributes.duration){this.duration=b}}}};gs.InterpolateBehavior.completeEvaluate=function(e,f){gs.CompletingBehavior.completeEvaluate.call(this,e,f);var d=f.time-this.startTime;if(d>=this.duration){if(!this.didSetFinalValue){this.targetAttribute.fastSetValue(this.finalValue);this.didSetFinalValue=true}this.setCompleted(true)}else{var b=d/this.duration;var a=this.easingFunction(b);var g=this.finalValue-this.initialValue;var c=this.initialValue+(g*a);this.targetAttribute.fastSetValue(c)}};gs.InterpolateBehavior.completeStop=function(a,b){gs.CompletingBehavior.completeStop.call(this,a,b);this.attributes.finalValue.removeObserver(this);this.attributes.duration.removeObserver(this);if(!this.didSetFinalValue){this.targetAttribute.setValue(this.finalValue);this.didSetFinalValue=true}this.duration=null;this.finalValue=null;this.easingFunction=null;this.startTime=null};gs.KeyboardInputAction=gs.Behavior.subclass("KeyboardInputAction",{init:function(){gs.Behavior.init.call(this);this.attributes.addReferenceImmutableAttribute("targetAttribute");this.attributes.addStringExpressionAttribute("keyboardPrompt","");return this},start:function(c,f){var i=gs.Game.current;if(i.isWaitingOnKeyboardInput){return}var b=this.attributes.targetAttribute.getValue();if(!b){return}var e=b.resolveRelativeTo(this._entity);this.target=e;if(!e){return}var a=this.attributes.keyboardPrompt.getValue();var h=String(e.getValue());i.isWaitingOnKeyboardInput=true;i.interceptKeyEvents=false;i.eventCenter.registerForEvent("keyboardInputEntered",this,"keyboardInputEntered");i.eventCenter.registerForEvent("keyboardInputCancelled",this,"keyboardInputCancelled");var j=gs.Game.current.eventCenter;var g=function(k){gs.clearTouchState(gs.Project.instance);if(k===null){j.postEvent("keyboardInputCancelled")}else{j.postEvent("keyboardInputEntered",null,k)}};var d=gs.platform.TextService.instance();d.openTextPrompt(a,h,g)},keyboardInputEntered:function(a){this.disconnect();if(this.target instanceof gs.BooleanMutableAttribute){this.target.setValue(gs.parseBoolean(a))}else{if(this.target instanceof gs.StringMutableAttribute){this.target.setValue(a)}else{this.target.setValue(parseFloat(a.trim()))}}},keyboardInputCancelled:function(){this.disconnect()},disconnect:function(){var a=gs.Game.current;a.eventCenter.deregisterForEvent("keyboardInputEntered",this);a.eventCenter.deregisterForEvent("keyboardInputCancelled",this);a.interceptKeyEvents=true;a.isWaitingOnKeyboardInput=false}});gs.LaunchServiceAction=function(){gs.StatelessBehavior.call(this)};gs.LaunchServiceAction.prototype={declareAttributes:function(a){a.addIntegerImmutableAttribute("page",0)},start:function(a,b){gs.EngineContext.current.delegate.onLaunchService(this.attributes.page.getValue())}};gs.inherits(gs.LaunchServiceAction,gs.StatelessBehavior);gs.LoadAttributeAction=function(){gs.StatelessBehavior.call(this)};gs.LoadAttributeAction.prototype={declareAttributes:function(a){a.addReferenceImmutableAttribute("targetAttribute");a.addVariantExpressionAttribute("key","")},start:function(c,g){var a=this.attributes.targetAttribute.getValue();if(!a){return}var h=a.resolveRelativeTo(c);var b=this.attributes.key.getValueForEntityStateless(c);if(h._type==="table"){var f=gs.LocalStorage.getObject(b);var d=h.getTableData();gs.TableParser.deserializeTableFromFileFormat(d,f)}else{var e=gs.LocalStorage.getString(b);if(e!==null){h.setValue(e);if(!b||b===""){gs.Log.warn("Loaded attribute with empty name. value =",e)}else{}}else{}}}};gs.inherits(gs.LoadAttributeAction,gs.StatelessBehavior);gs.LogDebuggingStatementAction=gs.Behavior.subclass("LogDebuggingStatementAction");gs.LogDebuggingStatementAction.init=function(){gs.Behavior.init.call(this);this.attributes.addStringExpressionAttribute("text","");return this};gs.LogDebuggingStatementAction.start=function(b,c){var d=this.attributes.text.getValue();var a=this._entity.attributes.name.getValue();gs.EngineContext.current.delegate.onLogDebuggingStatement(d,a)};gs.LoopBehavior=gs.CompoundBehavior.subclass("LoopBehavior",{LOOP_WHILE:0,LOOP_UNTIL:1,init:function(){gs.CompoundBehavior.init.call(this);this.attributes.addIntegerImmutableAttribute("loopType",gs.LoopBehavior.LOOP_WHILE);this.attributes.addIntegerImmutableAttribute("compoundConditionKind",gs.RuleBehavior.CONDITION_ALL);this.setObjectForKey(gs.PrototypicalKeylessArray.provide().init("condition"),"conditions");return this},testSingleCondition:function(){var a=this.conditions.array;var b=a[0];b.didEnter(this._entity,false,this,0);return b.test()},testAllConditions:function(){var c=this.conditions.array;var d=this.conditions.length();for(var b=0;b<d;b++){var e=c[b];e.didEnter(this._entity,false,this,b);var a=e.test();if(!a){return false}}return true},testAnyConditions:function(){var c=this.conditions.array;var d=this.conditions.length();for(var b=0;b<d;b++){var e=c[b];e.didEnter(this._entity,false,this,b);var a=e.test();if(a){return true}}return false},start:function(b,c){var d=this.conditions.array;var e=this.conditions.length();for(var a=0;a<e;a++){var f=d[a];f.start(b)}this.actorTime=c;this._registeredForEveryFrame=true;this.registerForEveryFrame()},stop:function(b,c){var d=this.conditions.array;var e=this.conditions.length();for(var a=0;a<e;a++){var f=d[a];f.stop(b)}if(this._registeredForEveryFrame){this.deregisterForEveryFrame();this._registeredForEveryFrame=false}this._needsUpdate=false},didEnter:function(c,e){gs.CompoundBehavior.didEnter.call(this,c,e);var d=this.conditions.array;var f=this.conditions.length();for(var b=0;b<f;b++){var g=d[b];g.didEnter(c,e,this,b)}var a=this.attributes.compoundConditionKind.getValue();if(f===1){this.testConditionsFunction=this.testSingleCondition}else{if(a===gs.RuleBehavior.CONDITION_ALL){this.testConditionsFunction=this.testAllConditions}else{this.testConditionsFunction=this.testAnyConditions}}},willExit:function(b){var c=this.conditions.array;var d=this.conditions.length();for(var a=0;a<d;a++){var e=c[a];e.willExit(b)}gs.CompoundBehavior.willExit.call(this,b)},everyFrame:function(c){var c=this._entity;var d=this.actorTime;var b=this.attributes.loopType.getValue();var a=this.testConditionsFunction();if(b===gs.LoopBehavior.LOOP_WHILE){a=!a}if(!a){this.behaviors.start(c,d);this.behaviors.stop(c,d)}if(a){this.deregisterForEveryFrame();this._registeredForEveryFrame=false}},conditionChangedState:function(a,b){if(a!==null&&!this._registeredForEveryFrame){this._registeredForEveryFrame=true;this.registerForEveryFrame()}},loadFromLite:function(b,a){gs.CompoundBehavior.loadFromLite.call(this,b,a);var c=b.conditions;if(c){this.conditions.loadFromLite(c,a)}}});gs.LoopTableBehavior=gs.CompoundBehavior.subclass("LoopTableBehavior",{LOOP_ROWS:0,LOOP_COLUMNS:1,CELL_START:0,CELL_END:1,CELL_AT:2,init:function(){gs.CompoundBehavior.init.call(this);this.attributes.addReferenceImmutableAttribute("loopAttribute");this.attributes.addStringImmutableAttribute("tableID","");this.attributes.addIntegerImmutableAttribute("loopType",gs.LoopTableBehavior.LOOP_ROWS);this.attributes.addIntegerImmutableAttribute("startCell",gs.LoopTableBehavior.CELL_START);this.attributes.addIntegerImmutableAttribute("endCell",gs.LoopTableBehavior.CELL_END);this.attributes.addIntegerExpressionAttribute("startCellExpression",0);this.attributes.addIntegerExpressionAttribute("endCellExpression",0);return this},start:function(e,g){this._registeredForEveryFrame=false;var b=this.resolveTableReferenceAttribute(this.attributes.tableID);if(!b){return}var f=0;var d=this.attributes.loopType.getValue();if(d===gs.LoopTableBehavior.LOOP_ROWS){f=b.getRowCount()}else{if(d===gs.LoopTableBehavior.LOOP_COLUMNS){f=b.getColumnCount()}}var c=this.attributes.startCell.getValue();if(c===gs.LoopTableBehavior.CELL_START){this._loopIndex=1}else{if(c==gs.LoopTableBehavior.CELL_END){this._loopIndex=f}else{this._loopIndex=gs.parseInteger(this.attributes.startCellExpression.getValue())}}c=this.attributes.endCell.getValue();if(c===gs.LoopTableBehavior.CELL_START){this._endIndex=1}else{if(c==gs.LoopTableBehavior.CELL_END){this._endIndex=f}else{this._endIndex=gs.parseInteger(this.attributes.endCellExpression.getValue())}}if(this._loopIndex<=this._endIndex){this._delta=1;if(this._loopIndex<1){this._loopIndex=1}if(this._endIndex>f){this._endIndex=f}}else{this._delta=-1;if(this._loopIndex>f){this._loopIndex=f}if(this._endIndex<1){this._endIndex=1}}var a=this.attributes.loopAttribute.getValue();if(!a){return}var h=a.resolveRelativeTo(e);if(h){h.setValue(this._loopIndex)}this._registeredForEveryFrame=true;this.registerForEveryFrame()},stop:function(a,b){if(this._registeredForEveryFrame){this.deregisterForEveryFrame();this._registeredForEveryFrame=false}this._needsUpdate=false},everyFrame:function(d,e){var c=false;var b=this.resolveTableReferenceAttribute(this.attributes.tableID);if(b){if((this._delta===1&&this._loopIndex<=this._endIndex)||(this._delta===-1&&this._loopIndex>=this._endIndex)){var a=this.attributes.loopAttribute.getValue();if(a){var f=a.resolveRelativeTo(d);if(f){f.setValue(this._loopIndex)}this.behaviors.start(d,e);this.behaviors.stop(d,e);this._loopIndex+=this._delta}else{c=true}}else{c=true}}else{c=true}if(c){this.deregisterForEveryFrame()}}});gs.MoveBehavior=gs.Behavior.subclass("MoveBehavior");gs.MoveBehavior.SPACE_ACTOR=0;gs.MoveBehavior.SPACE_SCENE=1;gs.MoveBehavior.MOVETYPE_ADDITIVE=0;gs.MoveBehavior.MOVETYPE_STACKED=1;gs.MoveBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addRealExpressionAttribute("direction",0);this.attributes.addIntegerImmutableAttribute("space",gs.MoveBehavior.SPACE_ACTOR);this.attributes.addIntegerImmutableAttribute("moveType",gs.MoveBehavior.MOVETYPE_ADDITIVE);this.attributes.addRealExpressionAttribute("speed",300);this.attributes.addBooleanImmutableAttribute("haltWhenBehaviorStops",true);return this};gs.MoveBehavior.start=function(a,c){var b=this.attributes.space.getValue();if(b==gs.MoveBehavior.SPACE_ACTOR){this.calculateRotation=this.calculateRotationInActorSpace;a.attributes.rotation.addObserver(this)}else{if(b==gs.MoveBehavior.SPACE_SCENE){this.calculateRotation=this.calculateRotationInSceneSpace}}if(this.attributes.moveType.getValue()==gs.MoveBehavior.MOVETYPE_ADDITIVE){this.modifyVelocity=this.modifyVelocityAdditive}else{if(this.attributes.moveType.getValue()==gs.MoveBehavior.MOVETYPE_STACKED){this.modifyVelocity=this.modifyVelocityStacked}}this.calculateVelocity();this._updatingSelf=false;this.attributes.speed.addObserver(this);this.attributes.direction.addObserver(this)};gs.MoveBehavior.observeValueChange=function(b,c){if(this._updatingSelf){return}var a=this._entity;this._updatingSelf=true;if((b===this.attributes.speed)||(b===this.attributes.direction)||(b===a.attributes.rotation)){this.calculateVelocity()}this._updatingSelf=false};gs.MoveBehavior.calculateVelocity=function(){var a=this.calculateRotation();var b=this.attributes.speed.getValue();a[0]=a[0]*b;a[1]=a[1]*b;this.modifyVelocity(a)};gs.MoveBehavior.calculateRotationInActorSpace=function(){var b=this._entity;var a=b.attributes.rotation.getValue();var e=(this.attributes.direction.getValue()+a)%360;var d=e*(Math.PI/180);var c=gs.g_tempVec2d;c[0]=Math.cos(d);c[1]=Math.sin(d);return c};gs.MoveBehavior.calculateRotationInSceneSpace=function(){var c=this.attributes.direction.getValue();var b=c*(Math.PI/180);var a=gs.g_tempVec2d;a[0]=Math.cos(b);a[1]=Math.sin(b);return a};gs.MoveBehavior.modifyVelocityAdditive=function(b){var a=this._entity.aspects.motion;a.modifyAdditiveVelocity(b,this.getUniqueKey())};gs.MoveBehavior.modifyVelocityStacked=function(b){var a=this._entity.aspects.motion;a.modifyStackedVelocity(b,this.getUniqueKey())};gs.MoveBehavior.stop=function(b,c){if(this.attributes.haltWhenBehaviorStops.getValue()){var a=this._entity.aspects.motion;if(this.attributes.moveType.getValue()===gs.MoveBehavior.MOVETYPE_ADDITIVE){a.removeAdditiveVelocity(this.getUniqueKey())}else{if(this.attributes.moveType.getValue()===gs.MoveBehavior.MOVETYPE_STACKED){a.removeStackedVelocity(this.getUniqueKey())}}this.attributes.speed.removeObserver(this);this.attributes.direction.removeObserver(this);if(this.attributes.space.getValue()===gs.MoveBehavior.SPACE_ACTOR){b.attributes.rotation.removeObserver(this)}this._updatingSelf=null}};gs.MoveBehavior.willExit=function(a){if(!this.attributes.haltWhenBehaviorStops.getValue()){this.attributes.speed.removeObserver(this);this.attributes.direction.removeObserver(this);if(this.attributes.space.getValue()===gs.MoveBehavior.SPACE_ACTOR){a.attributes.rotation.removeObserver(this)}}gs.Behavior.willExit.call(this,a)};gs.MoveToBehavior=gs.CompletingBehavior.subclass("MoveToBehavior");gs.MoveToBehavior.init=function(){gs.CompletingBehavior.init.call(this);this.attributes.addPointExpressionAttribute("position",0,0);this.attributes.addIntegerImmutableAttribute("space",gs.MoveBehavior.SPACE_SCENE);this.attributes.addRealExpressionAttribute("speed",300);return this};gs.MoveToBehavior.completeStart=function(d,e){var b=gs.Game.current;var a=d.aspects.motion;gs.CompletingBehavior.completeStart.call(this,d,e);var c=[gs.makeEqualityPredicate(d),null];b.eventCenter.registerForEvent("wrap",this,"actorDidWrap",c);if(this.attributes.space.getValue()===gs.MoveBehavior.SPACE_ACTOR){this.calculateDestination=this.calculateDestinationFunctionActorSpace}else{this.calculateDestination=this.calculateDestinationFunctionSceneSpace}this._targetPosition=[0,0];this.calculateDestination();this.calculateVelocity();this._updatingSelf=false;this.attributes.position.x.addObserver(this);this.attributes.position.y.addObserver(this);this.attributes.speed.addObserver(this);a.attributes.linearVelocity.x.addObserver(this);a.attributes.linearVelocity.y.addObserver(this)};gs.MoveToBehavior.calculateDestinationFunctionActorSpace=function(){var g=this._targetPosition;var f=this.attributes.position.x.getValue();var d=this.attributes.position.y.getValue();g[0]=f;g[1]=d;var c=this._entity;var e=c.attributes.position.x.getValue();var b=c.attributes.position.y.getValue();var a=c.attributes.rotation.getValue()*(Math.PI/180);gs.Vector2.vectorRotate2D(g,g,a);g[0]+=e;g[1]+=b};gs.MoveToBehavior.calculateDestinationFunctionSceneSpace=function(){this._targetPosition[0]=this.attributes.position.x.getValue();this._targetPosition[1]=this.attributes.position.y.getValue()};gs.MoveToBehavior.calculateVelocity=function(){var c=this._entity;var f=c.attributes.position.x.getValue();var b=c.attributes.position.y.getValue();var a=c.aspects.motion;var e=gs.g_tempVec2d;e[0]=0;e[1]=0;e[0]=this._targetPosition[0]-f;e[1]=this._targetPosition[1]-b;var d=Math.sqrt(e[0]*e[0]+e[1]*e[1]);if(d>0){e[0]=(e[0]/d);e[1]=(e[1]/d)}else{e[0]=0;e[1]=0}var g=this.attributes.speed.getValue();e[0]=e[0]*g;e[1]=e[1]*g;a.attributes.linearVelocity.x.fastSetValue(e[0]);a.attributes.linearVelocity.y.fastSetValue(e[1])};gs.MoveToBehavior.observeValueChange=function(b,c){if(this._updatingSelf){return}this._updatingSelf=true;var a=this.attributes.position;if((b===a.x)||(b===a.y)){this.calculateDestination()}this.calculateVelocity();this._updatingSelf=false};gs.MoveToBehavior.completeEvaluate=function(a,c){gs.CompletingBehavior.completeEvaluate.call(this,a,c);var b=gs.g_tempVec2d;b[0]=a.attributes.position.x.getValue();b[1]=a.attributes.position.y.getValue();if(gs.Vector2.equals(b,this._targetPosition,gs.Vector2.EPSILON)){this.setCompleted(true)}};gs.MoveToBehavior.completeStop=function(c,d){gs.CompletingBehavior.completeStop.call(this,c,d);var b=gs.Game.current;var a=c.aspects.motion;this.attributes.position.x.removeObserver(this);this.attributes.position.y.removeObserver(this);this.attributes.speed.removeObserver(this);a.attributes.linearVelocity.x.removeObserver(this);a.attributes.linearVelocity.y.removeObserver(this);this._updatingSelf=null;if(this.completed()){c.attributes.position.x.fastSetValue(this._targetPosition[0]);c.attributes.position.y.fastSetValue(this._targetPosition[1])}a.attributes.linearVelocity.x.fastSetValue(0);a.attributes.linearVelocity.y.fastSetValue(0);b.eventCenter.deregisterForEvent("wrap",this)};gs.MoveToBehavior.actorDidWrap=function(b,a,c,d){this._updatingSelf=true;if(a===gs.Vector2.X_COMPONENT){this._targetPosition[0]=this._targetPosition[0]%c}else{this._targetPosition[1]=this._targetPosition[1]%c}this.calculateVelocity();this._updatingSelf=false};gs.NoteBehavior=function(){gs.SingletonBehavior.call(this)};gs.NoteBehavior.prototype={};gs.inherits(gs.NoteBehavior,gs.SingletonBehavior);gs.singleton(gs.NoteBehavior);gs.NullBehavior=function(){gs.SingletonBehavior.call(this)};gs.NullBehavior.prototype={};gs.inherits(gs.NullBehavior,gs.SingletonBehavior);gs.singleton(gs.NullBehavior);gs.OpenURLAction=function(){gs.StatelessBehavior.call(this)};gs.OpenURLAction.Protocol={MAILTO:0,HTTP:1,HTTPS:2};gs.OpenURLAction.protocolMap={0:"mailto://",1:"http://",2:"https://"};gs.OpenURLAction.externalWhitelist=["www.google.com","facebook.com","itunes.com/apps"];gs.OpenURLAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("URL","");a.addBooleanImmutableAttribute("useExternalBrowser",true);a.addIntegerImmutableAttribute("protocol",gs.OpenURLAction.Protocol.HTTP)},start:function(c,g){var j=this.attributes.URL.getValue();var b=this.attributes.useExternalBrowser.getValue();var h=this.attributes.protocol.getValue();var e=gs.OpenURLAction.protocolMap[h];if(h===gs.OpenURLAction.Protocol.MAILTO){b=true}var a=gs.OpenURLAction.externalWhitelist;for(var d=0;d<a.length;d++){if(j.indexOf(a[d])!==-1){b=true}}if(j.indexOf(e)!==0){j=e+j}if(j!==null&&j.length>0){var f=gs.platform.BrowserService.instance();f.openBrowser(j,!b)}}};gs.inherits(gs.OpenURLAction,gs.StatelessBehavior);gs.ParticlesBehavior=gs.Behavior.subclass("ParticlesBehavior");gs.ParticlesBehavior.SYSTEM_LIFETIME_INFINITE=1;gs.ParticlesBehavior.SYSTEM_LIFETIME_FINITE=0;gs.ParticlesBehavior.RELATIVE_TO_ACTOR=0;gs.ParticlesBehavior.RELATIVE_TO_SCENE=1;gs.ParticlesBehavior.init=function(){gs.Behavior.init.call(this);var a=this.attributes;a.addIntegerExpressionAttribute("numParticles",20);a.addRealExpressionAttribute("size",15);a.addRealExpressionAttribute("lifetime",2);a.addRealExpressionAttribute("startupTime",2);a.addRealExpressionAttribute("direction",0);a.addRealExpressionAttribute("speed",10);a.addStringImmutableAttribute("image","");a.addRealExpressionAttribute("rotation",0);a.addRealExpressionAttribute("angularVelocity",0);a.addIntegerImmutableAttribute("directionRelativity",gs.ParticlesBehavior.RELATIVE_TO_ACTOR);a.addRealExpressionAttribute("emitterOffsetX",0);a.addRealExpressionAttribute("emitterOffsetY",0);a.addBooleanImmutableAttribute("colorChange",0);a.addBooleanImmutableAttribute("sizeChange",0);a.addRealExpressionAttribute("colorTransitionTime",1);a.addRealExpressionAttribute("sizeTarget",5);a.addRealExpressionAttribute("sizeTransitionTime",0);a.addColorImmutableAttribute("color",1,1,1,1);a.addColorImmutableAttribute("colorTarget",1,1,1,1);a.addBooleanImmutableAttribute("affectedByGravity",false);a.addIntegerImmutableAttribute("blendingMode",0);return this};gs.ParticlesBehavior.everyFrame=function(a,c){var b=this._particleSystem;b.time+=c.dt;if(this._endTime){if(b.time>this._endTime){this._entity.removeNodeSource(this);this.deregisterForEveryFrame()}}};gs.ParticlesBehavior.start=function(b,d){if(!b.visible()){return}this._endTime=null;var c=this._particleSystem;if(!c){this.createNodes();c=this._particleSystem}this.updateInitialValues();c.init();c.spawnParticles=true;c.time=0;b.addNodeSource(this);b.attributes.position.x.addObserver(this);b.attributes.position.y.addObserver(this);var a=this.attributes.directionRelativity.getValue();if(a===gs.ParticlesBehavior.RELATIVE_TO_ACTOR){b.attributes.rotation.addObserver(this)}this.registerForEveryFrame()};gs.ParticlesBehavior.stop=function(b,d){if(!b.visible()){return}b.attributes.position.x.removeObserver(this);b.attributes.position.y.removeObserver(this);var a=this.attributes.directionRelativity.getValue();if(a===gs.ParticlesBehavior.RELATIVE_TO_ACTOR){b.attributes.rotation.removeObserver(this)}var c=this._particleSystem;if(!d){c.spawnParticles=false;b.removeNodeSource(this);this.deregisterForEveryFrame()}else{this._endTime=c.time+this.attributes.lifetime.getValue();c.stopSpawning=true}};gs.ParticlesBehavior.didEnter=function(a,b){gs.Behavior.didEnter.call(this,a,b);if(b){this.createNodes()}};gs.ParticlesBehavior.willExit=function(a){if(this._particleSystem){this._particleSystem.recycle();this._particleSystem=null;gs.array.recycle(this._attributesWithExpressions);this._attributesWithExpressions=null}this._entity.removeNodeSource(this);this.deregisterForEveryFrame();gs.Behavior.willExit.call(this,a)};gs.ParticlesBehavior.createNodes=function(){var b=this.attributes;var c=gs.SGParticleSystemNode.provide();this._particleSystem=c;this.updateConstantValues();var a=gs.array.provide();this._attributesWithExpressions=a;this.bindDynamicValue(b.size,c,"sizeBegin","dirtySettings");this.bindDynamicValue(b.sizeTarget,c,"sizeEnd","dirtySettings");this.bindDynamicValue(b.sizeTransitionTime,c,"sizeTime","dirtySettings");this.bindDynamicValue(b.colorTransitionTime,c,"colorTime","dirtySettings");this.bindDynamicValue(b.emitterOffsetX,c,"offsetX","dirtyOffset");this.bindDynamicValue(b.emitterOffsetY,c,"offsetY","dirtyOffset");this.bindDynamicValue(b.direction,c,"offsetAngleDeg","dirtyOffset");this.bindDynamicValue(b.speed,c,"speed","dirtySettings");this.bindDynamicValue(b.rotation,c,"particleAngleDeg","dirtySettings");this.bindDynamicValue(b.angularVelocity,c,"particleAngularVelocityDeg","dirtySettings");if(a.length>0){c.attributesWithExpressions=this._attributesWithExpressions}};gs.ParticlesBehavior.bindDynamicValue=function(c,b,a,d){c.connectToSprite(b,a,d);if(c.hasExpression()){this._attributesWithExpressions.push(c)}};gs.ParticlesBehavior.createNodesInSpace=function(a,b){a.addNode(this._particleSystem);this._particleSystem.setLayer(b);return 1};gs.ParticlesBehavior.removeNodesFromSpace=function(b){var a=this.attributes;a.size.disconnectFromSprite();a.sizeTarget.disconnectFromSprite();a.sizeTransitionTime.disconnectFromSprite();a.colorTransitionTime.disconnectFromSprite();a.emitterOffsetX.disconnectFromSprite();a.emitterOffsetY.disconnectFromSprite();a.direction.disconnectFromSprite();a.speed.disconnectFromSprite();a.rotation.disconnectFromSprite();a.angularVelocity.disconnectFromSprite();b.removeNode(this._particleSystem)};gs.ParticlesBehavior.observeValueChange=function(b,c){var a=this._entity;var d=this._particleSystem;if(b===a.attributes.position.x){d.originX=c}else{if(b===a.attributes.position.y){d.originY=c}else{d.originAngleDeg=c}}d.dirtyOrigin=true};gs.ParticlesBehavior.updateConstantValues=function(){var a=this.attributes;var c=this._particleSystem;c.imageID=a.image.getValue();c.blendMode=a.blendingMode.getValue();c.sizeChanges=a.sizeChange.getValue();c.colorBegin[0]=a.color.red.getValue();c.colorBegin[1]=a.color.green.getValue();c.colorBegin[2]=a.color.blue.getValue();c.colorBegin[3]=a.color.alpha.getValue();var b=a.colorChange.getValue();c.colorChanges=b;if(b){c.colorEnd[0]=a.colorTarget.red.getValue();c.colorEnd[1]=a.colorTarget.green.getValue();c.colorEnd[2]=a.colorTarget.blue.getValue();c.colorEnd[3]=a.colorTarget.alpha.getValue()}else{c.colorEnd[0]=c.colorBegin[0];c.colorEnd[1]=c.colorBegin[1];c.colorEnd[2]=c.colorBegin[2];c.colorEnd[3]=c.colorBegin[3]}};gs.ParticlesBehavior.updateInitialValues=function(){var c=this._entity;var b=this.attributes;var d=this._particleSystem;d.particleCount=b.numParticles.getValue();d.lifeTime=b.lifetime.getValue();d.lifeStart=b.startupTime.getValue();if(b.affectedByGravity.getValue()){var e=c.scene.attributes.gravity;d.gravityX=-e.x.getValue();d.gravityY=-e.y.getValue()}else{d.gravityX=0;d.gravityY=0}d.originX=c.attributes.position.x.getValue();d.originY=c.attributes.position.y.getValue();var a=b.directionRelativity.getValue();if(a===gs.ParticlesBehavior.RELATIVE_TO_ACTOR){d.originAngleDeg=c.attributes.rotation.getValue()}};gs.ParticlesBehavior.getRequiredAssets=function(d,a,c){var b=this.attributes.image.getValue();if(b&&b.length>0){d[b]=true}};gs.PauseGameAction=function(){gs.StatelessBehavior.call(this)};gs.PauseGameAction.SOCIAL_CONSOLE_SCENE_KEY="socialConsoleID";gs.PauseGameAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("sceneKey",gs.PauseGameAction.SOCIAL_CONSOLE_SCENE_KEY);a.addBooleanImmutableAttribute("enableAdvertisement",false)},start:function(b,d){var a=this.attributes.sceneKey.getValue();var c=this.attributes.enableAdvertisement.getValue();if(a===gs.PauseGameAction.SOCIAL_CONSOLE_SCENE_KEY){gs.callSocialConsole(gs.Game.current.project,"show")}gs.Game.current.eventCenter.postEvent("startPauseScene",null,a,c)},getRequiredAssets:function(d,a,b){if(b===gs.LoadStrategyOption.SCENE){var c=this.attributes.sceneKey.getValue();gs.Game.current.scenes.fetchSceneByKey(c)}}};gs.inherits(gs.PauseGameAction,gs.StatelessBehavior);gs.PauseMusicAction=function(){gs.SingletonBehavior.call(this)};gs.PauseMusicAction.prototype={start:function(a,b){gs.AudioManager.current.pauseMusic()}};gs.inherits(gs.PauseMusicAction,gs.SingletonBehavior);gs.singleton(gs.PauseMusicAction);gs.PostEventAction=function(){gs.StatelessBehavior.call(this)};gs.PostEventAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("event","")},start:function(c,d){var b=this.attributes.event.getValue();var a=gs.Game.current;a.eventCenter.postEvent(b)}};gs.inherits(gs.PostEventAction,gs.StatelessBehavior);gs.PlayMusicAction=function(){gs.StatelessBehavior.call(this)};gs.PlayMusicAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("musicName","");a.addBooleanImmutableAttribute("loop",false)},start:function(b,d){if(!gs.debug.audio){return}var c=this.attributes.musicName.getValue();var a=this.attributes.loop.getValue();if(c){gs.AudioManager.current.playMusic(c,a)}else{gs.AudioManager.current.unpauseMusic()}}};gs.inherits(gs.PlayMusicAction,gs.StatelessBehavior);gs.PlaySoundAction=gs.Behavior.subclass("PlaySoundAction",{init:function(){gs.Behavior.init.call(this);var a=this.attributes;a.addStringImmutableAttribute("soundName","");a.addBooleanImmutableAttribute("loop",false);a.addBooleanImmutableAttribute("runToCompletion",true);a.addBooleanImmutableAttribute("positional",false);a.addBooleanImmutableAttribute("dopplerShift",false);a.addRealExpressionAttribute("volume",1);a.addRealExpressionAttribute("pitch",1);return this},start:function(b,e){if(!gs.debug.audio){return}var d=this.attributes.soundName.getValue();var a=this.attributes.loop.getValue();var c=gsMath.clampf(this.attributes.volume.getValue(),0,1);var f=Math.max(0,this.attributes.pitch.getValue());this.audioInstance=gs.AudioManager.current.playSound(d,c,a);this.attributes.volume.addObserver(this)},stop:function(a,b){if(!gs.debug.audio){return}if(this.audioInstance){if(this.attributes.loop.getValue()||!this.attributes.runToCompletion.getValue()){gs.AudioManager.current.stopInstance(this.audioInstance)}this.audioInstance=null}this.attributes.volume.removeObserver(this)},observeValueChange:function(a,b){if(a===this.attributes.volume){gs.AudioManager.current.setInstanceVolume(this.audioInstance,b)}},getRequiredAssets:function(d,a,b){var c=this.attributes.soundName.getValue();if(c&&c.length>0){a[c]=true}}});gs.PurchaseItemAction=function(){gs.StatelessBehavior.call(this)};gs.PurchaseItemAction.prototype={declareAttributes:function(a){a.addIntegerImmutableAttribute("item",0);a.addStringImmutableAttribute("table","")},start:function(c,e){var a=gs.Game.current;a.eventCenter.registerForEvent("purchaseItemSuccess",this,"purchaseItemSuccess");a.eventCenter.registerForEvent("purchaseItemFailure",this,"purchaseItemFailure");a.eventCenter.registerForEvent("purchaseItemCancel",this,"purchaseItemCancel");var d=this.attributes.item.getValue();var b={item:d,success:function(){a.eventCenter.postEvent("purchaseItemSuccess",null,d)},failure:function(){a.eventCenter.postEvent("purchaseItemFailure",null,d)},cancel:function(){a.eventCenter.postEvent("purchaseItemCancel",null,d)}};this.doStub("purchaseItem","purchaseItem",b)},stop:function(b,c){var a=gs.Game.current;a.eventCenter.deregisterForEvent("purchaseItemSuccess",this,"purchaseItemSuccess");a.eventCenter.deregisterForEvent("purchaseItemFailure",this,"purchaseItemFailure");a.eventCenter.deregisterForEvent("purchaseItemCancel",this,"purchaseItemCancel")},purchaseItemSuccess:function(a){a=parseInt(a,10);if(a===this.attributes.item.getValue()){this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.SUCCESS)}},purchaseItemFailure:function(a){a=parseInt(a,10);if(a===this.attributes.item.getValue()){this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.FAILURE)}},purchaseItemCancel:function(a){a=parseInt(a,10);if(a===this.attributes.item.getValue()){this.updateGameServiceStatus(a,gs.PurchasePredicate.EVENT.CANCEL)}},updateGameServiceStatus:function(c,a){var b=gs.Game.current;b.services.purchases.item.setValue(c);b.services.purchases.status.setValue(a)}};gs.inherits(gs.PurchaseItemAction,gs.StatelessBehavior);gs.ReplicateBehavior=function(){gs.MutableBehavior.call(this)};gs.ReplicateBehavior.prototype={declareAttributes:function(a){a.addRealExpressionAttribute("angle",0);a.addRealExpressionAttribute("spacing",50);a.addIntegerExpressionAttribute("copies",5)},start:function(a,b){if(!a.visible()){return}a.addSpaceSource(this)},stop:function(a,b){if(!a.visible()){return}a.removeSpaceSource(this)},createSpace:function(b){var a=b.createNode(gs.SGSpace.NodeType.SGReplicator);this.attributes.spacing.connectToSprite(a,"spacing","dirty");this.attributes.copies.connectToSprite(a,"copies","dirty");this.attributes.angle.connectToSprite(a,"angle","dirty");this._replicatorSpace=a;return a},getSpace:function(){return this._replicatorSpace},removeSpace:function(a){this.attributes.spacing.disconnectFromSprite();this.attributes.copies.disconnectFromSprite();this.attributes.angle.disconnectFromSprite();a.removeNode(this._replicatorSpace);this._replicatorSpace=null}};gs.inherits(gs.ReplicateBehavior,gs.MutableBehavior);gs.ResetGameAction=function(){gs.StatelessBehavior.call(this)};gs.ResetGameAction.prototype={declareAttributes:function(a){a.addBooleanImmutableAttribute("enableAdvertisement",false)},start:function(a,c){var b=this.attributes.enableAdvertisement.getValue();gs.Game.current.eventCenter.postEvent("resetGame",null,b)}};gs.inherits(gs.ResetGameAction,gs.StatelessBehavior);gs.ResetSceneAction=function(){gs.StatelessBehavior.call(this)};gs.ResetSceneAction.prototype={declareAttributes:function(a){a.addBooleanImmutableAttribute("enableAdvertisement",false)},start:function(a,c){var b=this.attributes.enableAdvertisement.getValue();gs.Game.current.eventCenter.postEvent("resetScene",null,b)}};gs.inherits(gs.ResetSceneAction,gs.StatelessBehavior);gs.RotateBehavior=gs.Behavior.subclass("RotateBehavior");gs.RotateBehavior.CLOCKWISE=0;gs.RotateBehavior.COUNTERCLOCKWISE=1;gs.RotateBehavior.init=function(){gs.Behavior.init.call(this);this.attributes.addRealExpressionAttribute("angularVelocity",90);this.attributes.addIntegerImmutableAttribute("direction",gs.RotateBehavior.COUNTERCLOCKWISE);this.attributes.addBooleanImmutableAttribute("haltWhenBehaviorStops",true);return this};gs.RotateBehavior.start=function(a,b){this.setAngularVelocity(this.attributes.angularVelocity.getValue());this._updatingSelf=false;this.attributes.angularVelocity.addObserver(this)};gs.RotateBehavior.observeValueChange=function(a,b){if(this._updatingSelf){return}this._updatingSelf=true;this.setAngularVelocity();this._updatingSelf=false};gs.RotateBehavior.setAngularVelocity=function(){var a=this._entity;var b=this.attributes.angularVelocity.getValue();if(this.attributes.direction.getValue()==gs.RotateBehavior.CLOCKWISE){b=-b}a.aspects.motion.attributes.angularVelocity.setValue(b)};gs.RotateBehavior.stop=function(b,c){if(this.attributes.haltWhenBehaviorStops.getValue()){var a=this._entity.aspects.motion;a.attributes.angularVelocity.setValue(0);this.attributes.angularVelocity.removeObserver(this);this._updatingSelf=null}};gs.RotateBehavior.willExit=function(a){if(!this.attributes.haltWhenBehaviorStops.getValue()){this.attributes.angularVelocity.removeObserver(this)}gs.Behavior.willExit.call(this,a)};gs.RotateToAngleBehavior=gs.CompletingBehavior.subclass("RotateToAngleBehavior");gs.RotateToAngleBehavior.init=function(){gs.CompletingBehavior.init.call(this);this.attributes.addRealExpressionAttribute("angle",0);this.attributes.addIntegerImmutableAttribute("space",gs.MoveBehavior.SPACE_ACTOR);this.attributes.addRealExpressionAttribute("angularVelocity",90);this.attributes.addBooleanImmutableAttribute("continuousMovement",false);return this};gs.RotateToAngleBehavior.standardAngle=function(a){return a%360};gs.RotateToAngleBehavior.angleEqual=function(f,e,c,d){var b=c*d;var a=this.standardAngle(e-f);if(a>180){a=a-360}else{if(a<-180){a=a+360}}return Math.abs(a)<Math.abs(b)};gs.RotateToAngleBehavior.completeStart=function(a,b){gs.CompletingBehavior.completeStart.call(this,a,b);this._initialActorRotation=0;if(this.attributes.space.getValue()==gs.MoveBehavior.SPACE_ACTOR){var a=this._entity;this._initialActorRotation=a.attributes.rotation.getValue()}if(!this._isRotateToPosition){this._targetAngle=this.attributes.angle.getValue()}this.calculateTargetAngle();this.calculateAngularVelocity();this._updatingSelf=false;this.attributes.angle.addObserver(this);this.attributes.angularVelocity.addObserver(this)};gs.RotateToAngleBehavior.calculateTargetAngle=function(){if(this.attributes.space.getValue()==gs.MoveBehavior.SPACE_ACTOR){this._targetAngle=this._targetAngle+this._initialActorRotation}this._targetAngle=this.standardAngle(this._targetAngle)};gs.RotateToAngleBehavior.calculateAngularVelocity=function(){var c=this._entity;var b=c.attributes.rotation.getValue();b=this.standardAngle(b);var a=this._targetAngle-b;var d=this.attributes.angularVelocity.getValue();if(a>180||(a<0&&a>-180)){d=-d}c.aspects.motion.attributes.angularVelocity.setValue(d)};gs.RotateToAngleBehavior.observeValueChange=function(a,b){if(this._updatingSelf){return}this._updatingSelf=true;if(a===this.attributes.angle){this._targetAngle=b;this.calculateTargetAngle()}this._updateAngularVelocity=true;this._updatingSelf=false};gs.RotateToAngleBehavior.completeEvaluate=function(c,d){gs.CompletingBehavior.completeEvaluate.call(this,c,d);var a=c.attributes.rotation.getValue();if(a<0||a>=360){a=this.standardAngle(a);c.attributes.rotation.setValue(a)}if(this._updateAngularVelocity){this.calculateAngularVelocity();this._updateAngularVelocity=false}this._updatingSelf=true;var b=this.attributes.angularVelocity.getValue();this._updatingSelf=false;if(this.angleEqual(this._targetAngle,a,b,d.dt)){c.attributes.rotation.fastSetValue(this._targetAngle);c.aspects.motion.attributes.angularVelocity.fastSetValue(0);if(!this.attributes.continuousMovement.getValue()){this.setCompleted(true)}}};gs.RotateToAngleBehavior.completeStop=function(a,b){gs.CompletingBehavior.completeStop.call(this,a,b);this.attributes.angle.removeObserver(this);this.attributes.angularVelocity.removeObserver(this);this._updatingSelf=null;a.aspects.motion.attributes.angularVelocity.fastSetValue(0)};gs.RotateToPositionBehavior=gs.RotateToAngleBehavior.subclass("RotateToPositionBehavior");gs.RotateToPositionBehavior.init=function(){gs.RotateToAngleBehavior.init.call(this);this.attributes.addPointExpressionAttribute("position");this.attributes.addRealExpressionAttribute("offsetAngle",0);this.attributes.space.changeDefaultValue(gs.MoveBehavior.SPACE_SCENE);return this};gs.RotateToPositionBehavior.completeStart=function(a,b){this._isRotateToPosition=true;this.updatePositionAngle();this.attributes.position.x.addObserver(this);this.attributes.position.y.addObserver(this);this.attributes.offsetAngle.addObserver(this);if(this.attributes.space.getValue()==gs.MoveBehavior.SPACE_SCENE){a.attributes.position.x.addObserver(this);a.attributes.position.y.addObserver(this)}this._updatingSelf=false;gs.RotateToAngleBehavior.completeStart.call(this,a,b)};gs.RotateToPositionBehavior.updatePositionAngle=function(){var c=this.standardAngle(this.attributes.offsetAngle.getValue());var e=gs.g_tempVec2d;e[0]=this.attributes.position.x.getValue();e[1]=this.attributes.position.y.getValue();var a=this._entity;if(this.attributes.space.getValue()==gs.MoveBehavior.SPACE_SCENE){e[0]=e[0]-a.attributes.position.x.getValue();e[1]=e[1]-a.attributes.position.y.getValue()}var b=Math.sqrt(e[0]*e[0]+e[1]*e[1]);if(b>0){e[0]=(e[0]/b);e[1]=(e[1]/b)}else{e[0]=0;e[1]=0}var d=180/Math.PI*(Math.atan2(e[1],e[0]));this._targetAngle=d+c};gs.RotateToPositionBehavior.observeValueChange=function(a,b){if(this._updatingSelf){return}this._updatingSelf=true;this.updatePositionAngle();this._updatingSelf=false;gs.RotateToAngleBehavior.observeValueChange.call(this,this.attributes.angle,this._targetAngle)};gs.RotateToPositionBehavior.completeStop=function(a,b){gs.RotateToAngleBehavior.completeStop.call(this,a,b);this.attributes.position.x.removeObserver(this);this.attributes.position.y.removeObserver(this);this.attributes.offsetAngle.removeObserver(this);if(this.attributes.space.getValue()==gs.MoveBehavior.SPACE_SCENE){a.attributes.position.x.removeObserver(this);a.attributes.position.y.removeObserver(this)}this._updatingSelf=null};gs.RuleBehavior=gs.Behavior.subclass("RuleBehavior");gs.RuleBehavior.CONDITION_ALL=0;gs.RuleBehavior.CONDITION_ANY=1;gs.RuleBehavior._sharedAttributeCollection=new gs.ImmutableAttributeCollection();gs.RuleBehavior._sharedAttributeCollection.addIntegerImmutableAttribute("compoundConditionKind",0);gs.RuleBehavior.init=function(){this.compoundConditionKind=gs.RuleBehavior.CONDITION_ALL;this.behaviors=new gs.BehaviorList();this.behaviors._parent=this;return this};gs.RuleBehavior.initPrime=function(){this.behaviors=null;this.elseBehaviors=null;this.conditionStates=gs.array.provide();this.thenDidEnter=false;this.elseDidEnter=false;this.thenIsStarted=false;this.elseIsStarted=false;this._needsUpdate=false;this._registeredForEveryFrame=false;this.lastTest=false;this.actorTime=null;return this};gs.RuleBehavior.clone=function(){var a=gs.Behavior.clone.call(this);a.compoundConditionKind=this.compoundConditionKind;a.behaviors=this.behaviors.clone();a.behaviors._parent=a;if(this.elseBehaviors){a.elseBehaviors=this.elseBehaviors.clone();a.elseBehaviors._parent=a}return a};gs.RuleBehavior.testSingleCondition=function(){return this.conditionState};gs.RuleBehavior.testAllConditions=function(){var a=this.conditionStates;for(var b=0,c=a.length;b<c;b++){if(!a[b]){return false}}return true};gs.RuleBehavior.testAnyConditions=function(){var a=this.conditionStates;for(var b=0,c=a.length;b<c;b++){if(a[b]){return true}}return false};gs.RuleBehavior.start=function(d,e){this._needsUpdate=false;this._registeredForEveryFrame=false;if(this.condition){this.condition.start(d,this);this.conditionState=this.condition.test()}else{var g=this.conditions.array;var a=this.conditionStates;for(var b=0,c=g.length;b<c;b++){var h=g[b];h.start(d,this);a[b]=h.test()}}var f=this.testConditionsFunction();if(f){if(!this.thenDidEnter){this.behaviors.didEnter(d,false);this.thenDidEnter=true}this.behaviors.start(d,e);this.thenIsStarted=true}else{if(!this.elseDidEnter){this.elseBehaviors&&this.elseBehaviors.didEnter(d,false);this.elseDidEnter=true}this.elseBehaviors&&this.elseBehaviors.start(d,e);this.elseIsStarted=true}this.lastTest=f;this.actorTime=e};gs.RuleBehavior.stop=function(c,d){if(this.condition){this.condition.stop(c)}else{var e=this.conditions.array;for(var a=0,b=e.length;a<b;a++){e[a].stop(c)}}if(this.lastTest){if(this.thenIsStarted){this.behaviors.stop(c,d);this.thenIsStarted=false}}else{if(this.elseIsStarted){this.elseBehaviors&&this.elseBehaviors.stop(c,d);this.elseIsStarted=false}}this.lastTest=null;this.actorTime=null;if(this._registeredForEveryFrame){this.deregisterForEveryFrame();this._registeredForEveryFrame=false}this._needsUpdate=false};gs.RuleBehavior.didEnter=function(c,e){gs.Behavior.didEnter.call(this,c,e);this.thenDidEnter=false;this.elseDidEnter=false;this.thenIsStarted=false;this.elseIsStarted=false;if(this.condition){this.conditionState=false;this.condition.didEnter(c,e,this,0);this.testConditionsFunction=this.testSingleCondition}else{var d=this.conditions.array;var f=d.length;var a=this.conditionStates;if(!a){a=gs.array.provide();this.conditionStates=a}for(var b=0;b<f;++b){a[b]=false;d[b].didEnter(c,e,this,b)}if(this.compoundConditionKind===gs.RuleBehavior.CONDITION_ANY){this.testConditionsFunction=this.testAnyConditions}else{this.testConditionsFunction=this.testAllConditions}}this.behaviors.didEnter(c,e);this.thenDidEnter=true;this.elseBehaviors&&this.elseBehaviors.didEnter(c,e);this.elseDidEnter=true};gs.RuleBehavior.willExit=function(c){if(this.thenDidEnter){this.behaviors.willExit(c);this.thenDidEnter=false}if(this.elseDidEnter){this.elseBehaviors&&this.elseBehaviors.willExit(c);this.elseDidEnter=false}if(this.condition){this.condition.willExit(c)}else{var d=this.conditions.array;for(var a=0,b=d.length;a<b;++a){d[a].willExit(c)}}gs.Behavior.willExit.call(this,c)};gs.RuleBehavior.conditionChangedState=function(a,c){if(!this.actorTime||typeof a!=="number"||(!this.condition&&!this.conditionStates)){return false}var b=this.testConditionsFunction();if(this.condition){this.conditionState=c}else{this.conditionStates[a]=c}var d=this.testConditionsFunction();if(!this._needsUpdate){this._needsUpdate=true;if(!this._registeredForEveryFrame){this.registerForEveryFrame();this._registeredForEveryFrame=true}}return(d!==b)};gs.RuleBehavior.everyFrame=function(a,b){this._needsUpdate=false;var c=this.testConditionsFunction();if(this.lastTest!==c){this.lastTest=c;if(c){if(this.elseIsStarted){this.elseBehaviors&&this.elseBehaviors.stop(a,b);this.elseIsStarted=false}if(!this.thenDidEnter){this.behaviors.didEnter(a,false);this.thenDidEnter=true}this.behaviors.start(a,b);this.thenIsStarted=true}else{if(this.thenIsStarted){this.behaviors.stop(a,b);this.thenIsStarted=false}if(!this.elseDidEnter){this.elseBehaviors&&this.elseBehaviors.didEnter(a,false);this.elseDidEnter=true}this.elseBehaviors&&this.elseBehaviors.start(a,b);this.elseIsStarted=true}}if(!this._needsUpdate){this.deregisterForEveryFrame();this._registeredForEveryFrame=false}};gs.RuleBehavior.loadFromLite=function(d,a){var e=d.attributes;var h=d.conditions;var b=d.behaviors;var i=d.elseBehaviors;if(e){var g=gs.RuleBehavior._sharedAttributeCollection;var f=g.compoundConditionKind;f.changeDefaultValue(0);g.loadFromLite(e,a);this.compoundConditionKind=f.getValue()}if(h){if(!Array.isArray(h)){var c=gs.Parser.parseCondition(h,a);this.setObjectForKey(c,"condition")}else{if(h.length===1){var c=gs.Parser.parseCondition(h[0],a);this.setObjectForKey(c,"condition")}else{this.setObjectForKey(gs.PrototypicalKeylessArray.provide().init("condition"),"conditions");this.conditions.loadFromLite(h,a)}}}else{this.setObjectForKey(gs.PrototypicalKeylessArray.provide().init("condition"),"conditions")}if(b){this.behaviors.loadFromLite(b,a)}if(i&&(!Array.isArray(i)||i.length>0)){this.elseBehaviors=new gs.BehaviorList();this.elseBehaviors._parent=this;this.elseBehaviors.loadFromLite(i,a)}};gs.RuleBehavior.loadFromTable=function(n,c){var o=gs.JXON;var k=o._type;var h=o._children;var j=gs.Project.nodeTypeNameMap;var b=n[h];if(b){for(var g=0,m=b.length;g<m;g++){var a=b[g];var l=a[h];if(l&&l.length>0){var p=j[a[k]];if(p==="conditions"){if(l.length===1){var d=gs.Parser.parseCondition(l[0],c);this.setObjectForKey(d,"condition")}else{this.setObjectForKey(gs.PrototypicalKeylessArray.provide().init(),"conditions");this.conditions.loadFromTable(l,c)}}else{if(p==="behaviors"){this.behaviors.loadFromTable(l,c)}else{if(p==="elseBehaviors"){this.setObjectForKey(gs.BehaviorList.provide().init(),"elseBehaviors");this.elseBehaviors.loadFromTable(l,c)}else{if(p==="attributes"){var e=gs.RuleBehavior._sharedAttributeCollection;var f=e.compoundConditionKind;f.changeDefaultValue(0);e.loadFromTable(l);this.compoundConditionKind=f.getValue()}}}}}}}};gs.RuleBehavior.getRequiredAssets=function(c,a,b){this.behaviors.getRequiredAssets(c,a,b);this.elseBehaviors&&this.elseBehaviors.getRequiredAssets(c,a,b)};gs.RuleBehavior.getRequiredActors=function(b,a){this.behaviors.getRequiredActors(b,a);this.elseBehaviors&&this.elseBehaviors.getRequiredActors(b,a)};gs.SaveAttributeAction=gs.Behavior.subclass("SaveAttributeAction");gs.SaveAttributeAction.init=function(){gs.Behavior.init.call(this);this.attributes.addReferenceImmutableAttribute("targetAttribute");this.attributes.addVariantExpressionAttribute("key","");return this};gs.SaveAttributeAction.start=function(c,g){var a=this.attributes.targetAttribute.getValue();if(!a){return}var h=a.resolveRelativeTo(c);if(!h){return}var f=h.getValue();var b=this.attributes.key.getValue();if(!b||b===""){gs.Log.warn("Saved attribute with empty name. value =",f)}else{}if(h._type==="table"){var d=h.getTableData();var e=gs.TableParser.serializeTableToFileFormat(d);gs.LocalStorage.setObject(e)}else{gs.LocalStorage.setString(b,f.toString())}};gs.SaveTableAction=function(){gs.StatelessBehavior.call(this)};gs.SaveTableAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("tableID","")},start:function(b,d){var e=this.resolveTableReferenceAttribute(this.attributes.tableID);if(!e){return}var c=e.getTableData();var a=this.attributes.tableID.getValue();gs.tables.saveToPersistence(c,a)}};gs.inherits(gs.SaveTableAction,gs.StatelessBehavior);gs.ShowBannerBehavior=gs.Behavior.subclass("ShowBannerBehavior",{positionIntToString:{0:"top",1:"bottom"},init:function(){gs.Behavior.init.call(this);this.attributes.addIntegerExpressionAttribute("position",0);return this},showBanner:function(a){var b=gs.ShowBannerBehavior.positionIntToString[a];gs.EngineContext.current.delegate.onShowBannerShow(b)},hideBanner:function(){gs.EngineContext.current.delegate.onShowBannerHide()},start:function(b,c){var a=this.attributes.position.getValue();this.showBanner(a)},stop:function(a,b){this.hideBanner()}});gs.ShowMoreGamesAction=gs.Behavior.subclass("ShowMoreGamesAction");gs.ShowMoreGamesAction.start=function(a,b){this.doStub("showMoreGames","show")};gs.SpawnAction=function(){gs.StatelessBehavior.call(this)};gs.SpawnAction.SPACE_ACTOR=0;gs.SpawnAction.SPACE_SCENE=1;gs.SpawnAction.ORDER_FRONT_ACTOR=0;gs.SpawnAction.ORDER_BACK_ACTOR=1;gs.SpawnAction.ORDER_FRONT_LAYER=2;gs.SpawnAction.ORDER_BACK_LAYER=3;gs.SpawnAction.prototype={declareAttributes:function(a){a.addStringImmutableAttribute("prototypeKey","");a.addRealExpressionAttribute("direction",0);a.addIntegerImmutableAttribute("directionSpace",gs.SpawnAction.SPACE_ACTOR);a.addRealExpressionAttribute("x",0);a.addRealExpressionAttribute("y",0);a.addIntegerImmutableAttribute("positionSpace",gs.SpawnAction.SPACE_ACTOR);a.addIntegerImmutableAttribute("layerOrder",gs.SpawnAction.ORDER_FRONT_ACTOR)},start:function(b,g){var c=b.scene;var l=this.attributes.x.getValueForEntityStateless(b);var j=this.attributes.y.getValueForEntityStateless(b);var k=this.attributes.direction.getValueForEntityStateless(b);if(this.attributes.positionSpace.getValue()===gs.SpawnAction.SPACE_ACTOR){var i=gs.g_tempVec2d;i[0]=l;i[1]=j;gs.Vector2.vectorRotate2D(i,i,(b.attributes.rotation.getValue()*gsMath.DEG2RAD));l=b.attributes.position.x.getValue()+i[0];j=b.attributes.position.y.getValue()+i[1]}if(!c.isInBounds(l,j)){return}var e=this.attributes.prototypeKey.getValue();var h=gs.ActorFactory.current.spawnActorInstance(e);if(!h){return}if(this.attributes.directionSpace.getValue()==gs.SpawnAction.SPACE_SCENE){h.attributes.rotation.setValue(k)}else{h.attributes.rotation.setValue(b.attributes.rotation.getValue()+k)}var a=this.attributes.layerOrder.getValue();var f=null;var d=b.layer;if(a==gs.SpawnAction.ORDER_FRONT_LAYER){f=d.countActors()}else{if(a==gs.SpawnAction.ORDER_BACK_LAYER){f=0}else{if(a==gs.SpawnAction.ORDER_FRONT_ACTOR){f=d.indexOfActor(b)+1}else{if(a==gs.SpawnAction.ORDER_BACK_ACTOR){f=d.indexOfActor(b)}}}}h.attributes.position.x.setValue(l);h.attributes.position.y.setValue(j);c.addActor(h,d,f);h.start(c.timebase.currentTimeStamp,c.firstFrame)},getRequiredActors:function(d,b){var c=this.attributes.prototypeKey.getValue();var a=gs.ActorFactory.current.getActorPrototype(c);if(!a){gs.Log.warn("SpawnAction: invalid actor id:",c);return}if(d[c]){d[c]++;return}d[c]=1;a.getRequiredActors(d,b)}};gs.inherits(gs.SpawnAction,gs.StatelessBehavior);gs.StopMusicAction=function(){gs.SingletonBehavior.call(this)};gs.StopMusicAction.prototype={start:function(a,b){gs.AudioManager.current.stopMusic()}};gs.inherits(gs.StopMusicAction,gs.SingletonBehavior);gs.singleton(gs.StopMusicAction);gs.TimerBehavior=gs.CompoundBehavior.subclass("TimerBehavior",{TYPE_REPEATING:0,TYPE_DELAY:1,TYPE_DURATION:2,init:function(){gs.CompoundBehavior.init.call(this);this.attributes.addIntegerImmutableAttribute("timerType",gs.TimerBehavior.TYPE_REPEATING);this.attributes.addRealExpressionAttribute("interval",5);this.attributes.addBooleanImmutableAttribute("runToCompletion",false);this._running=false;this._lastTest=false;this.type=0;this.interval=0;this.alreadyFired=false;this.firedCount=0;return this},initPrime:function(){this.attributes=null;this.behaviors=null;this._running=false;this._lastTest=false;this.type=0;this.interval=0;this.alreadyFired=false;this.firedCount=0;return this},start:function(b,d){if(this._running&&this.type===gs.TimerBehavior.TYPE_DELAY){this.finished(b,d);this.deregisterForEveryFrame()}if(!this._running){var c=this.attributes.timerType.getValue();var a=Math.max(0,this.attributes.interval.getValue());this.initTimer(c,a);this.startAtTime(d.time);this._lastTest=false;this._running=true;this.registerForEveryFrame()}},finished:function(a,b){if(this._lastTest){gs.CompoundBehavior.stop.call(this,a,b)}this._lastTest=null;this._running=false},stop:function(a,b){if(!this._running){return}if(!this.attributes.runToCompletion.getValue()||this.type===gs.TimerBehavior.TYPE_REPEATING){this.finished(a,b);this.deregisterForEveryFrame()}},everyFrame:function(a,b){if(!this._running){return}var c=this.stateForTime(b.time);if(this._lastTest!==c){if(c){this._lastTest=true;gs.CompoundBehavior.start.call(this,a,b)}else{if(this.type===gs.TimerBehavior.TYPE_REPEATING){gs.CompoundBehavior.stop.call(this,a,b)}else{this.finished(a,b);this.deregisterForEveryFrame()}this._lastTest=false}}},willExit:function(a){this.finished(a,null);this.deregisterForEveryFrame();gs.CompoundBehavior.willExit.call(this,a)},initTimer:function(b,a){this.type=b;this.interval=a;this.alreadyFired=false;this.firedCount=0},setInterval:function(a){this.interval=a},startAtTime:function(a){this.startTime=a;this.alreadyFired=false},stateForTime:function(c){var a=c-this.startTime;switch(this.type){case gs.TimerBehavior.TYPE_REPEATING:if(this.alreadyFired){this.alreadyFired=false}else{var b=(a>(this.interval*(this.firedCount+1)));if(b){this.alreadyFired=true;this.firedCount++}return b}return false;case gs.TimerBehavior.TYPE_DELAY:return(a>this.interval);case gs.TimerBehavior.TYPE_DURATION:return(a<=this.interval);default:return false}}});gs.UnpauseGameAction=function(){gs.SingletonBehavior.call(this)};gs.UnpauseGameAction.prototype={start:function(a,b){gs.Game.current.eventCenter.postEvent("endPauseScene")}};gs.inherits(gs.UnpauseGameAction,gs.SingletonBehavior);gs.singleton(gs.UnpauseGameAction);gs.ShowAdAction=gs.ShowBannerBehavior.subclass("ShowAdAction",{init:function(){gs.ShowBannerBehavior.init.call(this);this.attributes.addIntegerExpressionAttribute("location",0);return this},start:function(b,c){var a=this.attributes.location.getValue();this.showBanner(a)}});gs.ShowiAdBehavior=gs.ShowBannerBehavior.subclass("ShowiAdBehavior");gs.GameCenterLoginAction=gs.Behavior.subclass("GameCenterLoginAction",{init:function(){gs.Behavior.init.call(this);return this},start:function(a,b){gs.EngineContext.current.delegate.onGameCenterLogin()}});gs.GameCenterPostScoreAction=gs.Behavior.subclass("GameCenterPostScoreAction",{init:function(){gs.Behavior.init.call(this);return this},start:function(a,b){gs.EngineContext.current.delegate.onGameCenterPostScore()}});gs.GameCenterShowLeaderboardAction=gs.Behavior.subclass("GameCenterShowLeaderboardAction",{init:function(){gs.Behavior.init.call(this);return this},start:function(a,b){gs.EngineContext.current.delegate.onGameCenterShowLeaderboard()}});gs.GameCenterShowAchievementsAction=gs.Behavior.subclass("GameCenterShowAchievementsAction",{init:function(){gs.Behavior.init.call(this);return this},start:function(a,b){gs.EngineContext.current.delegate.onGameCenterResetAchievements()}});gs.GameCenterResetAchievementsAction=gs.Behavior.subclass("GameCenterResetAchievementsAction",{init:function(){gs.Behavior.init.call(this);return this},start:function(a,b){gs.EngineContext.current.delegate.onGameCenterResetAchievements()}});gs.GameCenterUpdateAchievement=gs.Behavior.subclass("GameCenterUpdateAchievement",{init:function(){gs.Behavior.init.call(this);this.attributes.addStringExpressionAttribute("identifier","");this.attributes.addRealExpressionAttribute("percentageComplete",0);return this},start:function(b,d){var a=this.attributes.identifier.getValue();var c=this.attributes.percentageComplete.getValue();gs.EngineContext.current.delegate.onGameCenterUpdateAchievement()}});gs.InAppPurchaseItemAction=gs.Behavior.subclass("InAppPurchaseItemAction");gs.InAppPurchaseItemAction.init=function(){gs.Behavior.init.call(this);this.attributes.addVariantExpressionAttribute("itemIdentifier","");this.attributes.addReferenceImmutableAttribute("targetAttribute");this.attributes.addBooleanImmutableAttribute("consumable",false);this.attributes.addVariantExpressionAttribute("RHS","");this.attributes.addStringImmutableAttribute("successSceneKey","");this.attributes.addStringImmutableAttribute("cancelSceneKey","");this.attributes.addStringImmutableAttribute("errorSceneKey","");return this};gs.InAppPurchaseItemAction.start=function(b,f){if(gs.globalOptions.useBehaviorStubs){this.doStub("InAppPurchase","purchaseItem");return}var h=gs.Game.current;var i=h.eventCenter;if(h.isWaitingOnIAP){return}h.isWaitingOnIAP=true;gs.EngineContext.current.pause();i.registerForEvent("InAppSuccess",this,"InAppSuccess");i.registerForEvent("InAppCancelled",this,"InAppCancelled");i.registerForEvent("InAppFailure",this,"InAppFailure");this._actor=b;var c=this.attributes.targetAttribute.getValue();if(!c){this.InAppFailure();return}var d=c.resolveRelativeTo(b);if(!d){this.InAppFailure();return}var g=this.attributes.itemIdentifier.getValueForEntity(b);try{var e=gs.platform.PurchaseService.instance();e.purchaseItem(g)}catch(a){gs.Log.error(a);this.InAppFailure()}};gs.InAppPurchaseItemAction.InAppSuccess=function(){var a=gs.Game.current;var b=a.eventCenter;a.isWaitingOnIAP=false;gs.EngineContext.current.unpause();b.deregisterForEvent("InAppSuccess",this);b.deregisterForEvent("InAppCancelled",this);b.deregisterForEvent("InAppFailure",this);this.saveItemAttribute();var c=this.attributes.successSceneKey.getValue();if(c){b.postEvent("startPauseScene",null,c)}};gs.InAppPurchaseItemAction.InAppCancelled=function(){var a=gs.Game.current;var b=a.eventCenter;a.isWaitingOnIAP=false;gs.EngineContext.current.unpause();b.deregisterForEvent("InAppSuccess",this);b.deregisterForEvent("InAppCancelled",this);b.deregisterForEvent("InAppFailure",this);var c=this.attributes.cancelSceneKey.getValue();if(c){b.postEvent("startPauseScene",null,c)}};gs.InAppPurchaseItemAction.InAppFailure=function(){var a=gs.Game.current;var b=a.eventCenter;a.isWaitingOnIAP=false;gs.EngineContext.current.unpause();b.deregisterForEvent("InAppSuccess",this);b.deregisterForEvent("InAppCancelled",this);b.deregisterForEvent("InAppFailure",this);var c=this.attributes.errorSceneKey.getValue();if(c){b.postEvent("startPauseScene",null,c)}};gs.InAppPurchaseItemAction.saveItemAttribute=function(){var e=this.attributes.targetAttribute.getValue();if(!e){return}var d=e.resolveRelativeTo(this._actor);if(!d){return}var b=this.attributes.consumable.getValue();if(b){d.setValue(this.attributes.RHS.getValueForEntity(this._actor))}else{d.setValue(true)}var c=d.getValue();var a=this.attributes.itemIdentifier.getValue();gs.LocalStorage.setString(a,c.toString())};gs.InAppPurchaseRestoreItem=gs.Behavior.subclass("InAppPurchaseRestoreItem");gs.InAppPurchaseRestoreItem.init=function(){gs.Behavior.init.call(this);this.attributes.addReservedCompoundAttribute("iapitems","array",null,true);return this};gs.InAppPurchaseRestoreItem.start=function(d,g){if(gs.globalOptions.useBehaviorStubs){this.doStub("InAppPurchase","restoreItem");return}var j=gs.Game.current;var k=j.eventCenter;if(j.isWaitingOnIAP){return}var a=this.attributes.iapitems.size();if(a<=0){return}var c=gs.array.provide();for(var e=1;e<=a;e++){var h=this.attributes.iapitems.at(e);c.push(h.first.getValueForEntity(d))}this._actor=d;j.isWaitingOnIAP=true;k.registerForEvent("InAppRestore",this,"InAppRestore");k.registerForEvent("InAppFailure",this,"InAppFailure");try{var f=gs.platform.PurchaseService.instance();f.restoreItems(c)}catch(b){gs.Log.error(b);this.InAppFailure()}};gs.InAppPurchaseRestoreItem.InAppFailure=function(){var a=gs.Game.current;var b=a.eventCenter;a.isWaitingOnIAP=false;b.deregisterForEvent("InAppRestore",this);b.deregisterForEvent("InAppFailure",this)};gs.InAppPurchaseRestoreItem.InAppRestore=function(b){var k=gs.Game.current;var l=k.eventCenter;k.isWaitingOnIAP=false;l.deregisterForEvent("InAppRestore",this);l.deregisterForEvent("InAppFailure",this);var a=this.attributes.iapitems.size();for(var c=1;c<=a;c++){var j=this.attributes.iapitems.at(c);var f=j.first.getValueForEntity(this._actor);if(b.indexOf(f)!==-1){var d=gs.Reference.lookup(j.second.getValue());if(d){var e=d.resolveRelativeTo(this._actor);if(e){e.setValue(true);var g=e.getValue();var h=f;gs.LocalStorage.setString(h,g.toString())}}}}};gs.TweetSheetAction=gs.Behavior.subclass("TweetSheetAction",{init:function(){gs.Behavior.init.call(this);this.attributes.addStringExpressionAttribute("message","");this.attributes.addBooleanImmutableAttribute("editable",true);this.attributes.addStringExpressionAttribute("image","");return this},start:function(a,c){var b=this.attributes.message.getValue();gs.EngineContext.current.delegate.onTweetSheet(b)}});gs.EntityList=gs.PrototypicalArray.subclass("EntityList",{init:function(a){gs.PrototypicalArray.init.call(this);this.entityType=a;return this},loadFromLite:function(d,a){var e=null;switch(this.entityType){case"actor":e=gs.Parser.parseActor;break;case"layer":e=gs.Parser.parseLayer;break;case"condition":e=gs.Parser.parseCondition;break}if(Array.isArray(d)){for(var c=0;c<d.length;c++){var b=e(d[c],a);this.addObjectAtIndex(b,c,d[c]["id"])}}else{var b=e(d,a);this.addObjectAtIndex(b,0,d.id)}}});gs.LazySceneList=gs.PrototypicalArray.subclass("LazySceneList");gs.LazySceneList.init=function(){gs.PrototypicalArray.init.call(this);this.declaredScenes=gs.array.provide();return this};gs.LazySceneList.getScene=function(c,a){var b=this[c];if(!b){b=this.loadScene(c,a)}return b};gs.LazySceneList.numberOfScenes=function(){return this.declaredScenes.length};gs.LazySceneList.keyForScene=function(a){return this.declaredScenes[a]};gs.LazySceneList.sceneExists=function(b){var a=this.indexAndKey(b);return(!!this.declaredScenes[a])};gs.LazySceneList.indexAndKey=function(b){if(typeof(b)==="number"){return b}else{var a=this.declaredScenes.indexOf(b);return a}};gs.LazySceneList.indexByKey=function(a){return 1+this.declaredScenes.indexOf(a)};gs.LazySceneList.unloadAllScenes=function(){var a;var b=this.declaredScenes.length;for(a=0;a<b;++a){var c=this.declaredScenes[a];if(this[c]){this.unloadScene(c)}}};gs.LazySceneList.unloadScene=function(b){var a=this[b];this.removeObjectForKey(b)};gs.LazySceneList.isSceneLoaded=function(a){return(!!this[a])};gs.LazySceneList.inflateScene=function(c,b){var a=this;return gs._yield(function(){gs.Game.profiler.sceneLoadProfiler.parse.enter();var d=gs.Parser.parseScene(b);gs.Game.profiler.sceneLoadProfiler.parse.exit();a.addObjectAtIndex(d,null,c)})};gs.LazySceneList.loadScene=function(c,a){var b=this.indexAndKey(c);if(b>=0){a.project.loadScene(b,c)}};gs.LazySceneList.fetchSceneByIndex=function(a){if(a<=this.declaredScenes.length){gs.file.VirtualFileCache.current.fetchSceneByIndex(a)}};gs.LazySceneList.fetchSceneByKey=function(b){var a=this.indexByKey(b);this.fetchSceneByIndex(a)};gs.LazySceneList.loadFromLite=function(c,a){if(Array.isArray(c)){for(var b=0;b<c.length;b++){this.declaredScenes[b]=c[b]["id"]}}else{this.declaredScenes[0]=c.id}};gs.LazySceneList.loadFromTable=function(d){var c=this.declaredScenes;var e=d.length;for(var b=0;b<e;++b){var a=d[b];c[b]=a.id}};gs.Layer=function(){gs.ObjectWithImmutableAttributes.call(this);this.scene=null;if(!this.actors){this.actors=gs.array.provide()}};gs.Layer.prototype={declareAttributes:function(a){if(!a.scrollable){a.addBooleanImmutableAttribute("scrollable",true)}},getScene:function(){return this.scene},game:function(){return gs.Game.instance},scrollable:function(){return this.attributes.scrollable.getValue()},countActors:function(){return this.actors.length},actorAtIndex:function(a){return this.actors[a]},indexOfActor:function(a){return this.actors.indexOf(a)},startAspects:function(a){var d=this.actors;for(var b=0,c=d.length;b<c;b++){d[b].startAspects(a)}},startBehaviors:function(a){var d=this.actors;var e=gs.array.provide();var b,c=d.length;for(b=0;b<c;b++){e[b]=d[b]}for(b=0;b<c;++b){e[b].startBehaviors(a,true)}gs.array.recycle(e)},stop:function(a){var d=this.actors;var b,c=d.length;for(b=0;b<c;b++){d[b].stop(a)}for(b=0;b<c;b++){d[b].hideActor()}},evaluate:function(a){var d=this.actors;var b,c=d.length;for(b=0;b<c;b++){d[b].evaluate(a)}this.game().entityCounter.actors.add(c)},addActor:function(b,a){this.actors.splice(a,0,b);b.layer=this;b.scene=this.scene},removeActor:function(b){var a=this.actors.indexOf(b);if(a!==-1){this.actors.splice(a,1);b.layer=null;b.scene=null}},removeFromScene:function(){this.scene.layers.removeObject(this)},getRequiredActors:function(h,c){var g=this.actors;for(var b=0,f=g.length;b<f;b++){var e=g[b];if(!c){var d=e._prototypeID;var a=gs.ActorFactory.current.getActorPrototype(d);h[d]=1}e.getRequiredActors(h,c)}},getActorInstances:function(e){var d=this.actors;for(var a=0,c=d.length;a<c;a++){var b=d[a];e[b._objectKey]=b}},loadFromLite:function(d){gs.Entity.loadFromLite.call(this,d);var c=d.actors;if(c){gs.ObjectListWithKeys.prototype.loadFromLite.call(this.actors,gs.Parser.parseActor,c,false)}for(var a=0,b=this.actors.length;a<b;a++){this.actors[a].layer=this}},recycleThis:function(){this.attributes.scrollable.changeDefaultValue(true);gs.ObjectListWithKeys.prototype.clear.call(this.actors);this.scene=null;gs.Layer.recycle(this)}};gs.inherits(gs.Layer,gs.ObjectWithImmutableAttributes);gs.Pool.init(gs.Layer);gs.Entity=gs.PrototypicalDictionary.subclass("Entity");gs.Entity.init=function(){gs.PrototypicalDictionary.init.call(this);this.setObjectForKey(new gs.MutableAttributeCollection(),"attributes");this.attributes.addRealMutableAttribute("time",0);return this};gs.Entity.start=function(a){this.attributes.time.fastSetValue(a.time)};gs.Entity.stop=function(a){};gs.Entity.game=function(){return gs.Game.instance};gs.Entity.resolveReference=function(a){return a.resolveRelativeTo(this)};gs.Entity.resolveKeypath=function(b){var a=gs.Reference.lookup(b);return this.resolveReference(a)};gs.Entity.loadFromLite=function(c,a){var d=c.id;var b=c.attributes;if(d){this._objectKey=d}if(b){this.attributes.loadFromLite(b,a)}};gs.Actor=gs.Entity.subclass("Actor");gs.Actor.defaultSize={width:100,height:100};gs.Actor.sharedTestPoint=[0,0];gs.Actor.init=function(){gs.Entity.init.call(this);this.initialBehaviors=new gs.BehaviorList();this.behaviors=this.initialBehaviors;this.behaviors._parent=this;this.setObjectForKey(gs.AspectList.provide().init(),"aspects");this.attributes.addStringMutableAttribute("name","New Name");this.attributes.addPointMutableAttribute("position",0,0);this.attributes.addImmutableAttributeCollection("size");var a=this.attributes.size;a.addRealPositiveMutableAttribute("width",gs.Actor.defaultSize.width);a.addRealPositiveMutableAttribute("height",gs.Actor.defaultSize.height);this.attributes.addRealAngleMutableAttribute("rotation",0);this.attributes.addColorMutableAttribute("color",1,1,1,1);this.attributes.addStringMutableAttribute("image","");this.attributes.addStringMutableAttribute("tags",null);this.attributes.addBooleanMutableAttribute("preloadArt",true);this.aspects.addAspect("graphics");this.aspects.addAspect("motion");this.aspects.addAspect("physics");this._prototype=this;this._entity=this;return this};gs.Actor.clone=function(){var a=gs.Entity.clone.call(this);a._prototypeID=this._prototypeID;a._prototype=this;a.cachedTagString=this.cachedTagString;a.cachedTagList=this.cachedTagList;a.initialBehaviors=this.initialBehaviors.clone();a.initialBehaviors._parent=a;a.behaviors=a.initialBehaviors;a._entity=a;return a};gs.Actor.visible=function(){return this.aspects.graphics.attributes.visible.getValue()};gs.Actor.start=function(a,b){this.startAspects(a);this.startBehaviors(a,b)};gs.Actor.checkReceivedCollisions=function(){var e=this.scene._collisionController;var b=e.sensorRegistrationCountForCategory(this._prototypeID);var d=e.collisionRegistrationCountForCategory(this._prototypeID);var a=this.tags();var f=a.length;for(var c=0;c<f;++c){b=b+e.sensorRegistrationCountForCategory(a[c]);d=d+e.collisionRegistrationCountForCategory(a[c])}if(d>0){this.receivedCollisions=d;this.aspects.addAspect("collisionShape")}if(b>0){this.receivedSensors=b;this.aspects.addAspect("collisionSensor")}};gs.Actor.startAspects=function(a){if(this.visible()){this.game().eventCenter.registerForEvent("startedWrap",this,"startWrap",null,this);this.game().eventCenter.registerForEvent("finishedWrap",this,"stopWrap",null,this)}this.receivedCollisions=0;this.receivedSensors=0;this.everyFrameBehaviors=gs.array.provide();this._currentEFIndex=0;this.timebase=gs.Timebase.provide().initWithTime(a);this.timebase.convertTimeStamp(a);this.actorTime=this.timebase.getTimeStamp();this.aspects.start(this,this.actorTime);this.checkReceivedCollisions()};gs.Actor.startBehaviors=function(a,b){gs.Entity.start.call(this,this.actorTime);this.behaviors.didEnter(this,b);this.behaviors.start(this,this.actorTime)};gs.Actor.stop=function(a){this.game().eventCenter.deregisterForEvent("startedWrap",this,this);this.game().eventCenter.deregisterForEvent("finishedWrap",this,this);this.timebase.convertTimeStamp(a);gs.Entity.stop.call(this,this.actorTime);this.behaviors.stop(this,this.actorTime);this.behaviors.willExit(this);this.aspects.stop(this,this.actorTime);this.actorTime=null;if(this.timebase){gs.Timebase.recycle(this.timebase);this.timebase=null}if(this.everyFrameBehaviors){gs.array.recycle(this.everyFrameBehaviors);this.everyFrameBehaviors=null}this._currentEFIndex=0;this.restoreInitialState()};gs.Actor.evaluate=function(b){this.timebase.convertTimeStamp(b);var a=this.actorTime;this.attributes.time.fastSetValue(a.time);this.aspects.motion.evaluate(this,a);this.everyFrame(a)};gs.Actor.everyFrame=gs.NOOP_FUNCTION;gs.Actor.everyFrameMethod=function(c){var a=this.everyFrameBehaviors;this._currentEFIndex=0;while(this._currentEFIndex<a.length){var b=a[this._currentEFIndex];b.everyFrame(this,c);this._currentEFIndex++}this._currentEFIndex=0};gs.Actor.registerForEveryFrame=function(a){this.everyFrameBehaviors.push(a);if(this.everyFrameBehaviors.length===1){this.everyFrame=gs.Actor.everyFrameMethod}};gs.Actor.deregisterForEveryFrame=function(c){var b=this.everyFrameBehaviors;var a=b.indexOf(c);if(a>-1){if(a<=this._currentEFIndex){this._currentEFIndex=this._currentEFIndex-1}b.splice(a,1);if(b.length===0){this.everyFrame=gs.NOOP_FUNCTION}}};gs.Actor.testPoint=function(i){var f=this.aspects.collisionShape;f=f||this.aspects.collisionSensor;if((f)&&(f.length>0)){return f.testPoint(i)}else{var e=this.attributes.size.width.getValue()*0.5;var h=this.attributes.size.height.getValue()*0.5;var d=this.attributes.position.x.getValue();var c=this.attributes.position.y.getValue();var j=gs.Actor.sharedTestPoint;j[0]=i[0]-d;j[1]=i[1]-c;var g=this.aspects.physics.attributes.collisionShape.getValue();if(g===gs.PhysicsAspect.CIRCLE_SHAPE){var a=Math.min(e,h);return((j[0]*j[0]+j[1]*j[1])<=a*a)}else{var b=this.attributes.rotation.getValue();if(b!==0){gs.Vector2.vectorRotate2D(j,j,b*-gsMath.DEG2RAD)}return((j[0]>=-e)&&(j[0]<=e)&&(j[1]>=-h)&&(j[1]<=h))}}};gs.Actor.sharedEmptyTags=[];gs.Actor.tags=function(){var a=this.attributes.tags.getValue();if(!this.cachedTagList||this.cachedTagString!==a){this.cachedTagString=a;if(!a||a===""){this.cachedTagList=gs.Actor.sharedEmptyTags}else{this.cachedTagList=a.split("\t")}}return this.cachedTagList};gs.Actor.hasTag=function(a){var b=this.tags();return(b.indexOf(a)!==-1)};gs.Actor.loadFromLite=function(c,a){gs.Entity.loadFromLite.call(this,c,a);var e=c.prototype;var g=c.aspects;var b=c.behaviors;if(e){this._prototypeID=e}if(g){this.aspects.loadFromLite(g,a)}if(b){if(a){this.initialBehaviors=this.behaviors}else{this.behaviors=new gs.BehaviorList();this.behaviors._parent=this}this.behaviors.loadFromLite(b,a)}if(!a){var f=this.attributes.image._value;var d=this.aspects.graphics.attributes;var h=this.attributes.image._initialValue;if(f!==h){if(d.tileWidth._value===d.tileWidth._initialValue){d.tileWidth.setValue(0)}if(d.tileHeight._value===d.tileHeight._initialValue){d.tileHeight.setValue(0)}}}var i=this.tags()};gs.Actor.loadFromTable=function(l,c){gs.Entity.loadFromTable.call(this,l,c);var f=l.prototype;if(f){this._prototypeID=f}var k=l[gs.JXON._children];if(!k){return}var a=k.length;for(var e=0;e<a;++e){var d=k[e];var b=gs.Project.nodeTypeNameMap[d[gs.JXON._type]];switch(b){case"behaviors":this.behaviors.loadFromTable(d[gs.JXON._children],c);break;case"aspects":this.aspects.loadFromTable(d[gs.JXON._children],c);break}}if(!c){var h=this.attributes.image._value;var g=this.aspects.graphics.attributes;var j=this.attributes.image._initialValue;if(h!==j){if(g.tileWidth._value===g.tileWidth._initialValue){g.tileWidth.setValue(0)}if(g.tileHeight._value===g.tileHeight._initialValue){g.tileHeight.setValue(0)}}}var m=this.tags()};gs.Actor.restoreInitialState=function(){this.attributes.restoreInitialState();this.aspects.restoreInitialState();this.behaviors=this.initialBehaviors};gs.Actor.getRequiredAssets=function(f,g,b,j){var h=this.attributes.preloadArt.getValue();var i=this.attributes.image.getValue();var a=i&&i.length>0;var c;var k;switch(b){case gs.LoadStrategyOption.NONE:c=false;k=false;break;case gs.LoadStrategyOption.INITIAL:c=!j;k=false;break;case gs.LoadStrategyOption.LATENCY:c=!j;k=h&&!a;break;case gs.LoadStrategyOption.SAFE:c=!j;k=h;break;case gs.LoadStrategyOption.SCENE:case gs.LoadStrategyOption.GAME:c=true;k=true;break;case gs.LoadStrategyOption.STRICT:default:c=h;k=h;break}if(a&&c){f[i]=true;var e=this.aspects.graphics.attributes.horizontalWrap.getValue();var d=this.aspects.graphics.attributes.verticalWrap.getValue();if(e===gs.SGWrapMode.SGWrapTile||d===gs.SGWrapMode.SGWrapTile){gs.AssetManager.current.imageForNamePow2(i)}}if(k){this.behaviors.getRequiredAssets(f,g,b)}};gs.Actor.getRequiredActors=function(b,a){this.behaviors.getRequiredActors(b,a)};gs.Actor.fileExtension=function(){return"actor"};gs.Actor.matchesCategory=function(a){if(this._prototypeID===a){return true}return this.hasTag(a)};gs.Game=gs.Entity.subclass("Game");gs.Game.instance=null;gs.Game.current=null;gs.Game.IPHONE_SCREEN_WIDTH=480;gs.Game.IPHONE_SCREEN_HEIGHT=320;gs.Game.addAccessors(["currentSceneKey"],["getCurrentSceneKey"]);gs.Game.addMutators(["currentSceneKey"],["setCurrentSceneKey"]);gs.Game.isWaitingOnKeyboardInput=false;gs.Game.init=function(){gs.Game.instance=this;gs.Game.current=this;gs.Entity.init.call(this);this.actorFactory=gs.ActorFactory.instance();this.primeInitialPools();this.primeBox2D();this.setObjectForKey(gs.LazySceneList.provide().init(),"scenes");this.collisionCategoryManager=new gs.CollisionCategoryManager;this.attributes.addSizeMutableAttribute("displaySize",gs.Game.IPHONE_SCREEN_WIDTH,gs.Game.IPHONE_SCREEN_HEIGHT);this.attributes.addStringImmutableAttribute("actorTags","");this.attributes.addReservedCompoundAttribute("manifests","compound");this.resolution=0;this.resolutionIndependence=0;this.isWaitingOnPurchaseItem=false;this.setupDevices();this.setupServices();this.sceneChangeEnabled=true;this.resetSceneEnabled=true;this.resetGameEnabled=true;this.currentSceneStack=gs.array.provide();this.sceneChangeMethod=gs.NOOP_FUNCTION;this.sceneLoadedMethod=null;this.deferredOpenURL=null;this.externalBrowser=false;this.tableLookupCache={};this.viewScaleX=1;this.viewScaleY=1;this.loadingFlag=false;this.firstFrameAfterLoading=false;this.texturePrimeFrames=0;this.prototypeCount=0;this.prototypeProgress=0;this.prototypeBatchSize=gs.globalOptions.actorPrototypeBatchSize;this.promiseGameParsed=new gs.Promise();this.inputEventTarget=null;this.inputEventTargetDetected=false;this.accelerometer=gs.platform.AccelerometerService.instance();this.accelerometer.init(this);this.frameProfiler=new gs.FrameProfiler();this.entityCounter=new gs.EntityCounter();this.sceneLoadProfiler=new gs.LoadProfiler();gs.Game.profiler={frameProfiler:this.frameProfiler,entityCounter:this.entityCounter,sceneLoadProfiler:this.sceneLoadProfiler};this.openURLView=false;this.openURLViewID=null;this.purchaseItemView=false;this.purchaseItemViewID=null;this.gameCenterView=false;this.gameCenterViewID=null;this.postScoreView=false;this.postScoreViewID=null;this.achivementView=false;this.achivementViewID=null;this.adView=false;this.adViewID=null;return this};gs.Game.setupDevices=function(){this.setObjectForKey(new gs.ImmutableAttributeCollection(),"devices");this.devices.addImmutableAttributeCollection("mouse");this.devices.mouse.addPointMutableAttribute("position",0,0);this.devices.mouse.addBooleanMutableAttribute("button",false);this.devices.addImmutableAttributeCollection("touches");this.devices.touches.addIntegerMutableAttribute("count",0);this.devices.touches.addImmutableAttributeCollection("active");this.devices.touches.active.addBooleanMutableAttribute("touch1",false);this.devices.touches.active.addBooleanMutableAttribute("touch2",false);this.devices.touches.active.addBooleanMutableAttribute("touch3",false);this.devices.touches.active.addBooleanMutableAttribute("touch4",false);this.devices.touches.active.addBooleanMutableAttribute("touch5",false);this.devices.touches.active.addBooleanMutableAttribute("touch6",false);this.devices.touches.active.addBooleanMutableAttribute("touch7",false);this.devices.touches.active.addBooleanMutableAttribute("touch8",false);this.devices.touches.active.addBooleanMutableAttribute("touch9",false);this.devices.touches.active.addBooleanMutableAttribute("touch10",false);this.devices.touches.active.addBooleanMutableAttribute("touch11",false);this.devices.touches.addPointMutableAttribute("touch1",0,0);this.devices.touches.addPointMutableAttribute("touch2",0,0);this.devices.touches.addPointMutableAttribute("touch3",0,0);this.devices.touches.addPointMutableAttribute("touch4",0,0);this.devices.touches.addPointMutableAttribute("touch5",0,0);this.devices.touches.addPointMutableAttribute("touch6",0,0);this.devices.touches.addPointMutableAttribute("touch7",0,0);this.devices.touches.addPointMutableAttribute("touch8",0,0);this.devices.touches.addPointMutableAttribute("touch9",0,0);this.devices.touches.addPointMutableAttribute("touch10",0,0);this.devices.touches.addPointMutableAttribute("touch11",0,0);this.devices.addImmutableAttributeCollection("accelerometer");this.devices.accelerometer.addRealMutableAttribute("x",0);this.devices.accelerometer.addRealMutableAttribute("y",0);this.devices.accelerometer.addRealMutableAttribute("z",0);this.devices.addImmutableAttributeCollection("screen");this.devices.screen.addSizeMutableAttribute("size",gs.Game.IPHONE_SCREEN_WIDTH,gs.Game.IPHONE_SCREEN_HEIGHT);this.devices.screen.addIntegerMutableAttribute("deviceOrientation",0);this.devices.screen.addIntegerMutableAttribute("interfaceOrientation",6);this.devices.screen.addRealAngleMutableAttribute("deviceRotation",0);this.devices.addImmutableAttributeCollection("audio");this.devices.audio.addRealNormalizedMutableAttribute("soundVolume",1);this.devices.audio.addRealNormalizedMutableAttribute("musicVolume",1);this.devices.addImmutableAttributeCollection("clock");this.devices.clock.addIntegerMutableAttribute("year",0);this.devices.clock.addIntegerMutableAttribute("month",0);this.devices.clock.addIntegerMutableAttribute("day",0);this.devices.clock.addIntegerMutableAttribute("hour",0);this.devices.clock.addIntegerMutableAttribute("minute",0);this.devices.clock.addIntegerMutableAttribute("second",0);this.devices.clock.addIntegerMutableAttribute("millisecond",0)};gs.Game.setupServices=function(){this.setObjectForKey(new gs.ImmutableAttributeCollection(),"services");this.services.addImmutableAttributeCollection("purchases");this.services.purchases.addIntegerMutableAttribute("status",0);this.services.purchases.addIntegerMutableAttribute("item",0)};gs.Game.setupCollisionCategories=function(){this.collisionCategoryManager.resetCollisionCategories();var d=this.actorFactory.getPrototypeIDs();for(var b=0,c=d.length;b<c;b++){this.collisionCategoryManager.addCollisionCategory(d[b])}var a=this.actorTags();for(b=0,c=a.length;b<c;b++){this.collisionCategoryManager.addCollisionCategory(a[b])}};gs.Game.getCurrentSceneKey=function(){return this._currentSceneKey};gs.Game.setCurrentSceneKey=function(a){this._currentSceneKey=a;this.currentScene=this.getCurrentScene()};gs.Game.getCurrentScene=function(){var b=this._currentSceneKey;var a=this.safeGetScene(b);return a};gs.Game.safeGetScene=function(a){if((a===undefined)||(a===null)){return null}else{return this.scenes.getScene(a,this)}};gs.Game.pushScene=function(e,c){var b=this.getCurrentScene();if(b&&b.hasStarted()){b.pause(c)}this.setValueForKey(e,"currentSceneKey");this.deviceOrientationChanged(this.devices.screen.deviceOrientation.getValue(),false);if(e!==null){var a=this.getCurrentScene();this.currentSceneStack.push(a);var d=(this.currentSceneStack.length>1);a.showScene(!d);if(!a.hasStarted()){a.start(c)}if(typeof(e)==="number"){this.setCurrentSceneKey(a._objectKey)}}};gs.Game.popScene=function(c){var b=this.getCurrentScene();this.tearDownScene(b,c);this.currentSceneStack.pop();var a=this.currentSceneStack[this.currentSceneStack.length-1];if(a){var d=a._objectKey;this.setValueForKey(d,"currentSceneKey");if(true){this.deviceOrientationChanged(this.devices.screen.deviceOrientation.getValue(),false)}this.getCurrentScene().resume(c)}else{this.setValueForKey(null,"currentSceneKey")}};gs.Game.flushSceneStack=function(a){while(this.currentSceneStack.length>0){var b=this.currentSceneStack.pop();this.tearDownScene(b,a)}this.setValueForKey(null,"currentSceneKey")};gs.Game.tearDownScene=function(b,a){if(b&&b.hasStarted()){b.stop(a)}b.hideScene();this.scenes.unloadScene(b._objectKey)};gs.Game.switchToScene=function(d,c){this.flushSceneStack(c);this.pushScene(d,c);var b=this.getCurrentScene();var a=gs.Map.provide();b.getRequiredActors(a,true);gs.ActorFactory.current.managePools(d,a)};gs.Game.setNeedsToChangeScene=function(a){if(this._currentSceneKey&&(a===this.currentSceneStack[0]._objectKey)){this.resetSceneViaChangeScene=true;this.setNeedsToResetScene();return}if(this.sceneChangeEnabled&&this.scenes.sceneExists(a)&&(this.sceneChangeMethod===gs.NOOP_FUNCTION)){this._sceneKeyToChangeTo=a;this.sceneChangeMethod=gs.Game.loadScene}};gs.Game.forceNeedsToChangeScene=function(a){this._sceneKeyToChangeTo=a;this.sceneChangeMethod=gs.Game.loadScene};gs.Game.setNeedsToResetScene=function(){if(this.resetSceneEnabled&&(this.sceneChangeMethod===gs.NOOP_FUNCTION)){this.sceneChangeMethod=this.resetScene}};gs.Game.setNeedsToResetGame=function(){if(this.resetGameEnabled&&(this.sceneChangeMethod===gs.NOOP_FUNCTION)){this.sceneChangeMethod=this.resetGame}};gs.Game.setNeedsToEndGame=function(){this.sceneChangeMethod=this.endGame};gs.Game.setNeedsToPauseGame=function(b){if(this.sceneChangeEnabled&&this.scenes.sceneExists(b)&&(this.sceneChangeMethod===gs.NOOP_FUNCTION)){this._sceneKeyToChangeTo=b;this.sceneChangeMethod=this.pauseGame;var a=this.scenes.indexAndKey(b);a++;this.project.virtualFileCache.retainSceneByIndex(a)}};gs.Game.setNeedsToUnpauseGame=function(){if(this.sceneChangeEnabled&&(this.currentSceneStack.length>1)&&(this.sceneChangeMethod===gs.NOOP_FUNCTION)){this.sceneChangeMethod=this.resumeGame}};gs.Game.start=function(a){this.setupCollisionCategories();gs.Entity.start.call(this,a);var b=this.eventCenter;b.registerForEvent("changeToScene",this,"setNeedsToChangeScene",null);b.registerForEvent("resetScene",this,"setNeedsToResetScene",null);b.registerForEvent("resetGame",this,"setNeedsToResetGame",null);b.registerForEvent("startPauseScene",this,"setNeedsToPauseGame",null);b.registerForEvent("endPauseScene",this,"setNeedsToUnpauseGame",null);b.registerForEvent("systemPause",this,"systemPause",null);this.devices.audio.musicVolume.addObserver(this);this.devices.audio.soundVolume.addObserver(this);gs.AudioManager.current.initWithGame(this);gs.AudioManager.current.setSoundVolume(this.devices.audio.soundVolume.getValue());gs.AudioManager.current.setMusicVolume(this.devices.audio.musicVolume.getValue())};gs.Game.stop=function(a){gs.Entity.stop.call(this,a);this.devices.audio.soundVolume.removeObserver(this);this.devices.audio.musicVolume.removeObserver(this);this.eventCenter.deregisterForEvent("changeToScene",this);this.eventCenter.deregisterForEvent("resetScene",this);this.eventCenter.deregisterForEvent("resetGame",this);this.eventCenter.deregisterForEvent("startPauseScene",this);this.eventCenter.deregisterForEvent("endPauseScene",this);this.flushSceneStack(a);gs.AudioManager.current.stopMusic()};gs.Game.teardown=function(){};gs.Game.reset=function(){this.setNeedsToChangeScene(this.scenes.declaredScenes[0])};gs.Game.observeValueChange=function(a,b){if(a===this.devices.audio.musicVolume){gs.AudioManager.current.setMusicVolume(b)}else{if(a===this.devices.audio.soundVolume){gs.AudioManager.current.setSoundVolume(b)}}};gs.Game.evaluate=function(a){this.attributes.time.fastSetValue(a.time);this.updateClock();if(!this.inputEventTargetDetected){this.redetectInputCoordinates()}if(this.currentScene){this.currentScene.evaluate(a)}this.sceneChangeMethod(a);this.eventCenter.checkEventQueue();this.project.dispatchDeferredActions();this.firstFrameAfterLoading=false};gs.Game.loadScene=function(b){this.sceneLoadProfiler.reset();this.sceneLoadProfiler.time.enter();this.setLoadingFlag(true);var a=this.getCurrentScene();var c=null;if(a&&a.hasStarted()){a.stop(b);c=a.attributes.name.getValue()}gs.platform.AnalyticsService.instance().beginSceneChange(c);this.preloadAssetsForScene(this._sceneKeyToChangeTo,true);this.scenes.getScene(this._sceneKeyToChangeTo,this);this.sceneLoadedMethod=gs.Game.changeScene;this.sceneChangeMethod=gs.Game.isSceneLoaded};gs.Game.isSceneLoaded=function(a){var b=this.scenes.isSceneLoaded(this._sceneKeyToChangeTo);if(b){this.sceneChangeMethod=this.sceneLoadedMethod}};gs.Game.changeScene=function(a){if(this._sceneKeyToChangeTo!==null){this.sceneChangeMethod=gs.NOOP_FUNCTION;this.switchToScene(this._sceneKeyToChangeTo,a);this._sceneKeyToChangeTo=null}};gs.Game.resetScene=function(a){var b=this._currentSceneKey;if(this.resetSceneViaChangeScene){while(this.currentSceneStack.length>0){b=this._currentSceneKey;this.popScene(a)}this.resetSceneViaChangeScene=false}else{this.popScene(a)}this.sceneChangeMethod=gs.NOOP_FUNCTION;this.setNeedsToChangeScene(b)};gs.Game.resetGame=function(b){this.stop(b);this.scenes.unloadAllScenes();this.sceneChangeMethod=gs.NOOP_FUNCTION;this.reset();var a=this;this.project.getObjectJSON(function(c){gs.Entity.loadFromLite.call(a,c);a.start(b)})};gs.Game.pauseGame=function(b){this.setLoadingFlag(true);var a=this.getCurrentScene();if(a&&a.hasStarted()){a.pause(b)}this.preloadAssetsForScene(this._sceneKeyToChangeTo,false);this.scenes.getScene(this._sceneKeyToChangeTo,this);this.sceneLoadedMethod=gs.Game.pushPauseScene;this.sceneChangeMethod=gs.Game.isSceneLoaded};gs.Game.pushPauseScene=function(a){this.sceneChangeMethod=gs.NOOP_FUNCTION;this.pushScene(this._sceneKeyToChangeTo,a);this._sceneKeyToChangeTo=null};gs.Game.resumeGame=function(a){this.sceneChangeMethod=gs.NOOP_FUNCTION;this.popScene(a);this._sceneKeyToChangeTo=null};gs.Game.endGame=function(a){};gs.Game.actorTags=function(){if(!this.cachedTags){var a=this.attributes.actorTags.getValue();this.cachedTags=a.split("\t")}return this.cachedTags};gs.Game.setActorTags=function(a){var b="\t";this.attributes.actorTags.setValue(table.concat(a,b))};gs.Game.addActorTag=function(b){var c=(b||"New Tag");if(!this.validateTagName(c)){var d=0;var e=c+" "+d;while(!this.validateTagName(e)){d=d+1;e=c+" "+d}c=e}if(this.actorTags().length===0){this.attributes.actorTags.setValue(c)}else{var a=this.attributes.actorTags.getValue();a=a+"\t"+c;this.attributes.actorTags.setValue(a)}return c};gs.Game.validateTagName=function(c){var b=this.actorTags();var a=set.arrayToSet(b);return(a[c]==null)};gs.Game.bestInterfaceOrientationForScene=function(b){var a=this.getCurrentScene().supportedOrientations();if(a[b]){return b}else{var c=0;if(a[3]){c=3}if(a[1]){c=1}if(a[2]){c=2}if(a[0]){c=0}return c}};gs.Game.updateInterfaceOrientation=function(a){this.devices.screen.interfaceOrientation.setValue(a)};gs.Game.deviceOrientationChanged=function(b,a){this.devices.screen.deviceOrientation.setValue(b);if(b>3){return}var c=this.bestInterfaceOrientationForScene(b);if(b===1&&c===0){c=0;this.accelerometer.setFlipAxes(true)}else{this.accelerometer.setFlipAxes(false)}this.devices.screen.interfaceOrientation.setValue(c)};gs.Game.updateScreenSize=function(){var e=gs.sizeAndOrientationForResolution(this.resolution);var d=e[0];var a=e[1];var c=e[2];var b=this.devices.screen;b.deviceOrientation.setValue(c);this.updateInterfaceOrientation(c);b.size.width.setValue(d);b.size.height.setValue(a);this.accelerometer.setOrientation(c===2?"portrait":"landscape")};gs.Game.updateGraphicsDimensions=function(){this.renderer.updateSize();var b=gs.EngineContext.current.renderContext.viewport;var e=b.reportWidth;var a=b.reportHeight;var c=b.reportAspect;if(gs.globalOptions.spoofIOSScreenSize){var g=false;switch(this.resolution){case gs.Resolution.IPHONE_LANDSCAPE:case gs.Resolution.IPHONE_PORTRAIT:case gs.Resolution.IPAD_LANDSCAPE:case gs.Resolution.IPAD_PORTRAIT:case gs.Resolution.LEGACY_IPHONE_LANDSCAPE:case gs.Resolution.LEGACY_IPHONE_PORTRAIT:g=true;break}if(g){var d=null;var f=(a>e);switch(c){case gs.AspectRatio.ASPECT_16_9:d=gs.sizeAndOrientationForResolution(f?gs.Resolution.IPHONE_PORTRAIT:gs.Resolution.IPHONE_LANDSCAPE);break;case gs.AspectRatio.ASPECT_4_3:d=gs.sizeAndOrientationForResolution(f?gs.Resolution.IPAD_PORTRAIT:gs.Resolution.IPAD_LANDSCAPE);break;case gs.AspectRatio.ASPECT_3_2:d=gs.sizeAndOrientationForResolution(f?gs.Resolution.LEGACY_IPHONE_PORTRAIT:gs.Resolution.LEGACY_IPHONE_LANDSCAPE);break;default:break}if(d){e=d[0];a=d[1]}}}this.devices.screen.size.width.setValue(e);this.devices.screen.size.height.setValue(a)};gs.Game.loadFromLite=function(b){gs.Entity.loadFromLite.call(this,b);this.title=b.title;this.resolution=Number(b.resolution);this.resolutionIndependence=Number(b.resolutionIndependence);var c=b.prototypes;var a=b.scenes;if(c){if(Array.isArray(c)){this.prototypeCount=c.length}else{this.prototypeCount=1}}if(a){this.scenes.loadFromLite(a)}this.updateScreenSize();this.loadNextBatchOfActorPrototypes()};gs.Game.loadFromTable=function(c){this.title=c.title;this.UID=c.UID;gs.Entity.loadFromTable.call(this,c);var e=c[gs.JXON._children];if(!e){return}var f=e.length;for(var b=0;b<f;++b){var d=e[b];var a=gs.Project.nodeTypeNameMap[d[gs.JXON._type]];switch(a){case"attributes":break;case"prototypes":this.prototypeCount=d[gs.JXON._children].length;break;case"scenes":this.scenes.loadFromTable(d[gs.JXON._children]);break;case"resolution":this.resolution=Number(d[gs.JXON._text]);this.updateScreenSize();break;case"resolutionIndependence":this.resolutionIndependence=Number(d[gs.JXON._text]);break;default:this[a]=d[gs.JXON._text]}}this.loadNextBatchOfActorPrototypes()};gs.Game.loadNextBatchOfActorPrototypes=function(){var d=this;var b=this.prototypeProgress;var c=this.prototypeCount;if(this.prototypeBatchSize>0){c=Math.min(this.prototypeCount,b+this.prototypeBatchSize)}for(;b<c;b++){var a=b+1;this.actorFactory.preloadActorPrototypeByIndex(a);this.prototypeProgress++}if(this.prototypeProgress<this.prototypeCount){gs._yield().then(function(){d.loadNextBatchOfActorPrototypes()})}else{this.promiseGameParsed.resolve()}};gs.Game.loadTableData=function(c){for(var a in this.attributes){var b=this.attributes[a];if(b._type==="table"){b.loadTableData(c)}}};gs.Game.fileExtension=function(){return("game")};gs.Game.initEngine=function(h){this.eventCenter=new gs.EventCenter();this.actorFactory=gs.ActorFactory.instance();this.isPlaying=false;var n=this.attributes.displaySize.width.getValue();var p=this.attributes.displaySize.height.getValue();var x=window.navigator.userAgent;var t=null;var c=gs.EngineContext.current.getRenderContext();var z=c.getRenderer();switch(z){case gs.RendererOption.WEBGL:t=gs.SGWebGLRenderer;break;case gs.RendererOption.CANVAS:t=gs.SGCanvasRenderer;break;default:if(gs.webgl.isSupported()){t=gs.SGWebGLRenderer}else{t=gs.SGCanvasRenderer}break}this.renderer=new t(h);var i=window;this.inputEventTarget=h.input;var m=h.input;if(gs.globalOptions.forceInputEventsOnCanvas){m=h.canvas}gs.ENABLE_COLOR_MULTIPLY=!(/Android.*?WebKit/).test(x);this.domElement=this.renderer.getRoot();this.sharedHandleManager=this.renderer.getHandleManager();var y=this;this.interceptKeyEvents=false;this.redetectInputCoordinates();var g=function(C){if(!y.interceptKeyEvents){return}y.frameProfiler.input.enter();C.preventDefault();var B=gs.mapKeyInput(C);y.eventCenter.postEvent("keyDown",null,B);y.frameProfiler.input.exit()};var f=function(C){if(!y.interceptKeyEvents){return}y.frameProfiler.input.enter();C.preventDefault();var B=gs.mapKeyInput(C);y.eventCenter.postEvent("keyUp",null,B);y.frameProfiler.input.exit()};i.addEventListener("keydown",g,false);i.addEventListener("keyup",f,false);window.addEventListener("scroll",function(B){y.redetectInputCoordinates()});var b=[0,0];var a=function(B){var G=B.clientX+y.documentScrollX-y.domElementX;var E=B.clientY+y.documentScrollY-y.domElementY;E=y.viewportPhysicalHeight-E;G*=n/y.viewportBufferWidth/y.viewportStretchX;E*=p/y.viewportBufferHeight/y.viewportStretchY;var F=y.attributes.displaySize.width.getValue();var C=y.attributes.displaySize.height.getValue();var D=y.getCurrentScene();if(D){F=D.attributes.camera.size.width.getValue();C=D.attributes.camera.size.height.getValue()}b[0]=G*F/n;b[1]=E*C/p;return b};var A=gs.array.provide();var k=gs.array.provide();var q=function(D,F){window.focus();if(D.preventDefault){D.preventDefault()}var E=a(D);var B=E[0];var G=E[1];var C=y.devices.touches.count.getValue();y.devices.touches.count.fastSetValue(C+1);y.eventCenter.postEvent("touchDown",null,F,B,G);if(F===1){y.eventCenter.postEvent("mouseDown",null,B,G)}};var v=function(E,G,D){if(E.preventDefault){E.preventDefault()}var F=a(E);var C=F[0];var H=F[1];var B=y.devices.mouse.button.getValue();if(D||B){y.eventCenter.postEvent("touchMoved",null,G,C,H)}if(G===1){y.eventCenter.postEvent("mouseMoved",null,C,H)}};var e=function(D,F){if(y.deferredOpenURL){window.open(y.deferredOpenURL);y.deferredOpenURL=null}if(D.preventDefault){D.preventDefault()}var E=a(D);var B=E[0];var G=E[1];var C=y.devices.touches.count.getValue();y.devices.touches.count.fastSetValue(C-1);y.eventCenter.postEvent("touchUp",null,F,B,G);if(F===1){y.eventCenter.postEvent("mouseUp",null,B,G)}};function r(E){if(E.preventDefault){E.preventDefault()}var G=E.changedTouches;if(!G){k[0]=E;E.identifier=E.pointerId;G=k}for(var C=0,D=G.length;C<D;C++){var I=G[C];var H=I.identifier;var B=A.indexOf(H);if(B===-1){B=0;while(A[B]!==undefined){B++}A[B]=H;var F=B+1;q(I,F)}else{gs.Log.debug("unexpected touchstart",H)}}}function j(E){if(E.preventDefault){E.preventDefault()}var G=E.changedTouches;if(!G){k[0]=E;E.identifier=E.pointerId;G=k}for(var C=0,D=G.length;C<D;C++){var I=G[C];var H=I.identifier;var B=A.indexOf(H);if(B===-1){v(I,1,false)}else{var F=B+1;v(I,F,true)}}}function u(E){if(E.preventDefault){E.preventDefault()}var G=E.changedTouches;if(!G){k[0]=E;E.identifier=E.pointerId;G=k}for(var C=0,D=G.length;C<D;C++){var I=G[C];var H=I.identifier;var B=A.indexOf(H);if(B===-1){gs.Log.debug("unexpected touch",H)}else{var F=B+1;e(I,F);A[B]=undefined}}}function d(E){if(E.preventDefault){E.preventDefault()}var G=E.changedTouches;if(!G){k[0]=E;E.identifier=E.pointerId;G=k}for(var C=0,D=G.length;C<D;C++){var I=G[C];var H=I.identifier;var B=A.indexOf(H);if(B===-1){gs.Log.debug("unexpected touch",H)}else{var F=B+1;e(I,F);A[B]=undefined}}}function w(E){if(E.preventDefault){E.preventDefault()}var G=E.changedTouches;if(!G){k[0]=E;E.identifier=E.pointerId;G=k}for(var C=0,D=G.length;C<D;C++){var I=G[C];var H=I.identifier;var B=A.indexOf(H);if(B===-1){gs.Log.debug("unexpected touch",H)}else{var F=B+1;e(I,F);A[B]=undefined}}}if(gs.globalOptions.forcePointerEvents){if(typeof MSPointerEvent!=="undefined"){m.addEventListener("MSPointerDown",r,false);m.addEventListener("MSPointerMove",j,false);m.addEventListener("MSPointerUp",u,false);m.addEventListener("MSPointerCancel",d,false);m.addEventListener("MSPointerLeave",w,false)}else{m.addEventListener("pointerdown",r,false);m.addEventListener("pointermove",j,false);m.addEventListener("pointerup",u,false);m.addEventListener("pointercancel",d,false);m.addEventListener("pointerleave",w,false)}}else{m.addEventListener("touchstart",r,false);m.addEventListener("touchmove",j,false);m.addEventListener("touchend",u,false);m.addEventListener("touchcancel",d,false);m.addEventListener("touchleave",w,false);m.addEventListener("mousedown",function l(B){q(B,1)},false);m.addEventListener("mousemove",function s(B){v(B,1,false)},false);m.addEventListener("mouseup",function o(B){e(B,1)},false)}};gs.Game.setLoadingFlag=function(a){var b=this.loadingFlag;this.loadingFlag=a;if(!b&&a){this.loaderProgress.beginTransition();gs.EngineContext.current.delegate.onLoadingBegin()}if(b&&!a){gs.EngineContext.current.delegate.onLoadingEnd();this.loaderProgress.endTransition();this.firstFrameAfterLoading=true}};gs.Game.deferOpenURL=function(a){this.deferredOpenURL=a};gs.Game.externalWriteGameAttribute=function(b,d){var a=gs.Reference.lookup(b);var c=a.resolveRelativeTo(this);c.setValue(d)};gs.Game.systemPause=function(){this.gameTimebase.pause();this.systemPaused=true;var a=this.getCurrentScene();if(a){a.pause(this.gameTimebase.currentTimeStamp)}gs.AudioManager.current.pauseAll()};gs.Game.systemResume=function(){this.gameTimebase.resume();gs.EngineContext.current.resetFrameTime();this.systemPaused=false;var a=this.getCurrentScene();if(a){a.resume(this.gameTimebase.currentTimeStamp)}gs.AudioManager.current.unpauseAll()};gs.Game.getRequiredImages=function(a,d){var c=null;if(d===gs.LoadStrategyOption.GAME){var b=this.project.getImages();c=b.toArray()}return c};gs.Game.getRequiredSounds=function(a,d){var c=null;if(d===gs.LoadStrategyOption.GAME){var b=this.project.getSounds();c=b.toArray()}return c};gs.Game.preloadAssetsForScene=function(c,f,d){var e=gs.AssetManager.current;e.beginPreloading();var b=this.getRequiredImages(c,f);var a=this.getRequiredSounds(c,f);if(d){b&&e.cleanupAndLoadImages(b,null);a&&e.cleanupAndLoadSounds(a,null)}else{b&&e.loadImages(b,null);a&&e.loadSounds(a,null)}};gs.Game.clearTouchState=function(){if(this.devices.touches.count.getValue()>0){this.devices.touches.count.fastSetValue(0);this.eventCenter.postEvent("mouseUp",null,0,0);this.eventCenter.postEvent("touchUp",null,1,0,0)}};gs.Game.getTableAttribute=function(a){var b=this.tableLookupCache[a];if(!b){var c=gs.tables.getKeypath(a);b=this.resolveKeypath(c);this.tableLookupCache[a]=b}return b};gs.Game.redetectInputCoordinates=function(){var a=this.inputEventTarget;this.documentScrollX=document.body.scrollLeft+document.documentElement.scrollLeft;this.documentScrollY=document.body.scrollTop+document.documentElement.scrollTop;var b=gs.dom.getElementPosition(a);this.domElementX=b[0];this.domElementY=b[1];this.viewportBufferWidth=a.clientWidth;this.viewportBufferHeight=a.clientHeight;this.viewportPhysicalWidth=a.clientWidth;this.viewportPhysicalHeight=a.clientHeight;this.viewportStretchX=this.viewportPhysicalWidth/this.viewportBufferWidth;this.viewportStretchY=this.viewportPhysicalHeight/this.viewportBufferHeight;this.inputEventTargetDetected=this.viewportPhysicalWidth&&this.viewportPhysicalHeight};gs.Scene=gs.Entity.subclass("Scene");gs.Scene.init=function(){gs.Entity.init.call(this);this.attributes.addStringMutableAttribute("name","New Scene");this.layers=gs.array.provide();var e=gs.Game.IPHONE_SCREEN_WIDTH;var c=gs.Game.IPHONE_SCREEN_HEIGHT;var a=gs.Game.instance;if(a){e=a.attributes.displaySize.width.getValue();c=a.attributes.displaySize.height.getValue()}this.attributes.addSizeMutableAttribute("size",e,c);this.attributes.addBooleanMutableAttribute("wrapX",false);this.attributes.addBooleanMutableAttribute("wrapY",false);this.attributes.addPointMutableAttribute("gravity",0,0);this.attributes.addColorMutableAttribute("color",0,0,0,1);this.attributes.addImmutableAttributeCollection("camera");var b=this.attributes.camera;b.addPointMutableAttribute("origin",0,0);b.addSizeMutableAttribute("size",e,c);b.addSizeMutableAttribute("trackingArea",e-80,c-80);b.addRealMutableAttribute("rotation",0);this.attributes.addImmutableAttributeCollection("autorotate");var d=this.attributes.autorotate;d.addBooleanMutableAttribute("landscapeLeft",true);d.addBooleanMutableAttribute("landscapeRight",false);d.addBooleanMutableAttribute("portrait",false);d.addBooleanMutableAttribute("portraitUpsideDown",false);if(!this._actorsMarkedForDestruction){this._actorsMarkedForDestruction=gs.Map.provide()}return this};gs.Scene.startPhysics=function(){this._world=new gs.physicsLib.World(-this.attributes.gravity.x.getValue(),-this.attributes.gravity.y.getValue(),true);this._collisionController=gs.CollisionController.provide().init()};gs.Scene.observeValueChange=function(g,h){if(this._world&&(g===this.attributes.gravity.x||g===this.attributes.gravity.y)){this._world.setGravity(-this.attributes.gravity.x.getValue(),-this.attributes.gravity.y.getValue());for(var d=0,f=this.layers.length;d<f;d++){var c=this.layers[d];for(var b=0,a=c.actors.length;b<a;b++){var e=c.actors[b];e.aspects.motion._body.setAwake(true)}}}};gs.physicsFixedStepDT=1/60;gs.physicsMinStepDT=0.04;gs.physicsMaxStepCount=25;gs.physicsVelocityIterations=10;gs.physicsPositionIterations=10;gs.Scene.evaluatePhysics=function(a){this.game().frameProfiler.physics.enter();var c=0;while(a>0&&c<gs.physicsMaxStepCount){var b=Math.min(a,gs.physicsFixedStepDT);a-=b;if(a<gs.physicsMinStepDT){b+=a;a=0}if(gs.debug.physics){this._world.step(b,gs.physicsVelocityIterations,gs.physicsPositionIterations)}c++}this._world.clearForces();this.game().frameProfiler.physics.exit()};gs.Scene.preloadAssets=function(f,h){var g=gs.Map.provide();var b=gs.Map.provide();this.getRequiredAssets(g,b,f);var d=gs.set.setToArray(g);var c=gs.set.setToArray(b);var a=true;if(gs.Game.current.currentSceneStack.length>1){a=false}if(f===gs.LoadStrategyOption.GAME||f===gs.LoadStrategyOption.LATENCY){a=false}var e=gs.AssetManager.current;if(a){e.cleanupAndLoadImages(d,h);e.cleanupAndLoadSounds(c,h)}else{e.loadImages(d,h);e.loadSounds(c,h)}gs.Map.recycle(g);gs.Map.recycle(b);gs.array.recycle(d);gs.array.recycle(c)};gs.Scene.prefetchAssets=function(e){var f=gs.Map.provide();var c=gs.Map.provide();this.getRequiredAssets(f,c,e);var b=gs.set.setToArray(f);var a=gs.set.setToArray(c);var d=gs.AssetManager.current;d.fetchSounds(a);d.fetchImages(b);gs.Map.recycle(f);gs.Map.recycle(c);gs.array.recycle(b);gs.array.recycle(a)};gs.Scene.start=function(g){this.frameCount=0;this.firstFrame=true;this.hasNotifiedRenderedOnce=false;var d=this.game();d.setLoadingFlag(true);var b=gs.Timebase.provide().initWithTime(g);b.convertTimeStamp(g);this.sceneTime=b.getTimeStamp();var f=this;var e=d.loaderProgress;var c=0;var a=function(){if(++c===2){e.setProgress(2,2);e.endLoading();f.assetsLoadedAndStart();gs.Game.profiler.sceneLoadProfiler.assets.exit();if(h===gs.LoadStrategyOption.LATENCY){f.prefetchAssets(gs.LoadStrategyOption.STRICT);var i=d.scenes.indexByKey(f._objectKey);d.scenes.fetchSceneByIndex(i+1);f.prefetchAssets(gs.LoadStrategyOption.SCENE)}}};e.beginLoading();gs.Game.profiler.sceneLoadProfiler.assets.enter();var h=gs.EngineContext.current.options.loadStrategy;this.preloadAssets(h,a)};gs.Scene.assetsLoadedAndStart=function(){var a=this.game();a.sceneLoadProfiler.time.exit();var d=this.attributes.name.getValue();gs.platform.AnalyticsService.instance().endSceneChange(d);a.eventCenter.postEvent("sceneWillStart",null,this);this.attributes.gravity.x.addObserver(this);this.attributes.gravity.y.addObserver(this);this.startPhysics();gs.devices.start(a);var e=gs.Game.instance.gameTimebase;if(e!==null){gs.EngineContext.current.resetFrameTime();this.timebase=gs.Timebase.provide().initWithTime(e.currentTimeStamp);this.sceneTime=this.timebase.getTimeStamp();this.attributes.time.fastSetValue(this.sceneTime.time)}gs.Entity.start.call(this,this.sceneTime);gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.startAspects,this.sceneTime);gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.startBehaviors,this.sceneTime);a.setLoadingFlag(false);var c=this._objectKey;var b=this.attributes.name.getValue();gs.EngineContext.current.delegate.onCurrentSceneChanged(c,b);a.primePoolsPerScene()};gs.Scene.stop=function(g){var k=gs.Game.current;k.eventCenter.postEvent("sceneWillEnd",null,this);gs.devices.stop(k);this.timebase.convertTimeStamp(g);gs.Entity.stop.call(this,this.sceneTime);gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.stop,this.sceneTime);var a=gs.ActorFactory.current;var e=this.layers;for(var f=0,l=e.length;f<l;f++){var c=e[f].actors;for(var d=0,h=c.length;d<h;d++){var b=c[0];this.removeActor(b);b.hideActor();a.recycleActorInstance(b)}}a.onSceneStop(this._objectKey);gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.recycleThis,this.sceneTime);this.sceneTime=null;gs.Timebase.recycle(this.timebase);this.timebase=null;this._collisionController=null;this._world.recycleThis();this._world=null;this.attributes.gravity.x.removeObserver(this);this.attributes.gravity.y.removeObserver(this)};gs.Scene.pause=function(b){var a=this.game();a.eventCenter.postEvent("sceneWillPause",null,this);this.timebase.pauseRelativeToTimestamp(b)};gs.Scene.resume=function(c){var a=this.game();a.eventCenter.postEvent("sceneWillResume",null,this);gs.devices.start(a);a.eventCenter.postEvent("mouseUp",null);a.eventCenter.postEvent("touchCancel",null);this.timebase.resumeRelativeToTimestamp(c);var d=this._objectKey;var b=this.attributes.name.getValue();gs.EngineContext.current.delegate.onCurrentSceneChanged(d,b)};gs.Scene.hasStarted=function(){return(!!this.timebase)};gs.Scene.isPaused=function(){return this.timebase&&this.timebase.paused};gs.Scene.evaluate=function(e){if(!this.hasStarted()||this.isPaused()){return}if(this.frameCount===2&&!this.hasNotifiedRenderedOnce){this.notifyRenderedOnce();this.hasNotifiedRenderedOnce=true}var a=this.game();this.timebase.convertTimeStamp(e);this.attributes.time.fastSetValue(this.sceneTime.time);a.frameProfiler.simulate.enter();a.entityCounter.layers.set(this.layers.length);for(var b in this._actorsMarkedForDestruction){var c=this._actorsMarkedForDestruction[b];delete this._actorsMarkedForDestruction[b];c.stop(this.sceneTime);this.removeActor(c);c.hideActor();gs.ActorFactory.current.recycleActorInstance(c)}gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.evaluate,this.sceneTime);a.frameProfiler.simulate.exit();var d=e.dt;if(this.frameCount<2){d=gs.physicsFixedStepDT}this.evaluatePhysics(d);this.frameCount++;this.firstFrame=false};gs.Scene.addActor=function(c,b,a){b.addActor(c,a);if(this._visible){b.makeActorVisible(c)}return true};gs.Scene.markActorForDestruction=function(a){this._actorsMarkedForDestruction[a._objectKey]=a};gs.Scene.removeActor=function(a){a.layer.removeActor(a)};gs.Scene.frame=function(){return{x:0,y:0,width:this.attributes.size.width.getValue(),height:this.attributes.size.height.getValue()}};gs.Scene.isInBounds=function(a,c){var b=gs.physicsLib.SIMULATION_BORDER;return(a>-b&&c>-b&&a<this.attributes.size.width.getValue()+b&&c<this.attributes.size.height.getValue()+b)};gs.Scene.wrappingEnabled=function(){return(this.attributes.wrapX.getValue()||this.attributes.wrapY.getValue())};gs.Scene.convertViewToScene=function(a){var d=this.attributes.camera.origin;var c=d.x.getValue();var b=d.y.getValue();a[0]+=c;a[1]+=b;return a};gs.Scene.supportedOrientations=function(){var b=this.attributes.autorotate;var a=[b.landscapeLeft.getValue(),b.landscapeRight.getValue(),b.portrait.getValue(),b.portraitUpsideDown.getValue()];return a};gs.Scene.animateCameraToNewOrientation=function(a,c,b){};gs.Scene.getRequiredAssets=function(g,i,d){var b=gs.ActorFactory.current;var a=gs.Map.provide();this.getActorInstances(a);for(var k in a){a[k].getRequiredAssets(g,i,d,false)}var h=gs.Map.provide();this.getRequiredActors(h,true);for(var f in h){var e=b.getActorPrototype(f);e.getRequiredAssets(g,i,d,true)}var j=/\.png$/;for(var c in g){if(j.test(c)){delete g[c];c=c.substr(0,c.length-4);g[c]=true}}gs.Map.recycle(a);gs.Map.recycle(h)};gs.Scene.getRequiredActors=function(e,b){var d=this.layers;for(var a=0,c=d.length;a<c;a++){d[a].getRequiredActors(e,b)}};gs.Scene.getActorInstances=function(d){var c=this.layers;for(var a=0,b=c.length;a<b;a++){c[a].getActorInstances(d)}};gs.Scene.loadFromLite=function(f,a){gs.Entity.loadFromLite.call(this,f,a);var g=f.layers;if(g){gs.ObjectListWithKeys.prototype.loadFromLite.call(this.layers,gs.Parser.parseLayer,g,a);for(var d=0;d<this.layers.length;d++){var c=this.layers[d];c.scene=this;for(var b=0;b<c.actors.length;b++){var e=c.actors[b];e.scene=this}}}};gs.Scene.loadFromTable=function(c){gs.Entity.loadFromTable.call(this,c);var e=c[gs.JXON._children];if(!e){return}var f=e.length;for(var b=0;b<f;++b){var d=e[b];var a=gs.Project.nodeTypeNameMap[d[gs.JXON._type]];switch(a){case"layers":this.layers.loadFromTable(d[gs.JXON._children]);break}}};gs.Scene.fileExtension=function(){return"scene"};gs.Scene.notifyRenderedOnce=function(){var a=this.getObjectKey();gs.Project.instance.dispatchAction("scene","renderOnce",a)};gs.PathResolver=function(a){this.allowCaching=true;this.prefix=a;if(/[/]$/.test(this.prefix)===false){this.prefix+="/"}return this};gs.PathResolver.prototype={getPath:function(a){var b=this.prefix+a;if(!this.allowCaching){b+="?"+Math.random().toString().substring(2)}return encodeURI(b)},getDataPath:function(a){return this.getPath(a+".json")},getObjectPath:function(){return this.getDataPath("object")},getAssetsPath:function(){return this.getDataPath("assets")},getScenePathByIndex:function(b){var a=b.toString();return this.getScenePathByName(a)},getScenePathByOffset:function(a){return this.getScenePathByIndex(a+1)},getScenePathByName:function(a){return this.getDataPath("scenes/"+a)},getSceneScreenshotPathByID:function(b){var a=b+".png";return this.getPath("screenshots/"+a)},getImagePath:function(a){return this.getPath("images/"+a)},getSoundPath:function(a){return this.getPath("sounds/"+a)},getTablePath:function(a){return this.getDataPath("tables/"+a)}};gs.Parser={compoundAttributeClassMap:{compound:gs.CompoundAttribute,attributes:gs.CompoundAttribute,point:gs.PointAttribute,size:gs.SizeAttribute,rect:gs.RectAttribute,color:gs.ColorAttribute,table:gs.TableAttribute,pair:gs.PairAttribute,tablecolumnassignment:gs.PairAttribute,array:gs.ArrayAttribute},behaviorClassMap:{AccelerateBehavior:gs.AccelerateBehavior,AccelerateTowardBehavior:gs.AccelerateTowardBehavior,AddRemoveRowAction:gs.AddRemoveRowAction,AnimateBehavior:gs.AnimateBehavior,CallExternalFunctionAction:gs.CallExternalFunctionAction,ChangeAttributeAction:gs.ChangeAttributeAction,ChangeImageAction:gs.ChangeImageAction,ChangeRowAction:gs.ChangeRowAction,ChangeSceneAction:gs.ChangeSceneAction,ChangeTableValueAction:gs.ChangeTableValueAction,ChangeVelocityAction:gs.ChangeVelocityAction,CollideBehavior:gs.CollideBehavior,CompletingBehavior:gs.CompletingBehavior,CompoundBehavior:gs.CompoundBehavior,ConstrainAttributeBehavior:gs.ConstrainAttributeBehavior,ControlCameraBehavior:gs.ControlCameraBehavior,CopyTableAction:gs.CopyTableAction,DestroyAction:gs.DestroyAction,DisplayTextBehavior:gs.DisplayTextBehavior,EndGameAction:gs.EndGameAction,GrowShrinkBehavior:gs.GrowShrinkBehavior,InterpolateBehavior:gs.InterpolateBehavior,InsertRowAction:gs.InsertRowAction,KeyboardInputAction:gs.KeyboardInputAction,LaunchServiceAction:gs.LaunchServiceAction,LoadAttributeAction:gs.LoadAttributeAction,LogDebuggingStatementAction:gs.LogDebuggingStatementAction,LoopBehavior:gs.LoopBehavior,LoopTableBehavior:gs.LoopTableBehavior,MoveBehavior:gs.MoveBehavior,MoveToBehavior:gs.MoveToBehavior,NoteBehavior:gs.NoteBehavior,OpenURLAction:gs.OpenURLAction,ParticlesBehavior:gs.ParticlesBehavior,PauseGameAction:gs.PauseGameAction,PauseMusicAction:gs.PauseMusicAction,PlayMusicAction:gs.PlayMusicAction,PlaySoundAction:gs.PlaySoundAction,PostEventAction:gs.PostEventAction,PurchaseItemAction:gs.PurchaseItemAction,ReplicateBehavior:gs.ReplicateBehavior,ResetGameAction:gs.ResetGameAction,ResetSceneAction:gs.ResetSceneAction,RotateBehavior:gs.RotateBehavior,RotateToAngleBehavior:gs.RotateToAngleBehavior,RotateToPositionBehavior:gs.RotateToPositionBehavior,RuleBehavior:gs.RuleBehavior,SaveAttributeAction:gs.SaveAttributeAction,SaveTableAction:gs.SaveTableAction,ShowAdAction:gs.ShowAdAction,ShowBannerBehavior:gs.ShowBannerBehavior,ShowMoreGamesAction:gs.ShowMoreGamesAction,SpawnAction:gs.SpawnAction,StopMusicAction:gs.StopMusicAction,TimerBehavior:gs.TimerBehavior,UnpauseGameAction:gs.UnpauseGameAction,ShowiAdBehavior:gs.ShowiAdBehavior,GameCenterLoginAction:gs.GameCenterLoginAction,GameCenterPostScoreAction:gs.GameCenterPostScoreAction,GameCenterShowLeaderboardAction:gs.GameCenterShowLeaderboardAction,GameCenterShowAchievementsAction:gs.GameCenterShowAchievementsAction,GameCenterResetAchievementsAction:gs.GameCenterResetAchievementsAction,GameCenterUpdateAchievement:gs.GameCenterUpdateAchievement,InAppPurchaseItemAction:gs.InAppPurchaseItemAction,InAppPurchaseRestoreItem:gs.InAppPurchaseRestoreItem,TweetSheetAction:gs.TweetSheetAction},predicateClassMap:{"auto-rotation":gs.AutorotatePredicate,"boolean":gs.BooleanPredicate,collision:gs.CollisionPredicate,enumeration:gs.EnumerationPredicate,hibernate:gs.HibernatePredicate,key:gs.KeyPredicate,mouse:gs.MousePredicate,mousePosition:gs.MousePositionPredicate,number:gs.NumberPredicate,purchase:gs.PurchasePredicate,string:gs.StringPredicate,touch:gs.TouchPredicate},parseGame:function(b){var a=gs.Game.provide().init();a.loadFromLite(b);return a},parseActor:function(a){var b=a.prototype;return gs.ActorFactory.current.provideActorInstance(b,a)},parseLayer:function(b){var a=gs.Layer.provide().init();a.loadFromLite(b);return a},parseScene:function(a){var b=gs.Scene.provide().init();b.loadFromLite(a);return b},parseArray:function(b){var a=gs.PrototypicalArray.provide().init();a.loadFromLite(b);return a},parseBehaviorList:function(b,a){var c=gs.BehaviorList.provide().init();c.loadFromLite(b,a);return c},parseBehaviorClass:function(b){var c=(b.enabled===false)||(b.enabled==="false");var e=b["class"];var a=gs.Parser.behaviorClassMap[e];if(c){a=gs.NullBehavior}else{if(!a){gs.Log.warn("Behavior not implemented:",e);gs.Parser.behaviorClassMap[e]=gs.NullBehavior;a=gs.NullBehavior}}var d=a.provide().init();return d},parseBehavior:function(b,a){var c=gs.Parser.parseBehaviorClass(b);c.loadFromLite(b,a);return c},parseCondition:function(b,a){var c=gs.Condition.provide().init();c.loadFromLite(b,a);return c},parseKeyValuePair:function(b,a){var c=gs.KeyValuePair.provide().init();c.loadFromLite(b,a);return c},parsePredicate:function(e,b){var c=e.type;var d=gs.Parser.predicateClassMap[c];if(!d){gs.Log.info("Predicate not implemented:",c);gs.Parser.predicateClassMap[c]=gs.NullPredicate;d=gs.NullPredicate}var a=d.provide().init();a.loadFromLite(e,b);return a},parseExpression:function(a){var b=gs.Expression.provide().init();b.loadFromLite(a);return b},parseReference:function(a){return gs.Reference.loadFromLiteStatic(a)},parseAttributeValue:function(c,a){var b=c[a];if(typeof b==="object"){return b["$"]}return b},parse:function(b,a){if(!b){return null}switch(b[gs.JXON._type]){case"game":return this.parseGame(b);case"actor":return this.parseActor(b);case"layer":return this.parseLayer(b);case"scene":return this.parseScene(b);case"actors":case"scenes":return this.parseArray(b);case"behaviors":return this.parseBehaviorList(b,a);case"behavior":return this.parseBehavior(b,a);case"condition":return this.parseCondition(b,a);case"keyvaluepair":return this.parseKeyValuePair(b,a);case"predicate":case"subjectPredicate":return this.parsePredicate(b,a);case"attributes":case"attribute":case"boolean":case"text":case"image":case"sound":case"music":case"real":case"integer":case"index":case"angle":case"enumeration":case"table":case"pair":case"array":case"tablecolumnassignment":return b;case"expression":return this.parseExpression(b);case"reference":return this.parseReference(b);default:gs.Log.warn("Unsupported PGF tag:",b[gs.JXON._type]);return null}}};gs.DefaultConstraints={"boolean":gs.BooleanConstraint.Default,text:gs.TextConstraint.Default,real:gs.NumberConstraint.Real,integer:gs.NumberConstraint.Integer,index:gs.NumberConstraint.Index,angle:gs.NumberConstraint.Angle,enumeration:gs.NumberConstraint.Index,image:gs.TextConstraint.Default,sound:gs.TextConstraint.Default,music:gs.TextConstraint.Default};gs.ImageResource=function(){this.id=null;this.ready=false;this.failed=false;this.src=null;this.imageElement=null;this.width=0;this.height=0;this.gl=null;this.texture=null};gs.ImageResource.createFromCanvas=function(a){var b=new gs.ImageResource();b.imageElement=a;b.width=a.width;b.height=a.height;b.ready=true;return b};gs.ImageResource.prototype={createTexture:function(a){this.gl=a;this.texture=gs.webgl.createTextureFromImage(a,this.imageElement)},deleteTexture:function(){this.gl.deleteTexture(this.texture);this.texture=null;this.gl=null},releaseImageElement:function(){var a=this.imageElement;this.imageElement=null;return a}};gs.AssetManager=function(a){this._project=a;this.imageResourceMap={};this.imageResourceMapPow2={};this.imageCount=0;this.imageRequestQueue=[];this.imageElementPool=[];this.imageElementPoolSize=gs.globalOptions.imageRequestPoolSize;this.useImageQueue=false;this.useTextures=false;this.gl=null;this.isBatchLoading=false;this.isPreloading=false;this.preloadRemaining=0;this.preloadCompleteCallback=null;this.renderer=null;this.resourcesWaitingForRenderer=gs.array.provide();this.transparent1x1=null;this.white1x1=null;gs.AssetManager.instance=this;gs.AssetManager.current=this;while(this.imageElementPool.length<this.imageElementPoolSize){this.imageElementPool.push(this.createImageElement())}};gs.AssetManager.transparent1x1PNG="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAFElEQVR4XgXAAQ0AAABAMP1L30IDCPwC/o5WcS4AAAAASUVORK5CYII=";gs.AssetManager.white1x1GIF="data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=";gs.AssetManager.onImageLoad=function(){var a=this.resource;gs.AssetManager.current.onImageLoad(a)};gs.AssetManager.onImageError=function(){var a=this.resource;gs.AssetManager.current.onImageError(a)};gs.AssetManager.prototype={setRenderer:function(a){this.renderer=a;if(a.gl){this.gl=a.gl;this.useTextures=true;this.useImageQueue=true}this.transparent1x1=this.createImageResource(null,gs.AssetManager.transparent1x1PNG);this.white1x1=this.createImageResource(null,gs.AssetManager.white1x1GIF);this.updateImageQueue()},onImageLoad:function(a){var b=a.imageElement;a.width=b.naturalWidth;a.height=b.naturalHeight;a.ready=true;if(this.useTextures){if(!this.renderer){this.resourcesWaitingForRenderer.push(a)}else{if(this.renderer.isImageTooLarge(a)){gs.Log.error("Image too large for texture:",a.id,a.width,a.height,this.renderer.maxTextureSize)}else{a.createTexture(this.gl)}this.imageElementPool.push(b);a.releaseImageElement();b.resource=null}}this.updateImageQueue();if(this.isPreloading){this.preloadRemaining--;this.checkPreloadComplete()}},onImageError:function(a){gs.Log.error("Image load failed:",a.id);var b=a.imageElement;this.imageElementPool.push(b);a.releaseImageElement();b.resource=null;this.convertToError(a);this.updateImageQueue();if(this.isPreloading){this.preloadRemaining--;this.checkPreloadComplete()}},getImageNames:function(){var a=[];for(var b in this.imageResourceMap){if(this.imageResourceMap.hasOwnProperty(b)){a.push(b)}}return a},checkPreloadComplete:function(){if(this.preloadRemaining<=0){if(this.preloadCompleteCallback){this.preloadCompleteCallback.call(null);this.preloadCompleteCallback=null}this.isPreloading=false}},updateImageQueue:function(){while(this.imageRequestQueue.length>0&&this.imageElementPool.length>0){var a=this.imageRequestQueue.shift();var b=this.imageElementPool.shift();a.imageElement=b;b.resource=a;if(b.srcRaw===a.src){this.onImageLoad(a)}else{b.srcRaw=a.src;b.src=a.src}}},createImageResource:function(c,b){var a=new gs.ImageResource();a.id=c;a.gl=this.gl;if(b){a.src=b;if(this.isPreloading){this.preloadRemaining++}if(this.useImageQueue){if(this.isBatchLoading){this.imageRequestQueue.push(a)}else{this.imageRequestQueue.unshift(a)}this.updateImageQueue()}else{a.imageElement=this.createImageElement(b);a.imageElement.resource=a}}return a},convertToError:function(b){var c=b.id;for(var a in this.transparent1x1){b[a]=this.transparent1x1[a]}b.id=c;b.failed=true},createImageElement:function(b){var a=gs.dom.createImage(b);a.addEventListener("load",gs.AssetManager.onImageLoad,false);a.addEventListener("error",gs.AssetManager.onImageError,false);return a},eraseImage:function(a){var b=this.imageResourceMap[a];if(this.useTextures&&!b.failed){b.deleteTexture()}delete this.imageResourceMap[a];this.imageCount--},pathForImage:function(a){return this._project.pathForImage(a)},loadImageForID:function(c){if(this.imageResourceMap[c]){return}var b=this.pathForImage(c);var a;if(b){a=this.createImageResource(c,b)}else{a=this.createImageResource(c,null);this.convertToError(a);gs.Log.strict("Image not in manifest:",c)}this.imageResourceMap[c]=a;this.imageCount++},imageForName:function(a){this.loadImageForID(a);return this.imageResourceMap[a]},imageForNamePow2:function(a){var b=this.imageResourceMapPow2[a];if(!b&&this.gl){b=new gs.ImageResource();b.id=a;b.gl=this.gl;var c=this.pathForImage(a);b.imageElement=gs.dom.createImage(c);b.imageElement.addEventListener("load",function(){var e=1;var d=1;while(e<b.imageElement.naturalWidth){e*=2}while(d<b.imageElement.naturalHeight){d*=2}b.texture=gs.webgl.createTextureFromImageSize(b.gl,b.imageElement,e,d);b.releaseImageElement();b.width=e;b.height=d;b.ready=true},false);this.imageResourceMapPow2[a]=b}return b},cleanupUnusedImages:function(a){for(var b in this.imageResourceMap){if(this.imageResourceMap.hasOwnProperty(b)){if(a.indexOf(b)===-1){this.eraseImage(b)}}}},beginPreloading:function(){this.isPreloading=true;this.preloadRemaining=0},loadImages:function(a,c){this.isBatchLoading=true;if(c){this.preloadCompleteCallback=c}this.fetchImages(a);gs.Game.profiler.sceneLoadProfiler.images.set(a.length);this.isBatchLoading=false;this.updateImageQueue();var b=this;gs._yield(function(){b.checkPreloadComplete()})},fetchImages:function(a){for(var b=0;b<a.length;b++){var c=a[b];var d=this.imageForName(c)}},cleanupAndLoadImages:function(a,b){this.cleanupUnusedImages(a);this.loadImages(a,b)},loadSounds:function(a,b){gs.AudioManager.current.loadAssets(a,b);b&&b.call(null)},fetchSounds:function(a){gs.AudioManager.current.loadAssets(a)},cleanupUnusedSounds:function(a){},cleanupAndLoadSounds:function(a,b){this.cleanupUnusedSounds(a);this.loadSounds(a,b)},getImageCount:function(){return this.imageCount}};gs.AssetList=function AssetList(){this.map={}};gs.AssetList.neuw=function(){return new gs.AssetList()};gs.AssetList.prototype.add=function(a){this.map[a.name]=a};gs.AssetList.prototype.indexOfAssetWithName=function(a){if(!this.map[a]){return -1}return 1};gs.AssetList.prototype.assetForName=function(a){return this.map[a]};gs.AssetList.prototype.removeAssetWithName=function(a){delete this.map[a]};gs.AssetList.prototype.toArray=function(){return Object.keys(this.map)};gs.Asset={};gs.Asset.typeForFileExtension=function(b){if(typeof b!=="string"||b.length===0){return null}var a=b.toLowerCase();if(/^(png|jpg|jpeg)$/.test(a)){return"image"}if(/^(ogg|m4a|wav|aac|caf|mp4)$/.test(a)){return"sound"}return null};gs.Asset.newAsset=function(d,c,e){var b=[{filename:d,size:e}];var a=gs.Asset.typeForFileExtension(d.pathExtension());if(a==="image"){return gs.ImageAsset.create().initWithName(c,b)}else{if(a==="sound"){return gs.SoundAsset.create().initWithName(c,b)}else{if(a==="music"){return gs.SoundAsset.create().initWithName(c,b)}}}return null};gs.Asset.init=function(){this.representations=gs.array.provide();return this};gs.Asset.initWithName=function(a,b){this.name=a;this.representations=b||[];return this};gs.Asset.getRepresentations=function(){return this.representations};gs.Asset.addRepresentation=function(a,c){var b=a.pathExtension();if(!this.representations[b]){var d={filename:a,size:c};this.representations.push(d);this.representations[b]=d}};gs.Asset.representationForType=function(a){return this.representations[a]};gs.Asset.bestFileRepresentation=function(){if(this.representations.length){return this.representations[0]}else{return null}};gs.Asset.loadFromLite=function(f,a){this.name=f.name;var e=f.files;var d,b;if(Array.isArray(e)){for(var c=0;c<e.length;c++){d=e[c];b=this.ensureReasonableFilename(d.name);if(b){this.addRepresentation(b,d.size)}}}else{if(e){d=e;b=this.ensureReasonableFilename(d.name);if(b){this.addRepresentation(b,d.size)}}}this.validateName(true)};gs.Asset.loadFromTable=function(e){this.name=e.name;var g=e[gs.JXON._children];if(!g){this.addRepresentation(this.name,5000);return}var f=g.length;for(var d=0;d<f;++d){var c=g[d];var a=this.ensureReasonableFilename(c.name);var b=c.size;if(a){this.addRepresentation(a,b)}}this.validateName(true)};gs.Asset.ensureReasonableFilename=function(b){if(!b){return null}var a=this.getType();if(gs.Asset.typeForFileExtension(b.pathExtension())!==a){if(a==="image"){b=b+".png"}else{if(a==="sound"){b=b+".m4a"}}}return b};gs.Asset.validateName=function(a){if((!this.name)&&a){var c=this.bestFileRepresentation();if(c&&c.filename){if(gs.Asset.typeForFileExtension(c.filename.pathExtension())===this.getType()){var b=c.filename.split(".");this.name=b[b.length-2]}else{this.name=this.filename}}}return(this.name!=null)};gs.ImageAsset=function(){};gs.ImageAsset.prototype=Object.create(gs.Asset);gs.ImageAsset.neuw=function(){var a=new gs.ImageAsset();a.init();return a};gs.ImageAsset.prototype.getType=function(){return"image"};gs.ImageAsset.prototype.bestFileRepresentation=function(){if(this.representations.jpg){return this.representations.jpg}if(this.representations.png){return this.representations.png}return gs.Asset.bestFileRepresentation.call(this)};gs.SoundAsset=function(){};gs.SoundAsset.prototype=Object.create(gs.Asset);gs.SoundAsset.neuw=function(){var a=new gs.SoundAsset();a.init();return a};gs.SoundAsset.prototype.getType=function(){return"sound"};gs.SoundAsset.prototype.bestFileRepresentation=function(){var c=["m4a","ogg","wav"];var b,d;for(b=0;b<c.length;b++){d=c[b];if(d in this.representations){if(gs.html5.Audio.canPlayExtension(d)){return this.representations[d]}}}for(b=0;b<c.length;b++){d=c[b];if(gs.html5.Audio.canPlayExtension(d)){var a=this.name+"."+d;return{filename:a,size:1}}}return null};gs.Project=function(){gs.Project.instance=this;gs.Project.current=this;var n=[];var b=gs.AssetList.neuw();var h=gs.AssetList.neuw();var d={beginTransition:function(){},endTransition:function(){},beginLoading:function(){},endLoading:function(){},tick:function(){},setProgress:function(o,p){},onError:function(o){}};var a=null;var i=this;this._readyToPlay=false;var g=false;var l=new gs.AssetManager(this);this._displayAnchor=null;var m=gs.EngineContext.current.options;this._changeSceneQueued=null;this.gameLoadProfiler=new gs.LoadProfiler();this.gameLoop=new gs.GameLoop(m.targetRate);this.virtualFileCache=new gs.file.VirtualFileCache();switch(m.format){case gs.file.Format.JSON:this.virtualFileCache.setFormats([gs.file.Format.JSON,gs.file.Format.XML,gs.file.Format.JSONP]);break;case gs.file.Format.JSONP:this.virtualFileCache.setFormats([gs.file.Format.JSONP,gs.file.Format.JSON,gs.file.Format.XML]);break;case gs.file.Format.XML:this.virtualFileCache.setFormats([gs.file.Format.XML,gs.file.Format.JSON,gs.file.Format.JSONP]);break}this.promiseGameReady=new gs.Promise();var e=1;this.validatePath=function(s){var q=window.location.protocol;var t=window.location.hostname;var p=q+"//"+window.location.host;if(q==="file:"){this.allDownloadsSynchronous=true;return true}if(q==="chrome-extension:"){return true}if(q==="app:"){return true}if(q==="ms-appx:"){this.allDownloadsSynchronous=false;return true}if(q==="http:"||q==="https:"){if(t==="localhost"||t==="chrome.gamesalad.com"){this.allDownloadsSynchronous=false;return true}var r=/^192\.168\.\d+\.\d+$/;if(r.test(t)){this.allDownloadsSynchronous=false;return true}var o=/\b(gamesalad|icecapgames)\.com\b/;if(o.test(p)){this.allDownloadsSynchronous=false;return true}}window.location="http://gamesalad.com/";return false};function f(s){var u=s.getData();d.setProgress(1,2);i.gameLoadProfiler.load.exit();var r=[];r.push(i.virtualFileCache.fetchAllActorPrototypes());var q=u.attributes;var o=gs.CompoundAttribute.provide().init();o.addReservedCompoundAttribute("displaySize","size",{width:gs.Game.IPHONE_SCREEN_WIDTH,height:gs.Game.IPHONE_SCREEN_HEIGHT});if(q){o.loadFromLite(q,true)}var p=o.displaySize.width.getValue();var t=o.displaySize.height.getValue();gs.EngineContext.current.delegate.onGameDimensionsKnown(p,t);gs._yield().then(function(){gs.Promise.all(r,function v(){i.gameLoadProfiler.parse.enter();var w=gs.Parser.parseGame(u);w.promiseGameParsed.then(function x(){w.loadTableData(i.virtualFileCache);i.gameLoadProfiler.parse.exit();i.gameLoadProfiler.time.exit();i.game=w;w.project=i;w.sharedAssetManager=l;w.loaderProgress=d;w.setLoadingFlag(true);i.virtualFileCache.loadAssetsManifest().then(function y(z){j(z);i.loadSceneByIndex(e).then(c);i.virtualFileCache.deleteGame()})})})})}function c(){var o=i.game;o.initEngine(a);o.reset();i._readyToPlay=true;i.gameLoop.setCallback(function(){gs.EngineContext.current.update()});i.gameLoop.setDOMElement(o.renderer.getRoot());i.promiseGameReady.resolve();if(g){i.play()}}this.load=function(o,q){this.virtualFileCache.setPrefix(o);this.pathResolver=new gs.PathResolver(o);a=q;this._displayAnchor=q;if(!this.validatePath(o)){return null}this.gameLoadProfiler.time.enter();this.gameLoadProfiler.load.enter();this.virtualFileCache.loadGame().then(f,function p(r){gs.Log.error(r);gs.Log.fatal("Game data not found",o)});this.virtualFileCache.fetchAssetsManifest();this.virtualFileCache.fetchSceneByIndex(e);return this};this.getObjectJSON=function(o){this.virtualFileCache.loadGame().then(function(p){var q=p.getData();o&&o.call(null,q)})};function k(r){var s=new gs.Promise();gs.Game.profiler.sceneLoadProfiler.load.exit();var q=i.game;var p=r.getData();var u=p.id;var t=q.scenes.indexAndKey(u);t++;var o=i.virtualFileCache.isSceneRetainedByIndex(t);q.scenes.inflateScene(u,p,q).then(function(){if(!o){gs.array.recycleJXONArraysAndMaps(p)}s.resolve()});d.endLoading();return s}this.loadScene=function(p){var o=p+1;this.loadSceneByIndex(o)};this.loadSceneByIndex=function(o){var p=new gs.Promise();gs.Game.profiler.sceneLoadProfiler.load.enter();this.virtualFileCache.loadSceneByIndex(o).then(function(q){k(q).then(function(){p.resolve()})});return p};function j(s){var r,t;var q=s.getData();var p=q.images;var o=q.sounds;if(p){if(Array.isArray(p)){for(r=0;r<p.length;r++){t=gs.ImageAsset.neuw();t.loadFromLite(p[r]);b.add(t)}}else{t=gs.ImageAsset.neuw();t.loadFromLite(p);b.add(t)}}if(o){if(Array.isArray(o)){for(r=0;r<o.length;r++){var t=gs.SoundAsset.neuw();t.loadFromLite(o[r]);h.add(t)}}else{var t=gs.SoundAsset.neuw();t.loadFromLite(o);h.add(t)}}}this.preloadAllScenes=function(p){i.virtualFileCache.loadGame().then(function o(r){var q=r.getData().scenes;if(q&&!Array.isArray(q)){q=[q]}p&&p.call(null,q)})};this.pathForImage=function(p){var o=b.assetForName(p);if(!o){return null}var q=o.bestFileRepresentation();if(q){return this.pathResolver.getImagePath(q.filename)}else{return null}};this.pathForSound=function(q){var p=h.assetForName(q);if(!p){return null}var o=p.bestFileRepresentation();if(o){return this.pathResolver.getSoundPath(o.filename)}else{return null}};this.pathForTable=function(o){return this.pathResolver.getTablePath(o)};this.isPathCrossOrigin=function(s){var p=/^https?:\/\//;if(!p.test(s)){return false}var o=/^\w+:\/\/[^\/]+/;var t=o.exec(s);var r=t!==null?t[0]:null;var q=window.location.protocol+"//"+window.location.host;return(q!==r)};this.getImageSize=function(q){var o=b.assetForName(q);if(!o){return 0}var r=o.bestFileRepresentation();if(r){var p=Number(r.size)}if(!p){p=5000}return p};this.play=function(){if(!this._readyToPlay){g=true;return}var o=this.game;o.interceptKeyEvents=true;if(o.systemPaused){o.systemResume();this.startGameLoop();o.eventCenter.postEvent("resume",null)}else{if(o.isPlaying){o.gameTimebase.resume();o.eventCenter.postEvent("resume",null)}else{o.updateGraphicsDimensions();if(i._changeSceneQueued!==null){var p=i._changeSceneQueued;if(typeof(p)==="number"){p=o.scenes.keyForScene(i._changeSceneQueued)}o.forceNeedsToChangeScene(p)}o.gameTimebase=gs.Timebase.provide().init();gs.EngineContext.current.resetFrameTime();o.start(o.gameTimebase.nextTimestamp(0))}}if(!this.gameLoopIsRunning()){this.startGameLoop()}o.isPlaying=true};this.gameLoopIsRunning=function(){return this.gameLoop.isRunning};this.startGameLoop=function(){this.gameLoop.start()};this.stopGameLoop=function(){this.gameLoop.stop()};this.setLoaderProgress=function(o){if(o){d=o;d.beginTransition();d.beginLoading()}};this.addActionListener=function(o,q,p){if(!this.actionListeners){this.actionListeners={}}if(!this.actionListeners[o]){this.actionListeners[o]={}}if(!this.actionListeners[o][q]){this.actionListeners[o][q]=[]}this.actionListeners[o][q].push(p)};this.dispatchAction=function(p,q,o){if(!this.actionListeners){this.actionListeners={}}if(!this.actionListeners[p]){this.actionListeners[p]={}}if(this.actionListeners[p][q]){this.actionListeners[p][q].forEach(function(s){try{s.call(null,o)}catch(r){gs.Log.error(r)}})}};this.deferAction=function(p,q,o){if(!this.deferredActions){this.deferredActions=[]}this.deferredActions.push({area:p,action:q,args:o})};this.dispatchDeferredActions=function(){if(this.deferredActions){for(var q=0,p=this.deferredActions.length;q!==p;q++){var o=this.deferredActions[q];this.dispatchAction(o.area,o.action,o.args)}this.deferredActions.length=0}};this.getImages=function(){return b};this.getSounds=function(){return h};this.SHOW_FRAMERATE=false;return this};gs.Project.nodeTypeNameMap=gs.util.createObfuscationLookup({actor:"actor",actors:"actors",angle:"angle",array:"array",aspects:"aspects",assets:"assets",attribute:"attribute",attributes:"attributes",behavior:"behavior",behaviors:"behaviors",color:"color",condition:"condition",conditions:"conditions",elseBehaviors:"elseBehaviors",enumeration:"enumeration",expression:"expression",file:"file",game:"game",graphics:"graphics",images:"images",index:"index",info:"info",instructions:"instructions",layer:"layer",layers:"layers",longDescription:"longDescription",motion:"motion",pair:"pair",physics:"physics",point:"point",predicate:"predicate",prototypes:"prototypes",real:"real",reference:"reference",resolution:"resolution",resolutionIndependence:"resolutionIndependence",scene:"scene",scenes:"scenes",size:"size",sounds:"sounds",subjectPredicate:"subjectPredicate",string:"string",tags:"tags",tablecolumnassignment:"tablecolumnassignment",tablecolumns:"tablecolumns",text:"text","boolean":"boolean"});gs.Layer.prototype.render=function(){var d=this.actors;for(var a=0,b=d.length;a<b;a++){var c=d[a].renderNode;if(c){c.compute()}}};gs.Layer.prototype.showLayer=function(f){var e;var c=f.attributes.camera;if(gs.Scene.HUDDisabled){e=f.sgScene.createSpace(gs.SGSpace.NodeType.SGSpace)}else{e=f.sgScene.createSpace(gs.SGSpace.NodeType.SGOrtho2DSpace);if(!this.scrollable()){e._x.setValue(0);e._y.setValue(0)}else{e._x.connectToAttribute(c.origin.x);e._y.connectToAttribute(c.origin.y)}e._width.connectToAttribute(c.size.width);e._height.connectToAttribute(c.size.height);e._near.setValue(0);e._far.setValue(1);e._viewRotation.connectToAttribute(this.game().devices.screen.deviceRotation);e._modelRotation.connectToAttribute(c.rotation)}var d=this.actors;for(var a=0,b=d.length;a<b;a++){d[a].showActor(e)}this.space=e;this.sortRenderNodes()};gs.Layer.prototype.hideLayer=function(){this.space=null};gs.Layer.prototype.sortRenderNodes=function(){var c=this.actors;for(var a=0,b=c.length;a<b;a++){c[a].setLayerIndex(a)}this.space.sortRenderNodes()};gs.Layer.prototype.makeActorVisible=function(a){var b=this.space;a.showActor(b);this.sortRenderNodes()};gs.Scene.showScene=function(b){var i=this.game();var a=gs.SGScene.create(i.sharedAssetManager,i.sharedHandleManager);this.sgScene=a;gs.ObjectList.prototype.makeChildrenPerformFunction.call(this.layers,gs.Layer.prototype.showLayer,this);var j=a.defaultSpace();if(!gs.Scene.HUDDisabled){if(b){var g=j.createNode(gs.SGSpace.NodeType.SGClear);var d=this.attributes.color;d.red.connectToSprite(g,"colorR","dirty");d.green.connectToSprite(g,"colorG","dirty");d.blue.connectToSprite(g,"colorB","dirty")}}var e=this.attributes.camera;var h=j.createNode(gs.SGSpace.NodeType.SGArithmetic);var c=j.createNode(gs.SGSpace.NodeType.SGArithmetic);h.setOperation("/");c.setOperation("/");h._input1.connectToAttribute(e.size.width);c._input1.connectToAttribute(e.size.height);h._input2.setValue(2);c._input2.setValue(2);var f=j.createNode(gs.SGSpace.NodeType.SGArithmetic);var k=j.createNode(gs.SGSpace.NodeType.SGArithmetic);f._input1.connectToAttribute(e.origin.x);k._input1.connectToAttribute(e.origin.y);f._input2.connectToPort(h._output);k._input2.connectToPort(c._output);this._visible=true};gs.Scene.hideScene=function(){this.sgScene=null;this._visible=null};gs.Actor.isDrawing=function(){return(!!this.rootSpace)};gs.Actor.showActor=function(a){if(this.visible()){this.rootSpace=a;this.spaceSources=gs.array.provide();this.spaceSources[0]=this;this.nodeSources=gs.array.provide();this.nodeSources[0]=this;this.createSceneGraph()}};gs.Actor.hideActor=function(){if(this.visible()){this.deleteSceneGraph();this.rootSpace=null;if(this.spaceSources){gs.array.recycle(this.spaceSources);this.spaceSources=null}if(this.nodeSources){gs.array.recycle(this.nodeSources);this.nodeSources=null}}};gs.Actor.topLevelSpace=function(){var a=this.rootSpace;var b=this.spaceSources;if(b&&b.length>0){a=b[b.length-1].getSpace()}return a};gs.Actor.createSceneGraph=function(){var c=this.spaceSources;var e=this.nodeSources;var a=this.rootSpace;var b,d;if(c){d=c.length;for(b=0;b<d;++b){a=c[b].createSpace(a)}}if(e){var f=0;d=e.length;for(b=0;b<d;++b){f=f+e[b].createNodesInSpace(a,f)}}if(a){a.sortRenderNodes()}};gs.Actor.deleteSceneGraph=function(){var d=this.rootSpace;var c=this.spaceSources;var g=this.nodeSources;var a=this.topLevelSpace();if(g){var e=g.length;for(var b=0;b<e;++b){g[b].removeNodesFromSpace(a)}}if(c){for(var b=c.length-1;b>=0;b--){var f;if(b===0){f=d}else{f=c[b-1].getSpace()}c[b].removeSpace(f)}}};gs.Actor.getLayerIndex=function(){return this._layerIndex};gs.Actor.setLayerIndex=function(a){this._layerIndex=a;if(this.spaceSources){if(this.spaceSources.length>0){this.spaceSources[0].getSpace().setLayer(a)}else{this._spriteNode.setLayer(a)}}};gs.Actor.addSpaceSource=function(a){if(!this.visible()||!this.isDrawing()){return}var c=this.getLayerIndex();this.deleteSceneGraph();var d=this.spaceSources;d.push(a);this.createSceneGraph();this.setLayerIndex(c);var b=this.layer;if(b){b.sortRenderNodes()}};gs.Actor.removeSpaceSource=function(a){if(!this.visible()||!this.isDrawing()){return}var d=this.getLayerIndex();this.deleteSceneGraph();var e=this.spaceSources;if(e){var b=e.indexOf(a);if(b>-1){e.splice(b,1)}}this.createSceneGraph();this.setLayerIndex(d);var c=this.layer;if(c){c.sortRenderNodes()}};gs.Actor.addNodeSource=function(b){if(!this.visible()||!this.isDrawing()){return}var a=this.topLevelSpace();var c=this.nodeSources;if(c){c[c.length]=b;var d=a.countRenderNodes();b.createNodesInSpace(a,d);a.sortRenderNodes()}};gs.Actor.removeNodeSource=function(c){if(!this.visible()||!this.isDrawing()){return}var b=this.topLevelSpace();var d=this.nodeSources;if(d){var a=d.indexOf(c);if(a>-1){d.splice(a,1);c.removeNodesFromSpace(b)}}};gs.Actor.createSpace=function(c){var b;if(this.scene.wrappingEnabled()){b=c.createNode(gs.SGSpace.NodeType.SGWrap);var a=this.attributes;b._x.connectToAttribute(a.position.x);b._y.connectToAttribute(a.position.y);b._wrapX.setValue(false);b._wrapY.setValue(false)}else{b=c.createNode(gs.SGSpace.NodeType.SGSpace)}this.actorSpace=b;return b};gs.Actor.getSpace=function(){return this.actorSpace};gs.Actor.removeSpace=function(a){if(this.actorSpace){a.removeNode(this.actorSpace);if(!(this.actorSpace instanceof gs.SGWrapNode)){gs.SGSpace.recycle(this.actorSpace)}this.actorSpace=null}};gs.Actor.createNodesInSpace=function(d,e){var c=d.createNode(gs.SGSpace.NodeType.SGSprite);this._spriteNode=c;var b=this.attributes;b.position.x.connectToSprite(c,"x","dirtyTransform");b.position.y.connectToSprite(c,"y","dirtyTransform");b.rotation.connectToSprite(c,"angleDeg","dirtyTransform");b.size.width.connectToSprite(c,"width","dirtyTransform");b.size.height.connectToSprite(c,"height","dirtyTransform");b.color.red.connectToSprite(c,"colorR","dirtyColor");b.color.green.connectToSprite(c,"colorG","dirtyColor");b.color.blue.connectToSprite(c,"colorB","dirtyColor");b.color.alpha.connectToSprite(c,"colorA","dirtyColor");b.image.connectToSprite(c,"imageID","dirtyImage");var a=this.aspects.graphics.attributes;a.flipHorizontally.connectToSprite(c,"flipY","dirtyTransform");a.flipVertically.connectToSprite(c,"flipX","dirtyTransform");a.blendingMode.connectToSprite(c,"blendMode","dirtyGraphics");a.horizontalWrap.connectToSprite(c,"wrapModeS","dirtyGraphics");a.verticalWrap.connectToSprite(c,"wrapModeT","dirtyGraphics");a.horizontalAnchor.connectToSprite(c,"anchorS","dirtyGraphics");a.verticalAnchor.connectToSprite(c,"anchorT","dirtyGraphics");a.tileWidth.connectToSprite(c,"tileWidth","dirtyGraphics");a.tileHeight.connectToSprite(c,"tileHeight","dirtyGraphics");return 1};gs.Actor.removeNodesFromSpace=function(c){var b=this.attributes;b.position.x.disconnectFromSprite();b.position.y.disconnectFromSprite();b.rotation.disconnectFromSprite();b.size.width.disconnectFromSprite();b.size.height.disconnectFromSprite();b.color.red.disconnectFromSprite();b.color.green.disconnectFromSprite();b.color.blue.disconnectFromSprite();b.color.alpha.disconnectFromSprite();b.image.disconnectFromSprite();var a=this.aspects.graphics.attributes;a.flipHorizontally.disconnectFromSprite();a.flipVertically.disconnectFromSprite();a.blendingMode.disconnectFromSprite();a.horizontalWrap.disconnectFromSprite();a.verticalWrap.disconnectFromSprite();a.horizontalAnchor.disconnectFromSprite();a.verticalAnchor.disconnectFromSprite();a.tileWidth.disconnectFromSprite();a.tileHeight.disconnectFromSprite();c.removeNode(this._spriteNode);this._spriteNode.recycle();this._spriteNode=null};gs.Actor.startWrap=function(c,b){var a=this.actorSpace;if(c===gs.Vector2.X_COMPONENT){a._wrapX.setValue(true);a._wrapWidth.setValue(b)}else{a._wrapY.setValue(true);a._wrapHeight.setValue(b)}};gs.Actor.stopWrap=function(b){var a=this.actorSpace;if(b===gs.Vector2.X_COMPONENT){a._wrapX.setValue(false)}else{a._wrapY.setValue(false)}};gs.Game.render=function(){if(this.loadingFlag){return}for(var b=0,c=this.currentSceneStack.length;b<c;b++){var d=this.currentSceneStack[b];var a=(d.frameCount>2);this.currentSceneStack[b].sgScene.render(this,a)}if(gs.globalOptions.forceTexturePrimeFrames&&this.texturePrimeFrames<gs.globalOptions.forceTexturePrimeFrames){this.texturePrimeFrames++;this.renderer.drawBlank()}};gs.Game.updateMousePosition=function(a,b){this.devices.mouse.position.x.fastSetValue(a);this.devices.mouse.position.y.fastSetValue(b)};gs.Game.mouseButtonDown=function(a,b){this.devices.mouse.button.fastSetValue(true);this.updateMousePosition(a,b)};gs.Game.mouseButtonUp=function(b,a){this.devices.mouse.button.fastSetValue(false)};gs.Game.updateAccelerometer=function(a,c,b){this.devices.accelerometer.x.fastSetValue(a);this.devices.accelerometer.y.fastSetValue(c);this.devices.accelerometer.z.fastSetValue(b)};gs.Game.updateTouchPosition=function(c,a,g,e){var d=gs.CompoundAttribute.obfuscationLookupTable["touch"+c];var b=this.devices.touches.active[d];b.fastSetValue(e);var f=this.devices.touches[d];f.x.fastSetValue(a);f.y.fastSetValue(g)};gs.Game.touchDown=function(b,a,c){this.updateTouchPosition(b,a,c,true)};gs.Game.touchUp=function(b,a,c){this.updateTouchPosition(b,a,c,false)};gs.Game.datetime=new Date();gs.Game.updateClock=function(){var a=gs.Game.datetime;a.setTime(Date.now());this.devices.clock.year.fastSetValue(a.getFullYear());this.devices.clock.month.fastSetValue(a.getMonth()+1);this.devices.clock.day.fastSetValue(a.getDate());this.devices.clock.hour.fastSetValue(a.getHours());this.devices.clock.minute.fastSetValue(a.getMinutes());this.devices.clock.second.fastSetValue(a.getSeconds());this.devices.clock.millisecond.fastSetValue(a.getMilliseconds())};gs.SGAnchorMode={SGAnchorMin:0,SGAnchorCenter:1,SGAnchorMax:2};gs.SGBlendingMode={Normal:0,Opaque:1,Additive:2,Screen:3,Multiply:4};gs.SGTextAlignment={Left:0,Center:1,Right:2};gs.SGWrapMode={SGWrapScale:0,SGWrapFixed:1,SGWrapTile:2};gs.SGTextureRect=function(d,a,b,c){this.left=d;this.bottom=a;this.right=b;this.top=c};gs.SGTextureRect.prototype.getWidth=function(){return Math.abs(this.right-this.left)};gs.SGTextureRect.prototype.getHeight=function(){return Math.abs(this.top-this.bottom)};gs.SGTextureRect.prototype.cropHorizontallyExact=function(c,b){var a=this.right-this.left;switch(b){case gs.SGAnchorMode.SGAnchorMin:this.right=this.left+c;break;case gs.SGAnchorMode.SGAnchorCenter:var d=(a-c)*0.5;this.left=this.left+d;this.right=this.left+c;break;case gs.SGAnchorMode.SGAnchorMax:this.right=a;this.left=a-c;break}};gs.SGTextureRect.prototype.cropVerticallyExact=function(a,b){var d=this.top-this.bottom;switch(b){case gs.SGAnchorMode.SGAnchorMin:this.top=this.bottom+a;break;case gs.SGAnchorMode.SGAnchorCenter:var c=(d-a)*0.5;this.bottom=this.bottom+c;this.top=this.bottom+a;break;case gs.SGAnchorMode.SGAnchorMax:this.top=d;this.bottom=d-a;break}};gs.SGNode=function(){this.dirty=true};gs.SGNode.prototype={update:function(){if(this.dirty){this.dirty=false;this.compute()}},compute:function(){}};gs.SGPort=function(){this._value=null;this.ignoreDirty=false;this.node=null;this.sourcePort=null;this.destPorts=gs.array.provide()};gs.Pool.init(gs.SGPort);gs.SGPort.addOutputPort=function(b){var a=gs.SGPort.provide();a.node=b;if(!b.outputPortsArray){b.outputPortsArray=gs.array.provide()}b.outputPortsArray.push(a);return a};gs.SGPort.addInputPort=function(e,c){var b=gs.SGPort.provide();b.ignoreDirty=!!c;b.node=e;var a=(e.outputPortsArray?e.outputPortsArray.length:0);for(var d=0;d<a;++d){b.addDestPort(e.outputPortsArray[d])}return b};gs.SGPort.prototype={getValue:function(){if(this.sourcePort){return this.sourcePort.getValue()}else{this.node.update();return this._value}},stringValue:function(){var a=this.getValue();return gs.Attribute.convertValueToString(a)},numberValue:function(){return Number(this.getValue())},intValue:function(){return this.numberValue()|0},boolValue:function(){return Boolean(this.getValue())},markAsDirty:function(){if(this.ignoreDirty){return}var c=this.node;if(c.dirty){return}for(var a=0,b=this.destPorts.length;a<b;a++){this.destPorts[a].markAsDirty()}c.dirty=true},markAsForceDirty:function(){var c=this.node;var a=0,b=this.destPorts.length;for(;a<b;a++){this.destPorts[a].markAsForceDirty()}c.dirty=true},addDestPort:function(a){this.destPorts.push(a)},removeDestPort:function(b){var a=this.destPorts.indexOf(b);if(a>-1){this.destPorts.splice(a,1)}},setValue:function(a){if(this._value!==a){this._value=a;this.markAsDirty()}},setValueForceDirty:function(a){this._value=a;this.markAsForceDirty()},connectToPort:function(a){if(!a){this.disconnect()}else{this.sourcePort=a;a.addDestPort(this)}},disconnect:function(){if(this.sourcePort){this.sourcePort.removeDestPort(this);this.sourcePort=null}},connectToAttribute:function(b){var a=b.getNode();this.connectToPort(a._value)}};gs.SGRenderNode=function(){gs.SGNode.call(this);this.layer=0};gs.SGRenderNode.compare=function(b,a){if(b.layer<a.layer){return -1}else{if(b.layer>a.layer){return 1}}return 0};gs.SGRenderNode.prototype=gs.subclass(gs.SGNode,{setLayer:function(a){this.layer=a}});gs.SGSpace=function(){gs.SGRenderNode.call(this);if(!this.allNodes){this.allNodes=gs.array.provide()}this.singleRenderNode=null;this.renderNodes=null;this.assetManager=null;this.handleManager=null};gs.SGSpace.NodeType={SGArithmetic:"SGArithmetic",SGAssetLoader:"SGAssetLoader",SGAttribute:"SGAttribute",SGClear:"SGClear",SGColor:"SGColor",SGReplicator:"SGReplicator",SGRender:"SGRender",SGSpace:"SGSpace",SGSprite:"SGSprite",SGOrtho2DSpace:"SGOrtho2DSpace",SGParticleSystem:"SGParticleSystem",SGText:"SGText",SGWrap:"SGWrap"};gs.Pool.init(gs.SGSpace);gs.SGSpace.prototype=gs.subclass(gs.SGRenderNode,{init:function(b,a){this.assetManager=b;this.handleManager=a;return this},initFromParent:function(a){return this.init(a.assetManager,a.handleManager)},createNode:function(a){var b=null;switch(a){case gs.SGSpace.NodeType.SGArithmetic:b=gs.SGArithmeticNode.provide();break;case gs.SGSpace.NodeType.SGClear:b=gs.SGClearNode.provide();break;case gs.SGSpace.NodeType.SGColor:b=gs.SGColorNode.provide();break;case gs.SGSpace.NodeType.SGReplicator:b=gs.SGReplicatorNode.provide().initFromParent(this);break;case gs.SGSpace.NodeType.SGSpace:b=gs.SGSpace.provide().initFromParent(this);break;case gs.SGSpace.NodeType.SGSprite:b=gs.SGSpriteNode.provide();break;case gs.SGSpace.NodeType.SGParticleSystem:b=gs.SGParticleSystemNode.provide();break;case gs.SGSpace.NodeType.SGText:b=gs.SGTextNode.provide();break;case gs.SGSpace.NodeType.SGWrap:b=gs.SGWrapNode.provide().init(this.assetManager,this.handleManager);break;default:b=null}this.addNode(b);return b},removeNode:function(b){var a=this.allNodes.indexOf(b);if(a>-1){if(b instanceof gs.SGRenderNode){if(b===this.singleRenderNode){this.singleRenderNode=null}else{var a=this.renderNodes.indexOf(b);if(a>-1){this.renderNodes.splice(a,1)}}}this.allNodes.splice(a,1)}},compute:function(b,a){this.dirty=false;this.render(b,a)},sortRenderNodes:function(){if(this.renderNodes){this.renderNodes.sort(gs.SGRenderNode.compare)}},render:function(b,a){if(this.renderNodes){this.renderAll(b,a)}else{if(this.singleRenderNode){this.singleRenderNode.compute(b,a)}}},renderAll:function(e,a){var b=this.renderNodes;for(var c=0,d=b.length;c<d;c++){b[c].compute(e,a)}},addNode:function(a){this.allNodes.push(a);if(a instanceof gs.SGRenderNode){if(this.renderNodes){this.renderNodes[this.renderNodes.length]=a}else{if(this.singleRenderNode){this.renderNodes=gs.array.provide();this.renderNodes[0]=this.singleRenderNode;this.singleRenderNode=null;this.renderNodes[1]=a}else{this.singleRenderNode=a}}}},countRenderNodes:function(){return this.singleRenderNode?1:this.renderNodes?this.renderNodes.length:0}});gs.SGOrtho2DSpace=function(){gs.SGSpace.call(this);this._x=gs.SGPort.addInputPort(this);this._y=gs.SGPort.addInputPort(this);this._width=gs.SGPort.addInputPort(this);this._height=gs.SGPort.addInputPort(this);this._near=gs.SGPort.addInputPort(this);this._far=gs.SGPort.addInputPort(this);this._viewRotation=gs.SGPort.addInputPort(this);this._modelRotation=gs.SGPort.addInputPort(this)};gs.Pool.init(gs.SGOrtho2DSpace);gs.SGOrtho2DSpace.prototype=gs.subclass(gs.SGSpace,{render:function(b,a){this.willRender(b);gs.SGSpace.prototype.render.call(this,b,a);this.didRender(b)},willRender:function(e){var b=this._x.getValue();var g=this._y.getValue();var c=this._width.getValue();var a=this._height.getValue();var d=this._viewRotation.getValue();var f=this._modelRotation.getValue();e.beginSpace(b,g,c,a,d,f)},didRender:function(a){a.endSpace()}});gs.SGScene=function(b,a){this.spaces=gs.array.provide();this._defaultSpace=gs.SGSpace.provide().init(b,a);this.assetManager=b;this.handleManager=a};gs.SGScene.create=function(b,a){return new gs.SGScene(b,a)};gs.SGScene.prototype={defaultSpace:function(){return this._defaultSpace},createSpace:function(b){var a=null;if(b===gs.SGSpace.NodeType.SGOrtho2DSpace){a=gs.SGOrtho2DSpace.provide().init(this.assetManager,this.handleManager)}else{a=gs.SGSpace.provide().init(this.assetManager,this.handleManager)}this.spaces.push(a);return a},removeSpace:function(a){},render:function(b,a){var d=b.renderer;d.beginScene();this._defaultSpace.compute(d,a);var e=this.spaces.length;for(var c=0;c<e;++c){this.spaces[c].compute(d,a)}d.endScene()}};gs.SGAttributeNode=function(){gs.SGNode.call(this);this._value=gs.SGPort.addOutputPort(this)};gs.Pool.init(gs.SGAttributeNode);gs.SGAttributeNode.prototype=gs.subclass(gs.SGNode,{setValue:function(a){this._value.setValue(a)}});gs.SGAssetLoaderNode=function(){gs.SGNode.call(this);this.assetManager=null};gs.SGAssetLoaderNode.prototype=gs.subclass(gs.SGNode);gs.SGColorNode=function(){gs.SGNode.call(this);this._output=gs.SGPort.addOutputPort(this);this._r=gs.SGPort.addInputPort(this);this._g=gs.SGPort.addInputPort(this);this._b=gs.SGPort.addInputPort(this);this._a=gs.SGPort.addInputPort(this);this._r._value=1;this._g._value=1;this._b._value=1;this._a._value=1;var a=gs.array.provide();a[0]=1;a[1]=1;a[2]=1;a[3]=1;this._output._value=a};gs.Pool.init(gs.SGColorNode);gs.SGColorNode.prototype=gs.subclass(gs.SGNode,{compute:function(){var a=this._output._value;a[0]=this._r.getValue();a[1]=this._g.getValue();a[2]=this._b.getValue();a[3]=this._a.getValue()}});gs.SGImageLoaderNode=function(){gs.SGAssetLoaderNode.call(this);this._asset=gs.SGPort.addOutputPort(this);this._name=gs.SGPort.addInputPort(this);this.previousImageName=null;this.handleManager=null};gs.SGImageLoaderNode.pngExtensionRegex=/\.png$/;gs.SGImageLoaderNode.imageIDCache={};gs.Pool.init(gs.SGImageLoaderNode);gs.SGImageLoaderNode.prototype=gs.subclass(gs.SGAssetLoaderNode,{init:function(b,a){this.assetManager=b;this.handleManager=a;return this},compute:function(){var a=this._name.getValue();if(!a){this.previousImageName=null;this._asset._value=this.handleManager.getColorHandle(0,0,0,0);return}var c=gs.SGImageLoaderNode.imageIDCache[a];if(!c){if(gs.SGImageLoaderNode.pngExtensionRegex.test(a)){c=a.substr(0,a.length-4)}else{c=a}gs.SGImageLoaderNode.imageIDCache[a]=c}if(c===this.previousImageName){return}this.previousImageName=c;var b=this.assetManager.imageForName(c);this._asset._value=this.handleManager.getImageHandle(b)}});gs.SGWhiteColor=[1,1,1,1];gs.SGSpriteNode=function(){gs.SGRenderNode.call(this);this.reset()};gs.SGSpriteNode.pngExtensionRegex=/\.png$/;gs.SGSpriteNode.imageIDCache={};gs.Pool.init(gs.SGSpriteNode);gs.SGSpriteNode.prototype=gs.subclass(gs.SGRenderNode,{reset:function(){if(!this.color){this.color=gs.array.provide()}this.dirtyTransform=true;this.x=0;this.y=0;this.angleDeg=0;this.angleRad=0;this.width=0;this.height=0;this.flipX=false;this.flipY=false;this.dirtyImage=true;this.imageID=null;this.imageHandle=null;this.loadingHandle=null;this.dirtyColor=true;this.colorR=1;this.colorG=1;this.colorB=1;this.colorA=1;this.color[0]=1;this.color[1]=1;this.color[2]=1;this.color[3]=1;this.dirtyGraphics=true;this.blendMode=0;this.wrapModeS=0;this.wrapModeT=0;this.anchorS=0;this.anchorT=0;this.tileWidth=0;this.tileHeight=0},recycle:function(){if(this.imageHandle){this.imageHandle.release()}if(this.loadingHandle){this.loadingHandle.release()}gs.SGSpriteNode.recycle(this)},updateDirty:function(g){if(this.dirtyTransform){this.angleRad=this.angleDeg*-gsMath.DEG2RAD;this.dirtyTransform=false}if(this.dirtyColor){if(this.blendMode===1){this.colorA=1}var a=this.color;a[0]=this.colorR;a[1]=this.colorG;a[2]=this.colorB;a[3]=this.colorA;this.dirtyColor=false}var f=this.imageHandle;var c=this.dirtyImage;if(c){if(this.loadingHandle){this.loadingHandle.release();this.loadingHandle=null}var b=this.imageID;if(!b){if(this.imageHandle){this.imageHandle.release();this.imageHandle=null}}else{var d=gs.SGSpriteNode.imageIDCache[b];if(!d){if(gs.SGSpriteNode.pngExtensionRegex.test(b)){d=b.substr(0,b.length-4)}else{d=b}gs.SGSpriteNode.imageIDCache[b]=d}var e=gs.AssetManager.current.imageForName(d);var h=g.handleManager.getImageHandle(e);if(h.ready){if(this.imageHandle){this.imageHandle.release()}this.imageHandle=h}else{this.loadingHandle=h}}f=this.imageHandle;this.dirtyImage=false}if(c||this.dirtyGraphics||(f&&f.isCanvas)){if(f){f.update(this)}this.dirtyGraphics=false}},updateLoading:function(){var a=this.loadingHandle;a.checkReady();if(a.ready){if(this.imageHandle){this.imageHandle.release()}this.imageHandle=a;this.loadingHandle=null;a.update(this)}},compute:function(d,a){gs.Game.profiler.entityCounter.sprites.increment();var b=this.dirtyTransform||this.dirtyColor||this.dirtyImage||this.dirtyGraphics;if(b||d instanceof gs.SGCanvasRenderer){this.updateDirty(d)}this.dirty=false;if(this.loadingHandle){this.updateLoading()}var c=this.imageHandle;if(c&&!c.ready){c.checkReady()}if(!a||(c&&!c.ready)||this.width<=0||this.height<=0||this.colorA<=0){return}if(c){if(this.wrapModeS!==0||this.wrapModeT!==0){d.drawImageWithWrap(this,c)}else{d.drawImage(this,c)}}else{if(!this.loadingHandle){d.drawRect(this)}}}});gs.SGClearNode=function(){gs.SGRenderNode.call(this);this.colorR=1;this.colorG=1;this.colorB=1};gs.Pool.init(gs.SGClearNode);gs.SGClearNode.prototype=gs.subclass(gs.SGRenderNode,{compute:function(b,a){if(a){b.clear(this.colorR,this.colorG,this.colorB)}}});gs.SGArithmeticNode=function(){gs.SGNode.call(this);this._output=gs.SGPort.addOutputPort(this);this._input1=gs.SGPort.addInputPort(this);this._input2=gs.SGPort.addInputPort(this);this._operation="+"};gs.Pool.init(gs.SGArithmeticNode);gs.SGArithmeticNode.prototype=gs.subclass(gs.SGNode,{setOperation:function(a){this._operation=a},compute:function(){var b=this._input1.getValue();var a=this._input2.getValue();switch(this._operation){case"+":this._output._value=b+a;break;case"-":this._output._value=b-a;break;case"*":this._output._value=b*a;break;case"/":this._output._value=b/a;break;case"%":this._output._value=b%a;break}}});gs.SGReplicatorNode=function(){gs.SGSpace.call(this);this.angle=0;this.spacing=0;this.copies=0};gs.Pool.init(gs.SGReplicatorNode);gs.SGReplicatorNode.prototype=gs.subclass(gs.SGSpace,{render:function(c,a){this.dirty=false;c.pushMatrix();for(var b=0;b<this.copies;b++){gs.SGSpace.prototype.render.call(this,c,a);c.transformPolar(this.angle,this.spacing)}c.popMatrix()}});gs.SGTextNode=function(){gs.SGSpriteNode.call(this);this.textAttribute=null;this.dirtyText=false;this.text=null;this.safeText=null;this.cachedLines=null;this.fontFamily=null;this.sizePx=0;this.alignment=gs.SGTextAlignment.Left;this.wrap=false;this.lineHeightFactor=1.35};gs.Pool.init(gs.SGTextNode);gs.SGTextNode.prototype=gs.subclass(gs.SGSpriteNode,{init:function(){this.dirtyTransform=true;this.dirtyColor=true;this.dirtyText=true;this.lineHeight=this.sizePx*this.lineHeightFactor},compute:function(d,a){this.dirty=false;if(!gs.debug.text){return}if(this.dirtyTransform){this.angleRad=this.angleDeg*-gsMath.DEG2RAD;this.dirtyTransform=false}if(this.dirtyColor){var b=this.color;b[0]=this.colorR;b[1]=this.colorG;b[2]=this.colorB;b[3]=this.colorA;this.dirtyColor=false}if(this.textAttribute){var c=this.textAttribute.getValue();if(c!==this.text){this.text=c;this.dirtyText=true}}if(this.dirtyText){if(this.cachedLines){gs.array.recycle(this.cachedLines)}this.safeText=String(this.text);this.safeText=gs.html5.Text.normalizeString(this.safeText);this.cachedLines=null;this.dirtyText=false}if(a){this.cachedLines=d.drawText(this,this.cachedLines||this.safeText)}}});gs.SGWrapNode=function(){gs.SGSpace.call(this);this._x=gs.SGPort.addInputPort(this);this._y=gs.SGPort.addInputPort(this);this._wrapX=gs.SGPort.addInputPort(this);this._wrapY=gs.SGPort.addInputPort(this);this._wrapWidth=gs.SGPort.addInputPort(this);this._wrapHeight=gs.SGPort.addInputPort(this)};gs.Pool.init(gs.SGWrapNode);gs.SGWrapNode.prototype=gs.subclass(gs.SGSpace,{render:function(e,i){this.dirty=false;var b=this._wrapX.getValue();var a=this._wrapY.getValue();gs.SGSpace.prototype.render.call(this,e,i);var d=0;var c=0;if(b){var h=this._wrapWidth.getValue();var j=this._x.getValue();if(j<h*0.5){d=h}else{d=-h}e.pushMatrix();e.transformPolar(0,d);gs.SGSpace.prototype.render.call(this,e,i);e.popMatrix()}if(a){var f=this._wrapHeight.getValue();var g=this._y.getValue();if(g<(f*0.5)){c=-f}else{c=f}e.pushMatrix();e.transformPolar(-90,c);gs.SGSpace.prototype.render.call(this,e,i);e.popMatrix()}if(b&&a){e.pushMatrix();e.transformPolar(0,d);e.transformPolar(-90,c);gs.SGSpace.prototype.render.call(this,e,i);e.popMatrix()}}});gs.InternalParticle=function(){this.initialized=false;this.startTime=0;this.lifeTime=0;this.initialX=0;this.initialY=0;this.initialDX=0;this.initialDY=0;this.initialAngleRad=0;this.angularVelocityRad=0;this.sizeBegin=0;this.sizeEnd=0;this.sizeTime=0;this.colorTime=0};gs.Pool.init(gs.InternalParticle);gs.InternalParticle.prototype.toString=function(){return this.startTime};gs.SGParticleSystemNode=function(){gs.SGRenderNode.call(this);this.reset()};gs.SGParticleSystemNode.interpolateFast=function(b,a,c){return b+(a-b)*c};gs.Pool.init(gs.SGParticleSystemNode);gs.SGParticleSystemNode.prototype=gs.subclass(gs.SGRenderNode,{reset:function(){if(!this.particles){this.particles=gs.array.provide();this.colorBegin=gs.array.provide();this.colorEnd=gs.array.provide();this.particleColor=gs.array.provide()}this.hasAllocatedParticles=false;this.dirtyOrigin=false;this.dirtyOffset=false;this.dirtySettings=false;this.attributesWithExpressions=null;this.time=0;this.spawnParticles=false;this.stopSpawning=false;this.particleCount=0;this.lifeTime=0;this.lifeTimeMin=0;this.lifeTimeMax=0;this.lifeStart=0;this.gravityX=0;this.gravityY=0;this.originX=0;this.originY=0;this.originAngleDeg=0;this.originAngleRad=0;this.offsetX=0;this.offsetY=0;this.offsetAngleDeg=0;this.offsetAngleRad=0;this.emitterX=0;this.emitterY=0;this.emitterAngleDeg=0;this.emitterAngleRad=0;this.imageID=null;this.imageHandle=null;this.blendMode=0;var a=this.colorBegin;a[0]=1;a[1]=1;a[2]=1;a[3]=1;var c=this.colorEnd;c[0]=1;c[1]=1;c[2]=1;c[3]=1;this.colorTime=0;this.colorChanges=false;this.onlyAlphaChanges=false;this.speed=0;this.particleAngleDeg=0;this.particleAngleRad=0;this.particleAngularVelocityDeg=0;this.particleAngularVelocityRad=0;this.sizeBegin=0;this.sizeEnd=0;this.sizeTime=0;this.sizeChanges=false;var b=this.particleColor;b[0]=1;b[1]=1;b[2]=1;b[3]=1},recycle:function(){var c=this.particleCount;var b=this.particles;for(var a=0;a<c;a++){gs.InternalParticle.recycle(b[a])}b.length=0;this.particleCount=0;this.hasAllocatedParticles=false;if(this.imageHandle){this.imageHandle.release();this.imageHandle=null}this.attributesWithExpressions=null;gs.SGParticleSystemNode.recycle(this)},allocateParticles:function(){var c=this.particleCount;var b=this.particles;for(var a=0;a<c;a++){b[a]=gs.InternalParticle.provide()}this.hasAllocatedParticles=true},init:function(){this.dirtyOrigin=true;this.dirtyOffset=true;this.dirtySettings=true;this.lifeTimeMax=this.lifeTime;this.lifeTimeMin=this.lifeTime*0.5;var d=this.colorBegin;var c=this.colorEnd;this.onlyAlphaChanges=this.colorChanges&&(d[3]!==c[3]&&d[0]===c[0]&&d[1]===c[1]&&d[2]===c[2]);if(!this.hasAllocatedParticles){this.allocateParticles()}this.generateParticles()},randomizeParticle:function(c){var b=this.emitterAngleRad;var a=this.speed;c.initialX=this.emitterX;c.initialY=this.emitterY;c.initialDX=Math.cos(b)*a;c.initialDY=Math.sin(b)*a;c.initialAngleRad=this.particleAngleRad;c.angularVelocityRad=this.particleAngularVelocityRad;c.lifeTime=Math.random()*(this.lifeTimeMax-this.lifeTimeMin)+this.lifeTimeMin;c.sizeBegin=this.sizeBegin;if(this.sizeChanges){c.sizeEnd=this.sizeEnd}else{c.sizeEnd=this.sizeBegin}c.sizeTime=this.sizeTime;c.colorTime=this.colorTime;c.initialized=true},generateParticles:function(){var c=this.particles;for(var a=0,b=this.particleCount;a<b;a++){var d=c[a];d.startTime=Math.random()*this.lifeStart;d.initialized=false}},refreshParticles:function(d){var c=this.particles;var f=true;for(var a=0,b=this.particleCount;a<b;a++){var e=c[a];if(d>e.startTime+e.lifeTime){if(f){this.updateDynamicValues();f=false}e.startTime=d;this.randomizeParticle(e)}}if(this.stopSpawning){this.spawnParticles=false;this.stopSpawning=false}},updateDynamicValues:function(){var a=this.attributesWithExpressions;if(a){for(var b=0,c=a.length;b<c;b++){a[b].getValue()}}this.particleAngleRad=this.particleAngleDeg*-gsMath.DEG2RAD;this.particleAngularVelocityRad=this.particleAngularVelocityDeg*-gsMath.DEG2RAD},renderAtTime:function(p,d,j){var n=this.imageHandle;if(!n&&this.imageID){var a=gs.AssetManager.current.imageForName(this.imageID);n=p.handleManager.getImageHandle(a);this.imageHandle=n}if(n&&!n.ready){n.checkReady()}j=j&&(!n||n.ready);var z=this.colorChanges;var D=this.onlyAlphaChanges;var u=this.colorBegin;var C=this.colorEnd;var o=z?null:this.colorEnd;var b=z?this.particleColor:null;if(b&&D){b[0]=C[0];b[1]=C[1];b[2]=C[2]}var w=this.gravityX;var t=this.gravityY;if(j){p.beginParticles(n,this.blendMode,o)}var A=0;var B=this.particles;for(var s=0,v=this.particleCount;s<v;s++){var r=B[s];var c=d-r.startTime;if(0<c&&c<r.lifeTime){A++;if(!r.initialized){this.randomizeParticle(r)}var l=r.initialDX+w*c*0.5;var k=r.initialDY+t*c*0.5;var h=r.initialX+l*c;var f=r.initialY+k*c;var e=r.initialAngleRad+c*r.angularVelocityRad;var m;if(c<r.sizeTime){var q=c/r.sizeTime;m=r.sizeBegin+(r.sizeEnd-r.sizeBegin)*q}else{m=r.sizeEnd}if(z){if(c<r.colorTime){var g=c/r.colorTime;if(!D){b[0]=u[0]+(C[0]-u[0])*g;b[1]=u[1]+(C[1]-u[1])*g;b[2]=u[2]+(C[2]-u[2])*g}b[3]=u[3]+(C[3]-u[3])*g}else{if(!D){b[0]=C[0];b[1]=C[1];b[2]=C[2]}b[3]=C[3]}}if(j){p.drawParticle(h,f,e,m,b)}}}if(j){p.endParticles()}gs.Game.profiler.entityCounter.particles.add(A)},compute:function(c,a){this.dirty=false;if(!gs.debug.particles){return}var b=this.dirtyOrigin;if(b){this.originAngleRad=this.originAngleDeg*-gsMath.DEG2RAD;this.dirtyOrigin=false}var d=this.dirtyOffset;if(d){this.offsetAngleRad=this.offsetAngleDeg*gsMath.DEG2RAD;this.dirtyOffset=false}if(this.dirtySettings){this.particleAngleRad=this.particleAngleDeg*-gsMath.DEG2RAD;this.dirtySettings=false}if(d||b){this.emitterX=this.originX+this.offsetX;this.emitterY=this.originY+this.offsetY;this.emitterAngleRad=this.originAngleRad+this.offsetAngleRad}if(this.spawnParticles){this.refreshParticles(this.time)}this.renderAtTime(c,this.time,a)}});gs.SGCanvasColor=function(f,e,c,d){this.isColorHandle=true;this.ready=true;this.color=gs.array.provide();this.color[0]=f;this.color[1]=e;this.color[2]=c;this.color[3]=d};gs.SGCanvasColor.prototype={update:function(a,c,b){this.color[0]=a[0];this.color[1]=a[1];this.color[2]=a[2];this.color[3]=a[3];this.blendingMode=b},release:function(){}};gs.SGCanvasString=function(){this.isStringHandle=true;this.lineHeightFactor=1.35;this.text=null;this.color=null;this.angleRadians=0;this.sizePx=0;this.lineHeight=0;this.fontFamily=null;this.alignment=gs.SGTextAlignment.Center;this.wrap=false;this.textLines=gs.array.provide();this.wrapWidth=0};gs.SGCanvasString.prototype={isReady:function(){return true},update:function(e,b,a,d,f,c){if(e!==this.text){this.clearTextLines()}this.text=e;this.color=b;this.sizePx=d;this.lineHeight=d*this.lineHeightFactor;this.fontFamily=a;this.alignment=f;this.wrap=c},clearTextLines:function(){this.textLines.length=0},appendTextLine:function(a){this.textLines.push(a)}};gs.SGCanvasImage=function(a){this.isImageHandle=true;this.isCanvas=true;this.imageTintCache=a;this.ready=false;this.color=gs.array.provide();this.color[0]=1;this.color[1]=1;this.color[2]=1;this.color[3]=1;this.colorEpsilon=1/64};gs.SGCanvasImage.prototype={reset:function(){this.resource=null;this.ready=false;this.color[0]=1;this.color[1]=1;this.color[2]=1;this.color[3]=1},release:function(){},setResource:function(a){this.resource=a;this.ready=false;this.checkReady()},checkReady:function(){if(!this.ready&&this.resource&&this.resource.ready){this.initFromResource()}},initFromResource:function(){var a=this.resource;this.width=a.width;this.height=a.height;this.color[0]=1;this.color[1]=1;this.color[2]=1;this.color[3]=1;this.currentImage=a.imageElement;this.originalImage=a.imageElement;this.imageWidth=a.width;this.imageHeight=a.height;this.assetWidth=a.width;this.assetHeight=a.height;this.tileWidth=a.width;this.tileHeight=a.height;this.ready=true},update:function(g){this.checkReady();if(!this.ready){return}var j=false;var h=false;var i=false;var f=g.tileWidth||this.assetWidth;var e=g.tileHeight||this.assetHeight;if(this.width!==g.width){this.width=g.width;j=true}if(this.height!==g.height){this.height=g.height;j=true}if(this.tileWidth!==f){this.tileWidth=f;j=true}if(this.tileHeight!==e){this.tileHeight=e;j=true}var a=this.colorEpsilon;var c=g.color;if(Math.abs(c[0]-this.color[0])>a||Math.abs(c[1]-this.color[1])>a||Math.abs(c[2]-this.color[2])>a){this.color[0]=c[0];this.color[1]=c[1];this.color[2]=c[2];h=true}this.color[3]=c[3];this.flipY=g.flipY;this.flipX=g.flipX;var d=this.originalImage;var b=this.currentImage;if(h){d=this.imageTintCache.getTintedImage(this.originalImage,this.color[0],this.color[1],this.color[2]);b=d;if(g.width!==this.assetWidth||g.height!==this.assetHeight){i=true}}if(j||(h&&i)){if(g.wrapModeS!==gs.SGWrapMode.SGWrapScale||g.wrapModeT!==gs.SGWrapMode.SGWrapScale){b=this.createFinalImage(b,g.width,g.height,g.wrapModeS,g.wrapModeT,g.anchorS,g.anchorT,this.tileWidth,this.tileHeight);this.imageWidth=b.width;this.imageHeight=b.height}else{this.imageWidth=this.assetWidth;this.imageHeight=this.assetHeight}}this.currentImage=b;this.ready=true},createFinalImage:function(c,b,k,f,d,g,e,j,h){if(f===gs.SGWrapMode.SGWrapScale&&d===gs.SGWrapMode.SGWrapScale){return c}var i=(g===0)?"left":(g===1)?"center":"right";var a=(e===0)?"bottom":(e===1)?"center":"top";if(f===gs.SGWrapMode.SGWrapTile&&d===gs.SGWrapMode.SGWrapTile){c=gs.html5.Canvas.createTiledImage(c,b,k,j,h);if(c.width!==b||c.height!==k){c=gs.html5.Canvas.createCroppedImage(c,b,k,i,a)}}else{if(f===gs.SGWrapMode.SGWrapTile&&d===gs.SGWrapMode.SGWrapScale){c=gs.html5.Canvas.createTiledImageHorizontal(c,b,j);if(c.width!==b){c=gs.html5.Canvas.createCroppedImage(c,b,c.height,i,a)}}else{if(f===gs.SGWrapMode.SGWrapScale&&d===gs.SGWrapMode.SGWrapTile){c=gs.html5.Canvas.createTiledImageVertical(c,k,h);if(c.height!==k){c=gs.html5.Canvas.createCroppedImage(c,c.width,k,i,a)}}else{if(f===gs.SGWrapMode.SGWrapTile&&d===gs.SGWrapMode.SGWrapFixed){if(c.height>k){c=gs.html5.Canvas.createTiledImageHorizontal(c,b,j);c=gs.html5.Canvas.createCroppedImage(c,b,k,i,a)}else{c=gs.html5.Canvas.createTiledImageHorizontal(c,b,j);if(c.width>b){c=gs.html5.Canvas.createCroppedImage(c,b,c.height,i,a)}c=gs.html5.Canvas.createPaddedImage(c,b,k)}}else{if(f===gs.SGWrapMode.SGWrapFixed&&d===gs.SGWrapMode.SGWrapTile){if(c.width>b){c=gs.html5.Canvas.createTiledImageVertical(c,k,h);c=gs.html5.Canvas.createCroppedImage(c,b,k,i,a)}else{c=gs.html5.Canvas.createTiledImageVertical(c,k,h);if(c.height>k){c=gs.html5.Canvas.createCroppedImage(c,c.width,k,i,a)}c=gs.html5.Canvas.createPaddedImage(c,b,k)}}}}}}if(f===gs.SGWrapMode.SGWrapFixed&&d===gs.SGWrapMode.SGWrapFixed){if(c.width>b&&c.height>k){c=gs.html5.Canvas.createCroppedImage(c,b,k,i,a)}else{if(c.width>b){c=gs.html5.Canvas.createCroppedImage(c,b,c.height,i,a);c=gs.html5.Canvas.createPaddedImage(c,b,k)}else{if(c.height>k){c=gs.html5.Canvas.createCroppedImage(c,c.width,k,i,a);c=gs.html5.Canvas.createPaddedImage(c,b,k)}else{c=gs.html5.Canvas.createPaddedImage(c,b,k)}}}}else{if(f===gs.SGWrapMode.SGWrapFixed&&d===gs.SGWrapMode.SGWrapScale){if(c.width>b){c=gs.html5.Canvas.createCroppedImage(c,b,c.height,i,a)}else{c=gs.html5.Canvas.createPaddedImage(c,b,c.height,i,a)}}else{if(f===gs.SGWrapMode.SGWrapScale&&d===gs.SGWrapMode.SGWrapFixed){if(c.height>k){c=gs.html5.Canvas.createCroppedImage(c,c.width,k,i,a)}else{c=gs.html5.Canvas.createPaddedImage(c,c.width,k,i,a)}}}}return c}};gs.SGCanvasHandleManager=function(){this.imageTintCache=new gs.SGCanvasImageTintCache()};gs.SGCanvasHandleManager.prototype={reset:function(){},releaseHandle:function(a){},getImageHandle:function(b){var a=new gs.SGCanvasImage(this.imageTintCache);a.reset();a.setResource(b);return a},getColorHandle:function(f,e,c,d){return new gs.SGCanvasColor(f,e,c,d)},getStringHandle:function(){return new gs.SGCanvasString()}};gs.SGCanvasImageTintCache=function(){this.imageResourceMap={};this.rCompromise=0;this.gCompromise=0;this.bCompromise=0;this.compromiseFactor=8};gs.SGCanvasImageTintCache.prototype.getTintedImage=function(e,c,f,i){var k=this.compromiseColor(c,f,i);if(!k){return e}var h=e.resource.id;var d=this.imageResourceMap[h];if(!d){d={};this.imageResourceMap[h]=d}var a=this.formatColorKey(this.rCompromise,this.gCompromise,this.bCompromise);var j=d[a];if(!j){j=gs.html5.Canvas.createTintedImage(e,c,f,i);d[a]=j}return j};gs.SGCanvasImageTintCache.prototype.formatColorKey=function(d,c,a){return((d*255)|0).toString(16)+","+((c*255)|0).toString(16)+","+((a*255)|0).toString(16)};gs.SGCanvasImageTintCache.prototype.compromiseColor=function(e,d,a){var c=this.compromiseFactor;if(e===1&&d===1&&a===1){return false}this.rCompromise=Math.round(e*c)/c;this.gCompromise=Math.round(d*c)/c;this.bCompromise=Math.round(a*c)/c;return true};gs.SGCanvasRenderer=function(a){this.canvas=a.canvas;this.context=this.canvas.getContext("2d");this.handleManager=new gs.SGCanvasHandleManager();this.fontPicker=new gs.html5.text.FontPicker();this.canvasWidth=this.canvas.width;this.canvasHeight=this.canvas.height;this.currentFont=null;this.particleImage=null;this.particleInverseTextureWidth=null;this.particleInverseTextureHeight=null;this.particleBlendMode=null};gs.SGCanvasRenderer.CompositeOperation={SOURCE_OVER:"source-over",LIGHTER:"lighter"};gs.SGCanvasRenderer.prototype={getRoot:function(){return this.canvas},getHandleManager:function(){return this.handleManager},setFillColorRGBA:function(f,e,c,d){this.context.fillStyle="rgba("+(f*100)+"%,"+(e*100)+"%,"+(c*100)+"%,"+d+")"},setFillColorArray:function(a){var b="rgba(";b+=(a[0]*100);b+="%,";b+=(a[1]*100);b+="%,";b+=(a[2]*100);b+="%,";b+=a[3];b+=")";this.context.fillStyle=b},setGlobalAlpha:function(a){if(a!==1){this.context.globalAlpha=a}},resetGlobalAlpha:function(){this.context.globalAlpha=1},setFont:function(a,b){this.currentFont=this.fontPicker.pickBestFont(a,b);this.context.font=this.currentFont.toCSS()},clear:function(d,c,a){this.setFillColorRGBA(d,c,a,1);this.context.fillRect(0,0,this.canvasWidth,this.canvasHeight)},beginScene:function(){this.canvasWidth=this.canvas.width;this.canvasHeight=this.canvas.height;this.resetGlobalAlpha()},endScene:function(){},updateSize:function(){},beginSpace:function(n,m,s,r,j,i){var h=this.context;var k=n;var z=n+s;var l=m;var q=m+r;var w=this.canvasWidth;var g=this.canvasHeight;h.save();if(s===0){s=0.000001}if(r===0){r=0.000001}var C=w/s;var B=0;var A=0;var v=g/r;var u=C*-n;var t=v*m+(g-(g*(g/r)));h.transform(C,B,A,v,u,t);var p=(z+k)*0.5;var o=(q+l)*0.5;h.translate(p,g-o);h.rotate(-i*gsMath.DEG2RAD);h.translate(-p,-(g-o))},endSpace:function(){this.context.restore()},pushMatrix:function(){this.context.save()},popMatrix:function(){this.context.restore()},transformPolar:function(d,e){var c=-d*gsMath.DEG2RAD;var b=Math.cos(c)*e;var a=Math.sin(c)*e;this.context.translate(b,a)},drawImage:function(l,c){var b=this.context;var k=l.x;var i=this.canvasHeight-l.y;var a=l.width;var m=l.height;var d=l.angleRad;var h=l.flipX||l.flipY;var g=(d===0&&!h);if(g){b.translate(k,i)}else{b.save();b.translate(k,i);b.rotate(d);if(h){b.scale(l.flipY?-1:1,l.flipX?-1:1)}}var f=l.colorA;var j=false;var e=gs.SGBlendingMode;switch(l.blendMode){case e.Normal:if(f<1){b.globalAlpha=f}break;case e.Multiply:b.globalAlpha=f;break;case e.Opaque:b.globalAlpha=1;break;case e.Additive:b.globalAlpha=f;b.globalCompositeOperation=gs.SGCanvasRenderer.CompositeOperation.LIGHTER;j=true;break;case e.Screen:b.globalAlpha=f;b.globalCompositeOperation=gs.SGCanvasRenderer.CompositeOperation.LIGHTER;j=true;break}b.drawImage(c.currentImage,0,0,c.imageWidth,c.imageHeight,-0.5*a,-0.5*m,a,m);if(g){b.translate(-k,-i);if(f<1){b.globalAlpha=1}if(j){b.globalCompositeOperation=gs.SGCanvasRenderer.CompositeOperation.SOURCE_OVER}}else{b.restore()}},drawImageWithWrap:function(a,b){this.drawImage(a,b)},drawRect:function(l){var b=this.context;var j=l.x;var i=l.y;var a=l.width;var m=l.height;var d=l.angleRad;var c=l.blendMode;var f=l.color;var e=f[3];if(e===0){return}if(a===0||m===0){return}if(c===gs.SGBlendingMode.Multiply){return}b.save();b.translate(j,this.canvasHeight-i);b.rotate(d);var g=a*0.5;var k=m*0.5;b.translate(-g,-k);this.setFillColorArray(f);switch(c){case gs.SGBlendingMode.Normal:this.setGlobalAlpha(e);break;case gs.SGBlendingMode.Opaque:this.setGlobalAlpha(1);break;case gs.SGBlendingMode.Additive:this.setGlobalAlpha(e);b.globalCompositeOperation="lighter";break;default:this.setGlobalAlpha(e);break}b.fillRect(0,0,a,m);b.restore()},drawText:function(r,m){var a=this.context;var g=r.x;var e=r.y;var q=r.sizePx;var A=r.fontFamily;var C=m;var u=r.color;var d=r.alignment;var B=r.angleRad;var f=r.wrap;var b=r.lineHeight;var n=f?(1+0.1*q):0;var s=Math.ceil(r.width-2*n);var p=Math.ceil(r.height-2*n);this.setFont(A,q);var o=r.textLines;var t=o?o.length:0;if(t===0){if(!f&&C.indexOf("\n")===-1){o=[C];r.wrapWidth=0;t=1}else{this.formatTextLines(r,C,s);o=r.textLines;t=o.length;if(f){r.wrapWidth=s}else{s=r.wrapWidth}}}if(r.wrapWidth){s=r.wrapWidth}a.save();if(u){this.setFillColorArray(u)}var c=0;a.textBaseline="middle";if(f){c=-((p-t*b)/2);a.textBaseline="top"}else{if(t>1){c=-0.5*t*b;a.textBaseline="top"}}var z=s*0.5;if(d===0){a.textAlign="left"}else{if(d===1){z=0;a.textAlign="center"}else{if(d===2){z=-z;a.textAlign="right"}}}var l=0;if(f){l=b*t*0.5}for(var w=0;w<t;++w){a.save();var k=c+w*b;if(B===0){a.translate(g,this.canvasHeight-e+k)}else{a.translate(g+Math.cos(Math.PI/2+B)*k,this.canvasHeight-(e-Math.sin(Math.PI/2+B)*k));a.rotate(B)}var j=o[w];a.fillText(j,Math.round(-z),Math.round(-l));a.restore()}a.restore()},formatTextLines:function(g,n,c){var e=this.context;var l=n.split(/\n/);var d=g.wrap;var m=0;for(var h=0;h<l.length;++h){var b=l[h];var f=e.measureText(b).width;if(f>m){m=f}var k=b;var a="";var j=-1;if(d){while((f>c)){j=k.lastIndexOf(" ");if(j===-1){break}a=k.substring(j)+a;k=k.substring(0,j);f=e.measureText(k).width}if(j!==-1){a=a.trim();k=k.trim();l.splice(h,1,k,a)}}}g.wrapWidth=m;g.textLines=l},beginParticles:function(c,d,a){var b=this.context;this.particleImage=c;this.particleBlendMode=d;if(a){var e=a[3];this.setFillColorArray(a);switch(d){case gs.SGBlendingMode.Normal:b.globalAlpha=e;break;case gs.SGBlendingMode.Opaque:b.globalAlpha=1;break;case gs.SGBlendingMode.Additive:b.globalAlpha=e;b.globalCompositeOperation="lighter";break;default:b.globalAlpha=e;break}}else{if(d===gs.SGBlendingMode.Additive){b.globalCompositeOperation="lighter"}}},drawParticle:function(b,g,f,e,c){var d=this.context;if(c){if(this.particleBlendMode!==gs.SGBlendingMode.Opaque){d.globalAlpha=c[3]}}d.translate(b,this.canvasHeight-g);if(f!==0){d.rotate(f)}var a=this.particleImage;if(a){d.drawImage(a.currentImage,0,0,a.imageWidth,a.imageHeight,-0.5*e,-0.5*e,e,e)}else{if(c){this.setFillColorArray(c)}d.fillRect(-0.5*e,-0.5*e,e,e)}if(f!==0){d.rotate(-f)}d.translate(-b,g-this.canvasHeight)},endParticles:function(){var a=this.context;a.globalAlpha=1;a.globalCompositeOperation=gs.SGCanvasRenderer.CompositeOperation.SOURCE_OVER}};gs.webgl.shaders={tint:{vertex:"attribute vec3 aPosition;attribute vec2 aTextureUV;uniform mat4 uPMatrix;uniform mat4 uMVMatrix;varying vec2 vTextureUV;void main(void) {	gl_Position = uPMatrix * uMVMatrix * vec4(aPosition, 1.0);	vTextureUV = aTextureUV;}",fragment:"precision mediump float;uniform sampler2D uTexture;uniform vec4 uTint;varying vec2 vTextureUV;void main(void) {	gl_FragColor = uTint * texture2D(uTexture, vTextureUV);}"},alpha:{vertex:"",fragment:""},white:{vertex:"",fragment:""},solid:{vertex:"",fragment:""},safe:{vertex:"attribute vec2 aPositionXY;attribute vec2 aTextureUV;uniform mat3 pMatrix;uniform mat3 mvMatrix;uniform vec2 uSizeXY;uniform vec4 uTextureSSTT;varying vec2 vTextureUV;void main(void) {	gl_Position = vec4(pMatrix * mvMatrix * vec3(aPositionXY * uSizeXY, 1.0), 1.0);	vTextureUV = aTextureUV * uTextureSSTT.yw + uTextureSSTT.xz;}",fragment:"precision lowp float;varying vec2 vTextureUV;uniform vec4 uTint;uniform sampler2D uTexture;void main(void) {	gl_FragColor = uTint * texture2D(uTexture, vTextureUV);}"}};gs.SGWebGLColor=function(f,e,c,d){this.isColorHandle=true;this.ready=true;this.color=gs.array.provide();this.color[0]=f;this.color[1]=e;this.color[2]=c;this.color[3]=d;this.blendingMode=null};gs.SGWebGLColor.prototype={update:function(a,c,b){this.color[0]=a[0];this.color[1]=a[1];this.color[2]=a[2];this.color[3]=a[3];this.blendingMode=b},release:function(){gs.array.recycle(this.color);this.color=null}};gs.SGWebGLImage=function(){this.isImageHandle=true;this.resource=null;this.ready=false;this.handleManager=null;this.tileWidth=0;this.tileHeight=0;this.isPowerOf2=false;this.waitingForPow2=false;this.texture=null;this.textureWidth=0;this.textureHeight=0;this.inverseTextureWidth=0;this.inverseTextureHeight=0;this.previousTextureU=1;this.previousTextureV=1};gs.Pool.init(gs.SGWebGLImage);gs.SGWebGLImage.prototype={setResource:function(a){this.resource=a;this.ready=false;this.checkReady()},checkReady:function(){if(!this.ready&&this.resource&&this.resource.ready){this.initFromResource()}},initFromResource:function(){var c=this.resource.width;var b=this.resource.height;this.textureWidth=c;this.textureHeight=b;this.inverseTextureWidth=1/c;this.inverseTextureHeight=1/b;if(this.waitingForPow2){this.waitingForPow2=false}else{this.originalWidth=c;this.originalHeight=b}this.texture=this.resource.texture;this.ready=true;var d=c;var a=b;while(d>1){d/=2}while(a>1){a/=2}this.isPowerOf2=(d===1&&a===1)},upsizeToPowerOf2Image:function(){this.ready=false;this.waitingForPow2=true;var b=this.resource.id;var a=gs.AssetManager.current.imageForNamePow2(b);this.setResource(a)},update:function(a){this.checkReady();this.tileWidth=a.tileWidth||this.originalWidth;this.tileHeight=a.tileHeight||this.originalHeight;if(this.ready&&!this.isPowerOf2&&(a.wrapModeS===2||a.wrapModeT===2)){this.upsizeToPowerOf2Image()}},release:function(){this.handleManager.releaseHandle(this)}};gs.SGWebGLString=function(){this.isStringHandle=true;this.ready=true;this.lineHeightFactor=1.35};gs.SGWebGLString.prototype={update:function(e,b,a,d,f,c){this.text=e;this.color=b;this.fontFamily=a;this.sizePx=d;this.alignment=f;this.wrap=c;this.lineHeight=d*this.lineHeightFactor}};gs.SGWebGLHandleManager=function(){};gs.SGWebGLHandleManager.prototype={reset:function(){},getImageHandle:function(b){var a=gs.SGWebGLImage.provide();a.handleManager=this;a.setResource(b);return a},getColorHandle:function(f,e,c,d){return new gs.SGWebGLColor(f,e,c,d)},getStringHandle:function(){return new gs.SGWebGLString()},releaseHandle:function(a){if(a instanceof gs.SGWebGLImage){gs.SGWebGLImage.recycle(a)}}};gs.SGWebGLRenderer=function(a){this.useFloat32Matrices=false;this.gl=null;this.maxTextureSize=0;this.canvas=a.webgl;this.canvasWidth=this.canvas.width;this.canvasHeight=this.canvas.height;this.frameCount=0;this.mvMatrix=null;this.onlyTranslate=null;this.mvMatrixStack=gs.array.provide();this.onlyTranslateStack=gs.array.provide();this.stackTop=-1;this.stackSize=0;this.p4Matrix=this.createMatrix();this.p3Matrix=this.createMatrix();this.f32mvMatrix=new Float32Array([1,0,0,0,1,0,0,0,1]);this.tempMultiplyMatrix=this.createMatrix();this.shaderProgram=null;this.tintColor=new Float32Array([-1,-1,-1,-1]);this.previous={bestCase:false,clearColor:new Float32Array([-1,-1,-1,-1]),tintColor:new Float32Array([-1,-1,-1,-1]),blendMode:null,texture:null,sizeXY:new Float32Array([-1,-1]),textureSSTT:new Float32Array([-1,-1,-1,-1]),isDefaultTextureSSTT:false};this.particleInverseTextureWidth=null;this.particleInverseTextureHeight=null;this.particleBlendMode=null;this.fontSprite=null;this.fontInverseTextureWidth=null;this.fontInverseTextureHeight=null;this.defaultVertexBuffer=null;this.defaultTextureCoordinateBuffer=null;this.defaultTextureSSTT=new Float32Array([0,1,0,1]);this.tempTextureCoordinateArray=new Float32Array(8);this.tintWhite=new Float32Array([1,1,1,1]);this.tintBlack=new Float32Array([0,0,0,1]);this.handleManager=new gs.SGWebGLHandleManager(this);this.fontPicker=new gs.html5.text.FontPicker();this.fontCache=gs.array.provide();this.initMatrixStack();this.init();gs.AssetManager.current.setRenderer(this);this.whiteImage=this.getHandleManager().getImageHandle(gs.AssetManager.current.white1x1)};gs.SGWebGLRenderer.prototype={transformPolar:function(d,e){var b=0;var a=0;switch(d){case 0:b=e;break;case -90:a=e;break;default:var c=d*-gsMath.DEG2RAD;b=Math.cos(c)*e;a=Math.sin(c)*e;if(Math.abs(b)<0.000001){b=0}if(Math.abs(a)<0.000001){a=0}break}this.translate(b,a)},beginScene:function(){this.whiteImage.checkReady();this.frameCount++;this.previous.texture=null;this.previous.bestCase=false;this.setBlendMode(0)},endScene:function(){if(gs.debug.renderFlush){this.gl.finish()}},beginSpace:function(m,l,r,q,i,h){var j=m;var w=m+r;var k=l;var p=l+q;var g=this.canvasHeight;var v=this.canvasWidth;this.pushMatrix();if(r===0){r=0.000001}if(q===0){q=0.000001}var B=v/r;var A=0;var z=0;var u=g/q;var t=B*-m;var s=u*l+(g-(g*(g/q)));this.setMatrix(B,A,z,u,t,s);var o=(w+j)*0.5;var n=(p+k)*0.5;this.translate(o,g-n);this.rotate(h*-gsMath.DEG2RAD);this.translate(-o,-(g-n))},endSpace:function(){this.popMatrix()},getRoot:function(){return this.canvas},getHandleManager:function(){return this.handleManager},clear:function(e,d,a){var f=this.gl;var c=this.previous.clearColor;if(e!==c[0]||d!==c[1]||a!==c[2]){f.clearColor(e,d,a,1);c[0]=e;c[1]=d;c[2]=a}f.clear(f.COLOR_BUFFER_BIT)},init:function(){var b=gs.webgl.getContext(this.canvas);this.gl=b;if(!b){gs.Log.fatal("Failed to initialize WebGL")}this.maxTextureSize=b.getParameter(b.MAX_TEXTURE_SIZE);b.enable(this.gl.BLEND);var a=new Float32Array([0.5,0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5]);this.defaultVertexBuffer=this.createBuffer(a,2,4);this.defaultTextureCoordinateBuffer=this.createTextureCoordinateBuffer(1,1);this.initShaders();this.setViewport(this.canvas.width,this.canvas.height);this.loadIdentityMatrix()},setMaterial:function(a,b){this.setTintArray(a,b);if(b!==this.previous.blendMode){var c=this.gl;this.previous.blendMode=b;switch(b){case 0:c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);break;case 1:c.blendFunc(c.ONE,c.ZERO);break;case 2:c.blendFunc(c.ONE,c.ONE);break;case 3:c.blendFunc(c.ONE,c.ONE_MINUS_SRC_COLOR);break;case 4:c.blendFunc(c.ZERO,c.SRC_COLOR);break}}},drawImage:function(j,a){var e=this.gl;var g=this.previous;var d=j.x;var c=this.canvasHeight-j.y;var i=j.angleRad;var k=j.width*a.inverseTextureWidth;var h=j.height*a.inverseTextureHeight;if(j.flipY){k*=-1}if(j.flipX){h*=-1}var b=(i===0&&k===1&&h===1);if(b){this.translate(d,c)}else{this.pushMatrix();this.translate(d,c);this.rotate(i);this.scale(k,h)}this.setMaterial(j.color,j.blendMode);this.setUniformTintFromMaterial();var f=this.setTexture(a.texture);if(f||!g.bestCase){this.setUniformSizeXY(a.textureWidth,a.textureHeight)}if(!g.bestCase){this.setUniformTextureSSTTToDefault()}this.setUniformMVMatrix();e.drawArrays(e.TRIANGLE_STRIP,0,4);this.previous.bestCase=true;if(b){this.translate(-d,-c)}else{this.popMatrix()}},drawImageWithWrap:function(x,f){var D=this.gl;var y=x.width;var u=x.height;var a=f.textureWidth;var v=f.textureHeight;var G=f.originalWidth;var A=f.originalHeight;var d=x.wrapModeS;var b=x.wrapModeT;var h=x.anchorS;var g=x.anchorT;var F=x.width*f.inverseTextureWidth;var E=x.height*f.inverseTextureHeight;var k=x.flipX;var i=x.flipY;if(i){F*=-1}if(k){E*=-1}var l=0;var j=0;var e=a;var c=v;var C=D.CLAMP_TO_EDGE;var B=D.CLAMP_TO_EDGE;var n=1;var w=1;if(d===2){C=D.REPEAT;e=y;n=a/f.tileWidth}else{if(d===1){if(G<=y){F=1}else{switch(h){case gs.SGAnchorMode.SGAnchorMax:l=a*(1-(y/G));e=a;break;case gs.SGAnchorMode.SGAnchorCenter:l=(a-y)*0.5;e=(a+y)*0.5;break;case gs.SGAnchorMode.SGAnchorMin:default:l=0;e=y*(a/G);break}}}}if(b===2){B=D.REPEAT;var z=u%v;j=-z;c=u-z;w=v/f.tileHeight}else{if(b===1){if(v<=u){E=1}else{switch(g){case gs.SGAnchorMode.SGAnchorMax:j=0;c=u*(v/A);break;case gs.SGAnchorMode.SGAnchorCenter:j=(v-u)/2;c=(v+u)/2;break;case gs.SGAnchorMode.SGAnchorMin:default:j=v*(1-u/A);c=v;break}}}}this.pushMatrix();this.translate(x.x,this.canvasHeight-x.y);this.rotate(x.angleRad);this.scale(F,E);if(n!==f.previousTextureU||w!==f.previousTextureV){f.previousTextureU=n;f.previousTextureV=w}var p=l*f.inverseTextureWidth;var r=(e-l)*f.inverseTextureWidth*f.previousTextureU;var o=1-(c*f.inverseTextureHeight);var q=(c-j)*f.inverseTextureHeight*f.previousTextureV;this.setMaterial(x.color,x.blendMode);this.setUniformTintFromMaterial();this.setTextureWithWrap(f.texture,C,B);this.setUniformTextureSSTT(p,r,o,q);this.setUniformSizeXY(f.textureWidth,f.textureHeight);this.setUniformMVMatrix();D.drawArrays(D.TRIANGLE_STRIP,0,4);this.popMatrix();this.previous.bestCase=false},setUniformTintFromMaterial:function(){var b=this.tintColor;var a=this.previous.tintColor;if(b[3]!==a[3]||b[0]!==a[0]||b[1]!==a[1]||b[2]!==a[2]){this.gl.uniform4fv(this.shaderProgram.tint,b)}},setUniformPMatrix:function(a){this.Matrix_flatten3x3to9(a,this.f32mvMatrix);this.gl.uniformMatrix3fv(this.shaderProgram.pMatrix,false,this.f32mvMatrix)},setUniformMVMatrix:function(){this.Matrix_flatten3x3to9(this.mvMatrix,this.f32mvMatrix);this.gl.uniformMatrix3fv(this.shaderProgram.mvMatrix,false,this.f32mvMatrix)},setTextureWithWrap:function(d,b,a){var c=this.previous;if(d!==c.texture){var e=this.gl;e.bindTexture(e.TEXTURE_2D,d);c.texture=d;if(d.previousWrapS!==b){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,b);d.previousWrapS=b}if(d.previousWrapT!==a){e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,a);d.previousWrapT=a}return true}return false},setTexture:function(b){var a=this.previous;if(b!==a.texture){var c=this.gl;c.bindTexture(c.TEXTURE_2D,b);a.texture=b;if(b.previousWrapS!==c.CLAMP_TO_EDGE){c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);b.previousWrapS=c.CLAMP_TO_EDGE}if(b.previousWrapT!==c.CLAMP_TO_EDGE){c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);b.previousWrapT=c.CLAMP_TO_EDGE}return true}return false},setUniformTextureSSTT:function(c,e,b,d){var a=this.previous.textureSSTT;a[0]=c;a[1]=e;a[2]=b;a[3]=d;this.gl.uniform4fv(this.shaderProgram.textureSSTT,a);this.previous.isDefaultTextureSSTT=false},setUniformTextureSSTTToDefault:function(){if(!this.previous.isDefaultTextureSSTT){this.gl.uniform4fv(this.shaderProgram.textureSSTT,this.defaultTextureSSTT);this.previous.isDefaultTextureSSTT=true}},setUniformSizeXY:function(b,a){var c=this.previous.sizeXY;if(b!==c[0]||a!==c[1]){c[0]=b;c[1]=a;this.gl.uniform2fv(this.shaderProgram.sizeXY,c)}},beginParticles:function(b,c,a){var d=this.gl;if(!b){b=this.whiteImage}this.particleInverseTextureWidth=b.inverseTextureWidth;this.particleInverseTextureHeight=b.inverseTextureHeight;this.particleBlendMode=c;if(a){this.setMaterial(a,c);this.setUniformTintFromMaterial()}else{this.setBlendMode(c)}this.setTexture(b.texture);this.setUniformSizeXY(b.textureWidth,b.textureHeight);this.setUniformTextureSSTTToDefault()},drawParticle:function(i,h,l,m,b){var g=this.gl;var a=this.shaderProgram;var c=this.f32mvMatrix;var k=m*this.particleInverseTextureWidth;var j=m*this.particleInverseTextureHeight;if(b){this.setTintArray(b,this.particleBlendMode);g.uniform4fv(a.tint,this.tintColor)}var f=i;var d=this.canvasHeight-h;this.pushMatrix();if(this.onlyTranslate){var e=this.mvMatrix;e[0][2]+=f;e[1][2]+=d;e[0][0]*=k;e[1][1]*=j;this.rotate(l)}else{this.translate(f,d);this.rotate(l);this.scale(k,j)}this.Matrix_flatten3x3to9(this.mvMatrix,c);g.uniformMatrix3fv(a.mvMatrix,false,c);g.drawArrays(g.TRIANGLE_STRIP,0,4);this.popMatrix()},endParticles:function(){this.previous.bestCase=true},beginGlyphs:function(b,a){this.fontSprite=b;this.fontInverseTextureWidth=b.inverseTextureWidth;this.fontInverseTextureHeight=b.inverseTextureHeight;this.setMaterial(a,0);this.setUniformTintFromMaterial();this.setTexture(this.fontSprite.texture)},drawGlyph:function(f,d,g,b){var e=this.gl;var i=f*this.fontInverseTextureWidth;var c=g*this.fontInverseTextureWidth;var h=d*this.fontInverseTextureHeight;var a=b*this.fontInverseTextureHeight;this.setUniformTextureSSTT(i,c,h,a);this.setUniformSizeXY(g,b);this.setUniformMVMatrix();e.drawArrays(e.TRIANGLE_STRIP,0,4)},drawGlyphTexture:function(a){var b=this.gl;this.setTexture(a.texture);this.setUniformTextureSSTTToDefault();this.setUniformSizeXY(a.textureWidth,a.textureHeight);this.setUniformMVMatrix();b.drawArrays(b.TRIANGLE_STRIP,0,4);this.setTexture(this.fontSprite.texture)},endGlyphs:function(){this.previous.bestCase=false},drawRect:function(c){var g=this.gl;var e=this.whiteImage;var b=c.x;var a=this.canvasHeight-c.y;var f=c.angleRad;var d=(f===0);if(d){this.translate(b,a)}else{this.pushMatrix();this.translate(b,a);this.rotate(f)}this.setMaterial(c.color,c.blendMode);this.setUniformTintFromMaterial();this.setTexture(e.texture);this.setUniformTextureSSTTToDefault();this.setUniformSizeXY(c.width,c.height);this.setUniformMVMatrix();if(d){this.translate(-b,-a)}else{this.popMatrix()}g.drawArrays(g.TRIANGLE_STRIP,0,4);this.previous.bestCase=true},getFontRenderer:function(a,c){var d=this.fontPicker.pickBestFont(a,c).toCSS();if(d in this.fontCache){return this.fontCache[d]}var b=new gs.FontRenderer(this,d,c);this.fontCache[d]=b;return b},drawText:function(d,c){var b=this.getFontRenderer(d.fontFamily,d.sizePx);this.beginGlyphs(b.sprite,d.color);var a=b.drawText(c,d.alignment,d.x,this.canvasHeight-d.y,d.width,d.height,d.angleRad,d.sizePx,d.wrap);this.endGlyphs();return a},primeTexture:function(a){var b=this.gl;this.setMaterial(this.tintWhite,0);this.setUniformTintFromMaterial();this.setTexture(a.texture);this.setUniformSizeXY(a.width,a.height);this.setUniformTextureSSTTToDefault();this.setUniformMVMatrix();b.drawArrays(b.TRIANGLE_STRIP,0,4);this.previous.bestCase=false},drawBlank:function(){var b=this.gl;var a=this.whiteImage;this.pushMatrix();this.translate(this.canvasWidth*0.5,this.canvasHeight*0.5);this.setMaterial(this.tintBlack,0);this.setUniformTintFromMaterial();this.setTexture(a.texture);this.setUniformTextureSSTTToDefault();this.setUniformSizeXY(this.canvasWidth,this.canvasHeight);this.setUniformMVMatrix();this.popMatrix();b.drawArrays(b.TRIANGLE_STRIP,0,4);this.previous.bestCase=false},updateSize:function(){this.canvasWidth=this.canvas.width;this.canvasHeight=this.canvas.height;this.setViewport(this.canvas.width,this.canvas.height)},createMatrix:function(){if(this.useFloat32Matrices){var a=[new Float32Array(4),new Float32Array(4),new Float32Array(4),new Float32Array(4)];this.Matrix_identity4x4(a);return a}else{return[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]}},initMatrixStack:function(){this.stackSize=16;for(var a=0;a<this.stackSize;a++){this.mvMatrixStack[a]=this.createMatrix();this.onlyTranslateStack[a]=true}this.stackTop=0;this.mvMatrix=this.mvMatrixStack[this.stackTop];this.onlyTranslate=this.onlyTranslateStack[this.stackTop]},pushMatrix:function(){this.onlyTranslateStack[this.stackTop]=this.onlyTranslate;this.stackTop++;var a=this.mvMatrixStack[this.stackTop];this.Matrix_copy3x3(this.mvMatrix,a);this.mvMatrix=a},popMatrix:function(){this.stackTop--;this.mvMatrix=this.mvMatrixStack[this.stackTop];this.onlyTranslate=this.onlyTranslateStack[this.stackTop]},loadIdentityMatrix:function(){this.Matrix_identity4x4(this.mvMatrix)},multiplyMatrix:function(a){var c=this.mvMatrix;var b=this.tempMultiplyMatrix;this.Matrix_multiply3x3(c,a,b);this.mvMatrix=b;this.mvMatrixStack[this.stackTop]=b;this.tempMultiplyMatrix=c},multiplyMatrixTranslate:function(a,d){var c=this.mvMatrix;var b=this.tempMultiplyMatrix;this.Matrix_multiply3x3_translate(c,a,d,b);this.mvMatrix=b;this.mvMatrixStack[this.stackTop]=b;this.tempMultiplyMatrix=c},multiplyMatrixRotate:function(c){var b=this.mvMatrix;var a=this.tempMultiplyMatrix;this.Matrix_multiply3x3_rotate(b,c,a);this.mvMatrix=a;this.mvMatrixStack[this.stackTop]=a;this.tempMultiplyMatrix=b},multiplyMatrixScale:function(d,c){var b=this.mvMatrix;var a=this.tempMultiplyMatrix;this.Matrix_multiply3x3_scale(b,d,c,a);this.mvMatrix=a;this.mvMatrixStack[this.stackTop]=a;this.tempMultiplyMatrix=b},translate:function(b,c){if(this.onlyTranslate){var a=this.mvMatrix;a[0][2]+=b;a[1][2]+=c}else{this.multiplyMatrixTranslate(b,c)}},rotate:function(a){if(a===0){return}this.multiplyMatrixRotate(a);this.onlyTranslate=false},scale:function(c,b){if(c===1&&b===1){return}if(this.onlyTranslate){var a=this.mvMatrix;a[0][0]*=c;a[1][1]*=b}else{this.multiplyMatrixScale(c,b);this.onlyTranslate=false}},getShader:function(b,c){var e=this.gl;var d=e.createShader(c);var a=null;if(c===e.VERTEX_SHADER){a=gs.webgl.shaders[b].vertex}else{if(c===e.FRAGMENT_SHADER){a=gs.webgl.shaders[b].fragment}}e.shaderSource(d,a);e.compileShader(d);if(!e.getShaderParameter(d,e.COMPILE_STATUS)){gs.Log.error(e.getShaderInfoLog(d));return null}return d},createShaderProgram:function(){var b=this.gl;var a=b.createProgram();b.attachShader(a,this.getShader("safe",b.VERTEX_SHADER));b.attachShader(a,this.getShader("safe",b.FRAGMENT_SHADER));b.linkProgram(a);if(!b.getProgramParameter(a,b.LINK_STATUS)){gs.Log.error(b.getProgramInfoLog(a))}return a},createBuffer:function(e,c,b){var d=this.gl;var a=d.createBuffer();d.bindBuffer(d.ARRAY_BUFFER,a);d.bufferData(d.ARRAY_BUFFER,e,d.STATIC_DRAW);a.itemSize=c;a.itemCount=b;return a},createTextureCoordinateBuffer:function(b,a){var c=this.tempTextureCoordinateArray;c[0]=b;c[1]=0;c[2]=0;c[3]=0;c[4]=b;c[5]=a;c[6]=0;c[7]=a;return this.createBuffer(c,2,4)},initShaders:function(){var a=this.gl;this.shaderProgram=this.createShaderProgram();a.useProgram(this.shaderProgram);this.shaderProgram.positionXY=a.getAttribLocation(this.shaderProgram,"aPositionXY");a.enableVertexAttribArray(this.shaderProgram.positionXY);this.shaderProgram.textureUV=a.getAttribLocation(this.shaderProgram,"aTextureUV");a.enableVertexAttribArray(this.shaderProgram.textureUV);this.shaderProgram.pMatrix=a.getUniformLocation(this.shaderProgram,"pMatrix");this.shaderProgram.mvMatrix=a.getUniformLocation(this.shaderProgram,"mvMatrix");this.shaderProgram.sizeXY=a.getUniformLocation(this.shaderProgram,"uSizeXY");this.shaderProgram.textureSSTT=a.getUniformLocation(this.shaderProgram,"uTextureSSTT");this.shaderProgram.texture=a.getUniformLocation(this.shaderProgram,"uTexture");this.shaderProgram.tint=a.getUniformLocation(this.shaderProgram,"uTint");a.activeTexture(a.TEXTURE0);a.uniform1i(this.shaderProgram.texture,0);a.bindBuffer(a.ARRAY_BUFFER,this.defaultVertexBuffer);a.vertexAttribPointer(this.shaderProgram.positionXY,this.defaultVertexBuffer.itemSize,a.FLOAT,false,0,0);a.bindBuffer(a.ARRAY_BUFFER,this.defaultTextureCoordinateBuffer);a.vertexAttribPointer(this.shaderProgram.textureUV,this.defaultTextureCoordinateBuffer.itemSize,a.FLOAT,false,0,0)},setMatrix:function(h,g,l,k,j,i){this.mvMatrix[0][0]=h;this.mvMatrix[1][0]=g;this.mvMatrix[2][0]=0;this.mvMatrix[0][1]=l;this.mvMatrix[1][1]=k;this.mvMatrix[2][1]=0;this.mvMatrix[0][2]=j;this.mvMatrix[1][2]=i;this.mvMatrix[2][2]=1;if(h!==1||g!==0||l!==0||k!==1){this.onlyTranslate=false}},setTintArray:function(a,b){var c=this.previous.tintColor;this.previous.tintColor=this.tintColor;this.tintColor=c;c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];if(b===0||b===3){c[0]*=a[3];c[1]*=a[3];c[2]*=a[3]}else{if(b===2){c[0]*=a[3];c[1]*=a[3];c[2]*=a[3]}}},setBlendMode:function(a){if(a!==this.previous.blendMode){var b=this.gl;this.previous.blendMode=a;switch(a){case 0:b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);break;case 1:b.blendFunc(b.ONE,b.ZERO);break;case 2:b.blendFunc(b.ONE,b.ONE);break;case 3:b.blendFunc(b.ONE,b.ONE_MINUS_SRC_COLOR);break;case 4:b.blendFunc(b.ZERO,b.SRC_COLOR);break}}},setAlpha:function(b){this.tintColor[3]=b},setViewport:function(b,a){this.gl.viewport(0,0,b,a);this.makeOrtho(0,b,a,0,1,-1,this.p4Matrix);this.Matrix_copy4x4to3x3(this.p4Matrix,this.p3Matrix);this.setUniformPMatrix(this.p3Matrix)},height:function(){return this.canvasHeight},width:function(){return this.canvasWidth},isImageTooLarge:function(b){var a=Math.max(b.width,b.height);return a>this.maxTextureSize}};gs.SGWebGLRenderer.prototype.Matrix_multiply4x4=function(s,q,d){var g=4,h=g,m,e,f=4,k;var p=4,n,l,o;do{m=h-g;e=f;do{k=f-e;n=0;l=p;do{o=p-l;n+=s[m][o]*q[o][k]}while(--l);d[m][k]=n}while(--e)}while(--g)};gs.SGWebGLRenderer.prototype.Matrix_copy4x4=function(d,c){c[0][0]=d[0][0];c[0][1]=d[0][1];c[0][2]=d[0][2];c[0][3]=d[0][3];c[1][0]=d[1][0];c[1][1]=d[1][1];c[1][2]=d[1][2];c[1][3]=d[1][3];c[2][0]=d[2][0];c[2][1]=d[2][1];c[2][2]=d[2][2];c[2][3]=d[2][3];c[3][0]=d[3][0];c[3][1]=d[3][1];c[3][2]=d[3][2];c[3][3]=d[3][3]};gs.SGWebGLRenderer.prototype.Matrix_multiply3x3=function(d,c,e){e[0][0]=d[0][0]*c[0][0]+d[0][1]*c[1][0];e[0][1]=d[0][0]*c[0][1]+d[0][1]*c[1][1];e[0][2]=d[0][0]*c[0][2]+d[0][1]*c[1][2]+d[0][2];e[1][0]=d[1][0]*c[0][0]+d[1][1]*c[1][0];e[1][1]=d[1][0]*c[0][1]+d[1][1]*c[1][1];e[1][2]=d[1][0]*c[0][2]+d[1][1]*c[1][2]+d[1][2]};gs.SGWebGLRenderer.prototype.Matrix_multiply3x3_translate=function(c,b,e,d){d[0][0]=c[0][0];d[0][1]=c[0][1];d[0][2]=c[0][0]*b+c[0][1]*e+c[0][2];d[1][0]=c[1][0];d[1][1]=c[1][1];d[1][2]=c[1][0]*b+c[1][1]*e+c[1][2]};gs.SGWebGLRenderer.prototype.Matrix_multiply3x3_rotate=function(b,f,e){var g=Math.cos(f);var d=Math.sin(f);e[0][0]=b[0][0]*g+b[0][1]*d;e[0][1]=b[0][0]*-d+b[0][1]*g;e[0][2]=b[0][2];e[1][0]=b[1][0]*g+b[1][1]*d;e[1][1]=b[1][0]*-d+b[1][1]*g;e[1][2]=b[1][2]};gs.SGWebGLRenderer.prototype.Matrix_multiply3x3_scale=function(b,e,d,c){c[0][0]=b[0][0]*e;c[0][1]=b[0][1]*d;c[0][2]=b[0][2];c[1][0]=b[1][0]*e;c[1][1]=b[1][1]*d;c[1][2]=b[1][2]};gs.SGWebGLRenderer.prototype.Matrix_copy3x3=function(d,c){c[0][0]=d[0][0];c[0][1]=d[0][1];c[0][2]=d[0][2];c[1][0]=d[1][0];c[1][1]=d[1][1];c[1][2]=d[1][2]};gs.SGWebGLRenderer.prototype.Matrix_copy3x3to4x4=function(d,c){c[0][0]=d[0][0];c[0][1]=d[0][1];c[0][3]=d[0][2];c[1][0]=d[1][0];c[1][1]=d[1][1];c[1][3]=d[1][2];c[2][0]=d[2][0];c[2][1]=d[2][1];c[3][3]=d[2][2]};gs.SGWebGLRenderer.prototype.Matrix_copy4x4to3x3=function(d,c){c[0][0]=d[0][0];c[0][1]=d[0][1];c[0][2]=d[0][3];c[1][0]=d[1][0];c[1][1]=d[1][1];c[1][2]=d[1][3];c[2][0]=d[2][0];c[2][1]=d[2][1];c[2][2]=d[3][3]};gs.SGWebGLRenderer.prototype.Matrix_identity4x4=function(a){a[0][0]=1;a[0][1]=0;a[0][2]=0;a[0][3]=0;a[1][0]=0;a[1][1]=1;a[1][2]=0;a[1][3]=0;a[2][0]=0;a[2][1]=0;a[2][2]=1;a[2][3]=0;a[3][0]=0;a[3][1]=0;a[3][2]=0;a[3][3]=1};gs.SGWebGLRenderer.prototype.Matrix_flatten4x4to16=function(d,c){c[0]=d[0][0];c[1]=d[1][0];c[2]=d[2][0];c[3]=d[3][0];c[4]=d[0][1];c[5]=d[1][1];c[6]=d[2][1];c[7]=d[3][1];c[8]=d[0][2];c[9]=d[1][2];c[10]=d[2][2];c[11]=d[3][2];c[12]=d[0][3];c[13]=d[1][3];c[14]=d[2][3];c[15]=d[3][3]};gs.SGWebGLRenderer.prototype.Matrix_flatten3x3to16=function(d,c){c[0]=d[0][0];c[1]=d[1][0];c[4]=d[0][1];c[5]=d[1][1];c[12]=d[0][2];c[13]=d[1][2]};gs.SGWebGLRenderer.prototype.Matrix_flatten3x3to9=function(d,c){c[0]=d[0][0];c[1]=d[1][0];c[3]=d[0][1];c[4]=d[1][1];c[6]=d[0][2];c[7]=d[1][2]};gs.SGWebGLRenderer.prototype.makeOrtho=function(c,i,b,h,j,g,a){var f=-(i+c)/(i-c);var e=-(h+b)/(h-b);var d=-(g+j)/(g-j);a[0][0]=2/(i-c);a[0][3]=f;a[1][1]=2/(h-b);a[1][3]=e;a[2][2]=-2/(g-j);a[2][3]=d;a[3][3]=1};gs.FontRenderer=function(b,c,a){this.sizeToFontHeightRatio=1.5;this.sizetoLineHeightRatio=1.35;this.renderContext=b;this.glyphData=gs.array.provide();this.rareData=gs.Map.provide();this.sprite=null;this.spaceChar=" ".charCodeAt(0);this.tabChar="\t".charCodeAt(0);this.spaceWidth=0;this.tabWidth=0;this.fontCSS=c;this.sizePx=a;this.fontHeight=Math.ceil(a*this.sizeToFontHeightRatio);this.lineHeight=Math.ceil(a*this.sizetoLineHeightRatio);this.generateFontMap(c,a)};gs.FontRenderer.prototype={drawText:function(g,c,f,d,m,k,o,l,e){var b=this.renderContext;b.pushMatrix();b.translate(f,d);b.rotate(o);var j=false;var a;if(Array.isArray(g)){a=g}else{a=this.splitLines(g);if(!Array.isArray(a)){j=true;var p=gs.array.provide();p[0]=a;a=p}}var h=1+0.1*l;if(e){h=1+0.1*l;this.wrapLinesInPlace(a,m-2*h)}var n=this.calculateMaxStringWidthPx(a);var i=this.calculateLinesHeightPx(a);var r=0;if(c===1||c==="center"){r=-0.5*n}else{if(c===2||c==="right"){r=0.5*m-n-h}else{r=-0.5*m+h}}var q=d;if(e){q=-0.5*k+h}else{q=-0.5*i}q=Math.ceil(q+l/8);this.drawLines(a,c,r,q,n);b.popMatrix();if(j){gs.array.recycle(a);a=null}return a},drawLines:function(j,d,f,e,a){var b=this.renderContext;b.translate(f,e);var g=this.lineHeight;for(var c=0,h=j.length;c<h;c++){this.drawLine(j[c],d,a);b.translate(0,g)}},drawLine:function(l,g,f){var a=this.renderContext;var k=this.glyphData;var o=this.fontHeight;var b=this.lineHeight;var d=this.calculateStringWidthPx(l);var r=0;if(g===1||g==="center"){r=0.5*(f-d)}else{if(g===2||g==="right"){r=f-d}else{r=0}}a.pushMatrix();a.translate(Math.round(r),Math.round(0.5*o));var u=l.length;for(var q=0;q<u;q++){var v=l.charCodeAt(q);var e=(v-32)*3;if(0<=e&&e+2<k.length){var n=k[e];var h=k[e+1];var t=0.5*h;var m=k[e+2];a.translate(t,0);a.drawGlyph(n-1,m,h+2,o);a.translate(t,0)}else{if(v===this.spaceChar){a.translate(this.spaceWidth,0)}else{if(v===this.tabChar){a.translate(this.tabWidth,0)}else{if(!this.rareData[v]){this.genRareChar(this.fontCSS,this.sizePx,v)}var j=this.rareData[v];var p=j.sprite;var h=j.width;var t=0.5*h;a.translate(t,0);p.checkReady();if(p.ready){a.drawGlyphTexture(p)}a.translate(t,0)}}}}a.popMatrix()},calculateStringWidthPx:function(f){var b=0;var a=f.length;var h=this.glyphData;for(var e=0;e<a;e++){var g=f.charCodeAt(e);var d=(g-32)*3;if(0<=d&&d+2<h.length){b+=h[d+1]}else{if(!this.rareData[g]){this.genRareChar(this.fontCSS,this.sizePx,g)}else{b+=this.rareData[g].width}}}return b},calculateMaxStringWidthPx:function(a){var d=0;for(var b=0,c=a.length;b<c;b++){var e=this.calculateStringWidthPx(a[b]);d=Math.max(d,e)}return d},calculateLinesHeightPx:function(b){var c=this.fontHeight;var a=b.length;if(a>1){c+=(a-1)*this.lineHeight}return c},generateFontMap:function(w,t){var x;var B;var v=new gs.html5.GraphicsBuffer();var d=v.context;d.font=w;d.textBaseline="top";var h=3;var s=this.fontHeight;var n=32;var g=127;var m=8;var C=12;var r=gs.array.provide();var j=gs.array.provide();var q=gs.array.provide();var p="00";var D=d.measureText(p).width;var y=h;var z=y;var u=s*m;var f=0;for(x=n;x<g;x++){B=String.fromCharCode(x);r[x]=B;var l="0"+B+"0";var o=d.measureText(l).width;j[x]=o-D;y+=j[x]+h;f=(f+1)%C;if(f===0){if(y>z){z=y}e=h;y=h}}v.canvas.width=z;v.canvas.height=u;d.font=w;d.textBaseline="top";d.fillStyle="transparent";d.fillRect(0,0,z,u);d.fillStyle="black";var e=h;var b=0;f=0;for(x=n;x<g;x++){B=r[x];d.fillText(B,e,b);q.push(e);q.push(j[x]);var k=s*(m-1)-b;q.push(k);e+=j[x]+h;f=(f+1)%C;if(f===0){e=h;b+=s}}var A=" ";var E=A.charCodeAt(0);this.spaceWidth=j[E];this.tabWidth=4*this.spaceWidth;d.fillStyle="white";d.globalCompositeOperation="source-atop";d.fillRect(0,0,z,u);var a=gs.ImageResource.createFromCanvas(v.canvas);a.id="font:"+w;a.createTexture(this.renderContext.gl);a.releaseImageElement();this.sprite=this.renderContext.getHandleManager().getImageHandle(a);this.glyphData=q},genRareChar:function(i,c,k){var h=new gs.html5.GraphicsBuffer();var a=h.context;a.font=i;a.textBaseline="top";var b=this.fontHeight;var j={width:null,sprite:null};var d=String.fromCharCode(k);j.width=a.measureText(d).width;this.rareData[k]=j;a.canvas.width=j.width;a.canvas.height=b;a.fillStyle="transparent";a.fillRect(0,0,j.width,b);var g=0;var f=0;a.fillStyle="black";a.font=i;a.textBaseline="top";a.fillText(d,g,f);a.fillStyle="white";a.globalCompositeOperation="source-atop";a.fillRect(0,0,j.width,b);var e=gs.ImageResource.createFromCanvas(h.canvas);e.id="char:"+d+i;e.createTexture(this.renderContext.gl);e.releaseImageElement();this.rareData[k].sprite=this.renderContext.getHandleManager().getImageHandle(e)},splitLines:function(a){if(a.indexOf("\n")===-1){return a}return a.split("\n")},wrapLinesInPlace:function(b,c){var a=b.length;var e;for(e=0;e<a;e++){b[e]=this.wrapString(b[e],c)}for(e=0;e<b.length;e++){var f=this.splitLines(b[e]);if(Array.isArray(f)){b.splice(e,1);for(var d=0;d<f.length;d++){b.splice(e+d,0,f[d])}e+=f.length-1;gs.array.recycle(f)}}return b},wrapString:function(m,g){var l=this.calculateStringWidthPx(m);if(l<=g){return m}else{var h=m.split(/\s+/g);var e=h.length;var b=this.spaceWidth;var a=h[0];var f=a;var c=this.calculateStringWidthPx(a);for(var d=1;d<e;d++){a=h[d];var j=this.calculateStringWidthPx(a);var k=j+b;if(c+k>g){f+="\n";f+=a;c=j}else{f+=" ";f+=a;c+=k}}gs.array.recycle(h);return f}}};gs.GS_COLLISION_SHAPE_ID=1;gs.GS_SENSOR_SHAPE_ID=2;gs.ActorUserData=function(){this.actorID=null;if(this.collisionCategories){this.collisionCategories.length=0}else{this.collisionCategories=gs.array.provide()}};gs.Pool.init(gs.ActorUserData);gs.ActorUserData.prototype.setActorID=function(a){this.actorID=a};gs.ActorUserData.prototype.addCollisionCategory=function(a){this.collisionCategories.push(a)};gs.ActorUserData.prototype.removeCollisionCategory=function(b){var a=this.collisionCategories.indexOf(b);if(a>-1){this.collisionCategories.splice(a,1)}};gs.FixtureUserData=function(){this.fixtureID=null;if(this.collisionMask){this.collisionMask.length=0}else{this.collisionMask=gs.array.provide()}};gs.Pool.init(gs.FixtureUserData);gs.FixtureUserData.prototype.setFixtureID=function(a){this.fixtureID=a};gs.FixtureUserData.prototype.addCollisionMaskCategory=function(a){this.collisionMask.push(a)};gs.FixtureUserData.prototype.removeCollisionMaskCategory=function(b){var a=this.collisionMask.indexOf(b);if(a>-1){this.collisionMask.splice(a,1)}};gs.ContactListener={m_collidingShapes:[],getContactCount:function(){return this.m_collidingShapes.length}};gs.ContactListener.m_collidingShapes.find=function(a,d){var c;for(var b=0;b<this.length;++b){c=this[b];if(c.equivalentTo(a,d)){return c}}return null};gs.ContactListener.m_collidingShapes.add=function(a,d,b){var c=gs.FixturePair.provide(a,d);c.collideCount=b;this.push(c)};gs.ContactListener.m_collidingShapes.erase=function(b){var a=this.indexOf(b);gs.FixturePair.recycle(this[a]);this.splice(a,1);return null};gs.FixturePair=function(a,b){this.fixtureA=a;this.fixtureB=b;this.collideCount=0};gs.FixturePair.pool=[];gs.FixturePair.recycle=function(a){a.fixtureA=null;a.fixtureB=null;gs.FixturePair.pool.push(a)};gs.FixturePair.provide=function(a,c){if(gs.FixturePair.pool.length>0){var b=gs.FixturePair.pool.pop();gs.FixturePair.call(b,a,c);return b}return new gs.FixturePair(a,c)};gs.FixturePair.prototype={equivalentTo:function(a,b){if(this.fixtureA===a){return(this.fixtureB===b)}if(this.fixtureB===a){return(this.fixtureA===b)}return false}};gs.ContactListener.getSensorFixture=function(a){var b=a.fixtureList.GetFirstNode();while(b&&(b.fixture.GetUserData().fixtureID!==gs.GS_SENSOR_SHAPE_ID)){b=b.GetNextNode()}return b?b.fixture:null};gs.ContactListener.BeginContact=function(b){var a=b.m_fixtureA;var f=b.m_fixtureB;if(a.GetUserData().fixtureID!==gs.GS_SENSOR_SHAPE_ID){var d=this.getSensorFixture(a.m_body);if(!d){return}}if(f.GetUserData().fixtureID!==gs.GS_SENSOR_SHAPE_ID){var c=this.getSensorFixture(f.m_body);if(!c){return}}var e=this.m_collidingShapes.find(a,f);if(e===null){this.fixtureCollisionBegan(a,f);this.m_collidingShapes.add(a,f,1);return}++e.collideCount};gs.ContactListener.EndContact=function(b){var a=b.m_fixtureA;var d=b.m_fixtureB;var c=this.m_collidingShapes.find(a,d);if(c===null){return}if((--c.collideCount)===0){this.fixtureCollisionEnded(a,d);this.m_collidingShapes.erase(c)}};gs.ContactListener.PreSolve=function(a,b){};gs.ContactListener.PostSolve=function(a,b){};gs.ContactFilter={};gs.ContactFilter.hasIntersection=function(d,b){if(d.length===0||b.length===0){return false}for(var c=0;c<d.length;c++){for(var a=0;a<b.length;a++){if(b[a]===d[c]){return true}}}return false};gs.ContactFilter.ShouldCollide=function(b,g){var c=b.GetUserData();var a=g.GetUserData();if(c.fixtureID===a.fixtureID){var e=b.m_body.GetUserData();var d=g.m_body.GetUserData();var f=(gs.ContactFilter.hasIntersection(c.collisionMask,d.collisionCategories)||gs.ContactFilter.hasIntersection(a.collisionMask,e.collisionCategories));return f}return false};gs.ContactListener.fixtureCollisionBegan=function(j,g){var k=gs.Game.current;var a=k.getCurrentScene()._collisionController;var h=j.m_body.GetUserData().actorID;var f=g.m_body.GetUserData().actorID;var c=a.getActorFromActorID(h);var b=a.getActorFromActorID(f);if(!c||!b){return}var e=a.delegatesForActorCollisionPair(c,b);for(var d=0;d<e.length;++d){e[d].collisionBegan(c,b)}};gs.ContactListener.fixtureCollisionEnded=function(k,h){var l=gs.Game.current;var f=l.getCurrentScene();var a;if(f){a=f._collisionController}if(!f||!a){return}var j=k.m_body.GetUserData().actorID;var g=h.m_body.GetUserData().actorID;var c=a.getActorFromActorID(j);var b=a.getActorFromActorID(g);if(!c||!b){return}var e=a.delegatesForActorCollisionPair(c,b);for(var d=0;d<e.length;++d){e[d].collisionEnded(c,b)}};gs.physicsLib=(function(){var a=window.Box2D;if(a===undefined){a=window}var j=500;var h=50;var b=1/h;var e=new a.Common.Math.b2Vec2(0,0);var g=new a.Collision.Shapes.b2CircleShape(0);var f=new a.Collision.Shapes.b2PolygonShape();var c=new a.Dynamics.b2FixtureDef();var k=new a.Dynamics.b2BodyDef();var d=function(){};d.SIMULATION_BORDER=j;d.BOX2D_TO_GS=h;d.GS_TO_BOX2D=b;d.DYNAMIC_BODY=a.Dynamics.b2BodyDef.b2_dynamicBody;d.STATIC_BODY=a.Dynamics.b2BodyDef.b2_staticBody;d.World=function(o,m,q){var p=a.Common.Math.b2Vec2.Get(o*b,m*b);var n=a.Dynamics.b2World.Get(p,q);a.Common.Math.b2Vec2.Free(p);n.SetContactListener(gs.ContactListener);n.SetContactFilter(gs.ContactFilter);this._world=n;return this};d.World.prototype={setGravity:function(n,m){n=n*b;m=m*b;this._world.SetGravity(a.Common.Math.b2Vec2.Get(n,m))},step:function(m,o,n){this._world.Step(m,o,n)},clearForces:function(){this._world.ClearForces()},createBody:function(m){var n=d.Body.provide();n._body=this._world.CreateBody(m._bodyDef);n._body.SetUserData(gs.ActorUserData.provide());return n},destroyBody:function(m){var n=m._body.GetUserData();m._body.SetUserData(null);this._world.DestroyBody(m._body);m._body=null;gs.ActorUserData.recycle(n);d.Body.recycle(m)},recycleThis:function(){a.Dynamics.b2World.Free(this._world);this._world=null}};d.BodyDef=function(){this.userData=null;this._bodyDef=k;return this};d.BodyDef.prototype={setPosition:function(m,n){this._bodyDef.position.Set(m*b,n*b)},setAngle:function(m){this._bodyDef.angle=(m)},setFixedRotation:function(m){this._bodyDef.fixedRotation=m},setType:function(m){this._bodyDef.type=m}};var i=new d.BodyDef();d.GetBodyDef=function(){return i};d.Fixture=function(){};gs.Pool.init(d.Fixture);d.Fixture.prototype={fixtureID:function(){var m=this._fixture.GetUserData();return m.fixtureID},setFixtureID:function(n){var m=this._fixture.GetUserData();m.setFixtureID(n)},addCollisionMaskCategory:function(n){var m=this._fixture.GetUserData();m.addCollisionMaskCategory(n)},removeCollisionMaskCategory:function(n){var m=this._fixture.GetUserData();m.removeCollisionMaskCategory(n)},testPoint:function(m,n){return this._fixture.TestPoint(m*b,n*b)}};d.Body=function(){};gs.Pool.init(d.Body);d.Body.prototype={setActorID:function(n){var m=this._body.GetUserData();m.setActorID(n)},addCollisionCategory:function(n){if(n===null){gs.Log.error("bad category to addCollisionCategory")}var m=this._body.GetUserData();m.addCollisionCategory(n)},getPosition:function(m){var n=this._body.GetPosition();m[0]=n.x*h;m[1]=n.y*h;return m},angle:function(){return this._body.GetAngle()},setLinearVelocity:function(n,m){e.x=n*b;e.y=m*b;this._body.SetAwake(true);this._body.SetLinearVelocity(e)},getLinearVelocity:function(m){var n=this._body.GetLinearVelocity();m[0]=n.x*h;m[1]=n.y*h;return m},setAngularVelocity:function(m){this._body.SetAwake(true);this._body.SetAngularVelocity(m)},angularVelocity:function(){return this._body.GetAngularVelocity()},setAngularDamping:function(m){this._body.SetAngularDamping(m)},applyForce:function(n,m){e.x=n[0]*b;e.y=n[1]*b;this._body.ApplyForce(e,m)},applyForceNoConversion:function(n,m){this._body.ApplyForce(n,m)},setAwake:function(m){this._body.SetAwake(m)},isAwake:function(){return this._body.IsAwake()},setPositionAndAngle:function(n,m,o){e.x=n*b;e.y=m*b;this._body.SetPositionAndAngle(e,o)},createFixture:function(m){var n=d.Fixture.provide();n._fixture=this._body.CreateFixture(m._fixtureDef);n._fixture.SetUserData(gs.FixtureUserData.provide());return n},destroyFixture:function(m){var n=m._fixture.GetUserData();this._body.DestroyFixture(m._fixture);m._fixture=null;gs.FixtureUserData.recycle(n);d.Fixture.recycle(m)},resizeFixtureShapesAsBox:function(n,m){this._body.ResizeFixtureShapesAsBox(n*b,m*b)},resizeFixtureShapesAsCircle:function(m){this._body.ResizeFixtureShapesAsCircle(m*b)},changeFixtureDensities:function(m){this._body.ChangeFixtureDensities(m)},changeFixtureFrictions:function(m){this._body.ChangeFixtureFrictions(m)},changeFixtureRestitutions:function(m){this._body.ChangeFixtureRestitutions(m)},getMass:function(){return this._body.GetMass()},getWorldCenter:function(){return this._body.GetWorldCenter()}};d.FixtureDef=function(){this.userData=null;this._fixtureDef=c};d.FixtureDef.prototype={setShape:function(m){this._fixtureDef.shape=m},setDensity:function(m){this._fixtureDef.density=m},setFriction:function(m){this._fixtureDef.friction=m*b},setRestitution:function(m){this._fixtureDef.restitution=m},setIsSensor:function(m){this._fixtureDef.isSensor=m},addCollisionMaskCategory:function(n){var m=this._fixtureDef.userData;m.addCollisionMaskCategory(n)}};var l=new d.FixtureDef();d.GetFixtureDef=function(){return l};d.GetCircleShape=function(m){g.m_radius=m*b;return g};d.GetPolygonShapeAsBox=function(n,m){f.SetAsBox(n*b,m*b);return f};return d})();gs.CollisionController=gs.GameSaladObject.subclass("CollisionController");gs.CollisionController.init=function(){gs.GameSaladObject.init.call(this);if(this){this.collidableActors=gs.sparseArray.create();this.sensorRegistrations=gs.Map.provide();this.collisionRegistrations=gs.Map.provide()}return this};gs.CollisionController.getActorFromActorID=function(a){return this.collidableActors[a]};gs.CollisionController.addCollidableActor=function(a){return this.collidableActors.addItem(a)};gs.CollisionController.removeCollidableActorForIndex=function(a){this.collidableActors.removeItemAtIndex(a)};gs.CollisionController.actorsMatchingCategoryResult=[];gs.CollisionController.actorsMatchingCategory=function(c){var f=0;var a=gs.CollisionController.actorsMatchingCategoryResult;a.length=0;var b=this.collidableActors;var g=b.n;for(var d=0;d<g;++d){var e=b[d];if((e)&&e.matchesCategory(c)){f++;a.push(e)}}return a};gs.CollisionController.sensorRegistrationCountForCategory=function(e){var a=0;var b=this.sensorRegistrations;for(var c in b){var f=b[c];var d=f[e];if(d){a=a+d.length}}return a};gs.CollisionController.collisionRegistrationCountForCategory=function(c){var a=0;var d=this.collisionRegistrations;for(var b in d){a=a+d[b].countOfObject(c)}return a};gs.CollisionController.addActorSensor=function(e,b,d){var j=e._objectKey;var k=this.sensorRegistrations;var n=k[j];if(!n){n=gs.Map.provide();k[j]=n;e.aspects.addAspect("collisionSensor")}var h=n[b];if(!h){h=gs.array.provide();n[b]=h;var l=e.game().collisionCategoryManager.categoryIndexForObject(b);e.aspects.collisionSensor.addCollisionMaskCategory(l)}h.push(d);var m=this.actorsMatchingCategory(b);var g=m.length;for(var f=0;f<g;++f){var a=m[f];var c=a.receivedSensors;if(c===0){a.aspects.addAspect("collisionSensor")}a.receivedSensors=c+1}};gs.CollisionController.removeActorSensor=function(f,b,d){var k=f._objectKey;var l=this.sensorRegistrations;var q=l[k];if(!q){return}var j=q[b];if(!j){return}var m=j.indexOf(d);if(m>-1){j.splice(m,1);if(j.length===0){delete q[b];var o=f.game().collisionCategoryManager.categoryIndexForObject(b);f.aspects.collisionSensor.removeCollisionMaskCategory(o);var e=0;for(var n in q){++e;break}if(e===0){delete l[k];if(f.receivedSensors===0){f.aspects.removeAspect("collisionSensor")}}}}var p=this.actorsMatchingCategory(b);var h=p.length;for(var g=0;g<h;++g){var a=p[g];var c=Math.max(a.receivedSensors-1,0);if((c===0)&&(!l[a._objectKey])){a.aspects.removeAspect("collisionSensor")}a.receivedSensors=c}};gs.CollisionController.delegatesForActorCollidingWithActor=function(d,c,n){var h=d._objectKey;var l=this.sensorRegistrations[h];if(!l){return n}var a=c.tags();for(var g=0,e=a.length;g<e;++g){var b=a[g];var f=l[b];if(f){var m=f.length;for(var j=0;j<m;++j){var k=f[j];if(n.indexOf(k)===-1){n.push(k)}}}}var b=c._prototypeID;f=l[b];if(f){m=f.length;for(j=0;j<m;++j){k=f[j];if(n.indexOf(k)===-1){n.push(k)}}}return n};gs.CollisionController.delegatesForActorCollisionPairResult=[];gs.CollisionController.delegatesForActorCollisionPairTemp=[];gs.CollisionController.delegatesForActorCollisionPair=function(g,f){var b=gs.CollisionController.delegatesForActorCollisionPairResult;b.length=0;var d=gs.CollisionController.delegatesForActorCollisionPairTemp;d.length=0;this.delegatesForActorCollidingWithActor(g,f,b);this.delegatesForActorCollidingWithActor(f,g,d);var a=d.length;for(var c=0;c<a;++c){var e=d[c];if(b.indexOf(e)===-1){b.push(e)}}return b};gs.CollisionController.addActorCollision=function(c,b){var f=c._objectKey;var g=this.collisionRegistrations;var k=g[f];if(!k){k=new gs.MultiSet();g[f]=k;c.aspects.addAspect("collisionShape")}k.addObject(b);if(k.countOfObject(b)===1){var h=c.game().collisionCategoryManager.categoryIndexForObject(b);c.aspects.collisionShape.addCollisionMaskCategory(h)}var l=this.actorsMatchingCategory(b);var e=l.length;for(var d=0;d<e;++d){var a=l[d];var j=a.receivedCollisions;if(j===0){a.aspects.addAspect("collisionShape")}a.receivedCollisions=j+1}};gs.CollisionController.removeActorCollision=function(d,b){var g=d._objectKey;var h=this.collisionRegistrations;var n=h[g];if(!n){return}n.removeObject(b);if(n.countOfObject(b)===0){var j=d.game().collisionCategoryManager.categoryIndexForObject(b);d.aspects.collisionShape.removeCollisionMaskCategory(j);var c=0;for(var k in n){++c;break}if(c===0){delete h[g];if(d.receivedCollisions===0){d.aspects.removeAspect("collisionShape")}}}var m=this.actorsMatchingCategory(b);var f=m.length;for(var e=0;e<f;++e){var a=m[e];var l=Math.max(a.receivedCollisions-1,0);if((l===0)&&(!h[a._objectKey])){a.aspects.removeAspect("collisionShape")}a.receivedCollisions=l}};gs.CollisionCategoryManager=function(){this.collisionCategories=gs.array.provide();this.reverseCollisionCategories=gs.Map.provide()};gs.CollisionCategoryManager.prototype.resetCollisionCategories=function(){this.collisionCategories=gs.array.provide();this.reverseCollisionCategories=gs.Map.provide()};gs.CollisionCategoryManager.prototype.addCollisionCategory=function(b){var c=this.collisionCategories;var a=c.length;c[a]=b;this.reverseCollisionCategories[b]=a};gs.CollisionCategoryManager.prototype.categoryIndexForObject=function(a){return this.reverseCollisionCategories[a]};gs.Game.primeInitialPools=function(){gs.Layer.primePool(8);gs.Timebase.primePool(64);gs.SGWebGLImage.primePool(64);gs.EventCenterRegistration.primePool(128);gs.SGParticleSystemNode.primePool(32);gs.InternalParticle.primePool(256);gs.SGClearNode.primePool(2);gs.SGColorNode.primePool(2);gs.SGOrtho2DSpace.primePool(8);gs.SGSpace.primePool(64);gs.SGSpriteNode.primePool(64);gs.SGWrapNode.primePool(64)};gs.Game.primePoolsPerScene=function(){gs.array.primePool(128)};gs.Game.primeBox2D=function(){var o;var l=64;var r=8;var p=256;var m=new gs.physicsLib.World(0,0,true);m._world.SetContactFilter({ShouldCollide:function(){return true}});var e=gs.array.provide();var j=gs.array.provide();var c=gs.array.provide();var d=gs.physicsLib.GetBodyDef();d.setType(gs.physicsLib.DYNAMIC_BODY);var n=gs.physicsLib.GetFixtureDef();n.setDensity(1);var q=gs.physicsLib.GetPolygonShapeAsBox(1,1);var a=gs.physicsLib.GetCircleShape(1);var b=[1,1];for(o=0;o<l;o++){var g=m.createBody(d);e.push(g);n.setShape(q);n.setIsSensor(false);var t=g.createFixture(n);j.push(t);n.setShape(a);n.setIsSensor(true);var f=g.createFixture(n);c.push(f);var s=g.getWorldCenter();g.applyForce(b,s)}for(o=r;o<l;o++){e[o].destroyFixture(j[o]);e[o].destroyFixture(c[o]);m.destroyBody(e[o])}m.step(1,10,10);m.clearForces();for(o=0;o<r;o++){e[o].destroyFixture(j[o]);e[o].destroyFixture(c[o]);m.destroyBody(e[o])}var k=new gs.physicsLib.World(0,0,true);k.recycleThis();m.recycleThis();for(o=0;o<p;o++){var h=new Box2D.Common.Math.b2Vec2(0,0);Box2D.Common.Math.b2Vec2.Free(h)}};gs.AutoplayOption={NONE:"NONE",ENGINE:"ENGINE",LOAD:"LOAD",PLAY:"PLAY"};gs.AudioOption={STANDARD:"STANDARD",EXTENSION:"EXTENSION",DETECT:"DETECT"};gs.LoadStrategyOption={NONE:"NONE",INITIAL:"INITIAL",LATENCY:"LATENCY",STRICT:"STRICT",SAFE:"SAFE",SCENE:"SCENE",GAME:"GAME"};gs.RendererOption={CANVAS:"CANVAS",WEBGL:"WEBGL",DETECT:"DETECT"};gs.SceneOption={FIRST:"first",LAST:"last",NEXT:"next",PREVIOUS:"prev"};gs.EngineOptions=function(){this.gamePath=null;this.defaultPath="game/default";this.autoplay=gs.AutoplayOption.PLAY;this.scene=gs.SceneOption.FIRST;this.format=gs.file.Format.JSON;this.loadStrategy=gs.LoadStrategyOption.SAFE;this.renderer=gs.RendererOption.DETECT;this.width=0;this.height=0;this.zoom=1;this.viewportReference=gs.ViewportReference.FRAME;this.viewportFit=gs.ViewportFit.LETTERBOX;this.viewportScale=gs.ViewportScale.RESIZE;this.viewportFactor=1;this.drawFactor=1;this.drawFirst=false;this.audio=gs.AudioOption.DETECT;this.targetRate=0;this.minFrameDeltaMS=4;this.maxFrameDeltaMS=1000/30;this.maxFrameDebtMS=16;this.idealFrameMS=16;this.hitchFrameMS=1000/15;this.hitchWindowMS=2*1000;this.logLevel=gs.Log.LogLevel.ALL};gs.EngineOptions.prototype={setOption:function(a,b){a=this.getCanonicalKey(a);if(a&&a in this.obfuscationLookup){a=this.obfuscationLookup[a];this[a]=b}},normalize:function(){this.format=this.format.toUpperCase();this.loadStrategy=this.loadStrategy.toUpperCase()},getCanonicalKey:function(a){if(a in this.obfuscationLookup){return a}switch(a){case"game":return"gamePath"}var b=a.indexOf("-");var c;while(b!==-1){c=a.charAt(b+1);a=a.substring(0,b)+c.toUpperCase()+a.substring(b+2);b=a.indexOf("-")}if(a in this.obfuscationLookup){return a}return null},loadObject:function(b){for(var a in b){this.setOption(a,b[a])}},loadJSONString:function(b){var a=JSON.parse(b);this.loadObject(a)},loadURLString:function(a){var b=gs.util.createMapFromURLString(a,"game");if(b.options){this.loadJSONString(b.options)}this.loadObject(b)},obfuscationLookup:gs.util.createObfuscationLookup({autoplay:"autoplay",defaultPath:"defaultPath",format:"format",gamePath:"gamePath",height:"height",loadStrategy:"loadStrategy",logLevel:"logLevel",audio:"audio",renderer:"renderer",scene:"scene",viewportFit:"viewportFit",viewportReference:"viewportReference",viewportScale:"viewportScale",viewportFactor:"viewportFactor",targetRate:"targetRate",drawFactor:"drawFactor",drawFirst:"drawFirst",minFrameDeltaMS:"minFrameDeltaMS",maxFrameDeltaMS:"maxFrameDeltaMS",maxFrameDebtMS:"maxFrameDebtMS",hitchFrameMS:"hitchFrameMS",hitchWindowMS:"hitchWindowMS",width:"width",zoom:"zoom"})};gs.RenderContext=function(){this.viewport=new gs.html5.Viewport();this.renderer=gs.RendererOption.DETECT;this.window=window;this.windowInnerWidth=0;this.windowInnerHeight=0;this.init()};gs.RenderContext.prototype={init:function(){var a=this;this.window.addEventListener("resize",function(b){gs.RenderContext.prototype.onWindowResize.call(a,b)},false)},getViewport:function(){return this.viewport},setFrame:function(b){var a=gs.dom.getElement(b);this.viewport.setFrame(a)},setCanvas:function(b){var a=gs.dom.getElement(b);this.viewport.setCanvas(a)},loadOptions:function(a){this.renderer=a.renderer.toUpperCase();this.viewport.reference=a.viewportReference.toUpperCase();this.viewport.fit=a.viewportFit.toUpperCase();this.viewport.scale=a.viewportScale.toUpperCase();this.viewport.factor=parseFloat(a.viewportFactor)},getRenderer:function(){return this.renderer},onWindowResize:function(a){this.updateWindowSize();this.viewport.relayout()},updateWindowSize:function(){this.windowInnerWidth=this.window.innerWidth;this.windowInnerHeight=this.window.innerHeight;this.viewport.updateWindowSize(this.windowInnerWidth,this.windowInnerHeight)},onGameDimensionsKnown:function(b,a){this.updateWindowSize();this.viewport.updateGameSize(b,a)},redetect:function(){this.updateWindowSize();this.viewport.relayout();this.viewport.show()}};gs.RenderContext.prototype.onGameDimensionsKnown=gs.RenderContext.prototype.onGameDimensionsKnown;gs.RenderContext=function(){this.viewport=new gs.html5.Viewport();this.renderer=gs.RendererOption.DETECT;this.window=window;this.windowInnerWidth=0;this.windowInnerHeight=0;this.init()};gs.RenderContext.prototype={init:function(){var a=this;this.window.addEventListener("resize",function(b){gs.RenderContext.prototype.onWindowResize.call(a,b)},false)},getViewport:function(){return this.viewport},setFrame:function(b){var a=gs.dom.getElement(b);this.viewport.setFrame(a)},setCanvas:function(b){var a=gs.dom.getElement(b);this.viewport.setCanvas(a)},loadOptions:function(a){this.renderer=a.renderer.toUpperCase();this.viewport.reference=a.viewportReference.toUpperCase();this.viewport.fit=a.viewportFit.toUpperCase();this.viewport.scale=a.viewportScale.toUpperCase();this.viewport.factor=parseFloat(a.viewportFactor)},getRenderer:function(){return this.renderer},onWindowResize:function(a){this.updateWindowSize();this.viewport.relayout()},updateWindowSize:function(){this.windowInnerWidth=this.window.innerWidth;this.windowInnerHeight=this.window.innerHeight;this.viewport.updateWindowSize(this.windowInnerWidth,this.windowInnerHeight)},onGameDimensionsKnown:function(b,a){this.updateWindowSize();this.viewport.updateGameSize(b,a)},redetect:function(){this.updateWindowSize();this.viewport.relayout();this.viewport.show()}};gs.RenderContext.prototype.onGameDimensionsKnown=gs.RenderContext.prototype.onGameDimensionsKnown;gs.EngineState={ENGINE_READY:"ENGINE_READY",GAME_LOADING:"GAME_LOADING",GAME_READY:"GAME_READY",SCENE_LOADING:"SCENE_LOADING",PLAYING:"PLAYING",PAUSED:"PAUSED",SUSPENDED:"SUSPENDED",HALTED:"HALTED"};gs.EngineContext=function(){this.options=new gs.EngineOptions();this.state=gs.EngineState.ENGINE_READY;this.delegate=new gs.api.Delegate();this.renderContext=new gs.RenderContext();this.previousSystemTimeMS=Date.now();this.frameDebtMS=0;this.frameCount=0;this.project=null;this.game=null;this.promiseGameReady=new gs.Promise();this.promiseFirstPlay=new gs.Promise();gs.EngineContext.current=this;gs.Log.delegate=this.delegate;this.appendDelegate(gs.LegacyDelegate);this.appendDelegate(this.renderContext);if(gs.debug.profile){this.log=new gs.LogVisualizer();this.renderContext.viewport.appendOverlay(this.log.root);this.appendDelegate(this.log);this.profiler=new gs.ProfilerVisualizer();this.renderContext.viewport.appendOverlay(this.profiler.root);this.appendDelegate(this.profiler)}if(gs.debug.fps){this.fps=new gs.FrameRateVisualizer();this.renderContext.viewport.appendOverlay(this.fps.root);this.appendDelegate(this.fps)}};gs.EngineContext.instance=function(){if(!gs.EngineContext.current){gs.EngineContext.current=new gs.EngineContext()}return gs.EngineContext.current};gs.EngineContext.prototype={getRenderContext:function(){return this.renderContext},setGamePath:function(a){this.options.gamePath=a},setRenderFrame:function(a){this.renderContext.setFrame(a)},setOptions:function(a){this.options.loadObject(a)},loadOptionsFromURL:function(){var a=window.location.search||window.location.hash;this.options.loadURLString(a)},appendDelegate:function(a){this.delegate.appendDelegate(a)},getState:function(){return this.state},changeState:function(a){this.state=a},load:function(a){if(this.state===gs.EngineState.ENGINE_READY){if(a){this.setGamePath(a)}this.beginLoading();var b=this;this.project.promiseGameReady.then(function(){b.game=gs.Game.instance;b.changeState(gs.EngineState.GAME_READY);b.promiseGameReady.resolve()})}return this.promiseGameReady},beginLoading:function(){this.options.normalize();this.renderContext.loadOptions(this.options);gs.AudioManager.init(this.options.audio.toUpperCase());this.changeState(gs.EngineState.GAME_LOADING);gs.LocalStorage.setPrefix(gs.LOCAL_STORAGE_KEY_PREFIX);var d=gs.platform.AnalyticsService.instance();d.beginSession();var a=this.renderContext.getViewport();var b={canvas:a.drawBuffer.canvas,webgl:a.drawBuffer.canvas,input:a.input};var c=this.options.gamePath||this.options.defaultPath;this.project=new gs.Project();this.project.load(c,b)},play:function(a){var b=this;switch(this.state){case gs.EngineState.ENGINE_READY:case gs.EngineState.GAME_LOADING:b.load(a).then(function(){b.play()});break;case gs.EngineState.GAME_READY:this.renderContext.redetect();this.game.redetectInputCoordinates();this.project.play();this.changeState(gs.EngineState.PLAYING);this.promiseFirstPlay.resolve();break;case gs.EngineState.PLAYING:break;case gs.EngineState.HALTED:break;case gs.EngineState.SCENE_LOADING:break;case gs.EngineState.PAUSED:return this.unpause();break;case gs.EngineState.SUSPENDED:return this.unsuspend();break;default:break}return this.promiseFirstPlay},pause:function(){var b=new gs.Promise();var a=this.getState();if(a!==gs.EngineState.PAUSED&&a!==gs.EngineState.SUSPENDED){this.game.interceptKeyEvents=false;this.game.eventCenter.postEvent("systemPause",null);this.project.stopGameLoop();this.changeState(gs.EngineState.PAUSED)}b.resolve();return b},unpause:function(){var b=new gs.Promise();var a=this.getState();if(a===gs.EngineState.PAUSED){this.project.play();this.changeState(gs.EngineState.PLAYING)}b.resolve();return b},suspend:function(){var b=new gs.Promise();var a=this.getState();if(a!==gs.EngineState.SUSPENDED){this.endSession()}this.pause();this.changeState(gs.EngineState.SUSPENDED);b.resolve();return b},unsuspend:function(){var b=new gs.Promise();var a=this.getState();if(a===gs.EngineState.SUSPENDED){this.beginSession();this.project.play();this.changeState(gs.EngineState.PLAYING)}b.resolve();return b},halt:function(){var a=new gs.Promise();if(this.game.gameTimebase){this.game.stop(this.game.gameTimebase.nextTimestamp(gs.TIME_STEP_MS));if(this.project.gameLoopIsRunning()){this.project.stopGameLoop()}this.game.gameTimebase=null;this.game.isPlaying=false}a.resolve();return a},reset:function(){var a=new gs.Promise();this.game.eventCenter.postEvent("resetGame",null);this.project.play();a.resolve();return a},resetScene:function(){var a=new gs.Promise();a.resolve();return a},changeScene:function(f){var h=new gs.Promise();var g=this.project;if(!g._readyToPlay){g._changeSceneQueued=f}else{var b=g.game;var d=b.getCurrentScene();var a=0;if(d){a=b.scenes.indexAndKey(d._objectKey)}var c=b.scenes.numberOfScenes()-1;var e;if(typeof(f)==="number"){f=b.scenes.keyForScene(f)}else{if(f==="first"){f=b.scenes.keyForScene(0)}else{if(f==="next"){e=a+1;if(e>c){e=0}f=b.scenes.keyForScene(e)}else{if(f==="prev"){e=a-1;if(e<0){e=c}f=b.scenes.keyForScene(e)}}}}b.eventCenter.postEvent("changeToScene",null,f,false);g.play()}h.resolve();return h},getCurrentSceneKey:function(){if(!this.game){return null}return this.game.getCurrentSceneKey()},beginSession:function(){var a=gs.platform.AnalyticsService.instance();a.beginSession()},endSession:function(){var a=gs.platform.AnalyticsService.instance();a.endSession()},update:function(){var l=this.game;if(l.isWaitingOnKeyboardInput){return}var c=this.getSystemTimeMS();var j=c-this.previousSystemTimeMS;var b=j;var f=0;if(b<this.options.minFrameDeltaMS){return}if(b>this.options.hitchFrameMS){var g=this.options.idealFrameMS;f=b-g;l.gameTimebase.base+=f;b=g;if(this.fps&&!l.loadingFlag&&!l.firstFrameAfterLoading){this.fps.hitch(f,this.options.hitchWindowMS)}}else{if(b>this.options.maxFrameDeltaMS){this.frameDebtMS+=(b-this.options.maxFrameDeltaMS);if(this.frameDebtMS>this.options.maxFrameDebtMS){f=this.options.maxFrameDeltaMS-this.frameDebtMS;this.frameDebtMS=this.options.maxFrameDebtMS;l.gameTimebase.base+=f}b=this.options.maxFrameDeltaMS}else{var a=this.options.maxFrameDeltaMS-b;if(a<this.frameDebtMS){b+=a;this.frameDebtMS-=a}else{b+=this.frameDebtMS;this.frameDebtMS=0}}}if(this.fps){this.fps.deltaMS=b;this.fps.trueDeltaMS=j}var h=b/1000;this.previousSystemTimeMS=c;if(l.gameTimebase){l.frameProfiler.frame.tick();l.frameProfiler.engine.enter();l.entityCounter.reset();if(this.options.drawFirst){this.draw();this.simulate(h)}else{this.simulate(h);this.draw()}this.frameCount++;l.entityCounter.contacts.set(gs.ContactListener.getContactCount());l.entityCounter.textures.set(gs.AssetManager.current.getImageCount());l.frameProfiler.engine.exit();l.frameProfiler.profile.enter();this.delegate.onProfilerFrame(l.frameProfiler.getReading(),l.entityCounter.getReading(),l.project.gameLoadProfiler.getReading(),l.sceneLoadProfiler.getReading());l.frameProfiler.profile.exit();if(gs.afterNextFrameCallbacks){for(var e=0,d=gs.afterNextFrameCallbacks.length;e<d;e++){var k=gs.afterNextFrameCallbacks[e];k&&k.call(null)}gs.afterNextFrameCallbacks.length=0}}},draw:function(){var a=this.game;a.frameProfiler.render.enter();if(gs.debug.render){if(this.frameCount%this.options.drawFactor===0){a.render()}}a.frameProfiler.render.exit()},simulate:function(b){var a=this.game;if(gs.debug.evaluate){a.evaluate(a.gameTimebase.nextTimestamp(b))}},resetFrameTime:function(){var a=this.getSystemTimeMS();var c=this.game.gameTimebase;if(c){var b=c.currentTimeStamp.time;c.base=(a/1000)-b;c.currentTimeStamp.base=c.base;c.currentTimeStamp.dt=0}this.frameDebtMS=0;this.previousSystemTimeMS=a},getSystemTimeMS:function(){return Date.now()},getSimulationTimeS:function(){return(this.getSystemTimeMS()-this.frameDebtMS)/1000},waitAfterNextFrame:function(){var a=new gs.Promise();if(!gs.afterNextFrameCallbacks){gs.afterNextFrameCallbacks=[]}gs.afterNextFrameCallbacks.push(function(){a.resolve()});return a},getVolume:function(){return gs.AudioManager.current.getMasterVolume()},setVolume:function(a){gs.AudioManager.current.setMasterVolume(a)},zoom:function(b){var a=this.renderContext.getViewport();a.setZoom(b)},getMetadataForAllScenes:function(){var b=new gs.Promise();var a=this.project;a.preloadAllScenes(function(c){var d=[];c.forEach(function(f){var g=f.id;var e={id:g,key:g,name:f.label||g,screenshot:a.pathResolver.getSceneScreenshotPathByID(g)};d.push(e)});b.resolve(d)});return b}};gs.EngineContext.prototype.appendDelegate=gs.EngineContext.prototype.appendDelegate;gs.EngineContext.prototype.changeScene=gs.EngineContext.prototype.changeScene;gs.EngineContext.prototype.getMetadataForAllScenes=gs.EngineContext.prototype.getMetadataForAllScenes;gs.EngineContext.prototype.getVolume=gs.EngineContext.prototype.getVolume;gs.EngineContext.prototype.halt=gs.EngineContext.prototype.halt;gs.EngineContext.prototype.load=gs.EngineContext.prototype.load;gs.EngineContext.prototype.loadOptionsFromURL=gs.EngineContext.prototype.loadOptionsFromURL;gs.EngineContext.prototype.pause=gs.EngineContext.prototype.pause;gs.EngineContext.prototype.play=gs.EngineContext.prototype.play;gs.EngineContext.prototype.reset=gs.EngineContext.prototype.reset;gs.EngineContext.prototype.resetScene=gs.EngineContext.prototype.resetScene;gs.EngineContext.prototype.setRenderCanvas=gs.EngineContext.prototype.setRenderCanvas;gs.EngineContext.prototype.setRenderFrame=gs.EngineContext.prototype.setRenderFrame;gs.EngineContext.prototype.setVolume=gs.EngineContext.prototype.setVolume;gs.EngineContext.prototype.suspend=gs.EngineContext.prototype.suspend;gs.EngineContext.prototype.unpause=gs.EngineContext.prototype.unpause;gs.EngineContext.prototype.unsuspend=gs.EngineContext.prototype.unsuspend;gs.EngineContext.prototype.waitAfterNextFrame=gs.EngineContext.prototype.waitAfterNextFrame;gs.EngineContext.prototype.zoom=gs.EngineContext.prototype.zoom;gs.version={number:"0.20.2",target:"core",revision:"",date:""};gs.version.target="interpreter";gs.Log.level=gs.Log.LogLevel.ERROR;gs.globalOptions.uploadAnalytics=true;gs.version.revision="ed9ebcc362a059ef97f627a986f7fa2db56fa704";gs.version.date="2014-06-25T18:51:14";