THROW_NO_IMPL=function(){throw new Error("function has not been implemented.")};var Sweaky2D={NextTextureId:1,TextureCache:{},DegreeRadianRatio:0.017453292519943295,DegreeToRadian:Math.PI/180,RadianToDegree:180/Math.PI};Sweaky2D.Equatable=Class.create({isEqualTo:function(a){},isNotEqualTo:function(a){return !this.isEqualTo(a)}});Sweaky2D.Color=Class.create(Sweaky2D.Equatable,{initialize:function(b,a,c,d){this.r=(b==null?1:b);this.g=(a==null?1:a);this.b=(c==null?1:c);this.a=(d==null?1:d)},add:function(a){return new Sweaky2D.Color(Math.min(this.r+a.r,1),Math.min(this.g+a.g,1),Math.min(this.b+a.b,1),Math.min(this.a+a.a,1))},subtract:function(a){return new Sweaky2D.Color(Math.max(this.r-a.r,0),Math.max(this.g-a.g,0),Math.max(this.b-a.b,0),Math.max(this.a-a.a,0))},toRGB:function(){return(((this.r*255)<<16)|((this.g*255)<<8)|(this.b*255))},toRGBString:function(){return"rgb("+parseInt(this.r*255)+","+parseInt(this.g*255)+","+parseInt(this.b*255)+")"},toRGBAString:function(){return"rgba("+parseInt(this.r*255)+","+parseInt(this.g*255)+","+parseInt(this.b*255)+","+Math.max(Math.min(this.a.toFixed(2),1),0)+")"},toHex:function(){return"#"+this.toRGB().toString(16)},isEqualTo:function(a){return(a.r==this.r&&a.g==this.g&&a.b==this.b&&a.a==this.a)},toString:function(){return this.toRGBString()}});Sweaky2D.Color.fromRGB=function(a){return new Sweaky2D.Color(((a>>16)&255)/255,((a>>8)&255)/255,((a&255))/255,1)};Sweaky2D.Color.fromHex=function(a){if(a.length==9){return new Sweaky2D.Color(parseInt("0x"+a.substring(1,3))/255,parseInt("0x"+a.substring(3,5))/255,parseInt("0x"+a.substring(5,7))/255,parseInt("0x"+a.substring(7,9))/255)}else{return new Sweaky2D.Color(parseInt("0x"+a.substring(1,3))/255,parseInt("0x"+a.substring(3,5))/255,parseInt("0x"+a.substring(5,7))/255,1)}};Sweaky2D.Color.Black=new Sweaky2D.Color(0,0,0,1);Sweaky2D.Color.White=new Sweaky2D.Color(1,1,1,1);Sweaky2D.Color.Red=new Sweaky2D.Color(1,0,0,1);Sweaky2D.Color.Green=new Sweaky2D.Color(0,1,0,1);Sweaky2D.Color.Blue=new Sweaky2D.Color(0,0,1,1);Sweaky2D.Vector2D=Class.create(Sweaky2D.Equatable,{initialize:function(a,b){this.x=(a==null?0:a);this.y=(b==null?0:b)},add:function(a){return new Sweaky2D.Vector2D(this.x+a.x,this.y+a.y)},subtract:function(a){return new Sweaky2D.Vector2D(this.x-a.x,this.y-a.y)},multiply:function(a){return new Sweaky2D.Vector2D(this.x*a.x,this.y*a.y)},divide:function(a){return new Sweaky2D.Vector2D(this.x/a.x,this.y/a.y)},negate:function(){return new Sweaky2D.Vector2D(-this.x,-this.y)},length:function(){return Math.sqrt(this.lengthSquared())},lengthSquared:function(){return(this.x*this.x+this.y*this.y)},distance:function(a){return this.subtract(a).length()},distanceSquared:function(a){return this.subtract(a).lengthSquared()},dotProduct:function(a){return(this.x*a.x+this.y*a.y)},crossProduct:function(a){return(this.x*a.y-this.y*a.x)},normalize:function(){var b=this.length();if(b>1e-8){var a=1/b;this.x*=a;this.y*=a}return b},midPoint:function(a){return new Sweaky2D.Vector2D((this.x+a.x)*0.5,(this.y+a.y)*0.5)},isLessThan:function(a){return(this.x<a.x&&this.y<a.y)},isGreaterThan:function(a){return(this.x>a.x&&this.y>a.y)},isEqualTo:function(a){return(this.x==a.x&&this.y==a.y)},toString:function(){return("x:"+this.x+", y:"+this.y)}});Sweaky2D.Vector2D.NotSet=new Sweaky2D.Vector2D(Infinity,Infinity);Sweaky2D.Vector2D.Zero=new Sweaky2D.Vector2D(0,0);Sweaky2D.Vector2D.UnitX=new Sweaky2D.Vector2D(1,0);Sweaky2D.Vector2D.UnitY=new Sweaky2D.Vector2D(0,1);Sweaky2D.Vector2D.NegativeUnitX=new Sweaky2D.Vector2D(-1,0);Sweaky2D.Vector2D.NegativeUnitY=new Sweaky2D.Vector2D(0,-1);Sweaky2D.Vector2D.UnitScale=new Sweaky2D.Vector2D(1,1);Sweaky2D.Rectangle=Class.create(Sweaky2D.Equatable,{initialize:function(a,b,c,d){this.x=(a==null?0:a);this.y=(b==null?0:b);this.width=(c==null?0:c);this.height=(d==null?0:d)},top:function(){return this.y},bottom:function(){return(this.y+this.height)},left:function(){return this.x},right:function(){return(this.x+this.width)},topLeft:function(){return new Sweaky2D.Vector2D(this.left(),this.top())},topRight:function(){return new Sweaky2D.Vector2D(this.right(),this.top())},bottomLeft:function(){return new Sweaky2D.Vector2D(this.left(),this.bottom())},bottomRight:function(){return new Sweaky2D.Vector2D(this.right(),this.bottom())},position:function(){return new Sweaky2D.Vector2D(this.x,this.y)},size:function(){return new Sweaky2D.Vector2D(this.width,this.height)},offset:function(a,b){this.x+=a;this.y+=b},unionWithPoint:function(a){this.unionWithRect(new Sweaky2D.Rectangle(a.x,a.y,a.x,a.y))},unionWithRect:function(d){if(this.isEqualTo(Sweaky2D.Rectangle.Zero)){this.initialize(d.x,d.y,d.width,d.height);return}if(this.isNotEqualTo(Sweaky2D.Rectangle.Zero)){var f=Math.min(this.left(),d.left());var c=Math.max(this.right(),d.right());var e=Math.min(this.top(),d.top());var g=Math.max(this.bottom(),d.bottom());var a=Math.max(c-f,0);var b=Math.max(g-e,0);this.x=f;this.y=e;if(a>=0){this.width=a}if(b>=0){this.height=b}}},contains:function(a,b){if(this.isEqualTo(Sweaky2D.Rectangle.Zero)){return false}return((a>=this.x)&&((a-this.width)<=this.x)&&(b>=this.y)&&((b-this.height)<=this.y))},containsPoint:function(a){return this.contains(a.x,a.y)},containsRect:function(a){if(this.isEqualTo(Sweaky2D.Rectangle.Zero)||a.isEqualTo(Sweaky2D.Rectangle.Zero)){return false}return((this.x<=a.x)&&(this.y<=a.y)&&(this.right()>=a.right())&&(this.bottom()>=a.bottom()))},isEqualTo:function(a){return(this.x==a.x&&this.y==a.y&&this.width==a.width&&this.height==a.height)},toString:function(){return("x:"+this.x+", y:"+this.y+", width:"+this.width+", height:"+this.height)}});Sweaky2D.Rectangle.Zero=new Sweaky2D.Rectangle(0,0,0,0);Sweaky2D.Rectangle.One=new Sweaky2D.Rectangle(1,1,1,1);Sweaky2D.Rectangle.fromPoints=function(e,d){var b=Math.min(e.x,d.x);var f=Math.min(e.y,d.y);var c=Math.max(Math.max(e.x,d.x)-b,0);var a=Math.max(Math.max(e.y,d.y)-f,0);return new Sweaky2D.Rectangle(b,f,c,a)};Sweaky2D.MatrixType={IsIdentity:0,IsTranslation:1,IsScaling:2,IsUnknown:4};Sweaky2D.Matrix2D=Class.create(Sweaky2D.Equatable,{initialize:function(){this.type=Sweaky2D.MatrixType.IsIdentity;this.m11=1;this.m12=0;this.m21=0;this.m22=1;this.offsetX=0;this.offsetY=0},isEqualTo:function(a){if(this.type==Sweaky2D.MatrixType.IsIdentity||a.type==Sweaky2D.MatrixType.IsIdentity){return(this.isIdentity()==a.isIdentity())}return(this.m11==a.m11&&this.m12==a.m12&&this.m21==a.m21&&this.m22==a.m22&&this.offsetX==a.offsetX&&this.offsetY==a.offsetY)},setMatrix:function(d,c,f,e,b,a){this.m11=d;this.m12=c;this.m21=f;this.m22=e;this.offsetX=b;this.offsetY=a;this.determineMatrixType()},setIdentity:function(){var a=Sweaky2D.Matrix2D.createIdentity();this.copy(a)},isIdentity:function(){return(this.type==Sweaky2D.MatrixType.IsIdentity||(this.m11==1&&this.m12==0&&this.m21==0&&this.m22==1&&this.offsetX==0&&this.offsetY==0))},determineMatrixType:function(){this.type=Sweaky2D.MatrixType.IsIdentity;if((this.m21!=0)||(this.m12!=0)){this.type=Sweaky2D.MatrixType.IsUnknown}else{if((this.m11!=1)||(this.m22!=1)){this.type=Sweaky2D.MatrixType.IsScaling}if((this.offsetX!=0)||(this.offsetY!=0)){this.type|=Sweaky2D.MatrixType.IsTranslation}if((this.type&(Sweaky2D.MatrixType.IsScaling|Sweaky2D.MatrixType.IsTranslation))==Sweaky2D.MatrixType.IsIdentity){this.type=Sweaky2D.MatrixType.IsIdentity}}},validate:function(){this.m11=(isNaN(this.m11)?0:this.m11);this.m12=(isNaN(this.m12)?0:this.m12);this.m21=(isNaN(this.m21)?0:this.m21);this.m22=(isNaN(this.m22)?0:this.m22);this.offsetX=(isNaN(this.offsetX)?0:this.offsetX);this.offsetY=(isNaN(this.offsetY)?0:this.offsetY)},copy:function(a){this.type=a.type;this.m11=a.m11;this.m12=a.m12;this.m21=a.m21;this.m22=a.m22;this.offsetX=a.offsetX;this.offsetY=a.offsetY},rotate:function(b,a){this.rotateAt(b,0,0,a)},rotateAt:function(e,b,f,c){var a=Sweaky2D.Matrix2D.createRotation((e%360)*Sweaky2D.DegreeRadianRatio,b,f);var d=null;if(c){d=this.prepend(a)}else{d=this.append(a)}this.copy(d)},scale:function(c,b,a){this.scaleAt(c,b,0,0,a)},scaleAt:function(g,e,b,f,c){var a=Sweaky2D.Matrix2D.createScale(g,e,b,f);var d=null;if(c){d=this.prepend(a)}else{d=this.append(a)}this.copy(d)},translate:function(c,b,d){if(d){var a=Sweaky2D.Matrix2D.createTranslation(c,b);a=this.prepend(a);this.copy(a)}else{if(this.type==Sweaky2D.MatrixType.IsIdentity){this.setMatrix(1,0,0,1,c,b);this.type=Sweaky2D.MatrixType.IsTranslation}else{if(this.type==Sweaky2D.MatrixType.IsUnknown){this.offsetX+=c;this.offsetY+=b}else{this.offsetX+=c;this.offsetY+=b;this.type|=Sweaky2D.MatrixType.IsTranslation}}}},append:function(a){return this.multiply(this,a)},prepend:function(a){return this.multiply(a,this)},add:function(c,b){var a=new Sweaky2D.Matrix2D();a.setMatrix(c.m11+b.m11,c.m12+b.m12,c.m21+b.m21,c.m22+b.m22,c.offsetX+b.offsetX,c.offsetY+b.offsetY);return a},transformVector:function(a){return this.transform(a,false)},transformPoint:function(a){return this.transform(a,true)},transform:function(e,d){if(d){return this.multiplyPoint(e.x,e.y)}else{var b=e.x;var f=e.y;switch(this.type){case Sweaky2D.MatrixType.IsIdentity:case Sweaky2D.MatrixType.IsTranslation:return new Sweaky2D.Vector2D(b,f);case Sweaky2D.MatrixType.IsScaling:case (Sweaky2D.MatrixType.IsScaling|Sweaky2D.MatrixType.IsTranslation):b*=this.m11;f*=this.m22;return new Sweaky2D.Vector2D(b,f)}var c=(b*this.m21);var a=(f*this.m12);b*=this.m11;b+=c;f*=this.m22;f+=a;return new Sweaky2D.Vector2D(b,f)}},multiply:function(c,b){var e=c.type;var d=b.type;if(d!=Sweaky2D.MatrixType.IsIdentity){if(e==Sweaky2D.MatrixType.IsIdentity){var a=new Sweaky2D.Matrix2D();a.setMatrix(b.m11,b.m12,b.m21,b.m22,b.offsetX,b.offsetY);return a}if(d==Sweaky2D.MatrixType.IsTranslation){var a=new Sweaky2D.Matrix2D();a.setMatrix(c.m11,c.m12,c.m21,c.m22,c.offsetX,c.offsetY);a.offsetX+=b.offsetX;a.offsetY+=b.offsetY;if(e!=Sweaky2D.MatrixType.IsUnknown){a.type|=Sweaky2D.MatrixType.IsTranslation}return a}if(e==Sweaky2D.MatrixType.IsTranslation){var a=new Sweaky2D.Matrix2D();a.setMatrix(b.m11,b.m12,b.m21,b.m22,b.offsetX,b.offsetY);a.offsetX=((c.offsetX*b.m11)+(c.offsetY*b.m21))+b.offsetX;a.offsetY=((c.offsetX*b.m12)+(c.offsetY*b.m22))+b.offsetY;if(d==Sweaky2D.MatrixType.IsUnknown){a.type=Sweaky2D.MatrixType.IsUnknown}else{a.type=Sweaky2D.MatrixType.IsScaling|Sweaky2D.MatrixType.IsTranslation}return a}var a=new Sweaky2D.Matrix2D();a.setMatrix(c.m11,c.m12,c.m21,c.m22,c.offsetX,c.offsetY);switch((e<<4)|d){case 34:a.m11*=b.m11;a.m22*=b.m22;return a;case 35:a.m11*=b.m11;a.m22*=b.m22;a.offsetX=b.offsetX;a.offsetY=b.offsetY;a.type=Sweaky2D.MatrixType.IsScaling|Sweaky2D.MatrixType.IsTranslation;return a;case 36:case 52:case 66:case 67:case 68:a.setMatrix((c.m11*b.m11)+(c.m12*b.m21),(c.m11*b.m12)+(c.m12*b.m22),(c.m21*b.m11)+(c.m22*b.m21),(c.m21*b.m12)+(c.m22*b.m22),((c.offsetX*b.m11)+(c.offsetY*b.m21))+b.offsetX,((c.offsetX*b.m12)+(c.offsetY*b.m22))+b.offsetY);return a;case 50:a.m11*=b.m11;a.m22*=b.m22;a.offsetX*=b.m11;a.offsetY*=b.m22;return a;case 51:a.m11*=b.m11;a.m22*=b.m22;a.offsetX=(b.m11*a.offsetX)+b.offsetX;a.offsetY=(b.m22*a.offsetY)+b.offsetY;return a}}var a=new Sweaky2D.Matrix2D();a.setMatrix(c.m11,c.m12,c.m21,c.m22,c.offsetX,c.offsetY);return a},multiplyPoint:function(c,f){var b=c;var e=f;switch(this.type){case Sweaky2D.MatrixType.IsIdentity:return new Sweaky2D.Vector2D(b,e);case Sweaky2D.MatrixType.IsTranslation:b+=this.offsetX;e+=this.offsetY;return new Sweaky2D.Vector2D(b,e);case Sweaky2D.MatrixType.IsScaling:b*=this.m11;e*=this.m22;return new Sweaky2D.Vector2D(b,e);case (Sweaky2D.MatrixType.IsScaling|Sweaky2D.MatrixType.IsTranslation):b*=this.m11;b+=this.offsetX;e*=this.m22;e+=this.offsetY;return new Sweaky2D.Vector2D(b,e)}var d=(b*this.m21)+this.offsetX;var a=(e*this.m12)+this.offsetY;b*=this.m11;b+=d;e*=this.m22;e+=a;return new Sweaky2D.Vector2D(b,e)},toString:function(){return"m11="+this.m11+", m12="+this.m12+", m21="+this.m21+", m22="+this.m22+", tx="+this.offsetX+", ty="+this.offsetY+", "}});Sweaky2D.Matrix2D.createIdentity=function(){return new Sweaky2D.Matrix2D()};Sweaky2D.Matrix2D.createTranslation=function(c,b){var a=new Sweaky2D.Matrix2D();a.offsetX=c;a.offsetY=b;a.type=Sweaky2D.MatrixType.IsTranslation;return a};Sweaky2D.Matrix2D.createRotation=function(g,c,h){if(c==null||h==null){c=0;h=0}var b=new Sweaky2D.Matrix2D();var f=Math.cos(g);var e=Math.sin(g);var d=(c*(1-f))+(h*e);var a=(h*(1-f))-(c*e);b.m11=f;b.m12=e;b.m21=-e;b.m22=f;b.offsetX=d;b.offsetY=a;b.type=Sweaky2D.MatrixType.IsUnknown;return b};Sweaky2D.Matrix2D.createScale=function(e,c,b,d){var a=new Sweaky2D.Matrix2D();a.type=Sweaky2D.MatrixType.IsScaling;if(b==null||d==null){b=0;d=0}else{a.type|=Sweaky2D.MatrixType.IsTranslation}a.m11=e;a.m12=0;a.m21=0;a.m22=c;a.offsetX=(b-(e*b));a.offsetY=(d-(c*d));return a};Sweaky2D.Math=Class.create({initialize:function(){}});Sweaky2D.Timer=Class.create({initialize:function(){this.maxStepAmount=0.05;this.reset()},reset:function(){this.last=0;this.lastStep=0;this.total=0},getElapsed:function(){var a=this.elapsed=this.total-this.last;this.last=this.total;return a},step:function(){var a=Date.now();var b=(a-this.lastStep)/1000;this.total+=Math.min(b,this.maxStepAmount);this.lastStep=a}});Sweaky2D.NamedObject=Class.create(Sweaky2D.Equatable,{initialize:function(a){this.name=a;this.index=0},isEqualTo:function(a){return(this==a)},toString:function(){return this.name}});Sweaky2D.NamedObjectCollection=Class.create(Sweaky2D.NamedObject,{initialize:function($super,a){$super(a);this.children=[]},onChildAdded:function(b,a){},onChildRemoved:function(b,a){},onChildIndexChanged:function(b,a){},add:function(a){this.addAt(a,this.children.length)},addAt:function(c,a){if(!this.exists(c)){var b=a;if(b>=this.children.length){b=this.children.length;this.children.push(c)}else{this.children.splice(b,0,c)}this.__refreshIndices(b);this.onChildAdded(c,b)}},remove:function(d){var b=null;if(!this.isEmpty()){var a=this.children.indexOf(d);if(a!=-1){var c=this.children.splice(a,1);if(c!=null&&c.length>0){b=c[0];this.__refreshIndices(a);this.onChildRemoved(b,a)}}}return b},removeAt:function(a){return this.remove(this.getAt(a))},removeByName:function(a){return this.remove(this.getByName(a))},getAt:function(a){if(a<this.children.length){return this.children[a]}return null},getByName:function(b){for(var c=0,a=this.children.length;c<a;++c){var d=this.children[c];if(d.name==b){return d}}return null},indexOf:function(a){return this.children.indexOf(a)},clear:function(){this.children.clear()},isEmpty:function(){return(this.children.length==0)},exists:function(a){if(a==null){return false}if(!this.isEmpty()){return(this.children.indexOf(a)!=-1)}return false},getCount:function(){return this.children.length},sort:function(a){this.children.sort(a);this.__refreshIndices(0)},toString:function(){var c="collection size: "+this.getCount();c+="\n";for(var b=0,a=this.getCount();b<a;++b){var d=this.children[b];c+="\t["+d.index+"] ";c+=d.name;c+="\n"}return c},__refreshIndices:function(b){var d=0;var e=null;for(var c=b,a=this.children.length;c<a;++c){e=this.children[c];if(e==null){continue}d=e.index;e.index=c;this.onChildIndexChanged(d,e.index)}}});Sweaky2D.Texture=Class.create(Sweaky2D.NamedObject,{initialize:function($super,a,b){$super("");this.id=Sweaky2D.NextTextureId++;this.data=null;this.size=Object.clone(Sweaky2D.Vector2D.Zero);this.originalSize=Object.clone(Sweaky2D.Vector2D.Zero);this.isReady=false;this.hasError=false;this.error="";this.filePath=a;this.loadCompleteHandlers=new Array();this.addLoadCompleteHandler(b);this.load()},addLoadCompleteHandler:function(a){this.loadCompleteHandlers.push({cb:a})},load:function(){if(this.isReady){this.onLoadComplete(true);return}this.data=new Image();this.data.onload=this.onLoad.bind(this);this.data.onerror=this.onError.bind(this);this.data.src=this.filePath+"?"+Math.random()},onLoad:function(a){this.originalSize.x=this.data.width;this.originalSize.y=this.data.height;this.size.x=this.data.width;this.size.y=this.data.height;this.isReady=true;this.onLoadComplete(true)},onError:function(a){this.hasError=true;this.error="Texture failed to load.";this.onLoadComplete(false)},onLoadComplete:function(b){if(this.loadCompleteHandlers!=null){for(var a=0;a<this.loadCompleteHandlers.length;a++){if(this.loadCompleteHandlers[a].cb!=null){this.loadCompleteHandlers[a].cb(this,b)}}}}});Sweaky2D.Texture.createTexture=function(b,c){var a=Sweaky2D.TextureCache[b];if(a==null){a=new Sweaky2D.Texture(b,c);Sweaky2D.TextureCache[b]=a}return a};Sweaky2D.GraphicsContext=Class.create({initialize:function(b,a){this.nativeContext=b;this.drawable=a},setAlpha:function(a){this.nativeContext.globalAlpha=a},setCompositeOp:function(a){this.nativeContext.globalCompositeOperation=a},setLineColor:function(a){this.nativeContext.strokeStyle=a},setLineWidth:function(a){this.nativeContext.lineWidth=a},setLineCap:function(a){this.nativeContext.lineCap=a},setLineJoin:function(a){this.nativeContext.lineJoin=a},setMiterLimit:function(a){this.nativeContext.miterLimit=a},setFillColor:function(a){this.nativeContext.fillStyle=a},setFont:function(a){this.nativeContext.font=a},setTextAlignment:function(a){this.nativeContext.textAlign=a},setTextBaseline:function(a){this.nativeContext.textBaseline=a},setTransform:function(h,g,l,k,j,i){this.nativeContext.setTransform(h,g,l,k,j,i)},save:function(){this.nativeContext.save()},restore:function(){this.nativeContext.restore()},translate:function(a,b){this.nativeContext.translate(a,b)},scale:function(b,a){this.nativeContext.scale(b,a)},rotate:function(a){this.nativeContext.rotate(a)},transform:function(h,g,l,k,j,i){this.nativeContext.transform(h,g,l,k,j,i)},clear:function(){},clearRect:function(b,d,c,a){this.nativeContext.clearRect(b,d,c,a)},fillRect:function(b,d,c,a){this.nativeContext.fillRect(b,d,c,a)},strokeRect:function(b,d,c,a){this.nativeContext.strokeRect(b,d,c,a)},beginPath:function(){this.nativeContext.beginPath()},closePath:function(){this.nativeContext.closePath()},moveTo:function(a,b){this.nativeContext.moveTo(a,b)},lineTo:function(a,b){this.nativeContext.lineTo(a,b)},quadraticCurveTo:function(c,b,a,d){this.nativeContext.quadraticCurveTo(c,b,a,d)},bezierCurveTo:function(c,e,b,d,a,f){this.nativeContext.bezierCurveTo(c,e,b,d,a,f)},arc:function(b,f,a,e,c,d){this.nativeContext.arc(b,f,a,e,c,d)},arcTo:function(c,e,b,d,a){this.nativeContext.arcTo(c,e,b,d,a)},rect:function(b,d,c,a){this.nativeContext.rect(b,d,c,a)},fill:function(){this.nativeContext.fill()},stroke:function(){this.nativeContext.stroke()},clip:function(){this.nativeContext.clip()},isPointInPath:function(a,b){return this.nativeContext.isPointInPath(a,b)},fillText:function(c,a,d,b){this.nativeContext.fillText(c,a,d,b)},strokeText:function(c,a,d,b){this.nativeContext.strokeText(c,a,d,b)},measureText:function(a){return this.nativeContext.measureText(a)},drawImage:function(d,b,e,c,a){this.nativeContext.drawImage(d,b,e,c,a)},drawTexture:function(c,b){var a=this.drawable.getSize();this.nativeContext.drawImage(c.data,b.x,b.y,b.width,b.height,0,0,a.x,a.y)},drawTextureTiled:function(d,c){var b=this.drawable.getSize();var a=this.nativeContext;var e=a.createPattern(d.data,"repeat");a.fillStyle=e;a.fillRect(0,0,b.x,b.y)},drawEllipse:function(b,e,d,a){var c=this.nativeContext;c.moveTo(b,e);c.beginPath();c.arc(b,e,d,0,360,false);c.closePath()},fillRadialGradient:function(b,h,a,f){var c=this.nativeContext;var e=c.createRadialGradient(b+a,h+a,0,b+a,h+a,a);for(var d=0;d<f.length;d++){e.addColorStop(f[d].offset,f[d].color)}c.fillStyle=e;c.fillRect(b,h,a*2,a*2)},drawRect:function(b,e,d,a){var c=this.nativeContext;c.beginPath();c.moveTo(b,e);c.lineTo(b+d,e);c.lineTo(b+d,e+a);c.lineTo(b,e+a);c.lineTo(b,e);c.closePath()}});Sweaky2D.SceneDrawable=Class.create(Sweaky2D.NamedObjectCollection,{initialize:function($super,a){$super(a);this.__matrix=new Sweaky2D.Matrix2D();this.__position=Object.clone(Sweaky2D.Vector2D.Zero);this.__size=Object.clone(Sweaky2D.Vector2D.NotSet);this.__scale=Object.clone(Sweaky2D.Vector2D.UnitScale);this.__bounds=Object.clone(Sweaky2D.Rectangle.Zero);this.__color=Object.clone(Sweaky2D.Color.White);this.__backgroundColor=new Sweaky2D.Color(0,0,0,0);this.__rotation=0;this.__centerOfRotation=Object.clone(Sweaky2D.Vector2D.NotSet);this.__opacity=0;this.__zIndex=Infinity;this.__isVisible=true;this.__useDefaultCenter=true;this.__gfx=new Sweaky2D.GraphicsContext(Sweaky2D.Application.getInstance().__context,this);this.parent=null;this.scene=null},getGraphics:function(){return this.__gfx},setCenterOfRotation:function(a,b){if((a!=this.__centerOfRotation.x||b!=this.__centerOfRotation.y)||this.__centerOfRotation.isEqualTo(Sweaky2D.Vector2D.NotSet)){this.__centerOfRotation.x=a;this.__centerOfRotation.y=b;this.__useDefaultCenter=false;this.__updateBounds();this.__updateMatrix()}},getPosition:function(){return this.__position},setPosition:function(a,b){if(a!=this.__position.x||b!=this.__position.y){this.__position.x=a;this.__position.y=b;this.__updateBounds();this.__updateMatrix()}},getSize:function(){return this.__size},setSize:function(b,a){if(b!=this.__size.x||a!=this.__size.y){this.__size.x=b;this.__size.y=a;this.__updateBounds();this.__updateMatrix()}},getScale:function(){return this.__scale},setScale:function(b,a){if(b!=this.__scale.x||a!=this.__scale.y){this.__scale.x=b;this.__scale.y=a;this.__updateBounds();this.__updateMatrix()}},getRotation:function(){return this.__rotation},setRotation:function(a){if(a!=this.__rotation){this.__rotation=a;this.__updateMatrix()}},getColor:function(){return this.__color},setColor:function(f,e,c,d){if(this.__color.r!=f||this.__color.g!=e||this.__color.b!=c||this.__color.a!=d){this.__color.r=f;this.__color.g=e;this.__color.b=c;this.setOpacity(d)}},getBackgroundColor:function(){return this.__backgroundColor},setBackgroundColor:function(f,e,c,d){if(this.__backgroundColor.r!=f||this.__backgroundColor.g!=e||this.__backgroundColor.b!=c||this.__backgroundColor.a!=d){this.__backgroundColor.r=f;this.__backgroundColor.g=e;this.__backgroundColor.b=c;this.__backgroundColor.a=d}},getOpacity:function(){return this.__color.a},setOpacity:function(a){if(this.__color.a!=a){this.__color.a=a}},getIsVisible:function(){return this.__isVisible},setIsVisible:function(a){if(a!=this.__isVisible){this.__isVisible=a}},getZIndex:function(){return this.__zIndex},setZIndex:function(a){if(a!=this.__zIndex){this.__zIndex=a;this.__updateDepth()}},localToGlobal:function(a){},globalToLocal:function(a){},removeFromParent:function(){},alignToCenter:function(){},alignToCenterOf:function(a){},alignToVerticalCenter:function(){},alignToVerticalCenterOf:function(a){},alignToHorizontalCenter:function(){},alignToHorizontalCenterOf:function(a){},computeOpacity:function(){var b=1;var a=this;while(a!=null){b*=a.getOpacity();a=a.parent}return b},drawChildren:function(d){if(this.getIsVisible()){var b=this.__matrix;this.__gfx.save();this.__gfx.transform(b.m11,b.m12,b.m21,b.m22,b.offsetX,b.offsetY);this.__gfx.setAlpha(this.computeOpacity());if(!this.isEmpty()){var c;var a=this.getCount();var e=null;for(c=0;c<a;c++){e=this.getAt(c);if(e!=null){e.drawChildren(d)}}}this.onDraw(d);this.__gfx.restore()}},updateChildren:function(c){if(!this.isEmpty()){var b;var a=this.getCount();var d=null;for(b=0;b<a;b++){d=this.getAt(b);if(d!=null){d.updateChildren(c)}}}this.onUpdate(c)},__sortByDepth:function(){this.sort(function(d,c){return(d.getZIndex()-c.getZIndex())})},__updateDepth:function(){if(this.parent!=null){this.parent.__sortByDepth()}else{this.__sortByDepth()}},onDraw:function(a){},onUpdate:function(a){},onAddedToStage:function(){},onChildAdded:function($super,b,a){if(b!=null){if(b!=this){b.parent=this}if(this.scene!=null){b.scene=this.scene}if(b.__zIndex==Infinity){b.setZIndex(this.getCount()-1)}b.__updateDepth();b.onAddedToStage()}$super(b,a)},onChildRemoved:function($super,b,a){if(b!=null){b.parent=null;b.scene=null}$super(b,a)},__updateBounds:function(){this.__bounds.x=this.__position.x;this.__bounds.y=this.__position.y;this.__bounds.width=this.__size.x;this.__bounds.height=this.__size.y},__updateMatrix:function(){if(this.__useDefaultCenter){this.__updateCenterOfRotation()}this.__matrix.setIdentity();this.__matrix.scaleAt(this.__scale.x,this.__scale.y,this.__centerOfRotation.x,this.__centerOfRotation.y);this.__matrix.rotateAt(this.__rotation,this.__centerOfRotation.x,this.__centerOfRotation.y);this.__matrix.translate(this.__position.x,this.__position.y);this.__matrix.validate()},__updateCenterOfRotation:function(){var a=this.getSize().multiply(this.getScale());if(a.x>0){this.__centerOfRotation.x=this.__position.x+(a.x*0.5)}if(a.y>0){this.__centerOfRotation.y=this.__position.y+(a.y*0.5)}}});Sweaky2D.Scene=Class.create(Sweaky2D.SceneDrawable,{initialize:function($super,b){$super(b);this.__isRunning=false;var a=Sweaky2D.Application.getInstance().getSize();this.setSize(a.x,a.y)},setZIndex:function($super,b){$super(b);var a=Sweaky2D.Application.getInstance();a.__sortByDepths()},getIsRunning:function(){return this.__isRunning},setIsRunning:function(a){this.__isRunning=a},drawChildren:function($super,a){if(this.getIsVisible()){$super(a)}},onChildAdded:function($super,b,a){if(b!=null){b.scene=this}$super(b,a)},onChildRemoved:function($super,b,a){if(b!=null){b.scene=null}$super(b,a)}});Sweaky2D.SceneManager=Class.create(Sweaky2D.NamedObjectCollection,{initialize:function($super){$super("SceneManager");this.__activeScene=null;this.__activeSceneIndex=0},nextScene:function(){this.goToScene(this.__activeSceneIndex++)},previousScene:function(){this.goToScene(this.__activeSceneIndex--)},runScene:function(a){this.add(a);this.goToScene(a.name)},goToScene:function(a){var b=this.getByName(a);if(b!=null){if(this.__activeScene!=null){this.__activeScene.setIsRunning(false)}this.__activeScene=b;this.__activeScene.setIsRunning(true);return true}return false},draw:function(f){var g=Sweaky2D.Application.getInstance();var d=g.getSize();var b=g.__context;b.clearRect(0,0,d.x,d.y);var c;var a=this.getCount();var e=null;for(c=0;c<a;c++){e=this.getAt(c);if(e==null||!e.getIsRunning()){continue}e.drawChildren(f)}},update:function(d){var b;var a=this.getCount();var c=null;for(b=0;b<a;b++){c=this.getAt(b);if(c==null||!c.getIsRunning()){continue}c.updateChildren(d)}},onChildAdded:function($super,b,a){if(b!=null){b.setSize(0,0);this.__sortByDepths()}$super(b,a)},__sortByDepths:function(){this.sort(function(d,c){return(d.getZIndex()-c.getZIndex())})}});Sweaky2D.Sprite=Class.create(Sweaky2D.SceneDrawable,{initialize:function($super,b,d,c,a){$super(b);this.texture=d;this.textureRect=null;this.isTiled=false;this.readyCallback=a;if(this.texture.isReady){this.initializeFromRect(c==null?new Sweaky2D.Rectangle(0,0,d.size.x,d.size.y):c)}else{if(c!=null){this.textureRect=c}this.texture.addLoadCompleteHandler(this.onTextureLoaded.bind(this))}},initializeFromRect:function(a){this.textureRect=a;if(this.getSize().isEqualTo(Sweaky2D.Vector2D.NotSet)){this.setSize(this.textureRect.width,this.textureRect.height)}if(this.readyCallback!=null){this.readyCallback(this)}},tile:function(){this.isTiled=true},untile:function(){this.isTiled=false},onTextureLoaded:function(a,b){if(b){this.initializeFromRect(this.textureRect==null?new Sweaky2D.Rectangle(0,0,this.texture.size.x,this.texture.size.y):this.textureRect)}},onDraw:function(a){if(this.isTiled){if(this.texture.isReady){this.getGraphics().drawTextureTiled(this.texture,this.textureRect)}}else{if(this.texture.isReady){this.getGraphics().drawTexture(this.texture,this.textureRect)}}}});Sweaky2D.SpriteManager=Class.create(Sweaky2D.NamedObjectCollection,{initialize:function($super){$super()},createTexture:function(a,b){if(this.getByName(a)!=null){return null}var c=Sweaky2D.Texture.createTexture(b,null);c.name=a;this.addTexture(c);return c},addTexture:function(a){this.add(a)},removeTextureByName:function(a){this.removeByName(a)},removeTexture:function(a){this.remove(a)},getSprite:function(a,b,d){var c=this.getByName(a);if(c==null){return null}return new Sweaky2D.Sprite(b,c,null,d)},getSpriteFromRect:function(a,c,e,f){var d=this.getByName(a);var b;if(d==null){return null}return new Sweaky2D.Sprite(c,d,e,f)}});Sweaky2D.SpriteManager.__instance=null;Sweaky2D.SpriteManager.getInstance=function(){if(Sweaky2D.SpriteManager.__instance==null){Sweaky2D.SpriteManager.__instance=new Sweaky2D.SpriteManager()}return Sweaky2D.SpriteManager.__instance};Sweaky2D.ParticlePoint=Class.create({initialize:function(){this.size=0;this.color=Object.clone(Sweaky2D.Color.Black);this.position=Object.clone(Sweaky2D.Vector2D.Zero)},toString:function(){return"position: "+this.position+", size: "+this.size+", color: "+this.color}});Sweaky2D.Particle=Class.create({initialize:function(){this.position=Object.clone(Sweaky2D.Vector2D.Zero);this.startPosition=Object.clone(Sweaky2D.Vector2D.Zero);this.direction=Object.clone(Sweaky2D.Vector2D.Zero);this.color=Object.clone(Sweaky2D.Color.Black);this.colorDelta=Object.clone(Sweaky2D.Color.Black);this.radialAccel=0;this.tangentAccel=0;this.size=0;this.sizeDelta=0;this.angle=0;this.angleDelta=0;this.lifeSpan=0}});Sweaky2D.ParticleEngine=Class.create(Sweaky2D.SceneDrawable,{initialize:function($super,a,c,b){$super(a);this.texture=c;this.particles=[];this.points=[];this.particleCount=0;this.particleIndex=0;this.inc=0;this.elapsed=0;this.isActive=false;this.totalParticles=0;this.additiveBlending=false;this.colorModulate=false;this.removeWhenFinished=false;this.duration=0;this.emissionRate=0;this.emissionCounter=0;this.emissionSpeed=0;this.angle=Object.clone(Sweaky2D.Vector2D.Zero);this.speed=Object.clone(Sweaky2D.Vector2D.Zero);this.tangentAccel=Object.clone(Sweaky2D.Vector2D.Zero);this.radialAccel=Object.clone(Sweaky2D.Vector2D.Zero);this.startSize=Object.clone(Sweaky2D.Vector2D.Zero);this.endSize=Object.clone(Sweaky2D.Vector2D.Zero);this.particleLife=Object.clone(Sweaky2D.Vector2D.Zero);this.startSpin=Object.clone(Sweaky2D.Vector2D.Zero);this.endSpin=Object.clone(Sweaky2D.Vector2D.Zero);this.gravity=Object.clone(Sweaky2D.Vector2D.Zero);this.centerOfGravity=Object.clone(Sweaky2D.Vector2D.Zero);this.positionVariance=Object.clone(Sweaky2D.Vector2D.Zero);this.positionType=1;this.startColor=Object.clone(Sweaky2D.Color.Black);this.startColorVariance=Object.clone(Sweaky2D.Color.Black);this.endColor=Object.clone(Sweaky2D.Color.Black);this.endColorVariance=Object.clone(Sweaky2D.Color.Black);this.initializeParticles(b)},stop:function(){this.isActive=false;this.elapsed=this.duration;this.emissionCounter=0},reset:function(){this.isActive=true;this.elapsed=0;for(this.particleIndex=0;this.particleIndex<this.particleCount;++this.particleIndex){var a=this.particles[this.particleIndex];a.lifeSpan=0}},isFull:function(){return(this.particleCount==this.totalParticles)},addParticle:function(){if(this.isFull()){return false}var a=new Sweaky2D.Particle();this.particles[this.particleCount]=a;this.initializeParticle(a);this.particleCount++;return true},initializeParticles:function(b){this.totalParticles=b;this.particles=new Array(this.totalParticles);this.points=new Array(this.totalParticles);for(var a=0;a<this.totalParticles;a++){if(this.points[a]==null){this.points[a]=new Sweaky2D.ParticlePoint()}}this.inc=2;this.elapsed=0;this.isActive=true;this.additiveBlending=false;this.colorModulate=false;this.removeWhenFinished=false;this.duration=0;this.emissionRate=0;this.emissionCounter=0;this.emissionSpeed=0.01;this.angle=Object.clone(Sweaky2D.Vector2D.Zero);this.speed=Object.clone(Sweaky2D.Vector2D.Zero);this.tangentAccel=Object.clone(Sweaky2D.Vector2D.Zero);this.radialAccel=Object.clone(Sweaky2D.Vector2D.Zero);this.startSize=Object.clone(Sweaky2D.Vector2D.UnitX);this.endSize=Object.clone(Sweaky2D.Vector2D.UnitX);this.particleLife=Object.clone(Sweaky2D.Vector2D.UnitNegativeX);this.startSpin=Object.clone(Sweaky2D.Vector2D.Zero);this.endSpin=Object.clone(Sweaky2D.Vector2D.Zero);this.gravity=Object.clone(Sweaky2D.Vector2D.Zero);this.centerOfGravity=Object.clone(Sweaky2D.Vector2D.Zero);this.positionVariance=Object.clone(Sweaky2D.Vector2D.Zero);this.positionType=1;this.startColor=Object.clone(Sweaky2D.Color.White);this.startColorVariance=Object.clone(Sweaky2D.Color.White);this.endColor=Object.clone(Sweaky2D.Color.White);this.endColorVariance=Object.clone(Sweaky2D.Color.White);this.particleIndex=0;this.particleCount=0},randomNegPos:function(){return((Math.random())-1)},randomZeroPos:function(){return(Math.random()/1073741823)},degToRad:function(a){return a/180*Math.PI},initializeParticle:function(f){var i=new Sweaky2D.Vector2D(0,0);f.position.x=(this.centerOfGravity.x+this.positionVariance.x*this.randomNegPos());f.position.y=(this.centerOfGravity.y+this.positionVariance.y*this.randomNegPos());var h=this.degToRad(this.angle.x+this.angle.y*this.randomNegPos());i.x=Math.cos(h);i.y=Math.sin(h);var k=this.speed.x+this.speed.y*this.randomNegPos();f.direction.x=i.x*k;f.direction.y=i.y*k;f.radialAccel=this.radialAccel.x+this.radialAccel.y*this.randomNegPos();f.tangentAccel=this.tangentAccel.x+this.tangentAccel.y*this.randomNegPos();f.lifeSpan=this.particleLife.x+this.particleLife.y*this.randomNegPos();f.lifeSpan=Math.max(0,f.lifeSpan);var b=new Sweaky2D.Color();b.r=this.startColor.r+this.startColorVariance.r*this.randomNegPos();b.g=this.startColor.g+this.startColorVariance.g*this.randomNegPos();b.b=this.startColor.b+this.startColorVariance.b*this.randomNegPos();b.a=this.startColor.a+this.startColorVariance.a*this.randomNegPos();var e=new Sweaky2D.Color();e.r=this.endColor.r+this.endColorVariance.r*this.randomNegPos();e.g=this.endColor.g+this.endColorVariance.g*this.randomNegPos();e.b=this.endColor.b+this.endColorVariance.b*this.randomNegPos();e.a=this.endColor.a+this.endColorVariance.a*this.randomNegPos();f.color=b;f.colorDelta.r=(e.r-b.r)/f.lifeSpan;f.colorDelta.g=(e.g-b.g)/f.lifeSpan;f.colorDelta.b=(e.b-b.b)/f.lifeSpan;f.colorDelta.a=(e.a-b.a)/f.lifeSpan;var j=this.startSize.x+this.startSize.y*this.randomNegPos();j=Math.max(0,j);f.size=j;if(this.endSize.x==-1){f.sizeDelta=0}else{var d=this.endSize.x+this.endSize.y*this.randomNegPos();f.sizeDelta=(d-j)/f.lifeSpan}var g=this.startSpin.x+this.startSpin.y*this.randomNegPos();var c=this.endSpin.x+this.endSpin.y*this.randomNegPos();f.angle=g;f.angleDelta=(c-g)/f.lifeSpan;f.startPosition=Object.clone(this.getPosition());return f},onUpdate:function(d){this.inc=2;var k=d;if(this.isActive&&this.emissionRate!=0){var g=1/this.emissionRate;this.emissionCounter+=k;while(this.particleCount<this.totalParticles&&this.emissionCounter>g){this.addParticle();this.emissionCounter-=g}this.elapsed+=k;if(this.duration!=-1&&this.duration<this.elapsed){this.stop()}}this.particleIndex=0;var a=Object.clone(this.getPosition());while(this.particleIndex<this.particleCount){var b=this.particles[this.particleIndex];if(b.lifeSpan>0){var e;var i=Object.clone(Sweaky2D.Vector2D.Zero);var c;if(b.position.x!=0||b.position.y!=0){i=Object.clone(b.position);i.normalize()}c=Object.clone(i);i.x=i.x*b.radialAccel;i.y=i.y*b.radialAccel;var f=c.x;c.x=-c.y;c.y=f;c.x=c.x*b.tangentAccel;c.y=c.y*b.tangentAccel;e=i.add(c).add(this.gravity);e.x=e.x*k;e.y=e.y*k;b.direction=b.direction.add(e);e.x=b.direction.x*k;e.y=b.direction.y*k;b.position=b.position.add(e);b.color.r+=(b.colorDelta.r*k);b.color.g+=(b.colorDelta.g*k);b.color.b+=(b.colorDelta.b*k);b.color.a+=(b.colorDelta.a*k);b.size+=(b.sizeDelta*k);b.size=Math.max(0,b.size);b.angle+=(b.angleDelta*k);b.lifeSpan-=k;var h=Object.clone(b.position);if(this.positionType==0){var j=a.subtract(b.startPosition);h=b.position.subtract(j)}this.points[this.particleIndex].color=Object.clone(b.color);this.points[this.particleIndex].size=b.size;this.points[this.particleIndex].position.x=h.x;this.points[this.particleIndex].position.y=h.y;this.particleIndex++}else{if(this.particleIndex!=this.particleCount-1){this.particles[this.particleIndex]=this.particles[this.particleCount-1]}this.particleCount--;if(this.particleCount==0&&this.removedWhenFinished){this.parent.remove(this)}}}},onDraw:function(d){var a=this.getGraphics();for(var b=0;b<this.particleCount;b++){var c=this.points[b];a.fillRadialGradient(c.position.x,c.position.y,c.size,[{offset:0,color:c.color.toRGBAString()},{offset:1,color:"rgba(255, 255, 255, 0)"}])}}});Sweaky2D.EventArgs=Class.create({initialize:function(){}});Sweaky2D.EventArgs.Empty=new Sweaky2D.EventArgs();Sweaky2D.MouseButton={Left:0,Right:1,Middle:2,XButton1:3,XButton2:4};Sweaky2D.MouseWheelDirection={Up:0,Down:1};Sweaky2D.MouseEventArgs=Class.create(Sweaky2D.EventArgs,{initialize:function($super){$super();this.isLeftButtonDown=false;this.isRightButtonDown=false;this.isMiddleButtonDown=false;this.isXButton1Down=false;this.isXButton2Down=false;this.x=0;this.y=0},getPosition:function(a){THROW_NO_IMPL()}});Sweaky2D.MouseButtonEventArgs=Class.create(Sweaky2D.MouseEventArgs,{initialize:function($super,a,b){$super();this.mouseButton=a;this.isDown=b;this.clickCount=1}});Sweaky2D.MouseWheelEventArgs=Class.create(Sweaky2D.MouseEventArgs,{initialize:function($super,a){$super();this.delta=a;this.direction=(a>0?Sweaky2D.MouseWheelDirection.Up:Sweaky2D.MouseWheelDirection.Down)}});Sweaky2D.InputManager=Class.create({initialize:function(){this.isUsingMouse=false;this.isUsingKeyboard=false;this.keyDownListener=this.keydown.bind(this);this.keyUpListener=this.keyup.bind(this);this.mouseWheelListener=this.mousewheel.bind(this);this.mouseMoveListener=this.mousemove.bind(this);this.mouseDownListener=this.keydown.bind(this);this.mouseUpListener=this.keyup.bind(this);this.contextMenuListener=this.contextmenu.bind(this);this.enableMouseEvents();this.enableKeyboardEvents()},enableMouseEvents:function(){if(this.isUsingMouse){return}this.isUsingMouse=true;var b=Sweaky2D.Application.getInstance();var a=b.getRenderTarget();window.addEventListener("mousewheel",this.mouseWheelListener,false);a.addEventListener("contextmenu",this.contextMenuListener,false);a.addEventListener("mousedown",this.mouseDownListener,false);a.addEventListener("mouseup",this.mouseUpListener,false);a.addEventListener("mousemove",this.mouseMoveListener,false)},disableMouseEvents:function(){if(!this.isUsingMouse){return}this.isUsingMouse=false;var b=Sweaky2D.Application.getInstance();var a=b.getRenderTarget();window.removeEventListener("mousewheel",this.mouseWheelListener,false);a.removeEventListener("contextmenu",this.contextMenuListener,false);a.removeEventListener("mousedown",this.mouseDownListener,false);a.removeEventListener("mouseup",this.mouseUpListener,false);a.removeEventListener("mousemove",this.mouseMoveListener,false)},enableKeyboardEvents:function(){if(this.isUsingKeyboard){return}this.isUsingKeyboard=true;window.addEventListener("keydown",this.keyDownListener,false);window.addEventListener("keyup",this.keyUpListener,false)},disableKeyboardEvents:function(){if(!this.isUsingKeyboard){return}this.isUsingKeyboard=false;window.removeEventListener("keydown",this.keyDownListener,false);window.removeEventListener("keyup",this.keyUpListener,false)},mousewheel:function(a){var c=Sweaky2D.Application.getInstance();var b=new Sweaky2D.MouseWheelEventArgs(a.wheelDelta);c.onMouseWheel(b);a.stopPropagation()},mousemove:function(a){var d=Sweaky2D.Application.getInstance();var c=d.getRenderTarget();var e=Object.clone(Sweaky2D.Vector2D.Zero);while(c!=null){e.x+=c.offsetLeft;e.y+=c.offsetTop;c=c.offsetParent}var b=new Sweaky2D.MouseEventArgs();b.x=(a.pageX-e.x);b.y=(a.pageY-e.y);d.onMouseMove(b)},contextmenu:function(a){var b=Sweaky2D.Application.getInstance();b.onContextMenu(Sweaky2D.EventArgs.Empty);a.stopPropagation();a.preventDefault()},keydown:function(a){if(a.target.type=="text"){return}var d=Sweaky2D.Application.getInstance();var b;var c;if(a.type=="keydown"){c=a.keyCode}else{switch(a.button){case 0:c=Sweaky2D.MouseButton.Left;break;case 1:c=Sweaky2D.MouseButton.Middle;break;case 2:c=Sweaky2D.MouseButton.Right;break}b=new Sweaky2D.MouseButtonEventArgs(c,true);d.onMouseDown(b)}a.stopPropagation();a.preventDefault()},keyup:function(a){if(a.target.type=="text"){return}var d=Sweaky2D.Application.getInstance();var b;var c;if(a.type=="keyup"){c=a.keyCode}else{switch(a.button){case 0:c=Sweaky2D.MouseButton.Left;break;case 1:c=Sweaky2D.MouseButton.Middle;break;case 2:c=Sweaky2D.MouseButton.Right;break}b=new Sweaky2D.MouseButtonEventArgs(c,false);d.onMouseUp(b)}a.stopPropagation();a.preventDefault()}});Sweaky2D.Application=Class.create(Sweaky2D.SceneManager,{initialize:function($super,b,c,a){$super();Sweaky2D.Application.__instance=this;this.__isInitialized=false;this.__is100PercentWidth=false;this.__is100PercentHeight=false;this.__isPaused=false;this.__isSuspended=true;this.__backgroundColor=Object.clone(Sweaky2D.Color.White);this.__size=new Sweaky2D.Vector2D((c==null?b.width:c),(a==null?b.getHeight():a));this.__suspensionIntervalTime=20;this.__maxAllowableElapsedTime=100;this.__previousElapsedTime=0;this.__totalElapsedTime=0;this.__clock=new Sweaky2D.Timer();this.__timer=null;this.__canvas=b;this.__canvas.width=this.__size.x;this.__canvas.height=this.__size.y;this.__context=this.__canvas.getContext("2d");this.__inputManager=new Sweaky2D.InputManager();this.__swap=false},getInputManager:function(){return this.__inputManager},getRenderTarget:function(){return this.__canvas},getIsInitialized:function(){return this.__isInitialized},getIsPaused:function(){return this.__isPaused},getIsSuspended:function(){return this.__isSuspended},getBackgroundColor:function(){return this.__backgroundColor},setBackgroundColor:function(a){this.__backgroundColor=a},setFrameRate:function(a){if(this.__timer!=null){clearInterval(this.__timer)}this.__timer=setInterval(this.step.bind(this),1000/a)},onMouseWheel:function(a){},onMouseDown:function(a){},onMouseUp:function(a){},onMouseMove:function(a){},onContextMenu:function(a){},getSize:function(){return this.__size},run:function(){this.__isPaused=false;this.__isSuspended=false;if(this.__timer==null){this.setFrameRate(30)}},pause:function(){this.__isPaused=true;this.__isSuspended=false},resume:function(){this.__isPaused=false;this.__isSuspended=false},suspend:function(){this.__isPaused=true;this.__isSuspended=true},dockToWindowWidth:function(a){this.__is100PercentWidth=a},dockToWindowHeight:function(a){this.__is100PercentHeight=a},onResize:function(){},step:function(){if(this.__is100PercentWidth){this.__canvas.width=document.body.clientWidth}if(this.__is100PercentHeight){this.__canvas.height=document.body.clientHeight}if(this.getIsSuspended()){return}this.__clock.step();var a=this.__clock.getElapsed();if(!this.__isPaused){this.update(a)}if(!this.__isSuspended){this.draw(a)}}});Sweaky2D.Application.__instance=null;Sweaky2D.Application.getInstance=function(){return Sweaky2D.Application.__instance};
