-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNaubino.min.js
1 lines (1 loc) · 77.7 KB
/
Naubino.min.js
1
(function(){var e=function(e,t){return function(){return e.apply(t,arguments)}};define("Audio",[],function(){var t;return t=function(){function t(){this.random_blub=e(this.random_blub,this);var t,n,r,i,s;s=this.blub_paths;for(n=r=0,i=s.length;r<i;n=++r)t=s[n],this.blubs[n]=AudioFX(this.path+t,{formats:["ogg","mp3"],pool:this.pool})}return t.prototype.path="sound/",t.prototype.blubs=[],t.prototype.pool=10,t.prototype.i=0,t.prototype.blub_paths=["8000__cfork__cf-fx-bloibb","8001__cfork__cf-fx-doppp-01","8003__cfork__cf-fx-doppp-03-dry","8008__cfork__cf-fx-plopp-01","8009__cfork__cf-fx-plopp-02"],t.prototype.random_blub=function(){var e;return e=this.i++%this.blubs.length,this.blubs[e].play()},t.prototype.connect_to_game=function(e){return e.naub_replaced.add(this.random_blub),e.naub_destroyed.add(this.random_blub)},t}()})}).call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty;define("Keybindings",[],function(){var n;return n=function(){function n(){this.keyup=e(this.keyup,this),this.keydown=e(this.keydown,this),this.step=e(this.step,this),this.disable=e(this.disable,this),this.enable=e(this.enable,this),this.bindings={},this.active_bindings={}}return n.prototype.enable=function(e,t,n,r){return this.bindings[e]={down:t,up:n,during:r}},n.prototype.disable=function(e){var t,n;return t=this.active_bindings[e],(n=this.bindings[e])!=null&&typeof n.up=="function"&&n.up(),delete this.bindings[e],delete this.active_bindings[e]},n.prototype.step=function(e){var n,r,i,s,o;s=this.active_bindings,o=[];for(r in s){if(!t.call(s,r))continue;n=typeof (i=this.active_bindings[r]).during=="function"?i.during(e):void 0,o.push(this.active_bindings[r].called=!0)}return o},n.prototype.keydown=function(e){var t,n;t=e.which;if(t in this.bindings&&!(t in this.active_bindings))return typeof (n=this.bindings[t]).down=="function"&&n.down(),this.active_bindings[t]={during:this.bindings[t].during,called:!1}},n.prototype.keyup=function(e){var t,n,r,i,s;r=e.which;if(r in this.active_bindings)return s=this.active_bindings[r],n=s.during,t=s.called,t||typeof n=="function"&&n(),delete this.active_bindings[r],typeof (i=this.bindings[r]).up=="function"?i.up():void 0},n}()})}.call(this),function(){define("Settings",[],function(){var e;return e={graphics:{fps:35,updating:!0,draw_shadows:!0,draw_borders:!1,effects:!1},game:{creation_offset:50,min_joining_force:1e3,font:"Helvetica"},naub:{size:42,margin:8,mass:5,friction:.1,elasticity:.3,min_join_len:1.2,max_join_len:2},step_rate:40,physics:{center_join:{restLength:30,stiffness:7,damping:7},join_length:3,spring_force:.6,damping:.1},canvas:{scale:1,width:800,height:450},events:{"default":[{name:"init",from:["none","stopped"],to:"stopped"},{name:"play",from:["paused","stopped"],to:"playing"},{name:"pause",from:["paused","playing"],to:"paused"},{name:"stop",from:"*",to:"stopped"}],game:[{name:"loose",from:"playing",to:"lost"},{name:"stop",from:"lost",to:"stopped"}],background:[{name:"pulse",from:"playing",to:"pulsing"},{name:"stop_pulse",from:"pulsing",to:"playing"},{name:"pause",from:"pulsing",to:"paused_pulse"},{name:"play",from:"paused_pulse",to:"pulsing"}]},menu:{font:"Helvetica",color:"white"},overlay:{font:"Helvetica",color:"Black",fontsize:25,duration:1,fade_duration:1},color:"output",colors:{output:[[229,53,23,1,"red"],[151,190,13,1,"green"],[0,139,208,1,"blue"],[255,204,0,1,"yellow"],[226,0,122,1,"pink"],[100,31,128,1,"purple"],[41,14,3,1,"tell me"]],high_contrast:[[255,0,0,1,"hcred"],[0,224,0,1,"hcgreen"],[0,128,224,1,"hcblue"],[255,255,0,1,"hcyellow"],[0,0,0,1,"hcblack"],[255,255,255,1,"hcwhite"],[128,0,128,1,"hcpurple"]],70:[[166,30,30,1],[38,110,128,1],[41,14,3,1],[188,105,105,1],[33,66,19,1],[12,47,56,1],[110,155,88,1]],"Gasoline Rainbow":[[189,42,51,1],[147,163,28,1],[48,55,79,1],[214,170,38,1],[64,129,86,1],[130,65,108,1],[188,86,43,1]]}}})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}};define("Layer",[],function(){var t;return t=function(){function t(t){this.canvas=t,this.one_after_another=e(this.one_after_another,this),this.move_pointer=e(this.move_pointer,this),this.unfocus=e(this.unfocus,this),this.click=e(this.click,this),this.name="unnamed layer",this.width=this.canvas.width,this.height=this.canvas.height,this.ctx=this.canvas.getContext("2d"),this.center=function(){return new cp.v(this.width/2,this.height/2)},this.pointer=this.center(),this.objects={},this.objects_count=0,this.fps=this.default_fps=Naubino.settings.graphics.fps,this.step_rate=this.default_step_rate=Naubino.settings.step_rate,this.show()}return t.prototype.default_state_machine={initial:"none",callbacks:{error:function(e,t,n,r,i,s){return console.error(""+this.name+"."+e+": "+t+" -> "+n+"\n"+i+"::"+s)}}},t.prototype.setup_fsm=function(e){var t;return e==null&&(e=[]),this.default_state_machine.target=this,t=Naubino.settings.events["default"].concat(e),this.default_state_machine.events=t,StateMachine.create(this.default_state_machine)},t.prototype.onplay=function(e,t,n){return this.show(),this.start_drawing(),this.start_stepping()},t.prototype.onpause=function(e,t,n){return this.stop_stepping(),this.stop_drawing()},t.prototype.onstop=function(e,t,n){return this.stop_stepping(),this.stop_drawing(),this.clear(),this.clear_objects()},t.prototype.start_stepping=function(){if(this.step_loop==null)return this.step_loop=setInterval(function(e){return function(){return e.step()}}(this),1e3/this.step_rate)},t.prototype.stop_stepping=function(){return clearInterval(this.step_loop),this.step_loop=null},t.prototype.start_drawing=function(){if(this.draw_loop==null)return this.draw_loop=setInterval(function(e){return function(){return e.draw()}}(this),1e3/this.fps)},t.prototype.stop_drawing=function(){return clearInterval(this.draw_loop),this.draw_loop=null},t.prototype.refresh_draw_rate=function(e){return e==null&&(e=!1),e&&(this.fps=e),this.stop_drawing(),this.start_drawing()},t.prototype.refresh_step_rate=function(e){return e==null&&(e=!1),e&&(this.step_rate=e),this.stop_drawing(),this.start_drawing()},t.prototype.step=function(){},t.prototype.draw=function(){},t.prototype.resize_to=function(e,t){return this.canvas.width=e,this.canvas.height=t},t.prototype.resize_by=function(e){return this.canvas.width*=e,this.canvas.height*=e,this.ctx.scale(e,e),this.clear()},t.prototype.reset_resize=function(){return this.ctx.setTransform(1,0,0,1,0,0),this.canvas.width=Naubino.settings.canvas.width,this.canvas.height=Naubino.settings.canvas.height,this.clear()},t.prototype.fade_in=function(e){var t;return e==null&&(e=null),this.start_drawing(),this.canvas.style.opacity=.01,this.backup_ctx!=null&&this.restore(),t=function(t){return function(){if((t.canvas.style.opacity*=1.2)>=1){clearInterval(t.fadeloop),t.show();if(e!=null&&typeof e=="function")return e.call()}}}(this),clearInterval(this.fadeloop),this.fadeloop=setInterval(t,40)},t.prototype.fade_out=function(e){var t;return e==null&&(e=null),this.start_drawing(),this.cache(),t=function(t){return function(){if((t.canvas.style.opacity*=.8)<=.05){clearInterval(t.fadeloop),t.hide();if(e!=null&&typeof e=="function")return e.call(),t.stop_drawing()}}}(this),clearInterval(this.fadeloop),this.fadeloop=setInterval(t,70)},t.prototype.show=function(){return this.canvas.style.opacity=1},t.prototype.hide=function(){return this.canvas.style.opacity=0},t.prototype.clear=function(){return this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)},t.prototype.cache=function(){return this.backup_ctx=this.ctx},t.prototype.restore=function(){return this.ctx=this.backup_ctx},t.prototype.click=function(e,t){var n,r;this.mousedown=!0,r=[e,t],this.pointer.x=r[0],this.pointer.y=r[1],n=this.get_obj_in_pos(this.pointer);if(n)return n.focus(),this.focused_naub=n},t.prototype.unfocus=function(){return this.mousedown=!1,this.focused_naub&&this.focused_naub.unfocus(),this.focused_naub=null},t.prototype.move_pointer=function(e,t){var n;if(this.mousedown)return n=[e,t],this.pointer.x=n[0],this.pointer.y=n[1],n},t.prototype.add_object=function(e){return e.center=this.center(),++this.objects_count,e.number=this.objects_count,this.objects[this.objects_count]=e,this.objects_count},t.prototype.remove_obj=function(e){var t;return t=this.get_object(e),delete this.objects[e]},t.prototype.get_object=function(e){return this.objects[e]},t.prototype.get_obj_in_pos=function(e){var t,n,r;r=this.objects;for(t in r){n=r[t];if(n.isHit(e.x,e.y)&&n.isClickable)return n}},t.prototype.clear_objects=function(){return this.objects={}},t.prototype.for_each=function(e){var t,n,r;r=this.objects;for(t in r)n=r[t],e(n)},t.prototype.one_after_another=function(e,t,n){var r;return n==null&&(n=Object.keys(this.objects)),r=n.shift(),r!=null?(setTimeout(function(r){return function(){return r.one_after_another(e,t,n)}}(this),150),e(this.get_object(r))):t()},t.prototype.draw_point=function(e,t){return t==null&&(t="black"),this.ctx.beginPath(),this.ctx.arc(e.x,e.y,4,0,2*Math.PI,!1),this.ctx.arc(e.x,e.y,1,0,2*Math.PI,!1),this.ctx.lineWidth=1,this.ctx.strokeStyle=t,this.ctx.stroke(),this.ctx.closePath()},t}()})}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};define("Background",["Layer"],function(e){var n;return n=function(e){function n(e){n.__super__.constructor.call(this,e),this.name="background",this.setup_fsm(Naubino.settings.events.background),this.fps=this.default_fps=2,this.min_fps=15,this.min_step_rate=15}return t(n,e),n.prototype.set_defaults=function(){return this.p_min={color:[130,130,130],thick:2},this.p_max={color:Naubino.colors()[0],thick:12},this.target=void 0,this.default_thickness=this.basket_thickness=4,this.color=this.default_color=[100,100,100],this.pulse_speed=10,this.pulsating=!1,this.pulse_ends=!1},n.prototype.onstopped=function(){return this.set_defaults()},n.prototype.onbeforepulse=function(){return Naubino.settings.graphics.effects===!0?this.refresh_draw_rate(25):this.refresh_draw_rate(10)},n.prototype.onenterpulsing=function(){return this.pulsating=!0},n.prototype.onleavepulsing=function(e,t,n){return e==="stop_pulse"?(this.pulse_ends=!0,StateMachine.ASYNC):(this.pulsating=!1,!0)},n.prototype.onstop_pulse=function(){return this.pulsating=!1,this.refresh_draw_rate(this.default_fps)},n.prototype.draw=function(){return this.clear(),this.draw_basket()},n.prototype.draw_basket=function(){var e,t;return e=this.center(),this.basket_size=(t=Naubino.game.basket_size())!=null?t:150,this.ctx.save(),this.ctx.beginPath(),this.ctx.arc(e.x,e.y,this.basket_size+this.basket_thickness*2,0,Math.PI*2,!1),this.ctx.lineWidth=this.basket_thickness,this.ctx.strokeStyle=Util.color_to_rgba(this.color),this.ctx.stroke(),this.ctx.closePath(),this.ctx.restore()},n.prototype.step=function(){this.pulsating&&(this.target==null&&(this.target=this.p_max),this.basket_thickness=Util.interpolate(this.basket_thickness,this.target.thick,this.pulse_speed/100),this.color=Util.interpolate_color(this.color,this.target.color,this.pulse_speed/100),Math.abs(this.basket_thickness-this.target.thick)<1&&(this.target===this.p_max?this.target=this.p_min:this.target=this.p_max));if(this.pulse_ends&&Math.abs(this.default_thickness-this.basket_thickness)<1)return this.set_defaults(),this.transition(),this.draw(),console.log("pulsing stopped")},n.prototype.drawTextAlongArc=function(e,t){var n,r,i,s,o;t==null&&(t=0),n=e.length*.1,this.ctx.save(),r=this.center(),this.ctx.translate(r.x,r.y),this.ctx.rotate(-1*n/2),this.ctx.rotate(-1*(n/e.length)/2+t);for(s=0,o=e.length;s<o;s++)i=e[s],this.ctx.rotate(n/e.length),this.ctx.save(),this.ctx.translate(0,-1*this.basket_size+15),this.ctx.fillStyle=Util.color_to_rgba(this.color),this.ctx.textAlign="center",this.ctx.font="20px Helvetica",this.ctx.fillText(i,0,0),this.ctx.restore();return this.ctx.restore()},n.prototype.draw_line=function(e,t,n,r,i){return n==null&&(n=this.center().x),r==null&&(r=this.center().y),i==null&&(i="black"),this.ctx.beginPath(),this.ctx.moveTo(e,t),this.ctx.lineTo(n,r),this.ctx.lineWidth=2,this.ctx.strokeStyle=i,this.ctx.stroke(),this.ctx.closePath()},n}(e)})}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};define("Physical_Layer",["Layer"],function(e){var n;return n=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.setup_physics=function(){return this.GRABABLE_MASK_BIT=1<<31,this.NOT_GRABABLE_MASK=~this.GRABABLE_MASK_BIT,this.space=new cp.Space,this.space.damping=Naubino.settings.physics.damping,this.mouseBody=new cp.Body(Infinity,Infinity),this.mouseBody.name="mouseBody",this.mouseBody.p=cp.vzero,this.space.addBody(this.mouseBody)},n.prototype.add_walls=function(){var e,t,n,r,i;r=15,this.walls={},n={ceil:new cp.SegmentShape(this.space.staticBody,cp.vzero,cp.v(this.width,0),r),floor:new cp.SegmentShape(this.space.staticBody,cp.v(0,this.height),cp.v(this.width,this.height),r),left:new cp.SegmentShape(this.space.staticBody,cp.vzero,cp.v(0,this.height),r),right:new cp.SegmentShape(this.space.staticBody,cp.v(this.width,0),cp.v(this.width,this.height),r)},i=[];for(e in n)t=n[e],this.walls[e]=this.space.addShape(t),this.walls[e].setElasticity(.01),this.walls[e].setFriction(3),this.walls[e].setLayers(this.NOT_GRABABLE_MASK),i.push(this.walls[e].group=1);return i},n.prototype.step_space=function(){var e;return this.space.step(1/this.step_rate),e=cp.v.lerp(this.mouseBody.p,this.pointer,.25),this.mouseBody.v=cp.v.mult(cp.v.sub(e,this.mouseBody.p),60),this.mouseBody.p=e},n.prototype.add_object=function(e){return this.space!=null&&(e.physical_shape!=null&&this.space.addShape(e.physical_shape),e.physical_body!=null&&this.space.addBody(e.physical_body)),n.__super__.add_object.call(this,e)},n.prototype.get_obj_in_pos=function(e){var t,r;if(this.space==null)return n.__super__.get_obj_in_pos.call(this,e);this.space!=null&&(r=this.space.pointQueryFirst(this.pointer,this.GRABABLE_MASK_BIT,cp.NO_GROUP)),r!=null&&(t=this.get_object(r.naub_number));if(t.isClickable)return t},n.prototype.remove_obj=function(e){var t,n,r,i,s;n=this.get_object(e);if(this.space!=null){n.physical_shape!=null&&this.space.removeShape(n.physical_shape),n.physical_body!=null&&this.space.removeBody(n.physical_body),s=n.constraints;for(r=0,i=s.length;r<i;r++)t=s[r],this.space.removeConstraint(t)}return delete this.objects[e]},n}(e)})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};define("Naub",[],function(){var n;return n=function(){function n(t,n,r){this.layer=t,this.color_id=n!=null?n:null,this.size=r!=null?r:Naubino.settings.naub.size,this.shrink=e(this.shrink,this),this.pulse=e(this.pulse,this),this.remove=e(this.remove,this),this.draw_joins=e(this.draw_joins,this),this.draw_outlines=e(this.draw_outlines,this),this.shapes=[],this.joins={},this.drawing_join={},this.ctx=this.layer.ctx,this.frame=this.size*1.5,this.radius=this.size/2,this.width=this.size*.9,this.height=this.size*.9,this.destroying=!1,this.removed=!1,this.focused=!1,this.disabled=!1,this.isClickable=!0,this.life_rendering=!1,this.color_id==null&&this.set_random_palette_color(),this.setup_style()}return n.prototype.set_opacity=function(e){return this.style.fill[3]=e},n.prototype.setup_style=function(){var e,t,n;this.style={fill:[0,0,0,1],scale:1,border_width:0,text_color:"white",glowing:!1},this.join_style={fill:[0,0,0,1],width:6},t=Naubino.colors(),e=this.color_id%t.length,n=t[e];if(n!=null)return this.style.fill=[n[0],n[1],n[2],n[3]]},n.prototype.random_color=function(){var e,t,n;return n=Math.random(),t=Math.random(),e=Math.random(),this.style.fill=[n,t,e,1],-1},n.prototype.set_random_palette_color=function(){var e;return e=Naubino.colors(),this.color_id=Math.floor(Math.random()*e.length),this.recolor()},n.prototype.setup_physics=function(){return this.constraints={},this.friction=Naubino.settings.naub.friction,this.elasticity=Naubino.settings.naub.elasticity,this.momentum=cp.momentForCircle(Naubino.settings.naub.mass,this.radius,this.radius,cp.vzero),this.physical_body=new cp.Body(Naubino.settings.naub.mass,this.momentum),this.physical_body.name="naub",this.physical_body.setAngle(0),this.physical_shape=new cp.CircleShape(this.physical_body,this.radius,cp.vzero),this.physical_shape.setElasticity(this.elasticity),this.physical_shape.setFriction(this.friction),this.physical_shape.setFriction(this.friction)},n.prototype.isHit=function(e){var t;return t=this.shapes[0],t.isHit(this.ctx,e)},n.prototype.area=function(){var e;return e=this.size/2,Math.floor(e*e*Math.PI)},n.prototype.draw=function(){var e,t,n;return e=this.physical_body?this.physical_body.p:this.pos,Naubino.settings.graphics.updating||this.life_rendering||this.is_active()?this.render(this.ctx,e.x,e.y):(this.ctx.save(),t=e.x-this.frame,n=e.y-this.frame,this.ctx.drawImage(this.buffer,t,n),this.ctx.restore())},n.prototype.update=function(){var e;return this.buffer=document.createElement("canvas"),this.buffer.width=this.buffer.height=this.frame*2,e=this.buffer.getContext("2d"),this.render(e,this.frame,this.frame)},n.prototype.render=function(e,t,n){var r,i,s,o,u;o=this.shapes,u=[];for(i=0,s=o.length;i<s;i++)r=o[i],u.push(r.draw(e,t,n));return u},n.prototype.add_shape=function(e){return e.setup(this),this.shapes.push(e),this.update()},n.prototype.add_shapes=function(e){var t,n,r,i;i=[];for(n=0,r=e.length;n<r;n++)t=e[n],i.push(this.add_shape(t));return i},n.prototype.update_shapes=function(){var e,t,n,r,i;r=this.shapes,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.setup(this));return i},n.prototype.add_filter=function(e){this.style.filters==null&&(this.style.filters=[]);if(t.call(this.style.filters,e)<0)return this.style.filters.push(e)},n.prototype.remove_filter=function(e){var t;this.style.filters!=null&&(t=this.style.filters.indexOf(e),t>=0&&this.style.filters.splice(t,1))},n.prototype.grey_out=function(){return this.style.fill=[100,100,100,1],this.update()},n.prototype.recolor=function(){return this.setup_style(),this.update()},n.prototype.draw_outlines=function(e){var t,n,r;r=this.joins;for(t in r)n=r[t],this.drawing_join[t]&&this.draw_outline(e,n,t)},n.prototype.draw_joins=function(e){var t,n,r;r=this.joins;for(t in r)n=r[t],this.drawing_join[t]&&this.draw_join(e,n,t)},n.prototype.draw_join=function(e,t,n){var r,i,s,o,u,a;return s=this.physical_body?this.physical_body.p:this.pos,o=t.physical_body?t.physical_body.p:t.pos,r=o.Copy(),r.sub(s),i=r.Length(),u=75/(i+10),a=this.join_style.width*u,e.save(),e.globalCompositeOperation="destination-over",e.strokeStyle=Util.color_to_rgba(this.join_style.fill),e.beginPath(),e.lineWidth=1,e.fillStyle="#000000",e.strokeStyle="#ffffff",e.translate(s.x,s.y),e.rotate(r.Angle()),e.rect(0,-a/2,i,a),e.fill(),e.stroke(),e.closePath(),e.restore()},n.prototype.draw_outline=function(e,t,n){var r,i,s,o;return s=this.physical_body?this.physical_body.p:this.pos,o=t.physical_body?t.physical_body.p:t.pos,r=o.Copy(),r.sub(s),i=r.Length(),e.save(),e.globalCompositeOperation="destination-over",e.strokeStyle=Util.color_to_rgba(this.join_style.fill),e.beginPath(),e.lineWidth=1,e.fillStyle="#000000",e.strokeStyle="#ffffff",e.rotate(r.Angle()),e.translate(s.x,s.y),e.rect(0,this.size/2,i,this.size),e.fill(),e.stroke(),e.closePath(),e.restore()},n.prototype.disable=function(){return this.disabled=!0},n.prototype.enable=function(){return this.disabled=!1},n.prototype.remove=function(){var e,t,n;n=this.joins;for(e in n)t=n[e],this.split_join(e);return this.removed=!0},n.prototype.split_join=function(e){var t,n,r,i,s,o;if(e in this.joins){n=this.joins[e],this.layer.graph.remove_join(e),delete n.joins[e],delete this.joins[e];if(this.constraints[e]!=null){s=this.constraints[e],o=[];for(r=0,i=s.length;r<i;r++)t=s[r],o.push(this.layer.space.removeConstraint(t));return o}}},n.prototype.points_on_destroy=function(){return 1},n.prototype.destroy=function(e){var t,n,r,i,s,o,u,a;e==null&&(e=!1),this.destroying=!0,t=270;if(!e){u=this.joins;for(n in u)r=u[n],this.drawing_join[n]=!0,r.drawing_join[n]=!1}this.disable(),this.life_rendering=!0,setTimeout(function(e){return function(){return e.remove()}}(this),t),this.animation(this.shrink,t),a=this.shapes.slice(1);for(s=0,o=a.length;s<o;s++)i=a[s],i.destroy_animation();return this.layer.naub_destroyed.dispatch(this.number)},n.prototype.animation_pulse=function(){return this.life_rendering=!0,this.animation(this.pulse)},n.prototype.pulse=function(e){return this.style.scale=1+Math.sin(3*Math.PI*e)*.2},n.prototype.shrink=function(e){return this.style.scale=1.1-e,this.style.fill[3]=1.1-e,this.join_style.width*=.3,this.join_style.fill[3]=1.1-e},n.prototype.animation=function(e,t){var n,r,i;t==null&&(t=1e3),i=50,t/=i;if(typeof e=="function")return n=0,r=setInterval(function(i){return function(){return n<t?e(++n/t):clearInterval(r)}}(this),i)},n.prototype.attach_to=function(e){if(this.centerjoin!=null)return console.warn("object is already attached to a point")},n.prototype.attracted_to=function(e){var t,n,r;return this.centerjoin==null?(n=Naubino.settings.physics.center_join.restLength,r=Naubino.settings.physics.center_join.stiffness,t=Naubino.settings.physics.center_join.damping,this.centerjoin=new cp.DampedSpring(this.physical_body,this.layer.space.staticBody,cp.vzero,e,n,r,t),this.centerjoin.centerjoin=!0,this.layer.space.addConstraint(this.centerjoin),this.constraints.center=this.centerjoin):console.warn("object is already attached to a point")},n.prototype.join_with=function(e){var t,n,r,i,s;return typeof e=="number"&&(e=this.layer.get_object(e)),e!=null&&!this.is_joined_with(e)?(t=this.layer.graph.add_join(this,e),s=Naubino.settings.naub.min_join_len*this.size,i=Naubino.settings.naub.max_join_len*this.size,n=new cp.DampedSpring(this.physical_body,e.physical_body,cp.vzero,cp.vzero,s,10,30),n.name="DampedSpring",this.layer.space.addConstraint(n),r=new cp.SlideJoint(this.physical_body,e.physical_body,cp.vzero,cp.vzero,s,i),r.name="SlideJoint",this.layer.space.addConstraint(r),this.constraints[t]=[],this.constraints[t].push(r),this.joins[t]=e,e.joins[t]=this,this.drawing_join[t]=!0,e.drawing_join[t]=!1,this.layer.naub_joined!=null&&this.layer.naub_joined.dispatch(),t):-1},n.prototype.replace_with=function(e){var t,n,r,i,s,o,u,a,f;a=this.joins;for(n in a){r=a[n];if(r.constraints[n]!=null){f=r.constraints[n];for(o=0,u=f.length;o<u;o++)t=f[o],this.layer.space.removeConstraint(t)}e.join_with(r),delete r.joins[n],this.layer.graph.remove_join(n)}return this.layer.unfocus(),i=e.physical_body.p,s=this.physical_body.p,e.physical_body.p=cp.v.lerp(i,s,.5),this.remove(),this.layer.naub_replaced.dispatch(e.number),42},n.prototype.close_related=function(e){var n,r,i,s,o;return i=function(){var e,t;e=this.joins,t=[];for(r in e)o=e[r],t.push(o.number);return t}.call(this),s=function(){var t,n;t=e.joins,n=[];for(r in t)o=t[r],n.push(o.number);return n}(),n=i.some(function(e){return t.call(s,e)>=0})},n.prototype.is_alone=function(){return Object.keys(this.joins).length===0},n.prototype.agrees_with=function(e){return this.color_id!=null&&this.kind!=null&&this.color_id===e.color_id&&this.kind===e.kind},n.prototype.is_joined_with=function(e){var t,n,r,i;n=!1,i=this.joins;for(t in i)r=i[t],r===e&&(n=!0);return n},n.prototype.joined_naubs=function(){var e,t,n,r;t=[],r=this.joins;for(e in r)n=r[e],t.push(n.number);return this.joins},n.prototype.distance_to=function(e){var t,n;return e.number!==this.number?(n=this.physical_body.p.Copy(),t=e.physical_body.p.Copy(),n.sub(t),n.Length()):NaN},n.prototype.enter_field=function(){var e;return e=function(){},setInterval(e,10)},n.prototype.is_active=function(){var e;return this.focused||this.layer.active_tree!=null&&(e=this.number,t.call(this.layer.active_tree,e)>=0)},n.prototype.is_active_end=function(){var e;return this.focused||this.layer.active_tree!=null&&(e=this.number,t.call(this.layer.active_tree,e)>=0)&&Object.keys(this.joins).length===1},n.prototype.onclick=function(){},n.prototype.onfocus=function(){},n.prototype.focus=function(){return this.focused=!0,this.onfocus(),this.layer.naub_focused.dispatch(this)},n.prototype.unfocus=function(){return this.focused=!1,this.onclick(),this.layer.naub_unfocused.dispatch(this)},n}()})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};define("Graph",[],function(){var n;return n=function(){function n(t){this.layer=t,this.cycle_test=e(this.cycle_test,this),this.join_id_sequence=0,this.naubs=[],this.joins={}}return n.prototype.update_naub_list=function(){var e,n,r,i,s;this.naubs=[],i=this.joins,s=[];for(n in i)r=i[n],s.push(function(){var n,i,s;s=[];for(e=n=0;n<=1;e=++n)(i=r[e],t.call(this.naubs,i)<0)?s.push(this.naubs.push(r[e])):s.push(void 0);return s}.call(this));return s},n.prototype.add_join=function(e,t){var n;return this.join_id_sequence++,n=[e.number,t.number],this.joins[this.join_id_sequence]=n,this.update_naub_list(),this.join_id_sequence},n.prototype.remove_join=function(e){return delete this.joins[e],this.update_naub_list()},n.prototype.clear=function(){return this.join_id_sequence=0,this.naubs=[],this.joins={}},n.prototype.join_list=function(){var e,t,n,r;console.log("joinList"),n=this.joins,r=[];for(e in n)t=n[e],r.push(console.log(e+" "+t));return r},n.prototype.dotty=function(){var e,t,n,r;return e="graph G {\n",r=function(){var e,r;e=this.joins,r=[];for(t in e)n=e[t],r.push(n[0]+" -- "+n[1]);return r}.call(this),e+=r.join("\n")+"}",console.log(e)},n.prototype.partners=function(e,n){var r,i,s,o;n==null&&(n=null),s=[],o=this.joins;for(r in o)i=o[r],t.call(i,e)>=0&&t.call(i,n)<0&&s.push(i[i.indexOf(e)^1]);return s},n.prototype.cycle_test=function(e){var n,r,i,s,o,u,a,f,l,c,h;r=[],this.dfs_map=[],l=this.naubs;for(a=0,f=l.length;a<f;a++)o=l[a],this.dfs_map[o]={naub:o,dfs_num:0,color:0};this.seq_num=1,c=this.dfs_map;for(o in c)h=c[o],u=h.naub,s=h.dfs_num,n=h.color,s===0&&(i=this.dfs(u,null,e),r=r.filter(function(e){return t.call(i,e)>=0}))},n.prototype.tree=function(e,n){var r,i,s,o;n==null&&(n=null),n==null&&(n=[]),o=this.partners(e);for(i=0,s=o.length;i<s;i++)r=o[i],t.call(n,r)<0&&(n.push(r),this.tree(r,n));return n},n.prototype.dfs=function(e,n,r){var i,s,o,u,a,f;n==null&&(n=null),r==null&&(r=null),i=[],this.dfs_map[e].dfs_num=this.seq_num,this.seq_num++,this.dfs_map[e].color=1,f=this.partners(e,n);for(u=0,a=f.length;u<a;u++)o=f[u],this.dfs_map[o].dfs_num===0&&(i=this.dfs(o,e,r).filter(function(e){return t.call(i,e)>=0})),this.dfs_map[o].color===1&&(s=this.cycle_list(e,o,r),s.length>0&&this.layer.cycle_found.dispatch(s));return this.dfs_map[e].color=2,i},n.prototype.cycle_list=function(e,n,r){var i,s,o,u;return r==null&&(r=null),i=this.dfs_map.filter(function(e){return function(t){var r,i;return i=t.dfs_num,r=t.color,i>=e.dfs_map[n].dfs_num&&r===1}}(this)),i.sort(function(e,t){return e.dfs_num-t.dfs_num}),s=function(){var e,t,n;n=[];for(e=0,t=i.length;e<t;e++)u=i[e],n.push(u.naub);return n}(),r!=null&&t.call(s,r)>=0&&(s=s,o=s.indexOf(r),s=s.slice(o,s.length).concat(s.slice(0,o))),s},n}()})}.call(this),function(){define("CollisionHandler",[],function(){var e;return e=function(){function e(e){this.game=e,this.a=this.b=0}return e.prototype.begin=function(e,t){return!0},e.prototype.preSolve=function(e,t){return!0},e.prototype.postSolve=function(e,t){var n,r,i;if(e.a.naub_number!=null&&e.b.naub_number!=null)return i=this.naubs(e),n=i.a,r=i.b,this.game.check_joining(n,r,e)},e.prototype.separate=function(e,t){},e.prototype.naub=function(e){return this.game.get_object(arb.a.naub_number)},e.prototype.naubs=function(e){var t,n;return t=this.game.get_object(e.a.naub_number),n=this.game.get_object(e.b.naub_number),{a:t,b:n}},e}()})}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};define("Shapes",[],function(){var e,n,r,i,s,o,u,a,f,l,c;return l={Shape:f=function(){function e(){}return e.prototype.setup=function(e){return this.naub=e,this.pos=this.naub.pos,this.ctx=this.naub.ctx,this.radius=this.naub.radius-Naubino.settings.naub.margin/2,this.width=this.naub.width-Naubino.settings.naub.margin,this.height=this.naub.height-Naubino.settings.naub.margin},e.prototype.apply_filters=function(e,t){var n,r,i,s;s=[];for(r=0,i=e.length;r<i;r++)n=e[r],s.push(this.apply_filter(n,t));return s},e.prototype.apply_filter=function(e,t){if(e==="alpha"||e==="draw_glow"||e==="draw_border"||e==="draw_shadow"||e==="draw_gradient"||e==="draw_gradient_soft")return this[e](t)},e.prototype.alpha=function(e){return e.globalAlpha=.4},e.prototype.draw=function(e,t,n){return t==null&&(t=42),n==null&&(n=t),e.save(),e.translate(t,n),this.naub.style.scale!=null&&e.scale(this.naub.style.scale,this.naub.style.scale),this.render(e,t,n),Naubino.settings.graphics.effects===!0&&(this.naub.style.filters!=null&&this.apply_filters(this.naub.style.filters,e),Naubino.settings.graphics.draw_borders&&this.apply_filter("draw_border",e),this.naub.is_active_end()||this.naub.destroying?(this.apply_filter("draw_glow",e),this.apply_filter("draw_gradient",e)):this.naub.is_active()&&this.apply_filter("draw_gradient_soft",e)),e.restore()},e.prototype.draw_border=function(e){return e.lineWidth=2,e.strokeStyle=Util.color_to_rgba(this.naub.join_style.fill),e.stroke()},e.prototype.draw_gradient=function(e){var t;return t=e.createRadialGradient(0,0,this.radius/3,0,0,this.radius),t.addColorStop(0,Util.color_to_rgba(this.naub.style.fill,60)),t.addColorStop(1,Util.color_to_rgba(this.naub.style.fill,30)),e.fillStyle=t,e.fill()},e.prototype.draw_gradient_soft=function(e){var t;return t=e.createRadialGradient(0,0,this.radius/3,0,0,this.radius),t.addColorStop(0,Util.color_to_rgba(this.naub.style.fill,45)),t.addColorStop(1,Util.color_to_rgba(this.naub.style.fill,20)),e.fillStyle=t,e.fill()},e.prototype.draw_glow=function(e){return e.shadowColor=Util.color_to_rgba(this.naub.style.fill),e.shadowBlur=10,e.shadowOffsetX=0,e.shadowOffsetY=0,e.fill()},e.prototype.draw_shadow=function(e){return e.shadowColor="#333",e.shadowBlur=3,e.shadowOffsetX=1,e.shadowOffsetY=1,e.fill()},e.prototype.destroy_animation=function(e){return this.naub.life_rendering=!0},e}(),Ball:e=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.render=function(e,t,n){return t==null&&(t=42),n==null&&(n=t),e.beginPath(),e.arc(0,0,this.radius,0,Math.PI*2,!1),e.fillStyle=Util.color_to_rgba(this.naub.style.fill),e.fill(),e.closePath()},n.prototype.isHit=function(e,t){var n;return n=this.naub.pos.Copy(),n.sub(t),n.Length()<=this.naub.size},n.prototype.setup=function(e){return n.__super__.setup.call(this,e)},n}(f),Box:n=function(e){function n(){n.__super__.constructor.call(this),this.rot=Math.random()*Math.PI}return t(n,e),n.prototype.area=function(){return this.width/2*this.width/2},n.prototype.setup=function(e){return e.width=e.size*.7,e.height=e.size*.7,n.__super__.setup.call(this,e)},n.prototype.render=function(e,t,n){return this.naub.physical_body!=null&&e.rotate(this.naub.physical_body.a),e.beginPath(),e.rect(-this.naub.width/2,-this.naub.height/2,this.naub.width,this.naub.height),e.fillStyle=Util.color_to_rgba(this.naub.style.fill),e.fill(),e.closePath()},n.prototype.adjust_physics=function(){return this.naub.momentum=cp.momentForBox(Naubino.settings.naub.mass,this.naub.width,this.naub.height),this.naub.physical_body=new cp.Body(Naubino.settings.naub.mass,this.naub.momentum),this.naub.physical_body.setAngle(0),this.naub.physical_shape=new cp.BoxShape(this.naub.physical_body,this.naub.width,this.naub.height),this.naub.physical_shape.setElasticity(this.naub.elasticity),this.naub.physical_shape.setFriction(this.naub.friction)},n.prototype.isHit=function(e,t){return e.beginPath(),e.rect(-this.naub.width/2,-this.naub.height/2,this.naub.width,this.naub.height),e.closePath(),e.isPointInPath(t.x,t.y)},n}(f),Clock:r=function(e){function n(){n.__super__.constructor.call(this),this.start=0}return t(n,e),n.prototype.setup=function(e){return this.naub=e,n.__super__.setup.call(this,this.naub),this.naub.clock_progress=0},n.prototype.render=function(e,t,n){var r,i;return t==null&&(t=42),n==null&&(n=t),i=this.naub.size-5,r=this.naub.clock_progress*Math.PI/100,e.translate(t,n),e.beginPath(),e.arc(0,0,i,this.start,r,!1),e.fillStyle=Util.color_to_rgba([255,255,255,.5]),e.strokeStyle=e.fillStyle,e.lineWidth=i+3,e.stroke(),e.closePath()},n}(f),Frame:i=function(e){function n(e){this.margin=e!=null?e:null,n.__super__.constructor.call(this)}return t(n,e),n.prototype.setup=function(e){return this.naub=e,n.__super__.setup.call(this,this.naub),this.margin!=null?this.frame=this.margin+this.naub.size:this.frame=this.naub.frame+this.naub.size*2},n.prototype.render=function(e,t,n){return t==null&&(t=42),n==null&&(n=t),t-=this.frame/2,n-=this.frame/2,e.beginPath(),e.moveTo(t,n),e.lineTo(t,this.frame+n),e.lineTo(this.frame+t,this.frame+n),e.lineTo(this.frame+t,n),e.lineTo(t,n),e.stroke(),e.closePath()},n}(f),FrameCircle:s=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.render=function(e,t,n){var r,i;return t==null&&(t=42),n==null&&(n=t),e.beginPath(),i=this.naub.physics.margin*this.naub.size,e.arc(t,n,i,0,Math.PI*2,!1),e.closePath(),e.strokeStyle="black",r=this.naub.style.fill,r[3]=.3,e.fillStyle=Util.color_to_rgba(r),e.stroke(),e.fill(),e.closePath()},n}(i),PlayButton:a=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.draw=function(e,t,n){return e.save(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(t-7,n-7),e.lineTo(t-7,n+7),e.lineTo(t+9,n+0),e.lineTo(t-7,n-7),e.closePath(),e.fill(),e.restore()},n}(f),PauseButton:u=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.draw=function(e,t,n){return e.save(),e.fillStyle="#ffffff",e.beginPath(),e.rect(t-7,n-7,5,13),e.rect(t+1,n-7,5,13),e.closePath(),e.fill(),e.restore()},n}(f),MainButton:o=function(e){function n(){return n.__super__.constructor.apply(this,arguments)}return t(n,e),n.prototype.draw=function(e,t,n){var r,i,s,o,u;o=(u=Naubino.game.points)!=null?u:"",s=38,this.width=this.naub.size*1.2,e.save(),e.translate(t,n),e.rotate(Math.PI/6),e.beginPath(),e.rect(-this.width/2,-this.width/2,this.width,this.width),this.naub.filters!=null&&this.apply_filters(this.naub.filters,e),Naubino.settings.graphics.draw_borders&&this.apply_filter("draw_border",e),e.fillStyle=Util.color_to_rgba(this.naub.style.fill),e.fill(),e.closePath(),e.restore(),r=o.toString().length;switch(r){case 1:case 2:i=1;break;case 3:i=.7;break;case 4:i=.5;break;default:i=.4}return e.save(),e.translate(t,n),e.scale(i,i),e.font="bold "+s+"px "+Naubino.settings.menu.font,e.textAlign="center",Naubino.settings.graphics.draw_borders&&(e.fillStyle="black",e.fillText(o,2,11),e.fillText(o,2,13),e.fillText(o,1,12),e.fillText(o,3,12),e.fillText(o,4,14)),e.fillStyle="white",e.fillText(o,2,12),e.restore()},n}(n),StringShape:c=function(e){function n(e,t){this.string=e,this.color=t!=null?t:"black",n.__super__.constructor.call(this)}return t(n,e),n.prototype.setup=function(e){return this.naub=e,n.__super__.setup.call(this,this.naub)},n.prototype.draw=function(e,t,n){var r,i;return r=this.naub.size*.5,typeof this.string=="function"?i=this.string():i=this.string,e.save(),e.translate(t,n),this.naub.style.scale!=null&&e.scale(this.naub.style.scale,this.naub.style.scale),this.naub.physical_body!=null&&e.rotate(this.naub.physical_body.a),e.fillStyle=this.color,e.textAlign="center",e.font=""+r+"px "+Naubino.settings.game.font,e.fillText(i,0,7),e.restore()},n}(f)}})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}};define("Factory",["Naub","Shapes"],function(t,n){var r,i,s,o,u,a,f,l,c,h;return r=n.Ball,i=n.Box,u=n.Frame,a=n.FrameCircle,s=n.Clock,f=n.NumberShape,h=n.StringShape,c=n.PlayButton,l=n.PauseButton,o=function(){function n(t){this.layer=t,this.create_naub_triple=e(this.create_naub_triple,this),this.create_naub_pair=e(this.create_naub_pair,this),this.add_box=e(this.add_box,this),this.add_ball=e(this.add_ball,this),this.add_button=e(this.add_button,this)}return n.prototype.add_button=function(e,n,i){var s,o;return s=new r,o=new t(this.layer,null),o.pos=o.fixed_pos=e,o.add_shape(s),o.add_shapes(i),o.focus=n,o.disabled=!0,o.isClickable=!0,o.update(),o},n.prototype.add_ball=function(e,n){var i,s;return e==null&&(e=this.random_outside()),n==null&&(n=null),s=new t(this.layer,n),i=new r,s.add_shape(i),s.setup_physics(),s.physical_body.setPos(e.Copy()),s.kind="ball",this.layer.add_object(s),s},n.prototype.add_box=function(e,n){var r,s;return e==null&&(e=this.random_outside()),n==null&&(n=null),s=new t(this.layer,n),r=new i,s.add_shape(r),s.setup_physics(),r.adjust_physics(),s.physical_body.setPos(e.Copy()),s.kind="box",s.life_rendering=!0,this.layer.add_object(s),s},n.prototype.create_naub_pair=function(e,t,n,r){var i,s,o,u,a,f,l;return e==null&&(e=null),t==null&&(t=null),n==null&&(n=null),r==null&&(r=0),e==null&&(e=this.random_outside()),i=Math.random()*Math.PI,f=e.Copy(),l=e.Copy(),f.AddPolar(i,15),l.AddPolar(i,-15),r===0?(console.log("0 boxes"),s=o=this.add_ball):r===1?(console.log("1 boxe"),s=this.add_ball,o=this.add_box):(console.log("2 boxes"),s=o=this.add_box),u=s(f,t),a=o(l,n),u.join_with(a),[u.color_id,a.color_id]},n.prototype.create_naub_triple=function(e,t,n,r){var i,s,o,u,a,f,l;return e==null&&(e=null),t==null&&(t=null),n==null&&(n=null),r==null&&(r=null),e==null&&(e=this.random_outside()),i=Math.random()*Math.PI,a=e.Copy(),f=e.Copy(),l=e.Copy(),a.AddPolar(i,30),l.AddPolar(i,-30),s=this.add_ball(a,t),o=this.add_ball(f,n),u=this.add_ball(l,r),s.join_with(o),o.join_with(u)},n.prototype.create_matching_naubs=function(e,t){var n,r,i,s,o,u,a,f,l;e==null&&(e=1),t==null&&(t=0);for(u=1;1<=e?u<=e:u>=e;1<=e?u++:u--){i=Util.shuffle([0,1,2,3,4,5]),i[5]=i[0],s=0;while(s<i.length-1)o=this.random_outside(),f=this.create_naub_pair(o,i[s],i[s+1]),n=f[0],r=f[1],s++}if(t>0){l=[];for(a=1;1<=t?a<=t:a>=t;1<=t?a++:a--)o=this.random_outside(),l.push(this.create_naub_pair(o));return l}},n.prototype.random_outside=function(){var e,t,n,r;e=Naubino.settings.game.creation_offset,t=Math.round(Math.random()*3+1);switch(t){case 1:n=this.layer.width+e,r=this.layer.height*Math.random();break;case 2:n=this.layer.width*Math.random(),r=this.layer.height+e;break;case 3:n=0-e,r=this.layer.height*Math.random();break;case 4:n=this.layer.width*Math.random(),r=0-e}return new cp.v(n,r)},n.prototype.random_factory=function(){var e,t;return e=[this.add_ball,this.add_box],t=Math.floor(Math.random()*e.length),e[t]},n}()})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};define("Game",["Physical_Layer","Naub","Graph","CollisionHandler","Factory"],function(t,r,i,s,o){var u;return u=function(t){function r(t){this.unfocus=e(this.unfocus,this),this.click=e(this.click,this),this.version=0,r.__super__.constructor.call(this,t),this.name="game",this.graph=new i(this),this.factory=new o(this),this.begin_time=Date.now(),this.focused_naub=null,this.joining_allowed=!0,Naubino.mousemove.add(this.move_pointer),Naubino.mousedown.add(this.click),Naubino.mouseup.add(this.unfocus),this.joining_naubs=[],this.replacing_naubs=[],this.active_tree=[],this.setup_fsm(Naubino.settings.events.game)}return n(r,t),r.prototype.oninit=function(e,t,n){return console.log("game INIT"),this.game_draw=new Naubino.Signal,this.naub_replaced=new Naubino.Signal,this.naub_joined=new Naubino.Signal,this.naub_destroyed=new Naubino.Signal,this.cycle_found=new Naubino.Signal,this.naub_focused=new Naubino.Signal,this.naub_unfocused=new Naubino.Signal,this.setup_physics(),this.space.defaultHandler=new s(this)},r.prototype.onstopped=function(e,t,n){if(e!=="init")return this.clear_objects()},r.prototype.onloose=function(){return Naubino.can("loose")&&Naubino.loose("Naub Overflow"),Naubino.background.pause(),this.stop_stepping()},r.prototype.click=function(e,t){var n,r;this.mousedown=!0,this.pointer=new cp.v(e,t),this.space!=null&&(r=this.space.pointQueryFirst(this.pointer,this.GRABABLE_MASK_BIT,cp.NO_GROUP)),r!=null&&(n=this.get_object(r.naub_number));if(n&&n.isClickable)return n.focus(),this.focused_naub=n,this.mouseBody.p=this.pointer,this.mouseJoint=new cp.PivotJoint(this.mouseBody,n.physical_body,cp.vzero,cp.vzero),this.mouseJoint.errorBias=Math.pow(.5,60),this.space.addConstraint(this.mouseJoint)},r.prototype.unfocus=function(){if(this.mousedown)return this.mousedown=!1,this.focused_naub&&this.focused_naub.unfocus(),this.focused_naub=null,this.space!=null&&this.mouseJoint!=null&&(this.space.removeConstraint(this.mouseJoint),this.mouseJoint=null),this.active_tree=[]},r.prototype.count_basket=function(e){var t,n,r,i,s,o;n=[],t=this.basket_size(),o=this.objects;for(i in o)s=o[i],r=this.center(),r.sub(s.physical_body.p),cp.v.len(r)<t*(1+e)-s.size/2&&n.push(s);return n},r.prototype.point_in_field=function(e){var t,n;return 0<(t=e.x)&&t<this.width&&0<(n=e.y)&&n<this.height},r.prototype.basket_size=function(){var e,t,n;if(this.max_naubs!=null)return t=Naubino.settings.naub.size/2,n=.62,e=Math.sqrt(this.max_naubs*t*t/n)},r.prototype.cur_naubs=function(){return this.count_basket(.08).length},r.prototype.capacity=function(){return 100-this.cur_naubs()*100/this.max_naubs},r.prototype.destroy_naubs=function(e){var t,n,r,i,s;for(i=0,s=e.length;i<s;i++)n=e[i],this.get_object(n).disable();return t=0,r=function(n){return function(){return t<e.length&&(n.get_object(e[t]).destroy(t===e.length-1),t++),setTimeout(r,120)}}(this),r()},r.prototype.check_joining=function(e,t,n){var r,i,s,o,u,a;return this.joining_allowed?!e.focused&&!t.focused?!1:e.disabled||t.disabled?!1:e.number===t.number?!1:n.totalImpulse().Length()<Naubino.settings.game.min_joining_force?!1:(o=e.focused?e:t,u=e.focused?t:e,a=o.close_related(u),s=o.is_joined_with(u),r=o.agrees_with(u)&&u.agrees_with(o),i=o.is_alone()||u.is_alone(),!s&&r&&!a&&!i?(this.replacing_naubs.push([o,u]),!0):o.is_alone()&&o.number!==this.just_joined?(this.just_joined=o.number,setTimeout(function(e){return function(){return e.just_joined=-1}}(this),300),this.joining_naubs.push([o,u]),!0):!1):!1},r.prototype.draw=function(){var e,t,n;this.clear(),this.ctx.save(),n=this.objects;for(e in n)t=n[e],t.draw_joins(this.ctx),t.draw(this.ctx);return this.ctx.restore(),this.game_draw.dispatch()},r.prototype.draw_constraints=function(){var e,t,n,r,i,s,o,u,a,f,l,c;l=this.space.constraints,c=[];for(r=a=0,f=l.length;a<f;r=++a){e=l[r],o=e.a.p,o.IsZero()&&(o=e.anchr1),u=e.b.p,u.IsZero()&&(u=e.anchr2),t=function(e){switch(e.name){case"DampedSpring":return"red";case"SlideJoint":return"blue";default:return"grey"}},o!=null&&u!=null&&(this.ctx.save(),this.ctx.strokeStyle=t(e),this.ctx.moveTo(o.x,o.y),this.ctx.lineTo(u.x,u.y),this.ctx.stroke(),this.ctx.restore());if(r!=null){n=u.Copy(),n.sub(o),i=r.toString(),s=cp.v.lerp(o,u,.5),this.ctx.save(),this.ctx.translate(s.x,s.y),this.ctx.rotate(n.Angle()),this.ctx.translate(0,-10),this.ctx.rotate(2*Math.PI-n.Angle()),this.ctx.fillStyle="black";if(e.a.isRogue()||e.b.isRogue())this.ctx.fillStyle="red";this.ctx.textAlign="center",this.ctx.font="10px Courier",this.ctx.fillText(i,0,6),c.push(this.ctx.restore())}else c.push(void 0)}return c},r.prototype.add_object=function(e){return r.__super__.add_object.call(this,e),e.physical_body!=null&&(e.physical_body.naub_number=this.objects_count),e.physical_shape!=null&&(e.physical_shape.naub_number=this.objects_count),e.attracted_to(this.center())},r.prototype.clear_objects=function(){return r.__super__.clear_objects.call(this),this.setup_physics(),this.graph.clear()},r.prototype.step=function(e){var t,n,r,i,s,o,u,a,f,l,c;this.step_space(),a=this.replacing_naubs;for(i=0,o=a.length;i<o;i++)r=a[i],r[0].replace_with(r[1]);f=this.joining_naubs;for(s=0,u=f.length;s<u;s++)r=f[s],r[0].join_with(r[1]);this.joining_naubs=[],this.replacing_naubs=[],l=this.objects,c=[];for(t in l)n=l[t],n.removed?(this.remove_obj(t),c.push(this.clean_up())):c.push(void 0);return c},r.prototype.clean_up=function(){var e,t,n,r,i,s;i=this.space.constraints,s=[];for(t=n=0,r=i.length;n<r;t=++n)e=i[t],e!=null&&e.IsRogue()?s.push(this.space.removeConstraint(e)):s.push(void 0);return s},r}(t)})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};define("Menu",["Layer","Naub","Graph","Shapes","Factory"],function(t,r,i,s,o){var u,a,f,l,c,h;return u=s.Ball,h=s.StringShape,c=s.PlayButton,l=s.PauseButton,a=s.MainButton,f=function(t){function r(t){this.click=e(this.click,this),r.__super__.constructor.call(this,t),this.name="menu",this.graph=new i(this),this.factory=new o(this),this.objects={},this.hovering=!1,this.listener_size=this.default_listener_size=45,Naubino.mousemove.add(this.move_pointer),Naubino.mousedown.add(this.click),Naubino.menu_button.active=!1,this.center=new cp.v(20,25),this.cube_size=45,this.default_fps=this.fps=35,this.min_fps=15,this.min_step_rate=15,this.min_fps=3,this.setup_fsm()}return n(r,t),r.prototype.oninit=function(){return this.add_buttons(),this.start_stepping(),this.start_drawing()},r.prototype.buttons={main:{position:new cp.v(23,26),"function":function(){},shapes:[new a]},play:{"function":function(){return Naubino.play()},position:new cp.v(70,32),shapes:[new u,new c]},help:{"function":function(){return alert("tutorial deactivated")},position:new cp.v(55,65),shapes:[new u,new h("?","white")]},exit:{"function":function(){return Naubino.stop()},position:new cp.v(20,80),shapes:[new u,new h("X","white")]}},r.prototype.add_buttons=function(){var e,t,n;n=this.buttons;for(t in n)e=n[t],this.objects[t]=this.factory.add_button(e.position,e["function"],e.shapes);return this.objects.main.life_rendering=!0},r.prototype.check_game_state=function(e){e==null&&(e=Naubino.game);if(this.objects.play!=null)return e.current==="playing"?(this.objects.play.focus=function(){return Naubino.pause()},this.objects.play.shapes.pop(),this.objects.play.add_shape(new l),this.objects.play.update()):(this.objects.play.focus=function(){return Naubino.play()},this.objects.play.shapes.pop(),this.objects.play.add_shape(new c),this.objects.play.update())},r.prototype.step=function(){var e,t,n,r;n=this.objects,r=[];for(e in n)t=n[e],this.hovering?(e!=="main"&&(t.pos=cp.v.lerp(t.pos,t.fixed_pos,.1)),t.pos===t.fixed_pos?r.push(t.isClickable=!0):r.push(void 0)):(e!=="main"&&(t.pos=cp.v.lerp(t.pos,this.center,.15)),r.push(t.isClickable=!1));return r},r.prototype.move_pointer=function(e,t){var n;return n=[e,t],this.pointer.x=n[0],this.pointer.y=n[1],n},r.prototype.click=function(e,t){var n,r,i,s;this.mousedown=!0,i=this.objects,s=[];for(n in i){r=i[n];if(r.isHit(this.pointer)){r.focus(),this.focused_naub=r;break}s.push(void 0)}return s},r.prototype.draw=function(){return this.draw_menu(),this.draw_listener_region()},r.prototype.draw_menu=function(){var e,t,n;this.ctx.clearRect(0,0,Naubino.game_canvas.width,Naubino.game_canvas.height),this.ctx.save(),n=this.objects;for(e in n)t=n[e],t.draw_join(this.ctx,this.objects.main),t.draw(this.ctx);return this.objects.main.draw(this.ctx),this.objects.main.draw_joins(),this.ctx.restore()},r.prototype.activate_menu=function(){return this.hovering=!0,this.deactivation_timeout!=null?(clearTimeout(this.deactivation_timeout),this.deactivation_timeout=null):this.refresh_draw_rate(this.default_fps),this.listener_size=90},r.prototype.deactivate_menu=function(){this.hovering=!1,this.for_each(function(e){return e.isClickable=!1}),this.listener_size=this.default_listener_size;if(this.deactivation_timeout==null)return this.deactivation_timeout=setTimeout(function(e){return function(){return e.refresh_draw_rate(e.min_fps),e.deactivation_timeout=null}}(this),1e3)},r.prototype.draw_listener_region=function(){return this.ctx.save(),this.ctx.beginPath(),this.ctx.arc(0,15,this.listener_size,0,Math.PI*2,!0),this.ctx.isPointInPath(this.pointer.x,this.pointer.y)?this.hovering||this.activate_menu():this.hovering&&this.deactivate_menu(),this.ctx.closePath(),this.ctx.restore()},r}(t)})}.call(this),function(){var e,t=function(e,t){return function(){return e.apply(t,arguments)}},n={}.hasOwnProperty,r=function(e,t){function i(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};define("Overlay",["Layer"],function(n){var i;return i=function(n){function i(e){this.queue_messages=t(this.queue_messages,this),i.__super__.constructor.call(this,e),this.name="overlay",this.fps=20,this.setup_fsm()}return r(i,n),i.prototype.active_objects=function(){var e,t,n,r;e=0,r=this.objects;for(t in r)n=r[t],n.life!==!0&&e++;return e},i.prototype.draw=function(){var e,t,n;this.active_objects()===0&&this.can("pause")&&this.pause(),this.ctx.clearRect(0,0,Naubino.game_canvas.width,Naubino.game_canvas.height),this.ctx.save(),n=this.objects;for(t in n)e=n[t],e.life!=null&&e.render(),this.fade_object(e,t),e.alpha!=null&&(this.ctx.globalAlpha=e.alpha),this.ctx.drawImage(e.buffer,0,0),this.ctx.globalAlpha=1;return this.ctx.restore()},i.prototype.fade_in_message=function(e,t){var n,r;return r=this.message(e),n=this.get_object(r),n.alpha=.01,n.alpha_delta=Naubino.settings.overlay.fade_duration/this.fps,n.callback=t,r},i.prototype.fade_out_message=function(e,t){var n;this.can("play")&&this.play(),n=this.get_object(e),console.log("fade out message",n.text),n.callback=t;if(n!=null)return n.alpha_delta=-Naubino.settings.overlay.fade_duration/this.fps},i.prototype.fade_out_messages=function(e){var t,n,r,i;this.can("play")&&this.play(),i=this.objects;for(t in i)r=i[t],r.life!==!0&&this.fade_out_message(t);n=Object.keys(this.objects);if(e!=null)return this.objects[n[n.length-1]].callback=e},i.prototype.fade_in_and_out_message=function(e,t){var n,r,i;return t==null&&(t=null),r=this.fade_in_message(e),n=this.get_object(r),n.callback=function(e){return function(){return e.fade_out_message(r,t)}}(this),n.duration=(i=e.duration)!=null?i:Naubino.settings.overlay.duration},i.prototype.queue_messages=function(e,t){var n;e==null&&(e=["hello..","...world"]);if(n=e.shift())return e=e.slice(0),this.fade_in_and_out_message(n,function(n){return function(){return n.queue_messages(e,t)}}(this));if(t!=null)return t()},i.prototype.warning=function(e){return this.fade_in_message({text:e,fontsize:45,color:Util.color_to_rgba(Naubino.colors()[0])})},i.prototype.reset_osd=function(t){return this.objects.OSD=new e(t,this),this.objects.OSD.life=!0,this.draw()},i.prototype.set_osd=function(e){return this.objects.OSD?(this.set_text("OSD",e),this.objects.OSD.life=!0,this.draw()):this.reset_osd(e)},i.prototype.set_text=function(e,t){return this.objects[e].parse_text(t),this.draw()},i.prototype.fade_object=function(e,t){var n,r;if(e.alpha_delta!=null&&0<(r=e.alpha)&&r<=1){e.alpha+=e.alpha_delta,e.alpha=Math.min(e.alpha,1),e.alpha=Math.max(e.alpha,0);if(1<=e.alpha||e.alpha<=0)return delete e.alpha_delta}else if(e.duration!=null){e.age=e.age!=null?e.age+1:0;if(e.age>=e.duration*this.fps)return delete e.duration}else{if(e.callback!=null)return n=e.callback,e.alpha<=0&&delete this.objects[t],e.alpha>=1&&(delete e.callback,delete e.age),n.call();if(e.alpha<=0)return delete this.objects[t]}},i.prototype.message=function(t,n){var r;return n==null&&(n=this.ctx),this.can("play")&&this.play(),r=new e(t,this),this.add_object(r)},i}(n)}),e=function(){function e(e,t){this.layer=t,this.buffer=document.createElement("canvas"),this.buffer.width=Naubino.settings.canvas.width,this.buffer.height=Naubino.settings.canvas.height,this.alpha=1,this.ctx=this.buffer.getContext("2d"),this.parse_text(e),this.render()}return e.prototype.parse_text=function(e){var t,n,r;return typeof e!="string"&&(r=e,this.life=r.life,this.color=r.color,this.fontsize=r.fontsize,this.font=r.font,e=r.text,this.pos=r.pos,this.weight=r.weight,this.align=r.align,t=r.x,n=r.y),t!=null&&n!=null&&(this.pos=new cp.v(t,n)),this.pos==null&&(this.pos=this.layer.center()),this.color==null&&(this.color=Naubino.settings.overlay.color),this.fontsize==null&&(this.fontsize=Naubino.settings.overlay.fontsize),typeof this.fontsize!="number"&&(this.fontsize=Naubino.settings.overlay.fontsize),this.font==null&&(this.font=Naubino.settings.overlay.font),this.align==null&&(this.align="center"),this.weight==null&&(this.weight=""),this.text=e},e.prototype.render=function(){var e,t,n,r,i,s;this.ctx.clearRect(0,0,this.buffer.width,this.buffer.height),t=this.text.split("\n"),n={x:this.pos.x,y:this.pos.y},n.y-=this.fontsize*t.length/2,s=[];for(r=0,i=t.length;r<i;r++)e=t[r],this.life||console.log("OVERLAY:",e),this.ctx.fillStyle=this.color,this.ctx.shadowColor="#fff",this.ctx.shadowBlur=3,this.ctx.strokeStyle=this.color,this.ctx.textAlign=this.align,this.ctx.font=""+this.weight+" "+this.fontsize+"px "+this.font,this.ctx.fillText(e,n.x,n.y),s.push(n.y+=this.fontsize);return s},e}()}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};define("StandardGame",["Game"],function(t){var r;return r=function(t){function r(t){this.event=e(this.event,this),this.check=e(this.check,this),r.__super__.constructor.call(this,t),this.version=2}return n(r,t),r.prototype.calculate_points=function(e){var t,n,r;this.ex_naubs+=e.length,n=3,t=(n-1)/this.max_naubs,r=Math.floor(t*e.length*e.length),this.points+=r;if(r>0)return Naubino.overlay.fade_in_and_out_message("\n\nChain Bonus "+r)},r.prototype.level_details=[{limit:-1,number_of_colors:3,interval:40,max_naubs:20},{limit:20,number_of_colors:3,interval:38,max_naubs:20,probabilities:{pair:1,mixed_1:0,mixed_2:0,triple:0}},{limit:50,number_of_colors:3,interval:36,max_naubs:25,probabilities:{pair:9,mixed_1:0,mixed_2:0,triple:2}},{limit:80,number_of_colors:4,interval:30,max_naubs:30,probabilities:{pair:9,mixed_1:0,mixed_2:0,triple:1}},{limit:120,number_of_colors:4,interval:25,max_naubs:35,probabilities:{pair:8,mixed_1:1,mixed_2:0,triple:1}},{limit:150,number_of_colors:5,interval:25,max_naubs:40,probabilities:{pair:7,mixed_1:2,mixed_2:0,triple:1}},{limit:180,number_of_colors:5,interval:29,max_naubs:43,probabilities:{pair:6,mixed_1:3,mixed_2:0,triple:1}},{limit:210,number_of_colors:6,interval:30,max_naubs:45,probabilities:{pair:5,mixed_1:3,mixed_2:1,triple:1}},{limit:240,number_of_colors:6,interval:33,max_naubs:47,probabilities:{pair:4,mixed_1:4,mixed_2:1,triple:1}},{limit:270,number_of_colors:7,interval:36,max_naubs:49,probabilities:{pair:3,mixed_1:4,mixed_2:2,triple:1}},{limit:300,number_of_colors:7,interval:28,max_naubs:50,probabilities:{pair:3,mixed_1:3,mixed_2:3,triple:2}},{limit:350,number_of_colors:7,interval:24,max_naubs:50,probabilities:{pair:3,mixed_1:3,mixed_2:3,triple:2}},{limit:380,number_of_colors:7,interval:22,max_naubs:50,probabilities:{pair:3,mixed_1:3,mixed_2:3,triple:2}},{limit:420,number_of_colors:7,interval:20,max_naubs:50,probabilities:{pair:3,mixed_1:3,mixed_2:3,triple:2}},{limit:500,number_of_colors:7,interval:15,max_naubs:50,probabilities:{pair:3,mixed_1:3,mixed_2:3,triple:2}}],r.prototype.load_level=function(e){var t,n,r,i,s,o,u,a;if(this.level_details.length>=e){0<e&&e<this.level&&this.load_level(0),this.level=e,t="Level "+this.level,e<1||Naubino.overlay.fade_in_and_out_message(t),Naubino.menu.for_each(function(t){if(!(e<2))return t.set_random_palette_color()}),r=this.level_details[this.level],this.max_naubs=(i=r["max_naubs"])!=null?i:this.max_naubs,this.number_of_colors=(s=r["number_of_colors"])!=null?s:this.number_of_colors,this.spammer_interval=(o=r["interval"])!=null?o:this.spammer_interval,u=r.probabilities,a=[];for(t in u)n=u[t],a.push(this.spammers[t].probability=n);return a}},r.prototype.max_color=function(){return Math.floor(Math.random()*this.number_of_colors)},r.prototype.oninit=function(){return r.__super__.oninit.call(this),this.naub_replaced.add(function(e){return function(t){return e.graph.cycle_test(t)}}(this)),this.naub_destroyed.add(function(e){return function(t){return e.points+=e.get_object(t).points_on_destroy()}}(this)),this.cycle_found.add(function(e){return function(t){return e.destroy_naubs(t)}}(this)),this.cycle_found.add(function(e){return function(t){return e.calculate_points(t)}}(this)),this.naub_focused.add(function(e){return function(t){return e.active_tree=e.graph.tree(t.number)}}(this)),this.number_of_colors=this.default_number_of_colors=3,this.spammers={pair:{method:function(e){return function(){return e.factory.create_naub_pair(null,e.max_color(),e.max_color())}}(this),probability:5},mixed_1:{method:function(e){return function(){return e.factory.create_naub_pair(null,e.max_color(),e.max_color(),1)}}(this),probability:0},mixed_2:{method:function(e){return function(){return e.factory.create_naub_pair(null,e.max_color(),e.max_color(),2)}}(this),probability:0},triple:{method:function(e){return function(){return e.factory.create_naub_triple(null,e.max_color(),e.max_color(),e.max_color())}}(this),probability:0}},this.inner_clock=0,this.points=0,this.ex_naubs=0,this.naubs_count=0,this.load_level(0)},r.prototype.onplaying=function(){this.spamming||(this.spamming=setInterval(this.event,100)),this.checking||(this.checking=setInterval(this.check,300));if(this.OSD==null)return Naubino.overlay.set_osd({text:"level0",pos:{x:10,y:this.height},fontsize:8,align:"",life:!0,color:"gray"})},r.prototype.onleaveplaying=function(){return clearInterval(this.spamming),clearInterval(this.checking),this.spamming=this.checking=null},r.prototype.onbeforestop=function(e,t,n,r){return Naubino.override||r?(delete Naubino.override,!0):confirm("Do you realy want to stop the game?")},r.prototype.map_spammers=function(){var e,t,n,r,i;n=0,r=this.spammers,i=[];for(e in r)t=r[e],n+=t.probability,i.push({range:n,name:e,method:t.method});return i},r.prototype.spam=function(){var e,t,n,r,i,s,o,u,a;r=function(){var e,t;e=this.spammers,t=[];for(n in e)i=e[n],t.push(i.probability);return t}.call(this),t=r.reduce(function(e,t){return e+t}),e=Math.floor(Math.random()*t),a=this.map_spammers();for(o=0,u=a.length;o<u;o++){s=a[o];if(e<s.range){s.method();return}}},r.prototype.check=function(){var e,t;return this.duration=Date.now()-this.begin_time,Naubino.set_score(),e=this.capacity(),t=45,e<t?(Naubino.background.pulsating===!1&&Naubino.background.pulse(),Naubino.background.ttl=Math.floor(e/2),Naubino.background.pulse_speed=Util.interpolate(3,25,(t-e)/t)):Naubino.background.pulsating===!0&&(Naubino.background.stop_pulse(),Naubino.background.ttl=t),this.capacity()<5&&this.loose(),this.level_details[this.level].limit<this.ex_naubs&&this.load_level(this.level+1),Naubino.overlay.set_osd("| level: "+this.level+" | points: "+this.points+" | destroyed naubs: "+this.ex_naubs+" | capacity:"+Math.round(this.capacity())+"% |")},r.prototype.event=function(){return this.inner_clock===0&&this.spam(),this.inner_clock=(this.inner_clock+1)%this.spammer_interval,this.spammer_interval},r}(t)})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};define("TestCase",["Naub","Game","Shapes","StandardGame"],function(t,r,i,s){var o,u,a,f,l;return f=i.StringShape,a=i.NumberShape,o=i.Ball,u=i.FrameCircle,l=function(r){function i(){return this.add_ball=e(this.add_ball,this),i.__super__.constructor.apply(this,arguments)}return n(i,r),i.prototype.oninit=function(){return i.__super__.oninit.call(this),Naubino.settings.graphics.updating=!1,Naubino.settings.game.creation_offset=-200,this.naub_replaced.add(function(e){return function(t){return e.graph.cycle_test(t)}}(this)),this.cycle_found.add(function(e){return function(t){return e.destroy_naubs(t)}}(this)),setTimeout(function(){return Naubino.play()},300)},i.prototype.onplaying=function(e,t,n){var r,i;t==="stopped"&&this.factory.create_matching_naubs();for(i=0;i<=5;i++)this.add_ball();return r=function(e){return function(){return e.gravity=!1}}(this)},i.prototype.event=function(){},i.prototype.add_ball=function(e,n){var r,i;return e==null&&(e=this.factory.random_outside()),n==null&&(n=null),i=new t(this,n),r=new o,i.add_shape(r),i.setup_physics(),i.physical_body.setPos(e.Copy()),i.kind="ball",this.add_object(i),i.add_shape(new f(i.number,"white")),i.update(),i},i}(r)})}.call(this),function(){var e=function(e,t){return function(){return e.apply(t,arguments)}},t={}.hasOwnProperty,n=function(e,n){function i(){this.constructor=e}for(var r in n)t.call(n,r)&&(e[r]=n[r]);return i.prototype=n.prototype,e.prototype=new i,e.__super__=n.prototype,e};define("Tutorial",["Game"],function(t){var r;return r=function(t){function r(t,n){this.toggle_joining=e(this.toggle_joining,this),r.__super__.constructor.call(this,t,n),this.multiplicator=10}return n(r,t),r.name="Tutorial",r.prototype.configure=function(){return Naubino.overlay.animation.play(),Naubino.background.animation.current!=="stopped"&&Naubino.background.animation.stop(),this.font_size=24,this.joining_allowed=!1,this.lessons=StateMachine.create(this.lesson_steps={initial:"welcome",error:function(e,t,n,r,i,s){if(e!=="click")return console.warn(e,t,n,r,i,s)},events:[{name:"click",from:"welcome",to:"lesson_show"},{name:"shown",from:"lesson_show",to:"lesson_move"},{name:"moved",from:"lesson_move",to:"lesson_join"},{name:"joined",from:"lesson_join",to:"lesson_cycle"},{name:"click",from:"lesson_cycle",to:"success"}],callbacks:{onchangestate:function(e,t,n){return console.info("Tutorial:",this.current),console.info(""+t+" --("+e+")--> "+n)},onwelcome:function(e){return function(t,n,r){return Naubino.mousedown.active=!1,Naubino.mousedown.add(function(){return e.lessons.click()}),Naubino.overlay.fade_in_message({text:"Tutorial",fontsize:24}),setTimeout(function(){return Naubino.overlay.fade_in_message({text:"\n\nclick to continue",fontsize:12}),Naubino.mousedown.active=!0},10*e.multiplicator),setTimeout(function(){var t;return t=e.center.Copy(),t.add(cp.v(0,e.height/2-10)),Naubino.overlay.fade_in_and_out_message({text:"use the menu to restart this tutorial at any time",duration:5,fontsize:12,pos:t})},30*e.multiplicator)}}(this),onleavewelcome:function(e){return function(){return Naubino.overlay.fade_out_messages(function(){return e.lessons.transition()}),!1}}(this),onclick:function(e){return function(){}}(this),onlesson_show:function(e){return function(){var t,n;return setTimeout(function(){return e.create_naubs(),e.for_each(function(e){return e.disable()}),console.warn("naubs inserted")},43*e.multiplicator),n=[{text:"Lesson 1",duration:1.3,fontsize:e.font_size*2},{text:"Naubino is all about Naubs",duration:1},{text:"These are Naubs",duration:1},{text:"They always come in pairs",duration:1},{text:"Try to move them around!",duration:1}],t=function(){return Naubino.overlay.queue_messages(n,function(){return e.lessons.shown()})},t()}}(this),onlesson_move:function(e){return function(){var t,n;return e.for_each(function(e){return e.enable()}),t=e.naub_focused.add(function(e){return e.old_pos=e.physics.pos.Copy()}),n=e.naub_unfocused.add(function(r){var i,s;s=r.physics.pos.Copy(),s.Subtract(r.old_pos),i=s.Length();if(i>180)return t.detach(),n.detach(),e.lessons.moved()}),e.fallback_warning_timer=setTimeout(function(){return Naubino.overlay.fade_in_and_out_message(["Just drag one pair across.",30*e.multiplicator],null,e.font_size)},100*e.multiplicator)}}(this),onleavelesson_move:function(e){return function(){return clearTimeout(e.fallback_warning_timer),Naubino.overlay.fade_out_messages(function(){return e.transition()}),!1}}(this),onlesson_join:function(e){return function(){return e.joining_allowed=!1,e.naub_replaced.addOnce(function(){return Naubino.overlay.queue_messages([["nicely done!",20*e.multiplicator]],function(){return e.lessons.joined()},e.font_size),e.toggle_joining()}),Naubino.overlay.queue_messages([["very Good",10*e.multiplicator],["Every Naub has a certain color",10*e.multiplicator],["You can connect pairs of Naubs...",14*e.multiplicator],["...by dragging on Naub onto\nanother with the same color",30*e.multiplicator],["Now try to connect two pairs of naubs!",30*e.multiplicator]],e.toggle_joining,e.font_size)}}(this),onlesson_cycle:function(e){return function(t,n,r){return e.cycle_found.add(function(){return Naubino.overlay.queue_messages([["Great",40*e.multiplicator]],null,e.font_size)}),Naubino.overlay.queue_messages([["now connect the remaining naubs",25*e.multiplicator],["and see what happens...",20*e.multiplicator]],e.toggle_joining,e.font_size)}}(this),onsuccess:function(e){return function(){return console.info}}(this)}})},r.prototype.onbeforestop=function(e,t,n){return Naubino.leave_tutorial()},r.prototype.onstopped=function(e,t,n){return e!=="init"?(Naubino.overlay.animation.stop(),this.animation.stop(),this.levels.reset(),this.stop_stepper(),this.clear(),this.clear_objects(),this.points=0,console.info("Tutorial stopped")):(console.info("Tutorial initialized"),this.configure()),!0},r.prototype.toggle_joining=function(){return this.joining_allowed=!this.joining_allowed,console.log("joining_allowed",this.joining_allowed)},r.prototype.create_naubs=function(){var e;return this.gravity=!0,this.factory.create_matching_naubs(1,1),this.start_stepper(),e=function(){return this.gravity=!1},setTimeout(e,55*this.multiplicator)},r}(t)})}.call(this),function(){define("LayerManager",["Background","Game","Menu","Overlay","StandardGame","TestCase","Tutorial"],function(e,t,n,r,i,s,o){var u;return u=function(){function t(){}return t.prototype.setup_fsm=function(){return StateMachine.create({target:this,events:Naubino.settings.events["default"].concat(Naubino.settings.events.game),error:function(e,t,n,r,i,s){return console.error(""+this.name+"."+e+": "+t+" -> "+n+"\n"+i+"::"+s)}})},t.prototype.setup_layers=function(){return this.background=new e(this.canvases.background_canvas),this.menu=new n(this.canvases.menu_canvas),this.overlay=new r(this.canvases.overlay_canvas),this.game_standard=new i(this.canvases.game_canvas),this.game_testcase=new s(this.game_canvas),this.game=this.game_standard,this.layers=[this.background,this.game,this.menu,this.overlay]},t.prototype.center=function(){var e,t,n,r,i,s,o,u;r=window.innerWidth,e=$("canvas#game_canvas").width(),n=r/2-e/2,document.querySelector("form").style.left=""+n+"px",o=this.layers,u=[];for(i=0,s=o.length;i<s;i++)t=o[i],u.push(t.canvas.style.left=""+n+"px");return u},t.prototype.demaximize=function(){var e,t,n,r;r=this.layers;for(t=0,n=r.length;t<n;t++)e=r[t],e.reset_resize();return this.scale=1},t.prototype.maximize=function(){var e,t,n,r,i,s,o,u,a,f,l,c;this.demaximize();if(this.scale===1){u=window.screen.width,o=window.screen.height,console.info("window size",u,o),t=$("canvas#game_canvas").width(),e=$("canvas#game_canvas").height(),r=$("canvas#game_canvas").offset().top,i=1,this.scale=Naubino.settings.canvas.scale=u/t,e*this.scale>o&&(this.scale=Naubino.settings.canvas.scale=(o-r)/e),document.querySelector("#gamediv").style.width="",s=Naubino.settings.canvas.scale/i,l=this.layers,c=[];for(a=0,f=l.length;a<f;a++)n=l[a],c.push(n.resize_by(s));return c}},t.prototype.stretch=function(e){var t,n,r,i,s;e==null&&(e="100%"),i="background game menu overlay".split(" "),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(document.querySelector("canvas#"+t+"_canvas").style.width=e);return s},t.prototype.list_states=function(){var e,t,n,r,i;this.name="Naubino",r=[this,this.menu,this.game,this.overlay,this.background],i=[];for(t=0,n=r.length;t<n;t++){e=r[t];switch(e.current){case"playing":i.push(console.info(e.name,e.current,e.fps,e.step_rate));break;case"paused":i.push(console.warn(e.name,e.current,e.fps,e.step_rate));break;case"stopped":i.push(console.warn(e.name,e.current,e.fps,e.step_rate));break;default:i.push(console.error(e.name,e.current))}}return i},t.prototype.toggle=function(){switch(this.current){case"playing":return this.pause();case"paused":return this.play();case"stopped":return this.play()}},t.prototype.oninit=function(){var e,t,n,r,i;r=this.layers,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.init());return i},t.prototype.onchangestate=function(e,t,n){return console.info("Naubino changed states "+e+": "+t+" -> "+n)},t.prototype.onleavestopped=function(){return this.menu.play()},t.prototype.onplay=function(e,t,n){var r,i,s,o;o=[this.game,this.overlay,this.background];for(i=0,s=o.length;i<s;i++)r=o[i],r.play();return this.menu.check_game_state(this.game)},t.prototype.onbeforepause=function(){return this.game.can("pause")&&this.background.can("pause")},t.prototype.onpause=function(e,t,n){var r,i,s,o;o=[this.game,this.overlay,this.background];for(i=0,s=o.length;i<s;i++)r=o[i],this.overlay.can("pause")&&r.pause();return this.menu.check_game_state(this.game)},t.prototype.onbeforestop=function(e,t,n,r){return this.override=r!=null?r:!1,this.game.stop(),this.game.current==="stopped"?(this.overlay.stop(),this.background.stop()):!1},t.prototype.onstopped=function(e,t,n){var r,i,s,o,u;console.warn("stopped"),u=[this.game,this.overlay,this.background];for(s=0,o=u.length;s<o;s++)r=u[s],r.init();this.menu.check_game_state(this.game);if(t!=="none"&&this.temp_score.points!==0){i=prompt("Enter your name for the highscore");if(i!=null)return Naubino.store_score(i)}},t.prototype.onloose=function(e,t,n,r){var i;return r==null&&(r="Game Over"),this.game.can("loose")&&this.game.loose(),this.overlay.warning(r),i=function(e){return function(){return console.warn("leaving lost"),e.overlay.stop(),e.background.stop(),e.game.fade_out(function(){return setTimeout(function(){return e.stop(!0)},2e3)})}}(this),this.game.one_after_another(function(e){return e.grey_out()},i)},t.prototype.onleavelost=function(){},t}()})}.call(this),function(){define("Util",[],function(){}),cp.Vect.prototype.Copy=function(){return new cp.Vect(this.x,this.y)},cp.Vect.prototype.Length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},cp.Vect.prototype.Angle=function(){return cp.v.toangle(this)},cp.Vect.prototype.IsZero=function(){var e;return this.x===(e=this.y)&&e===0},cp.Vect.prototype.AddPolar=function(e,t){return this.x+=Math.cos(e)*t,this.y+=Math.sin(e)*t},cp.Constraint.prototype.IsRogue=function(){return this.a.isRogue()&&!this.a.isStatic()||this.b.isRogue()&&!this.b.isStatic()},window.Util={shuffle:function(e){var t,n,r,i,s,o,u;t=e.slice();for(n=s=0,o=t.length;s<o;n=++s)i=t[n],r=Math.floor(Math.random()*t.length),u=[t[r],t[n]],t[n]=u[0],t[r]=u[1];return t},extend:function(e,t){var n,r,i;i=[];for(r in t)n=t[r],i.push(e[r]=n);return i},include:function(e,t){return this.extend(e.prototype,t)},color_to_rgba:function(e){return function(e,t){var n,r,i,s;return t==null&&(t=0),s=Math.round(e[0]+t),i=Math.round(e[1]+t),r=Math.round(e[2]+t),n=e[3],n!=null?"rgba("+s+","+i+","+r+","+n+")":"rgba("+s+","+i+","+r+",1)"}}(this),interpolate_color:function(e,t,n){var r,i,s,o;n==null&&(n=.5),i=Math.min(e.length,t.length),o=[];for(r=s=0;0<=i?s<i:s>i;r=0<=i?++s:--s)o.push(this.interpolate(e[r],t[r],n));return o},interpolate:function(e,t,n){var r,i;return n==null&&(n=.5),r=t-e,i=e+r*n},togglePrerendering:function(){return Naubino.settings.graphics.updating=$("#prerenderingCheck").is(":checked")?!1:!0},toggleMaximized:function(e){return e==null&&(e=!1),$("#maximizeCheck").is(":checked")||e?Naubino.maximize():Naubino.demaximize(),window.Naubino.center()},toggleEffects:function(){var e,t,n,r,i,s,o,u,a;if($("#effectsCheck").is(":checked")){Naubino.settings.graphics.effects=!0,s=Naubino.layers,u=[];for(t=0,r=s.length;t<r;t++)e=s[t],e.min_fps!=null&&e.refresh_draw_rate(e.min_fps),e.min_step_rate!=null?u.push(e.refresh_step_rate(e.min_step_rate)):u.push(void 0);return u}Naubino.settings.graphics.effects=!1,o=Naubino.layers,a=[];for(n=0,i=o.length;n<i;n++)e=o[n],e.refresh_draw_rate(e.default_fps),a.push(e.refresh_step_rate(e.default_step_rate));return a},toggleFullscreen:function(){return $("#fullScreenCheck").is(":checked")?this.requestFullscreen():this.exitFullscreen()},toggleAll:function(){return this.toggleEffects(),this.toggleFullscreen(),this.toggleMaximized(),this.togglePrerendering},requestFullscreen:function(){var e;e=document.documentElement;if(e.requestFullscreen!=null)return e.requestFullscreen();if(e.mozRequestFullScreen!=null)return e.mozRequestFullScreen();if(e.oRequestFullScreen!=null)return e.oRequestFullScreen();if(e.webkitRequestFullScreen!=null)return e.webkitRequestFullScreen()},exitFullscreen:function(){if(document.exitFullscreen)return document.exitFullscreen();if(document.mozCancelFullScreen)return document.mozCancelFullScreen();if(document.webkitCancelFullScreen)return document.webkitCancelFullScreen()},changeFullscreen:function(e){return e||document.fullscreen||document.mozFullScreen||document.webkitIsFullScreen?this.toggleMaximized(!0):this.toggleMaximized()}}}.call(this),function(){var e={}.hasOwnProperty,t=function(t,n){function i(){this.constructor=t}for(var r in n)e.call(n,r)&&(t[r]=n[r]);return i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,t};define("Naubino",["Audio","Keybindings","Settings","LayerManager","Util"],function(e,n,r,i){var s;return s=function(e){function i(){this.name="Naubino (unstable master)",this.settings=r,this.Signal=window.signals.Signal,this.setup_signals(),this.add_listeners(),this.scale=1,this.load_highscores()}return t(i,e),i.prototype.load_highscores=function(){var e;return e=localStorage.getItem("naubino_hiscore"),this.scores=e?JSON.parse(e):[{name:"nobody",points:0,time:0,naubs:0,level:0}]},i.prototype.set_score=function(){return this.temp_score={name:"nobody",points:this.game.points,time:this.game.duration,naubs:this.game.ex_naubs,game_version:this.game.version,level:this.game.level}},i.prototype.store_score=function(e){var t;return e==null&&(e="nobody"),this.temp_score.name=e,this.temp_score.date=Date.now(),this.scores.push(this.temp_score),t=JSON.stringify(this.scores),localStorage.setItem("naubino_hiscore",t)},i.prototype.setup=function(){return this.setup_dom(),this.setup_layers(),this.setup_keybindings(),this.setup_cursorbindings(),this.setup_fsm(),this.init(),console.timeEnd("loading")},i.prototype.colors=function(){return this.settings.colors[this.settings.color]},i.prototype.recolor=function(){return this.game.for_each(function(e){return e.recolor()})},i.prototype.print=function(){return this.gamediv.insertAdjacentHTML("afterend",'<img src="'+this.game_canvas.toDataURL()+'"/>')},i.prototype.setup_dom=function(){var e,t,n,r,i,s,o,u,a;this.gamediv=document.querySelector("#gamediv"),this.gamediv.max-(r=this.settings.canvas.width),this.canvases={},o=this.settings.canvas,r=o.width,t=o.height,u="background game menu overlay".split(" "),a=[];for(i=0,s=u.length;i<s;i++)n=u[i],n+="_canvas",e=document.createElement("canvas"),e.width=r,e.height=t,e.setAttribute("id",n),this[n]=e,this.gamediv.appendChild(e),a.push(this.canvases[n]=e);return a},i.prototype.setup_signals=function(){return this.mousedown=new this.Signal,this.mouseup=new this.Signal,this.mousemove=new this.Signal,this.keydown=new this.Signal,this.keyup=new this.Signal,this.touchstart=new this.Signal,this.touchend=new this.Signal,this.touchmove=new this.Signal,this.menu_button=new this.Signal,this.menu_focus=new this.Signal,this.menu_blur=new this.Signal},i.prototype.add_listeners=function(){},i.prototype.tutorial=function(){},i.prototype.setup_keybindings=function(){return this.keybindings=new n,window.onkeydown=function(e){return function(t){return e.keybindings.keydown(t)}}(this),window.onkeyup=function(e){return function(t){return e.keybindings.keyup(t)}}(this),this.keybindings.enable(32,function(e){return function(){return e.toggle()}}(this)),this.keybindings.enable(27,function(e){return function(){return e.stop()}}(this))},i.prototype.setup_cursorbindings=function(){var e,t,n;return t=function(e){return function(t){var n,r;return n=(t.pageX-e.overlay_canvas.offsetLeft)/e.scale,r=(t.pageY-e.overlay_canvas.offsetTop)/e.scale,e.mousemove.dispatch(n,r)}}(this),n=function(e){return function(t){var n,r;return n=(t.pageX-e.overlay_canvas.offsetLeft)/e.scale,r=(t.pageY-e.overlay_canvas.offsetTop)/e.scale,e.mouseup.dispatch(n,r)}}(this),e=function(e){return function(t){var n,r;return n=(t.pageX-e.overlay_canvas.offsetLeft)/e.scale,r=(t.pageY-e.overlay_canvas.offsetTop)/e.scale,e.mousedown.dispatch(n,r)}}(this),this.overlay_canvas.addEventListener("mousedown",e,!1),this.overlay_canvas.addEventListener("mouseup",n,!1),this.overlay_canvas.addEventListener("mousemove",t,!1),this.overlay_canvas.addEventListener("mouseout",n,!1),this.overlay_canvas.addEventListener("touchstart",e,!1),this.overlay_canvas.addEventListener("touchend",n,!1),this.overlay_canvas.addEventListener("touchmove",t,!1)},i}(i)})}.call(this),function(){console.time("loading"),define("Load",["Naubino"],function(e){return window.onresize=function(){return $("#maximizeCheck").is(":checked")?(window.resizetimeout!=null&&clearTimeout(window.resizetimeout),window.resizetimeout=setTimeout(function(){return window.Naubino.maximize(),window.Naubino.center()},1e3)):window.Naubino.center()},window.onload=function(){var t,n,r,i;r=window.Naubino=new e,r.setup(),$("#highscorelink").on("click",function(){return confirm("do you want to leave this page?")}),navigator.platform.indexOf("iPad")!==-1&&($("#maximizeCheck").prop("checked",!0),$("#github").hide(),$("form label").hide(),$("form input[type=checkbox]").hide()),Util.toggleMaximized(),i=r.settings.colors;for(n in i)t=i[n],$("select#colors").append('<option value="'+n+'">'+n+"</option>");return $("select#colors option").each(function(e,t){if(t.value===r.settings.color)return t.selected=!0}),$("select#colors").change(function(){return r.settings.color=this.value,this.value==="high_contrast"?(r.settings.graphics.draw_borders_old=r.settings.graphics.draw_borders,r.settings.graphics.draw_borders=!0):r.settings.graphics.draw_borders_old!=null&&(r.settings.graphics.draw_borders=r.settings.graphics.draw_borders_old),r.menu.for_each(function(e){return e.recolor()}),r.game.for_each(function(e){return e.recolor()}),r.game.draw()}),document.addEventListener("fullscreenchange",function(e){return function(){return Util.changeFullscreen(document.fullscreen)}}(this),!1),document.addEventListener("mozfullscreenchange",function(e){return function(){return Util.changeFullscreen(document.mozFullScreen)}}(this),!1),document.addEventListener("webkitfullscreenchange",function(e){return function(){return Util.changeFullscreen(document.webkitIsFullScreen)}}(this),!1)}})}.call(this);