brick-engine-js 1.0.12 → 1.0.13

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 01:46:48 UTC
723
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
606
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
637
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
645
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
562
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
581
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
534
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
529
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
553
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
516
+ Last updated 2026-02-24 15:10:55 UTC
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 01:46:48 UTC
766
+ Last updated 2026-02-24 15:10:55 UTC
767
767
  </div>
768
768
  </div>
769
769
  </body>
@@ -0,0 +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={584(t,e,i){i.d(e,{N:()=>p});var n=i(991),r=i.n(n),o=i(900),s=i(256),a=i(906);const u=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 c,l,h=function(t){try{c.view.unbindControls(),t.propagateSwitchHandler(c),t.setup();var e=t.modules,i=e.control,n=e.state;t.view.updateDebuggerGameModules(t.modules),t.view.bindControls(i),n.turnOn(),u.hasInstance()&&t!==u.getInstance()&&(i.subscribe(a.$N.EXIT,a.M8.PRESSED,function(){t.switchGame(u.getInstance())}),i.subscribe(a.$N.POWER,a.M8.PRESSED,function(){t.switchGame(u.getInstance()),n.turnOff()})),c=t}catch(t){console.error("Error switching game:",t)}l.loop()};function p(t){return window.BrickEngineGame=t,new(r())(function(e){l=e;var i=new o.A(e,document.body);t===s.A?((c=new t(e,i)).gameId="game-menu",u.setInstance(c)):(c=new t(e,i)).gameId="game",c.setSwitchHandler(h),e.setup=function(){c.setup(),c.view.setupDebugger(c.modules),c.view.setupSessionModal()},e.draw=function(){c.draw(),c.view.updateDebugger()}})}},728(t,e,i){i.d(e,{A:()=>n});const n={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}}}},186(t,e,i){i.d(e,{A:()=>X});var n=i(906),r=i(397),o={ArrowUp:n.$N.UP,ArrowDown:n.$N.DOWN,ArrowLeft:n.$N.LEFT,ArrowRight:n.$N.RIGHT,KeyW:n.$N.UP,KeyS:n.$N.DOWN,KeyA:n.$N.LEFT,KeyD:n.$N.RIGHT,KeyJ:n.$N.ACTION,Digit1:n.$N.POWER,Digit2:n.$N.START_PAUSE,Digit3:n.$N.SOUND,Digit4:n.$N.RESET,Digit5:n.$N.EXIT,Digit6:n.$N.COLOR};const s=function(){function t(t){this._inputHandler=new r.A(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=o[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=o[t.code];e&&this._inputHandler.handleRelease(e)},t}();var a=function(){function t(){this._subscribers=new Map}return t.prototype.setup=function(){this._keyBinding=new s(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 r={key:t,type:e,modules:this._modules},o=this._modules.state,s=!1;o.isOff()?s=t===n.$N.POWER:!o.isStarted()||o.isPlaying()||o.isGameOver()?s=!0:o.isPaused()&&(s=t.endsWith(";system"));var a=null===(i=this._subscribers.get(t))||void 0===i?void 0:i.get(e);a&&s&&a.forEach(function(t){return t(r)})},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 u=a;var c=i(728);const l=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:n.Q1.DEFAULT,coordinate:t}},t}();var h=function(){return h=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},h.apply(this,arguments)};const p=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return h(h({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})});return 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})?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:h(h({},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}();var d=function(){return d=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},d.apply(this,arguments)};const f=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 d(d({},t),{coordinate:{x:e.x+o,y:e.y+s}})});return 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})?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 d(d({},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}();var g=function(){return g=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},g.apply(this,arguments)};const y=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=g({},this.grid.getCell(t)),n=g({},this.grid.getCell(e));this.grid.stampCell(g(g({},n),{coordinate:t})),this.grid.stampCell(g(g({},i),{coordinate:e}))},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]=l.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]=l.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}(),m=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}(),v=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new p(this),this._transformEngine=new f(this),this._analysisEngine=new y(this),this._lineEngine=new _(this),this._regionEngine=new m(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return c.A.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return c.A.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]=l.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}(),b=function(){function t(){}return t.getRelativeWidth=function(t,e){return e*t.width},t.getRelativeHeight=function(t,e){return e*t.height},t}();var w=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=c.A.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=c.A.screenLayout.display.borderWeight;this._staticGraphics=this._p.createGraphics(this._p.width,this._p.height),this._staticGraphics.background(c.A.colors.background),this._staticGraphics.strokeWeight(b.getRelativeWidth(this._p,t)),this._staticGraphics.noFill(),this._staticGraphics.stroke(c.A.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,r=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;r=0===o||!e.isPlaying()&&!e.isPaused()?n.Q1.INACTIVE:e.isColorEnabled()?r:n.Q1.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(r),this._p.noFill(),this._p.rect(c,c,l,l),this._p.fill(r),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 E=w,S=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=c.A.screenLayout.display.margin;return i*e+b.getRelativeWidth(t,n)},t.getDisplayPosY=function(t,e,i){var n=c.A.screenLayout.display.margin;return i*e+b.getRelativeHeight(t,n)},t.getHudPosX=function(t,e,i){var n=c.A.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=c.A.screenLayout.display.margin;return i*e+b.getRelativeHeight(t,n)},t}();var x=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:S.getHudPosX(this._p,.078,t.display.width),y:S.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,r=t.score;this._p.push(),e.setTextSize(n.Z4.SMALL),e.setInactiveText(),e.setTextAlign(n.Z2.LEFT,n.TU.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(r.score.toString(),{x:.05,y:.13}),e.textOnHud("Hi-Score",{x:.05,y:.23}),e.textOnHud(r.highScore.toString(),{x:.05,y:.3}),e.textOnHud("Level",{x:.05,y:.72});var o="".concat(r.level<10?"0"+r.level:r.level," - ").concat(r.maxLevel);e.textOnHud(o,{x:.05,y:.8}),e.setTextAlign(n.Z2.CENTER,n.TU.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,r=t.state;this._p.push(),i.forEach(function(t){var i=t.coordinate,o=i.x,s=i.y;r.isOff()&&!r.isPlaying()&&(t.value=0);var a=0!==t.value?n.Q1.DEFAULT:n.Q1.INACTIVE;r.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(r.isOn()?n.Q1.DEFAULT:n.Q1.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=c.A.screenLayout.cell,s=o.margin,a=o.padding,u=s*e,l=e-s*e*2,h=a*e,p=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,l,l),this._p.fill(r),this._p.rect(h,h,p,p),this._p.pop()},t}();const C=x;var R=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 E(this._p),this._hudRenderer=new C(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=c.A.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=c.A.screenLayout.grid.columns,o=b.getRelativeWidth(this._p,e),s=b.getRelativeHeight(this._p,i),a=S.getRelativeCoordinate(this._p,{x:n,y:n}),u=o/r,l={x:S.getHudPosX(this._p,0,o),y:S.getHudPosY(this._p,0,s)},h=S.getHudPosX(this._p,1,o)-l.x,p=S.getHudPosY(this._p,1,s)-l.y;this._rendererMetrics={display:{width:o,height:s,origin:a},hud:{width:h,height:p,origin:l},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 P=R;var A,O=i(817),T=((A={})[O.tr.ON]={defaultValue:!1},A[O.tr.START]={defaultValue:!1},A[O.tr.PLAYING]={defaultValue:!1},A[O.tr.GAME_OVER]={defaultValue:!1},A[O.tr.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},A[O.tr.MUTED]={defaultValue:!1,storageKey:"muted"},A),M=function(){function t(){this._state=new Map,this._subscribers=new Map}return t.prototype.setup=function(){var t=this;Object.values(O.tr).forEach(function(e){var i=T[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(O.tr).forEach(function(e){var i=T[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=T[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(O.tr.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(O.tr.START)},t.prototype.isPlaying=function(){return this._state.get(O.tr.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(O.tr.GAME_OVER)},t.prototype.turnOn=function(){this._set(O.tr.ON,!0),this._set(O.tr.START,!1),this._set(O.tr.PLAYING,!1),this._set(O.tr.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(O.tr.ON,!1),this._set(O.tr.START,!1),this._set(O.tr.PLAYING,!1),this._set(O.tr.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(O.tr.START,!0),this._set(O.tr.PLAYING,!0),this._set(O.tr.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(O.tr.GAME_OVER,!1),this._set(O.tr.START,!0),this._set(O.tr.PLAYING,!0)},t.prototype.exitGame=function(){this._set(O.tr.START,!1),this._set(O.tr.PLAYING,!1),this._set(O.tr.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(O.tr.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(O.tr.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(O.tr.PLAYING,!1),this._set(O.tr.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(O.tr.GAME_OVER,!1),this._set(O.tr.START,!0),this._set(O.tr.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(O.tr.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(O.tr.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(O.tr.MUTED)},t.prototype.setMuted=function(t){this._set(O.tr.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 I=M;var D=function(){function t(t){this.defaultFontFamily="retro-gamming",this.fontSizes=[0],this._p=t}return t.prototype.setup=function(){var t=c.A.screenLayout.fontSize,e=t.extraSmall,i=t.small,r=t.medium,o=t.large,s=t.extraLarge;this._p.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[n.Z4.EXTRA_SMALL]=b.getRelativeWidth(this._p,e),this.fontSizes[n.Z4.SMALL]=b.getRelativeWidth(this._p,i),this.fontSizes[n.Z4.MEDIUM]=b.getRelativeWidth(this._p,r),this.fontSizes[n.Z4.LARGE]=b.getRelativeWidth(this._p,o),this.fontSizes[n.Z4.EXTRA_LARGE]=b.getRelativeWidth(this._p,s)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=c.A.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=S.getHudPosX(this._p,e.x,this._rendererMetrics.display.width),n=S.getHudPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.textOnDisplay=function(t,e){var i=S.getDisplayPosX(this._p,e.x,this._rendererMetrics.display.width),n=S.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 L=D,G=function(){function t(){this._accumulatedTime=0,this._initialTickInterval=c.A.game.tickInterval,this._minTickInterval=c.A.game.minTickInterval,this._tickInterval=c.A.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 N=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())})},B=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])}}},k=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=c.A.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 N(this,void 0,void 0,function(){var e,i,n;return B(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 N(this,void 0,void 0,function(){var e;return B(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 N(this,void 0,void 0,function(){var t,e,i,n;return B(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 N(this,void 0,void 0,function(){var t,e=this;return B(this,function(i){switch(i.label){case 0:return t=Object.values(n.AB).map(function(t){return N(e,void 0,void 0,function(){var e,i,n;return B(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(n.tr.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 z=k,H=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 F,U=(F=function(t,e){return F=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])},F(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}F(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),j=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return U(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}(v);const W=j,$=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 I)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var V=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 K=V,Y=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(n.tr.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(n.tr.GAME_OVER,function(t){t&&e._destroySession()}),t.subscribe(n.tr.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 Z=function(){function t(t,e){this._modules=void 0,this._initialStateSnapshot=new K,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 P(this._p),grid:new v,hudGrid:new W,text:new L(this._p),state:new I,control:new u,time:new G,sound:new z,score:new H,session:new Y},Object.values(this._modules).forEach(function(t){$.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){$.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){$.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(O.$N.POWER,O.M8.PRESSED,function(){n.isOn()?(n.turnOff(),t.modules.sound.stopAll()):n.turnOn()}),i.subscribe(O.$N.SOUND,O.M8.PRESSED,function(){return n.toggleMuted()}),i.subscribe(O.$N.COLOR,O.M8.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(O.$N.RESET,O.M8.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(O.$N.EXIT,O.M8.PRESSED,function(){t._modules.session.clearSession()}),i.subscribe(O.$N.START_PAUSE,O.M8.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(O.tr.ON,function(e){e||(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset())})},t}();const X=Z},397(t,e,i){i.d(e,{A:()=>o});var n=i(817),r=i(728);const o=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,n.M8.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,n.M8.HELD)},r.A.buttonHold.holdIntervalMs),o=e._activeKeys.get(t);o&&(o.hold=i)},r.A.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}()},817(t,e,i){i.d(e,{$N:()=>n.$N,M8:()=>n.M8,tr:()=>n.tr});var n=i(906)},906(t,e,i){var n,r,o,s,a,u,c,l;i.d(e,{$N:()=>u,AB:()=>a,M8:()=>c,Q1:()=>n,TU:()=>s,Z2:()=>r,Z4:()=>o,tr:()=>l}),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)"}(n||(n={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(r||(r={})),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"}(o||(o={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(s||(s={})),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"}(a||(a={})),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"}(u||(u={})),function(t){t.PRESSED="pressed",t.HELD="held"}(c||(c={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(l||(l={}))},256(t,e,i){i.d(e,{A:()=>c});var n=i(186),r=i(906);const o=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 s=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}();var a,u=(a=function(t,e){return a=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])},a(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}a(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const c=function(t){function e(e,i){var n=t.call(this,e,i)||this;return n._gameSelectionPointer=0,n._isLoading=!1,n._gameRepository=new o,n._gameManager=new s,n}return u(e,t),e.prototype.setupGame=function(){var t=this,e=this.modules,i=e.state,n=e.control,o=e.sound;n.subscribe(r.$N.ACTION,r.M8.PRESSED,function(){if(!t._isLoading&&i.isStarted()){var e=t._gameRepository.games[t._gameSelectionPointer];t._gameManager.handleGameSwitch(e,t)}}),n.subscribe(r.$N.LEFT,r.M8.PRESSED,function(){i.isPlaying()&&(o.play(r.AB.ACTION_1),0===t._gameSelectionPointer?t._gameSelectionPointer=t._gameRepository.games.length-1:t._gameSelectionPointer--)}),n.subscribe(r.$N.RIGHT,r.M8.PRESSED,function(){i.isPlaying()&&(o.play(r.AB.ACTION_1),t._gameSelectionPointer===t._gameRepository.games.length-1?t._gameSelectionPointer=0:t._gameSelectionPointer++)}),i.subscribe(r.tr.ON,function(t){t&&o.play(r.AB.START_THEME)})},e.prototype.update=function(){},e.prototype.render=function(){var t=this.modules.text,e=this.p;e.push(),t.setTextSize(r.Z4.LARGE),t.setActiveText(),t.setTextAlign(r.Z2.CENTER,r.TU.BOTTOM),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(r.Z4.SMALL),t.textOnDisplay("Choose a game and",{x:.5,y:.25}),t.textOnDisplay("Press action to play",{x:.5,y:.32}),t.setTextAlign(r.Z2.RIGHT,r.TU.BOTTOM),t.textOnDisplay("<",{x:.1,y:.54}),t.setTextAlign(r.Z2.LEFT,r.TU.BOTTOM),t.textOnDisplay(">",{x:.9,y:.54}),t.setTextSize(r.Z4.MEDIUM),t.setTextAlign(r.Z2.CENTER,r.TU.BOTTOM),t.textOnDisplay(this._gameRepository.games[this._gameSelectionPointer].name,{x:.5,y:.55}),t.setTextSize(r.Z4.EXTRA_SMALL),t.setTextAlign(r.Z2.LEFT,r.TU.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(r.Z4.LARGE),t.setActiveText(),t.setTextAlign(r.Z2.CENTER,r.TU.TOP),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(r.Z4.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}(n.A)},900(t,e,i){i.d(e,{A:()=>z});var n=i(728),r={grad:.9,turn:360,rad:360/(2*Math.PI)},o=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},s=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},a=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},u=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},c=function(t){return{r:a(t.r,0,255),g:a(t.g,0,255),b:a(t.b,0,255),a:a(t.a)}},l=function(t){return{r:s(t.r),g:s(t.g),b:s(t.b),a:s(t.a,3)}},h=/^#([0-9a-f]{3,8})$/i,p=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},d=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}},f=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}},g=function(t){return{h:u(t.h),s:a(t.s,0,100),l:a(t.l,0,100),a:a(t.a)}},y=function(t){return{h:s(t.h),s:s(t.s),l:s(t.l),a:s(t.a,3)}},_=function(t){return f((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},m=function(t){return{h:(e=d(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},v=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,b=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,w=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,E=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,S={string:[[function(t){var e=h.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?s(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?s(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=w.exec(t)||E.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:c({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=v.exec(t)||b.exec(t);if(!e)return null;var i,n,o=g({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(r[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return _(o)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,r=t.a,s=void 0===r?1:r;return o(e)&&o(i)&&o(n)?c({r:Number(e),g:Number(i),b:Number(n),a:Number(s)}):null},"rgb"],[function(t){var e=t.h,i=t.s,n=t.l,r=t.a,s=void 0===r?1:r;if(!o(e)||!o(i)||!o(n))return null;var a=g({h:Number(e),s:Number(i),l:Number(n),a:Number(s)});return _(a)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,s=void 0===r?1:r;if(!o(e)||!o(i)||!o(n))return null;var c=function(t){return{h:u(t.h),s:a(t.s,0,100),v:a(t.v,0,100),a:a(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(s)});return f(c)},"hsv"]]},x=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]},C=function(t,e){var i=m(t);return{h:i.h,s:a(i.s+100*e,0,100),l:i.l,a:i.a}},R=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},P=function(t,e){var i=m(t);return{h:i.h,s:i.s,l:a(i.l+100*e,0,100),a:i.a}},A=function(){function t(t){this.parsed=function(t){return"string"==typeof t?x(t.trim(),S.string):"object"==typeof t&&null!==t?x(t,S.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 s(R(this.rgba),2)},t.prototype.isDark=function(){return R(this.rgba)<.5},t.prototype.isLight=function(){return R(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=l(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?p(s(255*r)):"","#"+p(e)+p(i)+p(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return l(this.rgba)},t.prototype.toRgbString=function(){return e=(t=l(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 y(m(this.rgba))},t.prototype.toHslString=function(){return e=(t=y(m(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=d(this.rgba),{h:s(t.h),s:s(t.s),v:s(t.v),a:s(t.a,3)};var t},t.prototype.invert=function(){return O({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),O(C(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),O(C(this.rgba,-t))},t.prototype.grayscale=function(){return O(C(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),O(P(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),O(P(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?O({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):s(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=m(this.rgba);return"number"==typeof t?O({h:t,s:e.s,l:e.l,a:e.a}):s(e.h)},t.prototype.isEqual=function(t){return this.toHex()===O(t).toHex()},t}(),O=function(t){return t instanceof A?t:new A(t)};function T(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 M(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 I=i(906),D=i(397),L=function(){function t(t,e){this._moduleElements=[],this._gameModules=t,this._p=e}return t.prototype.setup=function(){var t=this;if(n.A.game.debugger.enabled){var e=this._p.select("#debugger"),i=!!e&&e.elt.hasAttribute("open"),r=new Set;e&&(this._p.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&r.add(t.id())}),e.remove()),this._moduleElements=[];var o=this._p.createElement("details");o.id("debugger"),i&&o.attribute("open",""),o.parent(this._p.select("body"));var s=this._p.createElement("summary");s.id("debugger-summary"),s.html("Debug"),s.parent(o),Object.entries(this._gameModules).forEach(function(e){var i=e[0],n=e[1];if("getDebugData"in n){var s={module:n,properties:[]},a=t._p.createElement("details");a.class("debugger-module"),a.id("debugger-".concat(i)),r.has("debugger-".concat(i))&&a.attribute("open",""),a.parent(o);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=n.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 G=L;var N=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 B=N;var k=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,r,o;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),r=(i=new URLSearchParams(e)).has(n.A.inputQueryParams.mainColor)?i.get(n.A.inputQueryParams.mainColor):n.A.colors.bodyMain,o=i.has(n.A.inputQueryParams.buttonColor)?i.get(n.A.inputQueryParams.buttonColor):n.A.colors.bodyButton,t.style.setProperty("--main-color",r),t.style.setProperty("--button-color",o),t.style.setProperty("--color-shadow",O(r).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",O(r).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",O(o).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",O(o).darken(.15).toHex());var s=function(t,e){var i,r=t.createDiv();if(r.parent(n.A.selectors.parent),r.id(n.A.selectors.viewElementIds.container),e.clientWidth<=n.A.viewLayout.mobileBreakpoint)return{container:r,width:i=e.clientWidth,height:e.clientHeight};var o=e.clientHeight/(1.05*n.A.viewLayout.bodyHeightWidthMultiplier);return{container:r,width:i=Math.min(e.clientWidth,o),height:i*n.A.viewLayout.bodyHeightWidthMultiplier}}(this._p,this._parent),a=s.container,u=s.height,c=s.width,l=function(t,e){var i=t.createDiv();i.parent(e),i.id(n.A.selectors.viewElementIds.frame);var r=t.createDiv();return r.parent(i),t.createP("Brick Game").parent(r),i}(this._p,a),h=function(t,e,i){var r=i*n.A.viewLayout.canvas.widthRatio,o=r*n.A.viewLayout.canvas.aspectRatio,s=t.createCanvas(r,o);return s.parent(e),s.id(n.A.selectors.viewElementIds.canvas),{canvasWidth:r,canvasHeight:o,canvas:s}}(this._p,l,c),p=h.canvas,d=h.canvasHeight,f=h.canvasWidth,g=function(t,e){var i=t.createDiv();i.parent(e),i.id(n.A.selectors.viewElementIds.buttonContainer);var r=t.createDiv();r.parent(i),r.id(n.A.selectors.viewElementIds.smallButtonContainer);var o=t.createDiv();o.parent(i),o.id(n.A.selectors.viewElementIds.innerButtonContainer);var s=t.createDiv();s.parent(o),s.id(n.A.selectors.viewElementIds.mediumButtonContainer);var a=t.createDiv();a.parent(s),a.id(n.A.selectors.viewElementIds.directionVerticalContainer);var u=t.createDiv();u.parent(s),u.id(n.A.selectors.viewElementIds.directionHorizontalContainer);var c=t.createDiv();return c.parent(o),c.id(n.A.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:r,mediumButtonContainer:s,largeButtonContainer:c,directionVerticalContainer:a,directionHorizontalContainer:u}}(this._p,a),y=g.largeButtonContainer,_=g.smallButtonContainer,m=g.directionHorizontalContainer,v=g.directionVerticalContainer;return this._onOffBtn=M(this._p,_,"On<br/>Off",!0),this._startPauseBtn=M(this._p,_,"Start<br/>Pause",!1),this._soundBtn=M(this._p,_,"Sound",!0),this._resetBtn=M(this._p,_,"Reset",!1),this._exitBtn=M(this._p,_,"Exit",!0),this._enableColorBtn=M(this._p,_,"Enable<br/>Colors",!1),this._upBtn=T(this._p,v,"UP"),this._leftBtn=T(this._p,m,"LEFT"),this._downBtn=T(this._p,v,"DOWN"),this._rightBtn=T(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,r){var o=document.querySelector(":root");o.style.setProperty("--dispersion",n.A.viewLayout.shadowDispersion),o.style.setProperty("--width","".concat(t,"px")),o.style.setProperty("--height","".concat(e,"px")),o.style.setProperty("--canvas-width","".concat(i,"px")),o.style.setProperty("--canvas-height","".concat(r,"px")),o.style.setProperty("--border-radius","".concat(t*n.A.viewLayout.dimensions.borderRadiusRatio,"px")),o.style.setProperty("--border","".concat(t*n.A.viewLayout.dimensions.borderWidthRatio,"px solid black")),o.style.setProperty("--sm-button-size","".concat(t*n.A.viewLayout.dimensions.button.smSizeRatio,"px")),o.style.setProperty("--button-size","".concat(t*n.A.viewLayout.dimensions.button.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size","".concat(t*n.A.viewLayout.dimensions.button.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile","".concat(t*n.A.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),o.style.setProperty("--button-size-mobile","".concat(t*n.A.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size-mobile","".concat(t*n.A.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*n.A.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*n.A.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--button-size-mobile-font-size","".concat(t*n.A.viewLayout.dimensions.button.mobile.fontRatio,"px")),o.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*n.A.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),o.style.setProperty("--button-size-mobile-spacing","".concat(t*n.A.viewLayout.dimensions.button.mobile.spacingRatio,"px")),o.style.setProperty("--button-border","".concat(t*n.A.viewLayout.dimensions.button.borderRatio,"px solid black")),o.style.setProperty("--button-animation-duration",n.A.viewLayout.dimensions.button.animationDuration)}(c,u,f,d),this._hideSplash(),this._cachedCanvas={canvas:p,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new B(this._p),this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new G(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 D.A(t),this._bindButtonEvents(this._onOffBtn,I.$N.POWER),this._bindButtonEvents(this._startPauseBtn,I.$N.START_PAUSE),this._bindButtonEvents(this._soundBtn,I.$N.SOUND),this._bindButtonEvents(this._resetBtn,I.$N.RESET),this._bindButtonEvents(this._exitBtn,I.$N.EXIT),this._bindButtonEvents(this._enableColorBtn,I.$N.COLOR),this._bindButtonEvents(this._upBtn,I.$N.UP),this._bindButtonEvents(this._downBtn,I.$N.DOWN),this._bindButtonEvents(this._rightBtn,I.$N.RIGHT),this._bindButtonEvents(this._leftBtn,I.$N.LEFT),this._bindButtonEvents(this._actionBtn,I.$N.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=n.A.viewLayout.splashHideDelayMs);var e=document.querySelector(n.A.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const z=k},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={};return r=n(584),o=n(256),(0,r.N)(o.A),(()=>{n.r(s),n.d(s,{Color:()=>t.Q1,ControlEventType:()=>t.M8,ControlKey:()=>t.$N,FontAlign:()=>t.Z2,FontSize:()=>t.Z4,FontVerticalAlign:()=>t.TU,Game:()=>e.A,GameView:()=>i.A,Sound:()=>t.AB,StateProperty:()=>t.tr,bootstrap:()=>o.N,configs:()=>r.A});var t=n(906),e=(n(817),n(186)),i=n(900),r=n(728),o=n(584)})(),s})());
package/dist/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang=en><head><meta charset=UTF-8><title>P5 Project</title><script src=vendor/p5.min.js></script><link rel=icon href=favicon.ico><link href=css/brick-engine.bundle.css rel=stylesheet></head><body><div id=brick-game></div><div id=splash><img src=images/splash.gif></div><script defer=defer src=brick-engine.js></script><script defer=defer src=app.js></script></body></html>
1
+ <!doctype html><html lang=en><head><title>Brick Engine</title><script src=vendor/p5.min.js></script><meta name=author content=https://github.com/LeonardoPinheiroLacerda><meta name=Content-Type content="text/html; charset=UTF-8"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><link href=css/game.bundle.css rel=stylesheet></head><body><div id=brick-game></div><div id=splash><img src=images/splash.gif></div><script defer=defer src=game.bundle.js></script></body></html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-engine-js",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A lightweight brick engine built with p5.js and TypeScript",
5
5
  "type": "commonjs",
6
6
  "main": "dist/brick-engine.js",
package/dist/app.js DELETED
@@ -1 +0,0 @@
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);var r=n(991),o=n.n(r);const s={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)"},a={columns:11,rows:18},u={width:.65,height:.956,margin:.022,borderWeight:.0075},c={extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},l={margin:.1,padding:.3,strokeWeight:.075},h=1.9,p=600,d={widthRatio:.7,aspectRatio:1.114},f=250,g={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"}},y="3px",_="body-color",v="button-color",m="#brick-game",b="#splash",w={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"},E=250,x=50,S=1e3/30,R=1e3/60,C={msInterval:100,enabled:!0},P={volume:.025};var O,T,M,D,I,A,G,L,B={grad:.9,turn:360,rad:360/(2*Math.PI)},k=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},z=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},N=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},H=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},F=function(t){return{r:N(t.r,0,255),g:N(t.g,0,255),b:N(t.b,0,255),a:N(t.a)}},j=function(t){return{r:z(t.r),g:z(t.g),b:z(t.b),a:z(t.a,3)}},U=/^#([0-9a-f]{3,8})$/i,W=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},V=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}},K=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}},Y=function(t){return{h:H(t.h),s:N(t.s,0,100),l:N(t.l,0,100),a:N(t.a)}},X=function(t){return{h:z(t.h),s:z(t.s),l:z(t.l),a:z(t.a,3)}},J=function(t){return K((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},q=function(t){return{h:(e=V(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},$=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Q=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Z=/^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,et={string:[[function(t){var e=U.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?z(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?z(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Z.exec(t)||tt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:F({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=$.exec(t)||Q.exec(t);if(!e)return null;var i,n,r=Y({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(B[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return J(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 k(e)&&k(i)&&k(n)?F({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(!k(e)||!k(i)||!k(n))return null;var s=Y({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return J(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!k(e)||!k(i)||!k(n))return null;var s=function(t){return{h:H(t.h),s:N(t.s,0,100),v:N(t.v,0,100),a:N(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(o)});return K(s)},"hsv"]]},it=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]},nt=function(t,e){var i=q(t);return{h:i.h,s:N(i.s+100*e,0,100),l:i.l,a:i.a}},rt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},ot=function(t,e){var i=q(t);return{h:i.h,s:i.s,l:N(i.l+100*e,0,100),a:i.a}},st=function(){function t(t){this.parsed=function(t){return"string"==typeof t?it(t.trim(),et.string):"object"==typeof t&&null!==t?it(t,et.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 z(rt(this.rgba),2)},t.prototype.isDark=function(){return rt(this.rgba)<.5},t.prototype.isLight=function(){return rt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=j(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?W(z(255*r)):"","#"+W(e)+W(i)+W(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return j(this.rgba)},t.prototype.toRgbString=function(){return e=(t=j(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 X(q(this.rgba))},t.prototype.toHslString=function(){return e=(t=X(q(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=V(this.rgba),{h:z(t.h),s:z(t.s),v:z(t.v),a:z(t.a,3)};var t},t.prototype.invert=function(){return at({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),at(nt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),at(nt(this.rgba,-t))},t.prototype.grayscale=function(){return at(nt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),at(ot(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),at(ot(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?at({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):z(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=q(this.rgba);return"number"==typeof t?at({h:t,s:e.s,l:e.l,a:e.a}):z(e.h)},t.prototype.isEqual=function(t){return this.toHex()===at(t).toHex()},t}(),at=function(t){return t instanceof st?t:new st(t)};function ut(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 ct(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}!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)"}(O||(O={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(T||(T={})),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"}(M||(M={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(D||(D={})),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"}(I||(I={})),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"}(A||(A={})),function(t){t.PRESSED="pressed",t.HELD="held"}(G||(G={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(L||(L={}));const lt=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,G.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,G.HELD)},x),n=e._activeKeys.get(t);n&&(n.hold=i)},E);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 ht=function(){function t(t,e){this._moduleElements=[],this._gameModules=t,this._p=e}return t.prototype.setup=function(){var t=this;if(C.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 pt=ht;var dt=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 ft=dt;var gt=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(_)?i.get(_):s.bodyMain,r=i.has(v)?i.get(v):s.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",at(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",at(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",at(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",at(r).darken(.15).toHex());var o=function(t,e){var i,n=t.createDiv();if(n.parent(m),n.id(w.container),e.clientWidth<=p)return{container:n,width:i=e.clientWidth,height:e.clientHeight};var r=e.clientHeight/(1.05*h);return{container:n,width:i=Math.min(e.clientWidth,r),height:i*h}}(this._p,this._parent),a=o.container,u=o.height,c=o.width,l=function(t,e){var i=t.createDiv();i.parent(e),i.id(w.frame);var n=t.createDiv();return n.parent(i),t.createP("Brick Game").parent(n),i}(this._p,a),f=function(t,e,i){var n=i*d.widthRatio,r=n*d.aspectRatio,o=t.createCanvas(n,r);return o.parent(e),o.id(w.canvas),{canvasWidth:n,canvasHeight:r,canvas:o}}(this._p,l,c),b=f.canvas,E=f.canvasHeight,x=f.canvasWidth,S=function(t,e){var i=t.createDiv();i.parent(e),i.id(w.buttonContainer);var n=t.createDiv();n.parent(i),n.id(w.smallButtonContainer);var r=t.createDiv();r.parent(i),r.id(w.innerButtonContainer);var o=t.createDiv();o.parent(r),o.id(w.mediumButtonContainer);var s=t.createDiv();s.parent(o),s.id(w.directionVerticalContainer);var a=t.createDiv();a.parent(o),a.id(w.directionHorizontalContainer);var u=t.createDiv();return u.parent(r),u.id(w.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(this._p,a),R=S.largeButtonContainer,C=S.smallButtonContainer,P=S.directionHorizontalContainer,O=S.directionVerticalContainer;return this._onOffBtn=ct(this._p,C,"On<br/>Off",!0),this._startPauseBtn=ct(this._p,C,"Start<br/>Pause",!1),this._soundBtn=ct(this._p,C,"Sound",!0),this._resetBtn=ct(this._p,C,"Reset",!1),this._exitBtn=ct(this._p,C,"Exit",!0),this._enableColorBtn=ct(this._p,C,"Enable<br/>Colors",!1),this._upBtn=ut(this._p,O,"UP"),this._leftBtn=ut(this._p,P,"LEFT"),this._downBtn=ut(this._p,O,"DOWN"),this._rightBtn=ut(this._p,P,"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,R),function(t,e,i,n){var r=document.querySelector(":root");r.style.setProperty("--dispersion",y),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*g.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*g.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*g.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*g.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*g.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*g.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*g.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*g.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*g.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*g.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*g.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*g.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*g.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*g.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",g.button.animationDuration)}(c,u,x,E),this._hideSplash(),this._cachedCanvas={canvas:b,canvasWidth:x,canvasHeight:E},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new ft(this._p),this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new pt(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 lt(t),this._bindButtonEvents(this._onOffBtn,A.POWER),this._bindButtonEvents(this._startPauseBtn,A.START_PAUSE),this._bindButtonEvents(this._soundBtn,A.SOUND),this._bindButtonEvents(this._resetBtn,A.RESET),this._bindButtonEvents(this._exitBtn,A.EXIT),this._bindButtonEvents(this._enableColorBtn,A.COLOR),this._bindButtonEvents(this._upBtn,A.UP),this._bindButtonEvents(this._downBtn,A.DOWN),this._bindButtonEvents(this._rightBtn,A.RIGHT),this._bindButtonEvents(this._leftBtn,A.LEFT),this._bindButtonEvents(this._actionBtn,A.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=f);var e=document.querySelector(b);setTimeout(function(){e.style.display="none"},t)},t}();const yt=gt;var _t={ArrowUp:A.UP,ArrowDown:A.DOWN,ArrowLeft:A.LEFT,ArrowRight:A.RIGHT,KeyW:A.UP,KeyS:A.DOWN,KeyA:A.LEFT,KeyD:A.RIGHT,KeyJ:A.ACTION,Digit1:A.POWER,Digit2:A.START_PAUSE,Digit3:A.SOUND,Digit4:A.RESET,Digit5:A.EXIT,Digit6:A.COLOR};const vt=function(){function t(t){this._inputHandler=new lt(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=_t[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=_t[t.code];e&&this._inputHandler.handleRelease(e)},t}();var mt=function(){function t(){this._subscribers=new Map}return t.prototype.setup=function(){this._keyBinding=new vt(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===A.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 bt=mt,wt=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:O.DEFAULT,coordinate:t}},t}();var Et=function(){return Et=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},Et.apply(this,arguments)},xt=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return Et(Et({},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:Et(Et({},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 St=xt;var Rt=function(){return Rt=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},Rt.apply(this,arguments)},Ct=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 Rt(Rt({},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 Rt(Rt({},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 Pt=Ct;var Ot=function(){return Ot=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},Ot.apply(this,arguments)},Tt=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=Ot({},this.grid.getCell(t)),n=Ot({},this.grid.getCell(e));this.grid.stampCell(Ot(Ot({},n),{coordinate:t})),this.grid.stampCell(Ot(Ot({},i),{coordinate:e}))},t}();const Mt=Tt;var Dt=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]=wt.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]=wt.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 It=Dt;var At=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 Gt=At;var Lt=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new St(this),this._transformEngine=new Pt(this),this._analysisEngine=new Mt(this),this._lineEngine=new It(this),this._regionEngine=new Gt(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return a.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return a.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]=wt.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 Bt=Lt;var kt=function(){function t(){}return t.getRelativeWidth=function(t,e){return e*t.width},t.getRelativeHeight=function(t,e){return e*t.height},t}();const zt=kt;var Nt=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=l,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=u.borderWeight;this._staticGraphics=this._p.createGraphics(this._p.width,this._p.height),this._staticGraphics.background(s.background),this._staticGraphics.strokeWeight(zt.getRelativeWidth(this._p,t)),this._staticGraphics.noFill(),this._staticGraphics.stroke(s.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,r=t.value,o=i.x,s=i.y,a=this._cellPreCalculatedGeometry,u=a.innerOffset,c=a.innerSize,l=a.paddingOffset,h=a.paddingSize,p=a.strokeWeight;n=0===r||!e.isPlaying()&&!e.isPaused()?O.INACTIVE:e.isColorEnabled()?n:O.DEFAULT,this._p.push(),this._p.translate(this._rendererMetrics.display.origin.x+o*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+s*this._rendererMetrics.cell.size),this._p.strokeWeight(p),this._p.stroke(n),this._p.noFill(),this._p.rect(u,u,c,c),this._p.fill(n),this._p.rect(l,l,h,h),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 Ht=Nt;var Ft=function(){function t(){}return t.getRelativeCoordinate=function(t,e){return{x:zt.getRelativeWidth(t,e.x),y:zt.getRelativeHeight(t,e.y)}},t.getDisplayPosX=function(t,e,i){var n=u.margin;return i*e+zt.getRelativeWidth(t,n)},t.getDisplayPosY=function(t,e,i){var n=u.margin;return i*e+zt.getRelativeHeight(t,n)},t.getHudPosX=function(t,e,i){var n=u.margin,r=i+2*zt.getRelativeWidth(t,n);return(t.width-r-zt.getRelativeWidth(t,n))*e+r},t.getHudPosY=function(t,e,i){var n=u.margin;return i*e+zt.getRelativeHeight(t,n)},t}();const jt=Ft;var Ut=function(){function t(t){this._p=t}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:jt.getHudPosX(this._p,.078,t.display.width),y:jt.getHudPosY(this._p,.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-zt.getRelativeWidth(this._p,.005),y:this._gridOrigin.y-zt.getRelativeHeight(this._p,.005),w:4*this._cellSize+zt.getRelativeWidth(this._p,.01),h:4*this._cellSize+zt.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(M.SMALL),e.setInactiveText(),e.setTextAlign(T.LEFT,D.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(T.CENTER,D.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,r=i.x,o=i.y;n.isOff()&&!n.isPlaying()&&(t.value=0);var s=0!==t.value?O.DEFAULT:O.INACTIVE;n.isColorEnabled()&&0!==t.value&&(s=t.color),e.drawCellElement({w:e._cellSize,h:e._cellSize,posX:e._gridOrigin.x+e._cellSize*r,posY:e._gridOrigin.y+e._cellSize*o,color:s})}),this._p.noFill(),this._p.stroke(n.isOn()?O.DEFAULT:O.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=l,s=o.margin,a=o.padding,u=s*e,c=e-s*e*2,h=a*e,p=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(h,h,p,p),this._p.pop()},t}();const Wt=Ut;var Vt=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 Ht(this._p),this._hudRenderer=new Wt(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=u,e=t.width,i=t.height,n=t.margin,r=a.columns,o=zt.getRelativeWidth(this._p,e),s=zt.getRelativeHeight(this._p,i),c=jt.getRelativeCoordinate(this._p,{x:n,y:n}),l=o/r,h={x:jt.getHudPosX(this._p,0,o),y:jt.getHudPosY(this._p,0,s)},p=jt.getHudPosX(this._p,1,o)-h.x,d=jt.getHudPosY(this._p,1,s)-h.y;this._rendererMetrics={display:{width:o,height:s,origin:c},hud:{width:p,height:d,origin:h},cell:{size:l}}},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 Kt=Vt;var Yt,Xt=((Yt={})[L.ON]={defaultValue:!1},Yt[L.START]={defaultValue:!1},Yt[L.PLAYING]={defaultValue:!1},Yt[L.GAME_OVER]={defaultValue:!1},Yt[L.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},Yt[L.MUTED]={defaultValue:!1,storageKey:"muted"},Yt),Jt=function(){function t(){this._state=new Map,this._subscribers=new Map}return t.prototype.setup=function(){var t=this;Object.values(L).forEach(function(e){var i=Xt[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(L).forEach(function(e){var i=Xt[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=Xt[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(L.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(L.START)},t.prototype.isPlaying=function(){return this._state.get(L.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(L.GAME_OVER)},t.prototype.turnOn=function(){this._set(L.ON,!0),this._set(L.START,!1),this._set(L.PLAYING,!1),this._set(L.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(L.ON,!1),this._set(L.START,!1),this._set(L.PLAYING,!1),this._set(L.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(L.START,!0),this._set(L.PLAYING,!0),this._set(L.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(L.GAME_OVER,!1),this._set(L.START,!0),this._set(L.PLAYING,!0)},t.prototype.exitGame=function(){this._set(L.START,!1),this._set(L.PLAYING,!1),this._set(L.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(L.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(L.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(L.PLAYING,!1),this._set(L.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(L.GAME_OVER,!1),this._set(L.START,!0),this._set(L.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(L.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(L.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(L.MUTED)},t.prototype.setMuted=function(t){this._set(L.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 qt=Jt;var $t=function(){function t(t){this.defaultFontFamily="retro-gamming",this.fontSizes=[0],this._p=t}return t.prototype.setup=function(){var t=c,e=t.extraSmall,i=t.small,n=t.medium,r=t.large,o=t.extraLarge;this._p.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[M.EXTRA_SMALL]=zt.getRelativeWidth(this._p,e),this.fontSizes[M.SMALL]=zt.getRelativeWidth(this._p,i),this.fontSizes[M.MEDIUM]=zt.getRelativeWidth(this._p,n),this.fontSizes[M.LARGE]=zt.getRelativeWidth(this._p,r),this.fontSizes[M.EXTRA_LARGE]=zt.getRelativeWidth(this._p,o)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=s.active,i=s.inactive;this._p.fill(t?e:i)},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=jt.getHudPosX(this._p,e.x,this._rendererMetrics.display.width),n=jt.getHudPosY(this._p,e.y,this._rendererMetrics.display.height);this._p.text(t,i,n)},t.prototype.textOnDisplay=function(t,e){var i=jt.getDisplayPosX(this._p,e.x,this._rendererMetrics.display.width),n=jt.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 Qt=$t,Zt=function(){function t(){this._accumulatedTime=0,this._initialTickInterval=S,this._minTickInterval=R,this._tickInterval=S,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 te=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())})},ee=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])}}},ie=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=P.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 te(this,void 0,void 0,function(){var e,i,n;return ee(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 te(this,void 0,void 0,function(){var e;return ee(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 te(this,void 0,void 0,function(){var t,e,i,n;return ee(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 te(this,void 0,void 0,function(){var t,e=this;return ee(this,function(i){switch(i.label){case 0:return t=Object.values(I).map(function(t){return te(e,void 0,void 0,function(){var e,i,n;return ee(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(L.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 ne=ie,re=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 oe,se=(oe=function(t,e){return oe=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])},oe(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}oe(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const ae=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return se(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}(Bt),ue=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 qt)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ce=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 le=ce,he=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(L.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(L.GAME_OVER,function(t){t&&e._destroySession()}),t.subscribe(L.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 pe=function(){function t(t,e){this._modules=void 0,this._initialStateSnapshot=new le,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 Kt(this._p),grid:new Bt,hudGrid:new ae,text:new Qt(this._p),state:new qt,control:new bt,time:new Zt,sound:new ne,score:new re,session:new he},Object.values(this._modules).forEach(function(t){ue.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){ue.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){ue.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(A.POWER,G.PRESSED,function(){n.isOn()?(n.turnOff(),t.modules.sound.stopAll()):n.turnOn()}),i.subscribe(A.SOUND,G.PRESSED,function(){return n.toggleMuted()}),i.subscribe(A.COLOR,G.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(A.RESET,G.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(A.EXIT,G.PRESSED,function(){t._modules.session.clearSession()}),i.subscribe(A.START_PAUSE,G.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(L.ON,function(e){e||(r.resetGrid(),t.modules.score.resetScore(),t.modules.score.resetLevel(),t.modules.time.reset())})},t}();const de=pe;var fe=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 ge=fe;var ye=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 _e=ye;var ve=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)}}(),me=function(t){function e(e,i){var n=t.call(this,e,i)||this;return n._gameSelectionPointer=0,n._isLoading=!1,n._gameRepository=new ge,n._gameManager=new _e,n}return ve(e,t),e.prototype.setupGame=function(){var t=this,e=this.modules,i=e.state,n=e.control,r=e.sound;n.subscribe(A.ACTION,G.PRESSED,function(){if(!t._isLoading&&i.isStarted()){var e=t._gameRepository.games[t._gameSelectionPointer];t._gameManager.handleGameSwitch(e,t)}}),n.subscribe(A.LEFT,G.PRESSED,function(){i.isPlaying()&&(r.play(I.ACTION_1),0===t._gameSelectionPointer?t._gameSelectionPointer=t._gameRepository.games.length-1:t._gameSelectionPointer--)}),n.subscribe(A.RIGHT,G.PRESSED,function(){i.isPlaying()&&(r.play(I.ACTION_1),t._gameSelectionPointer===t._gameRepository.games.length-1?t._gameSelectionPointer=0:t._gameSelectionPointer++)}),i.subscribe(L.ON,function(t){t&&r.play(I.START_THEME)})},e.prototype.update=function(){},e.prototype.render=function(){var t=this.modules.text,e=this.p;e.push(),t.setTextSize(M.LARGE),t.setActiveText(),t.setTextAlign(T.CENTER,D.BOTTOM),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(M.SMALL),t.textOnDisplay("Choose a game and",{x:.5,y:.25}),t.textOnDisplay("Press action to play",{x:.5,y:.32}),t.setTextAlign(T.RIGHT,D.BOTTOM),t.textOnDisplay("<",{x:.1,y:.54}),t.setTextAlign(T.LEFT,D.BOTTOM),t.textOnDisplay(">",{x:.9,y:.54}),t.setTextSize(M.MEDIUM),t.setTextAlign(T.CENTER,D.BOTTOM),t.textOnDisplay(this._gameRepository.games[this._gameSelectionPointer].name,{x:.5,y:.55}),t.setTextSize(M.EXTRA_SMALL),t.setTextAlign(T.LEFT,D.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(M.LARGE),t.setActiveText(),t.setTextAlign(T.CENTER,D.TOP),t.textOnDisplay("Menu",{x:.5,y:.15}),t.setTextSize(M.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}(de);const be=me,we=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 Ee,xe,Se,Re=function(t){try{Ee.view.unbindControls(),t.propagateSwitchHandler(Ee),t.setup();var e=t.modules,i=e.control,n=e.state;t.view.updateDebuggerGameModules(t.modules),t.view.bindControls(i),n.turnOn(),we.hasInstance()&&t!==we.getInstance()&&(i.subscribe(A.EXIT,G.PRESSED,function(){t.switchGame(we.getInstance())}),i.subscribe(A.POWER,G.PRESSED,function(){t.switchGame(we.getInstance()),n.turnOff()})),Ee=t}catch(t){console.error("Error switching game:",t)}xe.loop()};return Se=be,window.BrickEngineGame=Se,new(o())(function(t){xe=t;var e=new yt(t,document.body);Se===be?((Ee=new Se(t,e)).gameId="game-menu",we.setInstance(Ee)):(Ee=new Se(t,e)).gameId="game",Ee.setSwitchHandler(Re),t.setup=function(){Ee.setup(),Ee.view.setupDebugger(Ee.modules),Ee.view.setupSessionModal()},t.draw=function(){Ee.draw(),Ee.view.updateDebugger()}}),{}})());
@@ -1 +0,0 @@
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})());