/*! GraphicEngine Package - v0.1.0 - 2015-04-26 */ var GraphicEngine=function(){var a=function(){function a(){this._attributes={}}return a.prototype={set:function(a,b){return this._attributes[a]=b,this},get:function(a){return this._attributes[a]},_extend:function(a,b){if(b)for(var c in b)b.hasOwnProperty(c)&&(a[c]&&a[c]instanceof Object&&!(a[c]instanceof Array)?this._extend(a[c],b[c]):a[c]=b[c])}},a}(),b=function(){function a(a,b,c){this.x=parseFloat(a)||0,this.y=parseFloat(b)||0,this.z=parseFloat(c)||0}return a.prototype={toOrtho:function(){return new a(this.x-this.y,(this.x+this.y)/2-1.25*this.z,0)},toIso:function(){return new a(this.y+this.x/2,this.y-this.x/2,0)},toString:function(){return"{x:"+this.x+", y:"+this.y+", z:"+this.z+"}"},toObject:function(){return{x:this.x,y:this.y,z:this.z}},toArray:function(){return[this.x,this.y,this.z]},add:function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z)},subtract:function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z)},multiply:function(b){return new a(this.x*b.x,this.y*b.y,this.z*b.z)},distance:function(a){var b=Math.abs(this.x-a.x),c=Math.abs(this.y-a.y),d=Math.abs(this.z-a.z),e=Math.sqrt(Math.pow(b,2)+Math.pow(c,2));return Math.sqrt(Math.pow(e,2)+Math.pow(d,2))}},a}(),c=function(){function a(a){this._stepCallback=null,this._animation=null,this._startTime=0,a&&this.setCallback(a),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)}}(),window.cancelRequestAnimFrame=function(){return window.cancelAnimationFrame||window.cancelRequestAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout}()}return a.prototype={setCallback:function(a){this._stepCallback=a},start:function(a){this._startTime=(new Date).getTime(),this._animate(),a&&setTimeout(function(){this.stop()}.bind(this),a)},stop:function(){cancelRequestAnimFrame(this._animation),this._animation=null},_animate:function(){this._stepRender(),this._animation=requestAnimFrame(this._animate.bind(this))},_stepRender:function(){var a=(new Date).getTime()-this._startTime;this._stepCallback&&this._stepCallback(a)}},a}(),d=function(){function a(a){this.context=a,this.message=null,this.messageOrigin={x:0,y:0},this.isPath=!1,this.isStroke=!1}return a.prototype={setup:function(a){a||(a={});var b=null==a.fillColor?null:this.castToColor(a.fillColor),c=null==a.strokeColor?null:this.castToColor(a.strokeColor),d=a.strokeSize;this.context.restore(),this.context.fillStyle=b,this.context.strokeStyle=c,this.context.lineWidth=d,this.context.globalAlpha=a.alpha||1,this.context.font=a.font||"20px Open Sans",this.context.save(),this.isStroke=null!=c,this.isPath=null!=b,this.isPath&&this.context.beginPath()},render:function(){this.message&&(this.isPath&&this.context.fillText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.isStroke&&this.context.strokeText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.message=null),this.isPath&&this.context.closePath(),this.isPath&&this.context.fill(),this.isPath=!1,this.isStroke&&this.context.stroke(),this.isStroke=!1},moveTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.moveTo(a,b),c},lineTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.lineTo(a,b),c},text:function(a,b){if(!a)return[];b||(b=[0,0]),b=this.castToPoint(b),this.messageOrigin=b,this.message=a;var c=this.context.measureText(a),d=this.context.font,e=Math.ceil(c.width),f=parseInt(d);return isNaN(f)&&(d=d.substr(d.indexOf(" ")),f=parseInt(d)),[b.add([0,0]),b.add([e,0]),b.add([e,-f]),b.add([0,-f])]},line:function(a,b,c){return a&&b?(a=this.castToPoint(a),b=this.castToPoint(b),c&&(a=a.toOrtho(),b=b.toOrtho()),this.moveTo(a.x,a.y)&&this.lineTo(b.x,b.y)):!1},polygon:function(a,b,c){if(!a)return[];b||(b=[0,0,0]),b=this.castToPoint(b),a=a.map(function(a){return this.castToPoint(a)}.bind(this)),c&&(b=b.toOrtho()),c&&(a=a.map(function(a){return a.toOrtho()}));var d,e,f=b.add(a[0]),g=[];for(this.moveTo(f.x,f.y)&&g.push(f),d=1;d1&&a.length<4&&(c=new b(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),c}},a}(),e=function(a,b){function c(c){if(!c)throw new Error('no "name" provided for this displayObject:',this);if(a.call(this),this._name=c,this._parent=null,this._zIndex=0,this._position=new b,this._shape=null,this._info={stepCallback:null,renderMethod:null,renderInfo:null},this._options={strokeColor:0,fillColor:0,strokeSize:1,alpha:1,font:"14px Arial"},this[c])throw new Error('property "%s" already exists on',c,this)}return c.prototype=Object.create(a.prototype),c.prototype.setOptions=function(a){return a?(this._extend(this._options,a),!0):!1},c.prototype.setRenderInfo=function(a,b){b&&this.setOptions(b),this._info.renderInfo=a},c.prototype.setAnimationStep=function(a){this._info.stepCallback=a.bind(this)},c.prototype._addTo=function(a,b){this._zIndex=b||0,this._parent=a},c.prototype._remove=function(){delete this},c.prototype._render=function(a,b){if(!this._info.renderMethod)throw new Error("no renderMethod set for this instance of DisplayObject: ",this);return this._info.renderInfo?(a._info.draw.setup(this._options),this._shape=a._info.draw[this._info.renderMethod](this._info.renderInfo,this._position,b),a._info.draw.render(),!0):!1},c.prototype._step=function(a){return this._info.stepCallback&&this._info.stepCallback(a),!0},c}(a,b),f=function(a){function b(b){a.call(this,b),this._info.renderMethod="image"}return b.prototype=Object.create(a.prototype),b.prototype.render=function(){},b}(e),g=function(a){function b(b){a.call(this,b),this._options.font=this.getFont("Verdana",14),this._options.fillColor=0,this._options.strokeColor=null,this._info.renderMethod="text"}return b.prototype=Object.create(a.prototype),b.prototype.getFont=function(a,b,c){return a?(c||(c=""),b||(b=""),"number"==typeof b&&(b+="px"),[c,b,a].join(" ")):""},b.prototype.setFont=function(a,b,c){return a?(this._options.font=this.getFont(a,b,c),!0):!1},b}(e),h=function(a){function b(b){a.call(this,b),this._options.fillColor=null,this._options.strokeColor=0,this._info.renderMethod="polygon"}return b.prototype=Object.create(a.prototype),b}(e),i=function(a){function b(b){a.call(this,b),this._children={},this._childrenLength=function(){var a=0;return c(this,function(){a++}),a}.bind(this._children),this._childrenArray=function(){var a=[];return c(this,function(b){a.push(b)}),a.sort(function(a,b){return a._zIndex-b._zIndex})}.bind(this._children)}function c(a,b){if(a&&b)for(var c in a)a.hasOwnProperty(c)&&b(a[c])}return b.prototype=Object.create(a.prototype),b.prototype._render=function(a,b){this._childrenArray().forEach(function(c){c._render(a,b)})},b.prototype._step=function(b){return this._childrenArray().forEach(function(a){a._step(b)}),a.prototype._step.call(this,b),!0},b.prototype.addChild=function(b,c){if(!(b instanceof a))throw new Error("adding child with unsupported type:",typeof b);if(this[b._name])throw new Error('property "',b._name,'" already exists on',this);return c||(c=this._childrenLength()),this._children[b._name]=b,this[b._name]=b,b._addTo(this,c),this._reorderChildren(),b},b.prototype.removeChild=function(b){b instanceof String&&(b=this[b]),b&&this[b._name]&&this[b._name]instanceof a&&(delete this._children[b._name],delete this[b._name],b._remove())},b.prototype._reorderChildren=function(){this._childrenArray().forEach(function(a,b){a._info.index=b})},b.prototype._getShapes=function(){for(var a,c=[],d=0;d").addClass("iso-layer").css({position:"absolute",top:0,left:0}).append(this._info.canvas)}return e.prototype=Object.create(b.prototype),e.prototype._render=function(){this.clear(),b.prototype._render.call(this,this,this._info.mode==this._info.modes.ISOMETRIC)},e.prototype._remove=function(){this.$el.remove()},e.prototype._addTo=function(a){if(a){var b=a.worldSize();this.setSize(b.w,b.h),this.$el.appendTo(a.$el),this._engine=a}},e.prototype.toggleMode=function(a){this._info.modes[a]&&this.mode!=a&&(this.mode=a,this._render())},e.prototype.clear=function(){this._info.context.clearRect(-this._info.size.w/2,-this._info.size.h/2,this._info.size.w,this._info.size.h)},e.prototype.getCanvas=function(){return this._info.canvas},e.prototype.renderTime=function(a){this._step(a)&&this._render()},e.prototype.startAnimation=function(a){this._info.animator.start(a)},e.prototype.stopAnimation=function(){this._info.animator.stop()},e.prototype.setSize=function(a,b){this._info.size={w:a,h:b},this._info.canvas.width=a.toString(),this._info.canvas.height=b.toString(),this._info.context.translate(a/2,b/2)},e.prototype.setShadow=function(a,b,c,d){this._info.context.shadowColor=a||"#999",this._info.context.shadowBlur=b||20,this._info.context.shadowOffsetX=c||15,this._info.context.shadowOffsetY=d||c||15},e}(jQuery,i),k=function(a){function b(b){a.call(this,b)}return b.prototype=Object.create(a.prototype),b}(i),l=function(a,b){function c(){this.$el=a("
"),this.layers={},this.fpsInterval=null,this.fpsLogInterval=null,this.utils={worldSizeWidth:400,worldSizeHeight:400}}function d(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d