pandora.min.js 33 KB

1
  1. const PROPERTY_TYPE={NUMBER:1,VECTOR2:2,COLOR:3},SHAPES={RECT:1,ELLIPSE:2},TRANS_TYPE={LINEAR:1,QUAD:2,CUBIC:3,QUART:4,QUINT:5,SINE:6,EXPONENTIAL:7,CIRCULAR:8,ELASTIC:9,BACK:10,BOUNCE:11},EASE_TYPE={IN:1,OUT:2,IN_OUT:3},RENDER_MODES={P2D:1,WEBGL:2},STYLE={DEFAULT_FONT_SIZE:20,DEFAULT_STYLE:{"font-family":"Lato"}},Easings={Linear:{ease:function(t,e,i,s){return e+i*t/s}},Quad:{easeIn:function(t,e,i,s){return i*(t/=s)*t+e},easeOut:function(t,e,i,s){return-i*(t/=s)*(t-2)+e},easeInOut:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e}},Cubic:{easeIn:function(t,e,i,s){return i*(t/=s)*t*t+e},easeOut:function(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e},easeInOut:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e}},Quart:{easeIn:function(t,e,i,s){return i*(t/=s)*t*t*t+e},easeOut:function(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e},easeInOut:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e}},Quint:{easeIn:function(t,e,i,s){return i*(t/=s)*t*t*t*t+e},easeOut:function(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e},easeInOut:function(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e}},Sine:{easeIn:function(t,e,i,s){return-i*Math.cos(t/s*(Math.PI/2))+i+e},easeOut:function(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e},easeInOut:function(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e}},Expo:{easeIn:function(t,e,i,s){return 0==t?e:i*Math.pow(2,10*(t/s-1))+e},easeOut:function(t,e,i,s){return t==s?e+i:i*(1-Math.pow(2,-10*t/s))+e},easeInOut:function(t,e,i,s){return 0==t?e:t==s?e+i:(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e}},Circ:{easeIn:function(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e},easeOut:function(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e},easeInOut:function(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e}},Elastic:{easeIn:function(t,e,i,s){var n=1.70158,a=0,h=i;return 0==t?e:1==(t/=s)?e+i:(a=a||.3*s,n=h<Math.abs(i)?(h=i,a/4):a/(2*Math.PI)*Math.asin(i/h),-(h*Math.pow(2,10*--t)*Math.sin((t*s-n)*(2*Math.PI)/a))+e)},easeOut:function(t,e,i,s){var n=1.70158,a=0,h=i;return 0==t?e:1==(t/=s)?e+i:(a=a||.3*s,n=h<Math.abs(i)?(h=i,a/4):a/(2*Math.PI)*Math.asin(i/h),h*Math.pow(2,-10*t)*Math.sin((t*s-n)*(2*Math.PI)/a)+i+e)},easeInOut:function(t,e,i,s){var n=1.70158,a=0,h=i;return 0==t?e:2==(t/=s/2)?e+i:(a=a||s*(.3*1.5),n=h<Math.abs(i)?(h=i,a/4):a/(2*Math.PI)*Math.asin(i/h),t<1?h*Math.pow(2,10*--t)*Math.sin((t*s-n)*(2*Math.PI)/a)*-.5+e:h*Math.pow(2,-10*--t)*Math.sin((t*s-n)*(2*Math.PI)/a)*.5+i+e)}},Back:{easeIn:function(t,e,i,s){return i*(t/=s)*t*(2.70158*t-1.70158)+e},easeOut:function(t,e,i,s){return i*((t=t/s-1)*t*(2.70158*t+1.70158)+1)+e},easeInOut:function(t,e,i,s){var n=1.70158;return(t/=s/2)<1?i/2*(t*t*((1+(n*=1.525))*t-n))+e:i/2*((t-=2)*t*((1+(n*=1.525))*t+n)+2)+e}},Bounce:{easeIn:function(t,e,i,s){return i-Easings.Bounce.easeOut(s-t,0,i,s)+e},easeOut:function(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOut:function(t,e,i,s){return t<s/2?.5*Easings.Bounce.easeIn(2*t,0,i,s)+e:.5*Easings.Bounce.easeOut(2*t-s,0,i,s)+.5*i+e}}},Collisions={rotate(t,e,i){var s=t,n=e,a=radians(i);return i%360!=0&&(s=t*cos(-a)-e*sin(-a),n=t*sin(-a)+e*cos(-a)),Object.freeze([s,n])},Rect:{point(t,e,i,s,n,a,h,o){h-=t,o-=e;var[o,i]=Collisions.rotate(h,o,i);return abs(o)<=a.w/2*s&&abs(i)<=a.h/2*n}},Ellipse:{point(t,e,i,s,n,a,h,o){h-=t,o-=e;var[o,i]=Collisions.rotate(h,o,i),s=a.rx*s,n=a.ry*n;return o*o*(n*n)+i*i*(s*s)<=s*s*(n*n)}}},InputHandler={mouseIsPressed:!1,mouseIsReleased:!1,mouseIsClicked:!1,update(){this.mouseIsClicked=!1}};function mousePressed(){InputHandler.mouseIsPressed=!0,InputHandler.mouseIsReleased=!1}function mouseReleased(){InputHandler.mouseIsReleased=!0,InputHandler.mouseIsPressed=!1}function mouseClicked(){InputHandler.mouseIsClicked=!0,InputHandler.mouseIsPressed=!1,InputHandler.mouseIsReleased=!1}const GameHandler={nextId:0,rootObjects:[],renderMode:1,bDrawDebugFPS:!1,debugFpsLabel:null,bDrawDebugBufferBounds:!1,prevMillis:0,delta:0,db:null,dbWidth:1920,dbHeight:1080,isMobile:null,pixelDen:1,pixelDenMobile:2,mouseX:0,mouseY:0,pmouseX:0,pmouseY:0,backgroundColor:null,queuedCalls:[],setRenderMode(t){this.renderMode=t},setDoubleBufferSize(t,e){this.dbWidth=t,this.dbHeight=e},setPixelDensity(t){this.pixelDen=t},setPixelDensityMobile(t){this.pixelDenMobile=t},setBackgroundColor(t){this.backgroundColor=t},drawDebugFPS(t){this.bDrawDebugFPS=t},drawDebugBufferBounds(t){this.bDrawDebugBufferBounds=t},init(t=60){switch(this.isMobile=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),this.renderMode){case RENDER_MODES.P2D:createCanvas(windowWidth,windowHeight),this.db=createGraphics(this.dbWidth,this.dbHeight);break;case RENDER_MODES.WEBGL:createCanvas(windowWidth,windowHeight,WEBGL),this.db=createGraphics(this.dbWidth,this.dbHeight,WEBGL),this.db.smooth()}frameRate(t),this.isMobile?pixelDensity(this.pixelDenMobile):pixelDensity(this.pixelDen),smooth(),this.renderMode==RENDER_MODES.WEBGL&&(translate(-windowWidth/2,-windowHeight/2),db.translate(-this.dbWidth/2,-this.dbHeight/2)),this.bDrawDebugFPS&&(this.debugFpsLabel=new Label("debugFps","FPS: "+frameRate()),this.addRootObject(this.debugFpsLabel))},instanceGameObject(t){t.id=this.nextId,this.nextId++},addRootObject(t){this.rootObjects.push(t),t.isRoot=!0,t.setup()},removeRootObjectById(e){for(let t=0;t<this.rootObjects.length;t++)this.rootObjects[t].id==e&&this.rootObjects.splice(t,1)},queueCall(t,e,...i){this.queuedCalls.push([t,e,i])},upframecount:0,upframenum:20,update(){this.bDrawDebugFPS&&(frameCount%this.upframenum==0?(this.debugFpsLabel.setText("FPS: "+Math.round(1e3*this.upframecount)/1e3),this.upframecount=0):this.upframecount=max(this.upframecount,frameRate())),this.pmouseX=this.mouseX,this.pmouseY=this.mouseY;var t=this.db.screenWidth/this.db.width,e=(windowWidth-this.db.screenWidth)/2,i=(windowHeight-this.db.screenHeight)/2;this.mouseX=(mouseX-e)/t,this.mouseY=(mouseY-i)/t;for(let t=0;t<this.rootObjects.length;t++)this.rootObjects[t].update(this.delta)},draw(){this.db.clear(),this.bDrawDebugBufferBounds&&(this.db.push(),this.db.strokeWeight(5),this.db.noFill(),this.db.rect(0,0,this.dbWidth,this.dbHeight),this.db.pop()),imageMode(CENTER),windowWidth/windowHeight<this.dbWidth/this.dbHeight?(this.db.screenWidth=windowWidth,this.db.screenHeight=windowWidth*(this.dbHeight/this.dbWidth)):(this.db.screenHeight=windowHeight,this.db.screenWidth=windowHeight*(this.dbWidth/this.dbHeight));for(let t=0;t<this.rootObjects.length;t++)this.rootObjects[t].draw(this.delta,this.db);image(this.db,windowWidth/2,windowHeight/2,this.db.screenWidth,this.db.screenHeight),this.delta=(millis()-this.prevMillis)/1e3,this.prevMillis=millis();for(let t=0;t<this.queuedCalls.length;t++)this.queuedCalls[t][0][this.queuedCalls[t][1]](...this.queuedCalls[t][2]);for(;this.queuedCalls.length;)this.queuedCalls.pop()},_preload(){},_setup(){}};function preload(){GameHandler._preload()}function setup(){GameHandler._setup(),GameHandler.init()}function draw(){GameHandler.backgroundColor?background(GameHandler.backgroundColor.getP5Color()):background(200),GameHandler.update(),GameHandler.draw(),InputHandler.update()}function windowResized(){resizeCanvas(windowWidth,windowHeight)}const AssetHandler={cachedTextures:[],cachedAudios:[],cachedFonts:[],loadTexture:function(t,e){let i=new TextureRes(t,null);this.cachedTextures.push(i),loadImage(e,t=>{i.P5Image=t})},getTextureByName:function(e){for(let t=0;t<this.cachedTextures.length;t++)if(this.cachedTextures[t].name==e)return this.cachedTextures[t];return null},getP5ImageByName:function(e){for(let t=0;t<this.cachedTextures.length;t++)if(this.cachedTextures[t].name==e)return this.cachedTextures[t].P5Image;return null},clearTextureCache:function(){for(;this.cachedTextures.length;)this.cachedTextures.pop()},loadAudio:function(t,e){e=createAudio(e);this.cachedAudios.push(new AudioRes(t,e))},getAudioByName:function(e){for(let t=0;t<this.cachedAudios.length;t++)if(this.cachedAudios[t].name==e)return this.cachedAudios[t];return null},getP5AudioByName:function(e){for(let t=0;t<this.cachedAudios.length;t++)if(this.cachedAudios[t].name==e)return this.cachedAudios[t].P5Audio;return null},clearAudioCache:function(){for(;this.cachedAudios.length;)this.cachedAudios.pop()},loadFont:function(t,e){let i=new FontRes(t,null);this.cachedFonts.push(i),loadFont(e,t=>{i.P5Font=t})},getFontByName:function(e){for(let t=0;t<this.cachedFonts.length;t++)if(this.cachedFonts[t].name==e)return this.cachedFonts[t];return null},getP5FontByName:function(e){for(let t=0;t<this.cachedFonts.length;t++)if(this.cachedFonts[t].name==e)return this.cachedFonts[t].P5Font;return null},clearFontCache:function(){for(;this.cachedFonts.length;)this.cachedFonts.pop()}};class Component{constructor(){}}class Color{constructor(t,e,i,s=255){this.r=t,this.g=e,this.b=i,this.a=s,this.p5Color=color(this.r,this.g,this.b,this.a)}getP5Color(){return this.p5Color.setRed(this.r),this.p5Color.setGreen(this.g),this.p5Color.setBlue(this.b),this.p5Color.setAlpha(this.a),this.p5Color}}class Vector2 extends Component{static ZERO(){return new Vector2(0,0)}static ONE(){return new Vector2(1,1)}static RIGHT(){return new Vector2(1,0)}static LEFT(){return new Vector2(-1,0)}static UP(){return new Vector2(0,-1)}static DOWN(){return new Vector2(0,1)}constructor(t,e){super(),this.x=t,this.y=e}abs(){return new Vector2(abs(this.x),abs(this.y))}angle(){return atan2(this.y,this.x)}lengthSquared(){return this.x*this.x+this.y*this.y}length(){return sqrt(this.lengthSquared())}normalized(){var t=this.length();return new Vector2(this.x/t,this.y/t)}normalize(){var t=this.length();this.x/=t,this.y/=t}rotated(t){return new Vector2(this.x*cos(-t)-this.y*sin(-t),this.x*sin(-t)+this.y*cos(-t))}rotate(t){var e=this.x*cos(-t)-this.y*sin(-t),t=this.x*sin(-t)+this.y*cos(-t);this.x=e,this.y=t}scaled(t){return new Vector2(this.x*t,this.y*t)}scale(t){this.x*=t,this.y*=t}translated(t,e){return new Vector2(this.x+t,this.y+e)}translate(t,e){this.x+=t,this.y+=e}distanceSquaredTo(t){return new Vector2(t.x-this.x,t.y-this.y).length()}distance(t){return sqrt(this.distanceSquaredTo(t))}}class Signal extends Component{constructor(t){super(),this.name=t,this.targets=[],this.callbacks=[]}}class Shape extends Component{constructor(){super()}}class Rect extends Shape{constructor(t,e=t){super(),this.w=t,this.h=e}}class Ellipse extends Shape{constructor(t,e=t){super(),this.rx=t,this.ry=e}}class Resource{constructor(t=""){this.name=t}}class AudioRes extends Resource{constructor(t="",e=null){super(t),this.P5Audio=e}}class FontRes extends Resource{constructor(t="",e=null){super(t),this.P5Font=e}}class TextureRes extends Resource{constructor(t="",e=null){super(t),this.P5Image=e}}class SpriteAnimation extends Resource{constructor(t="default",e,i,s,n,a){super(t),this.fullP5Image=e,this.rows=i,this.columns=s,this.indices=n,this.numFrames=this.indices.length,this.frameTime=1/a,this.frames=[];for(let t=0;t<this.numFrames;t++)this.frames.push(this.makeFrame(t))}makeFrame(t){var e=int(this.indices[t]/this.columns),i=this.indices[t]%this.columns,s=this.fullP5Image.width/this.columns,t=this.fullP5Image.height/this.rows;return this.fullP5Image.get(i*s,e*t,s,t)}setFrameTime(t){this.frameTime=t}setFPS(t){this.frameTime=1/t}getFrame(t){return 0<=t&&t<this.numFrames?this.frames[t]:null}getFrameTime(){return this.frameTime}getNumFrames(){return this.numFrames}}class SpriteFrames extends Resource{constructor(){super(),this.animations=[],this.numAnimations=0}getAnimationByIndex(t){return 0<=t&&t<this.numAnimations?this.animations[t]:null}getAnimationByName(e){for(let t=0;this.numAnimations;t++)if(this.animations[t].name==e)return this.animations[t];return null}getAnimationIndexByName(e){for(let t=0;this.numAnimations;t++)if(this.animations[t].name==e)return t;return null}addAnimation(t,e,i,s,n,a=24){this.animations.push(new SpriteAnimation(t,e,i,s,n,a)),this.numAnimations++}}class GameObject{constructor(t){this.id=0,this.name=t,this.children=[],this.parented=!1,this.parent=null,this.isOnTree=!1,this.isRoot=!1,this.updatePaused=!1,this.signals=[],this.initSignals(),GameHandler.instanceGameObject(this)}getChildren(){return this.children}getChildByIndex(t){return 0<=t&&t<this.children.length?this.children[t]:null}getChildById(e){for(let t=0;t<this.children.length;t++)if(this.children[t].id==e)return this.children[t];return null}getChildByName(e){for(let t=0;t<this.children.length;t++)if(this.children[t].name==e)return this.children[t];return null}getParent(){return this.parented?this.parent:null}addSignal(t){this.signals.push(new Signal(t))}connect(e,i,s){for(let t=0;t<this.signals.length;t++)if(this.signals[t].name==e)return this.signals[t].targets.push(i),void this.signals[t].callbacks.push(s)}emitSignal(t,...i){for(let e=0;e<this.signals.length;e++)if(this.signals[e].name==t){for(let t=0;t<this.signals[e].callbacks.length;t++)this.signals[e].targets[t][this.signals[e].callbacks[t]](...i);return}}addChild(t){t.parent=this,t.parented=!0,this.children.push(t),this.isOnTree&&t.setup()}removeChildByIndex(t){0<=t&&t<this.children.length&&this.children.splice(t,1)}removeChildById(e){for(let t=0;t<this.children.length;t++)if(this.children[t].id==e)return void this.children.splice(t,1)}removeChildByName(e){for(let t=0;t<this.children.length;t++)if(this.children[t].name==e)return void this.children.splice(t,1)}callDeffered(t){GameHandler.queueCall(this,t)}free(){this.parented?this.getParent().removeChildById(this.id):this.isRoot&&GameHandler.removeRootObjectById(this.id),this.destroy()}queueFree(){GameHandler.queueCall(this,"free")}destroy(){for(let t=0;t<this.children.length;t++)this.children[t].destroy();for(var t in this)this[t]=null}initSignals(){this._initSignals()}setup(){this._setup();for(let t=0;t<this.children.length;t++)this.children[t].setup();this.isOnTree=!0}updateChildren(e){this._update(e);for(let t=0;t<this.children.length;t++)this.children[t].update(e)}update(t){this.updatePaused||this.updateChildren(t)}drawChildren(e,i){for(let t=0;t<this.children.length;t++)this.children[t].draw(e,i);this._draw(e,i)}draw(t,e){this.drawChildren(t,e)}_initSignals(){}_setup(){}_update(t){}_draw(t,e){}}class AudioPlayer extends GameObject{constructor(t,e=null){super(t),this.p5Audio=e}setP5Audio(t){this.p5Audio&&this.p5Audio.stop(),this.p5Audio=t}getP5Audio(){return this.p5Audio}play(){this.p5Audio&&this.p5Audio.play()}stop(){this.p5Audio&&this.p5Audio.stop()}autoplay(){this.p5Audio&&this.p5Audio.autoplay(!0)}}class Timer extends GameObject{constructor(t,e=1,i=!1,s=!1){super(t),this.duration=e,this.timeLeft=this.duration,this.paused=!i,this.autostart=i,this.oneShot=s}start(t=this.duration){this.paused&&(this.duration=t,this.paused=!1,this.timeLeft=this.duration)}stop(){this.paused=!0}resume(){this.paused=!1}isStopped(){return this.paused}onFinish(){this.oneShot&&(this.paused=!0),this.timeLeft=this.duration,this._onFinish(),this.emitSignal("timeout")}update(t){this.updatePaused||(this.paused||(this.timeLeft-=t,this.timeLeft<=0&&this.onFinish()),this.updateChildren(t))}initSignals(){this.addSignal("timeout"),this._initSignals()}_onFinish(){}}class TweenData{constructor(t,e,i,s,n,a,h,o,r){switch(this.target=t,this.property=e,this.propertyType=i,this.propertyType){case PROPERTY_TYPE.COLOR:this.initVal=new Color(s.r,s.g,s.b,s.a),this.finalVal=new Color(n.r,n.g,n.b,n.a);break;case PROPERTY_TYPE.VECTOR2:this.initVal=new Vector2(s.x,s.y),this.finalVal=new Vector2(n.x,n.y);break;case PROPERTY_TYPE.NUMBER:this.initVal=s,this.finalVal=n}switch(this.duration=a,this.transType=h,this.easeType=o,this.t=-r,this.playing=!1,this.done=!1,this.p=[],this.propertyType){case PROPERTY_TYPE.COLOR:this.p.push("r"),this.p.push("g"),this.p.push("b");break;case PROPERTY_TYPE.VECTOR2:this.p.push("x"),this.p.push("y");break;case PROPERTY_TYPE.NUMBER:}switch(this.trans="",this.transType){case TRANS_TYPE.LINEAR:this.trans="Linear";break;case TRANS_TYPE.QUAD:this.trans="Quad";break;case TRANS_TYPE.CUBIC:this.trans="Cubic";break;case TRANS_TYPE.QUART:this.trans="Quart";break;case TRANS_TYPE.QUINT:this.trans="Quint";break;case TRANS_TYPE.SINE:this.trans="Sine";break;case TRANS_TYPE.EXPONENTIAL:this.trans="Expo";break;case TRANS_TYPE.CIRCULAR:this.trans="Circ";break;case TRANS_TYPE.ELASTIC:this.trans="Elastic";break;case TRANS_TYPE.BACK:this.trans="Back";break;case TRANS_TYPE.BOUNCE:this.trans="Bounce"}if(this.ease="",this.transType==TRANS_TYPE.LINEAR)this.ease="ease";else switch(this.easeType){case EASE_TYPE.IN:this.ease="easeIn";break;case EASE_TYPE.OUT:this.ease="easeOut";break;case EASE_TYPE.IN_OUT:this.ease="easeInOut"}}}class Tween extends GameObject{constructor(t){super(t),this.tweenData=[],this.doneTweens=0,this.done=!1}interpolateProperty(t,e,i,s,n,a,h=1,o=3,r=0){this.done=!1,this.tweenData.push(new TweenData(t,e,i,s,n,a,h,o,r))}interpolate(e){if(e.propertyType==PROPERTY_TYPE.NUMBER)e.target[e.property]=Easings[e.trans][e.ease](e.t,e.initVal,e.finalVal-e.initVal,e.duration);else for(let t=0;t<e.p.length;t++)e.target[e.property][e.p[t]]=Easings[e.trans][e.ease](e.t,e.initVal[e.p[t]],e.finalVal[e.p[t]]-e.initVal[e.p[t]],e.duration)}startAll(){for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].playing=!0}startByIndex(t){t<0&&t>=this.tweenData.length||(this.tweenData[t].playing=!0)}stopAll(){for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].playing=!1}stopByIndex(t){t<0&&t>=this.tweenData.length||(this.tweenData[t].playing=!1)}resumeAll(){for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].playing=!0}resumeByIndex(t){t<0&&t>=this.tweenData.length||(this.tweenData[t].playing=!0)}resetAll(){this.doneTweens=0,this.done=!1;for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].t=0,this.tweenData[t].done=!1}resetByIndex(t){t<0&&t>=this.tweenData.length||(this.doneTweens--,this.done=!1,this.tweenData[t].t=0,this.tweenData[t].done=!1)}removeAll(){for(;0<this.tweenData.length;)this.tweenData.pop()}removeByIndex(t){t<0&&t>=this.tweenData.length||this.tweenData.splice(t,1)}seekAll(e){if(!(e<0))for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].t=min(e,this.tweenData[t].duration)}seekByIndex(t,e){t<0&&t>=this.tweenData.length||(this.tweenData[t].t=min(e,this.tweenData[t].duration))}allDone(){this.emitSignal("tweenAllCompleted"),this.done=!0}initSignals(){this.addSignal("tweenAllCompleted"),this.addSignal("tweenCompleted"),this.addSignal("tweenStarted"),this._initSignals()}update(e){if(!this.updatePaused){this.done||this.doneTweens!=this.tweenData.length||this.allDone();for(let t=0;t<this.tweenData.length;t++)this.tweenData[t].playing&&(0<=this.tweenData[t].t&&this.interpolate(this.tweenData[t]),this.tweenData[t].t<=0&&0<=this.tweenData[t].t+e&&this.emitSignal("tweenStarted",this.tweenData[t]),this.tweenData[t].t=min(this.tweenData[t].t+e,this.tweenData[t].duration),this.tweenData[t].done||this.tweenData[t].t!=this.tweenData[t].duration||(this.emitSignal("tweenDone",this.tweenData[t]),this.tweenData[t].done=!0,this.doneTweens+=1));this.updateChildren(e)}}}class Object2D extends GameObject{constructor(t){super(t),this.position=Vector2.ZERO(),this.rotationDegrees=0,this.scale=Vector2.ONE(),this.visible=!0,this.globalPosition=Vector2.ZERO(),this.globalRotationDegrees=0,this.globalScale=Vector2.ONE()}setPosition(t,e){this.position.x=t,this.position.y=e}show(){this.visible=!0;for(let t=0;t<this.children.length;t++)this.children[t].show&&this.children[t].show()}hide(){this.visible=!1;for(let t=0;t<this.children.length;t++)this.children[t].hide&&this.children[t].hide()}setVisibility(e){this.visible=e;for(let t=0;t<this.children.length;t++)this.children[t].setVisibility&&this.children[t].setVisibility(e)}getVisibility(){return this.visible}translate(t,e){this.position.x+=t,this.position.y+=e}rotate(t){this.rotationDegrees+=t}addScale(t,e){this.scale.x*=t,this.scale.y*=e}udpateGlobalTransform(){this.parented&&this.parent instanceof Object2D?(this.globalPosition.x=this.parent.globalPosition.x+this.position.x,this.globalPosition.y=this.parent.globalPosition.y+this.position.y,this.globalRotationDegrees=this.parent.globalRotationDegrees+this.rotationDegrees,this.globalScale.x=this.parent.globalScale.x*this.scale.x,this.globalScale.y=this.parent.globalScale.y*this.scale.y):(this.globalPosition=this.position,this.globalRotationDegrees=this.rotationDegrees,this.globalScale=this.scale)}update(t){this.updatePaused||(this.udpateGlobalTransform(),this.updateChildren(t))}applyTransform(t){t.translate(this.position.x,this.position.y),t.rotate(this.rotationDegrees/180*PI),t.scale(this.scale.x,this.scale.y)}draw(t,e){this.visible&&(e.push(),this.applyTransform(e),this.drawChildren(t,e),e.pop())}}class Sprite2D extends Object2D{constructor(t,e,i=CENTER){super(t),this.texture=e,this.imgMode=i,this.width=null,this.height=null}draw(t,e){e.push(),this.applyTransform(e),e.imageMode(this.imgMode),this.texture.P5Image&&(this.width&&this.height?e.image(this.texture.P5Image,0,0,this.width,this.height):e.image(this.texture.P5Image,0,0,this.texture.P5Image.width,this.texture.P5Image.height)),this.drawChildren(t,e),e.pop()}}class AnimatedSprite2D extends Sprite2D{constructor(t,e,i){super(t,e),this.spriteFrames=i,this.playing=!1,this.frame=0,this.currentAnimation=0,this.timeSinceLastFrame=0}setCurrentAnimationByIndex(t){t<this.spriteFrames.numAnimations?this.currentAnimation=t:this.currentAnimation=null,this.frame=0,this.timeSinceLastFrame=0}setCurrentAnimationByName(t){this.currentAnimation=this.spriteFrames.getAnimationIndexByName(t),this.frame=0,this.timeSinceLastFrame=0}setCurrentFrameTime(t){this.getCurrentAnimation().setFrameTime(t)}setCurrentFPS(t){this.getCurrentAnimation().setFPS(t)}getAnimationByIndex(t){return this.spriteFrames.getAnimationByIndex(t)}getCurrentAnimation(){return this.spriteFrames.getAnimationByIndex(this.currentAnimation)}getCurrentFrame(){return this.getCurrentAnimation().getFrame(this.frame)}getCurrentFrameTime(){return this.getCurrentAnimation().getFrameTime()}getCurrentNumFrames(){return this.getCurrentAnimation().getNumFrames()}play(){this.playing=!0}stop(){this.playing=!1}isPlaying(){return this.playing}update(t){this.updatePaused||(this.udpateGlobalTransform(),this.playing&&(this.timeSinceLastFrame+=t,this.timeSinceLastFrame>=this.getCurrentFrameTime()&&(this.frame=(this.frame+1)%this.getCurrentNumFrames(),this.timeSinceLastFrame=0)),this.P5Image=this.getCurrentFrame(),this.updateChildren(t))}}class Area2D extends Object2D{constructor(t,e,i,s=!0,n=!1){switch(super(t),this.shapeType=e,this.shapeType){case SHAPES.RECT:this.shapeName="Rect";break;case SHAPES.ELLIPSE:this.shapeName="Ellipse"}this.shape=i,this.listenToMouse=s,this.drawDebug=n,this.mouseIn=!1}setDrawDebug(t){this.drawDebug=t}initSignals(){this.addSignal("mouseEntered"),this.addSignal("mouseExited"),this._initSignals()}update(t){this.updatePaused||(this.udpateGlobalTransform(),this.listenToMouse&&(Collisions[this.shapeName].point(this.globalPosition.x,this.globalPosition.y,this.globalRotationDegrees,this.globalScale.x,this.globalScale.y,this.shape,GameHandler.mouseX,GameHandler.mouseY)?(this.mouseIn||this.emitSignal("mouseEntered"),this.mouseIn=!0):(this.mouseIn&&this.emitSignal("mouseExited"),this.mouseIn=!1)),this.updateChildren(t))}draw(t,e){if(this.visible){if(e.push(),this.applyTransform(e),this.drawDebug){switch(e.push(),e.noStroke(),e.fill(0,0,100,100),this.shapeType){case SHAPES.ELLIPSE:e.ellipseMode(CENTER),e.ellipse(0,0,2*this.shape.rx,2*this.shape.ry);break;case SHAPES.RECT:e.rectMode(CENTER),e.rect(0,0,this.shape.w,this.shape.h)}e.pop()}this.drawChildren(t,e),e.pop()}}}class UIObject extends GameObject{constructor(t){super(t),this.P5Element=null,this.visible=!0,this.position=new Vector2(0,0),this.size=new Vector2(300,100),this.fontSize=STYLE.DEFAULT_FONT_SIZE}connectCallbacks(){this.P5Element.mousePressed(this.onMousePressed),this.P5Element.doubleClicked(this.onDoubleClicked),this.P5Element.mouseWheel(this.onMouseWheel),this.P5Element.mouseReleased(this.onMouseReleased),this.P5Element.mouseClicked(this.onMouseClicked),this.P5Element.mouseMoved(this.onMouseMoved),this.P5Element.mouseOver(this.onMouseOver),this.P5Element.mouseOut(this.onMouseOut),this.P5Element.touchStarted(this.onTouchStarted),this.P5Element.touchMoved(this.onTouchMoved),this.P5Element.touchEnded(this.onTouchEnded),this.P5Element.dragOver(this.onDragOver),this.P5Element.dragLeave(this.onDragLeave),this.P5Element.pandoraObject=this}setPosition(t,e){this.position.x=t,this.position.y=e}setSize(t,e){this.size.x=t,this.size.y=e}setFontSize(t){this.fontSize=t}setVisibility(t){t?this.P5Element.show():this.P5Element.hide(),this.visible=!this.visible}setValue(t){this.P5Element.value(t)}setStyle(t){for(var[e,i]of Object.entries(t))this.P5Element.style(""+e,i)}getPosition(){return this.position}getSize(){return this.size}getFontSize(){return this.fontSize}getVisibility(){return this.visible}getValue(){return this.P5Element.value()}show(){this.visible=!0,this.P5Element.show();for(let t=0;t<this.children.length;t++)this.children[t].show&&this.children[t].show()}hide(){this.visible=!1,this.P5Element.hide();for(let t=0;t<this.children.length;t++)this.children[t].hide&&this.children[t].hide()}addChild(t){t.parent=this,t.parented=!0,this.children.push(t),t.P5Element&&t.P5Element.parent(this.P5Element)}destroy(){for(let t=0;t<this.children.length;t++)this.children[t].destroy();for(var t in this.P5Element&&this.P5Element.remove(),this)this[t]=null}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this._initSignals()}draw(t,e){var i=e.screenWidth/e.width,s=(windowWidth-e.screenWidth)/2,n=(windowHeight-e.screenHeight)/2;this.parented?this.P5Element.position(s+(this.parent.globalPosition.x+this.position.x)*i,n+(this.parent.globalPosition.y+this.position.y)*i):this.P5Element.position(s+this.position.x*i,n+this.position.y*i),this.P5Element.size(this.size.x*i,this.size.y*i),this.setStyle({"font-size":this.fontSize*i+"px"}),this.drawChildren(t,e)}onMousePressed(){this.pandoraObject.emitSignal("mousePressed"),this.pandoraObject._onMousePressed()}onDoubleClicked(){this.pandoraObject.emitSignal("doubleClicked"),this.pandoraObject._onDoubleClicked()}onMouseWheel(t){this.pandoraObject.emitSignal("mouseWheel",t),this.pandoraObject._onMouseWheel(t)}onMouseReleased(){this.pandoraObject.emitSignal("mouseReleased"),this.pandoraObject._onMouseReleased()}onMouseClicked(){this.pandoraObject.emitSignal("mouseClicked"),this.pandoraObject._onMouseClicked()}onMouseMoved(){this.pandoraObject.emitSignal("mouseMoved"),this.pandoraObject._onMouseMoved()}onMouseOver(){this.pandoraObject.emitSignal("mouseOver"),this.pandoraObject._onMouseOver()}onMouseOut(){this.pandoraObject.emitSignal("mouseOut"),this.pandoraObject._onMouseOut()}onTouchStarted(){this.pandoraObject.emitSignal("touchStarted"),this.pandoraObject._onTouchStarted()}onTouchMoved(){this.pandoraObject.emitSignal("touchMoved"),this.pandoraObject._onTouchMoved()}onTouchEnded(){this.pandoraObject.emitSignal("touchEnded"),this.pandoraObject._onTouchEnded()}onDragOver(){this.pandoraObject.emitSignal("dragOver"),this.pandoraObject._onDragOver()}onDragLeave(){this.pandoraObject.emitSignal("dragLeave"),this.pandoraObject._onDragLeave()}_onMousePressed(){}_onDoubleClicked(){}_onMouseWheel(t){}_onMouseReleased(){}_onMouseClicked(){}_onMouseMoved(){}_onMouseOver(){}_onMouseOut(){}_onTouchStarted(){}_onTouchMoved(){}_onTouchEnded(){}_onDragOver(){}_onDragLeave(){}}class Button extends UIObject{constructor(t,e="Button"){super(t),this.P5Element=createButton(),this.label=e,this.P5Element.html(e),this.setPosition(0,0),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks()}setLabel(t){this.label=t,this.P5Element.html(t)}}class CheckBox extends UIObject{constructor(t,e="checkbox",i=!1){super(t),this.label=e,this.P5Element=createCheckbox(e,i),this.setPosition(0,0),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks(),this.P5Element.changed(this.onChanged)}setLabel(t){this.label=t,this.P5Element.html(t)}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this.addSignal("changed"),this._initSignals()}onChanged(){this.pandoraObject.emitSignal("changed"),this.pandoraObject._onChanged()}_onChanged(){console.log(this.P5Element.checked())}}class ColorPicker extends UIObject{constructor(t,e="#FFFFFF"){super(t),this.P5Element=createColorPicker(e),this.setPosition(0,0),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks()}setColor(t){this.P5Element.color(t)}getColor(){return this.P5Element.color()}}class Input extends UIObject{constructor(t,e="",i="text"){super(t),this.P5Element=createInput(e,i),this.setPosition(0,0),this.setSize(200,30),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks(),this.P5Element.input(this.onInput)}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this.addSignal("input"),this._initSignals()}onInput(){this.pandoraObject.emitSignal("input"),this.pandoraObject._onInput()}_onInput(){}}class Label extends UIObject{constructor(t,e="Label"){super(t),this.text=e,this.P5Element=createDiv(e),this.setPosition(0,0),this.setSize(200,50),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks()}setText(t){this.P5Element.html(t),this.text=t}getText(){return this.text}}class Radio extends UIObject{constructor(t){super(t),this.P5Element=createRadio(),this.setPosition(10,10),this.multiLine=!1,this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks(),this.P5Element.changed(this.onChanged)}setSelected(t){this.P5Element.selected(t)}getSelected(){return this.P5Element.selected()}addOption(t){this.P5Element.option(t),this.multiLine&&this.makeMultiline()}makeMultiline(){this.multiLine=!0;var e=selectAll("input",this.P5Element),i=selectAll("label",this.P5Element),s=e.length;for(let t=0;t<s;++t)createDiv().parent(this.P5Element).child(e[t]).child(i[t]);this.fixRadioDivElement()}fixRadioDivElement(){this.P5Element._getInputChildrenArray=function(){return this.elt.getElementsByTagName("input")}}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this.emitSignal("changed"),this._initSignals()}onChanged(){this.pandoraObject.emitSignal("changed"),this.pandoraObject._onChanged()}_onChanged(){console.log(this.getSelected())}}class Select extends UIObject{constructor(t){super(t),this.P5Element=createSelect(),this.setPosition(0,0),this.setSize(100,20),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks(),this.P5Element.changed(this.onChanged)}setSelected(t){this.P5Element.selected(t)}getSelected(){return this.P5Element.selected()}addOption(t){this.P5Element.option(t)}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this.addSignal("changed"),this._initSignals()}onChanged(){this.pandoraObject.emitSignal("changed"),this.pandoraObject._onChanged()}_onChanged(){}}class Slider extends UIObject{constructor(t,e=0,i=100,s=0,n=0){super(t),this.P5Element=createSlider(e,i,s,n),this.setPosition(0,0),this.setSize(200,25),this.setStyle(STYLE.DEFAULT_STYLE),this.connectCallbacks(),this.P5Element.changed(this.onChanged)}initSignals(){this.addSignal("mousePressed"),this.addSignal("doubleClicked"),this.addSignal("mouseWheel"),this.addSignal("mouseReleased"),this.addSignal("mouseClicked"),this.addSignal("mouseMoved"),this.addSignal("mouseOver"),this.addSignal("mouseOut"),this.addSignal("touchStarted"),this.addSignal("touchMoved"),this.addSignal("touchEnded"),this.addSignal("dragOver"),this.addSignal("dragLeave"),this.addSignal("changed"),this._initSignals()}onChanged(){this.pandoraObject.emitSignal("changed"),this.pandoraObject._onChanged()}_onChanged(){}}