brick-engine-js 1.0.14 → 1.0.16

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.
@@ -720,7 +720,7 @@ module.exports = {
720
720
  </div>
721
721
  <div id="footer">
722
722
  <div id="footer-text">
723
- Last updated 2026-02-24 16:37:28 UTC
723
+ Last updated 2026-02-18 08:51:37 -0300
724
724
  </div>
725
725
  </div>
726
726
  </body>
@@ -603,7 +603,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
603
603
  </div>
604
604
  <div id="footer">
605
605
  <div id="footer-text">
606
- Last updated 2026-02-24 16:37:28 UTC
606
+ Last updated 2026-02-19 09:03:38 -0300
607
607
  </div>
608
608
  </div>
609
609
  </body>
@@ -634,7 +634,7 @@ export default class MyGame extends Game {
634
634
  </div>
635
635
  <div id="footer">
636
636
  <div id="footer-text">
637
- Last updated 2026-02-24 16:37:28 UTC
637
+ Last updated 2026-02-23 16:20:59 -0300
638
638
  </div>
639
639
  </div>
640
640
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
@@ -642,7 +642,7 @@ interface ButtonLayoutResponse {
642
642
  </div>
643
643
  <div id="footer">
644
644
  <div id="footer-text">
645
- Last updated 2026-02-24 16:37:28 UTC
645
+ Last updated 2026-02-13 12:20:51 -0300
646
646
  </div>
647
647
  </div>
648
648
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
@@ -559,7 +559,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
559
559
  </div>
560
560
  <div id="footer">
561
561
  <div id="footer-text">
562
- Last updated 2026-02-24 16:37:28 UTC
562
+ Last updated 2026-02-23 16:10:29 -0300
563
563
  </div>
564
564
  </div>
565
565
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
@@ -578,7 +578,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
578
578
  </div>
579
579
  <div id="footer">
580
580
  <div id="footer-text">
581
- Last updated 2026-02-24 16:37:28 UTC
581
+ Last updated 2026-02-23 16:03:34 -0300
582
582
  </div>
583
583
  </div>
584
584
  </body>
@@ -531,7 +531,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
531
531
  </div>
532
532
  <div id="footer">
533
533
  <div id="footer-text">
534
- Last updated 2026-02-24 16:37:28 UTC
534
+ Last updated 2026-02-23 16:03:32 -0300
535
535
  </div>
536
536
  </div>
537
537
  </body>
@@ -526,7 +526,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
526
526
  </div>
527
527
  <div id="footer">
528
528
  <div id="footer-text">
529
- Last updated 2026-02-24 16:37:28 UTC
529
+ Last updated 2026-02-22 22:09:51 -0300
530
530
  </div>
531
531
  </div>
532
532
  </body>
@@ -550,7 +550,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
550
550
  </div>
551
551
  <div id="footer">
552
552
  <div id="footer-text">
553
- Last updated 2026-02-24 16:37:28 UTC
553
+ Last updated 2026-02-22 17:57:57 -0300
554
554
  </div>
555
555
  </div>
556
556
  </body>
@@ -513,7 +513,7 @@ Constructs the background container wrapper, title frames, dialogue text, and co
513
513
  </div>
514
514
  <div id="footer">
515
515
  <div id="footer-text">
516
- Last updated 2026-02-24 16:37:28 UTC
516
+ Last updated 2026-02-22 17:04:18 -0300
517
517
  </div>
518
518
  </div>
519
519
  </body>
@@ -763,7 +763,7 @@ describe('GridAnalysisEngine', () =&gt; {
763
763
  </div>
764
764
  <div id="footer">
765
765
  <div id="footer-text">
766
- Last updated 2026-02-24 16:37:28 UTC
766
+ Last updated 2026-02-19 21:48:22 -0300
767
767
  </div>
768
768
  </div>
769
769
  </body>
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return e[t](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r,o,s,a,u,c,l,h,p={};n.r(p),n.d(p,{Color:()=>r,ControlEventType:()=>l,ControlKey:()=>c,FontAlign:()=>o,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>ht,GameView:()=>Vt,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>oe,configs:()=>d}),function(t){t.DEFAULT="rgb(19, 26, 18)",t.BLUE="rgb(0, 0, 128)",t.CYAN="rgb(0, 128, 128)",t.GRAY="rgb(128, 128, 128)",t.GREEN="rgb(0, 128, 0)",t.PURPLE="rgb(128, 0, 128)",t.RED="rgb(128, 0, 0)",t.YELLOW="rgb(128, 128, 0)",t.INACTIVE="rgb(166, 183, 165)"}(r||(r={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(o||(o={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const d={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},d.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},d.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var _=function(){function t(){this._subscribers=new Map}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._subscribers.clear()},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribers.has(t)||this._subscribers.set(t,new Map);var n=this._subscribers.get(t);n.has(e)||n.set(e,new Set),n.get(e).add(i)},t.prototype.unsubscribe=function(t,e,i){var n=this._subscribers.get(t);if(n){var r=n.get(e);r&&r.delete(i)}},t.prototype.notify=function(t,e){var i;if(!this._modules)throw new Error("Modules not initialized");var n={key:t,type:e,modules:this._modules},r=this._modules.state,o=!1;r.isOff()?o=t===c.POWER:!r.isStarted()||r.isPlaying()||r.isGameOver()?o=!0:r.isPaused()&&(o=t.endsWith(";system"));var s=null===(i=this._subscribers.get(t))||void 0===i?void 0:i.get(e);s&&o&&s.forEach(function(t){return t(n)})},t.prototype.getDebugData=function(){var t=0;return this._subscribers.forEach(function(e){e.forEach(function(e){t+=e.size})}),{total_subscribers:t,tracked_keys:this._subscribers.size}},t}();const m=_,v=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:r.DEFAULT,coordinate:t}},t}();var b=function(){return b=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},b.apply(this,arguments)},w=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return b(b({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),r=n.some(function(e){return!i.grid.isValidCoordinate(e.coordinate)||i.grid.isCellActive(e.coordinate)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}));var n});return r?null:n},t.prototype.movePieceLeft=function(t){return this.movePiece(t,{x:-1,y:0})},t.prototype.movePieceRight=function(t){return this.movePiece(t,{x:1,y:0})},t.prototype.movePieceUp=function(t){return this.movePiece(t,{x:0,y:-1})},t.prototype.movePieceDown=function(t){return this.movePiece(t,{x:0,y:1})},t.prototype.moveCell=function(t,e){var i={x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)};return!this.grid.isValidCoordinate(i)||this.grid.isCellActive(i)?null:b(b({},t),{coordinate:i})},t.prototype.moveCellLeft=function(t){return this.moveCell(t,{x:-1,y:0})},t.prototype.moveCellRight=function(t){return this.moveCell(t,{x:1,y:0})},t.prototype.moveCellUp=function(t){return this.moveCell(t,{x:0,y:-1})},t.prototype.moveCellDown=function(t){return this.moveCell(t,{x:0,y:1})},t.prototype.getDropPath=function(t){for(var e=t,i=this.movePieceDown(e);null!==i;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);null!==i;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);null!==i;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);null!==i;)e=i,i=this.movePieceRight(e);return e},t}();const E=w;var S=function(){return S=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},S.apply(this,arguments)},x=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var r=t.map(function(t){var n=t.coordinate.x-e.x,r=t.coordinate.y-e.y,o=i?-r:r,s=i?n:-n;return S(S({},t),{coordinate:{x:e.x+o,y:e.y+s}})}),o=r.some(function(e){return!n.grid.isValidCoordinate(e.coordinate)||n.grid.isCellActive(e.coordinate)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}));var i});return o?null:r},t.prototype.mirrorPiece=function(t,e){if(0===t.length)return[];var i=this.getPieceBounds(t),n="x"===e?(i.min.x+i.max.x)/2:(i.min.y+i.max.y)/2;return t.map(function(t){return S(S({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const C=x;var R=function(){return R=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},R.apply(this,arguments)},P=function(){function t(t){this.grid=t}return t.prototype.getFullRows=function(){for(var t=[],e=0;e<this.grid.height;e++){for(var i=!0,n=0;n<this.grid.width;n++)if(!this.grid.isCellActive({x:n,y:e})){i=!1;break}i&&t.push(e)}return t},t.prototype.getFullColumns=function(){for(var t=[],e=0;e<this.grid.width;e++){for(var i=!0,n=0;n<this.grid.height;n++)if(!this.grid.isCellActive({x:e,y:n})){i=!1;break}i&&t.push(e)}return t},t.prototype.getNeighbors=function(t,e){var i=this;void 0===e&&(e=!1);var n=[],r=[{x:-1,y:0},{x:1,y:0},{x:0,y:-1},{x:0,y:1}];return e&&r.push({x:-1,y:-1},{x:1,y:-1},{x:-1,y:1},{x:1,y:1}),r.forEach(function(e){var r={x:t.x+e.x,y:t.y+e.y};i.grid.isValidCoordinate(r)&&n.push(i.grid.getCell(r))}),n},t.prototype.findConnectedCells=function(t){var e=this;if(!this.grid.isCellActive(t))return[];var i=this.grid.getCell(t).value,n=[],r=new Set,o=[t],s=function(t){return"".concat(t.x,",").concat(t.y)};for(r.add(s(t));o.length>0;){var a=o.shift(),u=this.grid.getCell(a);u.value===i&&(n.push(u),[{x:a.x-1,y:a.y},{x:a.x+1,y:a.y},{x:a.x,y:a.y-1},{x:a.x,y:a.y+1}].forEach(function(t){var i=s(t);e.grid.isValidCoordinate(t)&&!r.has(i)&&e.grid.isCellActive(t)&&(r.add(i),o.push(t))}))}return n},t.prototype.swapCells=function(t,e){var i=R({},this.grid.getCell(t)),n=R({},this.grid.getCell(e));this.grid.stampCell(R(R({},n),{coordinate:t})),this.grid.stampCell(R(R({},i),{coordinate:e}))},t}();const O=P;var T=function(){function t(t){this.grid=t}return t.prototype.isRowFull=function(t){var e=this.grid.getGrid();return!(t<0||t>=this.grid.height)&&e[t].every(function(t){return t.value>0})},t.prototype.isRowEmpty=function(t){var e=this.grid.getGrid();return t<0||t>=this.grid.height||e[t].every(function(t){return 0===t.value})},t.prototype.clearRow=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.height))for(var i=0;i<this.grid.width;i++)e[t][i]=v.emptyCell({x:i,y:t})},t.prototype.shiftRowsDown=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.width;n++){var r=e[i-1][n];e[i][n].value=r.value,e[i][n].color=r.color}this.clearRow(0)},t.prototype.shiftRowsUp=function(t){for(var e=this.grid.getGrid(),i=t;i<this.grid.height-1;i++)for(var n=0;n<this.grid.width;n++){var r=e[i+1][n];e[i][n].value=r.value,e[i][n].color=r.color}this.clearRow(this.grid.height-1)},t.prototype.clearFullRows=function(){for(var t=0,e=this.grid.height-1;e>=0;e--)this.isRowFull(e)&&(this.clearRow(e),this.shiftRowsDown(e),t++,e++);return t},t.prototype.isColumnFull=function(t){var e=this.grid.getGrid();if(t<0||t>=this.grid.width)return!1;for(var i=0;i<this.grid.height;i++)if(0===e[i][t].value)return!1;return!0},t.prototype.isColumnEmpty=function(t){var e=this.grid.getGrid();if(t<0||t>=this.grid.width)return!0;for(var i=0;i<this.grid.height;i++)if(0!==e[i][t].value)return!1;return!0},t.prototype.clearColumn=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.width))for(var i=0;i<this.grid.height;i++)e[i][t]=v.emptyCell({x:t,y:i})},t.prototype.shiftColumnsRight=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.height;n++){var r=e[n][i-1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(0)},t.prototype.shiftColumnsLeft=function(t){for(var e=this.grid.getGrid(),i=t;i<this.grid.width-1;i++)for(var n=0;n<this.grid.height;n++){var r=e[n][i+1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(this.grid.width-1)},t.prototype.clearFullColumns=function(){for(var t=0,e=this.grid.width-1;e>=0;e--)this.isColumnFull(e)&&(this.clearColumn(e),this.shiftColumnsRight(e),t++,e++);return t},t}();const M=T;var I=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){return!e.grid.isValidCoordinate(t)||e.grid.isCellActive(t)})},t.prototype.fillArea=function(t,e,i,n){for(var r=Math.max(0,Math.min(t.x,e.x)),o=Math.min(this.grid.width-1,Math.max(t.x,e.x)),s=Math.max(0,Math.min(t.y,e.y)),a=Math.min(this.grid.height-1,Math.max(t.y,e.y)),u=s;u<=a;u++)for(var c=r;c<=o;c++)this.grid.setCellValue({x:c,y:u},i),this.grid.setCellColor({x:c,y:u},n)},t.prototype.stampPiece=function(t){var e=this;t.forEach(function(t){return e.grid.stampCell(t)})},t.prototype.stampCell=function(t){this.grid.setCellValue(t.coordinate,t.value),this.grid.setCellColor(t.coordinate,t.color)},t}();const D=I;var L=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new E(this),this._transformEngine=new C(this),this._analysisEngine=new O(this),this._lineEngine=new M(this),this._regionEngine=new D(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return d.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return d.screenLayout.grid.rows},enumerable:!1,configurable:!0}),t.prototype.setup=function(){this.resetGrid()},t.prototype.resetGrid=function(){this._grid=[];for(var t=0;t<this.height;t++){this._grid[t]=[];for(var e=0;e<this.width;e++)this._grid[t][e]=v.emptyCell({x:e,y:t})}},t.prototype.forEach=function(t){for(var e=0;e<this.height;e++)for(var i=0;i<this.width;i++)t(this._grid[e][i])},t.prototype.isValidCoordinate=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isValidCoordinate(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){var e=this.getCell(t);return null!==e&&e.value>0},t.prototype.isCellInactive=function(t){var e=this.getCell(t);return null!==e&&0===e.value},t.prototype.isRowFull=function(t){return this._lineEngine.isRowFull(t)},t.prototype.isRowEmpty=function(t){return this._lineEngine.isRowEmpty(t)},t.prototype.clearRow=function(t){this._lineEngine.clearRow(t)},t.prototype.shiftRowsDown=function(t){this._lineEngine.shiftRowsDown(t)},t.prototype.shiftRowsUp=function(t){this._lineEngine.shiftRowsUp(t)},t.prototype.clearFullRows=function(){return this._lineEngine.clearFullRows()},t.prototype.isColumnFull=function(t){return this._lineEngine.isColumnFull(t)},t.prototype.isColumnEmpty=function(t){return this._lineEngine.isColumnEmpty(t)},t.prototype.clearColumn=function(t){this._lineEngine.clearColumn(t)},t.prototype.shiftColumnsRight=function(t){this._lineEngine.shiftColumnsRight(t)},t.prototype.shiftColumnsLeft=function(t){this._lineEngine.shiftColumnsLeft(t)},t.prototype.clearFullColumns=function(){return this._lineEngine.clearFullColumns()},t.prototype.isAreaOccupied=function(t){return this._regionEngine.isAreaOccupied(t)},t.prototype.fillArea=function(t,e,i,n){this._regionEngine.fillArea(t,e,i,n)},t.prototype.stampPiece=function(t){this._regionEngine.stampPiece(t)},t.prototype.stampCell=function(t){this._regionEngine.stampCell(t)},t.prototype.movePiece=function(t,e){return this._movementEngine.movePiece(t,e)},t.prototype.movePieceLeft=function(t){return this._movementEngine.movePieceLeft(t)},t.prototype.movePieceRight=function(t){return this._movementEngine.movePieceRight(t)},t.prototype.movePieceUp=function(t){return this._movementEngine.movePieceUp(t)},t.prototype.movePieceDown=function(t){return this._movementEngine.movePieceDown(t)},t.prototype.moveCell=function(t,e){return this._movementEngine.moveCell(t,e)},t.prototype.moveCellLeft=function(t){return this._movementEngine.moveCellLeft(t)},t.prototype.moveCellRight=function(t){return this._movementEngine.moveCellRight(t)},t.prototype.moveCellUp=function(t){return this._movementEngine.moveCellUp(t)},t.prototype.moveCellDown=function(t){return this._movementEngine.moveCellDown(t)},t.prototype.rotatePiece=function(t,e,i){return void 0===i&&(i=!0),this._transformEngine.rotatePiece(t,e,i)},t.prototype.getFullRows=function(){return this._analysisEngine.getFullRows()},t.prototype.getFullColumns=function(){return this._analysisEngine.getFullColumns()},t.prototype.getDropPath=function(t){return this._movementEngine.getDropPath(t)},t.prototype.getRisePath=function(t){return this._movementEngine.getRisePath(t)},t.prototype.getReachPathLeft=function(t){return this._movementEngine.getReachPathLeft(t)},t.prototype.getReachPathRight=function(t){return this._movementEngine.getReachPathRight(t)},t.prototype.getNeighbors=function(t,e){return void 0===e&&(e=!1),this._analysisEngine.getNeighbors(t,e)},t.prototype.findConnectedCells=function(t){return this._analysisEngine.findConnectedCells(t)},t.prototype.mirrorPiece=function(t,e){return this._transformEngine.mirrorPiece(t,e)},t.prototype.swapCells=function(t,e){this._analysisEngine.swapCells(t,e)},t.prototype.getPieceBounds=function(t){return this._transformEngine.getPieceBounds(t)},t.prototype.getDebugData=function(){return{width:this.width,height:this.height,activeCells:this._grid.flat().filter(function(t){return t.value>0}).length}},t.prototype.serialize=function(){return console.log("serialize"),JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){console.log("deserialize");var e=JSON.parse(t);this._grid=e.grid},t}();const A=L;var G=function(){function t(){}return t.getRelativeWidth=function(t,e){return e*t.width},t.getRelativeHeight=function(t,e){return e*t.height},t}();const B=G;var k=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=d.screenLayout.cell,i=e.margin,n=e.padding,r=e.strokeWeight,o=this._rendererMetrics.cell.size;this._cellPreCalculatedGeometry={innerOffset:i*o,innerSize:o-i*o*2,paddingOffset:n*o,paddingSize:o-n*o*2,strokeWeight:r*o},this._renderStaticElements()},t.prototype.render=function(t,e){this._p.push(),this._p.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),this._p.pop()},t.prototype._renderStaticElements=function(){var t=d.screenLayout.display.borderWeight;this._staticGraphics=this._p.createGraphics(this._p.width,this._p.height),this._staticGraphics.background(d.colors.background),this._staticGraphics.strokeWeight(B.getRelativeWidth(this._p,t)),this._staticGraphics.noFill(),this._staticGraphics.stroke(d.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,o=t.value,s=i.x,a=i.y,u=this._cellPreCalculatedGeometry,c=u.innerOffset,l=u.innerSize,h=u.paddingOffset,p=u.paddingSize,d=u.strokeWeight;n=0===o||!e.isPlaying()&&!e.isPaused()?r.INACTIVE:e.isColorEnabled()?n:r.DEFAULT,this._p.push(),this._p.translate(this._rendererMetrics.display.origin.x+s*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+a*this._rendererMetrics.cell.size),this._p.strokeWeight(d),this._p.stroke(n),this._p.noFill(),this._p.rect(c,c,l,l),this._p.fill(n),this._p.rect(h,h,p,p),this._p.pop()},t.prototype.renderGrid=function(t,e){var i=this;t.forEach(function(t){t.forEach(function(t){i.renderCell(t,e)})})},t}();const z=k;var H=function(){function t(){}return t.getRelativeCoordinate=function(t,e){return{x:B.getRelativeWidth(t,e.x),y:B.getRelativeHeight(t,e.y)}},t.getDisplayPosX=function(t,e,i){var n=d.screenLayout.display.margin;return i*e+B.getRelativeWidth(t,n)},t.getDisplayPosY=function(t,e,i){var n=d.screenLayout.display.margin;return i*e+B.getRelativeHeight(t,n)},t.getHudPosX=function(t,e,i){var n=d.screenLayout.display.margin,r=i+2*B.getRelativeWidth(t,n);return(t.width-r-B.getRelativeWidth(t,n))*e+r},t.getHudPosY=function(t,e,i){var n=d.screenLayout.display.margin;return i*e+B.getRelativeHeight(t,n)},t}();const N=H;var F=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:N.getHudPosX(this._p,.078,t.display.width),y:N.getHudPosY(this._p,.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-B.getRelativeWidth(this._p,.005),y:this._gridOrigin.y-B.getRelativeHeight(this._p,.005),w:4*this._cellSize+B.getRelativeWidth(this._p,.01),h:4*this._cellSize+B.getRelativeHeight(this._p,.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=t.text,i=t.state,n=t.score;this._p.push(),e.setTextSize(s.SMALL),e.setInactiveText(),e.setTextAlign(o.LEFT,a.BOTTOM),e.textOnHud("88888888",{x:.05,y:.13}),e.textOnHud("88888888",{x:.05,y:.3}),e.textOnHud("88 - 88",{x:.05,y:.8}),i.isOn()&&e.setActiveText(),e.textOnHud("Score",{x:.05,y:.06}),e.textOnHud(n.score.toString(),{x:.05,y:.13}),e.textOnHud("Hi-Score",{x:.05,y:.23}),e.textOnHud(n.highScore.toString(),{x:.05,y:.3}),e.textOnHud("Level",{x:.05,y:.72});var r="".concat(n.level<10?"0"+n.level:n.level," - ").concat(n.maxLevel);e.textOnHud(r,{x:.05,y:.8}),e.setTextAlign(o.CENTER,a.BOTTOM),i.isPaused()?e.setActiveText():e.setInactiveText(),e.textOnHud("Paused",{x:.5,y:.9}),i.isOn()&&i.isMuted()?e.setActiveText():e.setInactiveText(),e.textOnHud("Muted",{x:.5,y:.97}),this._p.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=t.hudGrid,n=t.state;this._p.push(),i.forEach(function(t){var i=t.coordinate,o=i.x,s=i.y;n.isOff()&&!n.isPlaying()&&(t.value=0);var a=0!==t.value?r.DEFAULT:r.INACTIVE;n.isColorEnabled()&&0!==t.value&&(a=t.color),e.drawCellElement({w:e._cellSize,h:e._cellSize,posX:e._gridOrigin.x+e._cellSize*o,posY:e._gridOrigin.y+e._cellSize*s,color:a})}),this._p.noFill(),this._p.stroke(n.isOn()?r.DEFAULT:r.INACTIVE),this._p.rect(this._hudBorderRect.x,this._hudBorderRect.y,this._hudBorderRect.w,this._hudBorderRect.h),this._p.pop()},t.prototype.drawCellElement=function(t){var e=t.w,i=t.posX,n=t.posY,r=t.color,o=d.screenLayout.cell,s=o.margin,a=o.padding,u=s*e,c=e-s*e*2,l=a*e,h=e-a*e*2,p=o.strokeWeight*e;this._p.push(),this._p.translate(i,n),this._p.strokeWeight(p),this._p.stroke(r),this._p.noFill(),this._p.rect(u,u,c,c),this._p.fill(r),this._p.rect(l,l,h,h),this._p.pop()},t}();const j=F;var U=function(){function t(t){this._p=t}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new z(this._p),this._hudRenderer=new j(this._p),this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=d.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=d.screenLayout.grid.columns,o=B.getRelativeWidth(this._p,e),s=B.getRelativeHeight(this._p,i),a=N.getRelativeCoordinate(this._p,{x:n,y:n}),u=o/r,c={x:N.getHudPosX(this._p,0,o),y:N.getHudPosY(this._p,0,s)},l=N.getHudPosX(this._p,1,o)-c.x,h=N.getHudPosY(this._p,1,s)-c.y;this._rendererMetrics={display:{width:o,height:s,origin:a},hud:{width:l,height:h,origin:c},cell:{size:u}}},t.prototype.render=function(t,e){this._renderers.forEach(function(i){return i.render(t,e)})},Object.defineProperty(t.prototype,"rendererMetrics",{get:function(){return this._rendererMetrics},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{display_width:this._rendererMetrics.display.width.toFixed(2),display_height:this._rendererMetrics.display.height.toFixed(2),hud_width:this._rendererMetrics.hud.width.toFixed(2),hud_height:this._rendererMetrics.hud.height.toFixed(2),cell_size:this._rendererMetrics.cell.size.toFixed(2)}},t}();const W=U;var V,K=((V={})[h.ON]={defaultValue:!1},V[h.START]={defaultValue:!1},V[h.PLAYING]={defaultValue:!1},V[h.GAME_OVER]={defaultValue:!1},V[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},V[h.MUTED]={defaultValue:!1,storageKey:"muted"},V),Y=function(){function t(){this._state=new Map,this._subscribers=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=K[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=K[e];if(i.storageKey){var n=localStorage.getItem(i.storageKey);null!==n&&t._state.set(e,JSON.parse(n))}})},t.prototype._set=function(t,e){if(this._state.get(t)!==e){this._state.set(t,e);var i=K[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this._notify(t,e)}},t.prototype._notify=function(t,e){var i=this._subscribers.get(t);i&&i.forEach(function(t){return t(e)})},t.prototype.isOn=function(){return this._state.get(h.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(h.START)},t.prototype.isPlaying=function(){return this._state.get(h.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(h.GAME_OVER)},t.prototype.turnOn=function(){this._set(h.ON,!0),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(h.ON,!1),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(h.START,!0),this._set(h.PLAYING,!0),this._set(h.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0)},t.prototype.exitGame=function(){this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(h.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(h.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(h.MUTED)},t.prototype.setMuted=function(t){this._set(h.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.subscribe=function(t,e){var i;this._subscribers.has(t)||this._subscribers.set(t,[]),null===(i=this._subscribers.get(t))||void 0===i||i.push(e)},t.prototype.unsubscribe=function(t,e){var i=this._subscribers.get(t);i&&this._subscribers.set(t,i.filter(function(t){return t!==e}))},t.prototype.getDebugData=function(){return{on:this.isOn(),start:this.isStarted(),playing:this.isPlaying(),paused:this.isPaused(),game_over:this.isGameOver(),color_enabled:this.isColorEnabled(),muted:this.isMuted()}},t}();const X=Y;var J=function(){function t(t){this.defaultFontFamily="retro-gamming",this.fontSizes=[0],this._p=t}return t.prototype.setup=function(){var t=d.screenLayout.fontSize,e=t.extraSmall,i=t.small,n=t.medium,r=t.large,o=t.extraLarge;this._p.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=B.getRelativeWidth(this._p,e),this.fontSizes[s.SMALL]=B.getRelativeWidth(this._p,i),this.fontSizes[s.MEDIUM]=B.getRelativeWidth(this._p,n),this.fontSizes[s.LARGE]=B.getRelativeWidth(this._p,r),this.fontSizes[s.EXTRA_LARGE]=B.getRelativeWidth(this._p,o)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=d.colors,i=e.active,n=e.inactive;this._p.fill(t?i:n)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setTextSize=function(t){this._p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){this._p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=N.getHudPosX(this._p,e.x,this._rendererMetrics.display.width),n=N.getHudPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.textOnDisplay=function(t,e){var i=N.getDisplayPosX(this._p,e.x,this._rendererMetrics.display.width),n=N.getDisplayPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const q=J,Q=function(){function t(){this._accumulatedTime=0,this._initialTickInterval=d.game.tickInterval,this._minTickInterval=d.game.minTickInterval,this._tickInterval=d.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._accumulatedTime+=t,this._fps=1e3/t,this._timeSinceLastTpsUpdate+=t,this._timeSinceLastTpsUpdate>=1e3&&(this._tps=this._tickCounter,this._tickCounter=0,this._timeSinceLastTpsUpdate-=1e3)},t.prototype.shouldTick=function(){return this._accumulatedTime>=this._tickInterval&&(this._accumulatedTime-=this._tickInterval,this._tickCounter++,!0)},t.prototype.reset=function(){this._accumulatedTime=0,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this._tickInterval=this._initialTickInterval},Object.defineProperty(t.prototype,"tickInterval",{get:function(){return this._tickInterval},set:function(t){this._tickInterval=t},enumerable:!1,configurable:!0}),t.prototype.incrementTickInterval=function(t){this.tickInterval=this._tickInterval+t},t.prototype.decrementTickInterval=function(t){var e=Math.max(this._minTickInterval,this._tickInterval-t);this.tickInterval=e},t.prototype.getDebugData=function(){return{fps:Math.round(this._fps),tps:this._tps,tick_interval:this._tickInterval.toFixed(2),accumulated_time:this._accumulatedTime.toFixed(2)}},t.prototype.serialize=function(){return JSON.stringify({tickInterval:this._tickInterval})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._tickInterval=e.tickInterval},t.prototype.setTickInterval=function(t){this._tickInterval=t},t.prototype.setMinTickInterval=function(t){this._minTickInterval=t},t}();var $=function(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())})},Z=function(t,e){var i,n,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(i=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},tt=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=d.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return $(this,void 0,void 0,function(){var e,i,n;return Z(this,function(r){return"suspended"===this._audioContext.state&&this._audioContext.resume(),(e=this._buffers.get(t))?((i=this._audioContext.createBufferSource()).buffer=e,i.connect(this._gainNode),this._activeSources.has(t)||this._activeSources.set(t,[]),(n=this._activeSources.get(t)).push(i),i.onended=function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)},i.start(0),[2]):(console.warn("Sound buffer not found for: ".concat(t)),[2])})})},t.prototype.stop=function(t){return $(this,void 0,void 0,function(){var e;return Z(this,function(i){return(e=this._activeSources.get(t))&&(e.forEach(function(t){try{t.stop()}catch(t){}}),e.length=0),[2]})})},t.prototype.stopAll=function(){return $(this,void 0,void 0,function(){var t,e,i,n;return Z(this,function(r){switch(r.label){case 0:t=Array.from(this._activeSources.keys()),e=0,i=t,r.label=1;case 1:return e<i.length?(n=i[e],[4,this.stop(n)]):[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},t.prototype._updateGain=function(){var t=!!this._state&&this._state.isMuted();this._gainNode&&(t?this._gainNode.gain.setValueAtTime(0,this._audioContext.currentTime):this._gainNode.gain.setValueAtTime(this._volume,this._audioContext.currentTime))},t.prototype._loadAll=function(){return $(this,void 0,void 0,function(){var t,e=this;return Z(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return $(e,void 0,void 0,function(){var e,i,n;return Z(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),[4,fetch(t)];case 1:return[4,r.sent().arrayBuffer()];case 2:return e=r.sent(),[4,this._audioContext.decodeAudioData(e)];case 3:return i=r.sent(),this._buffers.set(t,i),[3,5];case 4:return n=r.sent(),console.error("Failed to load sound: ".concat(t),n),[3,5];case 5:return[2]}})})}),[4,Promise.all(t)];case 1:return i.sent(),[2]}})})},t.prototype.toggleMute=function(){this._state.toggleMuted(),this._updateGain()},t.prototype.syncState=function(t){var e=this;this._state=t,t.subscribe(h.MUTED,function(){e._updateGain()}),this._updateGain()},t.prototype.getDebugData=function(){var t=0;return this._activeSources.forEach(function(e){return t+=e.length}),{muted:!!this._state&&this._state.isMuted(),volume:this._volume,active_sources:t,loaded_buffers:this._buffers.size}},t}();const et=tt,it=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this.serialId="score"}return t.prototype.setup=function(){this._highScore=Number(localStorage.getItem("highScore"))},t.prototype.increaseScore=function(t){this._score+=t*this._multiplier,this._score>this._highScore&&(this.highScore=this._score)},t.prototype.resetScore=function(){this._score=0},t.prototype.getFormattedScore=function(t){return void 0===t&&(t=6),this._score.toString().padStart(t,"0")},t.prototype.increaseLevel=function(t){this._level+=t},t.prototype.resetLevel=function(){this._level=1},Object.defineProperty(t.prototype,"multiplier",{get:function(){return this._multiplier},set:function(t){this._multiplier=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"level",{get:function(){return this._level},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxLevel",{get:function(){return this._maxLevel},set:function(t){this._maxLevel=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"highScore",{get:function(){return this._highScore},set:function(t){this._highScore=t,localStorage.setItem("highScore",t.toString())},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel}},t.prototype.serialize=function(){return JSON.stringify({score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._score=e.score,this._multiplier=e.multiplier,this._level=e.level,this._maxLevel=e.max_level},t}();var nt,rt=(nt=function(t,e){return nt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},nt(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}nt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const ot=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return rt(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return 4},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return 4},enumerable:!1,configurable:!0}),e.prototype.serialize=function(){return JSON.stringify({grid:this._grid})},e.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},e}(A),st=function(){function t(){}return t.isSerializable=function(t){if(null==t)return!1;var e=t,i="function"==typeof e.serialize,n="function"==typeof e.deserialize,r="string"==typeof e.serialId;return i&&n&&r},t.isInitializable=function(t){return null!=t&&"function"==typeof t.setup},t.isStateSyncable=function(t){if(null==t)return!1;var e=t;return"function"==typeof e.syncState&&!(e instanceof X)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var at=function(){function t(){this._initialState=new Map,this._baseProperties=[]}return t.prototype.captureBaseProperties=function(t){this._baseProperties=Object.keys(t)},t.prototype.captureInitialState=function(t){var e=this;console.log("capturing initial state for snapshot"),Object.entries(t).forEach(function(t){var i=t[0],n=t[1];if(!e._baseProperties.includes(i)&&"function"!=typeof n){var r=n;try{r=structuredClone(n),console.log("capturing property",i,r)}catch(t){console.error("Failed to clone property ".concat(i,":"),t)}e._initialState.set(i,r)}})},t.prototype.restoreInitialState=function(t){console.log("restoring initial snapshot"),this._initialState.forEach(function(e,i){t[i]=e,console.log("restoring property",i,e)})},t}();const ut=at,ct=function(){function t(){this._isModalClosed=!1,this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isModalClosed&&!this._isGameMenuInstance()&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype._isGameMenuInstance=function(){return"game-menu"===this.gameId},t.prototype._hasSession=function(){var t=this;return this._serializables.every(function(e){return null!==localStorage.getItem(t._key(e.serialId))})},t.prototype._loadSession=function(){var t=this;this._serializables.forEach(function(e){var i=localStorage.getItem(t._key(e.serialId));i&&e.deserialize(i)})},t.prototype._destroySession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!1===e._isModalClosed){if(!e._hasSession()||e._isGameMenuInstance())return void(e._isModalClosed=!0);e._showSessionModal(function(){e._hasSession()&&!e._isGameMenuInstance()&&e._loadSession(),e._isModalClosed=!0},function(){e._destroySession(),e._isModalClosed=!0})}}),t.subscribe(h.GAME_OVER,function(t){t&&e._destroySession()}),t.subscribe(h.ON,function(t){t||(e._isModalClosed=!1)})},t.prototype.getDebugData=function(){return{gameId:this.gameId,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}();var lt=function(){function t(t,e){this._modules=void 0,this._initialStateSnapshot=new ut,this._gameId="unknown",this._switchHandler=void 0,this._p=t,this._view=e,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),t.prototype.setSwitchHandler=function(t){this._switchHandler=t},t.prototype.propagateSwitchHandler=function(t){this.setSwitchHandler(t._switchHandler)},Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),t.prototype.switchGame=function(t){this.destroy(),this._switchHandler?this._switchHandler(t):console.error("Game switch handler not registered. Cannot switch game.")},Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new W(this._p),grid:new A,hudGrid:new ot,text:new q(this._p),state:new X,control:new m,time:new Q,sound:new et,score:new it,session:new ct},Object.values(this._modules).forEach(function(t){st.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){st.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){st.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,r=e.renderer,o=e.session;o.gameId=this.gameId,o.setShowModalFunction(this._view.showSessionModal.bind(this._view)),n.setModules(this._modules),i.setRendererMetrics(r.rendererMetrics),this.setupGame(),this._initialStateSnapshot.captureInitialState(this),this._subscribeSystemControls(),this._view.bindControls(n)},t.prototype.draw=function(){if(this._modules){var t=this._modules,e=t.renderer,i=t.grid,n=t.time,r=t.state;e.render(i.getGrid(),this._modules),r.isOn()&&(r.isStarted()?r.isPlaying()?(n.update(this._p.deltaTime),n.shouldTick()&&(this.update(this._p.deltaTime),this._modules.session.saveSession()),this.render()):r.isPaused()&&this.render():this.drawTitleScreen(),r.isGameOver()&&this.drawGameOverScreen())}},t.prototype.destroy=function(){this._p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},Object.defineProperty(t.prototype,"p",{get:function(){return this._p},enumerable:!1,configurable:!0}),t.prototype._subscribeSystemControls=function(){var t=this,e=this._modules,i=e.control,n=e.state,r=e.grid;i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),t.modules.sound.stopAll()):n.turnOn()}),i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.RESET,l.PRESSED,function(){r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset(),t._modules.session.clearSession(),n.resetGame(),t._initialStateSnapshot.restoreInitialState(t)}),i.subscribe(c.EXIT,l.PRESSED,function(){t._modules.session.clearSession()}),i.subscribe(c.START_PAUSE,l.PRESSED,function(){n.isStarted()?n.isPlaying()?n.pause():n.isPaused()?n.resume():n.isGameOver()&&(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset(),t.modules.session.clearSession(),t._initialStateSnapshot.restoreInitialState(t),n.resetGameOver()):n.startGame()}),n.subscribe(h.ON,function(e){e||(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset())})},t}();const ht=lt;var pt={grad:.9,turn:360,rad:360/(2*Math.PI)},dt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},ft=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},gt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},yt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:gt(t.r,0,255),g:gt(t.g,0,255),b:gt(t.b,0,255),a:gt(t.a)}},mt=function(t){return{r:ft(t.r),g:ft(t.g),b:ft(t.b),a:ft(t.a,3)}},vt=/^#([0-9a-f]{3,8})$/i,bt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},wt=function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=Math.max(e,i,n),s=o-Math.min(e,i,n),a=s?o===e?(i-n)/s:o===i?2+(n-e)/s:4+(e-i)/s:0;return{h:60*(a<0?a+6:a),s:o?s/o*100:0,v:o/255*100,a:r}},Et=function(t){var e=t.h,i=t.s,n=t.v,r=t.a;e=e/360*6,i/=100,n/=100;var o=Math.floor(e),s=n*(1-i),a=n*(1-(e-o)*i),u=n*(1-(1-e+o)*i),c=o%6;return{r:255*[n,a,s,s,u,n][c],g:255*[u,n,n,a,s,s][c],b:255*[s,s,u,n,n,a][c],a:r}},St=function(t){return{h:yt(t.h),s:gt(t.s,0,100),l:gt(t.l,0,100),a:gt(t.a)}},xt=function(t){return{h:ft(t.h),s:ft(t.s),l:ft(t.l),a:ft(t.a,3)}},Ct=function(t){return Et((i=(e=t).s,{h:e.h,s:(i*=((n=e.l)<50?n:100-n)/100)>0?2*i/(n+i)*100:0,v:n+i,a:e.a}));var e,i,n},Rt=function(t){return{h:(e=wt(t)).h,s:(r=(200-(i=e.s))*(n=e.v)/100)>0&&r<200?i*n/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,n,r},Pt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Ot=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Tt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It={string:[[function(t){var e=vt.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?ft(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?ft(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Tt.exec(t)||Mt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:_t({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Pt.exec(t)||Ot.exec(t);if(!e)return null;var i,n,r=St({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(pt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Ct(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=void 0===r?1:r;return dt(e)&&dt(i)&&dt(n)?_t({r:Number(e),g:Number(i),b:Number(n),a:Number(o)}):null},"rgb"],[function(t){var e=t.h,i=t.s,n=t.l,r=t.a,o=void 0===r?1:r;if(!dt(e)||!dt(i)||!dt(n))return null;var s=St({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return Ct(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!dt(e)||!dt(i)||!dt(n))return null;var s=function(t){return{h:yt(t.h),s:gt(t.s,0,100),v:gt(t.v,0,100),a:gt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(o)});return Et(s)},"hsv"]]},Dt=function(t,e){for(var i=0;i<e.length;i++){var n=e[i][0](t);if(n)return[n,e[i][1]]}return[null,void 0]},Lt=function(t,e){var i=Rt(t);return{h:i.h,s:gt(i.s+100*e,0,100),l:i.l,a:i.a}},At=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Gt=function(t,e){var i=Rt(t);return{h:i.h,s:i.s,l:gt(i.l+100*e,0,100),a:i.a}},Bt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Dt(t.trim(),It.string):"object"==typeof t&&null!==t?Dt(t,It.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return ft(At(this.rgba),2)},t.prototype.isDark=function(){return At(this.rgba)<.5},t.prototype.isLight=function(){return At(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=mt(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?bt(ft(255*r)):"","#"+bt(e)+bt(i)+bt(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return mt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=mt(this.rgba)).r,i=t.g,n=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+n+", "+r+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,r},t.prototype.toHsl=function(){return xt(Rt(this.rgba))},t.prototype.toHslString=function(){return e=(t=xt(Rt(this.rgba))).h,i=t.s,n=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+n+"%, "+r+")":"hsl("+e+", "+i+"%, "+n+"%)";var t,e,i,n,r},t.prototype.toHsv=function(){return t=wt(this.rgba),{h:ft(t.h),s:ft(t.s),v:ft(t.v),a:ft(t.a,3)};var t},t.prototype.invert=function(){return kt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),kt(Lt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),kt(Lt(this.rgba,-t))},t.prototype.grayscale=function(){return kt(Lt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),kt(Gt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),kt(Gt(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?kt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):ft(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Rt(this.rgba);return"number"==typeof t?kt({h:t,s:e.s,l:e.l,a:e.a}):ft(e.h)},t.prototype.isEqual=function(t){return this.toHex()===kt(t).toHex()},t}(),kt=function(t){return t instanceof Bt?t:new Bt(t)};function zt(t,e,i){var n=t.createDiv();n.parent(e),n.addClass("btn-container");var r=t.createButton(i);return r.parent(n),r.addClass("btn"),r}function Ht(t,e,i,n){var r=t.createDiv();r.parent(e),r.addClass("sm-btn-container"),r.addClass(n?"sm-btn-container-top":"sm-btn-container-bottom");var o=t.createButton("");o.parent(r),o.addClass("sm-btn");var s=t.createP(i);return s.parent(r),s.addClass("sm-btn-p"),o}var Nt=function(){function t(t,e){this._moduleElements=[],this._gameModules=t,this._p=e}return t.prototype.setup=function(){var t=this;if(d.game.debugger.enabled){var e=this._p.select("#debugger"),i=!!e&&e.elt.hasAttribute("open"),n=new Set;e&&(this._p.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&n.add(t.id())}),e.remove()),this._moduleElements=[];var r=this._p.createElement("details");r.id("debugger"),i&&r.attribute("open",""),r.parent(this._p.select("body"));var o=this._p.createElement("summary");o.id("debugger-summary"),o.html("Debug"),o.parent(r),Object.entries(this._gameModules).forEach(function(e){var i=e[0],o=e[1];if("getDebugData"in o){var s={module:o,properties:[]},a=t._p.createElement("details");a.class("debugger-module"),a.id("debugger-".concat(i)),n.has("debugger-".concat(i))&&a.attribute("open",""),a.parent(r);var u=t._p.createElement("summary");u.id("debugger-".concat(i,"-summary")),u.html(i),u.class("debugger-module-summary"),u.parent(a);var c=o.getDebugData();Object.entries(c).forEach(function(e){var i=e[0],n=e[1],r=t._p.createElement("div");r.class("debugger-container"),r.id("debugger-container-".concat(i,"-").concat(n)),r.parent(a),r.mouseClicked(function(){r.toggleClass("highlight")});var o=t._p.createElement("p");o.id("debugger-".concat(i,"-").concat(n)),o.html("".concat(i,":")),o.parent(r);var u=t._p.createElement("span");u.id("debugger-".concat(i,"-").concat(n,"-value")),u.html("".concat(n)),u.parent(r),s.properties.push({key:i,element:u})}),t._moduleElements.push(s)}})}},t.prototype.setGameModules=function(t){this._gameModules=t,this.setup()},t.prototype.update=function(){this._moduleElements.forEach(function(t){var e=t.module.getDebugData();t.properties.forEach(function(t){t.element.html("".concat(e[t.key]))})})},t}();const Ft=Nt;var jt=function(){function t(t){this._p=t}return t.prototype.setup=function(){this._container=this._p.createDiv(),this._container.parent(this._p.select("body")),this._container.id("modal-background"),this._container.class("hidden");var t=this._p.createDiv();t.parent(this._container),t.id("session-modal");var e=this._p.createDiv();e.parent(t),e.id("session-modal-frame");var i=this._p.createP();i.parent(e),i.html("Brick Engine Session");var n=this._p.createDiv();n.parent(e),n.id("session-modal-screen");var r=this._p.createP();r.parent(n),r.html("<span>Looks like you have an active session.</span><br><br>Do you want to continue?");var o=this._p.createDiv();o.parent(t),o.id("session-modal-buttons"),this._cancelButton=this._p.createButton("Cancel"),this._cancelButton.parent(o),this._cancelButton.class("session-modal-button"),this._confirmButton=this._p.createButton("Confirm"),this._confirmButton.parent(o),this._confirmButton.class("session-modal-button")},t.prototype.show=function(t,e){var i=this;this._confirmButton.mousePressed(function(){t(),i._hide()}),this._cancelButton.mousePressed(function(){e(),i._hide()}),this._container.removeClass("hidden")},t.prototype._hide=function(){this._confirmButton.mousePressed(null),this._cancelButton.mousePressed(null),this._container.addClass("hidden")},t}();const Ut=jt;var Wt=function(){function t(t,e){this._parent=e,this._p=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,r;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(d.inputQueryParams.mainColor)?i.get(d.inputQueryParams.mainColor):d.colors.bodyMain,r=i.has(d.inputQueryParams.buttonColor)?i.get(d.inputQueryParams.buttonColor):d.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",kt(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",kt(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",kt(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",kt(r).darken(.15).toHex());var o=function(t,e){var i,n=t.createDiv();if(n.parent(d.selectors.parent),n.id(d.selectors.viewElementIds.container),e.clientWidth<=d.viewLayout.mobileBreakpoint)return{container:n,width:i=e.clientWidth,height:e.clientHeight};var r=e.clientHeight/(1.05*d.viewLayout.bodyHeightWidthMultiplier);return{container:n,width:i=Math.min(e.clientWidth,r),height:i*d.viewLayout.bodyHeightWidthMultiplier}}(this._p,this._parent),s=o.container,a=o.height,u=o.width,c=function(t,e){var i=t.createDiv();i.parent(e),i.id(d.selectors.viewElementIds.frame);var n=t.createDiv();return n.parent(i),t.createP("Brick Game").parent(n),i}(this._p,s),l=function(t,e,i){var n=i*d.viewLayout.canvas.widthRatio,r=n*d.viewLayout.canvas.aspectRatio,o=t.createCanvas(n,r);return o.parent(e),o.id(d.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:r,canvas:o}}(this._p,c,u),h=l.canvas,p=l.canvasHeight,f=l.canvasWidth,g=function(t,e){var i=t.createDiv();i.parent(e),i.id(d.selectors.viewElementIds.buttonContainer);var n=t.createDiv();n.parent(i),n.id(d.selectors.viewElementIds.smallButtonContainer);var r=t.createDiv();r.parent(i),r.id(d.selectors.viewElementIds.innerButtonContainer);var o=t.createDiv();o.parent(r),o.id(d.selectors.viewElementIds.mediumButtonContainer);var s=t.createDiv();s.parent(o),s.id(d.selectors.viewElementIds.directionVerticalContainer);var a=t.createDiv();a.parent(o),a.id(d.selectors.viewElementIds.directionHorizontalContainer);var u=t.createDiv();return u.parent(r),u.id(d.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(this._p,s),y=g.largeButtonContainer,_=g.smallButtonContainer,m=g.directionHorizontalContainer,v=g.directionVerticalContainer;return this._onOffBtn=Ht(this._p,_,"On<br/>Off",!0),this._startPauseBtn=Ht(this._p,_,"Start<br/>Pause",!1),this._soundBtn=Ht(this._p,_,"Sound",!0),this._resetBtn=Ht(this._p,_,"Reset",!1),this._exitBtn=Ht(this._p,_,"Exit",!0),this._enableColorBtn=Ht(this._p,_,"Enable<br/>Colors",!1),this._upBtn=zt(this._p,v,"UP"),this._leftBtn=zt(this._p,m,"LEFT"),this._downBtn=zt(this._p,v,"DOWN"),this._rightBtn=zt(this._p,m,"RIGHT"),this._actionBtn=function(t,e){var i=t.createDiv();i.parent(e),i.addClass("lg-btn-container");var n=t.createButton("Action");return n.parent(i),n.addClass("lg-btn"),n}(this._p,y),function(t,e,i,n){var r=document.querySelector(":root");r.style.setProperty("--dispersion",d.viewLayout.shadowDispersion),r.style.setProperty("--width","".concat(t,"px")),r.style.setProperty("--height","".concat(e,"px")),r.style.setProperty("--canvas-width","".concat(i,"px")),r.style.setProperty("--canvas-height","".concat(n,"px")),r.style.setProperty("--border-radius","".concat(t*d.viewLayout.dimensions.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*d.viewLayout.dimensions.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*d.viewLayout.dimensions.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*d.viewLayout.dimensions.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*d.viewLayout.dimensions.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*d.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*d.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*d.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*d.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*d.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*d.viewLayout.dimensions.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*d.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*d.viewLayout.dimensions.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*d.viewLayout.dimensions.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",d.viewLayout.dimensions.button.animationDuration)}(u,a,f,p),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:p},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Ut(this._p),this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new Ft(t,this._p),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=d.viewLayout.splashHideDelayMs);var e=document.querySelector(d.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Vt=Wt;var Kt=n(991),Yt=n.n(Kt),Xt=function(){function t(){this._games=[{id:"loading",name:"Loading...",url:""}],this.fetchGames()}return t.prototype.fetchGames=function(){return t=this,e=void 0,n=function(){var t,e,i,n;return function(t,e){var i,n,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(i=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),t={},[4,fetch("".concat("http://127.0.0.1:54321","/functions/v1/list"),{headers:t})];case 1:if(!(e=r.sent()).ok)throw new Error("Error fetching games: ".concat(e.statusText));return[4,e.json()];case 2:return(i=r.sent())&&i.games&&i.games.length>0?this._games=i.games.map(function(t){return{id:t.id,name:t.name,url:t.url}}):this._games=[{id:"empty",name:"Not found",url:""}],[3,4];case 3:return n=r.sent(),console.error(n),this._games=[{id:"error",name:"Error",url:""}],[3,4];case 4:return[2]}})},new((i=void 0)||(i=Promise))(function(r,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())});var t,e,i,n},Object.defineProperty(t.prototype,"games",{get:function(){return Object.freeze(this._games)},enumerable:!1,configurable:!0}),t}();const Jt=Xt;var qt=function(){function t(){}return t.prototype.handleGameSwitch=function(t,e){return i=this,n=void 0,o=function(){var i,n;return function(t,e){var i,n,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(i=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._loadGameScript(t.url)];case 1:return r.sent(),console.log("Game instance defined on window.BrickEngineGame by client project: ",window.BrickEngineGame),window.BrickEngineGame?(i=new window.BrickEngineGame(e.p,e.view),console.log("Game loaded: ",t.name),console.log("Game loaded: ",t.name),i.gameId=t.id,console.log("Switching to game"),e.switchGame(i),console.log("Game switched"),console.log("Cleaning up window.BrickEngineGame"),delete window.BrickEngineGame):console.error("Game bundle loaded but window.BrickEngineGame was not set."),[3,3];case 2:return n=r.sent(),console.error("Failed to load game:",n),[3,3];case 3:return[2]}})},new((r=void 0)||(r=Promise))(function(t,e){function s(t){try{u(o.next(t))}catch(t){e(t)}}function a(t){try{u(o.throw(t))}catch(t){e(t)}}function u(e){var i;e.done?t(e.value):(i=e.value,i instanceof r?i:new r(function(t){t(i)})).then(s,a)}u((o=o.apply(i,n||[])).next())});var i,n,r,o},t.prototype._loadGameScript=function(t){return new Promise(function(e,i){var n=document.getElementById("game-client-script");n&&n.remove();var r=document.createElement("script");r.src=t,r.id="game-client-script",r.onload=function(){return e()},r.onerror=function(){return i(new Error("Failed to load script ".concat(t)))},document.head.appendChild(r)})},t}();const Qt=qt;var $t=function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Zt=function(t){function e(e,i){var n=t.call(this,e,i)||this;return n._gameSelectionPointer=0,n._isLoading=!1,n._gameRepository=new Jt,n._gameManager=new Qt,n}return $t(e,t),e.prototype.setupGame=function(){var t=this,e=this.modules,i=e.state,n=e.control,r=e.sound;n.subscribe(c.ACTION,l.PRESSED,function(){if(!t._isLoading&&i.isStarted()){var e=t._gameRepository.games[t._gameSelectionPointer];t._gameManager.handleGameSwitch(e,t)}}),n.subscribe(c.LEFT,l.PRESSED,function(){i.isPlaying()&&(r.play(u.ACTION_1),0===t._gameSelectionPointer?t._gameSelectionPointer=t._gameRepository.games.length-1:t._gameSelectionPointer--)}),n.subscribe(c.RIGHT,l.PRESSED,function(){i.isPlaying()&&(r.play(u.ACTION_1),t._gameSelectionPointer===t._gameRepository.games.length-1?t._gameSelectionPointer=0:t._gameSelectionPointer++)}),i.subscribe(h.ON,function(t){t&&r.play(u.START_THEME)})},e.prototype.update=function(){},e.prototype.render=function(){var t=this.modules.text,e=this.p;e.push(),t.setTextSize(s.LARGE),t.setActiveText(),t.setTextAlign(o.CENTER,a.BOTTOM),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(s.SMALL),t.textOnDisplay("Choose a game and",{x:.5,y:.25}),t.textOnDisplay("Press action to play",{x:.5,y:.32}),t.setTextAlign(o.RIGHT,a.BOTTOM),t.textOnDisplay("<",{x:.1,y:.54}),t.setTextAlign(o.LEFT,a.BOTTOM),t.textOnDisplay(">",{x:.9,y:.54}),t.setTextSize(s.MEDIUM),t.setTextAlign(o.CENTER,a.BOTTOM),t.textOnDisplay(this._gameRepository.games[this._gameSelectionPointer].name,{x:.5,y:.55}),t.setTextSize(s.EXTRA_SMALL),t.setTextAlign(o.LEFT,a.BOTTOM),t.textOnDisplay("Left: Previous option",{x:.05,y:.78}),t.textOnDisplay("Right: Next option",{x:.05,y:.84}),t.textOnDisplay("Action: Select",{x:.05,y:.9}),e.pop()},e.prototype.drawTitleScreen=function(){var t=this.modules.text;this.p.push(),t.setTextSize(s.LARGE),t.setActiveText(),t.setTextAlign(o.CENTER,a.TOP),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(s.SMALL),t.textOnDisplay("Wellcome to your",{x:.5,y:.25}),t.textOnDisplay("favorite brick game",{x:.5,y:.32}),t.textOnDisplay("simulator!",{x:.5,y:.39}),t.textOnDisplay("Press start",{x:.5,y:.66}),t.textOnDisplay("to continue.",{x:.5,y:.72}),this.p.pop()},e.prototype.drawGameOverScreen=function(){},e}(ht);const te=Zt,ee=function(){function t(){}return t.setInstance=function(e){t._instance=e},t.getInstance=function(){return t._instance},t.hasInstance=function(){return void 0!==t._instance},t}();var ie,ne,re=function(t){try{ie.view.unbindControls(),t.propagateSwitchHandler(ie),t.setup();var e=t.modules,i=e.control,n=e.state;t.view.updateDebuggerGameModules(t.modules),t.view.bindControls(i),n.turnOn(),ee.hasInstance()&&t!==ee.getInstance()&&(i.subscribe(c.EXIT,l.PRESSED,function(){t.switchGame(ee.getInstance())}),i.subscribe(c.POWER,l.PRESSED,function(){t.switchGame(ee.getInstance()),n.turnOff()})),ie=t}catch(t){console.error("Error switching game:",t)}ne.loop()};function oe(t){return window.BrickEngineGame=t,new(Yt())(function(e){ne=e;var i=new Vt(e,document.body);t===te?((ie=new t(e,i)).gameId="game-menu",ee.setInstance(ie)):(ie=new t(e,i)).gameId="game",ie.setSwitchHandler(re),e.setup=function(){ie.setup(),ie.view.setupDebugger(ie.modules),ie.view.setupSessionModal()},e.draw=function(){ie.draw(),ie.view.updateDebugger()}})}return p})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return e[t](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r,o,s,a,u,c,l,h,d={};n.r(d),n.d(d,{Color:()=>r,ControlEventType:()=>l,ControlKey:()=>c,FontAlign:()=>o,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>ht,GameView:()=>Vt,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>qt,configs:()=>p,setActiveGame:()=>Jt}),function(t){t.DEFAULT="rgb(19, 26, 18)",t.BLUE="rgb(0, 0, 128)",t.CYAN="rgb(0, 128, 128)",t.GRAY="rgb(128, 128, 128)",t.GREEN="rgb(0, 128, 0)",t.PURPLE="rgb(128, 0, 128)",t.RED="rgb(128, 0, 0)",t.YELLOW="rgb(128, 128, 0)",t.INACTIVE="rgb(166, 183, 165)"}(r||(r={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(o||(o={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const p={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},p.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},p.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var _=function(){function t(){this._subscribers=new Map}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._subscribers.clear()},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribers.has(t)||this._subscribers.set(t,new Map);var n=this._subscribers.get(t);n.has(e)||n.set(e,new Set),n.get(e).add(i)},t.prototype.unsubscribe=function(t,e,i){var n=this._subscribers.get(t);if(n){var r=n.get(e);r&&r.delete(i)}},t.prototype.notify=function(t,e){var i;if(!this._modules)throw new Error("Modules not initialized");var n={key:t,type:e,modules:this._modules},r=this._modules.state,o=!1;r.isOff()?o=t===c.POWER:!r.isStarted()||r.isPlaying()||r.isGameOver()?o=!0:r.isPaused()&&(o=t.endsWith(";system"));var s=null===(i=this._subscribers.get(t))||void 0===i?void 0:i.get(e);s&&o&&s.forEach(function(t){return t(n)})},t.prototype.getDebugData=function(){var t=0;return this._subscribers.forEach(function(e){e.forEach(function(e){t+=e.size})}),{total_subscribers:t,tracked_keys:this._subscribers.size}},t}();const v=_,m=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:r.DEFAULT,coordinate:t}},t}();var b=function(){return b=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},b.apply(this,arguments)},E=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return b(b({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),r=n.some(function(e){return!i.grid.isValidCoordinate(e.coordinate)||i.grid.isCellActive(e.coordinate)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}));var n});return r?null:n},t.prototype.movePieceLeft=function(t){return this.movePiece(t,{x:-1,y:0})},t.prototype.movePieceRight=function(t){return this.movePiece(t,{x:1,y:0})},t.prototype.movePieceUp=function(t){return this.movePiece(t,{x:0,y:-1})},t.prototype.movePieceDown=function(t){return this.movePiece(t,{x:0,y:1})},t.prototype.moveCell=function(t,e){var i={x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)};return!this.grid.isValidCoordinate(i)||this.grid.isCellActive(i)?null:b(b({},t),{coordinate:i})},t.prototype.moveCellLeft=function(t){return this.moveCell(t,{x:-1,y:0})},t.prototype.moveCellRight=function(t){return this.moveCell(t,{x:1,y:0})},t.prototype.moveCellUp=function(t){return this.moveCell(t,{x:0,y:-1})},t.prototype.moveCellDown=function(t){return this.moveCell(t,{x:0,y:1})},t.prototype.getDropPath=function(t){for(var e=t,i=this.movePieceDown(e);null!==i;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);null!==i;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);null!==i;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);null!==i;)e=i,i=this.movePieceRight(e);return e},t}();const w=E;var S=function(){return S=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},S.apply(this,arguments)},C=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var r=t.map(function(t){var n=t.coordinate.x-e.x,r=t.coordinate.y-e.y,o=i?-r:r,s=i?n:-n;return S(S({},t),{coordinate:{x:e.x+o,y:e.y+s}})}),o=r.some(function(e){return!n.grid.isValidCoordinate(e.coordinate)||n.grid.isCellActive(e.coordinate)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}));var i});return o?null:r},t.prototype.mirrorPiece=function(t,e){if(0===t.length)return[];var i=this.getPieceBounds(t),n="x"===e?(i.min.x+i.max.x)/2:(i.min.y+i.max.y)/2;return t.map(function(t){return S(S({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const x=C;var R=function(){return R=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var r in e=arguments[i])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},R.apply(this,arguments)},P=function(){function t(t){this.grid=t}return t.prototype.getFullRows=function(){for(var t=[],e=0;e<this.grid.height;e++){for(var i=!0,n=0;n<this.grid.width;n++)if(!this.grid.isCellActive({x:n,y:e})){i=!1;break}i&&t.push(e)}return t},t.prototype.getFullColumns=function(){for(var t=[],e=0;e<this.grid.width;e++){for(var i=!0,n=0;n<this.grid.height;n++)if(!this.grid.isCellActive({x:e,y:n})){i=!1;break}i&&t.push(e)}return t},t.prototype.getNeighbors=function(t,e){var i=this;void 0===e&&(e=!1);var n=[],r=[{x:-1,y:0},{x:1,y:0},{x:0,y:-1},{x:0,y:1}];return e&&r.push({x:-1,y:-1},{x:1,y:-1},{x:-1,y:1},{x:1,y:1}),r.forEach(function(e){var r={x:t.x+e.x,y:t.y+e.y};i.grid.isValidCoordinate(r)&&n.push(i.grid.getCell(r))}),n},t.prototype.findConnectedCells=function(t){var e=this;if(!this.grid.isCellActive(t))return[];var i=this.grid.getCell(t).value,n=[],r=new Set,o=[t],s=function(t){return"".concat(t.x,",").concat(t.y)};for(r.add(s(t));o.length>0;){var a=o.shift(),u=this.grid.getCell(a);u.value===i&&(n.push(u),[{x:a.x-1,y:a.y},{x:a.x+1,y:a.y},{x:a.x,y:a.y-1},{x:a.x,y:a.y+1}].forEach(function(t){var i=s(t);e.grid.isValidCoordinate(t)&&!r.has(i)&&e.grid.isCellActive(t)&&(r.add(i),o.push(t))}))}return n},t.prototype.swapCells=function(t,e){var i=R({},this.grid.getCell(t)),n=R({},this.grid.getCell(e));this.grid.stampCell(R(R({},n),{coordinate:t})),this.grid.stampCell(R(R({},i),{coordinate:e}))},t}();const O=P;var M=function(){function t(t){this.grid=t}return t.prototype.isRowFull=function(t){var e=this.grid.getGrid();return!(t<0||t>=this.grid.height)&&e[t].every(function(t){return t.value>0})},t.prototype.isRowEmpty=function(t){var e=this.grid.getGrid();return t<0||t>=this.grid.height||e[t].every(function(t){return 0===t.value})},t.prototype.clearRow=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.height))for(var i=0;i<this.grid.width;i++)e[t][i]=m.emptyCell({x:i,y:t})},t.prototype.shiftRowsDown=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.width;n++){var r=e[i-1][n];e[i][n].value=r.value,e[i][n].color=r.color}this.clearRow(0)},t.prototype.shiftRowsUp=function(t){for(var e=this.grid.getGrid(),i=t;i<this.grid.height-1;i++)for(var n=0;n<this.grid.width;n++){var r=e[i+1][n];e[i][n].value=r.value,e[i][n].color=r.color}this.clearRow(this.grid.height-1)},t.prototype.clearFullRows=function(){for(var t=0,e=this.grid.height-1;e>=0;e--)this.isRowFull(e)&&(this.clearRow(e),this.shiftRowsDown(e),t++,e++);return t},t.prototype.isColumnFull=function(t){var e=this.grid.getGrid();if(t<0||t>=this.grid.width)return!1;for(var i=0;i<this.grid.height;i++)if(0===e[i][t].value)return!1;return!0},t.prototype.isColumnEmpty=function(t){var e=this.grid.getGrid();if(t<0||t>=this.grid.width)return!0;for(var i=0;i<this.grid.height;i++)if(0!==e[i][t].value)return!1;return!0},t.prototype.clearColumn=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.width))for(var i=0;i<this.grid.height;i++)e[i][t]=m.emptyCell({x:t,y:i})},t.prototype.shiftColumnsRight=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.height;n++){var r=e[n][i-1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(0)},t.prototype.shiftColumnsLeft=function(t){for(var e=this.grid.getGrid(),i=t;i<this.grid.width-1;i++)for(var n=0;n<this.grid.height;n++){var r=e[n][i+1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(this.grid.width-1)},t.prototype.clearFullColumns=function(){for(var t=0,e=this.grid.width-1;e>=0;e--)this.isColumnFull(e)&&(this.clearColumn(e),this.shiftColumnsRight(e),t++,e++);return t},t}();const T=M;var I=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){return!e.grid.isValidCoordinate(t)||e.grid.isCellActive(t)})},t.prototype.fillArea=function(t,e,i,n){for(var r=Math.max(0,Math.min(t.x,e.x)),o=Math.min(this.grid.width-1,Math.max(t.x,e.x)),s=Math.max(0,Math.min(t.y,e.y)),a=Math.min(this.grid.height-1,Math.max(t.y,e.y)),u=s;u<=a;u++)for(var c=r;c<=o;c++)this.grid.setCellValue({x:c,y:u},i),this.grid.setCellColor({x:c,y:u},n)},t.prototype.stampPiece=function(t){var e=this;t.forEach(function(t){return e.grid.stampCell(t)})},t.prototype.stampCell=function(t){this.grid.setCellValue(t.coordinate,t.value),this.grid.setCellColor(t.coordinate,t.color)},t}();const L=I;var A=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new w(this),this._transformEngine=new x(this),this._analysisEngine=new O(this),this._lineEngine=new T(this),this._regionEngine=new L(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return p.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return p.screenLayout.grid.rows},enumerable:!1,configurable:!0}),t.prototype.setup=function(){this.resetGrid()},t.prototype.resetGrid=function(){this._grid=[];for(var t=0;t<this.height;t++){this._grid[t]=[];for(var e=0;e<this.width;e++)this._grid[t][e]=m.emptyCell({x:e,y:t})}},t.prototype.forEach=function(t){for(var e=0;e<this.height;e++)for(var i=0;i<this.width;i++)t(this._grid[e][i])},t.prototype.isValidCoordinate=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isValidCoordinate(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){var e=this.getCell(t);return null!==e&&e.value>0},t.prototype.isCellInactive=function(t){var e=this.getCell(t);return null!==e&&0===e.value},t.prototype.isRowFull=function(t){return this._lineEngine.isRowFull(t)},t.prototype.isRowEmpty=function(t){return this._lineEngine.isRowEmpty(t)},t.prototype.clearRow=function(t){this._lineEngine.clearRow(t)},t.prototype.shiftRowsDown=function(t){this._lineEngine.shiftRowsDown(t)},t.prototype.shiftRowsUp=function(t){this._lineEngine.shiftRowsUp(t)},t.prototype.clearFullRows=function(){return this._lineEngine.clearFullRows()},t.prototype.isColumnFull=function(t){return this._lineEngine.isColumnFull(t)},t.prototype.isColumnEmpty=function(t){return this._lineEngine.isColumnEmpty(t)},t.prototype.clearColumn=function(t){this._lineEngine.clearColumn(t)},t.prototype.shiftColumnsRight=function(t){this._lineEngine.shiftColumnsRight(t)},t.prototype.shiftColumnsLeft=function(t){this._lineEngine.shiftColumnsLeft(t)},t.prototype.clearFullColumns=function(){return this._lineEngine.clearFullColumns()},t.prototype.isAreaOccupied=function(t){return this._regionEngine.isAreaOccupied(t)},t.prototype.fillArea=function(t,e,i,n){this._regionEngine.fillArea(t,e,i,n)},t.prototype.stampPiece=function(t){this._regionEngine.stampPiece(t)},t.prototype.stampCell=function(t){this._regionEngine.stampCell(t)},t.prototype.movePiece=function(t,e){return this._movementEngine.movePiece(t,e)},t.prototype.movePieceLeft=function(t){return this._movementEngine.movePieceLeft(t)},t.prototype.movePieceRight=function(t){return this._movementEngine.movePieceRight(t)},t.prototype.movePieceUp=function(t){return this._movementEngine.movePieceUp(t)},t.prototype.movePieceDown=function(t){return this._movementEngine.movePieceDown(t)},t.prototype.moveCell=function(t,e){return this._movementEngine.moveCell(t,e)},t.prototype.moveCellLeft=function(t){return this._movementEngine.moveCellLeft(t)},t.prototype.moveCellRight=function(t){return this._movementEngine.moveCellRight(t)},t.prototype.moveCellUp=function(t){return this._movementEngine.moveCellUp(t)},t.prototype.moveCellDown=function(t){return this._movementEngine.moveCellDown(t)},t.prototype.rotatePiece=function(t,e,i){return void 0===i&&(i=!0),this._transformEngine.rotatePiece(t,e,i)},t.prototype.getFullRows=function(){return this._analysisEngine.getFullRows()},t.prototype.getFullColumns=function(){return this._analysisEngine.getFullColumns()},t.prototype.getDropPath=function(t){return this._movementEngine.getDropPath(t)},t.prototype.getRisePath=function(t){return this._movementEngine.getRisePath(t)},t.prototype.getReachPathLeft=function(t){return this._movementEngine.getReachPathLeft(t)},t.prototype.getReachPathRight=function(t){return this._movementEngine.getReachPathRight(t)},t.prototype.getNeighbors=function(t,e){return void 0===e&&(e=!1),this._analysisEngine.getNeighbors(t,e)},t.prototype.findConnectedCells=function(t){return this._analysisEngine.findConnectedCells(t)},t.prototype.mirrorPiece=function(t,e){return this._transformEngine.mirrorPiece(t,e)},t.prototype.swapCells=function(t,e){this._analysisEngine.swapCells(t,e)},t.prototype.getPieceBounds=function(t){return this._transformEngine.getPieceBounds(t)},t.prototype.getDebugData=function(){return{width:this.width,height:this.height,activeCells:this._grid.flat().filter(function(t){return t.value>0}).length}},t.prototype.serialize=function(){return console.log("serialize"),JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){console.log("deserialize");var e=JSON.parse(t);this._grid=e.grid},t}();const D=A;var G=function(){function t(){}return t.getRelativeWidth=function(t,e){return e*t.width},t.getRelativeHeight=function(t,e){return e*t.height},t}();const B=G;var k=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=p.screenLayout.cell,i=e.margin,n=e.padding,r=e.strokeWeight,o=this._rendererMetrics.cell.size;this._cellPreCalculatedGeometry={innerOffset:i*o,innerSize:o-i*o*2,paddingOffset:n*o,paddingSize:o-n*o*2,strokeWeight:r*o},this._renderStaticElements()},t.prototype.render=function(t,e){this._p.push(),this._p.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),this._p.pop()},t.prototype._renderStaticElements=function(){var t=p.screenLayout.display.borderWeight;this._staticGraphics=this._p.createGraphics(this._p.width,this._p.height),this._staticGraphics.background(p.colors.background),this._staticGraphics.strokeWeight(B.getRelativeWidth(this._p,t)),this._staticGraphics.noFill(),this._staticGraphics.stroke(p.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,o=t.value,s=i.x,a=i.y,u=this._cellPreCalculatedGeometry,c=u.innerOffset,l=u.innerSize,h=u.paddingOffset,d=u.paddingSize,p=u.strokeWeight;n=0===o||!e.isPlaying()&&!e.isPaused()?r.INACTIVE:e.isColorEnabled()?n:r.DEFAULT,this._p.push(),this._p.translate(this._rendererMetrics.display.origin.x+s*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+a*this._rendererMetrics.cell.size),this._p.strokeWeight(p),this._p.stroke(n),this._p.noFill(),this._p.rect(c,c,l,l),this._p.fill(n),this._p.rect(h,h,d,d),this._p.pop()},t.prototype.renderGrid=function(t,e){var i=this;t.forEach(function(t){t.forEach(function(t){i.renderCell(t,e)})})},t}();const z=k;var N=function(){function t(){}return t.getRelativeCoordinate=function(t,e){return{x:B.getRelativeWidth(t,e.x),y:B.getRelativeHeight(t,e.y)}},t.getDisplayPosX=function(t,e,i){var n=p.screenLayout.display.margin;return i*e+B.getRelativeWidth(t,n)},t.getDisplayPosY=function(t,e,i){var n=p.screenLayout.display.margin;return i*e+B.getRelativeHeight(t,n)},t.getHudPosX=function(t,e,i){var n=p.screenLayout.display.margin,r=i+2*B.getRelativeWidth(t,n);return(t.width-r-B.getRelativeWidth(t,n))*e+r},t.getHudPosY=function(t,e,i){var n=p.screenLayout.display.margin;return i*e+B.getRelativeHeight(t,n)},t}();const H=N;var F=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:H.getHudPosX(this._p,.078,t.display.width),y:H.getHudPosY(this._p,.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-B.getRelativeWidth(this._p,.005),y:this._gridOrigin.y-B.getRelativeHeight(this._p,.005),w:4*this._cellSize+B.getRelativeWidth(this._p,.01),h:4*this._cellSize+B.getRelativeHeight(this._p,.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=t.text,i=t.state,n=t.score;this._p.push(),e.setTextSize(s.SMALL),e.setInactiveText(),e.setTextAlign(o.LEFT,a.BOTTOM),e.textOnHud("88888888",{x:.05,y:.13}),e.textOnHud("88888888",{x:.05,y:.3}),e.textOnHud("88 - 88",{x:.05,y:.8}),i.isOn()&&e.setActiveText(),e.textOnHud("Score",{x:.05,y:.06}),e.textOnHud(n.score.toString(),{x:.05,y:.13}),e.textOnHud("Hi-Score",{x:.05,y:.23}),e.textOnHud(n.highScore.toString(),{x:.05,y:.3}),e.textOnHud("Level",{x:.05,y:.72});var r="".concat(n.level<10?"0"+n.level:n.level," - ").concat(n.maxLevel);e.textOnHud(r,{x:.05,y:.8}),e.setTextAlign(o.CENTER,a.BOTTOM),i.isPaused()?e.setActiveText():e.setInactiveText(),e.textOnHud("Paused",{x:.5,y:.9}),i.isOn()&&i.isMuted()?e.setActiveText():e.setInactiveText(),e.textOnHud("Muted",{x:.5,y:.97}),this._p.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=t.hudGrid,n=t.state;this._p.push(),i.forEach(function(t){var i=t.coordinate,o=i.x,s=i.y;n.isOff()&&!n.isPlaying()&&(t.value=0);var a=0!==t.value?r.DEFAULT:r.INACTIVE;n.isColorEnabled()&&0!==t.value&&(a=t.color),e.drawCellElement({w:e._cellSize,h:e._cellSize,posX:e._gridOrigin.x+e._cellSize*o,posY:e._gridOrigin.y+e._cellSize*s,color:a})}),this._p.noFill(),this._p.stroke(n.isOn()?r.DEFAULT:r.INACTIVE),this._p.rect(this._hudBorderRect.x,this._hudBorderRect.y,this._hudBorderRect.w,this._hudBorderRect.h),this._p.pop()},t.prototype.drawCellElement=function(t){var e=t.w,i=t.posX,n=t.posY,r=t.color,o=p.screenLayout.cell,s=o.margin,a=o.padding,u=s*e,c=e-s*e*2,l=a*e,h=e-a*e*2,d=o.strokeWeight*e;this._p.push(),this._p.translate(i,n),this._p.strokeWeight(d),this._p.stroke(r),this._p.noFill(),this._p.rect(u,u,c,c),this._p.fill(r),this._p.rect(l,l,h,h),this._p.pop()},t}();const U=F;var W=function(){function t(t){this._p=t}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new z(this._p),this._hudRenderer=new U(this._p),this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=p.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=p.screenLayout.grid.columns,o=B.getRelativeWidth(this._p,e),s=B.getRelativeHeight(this._p,i),a=H.getRelativeCoordinate(this._p,{x:n,y:n}),u=o/r,c={x:H.getHudPosX(this._p,0,o),y:H.getHudPosY(this._p,0,s)},l=H.getHudPosX(this._p,1,o)-c.x,h=H.getHudPosY(this._p,1,s)-c.y;this._rendererMetrics={display:{width:o,height:s,origin:a},hud:{width:l,height:h,origin:c},cell:{size:u}}},t.prototype.render=function(t,e){this._renderers.forEach(function(i){return i.render(t,e)})},Object.defineProperty(t.prototype,"rendererMetrics",{get:function(){return this._rendererMetrics},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{display_width:this._rendererMetrics.display.width.toFixed(2),display_height:this._rendererMetrics.display.height.toFixed(2),hud_width:this._rendererMetrics.hud.width.toFixed(2),hud_height:this._rendererMetrics.hud.height.toFixed(2),cell_size:this._rendererMetrics.cell.size.toFixed(2)}},t}();const j=W;var V,K=((V={})[h.ON]={defaultValue:!1},V[h.START]={defaultValue:!1},V[h.PLAYING]={defaultValue:!1},V[h.GAME_OVER]={defaultValue:!1},V[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},V[h.MUTED]={defaultValue:!1,storageKey:"muted"},V),Y=function(){function t(){this._state=new Map,this._subscribers=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=K[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=K[e];if(i.storageKey){var n=localStorage.getItem(i.storageKey);null!==n&&t._state.set(e,JSON.parse(n))}})},t.prototype._set=function(t,e){if(this._state.get(t)!==e){this._state.set(t,e);var i=K[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this._notify(t,e)}},t.prototype._notify=function(t,e){var i=this._subscribers.get(t);i&&i.forEach(function(t){return t(e)})},t.prototype.isOn=function(){return this._state.get(h.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(h.START)},t.prototype.isPlaying=function(){return this._state.get(h.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(h.GAME_OVER)},t.prototype.turnOn=function(){this._set(h.ON,!0),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(h.ON,!1),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(h.START,!0),this._set(h.PLAYING,!0),this._set(h.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0)},t.prototype.exitGame=function(){this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(h.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(h.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(h.MUTED)},t.prototype.setMuted=function(t){this._set(h.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.subscribe=function(t,e){var i;this._subscribers.has(t)||this._subscribers.set(t,[]),null===(i=this._subscribers.get(t))||void 0===i||i.push(e)},t.prototype.unsubscribe=function(t,e){var i=this._subscribers.get(t);i&&this._subscribers.set(t,i.filter(function(t){return t!==e}))},t.prototype.getDebugData=function(){return{on:this.isOn(),start:this.isStarted(),playing:this.isPlaying(),paused:this.isPaused(),game_over:this.isGameOver(),color_enabled:this.isColorEnabled(),muted:this.isMuted()}},t}();const X=Y;var J=function(){function t(t){this.defaultFontFamily="retro-gamming",this.fontSizes=[0],this._p=t}return t.prototype.setup=function(){var t=p.screenLayout.fontSize,e=t.extraSmall,i=t.small,n=t.medium,r=t.large,o=t.extraLarge;this._p.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=B.getRelativeWidth(this._p,e),this.fontSizes[s.SMALL]=B.getRelativeWidth(this._p,i),this.fontSizes[s.MEDIUM]=B.getRelativeWidth(this._p,n),this.fontSizes[s.LARGE]=B.getRelativeWidth(this._p,r),this.fontSizes[s.EXTRA_LARGE]=B.getRelativeWidth(this._p,o)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=p.colors,i=e.active,n=e.inactive;this._p.fill(t?i:n)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setTextSize=function(t){this._p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){this._p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=H.getHudPosX(this._p,e.x,this._rendererMetrics.display.width),n=H.getHudPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.textOnDisplay=function(t,e){var i=H.getDisplayPosX(this._p,e.x,this._rendererMetrics.display.width),n=H.getDisplayPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const q=J,Q=function(){function t(){this._accumulatedTime=0,this._initialTickInterval=p.game.tickInterval,this._minTickInterval=p.game.minTickInterval,this._tickInterval=p.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._accumulatedTime+=t,this._fps=1e3/t,this._timeSinceLastTpsUpdate+=t,this._timeSinceLastTpsUpdate>=1e3&&(this._tps=this._tickCounter,this._tickCounter=0,this._timeSinceLastTpsUpdate-=1e3)},t.prototype.shouldTick=function(){return this._accumulatedTime>=this._tickInterval&&(this._accumulatedTime-=this._tickInterval,this._tickCounter++,!0)},t.prototype.reset=function(){this._accumulatedTime=0,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this._tickInterval=this._initialTickInterval},Object.defineProperty(t.prototype,"tickInterval",{get:function(){return this._tickInterval},set:function(t){this._tickInterval=t},enumerable:!1,configurable:!0}),t.prototype.incrementTickInterval=function(t){this.tickInterval=this._tickInterval+t},t.prototype.decrementTickInterval=function(t){var e=Math.max(this._minTickInterval,this._tickInterval-t);this.tickInterval=e},t.prototype.getDebugData=function(){return{fps:Math.round(this._fps),tps:this._tps,tick_interval:this._tickInterval.toFixed(2),accumulated_time:this._accumulatedTime.toFixed(2)}},t.prototype.serialize=function(){return JSON.stringify({tickInterval:this._tickInterval})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._tickInterval=e.tickInterval},t.prototype.setTickInterval=function(t){this._tickInterval=t},t.prototype.setMinTickInterval=function(t){this._minTickInterval=t},t}();var $=function(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())})},Z=function(t,e){var i,n,r,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(i=1,n&&(r=2&a[0]?n.return:a[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,a[1])).done)return r;switch(n=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((r=(r=o.trys).length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){o.label=a[1];break}if(6===a[0]&&o.label<r[1]){o.label=r[1],r=a;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(a);break}r[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{i=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},tt=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=p.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return $(this,void 0,void 0,function(){var e,i,n;return Z(this,function(r){return"suspended"===this._audioContext.state&&this._audioContext.resume(),(e=this._buffers.get(t))?((i=this._audioContext.createBufferSource()).buffer=e,i.connect(this._gainNode),this._activeSources.has(t)||this._activeSources.set(t,[]),(n=this._activeSources.get(t)).push(i),i.onended=function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)},i.start(0),[2]):(console.warn("Sound buffer not found for: ".concat(t)),[2])})})},t.prototype.stop=function(t){return $(this,void 0,void 0,function(){var e;return Z(this,function(i){return(e=this._activeSources.get(t))&&(e.forEach(function(t){try{t.stop()}catch(t){}}),e.length=0),[2]})})},t.prototype.stopAll=function(){return $(this,void 0,void 0,function(){var t,e,i,n;return Z(this,function(r){switch(r.label){case 0:t=Array.from(this._activeSources.keys()),e=0,i=t,r.label=1;case 1:return e<i.length?(n=i[e],[4,this.stop(n)]):[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},t.prototype._updateGain=function(){var t=!!this._state&&this._state.isMuted();this._gainNode&&(t?this._gainNode.gain.setValueAtTime(0,this._audioContext.currentTime):this._gainNode.gain.setValueAtTime(this._volume,this._audioContext.currentTime))},t.prototype._loadAll=function(){return $(this,void 0,void 0,function(){var t,e=this;return Z(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return $(e,void 0,void 0,function(){var e,i,n;return Z(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),[4,fetch(t)];case 1:return[4,r.sent().arrayBuffer()];case 2:return e=r.sent(),[4,this._audioContext.decodeAudioData(e)];case 3:return i=r.sent(),this._buffers.set(t,i),[3,5];case 4:return n=r.sent(),console.error("Failed to load sound: ".concat(t),n),[3,5];case 5:return[2]}})})}),[4,Promise.all(t)];case 1:return i.sent(),[2]}})})},t.prototype.toggleMute=function(){this._state.toggleMuted(),this._updateGain()},t.prototype.syncState=function(t){var e=this;this._state=t,t.subscribe(h.MUTED,function(){e._updateGain()}),this._updateGain()},t.prototype.getDebugData=function(){var t=0;return this._activeSources.forEach(function(e){return t+=e.length}),{muted:!!this._state&&this._state.isMuted(),volume:this._volume,active_sources:t,loaded_buffers:this._buffers.size}},t}();const et=tt,it=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this.serialId="score"}return t.prototype.setup=function(){this._highScore=Number(localStorage.getItem("highScore"))},t.prototype.increaseScore=function(t){this._score+=t*this._multiplier,this._score>this._highScore&&(this.highScore=this._score)},t.prototype.resetScore=function(){this._score=0},t.prototype.getFormattedScore=function(t){return void 0===t&&(t=6),this._score.toString().padStart(t,"0")},t.prototype.increaseLevel=function(t){this._level+=t},t.prototype.resetLevel=function(){this._level=1},Object.defineProperty(t.prototype,"multiplier",{get:function(){return this._multiplier},set:function(t){this._multiplier=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"level",{get:function(){return this._level},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxLevel",{get:function(){return this._maxLevel},set:function(t){this._maxLevel=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"highScore",{get:function(){return this._highScore},set:function(t){this._highScore=t,localStorage.setItem("highScore",t.toString())},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel}},t.prototype.serialize=function(){return JSON.stringify({score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._score=e.score,this._multiplier=e.multiplier,this._level=e.level,this._maxLevel=e.max_level},t}();var nt,rt=(nt=function(t,e){return nt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},nt(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}nt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const ot=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return rt(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return 4},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return 4},enumerable:!1,configurable:!0}),e.prototype.serialize=function(){return JSON.stringify({grid:this._grid})},e.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},e}(D),st=function(){function t(){}return t.isSerializable=function(t){if(null==t)return!1;var e=t,i="function"==typeof e.serialize,n="function"==typeof e.deserialize,r="string"==typeof e.serialId;return i&&n&&r},t.isInitializable=function(t){return null!=t&&"function"==typeof t.setup},t.isStateSyncable=function(t){if(null==t)return!1;var e=t;return"function"==typeof e.syncState&&!(e instanceof X)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var at=function(){function t(){this._initialState=new Map,this._baseProperties=[]}return t.prototype.captureBaseProperties=function(t){this._baseProperties=Object.keys(t)},t.prototype.captureInitialState=function(t){var e=this;console.log("capturing initial state for snapshot"),Object.entries(t).forEach(function(t){var i=t[0],n=t[1];if(!e._baseProperties.includes(i)&&"function"!=typeof n){var r=n;try{r=structuredClone(n),console.log("capturing property",i,r)}catch(t){console.error("Failed to clone property ".concat(i,":"),t)}e._initialState.set(i,r)}})},t.prototype.restoreInitialState=function(t){console.log("restoring initial snapshot"),this._initialState.forEach(function(e,i){t[i]=e,console.log("restoring property",i,e)})},t}();const ut=at,ct=function(){function t(){this._isModalClosed=!1,this._isEnabled=!0,this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isModalClosed&&this._isEnabled&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype.setSessionEnabled=function(t){this._isEnabled=t},t.prototype._hasSession=function(){var t=this;return this._serializables.every(function(e){return null!==localStorage.getItem(t._key(e.serialId))})},t.prototype._loadSession=function(){var t=this;this._serializables.forEach(function(e){var i=localStorage.getItem(t._key(e.serialId));i&&e.deserialize(i)})},t.prototype._destroySession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!1===e._isModalClosed){if(!e._hasSession()||!e._isEnabled)return void(e._isModalClosed=!0);e._showSessionModal(function(){e._hasSession()&&e._isEnabled&&e._loadSession(),e._isModalClosed=!0},function(){e._destroySession(),e._isModalClosed=!0})}}),t.subscribe(h.GAME_OVER,function(t){t&&e._destroySession()}),t.subscribe(h.ON,function(t){t||(e._isModalClosed=!1)})},t.prototype.getDebugData=function(){return{gameId:this.gameId,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}();var lt=function(){function t(t,e){this._modules=void 0,this._initialStateSnapshot=new ut,this._gameId="unknown",this._p=t,this._view=e,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new j(this._p),grid:new D,hudGrid:new ot,text:new q(this._p),state:new X,control:new v,time:new Q,sound:new et,score:new it,session:new ct},Object.values(this._modules).forEach(function(t){st.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){st.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){st.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,r=e.renderer,o=e.session;o.gameId=this.gameId,o.setShowModalFunction(this._view.showSessionModal.bind(this._view)),n.setModules(this._modules),i.setRendererMetrics(r.rendererMetrics),this.setupGame(),this._initialStateSnapshot.captureInitialState(this),this._subscribeSystemControls(),this._view.bindControls(n)},t.prototype.draw=function(){if(this._modules){var t=this._modules,e=t.renderer,i=t.grid,n=t.time,r=t.state;e.render(i.getGrid(),this._modules),r.isOn()&&(r.isStarted()?r.isPlaying()?(n.update(this._p.deltaTime),n.shouldTick()&&(this.update(this._p.deltaTime),this._modules.session.saveSession()),this.render()):r.isPaused()&&this.render():this.drawTitleScreen(),r.isGameOver()&&this.drawGameOverScreen())}},t.prototype.destroy=function(){this._p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},Object.defineProperty(t.prototype,"p",{get:function(){return this._p},enumerable:!1,configurable:!0}),t.prototype._subscribeSystemControls=function(){var t=this,e=this._modules,i=e.control,n=e.state,r=e.grid;i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),t.modules.sound.stopAll()):n.turnOn()}),i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.RESET,l.PRESSED,function(){r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset(),t._modules.session.clearSession(),n.resetGame(),t._initialStateSnapshot.restoreInitialState(t)}),i.subscribe(c.EXIT,l.PRESSED,function(){t._modules.session.clearSession()}),i.subscribe(c.START_PAUSE,l.PRESSED,function(){n.isStarted()?n.isPlaying()?n.pause():n.isPaused()?n.resume():n.isGameOver()&&(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset(),t.modules.session.clearSession(),t._initialStateSnapshot.restoreInitialState(t),n.resetGameOver()):n.startGame()}),n.subscribe(h.ON,function(e){e||(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset())})},t}();const ht=lt;var dt={grad:.9,turn:360,rad:360/(2*Math.PI)},pt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},ft=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},gt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},yt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:gt(t.r,0,255),g:gt(t.g,0,255),b:gt(t.b,0,255),a:gt(t.a)}},vt=function(t){return{r:ft(t.r),g:ft(t.g),b:ft(t.b),a:ft(t.a,3)}},mt=/^#([0-9a-f]{3,8})$/i,bt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Et=function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=Math.max(e,i,n),s=o-Math.min(e,i,n),a=s?o===e?(i-n)/s:o===i?2+(n-e)/s:4+(e-i)/s:0;return{h:60*(a<0?a+6:a),s:o?s/o*100:0,v:o/255*100,a:r}},wt=function(t){var e=t.h,i=t.s,n=t.v,r=t.a;e=e/360*6,i/=100,n/=100;var o=Math.floor(e),s=n*(1-i),a=n*(1-(e-o)*i),u=n*(1-(1-e+o)*i),c=o%6;return{r:255*[n,a,s,s,u,n][c],g:255*[u,n,n,a,s,s][c],b:255*[s,s,u,n,n,a][c],a:r}},St=function(t){return{h:yt(t.h),s:gt(t.s,0,100),l:gt(t.l,0,100),a:gt(t.a)}},Ct=function(t){return{h:ft(t.h),s:ft(t.s),l:ft(t.l),a:ft(t.a,3)}},xt=function(t){return wt((i=(e=t).s,{h:e.h,s:(i*=((n=e.l)<50?n:100-n)/100)>0?2*i/(n+i)*100:0,v:n+i,a:e.a}));var e,i,n},Rt=function(t){return{h:(e=Et(t)).h,s:(r=(200-(i=e.s))*(n=e.v)/100)>0&&r<200?i*n/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,i,n,r},Pt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Ot=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Tt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It={string:[[function(t){var e=mt.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?ft(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?ft(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Mt.exec(t)||Tt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:_t({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Pt.exec(t)||Ot.exec(t);if(!e)return null;var i,n,r=St({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(dt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return xt(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=void 0===r?1:r;return pt(e)&&pt(i)&&pt(n)?_t({r:Number(e),g:Number(i),b:Number(n),a:Number(o)}):null},"rgb"],[function(t){var e=t.h,i=t.s,n=t.l,r=t.a,o=void 0===r?1:r;if(!pt(e)||!pt(i)||!pt(n))return null;var s=St({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return xt(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!pt(e)||!pt(i)||!pt(n))return null;var s=function(t){return{h:yt(t.h),s:gt(t.s,0,100),v:gt(t.v,0,100),a:gt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(o)});return wt(s)},"hsv"]]},Lt=function(t,e){for(var i=0;i<e.length;i++){var n=e[i][0](t);if(n)return[n,e[i][1]]}return[null,void 0]},At=function(t,e){var i=Rt(t);return{h:i.h,s:gt(i.s+100*e,0,100),l:i.l,a:i.a}},Dt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Gt=function(t,e){var i=Rt(t);return{h:i.h,s:i.s,l:gt(i.l+100*e,0,100),a:i.a}},Bt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Lt(t.trim(),It.string):"object"==typeof t&&null!==t?Lt(t,It.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return ft(Dt(this.rgba),2)},t.prototype.isDark=function(){return Dt(this.rgba)<.5},t.prototype.isLight=function(){return Dt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=vt(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?bt(ft(255*r)):"","#"+bt(e)+bt(i)+bt(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return vt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=vt(this.rgba)).r,i=t.g,n=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+n+", "+r+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,r},t.prototype.toHsl=function(){return Ct(Rt(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ct(Rt(this.rgba))).h,i=t.s,n=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+n+"%, "+r+")":"hsl("+e+", "+i+"%, "+n+"%)";var t,e,i,n,r},t.prototype.toHsv=function(){return t=Et(this.rgba),{h:ft(t.h),s:ft(t.s),v:ft(t.v),a:ft(t.a,3)};var t},t.prototype.invert=function(){return kt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),kt(At(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),kt(At(this.rgba,-t))},t.prototype.grayscale=function(){return kt(At(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),kt(Gt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),kt(Gt(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?kt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):ft(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Rt(this.rgba);return"number"==typeof t?kt({h:t,s:e.s,l:e.l,a:e.a}):ft(e.h)},t.prototype.isEqual=function(t){return this.toHex()===kt(t).toHex()},t}(),kt=function(t){return t instanceof Bt?t:new Bt(t)};function zt(t,e,i){var n=t.createDiv();n.parent(e),n.addClass("btn-container");var r=t.createButton(i);return r.parent(n),r.addClass("btn"),r}function Nt(t,e,i,n){var r=t.createDiv();r.parent(e),r.addClass("sm-btn-container"),r.addClass(n?"sm-btn-container-top":"sm-btn-container-bottom");var o=t.createButton("");o.parent(r),o.addClass("sm-btn");var s=t.createP(i);return s.parent(r),s.addClass("sm-btn-p"),o}var Ht=function(){function t(t,e){this._moduleElements=[],this._gameModules=t,this._p=e}return t.prototype.setup=function(){var t=this;if(p.game.debugger.enabled){var e=this._p.select("#debugger"),i=!!e&&e.elt.hasAttribute("open"),n=new Set;e&&(this._p.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&n.add(t.id())}),e.remove()),this._moduleElements=[];var r=this._p.createElement("details");r.id("debugger"),i&&r.attribute("open",""),r.parent(this._p.select("body"));var o=this._p.createElement("summary");o.id("debugger-summary"),o.html("Debug"),o.parent(r),Object.entries(this._gameModules).forEach(function(e){var i=e[0],o=e[1];if("getDebugData"in o){var s={module:o,properties:[]},a=t._p.createElement("details");a.class("debugger-module"),a.id("debugger-".concat(i)),n.has("debugger-".concat(i))&&a.attribute("open",""),a.parent(r);var u=t._p.createElement("summary");u.id("debugger-".concat(i,"-summary")),u.html(i),u.class("debugger-module-summary"),u.parent(a);var c=o.getDebugData();Object.entries(c).forEach(function(e){var i=e[0],n=e[1],r=t._p.createElement("div");r.class("debugger-container"),r.id("debugger-container-".concat(i,"-").concat(n)),r.parent(a),r.mouseClicked(function(){r.toggleClass("highlight")});var o=t._p.createElement("p");o.id("debugger-".concat(i,"-").concat(n)),o.html("".concat(i,":")),o.parent(r);var u=t._p.createElement("span");u.id("debugger-".concat(i,"-").concat(n,"-value")),u.html("".concat(n)),u.parent(r),s.properties.push({key:i,element:u})}),t._moduleElements.push(s)}})}},t.prototype.setGameModules=function(t){this._gameModules=t,this.setup()},t.prototype.update=function(){this._moduleElements.forEach(function(t){var e=t.module.getDebugData();t.properties.forEach(function(t){t.element.html("".concat(e[t.key]))})})},t}();const Ft=Ht;var Ut=function(){function t(t){this._p=t}return t.prototype.setup=function(){this._container=this._p.createDiv(),this._container.parent(this._p.select("body")),this._container.id("modal-background"),this._container.class("hidden");var t=this._p.createDiv();t.parent(this._container),t.id("session-modal");var e=this._p.createDiv();e.parent(t),e.id("session-modal-frame");var i=this._p.createP();i.parent(e),i.html("Brick Engine Session");var n=this._p.createDiv();n.parent(e),n.id("session-modal-screen");var r=this._p.createP();r.parent(n),r.html("<span>Looks like you have an active session.</span><br><br>Do you want to continue?");var o=this._p.createDiv();o.parent(t),o.id("session-modal-buttons"),this._cancelButton=this._p.createButton("Cancel"),this._cancelButton.parent(o),this._cancelButton.class("session-modal-button"),this._confirmButton=this._p.createButton("Confirm"),this._confirmButton.parent(o),this._confirmButton.class("session-modal-button")},t.prototype.show=function(t,e){var i=this;this._confirmButton.mousePressed(function(){t(),i._hide()}),this._cancelButton.mousePressed(function(){e(),i._hide()}),this._container.removeClass("hidden")},t.prototype._hide=function(){this._confirmButton.mousePressed(null),this._cancelButton.mousePressed(null),this._container.addClass("hidden")},t}();const Wt=Ut;var jt=function(){function t(t,e){this._parent=e,this._p=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,r;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(p.inputQueryParams.mainColor)?i.get(p.inputQueryParams.mainColor):p.colors.bodyMain,r=i.has(p.inputQueryParams.buttonColor)?i.get(p.inputQueryParams.buttonColor):p.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",kt(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",kt(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",kt(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",kt(r).darken(.15).toHex());var o=function(t,e){var i,n=t.createDiv();if(n.parent(p.selectors.parent),n.id(p.selectors.viewElementIds.container),e.clientWidth<=p.viewLayout.mobileBreakpoint)return{container:n,width:i=e.clientWidth,height:e.clientHeight};var r=e.clientHeight/(1.05*p.viewLayout.bodyHeightWidthMultiplier);return{container:n,width:i=Math.min(e.clientWidth,r),height:i*p.viewLayout.bodyHeightWidthMultiplier}}(this._p,this._parent),s=o.container,a=o.height,u=o.width,c=function(t,e){var i=t.createDiv();i.parent(e),i.id(p.selectors.viewElementIds.frame);var n=t.createDiv();return n.parent(i),t.createP("Brick Game").parent(n),i}(this._p,s),l=function(t,e,i){var n=i*p.viewLayout.canvas.widthRatio,r=n*p.viewLayout.canvas.aspectRatio,o=t.createCanvas(n,r);return o.parent(e),o.id(p.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:r,canvas:o}}(this._p,c,u),h=l.canvas,d=l.canvasHeight,f=l.canvasWidth,g=function(t,e){var i=t.createDiv();i.parent(e),i.id(p.selectors.viewElementIds.buttonContainer);var n=t.createDiv();n.parent(i),n.id(p.selectors.viewElementIds.smallButtonContainer);var r=t.createDiv();r.parent(i),r.id(p.selectors.viewElementIds.innerButtonContainer);var o=t.createDiv();o.parent(r),o.id(p.selectors.viewElementIds.mediumButtonContainer);var s=t.createDiv();s.parent(o),s.id(p.selectors.viewElementIds.directionVerticalContainer);var a=t.createDiv();a.parent(o),a.id(p.selectors.viewElementIds.directionHorizontalContainer);var u=t.createDiv();return u.parent(r),u.id(p.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(this._p,s),y=g.largeButtonContainer,_=g.smallButtonContainer,v=g.directionHorizontalContainer,m=g.directionVerticalContainer;return this._onOffBtn=Nt(this._p,_,"On<br/>Off",!0),this._startPauseBtn=Nt(this._p,_,"Start<br/>Pause",!1),this._soundBtn=Nt(this._p,_,"Sound",!0),this._resetBtn=Nt(this._p,_,"Reset",!1),this._exitBtn=Nt(this._p,_,"Exit",!0),this._enableColorBtn=Nt(this._p,_,"Enable<br/>Colors",!1),this._upBtn=zt(this._p,m,"UP"),this._leftBtn=zt(this._p,v,"LEFT"),this._downBtn=zt(this._p,m,"DOWN"),this._rightBtn=zt(this._p,v,"RIGHT"),this._actionBtn=function(t,e){var i=t.createDiv();i.parent(e),i.addClass("lg-btn-container");var n=t.createButton("Action");return n.parent(i),n.addClass("lg-btn"),n}(this._p,y),function(t,e,i,n){var r=document.querySelector(":root");r.style.setProperty("--dispersion",p.viewLayout.shadowDispersion),r.style.setProperty("--width","".concat(t,"px")),r.style.setProperty("--height","".concat(e,"px")),r.style.setProperty("--canvas-width","".concat(i,"px")),r.style.setProperty("--canvas-height","".concat(n,"px")),r.style.setProperty("--border-radius","".concat(t*p.viewLayout.dimensions.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*p.viewLayout.dimensions.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*p.viewLayout.dimensions.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*p.viewLayout.dimensions.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*p.viewLayout.dimensions.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*p.viewLayout.dimensions.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*p.viewLayout.dimensions.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",p.viewLayout.dimensions.button.animationDuration)}(u,a,f,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Wt(this._p),this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new Ft(t,this._p),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=p.viewLayout.splashHideDelayMs);var e=document.querySelector(p.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Vt=jt;var Kt,Yt=n(991),Xt=n.n(Yt);function Jt(t){Kt=t}function qt(t){return window.BrickEngineGame=t,new(Xt())(function(e){var i=new Vt(e,document.body);Jt(new t(e,i)),"unknown"===Kt.gameId&&(Kt.gameId="game"),e.setup=function(){Kt.setup(),Kt.view.setupDebugger(Kt.modules),Kt.view.setupSessionModal()},e.draw=function(){Kt.draw(),Kt.view.updateDebugger()}})}return d})());
@@ -10,6 +10,12 @@ import GameView from './view/GameView';
10
10
  * @returns {Game} A new game instance.
11
11
  */
12
12
  type ClientGameConstructor = new (p: p5, view: GameView) => Game;
13
+ /**
14
+ * Updates the currently active game in the engine's execution loop.
15
+ *
16
+ * @param {Game} game - The new game instance to become active.
17
+ */
18
+ export declare function setActiveGame(game: Game): void;
13
19
  /**
14
20
  * Bootstraps the brick engine and initializes the game.
15
21
  *
@@ -14,7 +14,6 @@ export default abstract class Game implements Initializable {
14
14
  private _modules;
15
15
  private _initialStateSnapshot;
16
16
  private _gameId;
17
- private _switchHandler;
18
17
  /**
19
18
  * Gets the game ID
20
19
  */
@@ -23,17 +22,6 @@ export default abstract class Game implements Initializable {
23
22
  * Sets the game ID
24
23
  */
25
24
  set gameId(id: string);
26
- /**
27
- * Registers the callback to be used when a game requests to switch to another game.
28
- * This is typically called by the engine's main loop (index.ts).
29
- * @param handler The callback function.
30
- */
31
- setSwitchHandler(handler: (newGame: Game) => void): void;
32
- /**
33
- * Propagates the switch handler to the new game.
34
- * @param game Game instance that has the switch handler.
35
- */
36
- propagateSwitchHandler(game: Game): void;
37
25
  /**
38
26
  * Creates an instance of the Game.
39
27
  *
@@ -47,13 +35,6 @@ export default abstract class Game implements Initializable {
47
35
  * @returns {GameView} The game view instance.
48
36
  */
49
37
  get view(): GameView;
50
- /**
51
- * Switches execution to a new game instance.
52
- * Use this instead of global window methods.
53
- *
54
- * @param {Game} newGame - The new game instance to load.
55
- */
56
- switchGame(newGame: Game): void;
57
38
  /**
58
39
  * Gets the game modules.
59
40
  *
@@ -4,13 +4,14 @@ export default class GameSession implements Session {
4
4
  _state: State;
5
5
  gameId: string;
6
6
  private _isModalClosed;
7
+ private _isEnabled;
7
8
  private _showSessionModal;
8
9
  private _serializables;
9
10
  register(serializable: Serializable): void;
10
11
  saveSession(): void;
11
12
  clearSession(): void;
12
13
  setShowModalFunction(showModal: (onConfirm: () => void, onCancel: () => void) => void): void;
13
- private _isGameMenuInstance;
14
+ setSessionEnabled(enabled: boolean): void;
14
15
  private _hasSession;
15
16
  private _loadSession;
16
17
  private _destroySession;
@@ -715,6 +715,11 @@ export interface Session extends StateSyncable, Debuggable {
715
715
  * Clears the current session.
716
716
  */
717
717
  clearSession(): void;
718
+ /**
719
+ * Sets whether the session is enabled.
720
+ * @param {boolean} enabled - Whether the session should be enabled.
721
+ */
722
+ setSessionEnabled(enabled: boolean): void;
718
723
  /**
719
724
  * Sets the function to be called when the session modal should be shown.
720
725
  * @param {function} callback - The function to be called.
@@ -3,8 +3,7 @@ export * from './core/types/enums';
3
3
  export * from './core/types/Interfaces';
4
4
  export * from './core/types/modules';
5
5
  export * from './core/types/Types';
6
- export * from './types/interfaces';
7
6
  export { default as Game } from './core/Game';
8
7
  export { default as GameView } from './view/GameView';
9
8
  export { default as configs } from './config/configs';
10
- export { bootstrap } from './bootstrap';
9
+ export { bootstrap, setActiveGame } from './bootstrap';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-engine-js",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "A lightweight brick engine built with p5.js and TypeScript",
5
5
  "type": "commonjs",
6
6
  "main": "dist/brick-engine.js",
@@ -14,7 +14,7 @@
14
14
  "author": "LeonardoPinheiroLacerda",
15
15
  "scripts": {
16
16
  "start": "webpack serve --open",
17
- "build": "webpack --mode production && npm run docs:build",
17
+ "build": "webpack --mode production",
18
18
  "build:types": "tsc --emitDeclarationOnly",
19
19
  "lint": "eslint .",
20
20
  "format": "npx prettier -w .",
@@ -23,8 +23,7 @@
23
23
  "docs:build": "node ./scripts/generate-docs.js",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest",
26
- "coverage": "vitest run --coverage",
27
- "prepublishOnly": "npm run build && npm run build:types"
26
+ "coverage": "vitest run --coverage"
28
27
  },
29
28
  "dependencies": {
30
29
  "colord": "^2.9.3",
@@ -38,7 +37,6 @@
38
37
  "asciidoctor": "^3.0.4",
39
38
  "copy-webpack-plugin": "^13.0.1",
40
39
  "css-loader": "^7.1.3",
41
- "dotenv": "^17.3.1",
42
40
  "eslint": "^10.0.0",
43
41
  "globals": "^17.3.0",
44
42
  "html-webpack-plugin": "^5.6.6",
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import p5 from 'p5';
2
- import GameView from '../view/GameView';
3
- import Game from '../core/Game';
4
- export default class GameMenu extends Game {
5
- private _gameSelectionPointer;
6
- private _isLoading;
7
- private _gameRepository;
8
- private _gameManager;
9
- constructor(p: p5, view: GameView);
10
- setupGame(): void;
11
- update(): void;
12
- render(): void;
13
- drawTitleScreen(): void;
14
- drawGameOverScreen(): void;
15
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- import GameMenu from './GameMenu';
2
- /**
3
- * Singleton manager for the Game Menu instance.
4
- *
5
- * This class provides a centralized point to store and retrieve the Game Menu
6
- * instance, facilitating access for game switching and system-level actions.
7
- */
8
- export default class GameMenuSingleton {
9
- private static _instance;
10
- /**
11
- * Sets the global instance of the Game Menu.
12
- *
13
- * @param {GameMenu} instance - The Game Menu instance.
14
- * @returns {void}
15
- */
16
- static setInstance(instance: GameMenu): void;
17
- /**
18
- * Retrieves the global instance of the Game Menu.
19
- *
20
- * @returns {GameMenu} The Game Menu instance.
21
- */
22
- static getInstance(): GameMenu;
23
- /**
24
- * Checks if the Game Menu instance has been initialized.
25
- *
26
- * @returns {boolean} True if the instance exists, false otherwise.
27
- */
28
- static hasInstance(): boolean;
29
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { GameEntry } from '../types/interfaces';
2
- export default class GameRepository {
3
- private _games;
4
- constructor();
5
- private fetchGames;
6
- get games(): readonly GameEntry[];
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import Game from '../../core/Game';
2
- import { GameEntry } from '../../types/interfaces';
3
- export default class GameManager {
4
- handleGameSwitch(entry: GameEntry, actualGame: Game): Promise<void>;
5
- private _loadGameScript;
6
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export interface GameEntry {
2
- id: string;
3
- name: string;
4
- url: string;
5
- }