thrunium 1.2.0-rc.1 → 1.2.0-rc.2

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.
package/dist/thrunium.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! THRUNIUM v1.2.0-rc.1 | (c) Infobits ApS | MIT License */
1
+ /*! THRUNIUM v1.2.0-rc.2 | (c) Infobits ApS | MIT License */
2
2
  "use strict";
3
3
  (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -121,9 +121,9 @@
121
121
  * ```
122
122
  */
123
123
  this.fps = 0;
124
- // 1.0.0 stores (fps / 60).toFixed(2), a string; kept for compatibility.
124
+ // Before 1.2.0 this was the string (fps / 60).toFixed(2); it is now a number.
125
125
  /**
126
- * Current frames per second divided by 60, as a string with two decimals (for example `"1.00"`). Use it to correct game speed on devices that run below 60 fps. Updated every frame. Read-only.
126
+ * Current frames per second divided by 60, as a number with two decimals (for example `1`). Use it to correct game speed on devices that run below 60 fps. Updated every frame. Read-only.
127
127
  *
128
128
  * @category Variables
129
129
  * @example
@@ -281,6 +281,8 @@
281
281
  * game.start();
282
282
  * ```
283
283
  */
284
+ // Typed for strict consumers: entries going in are strings or AssetEntry, and
285
+ // after init() the same array is read by key, which the Record part allows.
284
286
  this.assets = [];
285
287
  /**
286
288
  * Whether `loadAssets()` has run, so the entries of `assets` have been turned into loadable elements. Use `loadedAssets` to see how many have actually finished loading.
@@ -340,6 +342,7 @@
340
342
  // User-assignable events (own properties, no-ops by default).
341
343
  /**
342
344
  * Called when the user clicks the game, and when a touch ends on it (`touchend` calls `click` just before its own handler). It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
345
+ * @param evt The mouse click, or the touch event when a touch ended.
343
346
  *
344
347
  * @category Events
345
348
  * @example
@@ -354,6 +357,7 @@
354
357
  };
355
358
  /**
356
359
  * Called when the user presses a mouse button in the game. It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
360
+ * @param evt The mouse event.
357
361
  *
358
362
  * @category Events
359
363
  * @example
@@ -368,6 +372,7 @@
368
372
  };
369
373
  /**
370
374
  * Called when the user releases a mouse button in the game. It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
375
+ * @param evt The mouse event.
371
376
  *
372
377
  * @category Events
373
378
  * @example
@@ -396,6 +401,7 @@
396
401
  };
397
402
  /**
398
403
  * Called when the user touches the game with a touchscreen. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
404
+ * @param evt The touch event.
399
405
  *
400
406
  * @category Events
401
407
  * @example
@@ -410,6 +416,7 @@
410
416
  };
411
417
  /**
412
418
  * Called when the user first touches the game with a touchscreen, after `touch`. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
419
+ * @param evt The touch event.
413
420
  *
414
421
  * @category Events
415
422
  * @example
@@ -424,6 +431,7 @@
424
431
  };
425
432
  /**
426
433
  * Called when the user lifts the touch from a touchscreen, after `click`. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
434
+ * @param evt The touch event.
427
435
  *
428
436
  * @category Events
429
437
  * @example
@@ -438,6 +446,7 @@
438
446
  };
439
447
  /**
440
448
  * Called when the user presses a key. Assign a function to handle it; find key codes at keycode.info. Attached by `init()`, so assign it first.
449
+ * @param evt The keyboard event; `evt.key` holds the key.
441
450
  *
442
451
  * @category Events
443
452
  * @example
@@ -453,6 +462,7 @@
453
462
  };
454
463
  /**
455
464
  * Called when the user releases a key. Assign a function to handle it. Attached by `init()`, so assign it first.
465
+ * @param evt The keyboard event; `evt.key` holds the key.
456
466
  *
457
467
  * @category Events
458
468
  * @example
@@ -610,7 +620,7 @@
610
620
  this.delta = (Date.now() - this.lastRun) / 1e3;
611
621
  this.lastRun = Date.now();
612
622
  this.fps = 1 / this.delta;
613
- this.runSpeed = (this.fps / 60).toFixed(2);
623
+ this.runSpeed = Math.round(this.fps / 60 * 100) / 100;
614
624
  this.ctx.clearRect(0, 0, this.width, this.height);
615
625
  this.canvas.style.cursor = "default";
616
626
  this.drawRect(0, 0, this.width, this.height);
@@ -2212,7 +2222,7 @@
2212
2222
  }
2213
2223
 
2214
2224
  // src/index.ts
2215
- T.version = "1.2.0-rc.1";
2225
+ T.version = "1.2.0-rc.2";
2216
2226
  T.pageLoad = pageLoad;
2217
2227
  T.ready = ready;
2218
2228
  T.throwError = throwError;
@@ -1,3 +1,3 @@
1
- /*! THRUNIUM v1.2.0-rc.1 | (c) Infobits ApS | MIT License */
2
- "use strict";(()=>{var A=Object.defineProperty;var _=(s,e)=>{for(var t in e)A(s,t,{get:e[t],enumerable:!0})};window.THRUNIUM||(window.THRUNIUM={});var o=window.THRUNIUM;function b(){o.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),o.error=!0}function L(){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 E(){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(){o.container=null,o.gameObject=null,o.error=!1,o.pageLoaded=!1,o.fontsLoaded=!1,x(b),typeof document!="undefined"&&document.fonts&&document.fonts.ready?document.fonts.ready.then(()=>{o.fontsLoaded=!0}):o.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,n;this.updateFitScale(),this.updateScale();let t=(n=(i=o.Elem)==null?void 0:i.elemsList)!=null?n:[];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=o.Sprite,n=new i(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=(this.fps/60).toFixed(2),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&&!o.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(),n=this.canvas.scrollWidth/this.width,r=this.canvas.scrollHeight/this.height;this.mouseX=(t.clientX-i.left)/n,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=o.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",o.container=e,o.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 n=this.assets[i],r,a,d=null;if(typeof n=="string")a=n,r=a;else if(typeof n=="object"&&n!==null){let h=n;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,n,r){this.ctx.beginPath(),r&&(this.ctx.lineWidth=r),this.ctx.moveTo(e,t),this.ctx.lineTo(i,n),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,n,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+n-r),a.quadraticCurveTo(e+i,t+n,e+i-r,t+n),a.lineTo(e+r,t+n),a.quadraticCurveTo(e,t+n,e,t+n-r),a.lineTo(e,t+r),a.quadraticCurveTo(e,t,e+r,t)):a.rect(e,t,i,n),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,n=null,r=null){this.ctx.beginPath(),n!==null&&r!==null?this.ctx.drawImage(e,t,i,n,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&&o.pageLoaded&&o.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 o.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[n,r,a,d]=[t.x,t.y,t.width,t.height],[c,l,h,T]=[i.x,i.y,i.width,i.height];return!(n+a/2<c-h/2||n-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 n=t.x-i.x,r=t.y-i.y;return Math.sqrt(n*n+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 n=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(n>=a+c||r>=d+c)return!1;if(n<a||r<d)return!0;let l=n-a,h=r-d;return l*l+h*h<=c*c}};var F=()=>o.gameObject,H;H=Symbol.toStringTag;var g=class{constructor(e){this[H]="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,n,r){let a=e*this.spriteWidth%this.fullWidth,d=Math.floor(e*this.spriteWidth/this.fullWidth)*this.spriteHeight,c=n===void 0?this.spriteWidth:n,l=r===void 0?this.spriteHeight:r,h=F().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,n,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,n,r,a)}};var w=()=>o.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),o.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 P(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(),n=document.createElement("input");return n.style.position="absolute",n.style.left=s*i.scale*i.fitScale+"px",n.style.top=e*i.scale*i.fitScale+"px",n.style.border="2px solid #000",n.style.borderRadius="5px",n.style.color="#000",n.style.backgroundColor="#fff",n.style.fontFamily=i.font,n.style.fontSize=i.textSize,n.type=t.type?t.type:"text",t.placeholder&&(n.placeholder=t.placeholder),o.container.appendChild(n),n}var S={elemsList:[],Elem:v,Button:P,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",n=new XMLHttpRequest;return n.withCredentials=(c=s.withCredentials)!=null?c:!1,n.onreadystatechange=function(){n.readyState===4&&(n.status===200?e(n):t(n))},n.open(s.type,s.url,!0),i!==!1&&n.setRequestHeader("Content-Type",i),n.send(s.data),n}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(n){return i}}return null}var q={set:z,get:j};var k={};_(k,{_options:()=>G,_receiveMessage:()=>B,accessRequested:()=>D,loginPopup:()=>W,reqToken:()=>V,reqUserToken:()=>Y,request:()=>$,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){o.Storage.reqToken=s}function Y(s){o.Storage._options.succes=s.succes,o.Storage._options.error=s.error,y({url:"https://api.thrungames.com/request/user-token",type:"post",data:"requestToken="+o.Storage.reqToken,succes:function(e){var i,n,r,a;let t=JSON.parse(e.response);t.access=="0"&&!o.Storage.accessRequested?(window.addEventListener("message",o.Storage._receiveMessage,!1),window.parent.postMessage({reqToken:o.Storage.reqToken},document.origin),o.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="+o.Storage.reqToken;o.Storage.loginPopup=window.open(h,"Approval of game",l)},200)):t.access=="1"?(o.Storage.userToken=window.event.data.userToken,(n=(i=o.Storage._options).succes)==null||n.call(i,{type:"userAccepted",event:e})):(a=(r=o.Storage._options).error)==null||a.call(r,{type:"ajaxFailed",event:e})},error:function(e){var t,i;(i=(t=o.Storage._options).error)==null||i.call(t,{type:"ajaxFailed",event:e})}})}function B(s){var t,i,n;let e=window.event;e.origin!=="https://www.thrungames.com/"&&e.origin!=="https://www.thrungames.com/"||(clearTimeout((t=o.Storage.timeout)!=null?t:void 0),o.Storage.accessRequested=!0,e.data.state==1?o.Storage.reqUserToken(o.Storage._options):(n=(i=o.Storage._options).error)==null||n.call(i,{type:"userRejected",event:s}))}function $(s){}o.version="1.2.0-rc.1";o.pageLoad=b;o.ready=x;o.throwError=m;o.mobileAndTabletcheck=L;o.iOScheck=E;o.getRandom=R;M();o.Game=p;o.Vector=f;o.Collider=Object.assign(o.Collider||{},u);o.Sprite=g;o.Elem=Object.assign(o.Elem||{},S);o.ajax=y;o.Storage=Object.assign(o.Storage||{},q,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.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);})();
3
3
  //# sourceMappingURL=thrunium.min.js.map