thrunium 1.2.0-rc.2 → 1.2.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
- /*! THRUNIUM v1.2.0-rc.2 | (c) Infobits ApS | MIT License */
2
- "use strict";(()=>{var H=Object.defineProperty;var _=(s,e)=>{for(var t in e)H(s,t,{get:e[t],enumerable:!0})};window.THRUNIUM||(window.THRUNIUM={});var n=window.THRUNIUM;function b(){n.pageLoaded=!0}function x(s){let e=!1,t=()=>{e||(e=!0,s())};if(document.readyState==="complete"){t();return}document.addEventListener("DOMContentLoaded",t,!1),window.addEventListener("load",t,!1)}function m(s){console.error(s),n.error=!0}function E(){let s=navigator.userAgent||navigator.vendor||"";return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(s)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(s.substr(0,4))}function L(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function R(s,e,t=!1){return t?Math.random()*(e-s)+s:Math.floor(Math.random()*(e-s+1))+s}function M(){n.container=null,n.gameObject=null,n.error=!1,n.pageLoaded=!1,n.fontsLoaded=!1,x(b),typeof document!="undefined"&&document.fonts&&document.fonts.ready?document.fonts.ready.then(()=>{n.fontsLoaded=!0}):n.fontsLoaded=!0}var C;C=Symbol.toStringTag;var p=class{constructor(e,t){this[C]="THRUNIUM.Game";this.scale=1;this.fitScale=1;this.delta=0;this.fps=0;this.runSpeed=0;this.lastRun=null;this.gameRunning=!1;this.showFPS=!1;this.namespace="";this.mouseX=0;this.mouseY=0;this.state="startup";this.startState=null;this.states=[];this.backgroundColor="#fff";this.assets=[];this.assetsLoaded=!1;this.loadedAssets=0;this.assetsToLoad=0;this.font="Arial";this.textSize="30px";this.click=()=>{};this.mousedown=()=>{};this.mouseup=()=>{};this.mousemove=()=>{};this.touch=()=>{};this.touchstart=()=>{};this.touchend=()=>{};this.keydown=()=>{};this.keyup=()=>{};this.deviceorientation=()=>{};this.devicemotion=()=>{};this.rezise=()=>{};this._deviceorientation=e=>{this.deviceorientation(e)};this._devicemotion=e=>{this.devicemotion(e)};this._mousetouchmove=e=>{e.preventDefault(),this.getMouseCords(e),this.mousemove(e)};this._touchstart=e=>{e.preventDefault(),this.getMouseCords(e),this.touch(e),this.touchstart(e)};this._touchend=e=>{e.preventDefault(),this.getMouseCords(e),this.click(e),this.touchend(e)};this._resize=e=>{var i,o;this.updateFitScale(),this.updateScale();let t=(o=(i=n.Elem)==null?void 0:i.elemsList)!=null?o:[];for(let r=0;r<t.length;r++)t[r].resize();this.rezise(e)};this.assetLoaded=()=>{this.loadedAssets++};this.initAssetSpriteMap=(e=>function(){let t=e.assets,i=n.Sprite,o=new i(this);t[this.dataset.index]=o,o.setSpriteMap(Number(this.dataset.spriteWidth),Number(this.dataset.spriteHeight)),e.loadedAssets++})(this);this.gameLoop=()=>{if(!this.lastRun){this.lastRun=Date.now(),this.requestFrame(this.gameLoop);return}this.delta=(Date.now()-this.lastRun)/1e3,this.lastRun=Date.now(),this.fps=1/this.delta,this.runSpeed=Math.round(this.fps/60*100)/100,this.ctx.clearRect(0,0,this.width,this.height),this.canvas.style.cursor="default",this.drawRect(0,0,this.width,this.height),this.setFillColor(this.backgroundColor),this.fill(),this.state=="startup"?this.startup():this.states[this.state](),this.showFPS&&this.drawFPS(),this.gameRunning&&!n.error&&this.requestFrame(this.gameLoop)};this.width=e,this.height=t,this.contruct()}getMouseCords(e){let t=e;if(t.clientX===void 0){let a=e;a.touches&&a.touches[0]?t=a.touches[0]:a.changedTouches&&a.changedTouches[0]&&(t=a.changedTouches[0])}let i=this.canvas.getBoundingClientRect(),o=this.canvas.scrollWidth/this.width,r=this.canvas.scrollHeight/this.height;this.mouseX=(t.clientX-i.left)/o,this.mouseY=(t.clientY-i.top)/r}updateScale(){this.scale=window.devicePixelRatio*this.fitScale,this.canvas.width=this.width*this.scale,this.canvas.height=this.height*this.scale,this.ctx.scale(this.scale,this.scale)}updateFitScale(){this.width/this.height>window.innerWidth/window.innerHeight?this.fitScale=window.innerWidth/this.width:this.fitScale=window.innerHeight/this.height;let e=this.width*this.fitScale+"px",t=this.height*this.fitScale+"px";this.canvas.style.width=e,this.canvas.style.height=t;let i=n.container;i.style.width=e,i.style.height=t}contruct(){document.body.style.background="#333";let e=document.createElement("div");e.style.position="relative",e.style.display="block",e.style.margin="auto",n.container=e,n.gameObject=this,document.body.appendChild(e),this.canvas=document.createElement("canvas"),e.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this.canvas.style.display="block",this.canvas.style.margin="auto",this._resize(),window.addEventListener("resize",this._resize,!1),this.ctx.imageSmoothingEnabled=!1}init(){this.assetsLoaded||this.loadAssets(),this._resize(),this.canvas.addEventListener("click",this.click,!1),this.canvas.addEventListener("mousedown",this.mousedown,!1),this.canvas.addEventListener("mouseup",this.mouseup,!1),this.canvas.addEventListener("touchstart",this._touchstart,!1),this.canvas.addEventListener("touchend",this._touchend,!1),document.addEventListener("keydown",this.keydown,!1),document.addEventListener("keyup",this.keyup,!1),this.canvas.addEventListener("touchmove",this._mousetouchmove,!1),this.canvas.addEventListener("mousemove",this._mousetouchmove,!1),window.addEventListener("deviceorientation",this._deviceorientation),window.addEventListener("devicemotion",this._devicemotion)}loadAssets(){this.assetsToLoad=this.assets.length;let e=[],t=e;for(let i=0;i<this.assets.length;i++){let o=this.assets[i],r,a,d=null;if(typeof o=="string")a=o,r=a;else if(typeof o=="object"&&o!==null){let h=o;a=h.src,r=h.index,h.spriteMap!==void 0&&(d=h.spriteMap)}else{console.error("ASSETS - Unknown entry");continue}let c=this.getFileExtension(a);t[r]=null;let l;if(this.isImage(c))l=new Image;else if(this.isAudio(c))l=new Audio;else{console.error("ASSETS - Unknown file type: "+c+" for file "+a);continue}t[r]=l,l.dataset.index=r,d!==null&&(l.dataset.spriteWidth=String(d.width),l.dataset.spriteHeight=String(d.height)),l.onload=d!==null?this.initAssetSpriteMap:this.assetLoaded,l.src=a}this.assets=e,this.assetsLoaded=!0}getFileExtension(e){return/[.]/.exec(e)?/[^.]+$/.exec(e)[0]:void 0}isImage(e){return["jpg","jpeg","png","gif","xbm"].includes(e)}isAudio(e){return["mp3","wav","ogg","aac"].includes(e)}setFillColor(e){this.ctx.fillStyle=e}fill(){this.ctx.fill()}setStrokeColor(e){this.ctx.strokeStyle=e}stroke(){this.ctx.stroke()}drawLine(e,t,i,o,r){this.ctx.beginPath(),r&&(this.ctx.lineWidth=r),this.ctx.moveTo(e,t),this.ctx.lineTo(i,o),this.ctx.stroke(),this.ctx.closePath()}drawText(e,t,i){this.ctx.font=this.textSize+" "+this.font,this.ctx.fillText(e,t,i)}drawRect(e,t,i,o,r){let a=this.ctx;a.beginPath(),r?(a.moveTo(e+r,t),a.lineTo(e+i-r,t),a.quadraticCurveTo(e+i,t,e+i,t+r),a.lineTo(e+i,t+o-r),a.quadraticCurveTo(e+i,t+o,e+i-r,t+o),a.lineTo(e+r,t+o),a.quadraticCurveTo(e,t+o,e,t+o-r),a.lineTo(e,t+r),a.quadraticCurveTo(e,t,e+r,t)):a.rect(e,t,i,o),a.closePath()}drawCircle(e,t,i){this.ctx.beginPath(),this.ctx.arc(e,t,i,0,2*Math.PI),this.ctx.closePath()}drawImage(e,t,i,o=null,r=null){this.ctx.beginPath(),o!==null&&r!==null?this.ctx.drawImage(e,t,i,o,r):this.ctx.drawImage(e,t,i),this.ctx.closePath()}start(){this.gameRunning=!0,this.requestFrame(this.gameLoop)}stop(){this.gameRunning=!1}requestFrame(e){typeof window.requestAnimFrame=="function"?window.requestAnimFrame(e):requestAnimationFrame(e)}startup(){this.drawRect(0,0,this.width,this.height),this.setFillColor("#000"),this.fill(),this.ctx.font="25px Arial",this.ctx.textAlign="center",this.ctx.textBaseline="bottom",this.setFillColor("#fff"),this.ctx.fillText("Loading game",this.width/2,this.height/2-10),this.drawRect(this.width/2-100,this.height/2,200,20,10),this.setStrokeColor("#fff"),this.stroke();let e=200/this.assetsToLoad*this.loadedAssets;e<20&&(e=20),this.drawRect(this.width/2-100,this.height/2,e,20,10),this.setFillColor("#fff"),this.fill(),this.assetsToLoad==this.loadedAssets&&n.pageLoaded&&n.fontsLoaded&&(this._resize(),this.state=this.startState)}drawFPS(){this.ctx.fillStyle="gray",this.ctx.font="normal 16pt Arial",this.ctx.textAlign="left",this.ctx.textBaseline="top",this.ctx.fillText(Math.round(this.fps)+" fps - scale: "+this.scale,5,5)}};var f=class{constructor(e,t){this.x=e,this.y=t}get[Symbol.toStringTag](){return"THRUNIUM.Vector"}clone(){return new n.Vector(this.x,this.y)}equal(e){return this.x==e.x&&this.y==e.y}scale(e){this.x*=e,this.y*=e}scaleX(e){this.x*=e}scaleY(e){this.y*=e}add(e){this.x+=e.x,this.y+=e.y}addX(e){this.x+=e.x}addY(e){this.y+=e.y}subtract(e){this.x-=e.x,this.y-=e.y}subtractX(e){this.x-=e.x}subtractY(e){this.y-=e.y}divide(e){this.x/=e.x,this.y/=e.y}divideX(e){this.x/=e.x}divideY(e){this.y/=e.y}multiply(e){this.x*=e.x,this.y*=e.y}multiplyX(e){this.x*=e.x}multiplyY(e){this.y*=e.y}invert(){this.x*=-1,this.y*=-1}invertX(){this.x*=-1}invertY(){this.y*=-1}normalize(){let e=Math.sqrt(this.x*this.x+this.y*this.y);e!==0&&(this.x/=e,this.y/=e)}limit(e){this.x>e.x&&(this.x=e.x),this.y>e.y&&(this.y=e.y),this.x<e.x*-1&&(this.x=e.x*-1),this.y<e.y*-1&&(this.y=e.y*-1)}limitLength(e){}};var u={isCircle(s){return s.x!==void 0&&s.y!==void 0&&s.radius!==void 0},isRect(s){return s.x!==void 0&&s.y!==void 0&&s.width!==void 0&&s.height!==void 0},fixPos(s){return s.pos===void 0||s.pos.x===void 0&&s.pos.y===void 0||(s.x=s.pos.x,s.y=s.pos.y),s},rect(s,e){let t=u.fixPos(s),i=u.fixPos(e);if(!u.isRect(t)||!u.isRect(i))return m("One of the objects is not defined correctly as a rect"),!1;let[o,r,a,d]=[t.x,t.y,t.width,t.height],[c,l,h,T]=[i.x,i.y,i.width,i.height];return!(o+a/2<c-h/2||o-a/2>c+h/2||r+d/2<l-T/2||r-d/2>l+T/2)},circle(s,e){let t=u.fixPos(s),i=u.fixPos(e);if(!u.isCircle(t)||!u.isCircle(i))return m("One of the objects is not defined correctly as a circle"),!1;let o=t.x-i.x,r=t.y-i.y;return Math.sqrt(o*o+r*r)<t.radius+i.radius},circleRect(s,e){let t=u.fixPos(s),i=u.fixPos(e);if(!u.isCircle(t)||!u.isRect(i))return m("One of the objects is not defined correctly as a circle or rect"),!1;let o=Math.abs(t.x-i.x),r=Math.abs(t.y-i.y),a=i.width/2,d=i.height/2,c=t.radius;if(o>=a+c||r>=d+c)return!1;if(o<a||r<d)return!0;let l=o-a,h=r-d;return l*l+h*h<=c*c}};var P=()=>n.gameObject,q;q=Symbol.toStringTag;var g=class{constructor(e){this[q]="THRUNIUM.Sprite";this.angle=0;this.currentSprite=null;this.animTimeDur=100;this.frameTimeLast=0;this.animLoop=!1;this.animCallback=()=>{};this.image=e,this.fullWidth=e.width,this.fullHeight=e.height,this.spriteWidth=e.width,this.spriteHeight=e.height}setAngle(e){this.angle=e}setLoop(e){this.animLoop=e}setAnimCallback(e){this.animCallback=e}setAnimTime(e){this.animTimeDur=e}setSpriteMap(e,t){this.spriteWidth=e,this.spriteHeight=t}draw(e=0,t,i,o,r){let a=e*this.spriteWidth%this.fullWidth,d=Math.floor(e*this.spriteWidth/this.fullWidth)*this.spriteHeight,c=o===void 0?this.spriteWidth:o,l=r===void 0?this.spriteHeight:r,h=P().ctx;h.beginPath(),h.save(),h.translate(t,i),h.rotate(this.angle*Math.PI/180),h.drawImage(this.image,a,d,this.spriteWidth,this.spriteHeight,-c/2,-l/2,c,l),h.restore(),h.closePath()}drawAnim(e,t,i,o,r,a){var l;this.currentSprite==null&&(this.currentSprite=e);let d=this.animTimeDur/(t-e+1),c=Date.now();c-this.frameTimeLast>d&&(this.currentSprite<t?this.currentSprite++:this.animLoop?this.currentSprite=e:(this.currentSprite=null,this.animCallback()),this.frameTimeLast=c),this.draw((l=this.currentSprite)!=null?l:void 0,i,o,r,a)}};var w=()=>n.gameObject,v=class{constructor(e,t,i){this.style={};this.hoverStyle={};this.hoverOverrides={};this._tag="THRUNIUM.Elem."+e,this.x=t,this.y=i,this.elem=document.createElement(e),this.elem.addEventListener("mouseenter",()=>this.updateStyle(this.hoverStyle),!1),this.elem.addEventListener("mouseleave",()=>this.updateStyle(this.style),!1),this.setStyle("display","block"),this.setStyle("position","absolute"),this.setStyle("color","#000"),this.setStyle("backgroundColor","#fff"),this.setStyle("fontFamily",w().font),this.setStyle("borderRadius","5px"),this.resize(),S.elemsList.push(this),n.container.appendChild(this.elem)}get[Symbol.toStringTag](){return this._tag}setPos(e,t){this.x=e,this.y=t,this.resize()}resize(){let e=w().fitScale;this.setStyle("left",this.x*e+"px"),this.setStyle("top",this.y*e+"px"),this.setStyle("transformOrigin","top left"),this.setStyle("transform","scale("+e+")")}addEventListener(e,t,i){this.elem.addEventListener(e,t,i)}updateStyle(e){for(let t in e)this.elem.style[t]=e[t]}setStyle(e,t){this.style[e]=t,this.hoverOverrides[e]||(this.hoverStyle[e]=t),this.updateStyle(this.style)}setHoverStyle(e,t){this.hoverStyle[e]=t,this.hoverOverrides[e]=!0}show(){this.setStyle("display","block")}hide(){this.setStyle("display","none")}};function F(s,e,t){let i=new v("button",e,t);return i.elem.textContent=s,i.elem.style.border="none",i}function O(s,e,t){let i=w(),o=document.createElement("input");return o.style.position="absolute",o.style.left=s*i.scale*i.fitScale+"px",o.style.top=e*i.scale*i.fitScale+"px",o.style.border="2px solid #000",o.style.borderRadius="5px",o.style.color="#000",o.style.backgroundColor="#fff",o.style.fontFamily=i.font,o.style.fontSize=i.textSize,o.type=t.type?t.type:"text",t.placeholder&&(o.placeholder=t.placeholder),n.container.appendChild(o),o}var S={elemsList:[],Elem:v,Button:F,Input:O};function y(s){var r,a,d,c;let e=(r=s.success)!=null?r:(l=>console.log(l)),t=(a=s.error)!=null?a:(()=>{}),i=(d=s.contentType)!=null?d:"application/x-www-form-urlencoded",o=new XMLHttpRequest;return o.withCredentials=(c=s.withCredentials)!=null?c:!1,o.onreadystatechange=function(){o.readyState===4&&(o.status===200?e(o):t(o))},o.open(s.type,s.url,!0),i!==!1&&o.setRequestHeader("Content-Type",i),o.send(s.data),o}function I(s){return s.replace(/[%;\x00-\x1f\x7f]/g,encodeURIComponent).replace(/^ +| +$/g,e=>e.replace(/ /g,"%20"))}function z(s,e){let t=new Date;t.setTime(t.getTime()+365*24*60*60*1e3);let i="expires="+t.toUTCString();return document.cookie=s+"="+I(String(e))+";"+i+";path="+document.location.pathname,!0}function j(s){let e=s+"=";for(let t of document.cookie.split(";"))if(t=t.replace(/^ +/,""),t.indexOf(e)===0){let i=t.substring(e.length);try{return decodeURIComponent(i)}catch(o){return i}}return null}var A={set:z,get:j};var k={};_(k,{_options:()=>G,_receiveMessage:()=>B,accessRequested:()=>D,loginPopup:()=>W,reqToken:()=>V,reqUserToken:()=>Y,request:()=>K,setReqToken:()=>N,timeout:()=>X,userToken:()=>U});var V=null,U=null,X=null,W=null,D=!1,G={succes:s=>console.log(s),error:s=>console.log(s)};function N(s){n.Storage.reqToken=s}function Y(s){n.Storage._options.succes=s.succes,n.Storage._options.error=s.error,y({url:"https://api.thrungames.com/request/user-token",type:"post",data:"requestToken="+n.Storage.reqToken,succes:function(e){var i,o,r,a;let t=JSON.parse(e.response);t.access=="0"&&!n.Storage.accessRequested?(window.addEventListener("message",n.Storage._receiveMessage,!1),window.parent.postMessage({reqToken:n.Storage.reqToken},document.origin),n.Storage.timeout=setTimeout(function(){let d=screen.width?(screen.width-400)/2:0,l="height=500,width=400,top="+(screen.height?(screen.height-500)/2:0)+",left="+d+",scrollbars=yes,resizable",h="https://api.thrungames.com/user/access?token="+n.Storage.reqToken;n.Storage.loginPopup=window.open(h,"Approval of game",l)},200)):t.access=="1"?(n.Storage.userToken=window.event.data.userToken,(o=(i=n.Storage._options).succes)==null||o.call(i,{type:"userAccepted",event:e})):(a=(r=n.Storage._options).error)==null||a.call(r,{type:"ajaxFailed",event:e})},error:function(e){var t,i;(i=(t=n.Storage._options).error)==null||i.call(t,{type:"ajaxFailed",event:e})}})}function B(s){var t,i,o;let e=window.event;e.origin!=="https://www.thrungames.com/"&&e.origin!=="https://www.thrungames.com/"||(clearTimeout((t=n.Storage.timeout)!=null?t:void 0),n.Storage.accessRequested=!0,e.data.state==1?n.Storage.reqUserToken(n.Storage._options):(o=(i=n.Storage._options).error)==null||o.call(i,{type:"userRejected",event:s}))}function K(s){}n.version="1.2.0-rc.2";n.pageLoad=b;n.ready=x;n.throwError=m;n.mobileAndTabletcheck=E;n.iOScheck=L;n.getRandom=R;M();n.Game=p;n.Vector=f;n.Collider=Object.assign(n.Collider||{},u);n.Sprite=g;n.Elem=Object.assign(n.Elem||{},S);n.ajax=y;n.Storage=Object.assign(n.Storage||{},A,k);window.requestAnimFrame=typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame.bind(window):s=>window.setTimeout(()=>s(Date.now()),1e3/60);})();
1
+ /*! THRUNIUM v1.2.0-rc.4 | (c) Infobits ApS | MIT License */
2
+ "use strict";(()=>{var be=Object.defineProperty,Be=Object.defineProperties;var je=Object.getOwnPropertyDescriptors;var ge=Object.getOwnPropertySymbols;var Oe=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ye=i=>{throw TypeError(i)};var ve=(i,e,t)=>e in i?be(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,we=(i,e)=>{for(var t in e||(e={}))Oe.call(e,t)&&ve(i,t,e[t]);if(ge)for(var t of ge(e))Pe.call(e,t)&&ve(i,t,e[t]);return i},xe=(i,e)=>Be(i,je(e));var De=(i,e)=>{for(var t in e)be(i,t,{get:e[t],enumerable:!0})};var Q=(i,e,t)=>e.has(i)||ye("Cannot "+t);var c=(i,e,t)=>(Q(i,e,"read from private field"),t?t.call(i):e.get(i)),x=(i,e,t)=>e.has(i)?ye("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),M=(i,e,t,s)=>(Q(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t),Z=(i,e,t)=>(Q(i,e,"access private method"),t);window.THRUNIUM||(window.THRUNIUM={});var a=window.THRUNIUM;function ee(){a.pageLoaded=!0}function te(i){let e=!1,t=()=>{e||(e=!0,i())};if(document.readyState==="complete"){t();return}document.addEventListener("DOMContentLoaded",t,!1),window.addEventListener("load",t,!1)}function A(i){console.error(i),a.error=!0}function Se(){let i=navigator.userAgent||navigator.vendor||"";return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(i)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(i.substr(0,4))}function Te(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!("MSStream"in window)}function ke(i,e,t=!1){return t?Math.random()*(e-i)+i:Math.floor(Math.random()*(e-i+1))+i}function Ee(){a.container=null,a.gameObject=null,a.error=!1,a.pageLoaded=!1,a.fontsLoaded=!1,te(ee),typeof document!="undefined"&&document.fonts&&document.fonts.ready?document.fonts.ready.then(()=>{a.fontsLoaded=!0}):a.fontsLoaded=!0}var P=class{constructor(){this.down=new Set;this.pressed=new Set;this.released=new Set}get held(){return this.down}press(e){this.down.has(e)||(this.down.add(e),this.pressed.add(e))}release(e){this.down.delete(e)&&this.released.add(e)}releaseAll(){for(let e of[...this.down])this.release(e)}endFrame(){this.pressed.clear(),this.released.clear()}},D=class extends P{isDown(e){return this.held.has(e)}wasPressed(e){return this.pressed.has(e)}wasReleased(e){return this.released.has(e)}},U=class extends P{constructor(){super(...arguments);this.x=0;this.y=0}isDown(t=0){return this.held.has(t)}wasPressed(t=0){return this.pressed.has(t)}wasReleased(t=0){return this.released.has(t)}};var $=class{constructor(e,t,s,n,o){this.timers=e;this.due=t;this.interval=s;this.fn=n;this.owner=o;this.scheduled=!0}get active(){return this.scheduled}cancel(){this.timers.remove(this)}},G=class{constructor(){this.now=0;this.list=[]}after(e,t,s){return this.add(new $(this,this.now+e,null,t,s))}every(e,t,s){return this.add(new $(this,this.now+e,e,t,s))}advance(e){this.now+=e;for(let t of this.list.slice())!t.scheduled||t.due>this.now||(t.interval===null?this.remove(t):t.interval>0?(t.due+=(Math.floor((this.now-t.due)/t.interval)+1)*t.interval,t.due<=this.now&&(t.due=this.now+t.interval)):t.due=this.now,t.fn())}cancelOwner(e){this.list=this.list.filter(t=>t.owner!==e?!0:(t.scheduled=!1,!1))}get count(){return this.list.length}remove(e){e.scheduled&&(e.scheduled=!1,this.list.splice(this.list.indexOf(e),1))}add(e){return this.list.push(e),e}};function Ue(i){var s;let e=(s=i.split("?")[1])!=null?s:"",t=[];for(let n of e.split("&")){if(!n.startsWith("family="))continue;let o=decodeURIComponent(n.slice(7).split(":")[0].replace(/\+/g," "));o&&t.push(o)}return t}function Le(i,e,t,s=!1){let n=0,o=[],r=[],d=(l,u)=>{r.push(Promise.allSettled(u).then(p=>{for(let m of p)m.status==="rejected"&&console.warn(`Font "${l}" failed to load; using the fallback font.`,m.reason);n++}))},h=(l,u,p)=>{let m=new FontFace(l,`url(${u})`,p);return m.load().then(()=>(document.fonts.add(m),m))};for(let l of i){if(typeof l=="object"&&"family"in l){o.push({family:l.family,source:"file"}),d(l.family,[h(l.family,l.src,{weight:l.weight,style:l.style})]);continue}let u=typeof l=="string"?l:l.url,p=typeof l=="object"&&l.cdn===!0,m=p||e==null?void 0:e[u],b=Ue(u);if(m){for(let f of m)o.push({family:f.family,source:"bundled"});d(b.join(", ")||u,m.map(f=>h(f.family,f.src,{weight:f.weight,style:f.style,unicodeRange:f.unicodeRange})));continue}!p&&t&&console.warn(s?`Font ${u} is loaded from Google; thrunium dev could not download it or did not find it in the bundle.`:`Font ${u} is loaded from Google; it was not found when the game was built.`);for(let f of b)o.push({family:f,source:"google"});let g=document.createElement("link");g.rel="stylesheet",g.href=u;let v=new Promise((f,L)=>{g.addEventListener("load",()=>f()),g.addEventListener("error",()=>L(new Error(`could not load ${u}`)))});document.head.appendChild(g);let S=v.then(()=>Promise.all(b.map(f=>document.fonts.load(`1em "${f}"`).then(L=>{if(L.length===0)throw new Error(`no font face found for "${f}"`)}))));d(b.join(", ")||u,[S])}return{total:i.length,loaded:()=>n,done:Promise.all(r).then(()=>{}),sources:o}}var Me=new WeakMap;function Re(i,e){Me.set(i,e)}function C(i){let e=Me.get(i);if(!e)throw new Error("THRUNIUM: not a Game made by this engine.");return e}var _e=120,$e=250,Ge=50,Ae=30,z=class{constructor(e){this.visible=!0;this.watches=new Map;this.frameTimes=[];this.lastFrame=0;this.lastText=-1/0;this.root=null;this.game=e}get enabled(){var e;return(e=this.override)!=null?e:typeof window!="undefined"&&window.THRUNIUM_DEV===!0}set enabled(e){this.override=e}watch(e,t){this.watches.set(e,t),this.lastText=-1/0}unwatch(e){this.watches.delete(e),this.lastText=-1/0}update(){var s;if(!this.enabled){this.remove();return}C(this.game).keys.wasPressed("Backquote")&&(this.visible=!this.visible);let e=performance.now();this.lastFrame&&this.frameTimes.push(e-this.lastFrame),this.frameTimes.length>_e&&this.frameTimes.shift(),this.lastFrame=e;let t=(s=this.root)!=null?s:this.build();t.style.display=this.visible?"block":"none",this.visible&&(this.drawGraph(),this.stepButton.style.display=this.game.paused?"inline-block":"none",this.pauseButton.textContent=this.game.paused?"resume":"pause",this.pauseButton.title=this.game.paused?"Resume scenes and timers":"Pause scenes and timers",e-this.lastText>=$e&&(this.lastText=e,this.info.textContent=this.lines().join(`
3
+ `)))}remove(){var e;(e=this.root)==null||e.remove(),this.root=null,this.frameTimes=[],this.lastFrame=0}build(){let e=document.createElement("div");e.id="thrunium-debug",e.style.cssText="position:fixed;left:0;top:0;z-index:2147483646;padding:6px;margin:0;pointer-events:none;background:rgba(0,0,0,0.7);color:#fff;font:11px/1.3 ui-monospace,Menlo,Consolas,monospace;",this.graph=document.createElement("div"),this.graph.style.cssText=`display:flex;align-items:flex-end;width:${_e}px;height:${Ae}px;margin-bottom:4px;`,this.info=document.createElement("pre"),this.info.style.cssText="margin:0;font:inherit;white-space:pre;";let t=document.createElement("div");return t.style.cssText="margin-top:4px;",this.pauseButton=this.makeButton("pause","Pause scenes and timers",()=>{this.game.paused=!this.game.paused,this.lastText=-1/0}),this.stepButton=this.makeButton("step","Run scenes and timers for one frame (1/60 s)",()=>{this.game.stepOnce=!0}),this.stepButton.style.display="none",t.append(this.pauseButton,this.stepButton),e.append(this.graph,this.info,t),document.body.appendChild(e),this.root=e,e}makeButton(e,t,s){let n=document.createElement("button");return n.type="button",n.textContent=e,n.title=t,n.style.cssText="pointer-events:auto;margin-right:4px;font:inherit;padding:1px 6px;cursor:pointer;",n.addEventListener("mousedown",o=>o.preventDefault()),n.addEventListener("click",()=>{s(),n.blur()}),n}drawGraph(){let e=this.graph.children;for(;e.length<this.frameTimes.length;){let t=document.createElement("div");t.setAttribute("data-bar",""),t.style.cssText="width:1px;background:#6f6;",this.graph.appendChild(t)}this.frameTimes.forEach((t,s)=>{let n=e[s];n.style.height=`${Math.max(1,Math.min(t/Ge,1)*Ae)}px`,n.style.background=t>33?"#f66":"#6f6"})}lines(){var h;let e=this.game,t=C(e),s=l=>l.toFixed(2),n=e.state,o=typeof e.states[n]=="object"?"scene":"function",r=((h=e.fontStatus)==null?void 0:h.sources.map(l=>`${l.family} (${l.source})`).join(", "))||"none",d=[`${Math.round(e.fps)} fps`,`state: ${n} (${o})`,`paused: ${e.paused} dt: ${s(t.dt())} speed: ${s(e.runSpeed)} time: ${s(t.time())}`,`timers: ${e.timerCount}`,`assets: ${e.loadedAssets}/${e.assetsToLoad}${e.failedAssets>0?`, failed ${e.failedAssets}`:""}`,`fonts: ${r}`,`mouse: ${Math.round(e.mouseX)}, ${Math.round(e.mouseY)} buttons: ${[...t.mouse.held].join(",")||"-"}`,`keys: ${[...t.keys.held].join(",")||"-"}`,`canvas: ${e.width}x${e.height} scale: ${s(e.scale)}`,"thrunium 1.2.0-rc.4"];for(let[l,u]of this.watches){let p;try{p=String(u())}catch(m){p="(error)"}d.push(`${l}: ${p}`)}return d}};var ze=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]);function Xe(i){let e=i.trim();return/^(["']).*\1$/.test(e)||e.includes(",")||ze.has(e.toLowerCase())?i:'"'+e.replace(/[\\"]/g,"\\$&")+'"'}function X(i,e,t){let s=typeof e=="number"?e+"px":e;return(i?i+" ":"")+s+" "+Xe(t)}var F=class{constructor(e,t,s,n,o,r={}){this.box={left:0,top:0,right:0,bottom:0};this.game=e,this.drawn=t,this.text=s,this.x=n,this.y=o,this.options=r}get hovered(){if(!this.drawn.previous.has(this))return!1;let{x:e,y:t}=C(this.game).mouse,s=this.box;return e>=s.left&&e<=s.right&&t>=s.top&&t<=s.bottom}get clicked(){return this.hovered&&C(this.game).mouse.wasReleased(0)}draw(){var n;let e=this.game,t=this.options;this.measure(),this.drawn.current.add(this);let s=this.hovered;e.drawText(this.text,this.x,this.y,s&&t.hoverColor?xe(we({},t),{color:t.hoverColor}):t),s&&(e.canvas.style.cursor="pointer",(n=t.onHover)==null||n.call(t,this))}measure(){var m,b,g,v,S;let{ctx:e}=this.game,t=this.options,s=(m=t.padding)!=null?m:8,n=(b=t.size)!=null?b:this.game.textSize,o=(g=t.baseline)!=null?g:"alphabetic";e.save(),e.font=X(t.weight,n,(v=t.font)!=null?v:this.game.font),t.baseline&&(e.textBaseline=t.baseline);let r=e.measureText(this.text);e.restore();let d=r.width,h=(S=t.align)!=null?S:"left",l=h==="center"?this.x-d/2:h==="right"||h==="end"?this.x-d:this.x,u,p;if(typeof r.actualBoundingBoxAscent=="number"&&typeof r.actualBoundingBoxDescent=="number")u=this.y-r.actualBoundingBoxAscent,p=this.y+r.actualBoundingBoxDescent;else if(typeof r.fontBoundingBoxAscent=="number"&&typeof r.fontBoundingBoxDescent=="number")u=this.y-r.fontBoundingBoxAscent,p=this.y+r.fontBoundingBoxDescent;else{let f=typeof n=="number"?n:parseFloat(n)||0;u=o==="middle"?this.y-f/2:o==="top"||o==="hanging"?this.y:this.y-f,p=u+f}this.box={left:l-s,top:u-s,right:l+d+s,bottom:p+s}}};var Ce,T,w,q,E,B,H,k,R,_,I,Fe,He;Ce=Symbol.toStringTag;var V=class{constructor(e,t){x(this,I);this[Ce]="THRUNIUM.Game";x(this,T,new D);x(this,w,new U);x(this,q,new z(this));x(this,E,new G);x(this,B,{current:new Set,previous:new Set});x(this,H,0);x(this,k,0);x(this,R,0);x(this,_,0);this.scale=1;this.fitScale=1;this.delta=0;this.dt=0;this.time=0;this.fps=0;this.runSpeed=1;this.lastRun=null;this.gameRunning=!1;this.showFPS=!1;this.debug=c(this,q);this.namespace="";this.mouseX=0;this.mouseY=0;this.keys=c(this,T);this.mouse=c(this,w);this._loadedIndexes=new Set;this._requestedState="startup";this._runningState="startup";this._scene=null;this.startState=null;this.states=[];this.paused=!1;this.stepOnce=!1;this.backgroundColor="#fff";this.assets=[];this.fonts=[];this.fontStatus=null;this.assetsLoaded=!1;this.loadedAssets=0;this.assetsToLoad=0;this._failedIndexes=new Set;this.font="Arial";this.textSize="30px";this.click=()=>{};this.mousedown=()=>{};this.mouseup=()=>{};this.mousemove=()=>{};this.touch=()=>{};this.touchstart=()=>{};this.touchend=()=>{};this.keydown=()=>{};this.keyup=()=>{};this.deviceorientation=()=>{};this.devicemotion=()=>{};this.rezise=()=>{};this._deviceorientation=e=>{this.deviceorientation(e)};this._devicemotion=e=>{this.devicemotion(e)};this._mousetouchmove=e=>{e.preventDefault(),this.getMouseCords(e),this.mousemove(e)};this._touchstart=e=>{e.preventDefault(),this.getMouseCords(e),this.touch(e),this.touchstart(e)};this._touchend=e=>{e.preventDefault(),this.getMouseCords(e),this.click(e),this.touchend(e)};this._resize=e=>{var s,n;this.updateFitScale(),this.updateScale();let t=(n=(s=a.Elem)==null?void 0:s.elemsList)!=null?n:[];for(let o=0;o<t.length;o++)t[o].resize();this.rezise(e)};this._keysDown=e=>{c(this,T).press(e.code)};this._keysUp=e=>{c(this,T).release(e.code)};this._mouseDown=e=>{c(this,w).press(e.button)};this._mouseUp=e=>{c(this,w).release(e.button)};this._mouseTouchDown=e=>{this.getMouseCords(e),c(this,w).press(0)};this._mouseTouchUp=e=>{this.getMouseCords(e),c(this,w).release(0)};this._releaseAllInput=()=>{c(this,T).releaseAll(),c(this,w).releaseAll()};this.assetLoaded=()=>{this.loadedAssets++};this.initAssetSpriteMap=(e=>function(){let t=e.assets,s=a.Sprite,n=new s(this);t[this.dataset.index]=n,n.setSpriteMap(Number(this.dataset.spriteWidth),Number(this.dataset.spriteHeight)),e.loadedAssets++})(this);this.gameLoop=()=>{if(!this.lastRun){this.lastRun=Date.now(),this.requestFrame(this.gameLoop);return}this.delta=(Date.now()-this.lastRun)/1e3,this.lastRun=Date.now(),this.fps=1/this.delta,this.runSpeed=Math.round(this.fps/60*100)/100,M(this,k,Math.min(this.delta,.1)),Z(this,I,He).call(this),this.switchState(),this.ctx.clearRect(0,0,this.width,this.height),this.canvas.style.cursor="default",this.drawRect(0,0,this.width,this.height),this.setFillColor(this.backgroundColor),this.fill(),this.runState(),this.showFPS&&this.drawFPS(),c(this,q).update(),this.endFrame(),this.gameRunning&&!a.error&&this.requestFrame(this.gameLoop)};this.width=e,this.height=t,Re(this,{keys:c(this,T),mouse:c(this,w),time:()=>c(this,H),dt:()=>c(this,k)}),this.contruct()}get state(){return this._requestedState}set state(e){this._requestedState=e}get failedAssets(){return this._failedIndexes.size}getMouseCords(e){let t=e;if(t.clientX===void 0){let r=e;r.touches&&r.touches[0]?t=r.touches[0]:r.changedTouches&&r.changedTouches[0]&&(t=r.changedTouches[0])}let s=this.canvas.getBoundingClientRect(),n=this.canvas.scrollWidth/this.width,o=this.canvas.scrollHeight/this.height;this.mouseX=(t.clientX-s.left)/n,this.mouseY=(t.clientY-s.top)/o,c(this,w).x=this.mouseX,c(this,w).y=this.mouseY}updateScale(){this.scale=window.devicePixelRatio*this.fitScale,this.canvas.width=this.width*this.scale,this.canvas.height=this.height*this.scale,this.ctx.scale(this.scale,this.scale)}updateFitScale(){this.width/this.height>window.innerWidth/window.innerHeight?this.fitScale=window.innerWidth/this.width:this.fitScale=window.innerHeight/this.height;let e=this.width*this.fitScale+"px",t=this.height*this.fitScale+"px";this.canvas.style.width=e,this.canvas.style.height=t;let s=a.container;s.style.width=e,s.style.height=t}contruct(){let e=getComputedStyle(document.body);!["","transparent","rgba(0, 0, 0, 0)"].includes(e.backgroundColor)||!["","none"].includes(e.backgroundImage)||(document.body.style.background="#333");let s=document.createElement("div");s.style.position="relative",s.style.display="block",s.style.margin="auto",a.container=s,a.gameObject=this,document.body.appendChild(s),this.canvas=document.createElement("canvas"),s.appendChild(this.canvas),this.ctx=this.canvas.getContext("2d"),this.canvas.style.display="block",this.canvas.style.margin="auto",this._resize(),window.addEventListener("resize",this._resize,!1),this.ctx.imageSmoothingEnabled=!1}init(){this.assetsLoaded||this.loadAssets();let e=Array.isArray(this.fonts)?this.fonts:[];this.fontStatus=Le(e,window.THRUNIUM_FONTS,window.THRUNIUM_FONTS!==void 0,window.THRUNIUM_DEV===!0),this._resize(),this.canvas.addEventListener("click",this.click,!1),this.canvas.addEventListener("mousedown",this.mousedown,!1),this.canvas.addEventListener("mouseup",this.mouseup,!1),this.canvas.addEventListener("touchstart",this._touchstart,!1),this.canvas.addEventListener("touchend",this._touchend,!1),document.addEventListener("keydown",this.keydown,!1),document.addEventListener("keyup",this.keyup,!1),this.canvas.addEventListener("touchmove",this._mousetouchmove,!1),this.canvas.addEventListener("mousemove",this._mousetouchmove,!1),window.addEventListener("deviceorientation",this._deviceorientation),window.addEventListener("devicemotion",this._devicemotion),document.addEventListener("keydown",this._keysDown,!1),document.addEventListener("keyup",this._keysUp,!1),this.canvas.addEventListener("mousedown",this._mouseDown,!1),this.canvas.addEventListener("mouseup",this._mouseUp,!1),window.addEventListener("mouseup",this._mouseUp,!1),this.canvas.addEventListener("touchstart",this._mouseTouchDown,!1),this.canvas.addEventListener("touchend",this._mouseTouchUp,!1),this.canvas.addEventListener("touchcancel",this._mouseTouchUp,!1),window.addEventListener("blur",this._releaseAllInput)}endFrameInput(){c(this,T).endFrame(),c(this,w).endFrame()}loadAssets(){this.assetsToLoad=this.assets.length,this._loadedIndexes.clear(),this._failedIndexes.clear();let e=[],t=e;for(let s=0;s<this.assets.length;s++){let n=this.assets[s],o,r,d=null;if(typeof n=="string")r=n,o=r;else if(typeof n=="object"&&n!==null){let v=n;r=v.src,o=v.index,v.spriteMap!==void 0&&(d=v.spriteMap)}else{console.error("ASSETS - Unknown entry");continue}let h=this.getFileExtension(r);t[o]=null;let l;if(this.isImage(h))l=new Image;else if(this.isAudio(h))l=new Audio;else{console.error("ASSETS - Unknown file type: "+h+" for file "+r);continue}t[o]=l,l.dataset.index=o,d!==null&&(l.dataset.spriteWidth=String(d.width),l.dataset.spriteHeight=String(d.height));let u=d!==null?this.initAssetSpriteMap:this.assetLoaded,p=this._loadedIndexes,m=!1,b=function(){m||(m=!0,p.add(o),u.call(this))};l.onload=b,l instanceof HTMLAudioElement&&(l.preload="auto",l.addEventListener("canplaythrough",b),l.addEventListener("loadeddata",b));let g=this._failedIndexes;l.onerror=()=>{g.add(o)},l.src=r}this.assets=e,this.assetsLoaded=!0}_getAsset(e,t){let s=this.assets,n=Object.keys(s).filter(l=>s[l]!==null&&s[l]!==void 0),o=Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0;if(o==null)throw new Error('No asset "'+e+'". Loaded assets: '+(n.length>0?n.join(", "):"(none)")+".");if(this._failedIndexes.has(e))throw new Error('Asset "'+e+'" failed to load. Check that the file exists and the path is right.');if(!this._loadedIndexes.has(e))throw new Error('Asset "'+e+'" is still loading. Use it from a state that runs after the loading screen.');let r=a.Sprite!==void 0&&o instanceof a.Sprite,d=!r&&o instanceof HTMLImageElement,h=o instanceof HTMLAudioElement;if(t==="image"&&r)throw new Error('Asset "'+e+'" is a sprite map, not an image. Use game.sprite("'+e+'").');if(t==="image"&&!d)throw new Error('Asset "'+e+'" is not an image.');if(t==="sound"&&!h)throw new Error('Asset "'+e+'" is not a sound.');if(t==="sprite"&&!r)throw new Error('Asset "'+e+'" is not a sprite. Give its assets entry a spriteMap to get a sprite.');return o}image(e){return this._getAsset(e,"image")}sound(e){return this._getAsset(e,"sound")}sprite(e){return this._getAsset(e,"sprite")}getFileExtension(e){return/[.]/.exec(e)?/[^.]+$/.exec(e)[0]:void 0}isImage(e){return["jpg","jpeg","png","gif","xbm"].includes(e)}isAudio(e){return["mp3","wav","ogg","aac"].includes(e)}setFillColor(e){this.ctx.fillStyle=e}fill(){this.ctx.fill()}setStrokeColor(e){this.ctx.strokeStyle=e}stroke(){this.ctx.stroke()}drawLine(e,t,s,n,o){this.ctx.beginPath(),o&&(this.ctx.lineWidth=o),this.ctx.moveTo(e,t),this.ctx.lineTo(s,n),this.ctx.stroke(),this.ctx.closePath()}drawText(e,t,s,n){var r,d;if(!n){this.ctx.font=this.textSize+" "+this.font,this.ctx.fillText(e,t,s);return}let o=this.ctx;o.save(),o.font=X(n.weight,(r=n.size)!=null?r:this.textSize,(d=n.font)!=null?d:this.font),n.align&&(o.textAlign=n.align),n.baseline&&(o.textBaseline=n.baseline),n.color&&(o.fillStyle=n.color),o.fillText(e,t,s),o.restore()}drawRect(e,t,s,n,o){let r=this.ctx;r.beginPath(),o?(r.moveTo(e+o,t),r.lineTo(e+s-o,t),r.quadraticCurveTo(e+s,t,e+s,t+o),r.lineTo(e+s,t+n-o),r.quadraticCurveTo(e+s,t+n,e+s-o,t+n),r.lineTo(e+o,t+n),r.quadraticCurveTo(e,t+n,e,t+n-o),r.lineTo(e,t+o),r.quadraticCurveTo(e,t,e+o,t)):r.rect(e,t,s,n),r.closePath()}drawCircle(e,t,s){this.ctx.beginPath(),this.ctx.arc(e,t,s,0,2*Math.PI),this.ctx.closePath()}drawImage(e,t,s,n=null,o=null){var oe,re,ae,le,de,ue,he,ce,me;let r=this.ctx,d=typeof n=="object"&&n!==null?n:null,h=d?(oe=d.width)!=null?oe:null:n,l=d?(re=d.height)!=null?re:null:o,u=a.Sprite&&e instanceof a.Sprite?e:null,p=u?u.image:e,m=u?u.frameRect():null;if(!d&&!m){r.beginPath(),h!==null&&l!==null?r.drawImage(p,t,s,h,l):r.drawImage(p,t,s),r.closePath();return}let b=p,g=(le=(ae=h!=null?h:m==null?void 0:m.sw)!=null?ae:b.width)!=null?le:0,v=(ue=(de=l!=null?l:m==null?void 0:m.sh)!=null?de:b.height)!=null?ue:0,S=(pe,fe)=>{m?r.drawImage(p,m.sx,m.sy,m.sw,m.sh,pe,fe,g,v):r.drawImage(p,pe,fe,g,v)},f=(d==null?void 0:d.anchor)==="center",L=(he=d==null?void 0:d.angle)!=null?he:0,J=d==null?void 0:d.alpha,j=(ce=d==null?void 0:d.flipX)!=null?ce:!1,O=(me=d==null?void 0:d.flipY)!=null?me:!1;if(!L&&J===void 0&&!j&&!O)return d&&f?S(t-g/2,s-v/2):S(t,s);r.save(),J!==void 0&&(r.globalAlpha=J),r.translate(t,s),L&&r.rotate(L),(j||O)&&r.scale(j?-1:1,O?-1:1),S(f?-g/2:j?-g:0,f?-v/2:O?-v:0),r.restore()}button(e,t,s,n){return new F(this,c(this,B),e,t,s,n)}after(e,t){return c(this,E).after(e,t,this._scene)}every(e,t){return c(this,E).every(e,t,this._scene)}get timerCount(){return c(this,E).count}start(){this.gameRunning=!0,this.requestFrame(this.gameLoop)}stop(){this.gameRunning=!1}requestFrame(e){typeof window.requestAnimFrame=="function"?window.requestAnimFrame(e):requestAnimationFrame(e)}startup(){var n,o,r,d;this.drawRect(0,0,this.width,this.height),this.setFillColor("#000"),this.fill(),this.ctx.font="25px Arial",this.ctx.textAlign="center",this.ctx.textBaseline="bottom",this.setFillColor("#fff"),this.ctx.fillText("Loading game",this.width/2,this.height/2-10),this.drawRect(this.width/2-100,this.height/2,200,20,10),this.setStrokeColor("#fff"),this.stroke();let e=(o=(n=this.fontStatus)==null?void 0:n.total)!=null?o:0,t=(d=(r=this.fontStatus)==null?void 0:r.loaded())!=null?d:0,s=200/(this.assetsToLoad+e)*(this.loadedAssets+t);s<20&&(s=20),this.drawRect(this.width/2-100,this.height/2,s,20,10),this.setFillColor("#fff"),this.fill(),this.assetsToLoad==this.loadedAssets&&e==t&&a.pageLoaded&&a.fontsLoaded&&(this._resize(),this.state=this.startState)}drawFPS(){this.ctx.fillStyle="gray",this.ctx.font="normal 16pt Arial",this.ctx.textAlign="left",this.ctx.textBaseline="top",this.ctx.fillText(Math.round(this.fps)+" fps - scale: "+this.scale,5,5)}stateNamed(e){let t=this.states[e];if(typeof t!="function"&&(typeof t!="object"||t===null))throw new Error('Unknown state "'+e+'". Known states: '+Object.keys(this.states).join(", ")+".");return t}switchState(){var n,o;let e=this._requestedState;if(e===this._runningState)return;let t=e==="startup"?null:this.stateNamed(e),s=this._scene;s&&(this._scene=null,c(this,E).cancelOwner(s),(n=s.exit)==null||n.call(s)),this._runningState=e,t&&typeof t!="function"&&(this._scene=t,(o=t.enter)==null||o.call(t))}runState(){var s,n,o;let e=this._runningState,t=e==="startup"?null:this.stateNamed(e);if(t===null||typeof t=="function"){t?t.call(this.states):this.startup(),t&&!this.paused&&this.advanceTime(c(this,k)),this.stepOnce=!1;return}this.paused?this.stepOnce&&((n=t.update)==null||n.call(t,1/60),this.advanceTime(1/60)):((s=t.update)==null||s.call(t,c(this,k)),this.advanceTime(c(this,k))),this.stepOnce=!1,(o=t.draw)==null||o.call(t)}advanceTime(e){M(this,H,c(this,H)+e),Z(this,I,Fe).call(this),c(this,E).advance(e)}endFrame(){let e=c(this,B);[e.current,e.previous]=[e.previous,e.current],e.current.clear(),this.endFrameInput()}};T=new WeakMap,w=new WeakMap,q=new WeakMap,E=new WeakMap,B=new WeakMap,H=new WeakMap,k=new WeakMap,R=new WeakMap,_=new WeakMap,I=new WeakSet,Fe=function(){if(c(this,R)!==null){if(this.time!==c(this,R)){M(this,R,null);return}this.time=M(this,R,c(this,H))}},He=function(){if(c(this,_)!==null){if(this.dt!==c(this,_)){M(this,_,null);return}this.dt=M(this,_,c(this,k))}};var N=class{constructor(e,t){this.x=e,this.y=t}get[Symbol.toStringTag](){return"THRUNIUM.Vector"}clone(){return new a.Vector(this.x,this.y)}equal(e){return this.x==e.x&&this.y==e.y}scale(e){this.x*=e,this.y*=e}scaleX(e){this.x*=e}scaleY(e){this.y*=e}add(e){this.x+=e.x,this.y+=e.y}addX(e){this.x+=e.x}addY(e){this.y+=e.y}subtract(e){this.x-=e.x,this.y-=e.y}subtractX(e){this.x-=e.x}subtractY(e){this.y-=e.y}divide(e){this.x/=e.x,this.y/=e.y}divideX(e){this.x/=e.x}divideY(e){this.y/=e.y}multiply(e){this.x*=e.x,this.y*=e.y}multiplyX(e){this.x*=e.x}multiplyY(e){this.y*=e.y}invert(){this.x*=-1,this.y*=-1}invertX(){this.x*=-1}invertY(){this.y*=-1}normalize(){let e=Math.sqrt(this.x*this.x+this.y*this.y);e!==0&&(this.x/=e,this.y/=e)}limit(e){this.x>e.x&&(this.x=e.x),this.y>e.y&&(this.y=e.y),this.x<e.x*-1&&(this.x=e.x*-1),this.y<e.y*-1&&(this.y=e.y*-1)}limitLength(e){}};var y={isCircle(i){return i.x!==void 0&&i.y!==void 0&&i.radius!==void 0},isRect(i){return i.x!==void 0&&i.y!==void 0&&i.width!==void 0&&i.height!==void 0},fixPos(i){if(i.pos===void 0||i.pos.x===void 0&&i.pos.y===void 0)return i;let e=Object.create(i);return Object.defineProperty(e,"x",{value:i.pos.x,enumerable:!0,writable:!0,configurable:!0}),Object.defineProperty(e,"y",{value:i.pos.y,enumerable:!0,writable:!0,configurable:!0}),e},rect(i,e){let t=y.fixPos(i),s=y.fixPos(e);if(!y.isRect(t)||!y.isRect(s))return A("One of the objects is not defined correctly as a rect"),!1;let[n,o,r,d]=[t.x,t.y,t.width,t.height],[h,l,u,p]=[s.x,s.y,s.width,s.height];return!(n+r/2<h-u/2||n-r/2>h+u/2||o+d/2<l-p/2||o-d/2>l+p/2)},circle(i,e){let t=y.fixPos(i),s=y.fixPos(e);if(!y.isCircle(t)||!y.isCircle(s))return A("One of the objects is not defined correctly as a circle"),!1;let n=t.x-s.x,o=t.y-s.y;return Math.sqrt(n*n+o*o)<t.radius+s.radius},circleRect(i,e){let t=y.fixPos(i),s=y.fixPos(e);if(!y.isCircle(t)||!y.isRect(s))return A("One of the objects is not defined correctly as a circle or rect"),!1;let n=Math.abs(t.x-s.x),o=Math.abs(t.y-s.y),r=s.width/2,d=s.height/2,h=t.radius;if(n>=r+h||o>=d+h)return!1;if(n<r||o<d)return!0;let l=n-r,u=o-d;return l*l+u*u<=h*h}};var Ve=()=>a.gameObject,Ie;Ie=Symbol.toStringTag;var W=class{constructor(e){this[Ie]="THRUNIUM.Sprite";this.angle=0;this.currentSprite=null;this.animTimeDur=100;this.frameTimeLast=0;this.animLoop=!1;this.animCallback=()=>{};this.image=e,this.fullWidth=e.width,this.fullHeight=e.height,this.spriteWidth=e.width,this.spriteHeight=e.height}setAngle(e){this.angle=e}setLoop(e){this.animLoop=e}setAnimCallback(e){this.animCallback=e}setAnimTime(e){this.animTimeDur=e}setSpriteMap(e,t){this.spriteWidth=e,this.spriteHeight=t}frameRect(e=(t=>(t=this.currentSprite)!=null?t:0)()){return{sx:e*this.spriteWidth%this.fullWidth,sy:Math.floor(e*this.spriteWidth/this.fullWidth)*this.spriteHeight,sw:this.spriteWidth,sh:this.spriteHeight}}draw(e=0,t,s,n,o){let{sx:r,sy:d}=this.frameRect(e),h=n===void 0?this.spriteWidth:n,l=o===void 0?this.spriteHeight:o,u=Ve().ctx;u.beginPath(),u.save(),u.translate(t,s),u.rotate(this.angle*Math.PI/180),u.drawImage(this.image,r,d,this.spriteWidth,this.spriteHeight,-h/2,-l/2,h,l),u.restore(),u.closePath()}drawAnim(e,t,s,n,o,r){var l;this.currentSprite==null&&(this.currentSprite=e);let d=this.animTimeDur/(t-e+1),h=Date.now();h-this.frameTimeLast>d&&(this.currentSprite<t?this.currentSprite++:this.animLoop?this.currentSprite=e:(this.currentSprite=null,this.animCallback()),this.frameTimeLast=h),this.draw((l=this.currentSprite)!=null?l:void 0,s,n,o,r)}};var se=()=>a.gameObject,Y=class{constructor(e,t,s){this.style={};this.hoverStyle={};this.hoverOverrides={};this._tag="THRUNIUM.Elem."+e,this.x=t,this.y=s,this.elem=document.createElement(e),this.elem.addEventListener("mouseenter",()=>this.updateStyle(this.hoverStyle),!1),this.elem.addEventListener("mouseleave",()=>this.updateStyle(this.style),!1),this.setStyle("display","block"),this.setStyle("position","absolute"),this.setStyle("color","#000"),this.setStyle("backgroundColor","#fff"),this.setStyle("fontFamily",se().font),this.setStyle("borderRadius","5px"),this.resize(),ne.elemsList.push(this),a.container.appendChild(this.elem)}get[Symbol.toStringTag](){return this._tag}setPos(e,t){this.x=e,this.y=t,this.resize()}resize(){let e=se().fitScale;this.setStyle("left",this.x*e+"px"),this.setStyle("top",this.y*e+"px"),this.setStyle("transformOrigin","top left"),this.setStyle("transform","scale("+e+")")}addEventListener(e,t,s){this.elem.addEventListener(e,t,s)}updateStyle(e){for(let t in e)this.elem.style[t]=e[t]}setStyle(e,t){this.style[e]=t,this.hoverOverrides[e]||(this.hoverStyle[e]=t),this.updateStyle(this.style)}setHoverStyle(e,t){this.hoverStyle[e]=t,this.hoverOverrides[e]=!0}show(){this.setStyle("display","block")}hide(){this.setStyle("display","none")}};function Ne(i,e,t){let s=new Y("button",e,t);return s.elem.textContent=i,s.elem.style.border="none",s}function We(i,e,t){let s=se(),n=document.createElement("input");return n.style.position="absolute",n.style.left=i*s.scale*s.fitScale+"px",n.style.top=e*s.scale*s.fitScale+"px",n.style.border="2px solid #000",n.style.borderRadius="5px",n.style.color="#000",n.style.backgroundColor="#fff",n.style.fontFamily=s.font,n.style.fontSize=s.textSize,n.type=t.type?t.type:"text",t.placeholder&&(n.placeholder=t.placeholder),a.container.appendChild(n),n}var ne={elemsList:[],Elem:Y,Button:Ne,Input:We};function K(i){var o,r,d,h;let e=(o=i.success)!=null?o:(l=>console.log(l)),t=(r=i.error)!=null?r:(()=>{}),s=(d=i.contentType)!=null?d:"application/x-www-form-urlencoded",n=new XMLHttpRequest;return n.withCredentials=(h=i.withCredentials)!=null?h:!1,n.onreadystatechange=function(){n.readyState===4&&(n.status===200?e(n):t(n))},n.open(i.type,i.url,!0),s!==!1&&n.setRequestHeader("Content-Type",s),n.send(i.data),n}function Ye(i){return i.replace(/[%;\x00-\x1f\x7f]/g,encodeURIComponent).replace(/^ +| +$/g,e=>e.replace(/ /g,"%20"))}function Ke(i,e){let t=new Date;t.setTime(t.getTime()+365*24*60*60*1e3);let s="expires="+t.toUTCString();return document.cookie=i+"="+Ye(String(e))+";"+s+";path="+document.location.pathname,!0}function Je(i){let e=i+"=";for(let t of document.cookie.split(";"))if(t=t.replace(/^ +/,""),t.indexOf(e)===0){let s=t.substring(e.length);try{return decodeURIComponent(s)}catch(n){return s}}return null}var qe={set:Ke,get:Je};var ie={};De(ie,{_options:()=>nt,_receiveMessage:()=>rt,accessRequested:()=>st,loginPopup:()=>tt,reqToken:()=>Qe,reqUserToken:()=>ot,request:()=>at,setReqToken:()=>it,timeout:()=>et,userToken:()=>Ze});var Qe=null,Ze=null,et=null,tt=null,st=!1,nt={succes:i=>console.log(i),error:i=>console.log(i)};function it(i){a.Storage.reqToken=i}function ot(i){a.Storage._options.succes=i.succes,a.Storage._options.error=i.error,K({url:"https://api.thrungames.com/request/user-token",type:"post",data:"requestToken="+a.Storage.reqToken,succes:function(e){var s,n,o,r;let t=JSON.parse(e.response);t.access=="0"&&!a.Storage.accessRequested?(window.addEventListener("message",a.Storage._receiveMessage,!1),window.parent.postMessage({reqToken:a.Storage.reqToken},document.origin),a.Storage.timeout=setTimeout(function(){let d=screen.width?(screen.width-400)/2:0,l="height=500,width=400,top="+(screen.height?(screen.height-500)/2:0)+",left="+d+",scrollbars=yes,resizable",u="https://api.thrungames.com/user/access?token="+a.Storage.reqToken;a.Storage.loginPopup=window.open(u,"Approval of game",l)},200)):t.access=="1"?(a.Storage.userToken=window.event.data.userToken,(n=(s=a.Storage._options).succes)==null||n.call(s,{type:"userAccepted",event:e})):(r=(o=a.Storage._options).error)==null||r.call(o,{type:"ajaxFailed",event:e})},error:function(e){var t,s;(s=(t=a.Storage._options).error)==null||s.call(t,{type:"ajaxFailed",event:e})}})}function rt(i){var t,s,n;let e=window.event;e.origin!=="https://www.thrungames.com/"&&e.origin!=="https://www.thrungames.com/"||(clearTimeout((t=a.Storage.timeout)!=null?t:void 0),a.Storage.accessRequested=!0,e.data.state==1?a.Storage.reqUserToken(a.Storage._options):(n=(s=a.Storage._options).error)==null||n.call(s,{type:"userRejected",event:i}))}function at(i){}a.version="1.2.0-rc.4";a.pageLoad=ee;a.ready=te;a.throwError=A;a.mobileAndTabletcheck=Se;a.iOScheck=Te;a.getRandom=ke;Ee();a.Game=V;a.Vector=N;a.Collider=Object.assign(a.Collider||{},y);a.Sprite=W;a.Button=F;a.Elem=Object.assign(a.Elem||{},ne);a.ajax=K;a.Storage=Object.assign(a.Storage||{},qe,ie);window.requestAnimFrame=typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame.bind(window):i=>window.setTimeout(()=>i(Date.now()),1e3/60);})();
3
4
  //# sourceMappingURL=thrunium.min.js.map