brick-engine-js 1.0.26 → 1.0.27

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.
@@ -726,6 +726,11 @@ body {
726
726
  touch-action: none !important;
727
727
  }
728
728
 
729
+ #session-modal-screen p {
730
+ font-size: 1rem !important;
731
+ line-height: 1.2rem !important;
732
+ }
733
+
729
734
  #debugger {
730
735
  display: none !important;
731
736
  }
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return e[t](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r,o,s,a,u,c,l,h,d={};n.r(d),n.d(d,{Color:()=>r,ControlEventType:()=>l,ControlKey:()=>c,EventEmitter:()=>m,FontAlign:()=>o,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>pt,GameView:()=>Kt,RendererContext:()=>B,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>$t,configs:()=>p,setActiveGame:()=>Qt}),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)",t.SHADOW="rgb(93, 105, 92)"}(r||(r={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(o||(o={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const p={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},p.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},p.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var v;!function(t){t.TITLE="title",t.PLAYING="playing",t.GAMEOVER="gameover",t.PAUSED="paused"}(v||(v={}));const m=function(){function t(){}return t.subscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]||(this._events[n]=[]),this._events[n].push(e)},t.unsubscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]&&(this._events[n]=this._events[n].filter(function(t){return t!==e}))},t.notify=function(t,e){this._events[t]&&this._events[t].forEach(function(t){return t(e)})},t.notifyContextual=function(t,e,i){this.notify(t,e),i.isPlaying()?this.notify(this._formatName(t,v.PLAYING),e):i.isPaused()?this.notify(this._formatName(t,v.PAUSED),e):i.isOn()&&!i.isStarted()?this.notify(this._formatName(t,v.TITLE),e):i.isGameOver()&&this.notify(this._formatName(t,v.GAMEOVER),e)},t._formatName=function(t,e){return e?"".concat(t,":").concat(e):t},t.clear=function(){this._events={}},t._events={},t}();var _=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._activeListeners.forEach(function(t){var e=t.event,i=t.callback;m.unsubscribe(e,i)}),this._activeListeners=[]},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribe(t,e,i)},t.prototype.unsubscribe=function(t,e,i){this._unsubscribe(t,e,i)},t.prototype.subscribeForTitleScreen=function(t,e,i){this._subscribe(t,e,i,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e,i){this._unsubscribe(t,e,i,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e,i){this._subscribe(t,e,i,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e,i){this._unsubscribe(t,e,i,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e,i){this._subscribe(t,e,i,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e,i){this._subscribe(t,e,i,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PAUSED)},t.prototype._subscribe=function(t,e,i,n){var r="".concat(t,":").concat(e);m.subscribe(r,i,n);var o=n?"".concat(r,":").concat(n):r;this._activeListeners.push({event:o,callback:i})},t.prototype._unsubscribe=function(t,e,i,n){var r="".concat(t,":").concat(e);m.unsubscribe(r,i,n);var o=n?"".concat(r,":").concat(n):r;this._activeListeners=this._activeListeners.filter(function(t){return!(t.event===o&&t.callback===i)})},t.prototype.notify=function(t,e){if(!this._modules)throw new Error("Modules not initialized");var i={key:t,type:e,modules:this._modules},n=this._modules.state,r=this._modules.session,o=!1;r.isModalOpen()||n.isPlaying()&&!r.isSessionResolved()?o=!1:n.isOff()?o=t===c.POWER:!n.isStarted()||n.isPlaying()||n.isGameOver()?o=!0:n.isPaused()&&(o=t.endsWith(";system")),o&&m.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const b=_,E=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:r.DEFAULT,coordinate:t}},t}();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)},w=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return S(S({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),r=n.some(function(e){if(!i.grid.isCoordinateValid(e.coordinate))return!0;var n,r=i.grid.getCell(e.coordinate);return r&&i.grid.isCellActive(r)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}))});return r?t: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)};if(!this.grid.isCoordinateValid(i))return t;var n=this.grid.getCell(i);return n&&this.grid.isCellActive(n)?t:S(S({},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);i!==e;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);i!==e;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);i!==e;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);i!==e;)e=i,i=this.movePieceRight(e);return e},t}();const P=w;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)},C=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var r=t.map(function(t){var n=t.coordinate.x-e.x,r=t.coordinate.y-e.y,o=i?-r:r,s=i?n:-n;return R(R({},t),{coordinate:{x:e.x+o,y:e.y+s}})}),o=r.some(function(e){if(!n.grid.isCoordinateValid(e.coordinate))return!0;var i,r=n.grid.getCell(e.coordinate);return r&&n.grid.isCellActive(r)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}))});return o?t: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 R(R({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const x=C;var O=function(){return O=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},O.apply(this,arguments)},T=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++){var r=this.grid.getCell({x:n,y:e});if(r&&!this.grid.isCellActive(r)){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++){var r=this.grid.getCell({x:e,y:n});if(r&&!this.grid.isCellActive(r)){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};if(i.grid.isCoordinateValid(r)){var o=i.grid.getCell(r);o&&n.push(o)}}),n},t.prototype.findConnectedCells=function(t){var e=this,i=this.grid.getCell(t);if(!i||!this.grid.isCellActive(i))return[];var n=i.value,r=[],o=new Set,s=[t],a=function(t){return"".concat(t.x,",").concat(t.y)};for(o.add(a(t));s.length>0;){var u=s.shift(),c=this.grid.getCell(u);c.value===n&&(r.push(c),[{x:u.x-1,y:u.y},{x:u.x+1,y:u.y},{x:u.x,y:u.y-1},{x:u.x,y:u.y+1}].forEach(function(t){var i=a(t),n=e.grid.getCell(t);e.grid.isCoordinateValid(t)&&!o.has(i)&&n&&e.grid.isCellActive(n)&&(o.add(i),s.push(t))}))}return r},t.prototype.swapCells=function(t,e){var i=O({},this.grid.getCell(t)),n=O({},this.grid.getCell(e));this.grid.stampCell(O(O({},n),{coordinate:t})),this.grid.stampCell(O(O({},i),{coordinate:e}))},t}();const A=T;var I=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]=E.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]=E.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 L=I;var M=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){if(!e.grid.isCoordinateValid(t))return!0;var i=e.grid.getCell(t);return i&&e.grid.isCellActive(i)})},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=M;var G=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new P(this),this._transformEngine=new x(this),this._analysisEngine=new A(this),this._lineEngine=new L(this),this._regionEngine=new D(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return p.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return p.screenLayout.grid.rows},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topRow",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomRow",{get:function(){return this.height-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftColumn",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightColumn",{get:function(){return this.width-1},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]=E.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.isCoordinateValid=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isCoordinateValid(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){return null!==t&&t.value>0},t.prototype.isCellInactive=function(t){return null!==t&&0===t.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 JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},t}();const k=G,B=function(){function t(){}return t.init=function(t){this._p?console.warn("[BrickEngine] RendererContext is already initialized. Ignoring subsequent initialization."):this._p=t},Object.defineProperty(t,"p",{get:function(){if(!this._p)throw new Error("RendererContext not initialized yet. Ensure the Game object has been created.");return this._p},enumerable:!1,configurable:!0}),t.reset=function(){this._p=void 0},t}(),N=function(){function t(){}return t.getRelativeWidth=function(t){return t*B.p.width},t.getRelativeHeight=function(t){return t*B.p.height},t}();var z=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=p.screenLayout.cell,i=e.margin,n=e.padding,r=e.strokeWeight,o=this._rendererMetrics.cell.size;this._cellPreCalculatedGeometry={innerOffset:i*o,innerSize:o-i*o*2,paddingOffset:n*o,paddingSize:o-n*o*2,strokeWeight:r*o},this._renderStaticElements()},t.prototype.render=function(t,e){var i=B.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=B.p,e=p.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(p.colors.background),this._staticGraphics.strokeWeight(N.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(p.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,o=t.value,s=B.p,a=i.x,u=i.y,c=this._cellPreCalculatedGeometry,l=c.innerOffset,h=c.innerSize,d=c.paddingOffset,p=c.paddingSize,f=c.strokeWeight;n=0===o||!e.isPlaying()&&!e.isPaused()?r.INACTIVE:e.isColorEnabled()?n:r.DEFAULT,s.push(),s.translate(this._rendererMetrics.display.origin.x+a*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+u*this._rendererMetrics.cell.size),s.strokeWeight(f),s.stroke(n),s.noFill(),s.rect(l,l,h,h),s.fill(n),s.rect(d,d,p,p),s.pop()},t.prototype.renderGrid=function(t,e){var i=this;t.forEach(function(t){t.forEach(function(t){i.renderCell(t,e)})})},t}();const F=z;var H=function(){function t(){}return t.getRelativeCoordinate=function(t){return{x:N.getRelativeWidth(t.x),y:N.getRelativeHeight(t.y)}},t.getDisplayPosX=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=B.p,n=p.screenLayout.display.margin,r=N.getRelativeWidth(n),o=e+2*r;return(i.width-o-r)*t+o},t.getHudPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t}();const U=H;var j=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:U.getHudPosX(.078,t.display.width),y:U.getHudPosY(.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-N.getRelativeWidth(.005),y:this._gridOrigin.y-N.getRelativeHeight(.005),w:4*this._cellSize+N.getRelativeWidth(.01),h:4*this._cellSize+N.getRelativeHeight(.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=B.p,i=t.text,n=t.state,r=t.score;e.push(),i.setTextSize(s.SMALL),i.setInactiveText(),i.setTextAlign(o.LEFT,a.BOTTOM),i.textOnHud("88888888",{x:.05,y:.13}),i.textOnHud("88888888",{x:.05,y:.3}),i.textOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.textOnHud("Score",{x:.05,y:.06}),i.textOnHud(r.score.toString(),{x:.05,y:.13}),i.textOnHud("Hi-Score",{x:.05,y:.23}),i.textOnHud(r.highScore.toString(),{x:.05,y:.3}),i.textOnHud("Level",{x:.05,y:.72});var u="".concat(r.level<10?"0"+r.level:r.level," - ").concat(r.maxLevel);i.textOnHud(u,{x:.05,y:.8}),i.setTextAlign(o.CENTER,a.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.textOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.textOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=B.p,n=t.hudGrid,o=t.state;i.push(),n.forEach(function(t){var i=t.coordinate,n=i.x,s=i.y;o.isOff()&&!o.isPlaying()&&(t.value=0);var a=0!==t.value?r.DEFAULT:r.INACTIVE;o.isColorEnabled()&&0!==t.value&&(a=t.color),e.drawCellElement({w:e._cellSize,h:e._cellSize,posX:e._gridOrigin.x+e._cellSize*n,posY:e._gridOrigin.y+e._cellSize*s,color:a})}),i.noFill(),i.stroke(o.isOn()?r.DEFAULT:r.INACTIVE),i.rect(this._hudBorderRect.x,this._hudBorderRect.y,this._hudBorderRect.w,this._hudBorderRect.h),i.pop()},t.prototype.drawCellElement=function(t){var e=t.w,i=t.posX,n=t.posY,r=t.color,o=B.p,s=p.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,f=s.strokeWeight*e;o.push(),o.translate(i,n),o.strokeWeight(f),o.stroke(r),o.noFill(),o.rect(c,c,l,l),o.fill(r),o.rect(h,h,d,d),o.pop()},t}();const V=j;var W=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new F,this._hudRenderer=new V,this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=p.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=p.screenLayout.grid.columns,o=N.getRelativeWidth(e),s=N.getRelativeHeight(i),a=U.getRelativeCoordinate({x:n,y:n}),u=o/r,c={x:U.getHudPosX(0,o),y:U.getHudPosY(0,s)},l=U.getHudPosX(1,o)-c.x,h=U.getHudPosY(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 Y=W;var K,X=((K={})[h.ON]={defaultValue:!1},K[h.START]={defaultValue:!1},K[h.PLAYING]={defaultValue:!1},K[h.GAME_OVER]={defaultValue:!1},K[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},K[h.MUTED]={defaultValue:!1,storageKey:"muted"},K);const J=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=X[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=X[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this.notify(t)}},t.prototype.notify=function(t){var e=this._state.get(t);m.notifyContextual(t,e,this)},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){this._subscribe(t,e)},t.prototype.unsubscribe=function(t,e){this._unsubscribe(t,e)},t.prototype.subscribeForTitleScreen=function(t,e){this._subscribe(t,e,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e){this._unsubscribe(t,e,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e){this._subscribe(t,e,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e){this._unsubscribe(t,e,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e){this._subscribe(t,e,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e){this._unsubscribe(t,e,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e){this._subscribe(t,e,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e){this._unsubscribe(t,e,v.PAUSED)},t.prototype._subscribe=function(t,e,i){m.subscribe(t,e,i)},t.prototype._unsubscribe=function(t,e,i){m.unsubscribe(t,e,i)},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}();var q=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=B.p,e=p.screenLayout.fontSize,i=e.extraSmall,n=e.small,r=e.medium,o=e.large,a=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=N.getRelativeWidth(i),this.fontSizes[s.SMALL]=N.getRelativeWidth(n),this.fontSizes[s.MEDIUM]=N.getRelativeWidth(r),this.fontSizes[s.LARGE]=N.getRelativeWidth(o),this.fontSizes[s.EXTRA_LARGE]=N.getRelativeWidth(a)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=B.p,i=p.colors,n=i.active,r=i.inactive;e.fill(t?n:r)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setTextSize=function(t){B.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){B.p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=B.p,n=U.getHudPosX(e.x,this._rendererMetrics.display.width),r=U.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.textOnDisplay=function(t,e){var i=B.p,n=U.getDisplayPosX(e.x,this._rendererMetrics.display.width),r=U.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const Q=q,$=function(){function t(){this._tickAccumulator=0,this._initialTickInterval=p.game.tickInterval,this._minTickInterval=p.game.minTickInterval,this._tickInterval=p.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._tickAccumulator+=t,this._totalElapsedTime+=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._tickAccumulator>=this._tickInterval&&(this._tickAccumulator-=this._tickInterval,this._tickCounter++,this._totalTicks++,!0)},t.prototype.reset=function(){this._tickAccumulator=0,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=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),tick_accumulator:this._tickAccumulator.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},Object.defineProperty(t.prototype,"totalTicks",{get:function(){return this._totalTicks},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"elapsedTime",{get:function(){return this._totalElapsedTime},enumerable:!1,configurable:!0}),t.prototype.isTickEvery=function(t){return this._totalTicks>0&&this._totalTicks%t===0},t.prototype.captureInitialState=function(){this._initialTickInterval=this._tickInterval},t}();var Z=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())})},tt=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])}}},et=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=p.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return Z(this,void 0,void 0,function(){var e,i,n;return tt(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 Z(this,void 0,void 0,function(){var e;return tt(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 Z(this,void 0,void 0,function(){var t,e,i,n;return tt(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 Z(this,void 0,void 0,function(){var t,e=this;return tt(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return Z(e,void 0,void 0,function(){var e,i,n;return tt(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 it=et,nt=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this._gameId="unknown",this.serialId="score"}return t.prototype.setupGameHighScore=function(t){this._gameId=t,this._highScore=Number(localStorage.getItem("".concat(this._gameId,"::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("".concat(this._gameId,"::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 rt,ot=(rt=function(t,e){return rt=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])},rt(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}rt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const st=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return ot(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}(k),at=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 J)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ut=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{if(n&&"object"==typeof n){var o=Object.getPrototypeOf(n)===Object.prototype||null===Object.getPrototypeOf(n),s=Array.isArray(n);o||s?r=structuredClone(n):(console.warn("[BrickEngine] Property '".concat(i,"' is a complex object without a clone() or copy() method. A reference will be saved. State reset might not work for its internal properties.")),r=n)}else r=n;console.log("capturing property",i,r)}catch(t){console.error("Failed to clone property '".concat(i,"' (value: ").concat(String(n),"). Saving reference instead. Reset may not work as expected for this property. Error:"),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 ct=ut,lt=function(){function t(){this._isSessionResolved=!1,this._isModalOpen=!1,this._isEnabled=!0,this._resetFn=function(){},this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isSessionResolved&&this._isEnabled&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype.setResetFunction=function(t){this._resetFn=t},t.prototype.setSessionEnabled=function(t){this._isEnabled=t},t.prototype.isModalOpen=function(){return this._isModalOpen},t.prototype.isSessionResolved=function(){return this._isSessionResolved},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.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0})}}),t.subscribe(h.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(h.START,function(t){t||(e._isSessionResolved=!1)})},t.prototype.getDebugData=function(){return{game_id:this.gameId,is_session_resolved:this._isSessionResolved,is_modal_open:this._isModalOpen,is_enabled:this._isEnabled,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}(),ht=function(){function t(){}return t.setupControlEvents=function(t,e){var i=t.control,n=t.state,r=t.session,o=t.sound;i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.EXIT,l.PRESSED,function(){return r.clearSession()}),i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),o.stopAll()):n.turnOn()}),i.subscribeForGameOverScreen(c.POWER,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForTitleScreen(c.START_PAUSE,l.PRESSED,function(){return n.startGame()}),i.subscribeForPlayingScreen(c.START_PAUSE,l.PRESSED,function(){return n.pause()}),i.subscribeForGameOverScreen(c.START_PAUSE,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForPausedScreen(c.START_PAUSE,l.PRESSED,function(){return n.resume()}),i.subscribeForPlayingScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()}),i.subscribeForPausedScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()})},t.setupStateEvents=function(t){var e=t.state,i=t.session;e.subscribe(h.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),e.subscribeForGameOverScreen(h.GAME_OVER,function(){i.clearSession()})},t}();var dt=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new ct,this._gameId="unknown",this._view=t,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"p",{get:function(){return B.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new Y,grid:new k,hudGrid:new st,text:new Q,state:new J,control:new b,time:new $,sound:new it,score:new nt,session:new lt},Object.values(this._modules).forEach(function(t){at.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){at.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){at.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,r=e.renderer,o=e.session,s=e.score;o.gameId=this.gameId,o.setShowModalFunction(this._view.showSessionModal.bind(this._view)),o.setResetFunction(this.reset.bind(this)),n.setModules(this._modules),i.setRendererMetrics(r.rendererMetrics),s.setupGameHighScore(this.gameId),this.setupGame(),ht.setupControlEvents(this._modules,this.reset.bind(this)),ht.setupStateEvents(this._modules),this._view.bindControls(n),this._modules.time.captureInitialState(),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=B.p;if(this._modules){var e=this._modules,i=e.renderer,n=e.grid,r=e.time,o=e.state,s=e.session;s.isModalOpen()||o.isPlaying()&&!s.isSessionResolved()||(i.render(n.getGrid(),this._modules),o.isOn()&&(o.isStarted()?o.isPlaying()?(r.update(t.deltaTime),r.shouldTick()&&(this.update(t.deltaTime),this._modules.session.saveSession()),this.render()):o.isPaused()&&this.render():this.drawTitleScreen(),o.isGameOver()&&this.drawGameOverScreen()))}},t.prototype.destroy=function(){B.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},t.prototype.reset=function(){this._modules.grid.resetGrid(),this._modules.score.resetScore(),this._modules.score.resetLevel(),this._modules.time.reset(),this._modules.session.clearSession(),this._initialStateSnapshot.restoreInitialState(this)},t}();const pt=dt;var ft={grad:.9,turn:360,rad:360/(2*Math.PI)},gt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},yt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},vt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},mt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:vt(t.r,0,255),g:vt(t.g,0,255),b:vt(t.b,0,255),a:vt(t.a)}},bt=function(t){return{r:yt(t.r),g:yt(t.g),b:yt(t.b),a:yt(t.a,3)}},Et=/^#([0-9a-f]{3,8})$/i,St=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}},Pt=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}},Rt=function(t){return{h:mt(t.h),s:vt(t.s,0,100),l:vt(t.l,0,100),a:vt(t.a)}},Ct=function(t){return{h:yt(t.h),s:yt(t.s),l:yt(t.l),a:yt(t.a,3)}},xt=function(t){return Pt((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},Ot=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},Tt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,At=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt={string:[[function(t){var e=Et.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?yt(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?yt(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=It.exec(t)||Lt.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=Tt.exec(t)||At.exec(t);if(!e)return null;var i,n,r=Rt({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(ft[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return xt(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=void 0===r?1:r;return gt(e)&&gt(i)&&gt(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(!gt(e)||!gt(i)||!gt(n))return null;var s=Rt({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return xt(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!gt(e)||!gt(i)||!gt(n))return null;var s=function(t){return{h:mt(t.h),s:vt(t.s,0,100),v:vt(t.v,0,100),a:vt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(o)});return Pt(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]},Gt=function(t,e){var i=Ot(t);return{h:i.h,s:vt(i.s+100*e,0,100),l:i.l,a:i.a}},kt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Bt=function(t,e){var i=Ot(t);return{h:i.h,s:i.s,l:vt(i.l+100*e,0,100),a:i.a}},Nt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Dt(t.trim(),Mt.string):"object"==typeof t&&null!==t?Dt(t,Mt.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 yt(kt(this.rgba),2)},t.prototype.isDark=function(){return kt(this.rgba)<.5},t.prototype.isLight=function(){return kt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?St(yt(255*r)):"","#"+St(e)+St(i)+St(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return bt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+n+", "+r+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,r},t.prototype.toHsl=function(){return Ct(Ot(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ct(Ot(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:yt(t.h),s:yt(t.s),v:yt(t.v),a:yt(t.a,3)};var t},t.prototype.invert=function(){return zt({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),zt(Gt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,-t))},t.prototype.grayscale=function(){return zt(Gt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),zt(Bt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),zt(Bt(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?zt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):yt(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Ot(this.rgba);return"number"==typeof t?zt({h:t,s:e.s,l:e.l,a:e.a}):yt(e.h)},t.prototype.isEqual=function(t){return this.toHex()===zt(t).toHex()},t}(),zt=function(t){return t instanceof Nt?t:new Nt(t)};function Ft(t,e){var i=B.p,n=i.createDiv();n.parent(t),n.addClass("btn-container");var r=i.createButton(e);return r.parent(n),r.addClass("btn"),r}function Ht(t,e,i){var n=B.p,r=n.createDiv();r.parent(t),r.addClass("sm-btn-container"),r.addClass(i?"sm-btn-container-top":"sm-btn-container-bottom");var o=n.createButton("");o.parent(r),o.addClass("sm-btn");var s=n.createP(e);return s.parent(r),s.addClass("sm-btn-p"),o}var Ut=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(p.game.debugger.enabled){var e=B.p,i=e.select("#debugger"),n=!!i&&i.elt.hasAttribute("open"),r=new Set;i&&(e.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&r.add(t.id())}),i.remove()),this._moduleElements=[];var o=e.createElement("details");o.id("debugger"),n&&o.attribute("open",""),o.parent(e.select("body"));var s=e.createElement("summary");s.id("debugger-summary"),s.html("Debug"),s.parent(o),Object.entries(this._gameModules).forEach(function(i){var n=i[0],s=i[1];if("getDebugData"in s){var a={module:s,properties:[]},u=e.createElement("details");u.class("debugger-module"),u.id("debugger-".concat(n)),r.has("debugger-".concat(n))&&u.attribute("open",""),u.parent(o);var c=e.createElement("summary");c.id("debugger-".concat(n,"-summary")),c.html(n),c.class("debugger-module-summary"),c.parent(u);var l=s.getDebugData();Object.entries(l).forEach(function(t){var i=t[0],n=t[1],r=e.createElement("div");r.class("debugger-container"),r.id("debugger-container-".concat(i,"-").concat(n)),r.parent(u),r.mouseClicked(function(){r.toggleClass("highlight")});var o=e.createElement("p");o.id("debugger-".concat(i,"-").concat(n)),o.html("".concat(i,":")),o.parent(r);var s=e.createElement("span");s.id("debugger-".concat(i,"-").concat(n,"-value")),s.html("".concat(n)),s.parent(r),a.properties.push({key:i,element:s})}),t._moduleElements.push(a)}})}},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 jt=Ut;var Vt=function(){function t(){}return t.prototype.setup=function(){var t=B.p;this._container=t.createDiv(),this._container.parent(t.select("body")),this._container.id("modal-background"),this._container.class("hidden");var e=t.createDiv();e.parent(this._container),e.id("session-modal");var i=t.createDiv();i.parent(e),i.id("session-modal-frame");var n=t.createP();n.parent(i),n.html("Brick Engine Session");var r=t.createDiv();r.parent(i),r.id("session-modal-screen");var o=t.createP();o.parent(r),o.html("<span>Looks like you have an active session.</span><br><br>Do you want to continue?");var s=t.createDiv();s.parent(e),s.id("session-modal-buttons"),this._cancelButton=t.createButton("Cancel"),this._cancelButton.parent(s),this._cancelButton.class("session-modal-button"),this._confirmButton=t.createButton("Confirm"),this._confirmButton.parent(s),this._confirmButton.class("session-modal-button")},t.prototype.show=function(t,e){var i=this;this._confirmButton.mousePressed(function(){t(),i._hide()}),this._cancelButton.mousePressed(function(){e(),i._hide()}),this._container.removeClass("hidden")},t.prototype._hide=function(){this._confirmButton.mousePressed(null),this._cancelButton.mousePressed(null),this._container.addClass("hidden")},t}();const Wt=Vt;var Yt=function(){function t(t){this._parent=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,r;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(p.inputQueryParams.mainColor)?i.get(p.inputQueryParams.mainColor):p.colors.bodyMain,r=i.has(p.inputQueryParams.buttonColor)?i.get(p.inputQueryParams.buttonColor):p.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",zt(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",zt(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",zt(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",zt(r).darken(.15).toHex());var o=function(t){var e,i=B.p.createDiv();if(i.parent(p.selectors.parent),i.id(p.selectors.viewElementIds.container),t.clientWidth<=p.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*p.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*p.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=o.container,a=o.height,u=o.width,c=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.frame);var n=e.createDiv();return n.parent(i),e.createP("Brick Game").parent(n),i}(s),l=function(t,e){var i=B.p,n=e*p.viewLayout.canvas.widthRatio,r=n*p.viewLayout.canvas.aspectRatio,o=i.createCanvas(n,r);return o.parent(t),o.id(p.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:r,canvas:o}}(c,u),h=l.canvas,d=l.canvasHeight,f=l.canvasWidth,g=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.buttonContainer);var n=e.createDiv();n.parent(i),n.id(p.selectors.viewElementIds.smallButtonContainer);var r=e.createDiv();r.parent(i),r.id(p.selectors.viewElementIds.innerButtonContainer);var o=e.createDiv();o.parent(r),o.id(p.selectors.viewElementIds.mediumButtonContainer);var s=e.createDiv();s.parent(o),s.id(p.selectors.viewElementIds.directionVerticalContainer);var a=e.createDiv();a.parent(o),a.id(p.selectors.viewElementIds.directionHorizontalContainer);var u=e.createDiv();return u.parent(r),u.id(p.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(s),y=g.largeButtonContainer,v=g.smallButtonContainer,m=g.directionHorizontalContainer,_=g.directionVerticalContainer;return this._onOffBtn=Ht(v,"On<br/>Off",!0),this._startPauseBtn=Ht(v,"Start<br/>Pause",!1),this._soundBtn=Ht(v,"Sound",!0),this._resetBtn=Ht(v,"Reset",!1),this._exitBtn=Ht(v,"Exit",!0),this._enableColorBtn=Ht(v,"Enable<br/>Colors",!1),this._upBtn=Ft(_,"UP"),this._leftBtn=Ft(m,"LEFT"),this._downBtn=Ft(_,"DOWN"),this._rightBtn=Ft(m,"RIGHT"),this._actionBtn=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.addClass("lg-btn-container");var n=e.createButton("Action");return n.parent(i),n.addClass("lg-btn"),n}(y),function(t,e,i,n){var r=document.querySelector(":root");r.style.setProperty("--dispersion",p.viewLayout.shadowDispersion),r.style.setProperty("--width","".concat(t,"px")),r.style.setProperty("--height","".concat(e,"px")),r.style.setProperty("--canvas-width","".concat(i,"px")),r.style.setProperty("--canvas-height","".concat(n,"px")),r.style.setProperty("--border-radius","".concat(t*p.viewLayout.dimensions.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*p.viewLayout.dimensions.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*p.viewLayout.dimensions.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*p.viewLayout.dimensions.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*p.viewLayout.dimensions.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*p.viewLayout.dimensions.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*p.viewLayout.dimensions.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",p.viewLayout.dimensions.button.animationDuration)}(u,a,f,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Wt,this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new jt(t),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=p.viewLayout.splashHideDelayMs);var e=document.querySelector(p.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Kt=Yt;var Xt,Jt=n(991),qt=n.n(Jt);function Qt(t){Xt=t}function $t(t){return window.BrickEngineGame=t,new(qt())(function(e){B.init(e);var i=new Kt(document.body);Qt(new t(i)),"unknown"===Xt.gameId&&(Xt.gameId="game"),e.setup=function(){Xt.setup(),Xt.view.setupDebugger(Xt.modules),Xt.view.setupSessionModal()},e.draw=function(){Xt.draw(),Xt.view.updateDebugger()}})}return d})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var r=i[t];if(void 0!==r)return r.exports;var o=i[t]={exports:{}};return e[t](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r,o,s,a,u,c,l,h,d={};n.r(d),n.d(d,{Color:()=>r,ControlEventType:()=>l,ControlKey:()=>c,EventEmitter:()=>m,FontAlign:()=>o,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>pt,GameView:()=>Kt,RendererContext:()=>B,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>$t,configs:()=>p,setActiveGame:()=>Qt}),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)",t.SHADOW="rgb(93, 105, 92)"}(r||(r={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(o||(o={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const p={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},p.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},p.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var v;!function(t){t.TITLE="title",t.PLAYING="playing",t.GAMEOVER="gameover",t.PAUSED="paused"}(v||(v={}));const m=function(){function t(){}return t.subscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]||(this._events[n]=[]),this._events[n].push(e)},t.unsubscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]&&(this._events[n]=this._events[n].filter(function(t){return t!==e}))},t.notify=function(t,e){this._events[t]&&this._events[t].forEach(function(t){return t(e)})},t.notifyContextual=function(t,e,i){this.notify(t,e),i.isPlaying()?this.notify(this._formatName(t,v.PLAYING),e):i.isPaused()?this.notify(this._formatName(t,v.PAUSED),e):i.isOn()&&!i.isStarted()?this.notify(this._formatName(t,v.TITLE),e):i.isGameOver()&&this.notify(this._formatName(t,v.GAMEOVER),e)},t._formatName=function(t,e){return e?"".concat(t,":").concat(e):t},t.clear=function(){this._events={}},t._events={},t}();var _=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._activeListeners.forEach(function(t){var e=t.event,i=t.callback;m.unsubscribe(e,i)}),this._activeListeners=[]},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribe(t,e,i)},t.prototype.unsubscribe=function(t,e,i){this._unsubscribe(t,e,i)},t.prototype.subscribeForTitleScreen=function(t,e,i){this._subscribe(t,e,i,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e,i){this._unsubscribe(t,e,i,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e,i){this._subscribe(t,e,i,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e,i){this._unsubscribe(t,e,i,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e,i){this._subscribe(t,e,i,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e,i){this._subscribe(t,e,i,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PAUSED)},t.prototype._subscribe=function(t,e,i,n){var r="".concat(t,":").concat(e);m.subscribe(r,i,n);var o=n?"".concat(r,":").concat(n):r;this._activeListeners.push({event:o,callback:i})},t.prototype._unsubscribe=function(t,e,i,n){var r="".concat(t,":").concat(e);m.unsubscribe(r,i,n);var o=n?"".concat(r,":").concat(n):r;this._activeListeners=this._activeListeners.filter(function(t){return!(t.event===o&&t.callback===i)})},t.prototype.notify=function(t,e){if(!this._modules)throw new Error("Modules not initialized");var i={key:t,type:e,modules:this._modules},n=this._modules.state,r=this._modules.session,o=!1;r.isModalOpen()||n.isPlaying()&&!r.isSessionResolved()?o=!1:n.isOff()?o=t===c.POWER:!n.isStarted()||n.isPlaying()||n.isGameOver()?o=!0:n.isPaused()&&(o=t.endsWith(";system")),o&&m.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const b=_,E=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:r.DEFAULT,coordinate:t}},t}();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)},w=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return S(S({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),r=n.some(function(e){if(!i.grid.isCoordinateValid(e.coordinate))return!0;var n,r=i.grid.getCell(e.coordinate);return r&&i.grid.isCellActive(r)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}))});return r?t: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)};if(!this.grid.isCoordinateValid(i))return t;var n=this.grid.getCell(i);return n&&this.grid.isCellActive(n)?t:S(S({},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);i!==e;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);i!==e;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);i!==e;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);i!==e;)e=i,i=this.movePieceRight(e);return e},t}();const P=w;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)},C=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var r=t.map(function(t){var n=t.coordinate.x-e.x,r=t.coordinate.y-e.y,o=i?-r:r,s=i?n:-n;return R(R({},t),{coordinate:{x:e.x+o,y:e.y+s}})}),o=r.some(function(e){if(!n.grid.isCoordinateValid(e.coordinate))return!0;var i,r=n.grid.getCell(e.coordinate);return r&&n.grid.isCellActive(r)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}))});return o?t: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 R(R({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const x=C;var O=function(){return O=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},O.apply(this,arguments)},T=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++){var r=this.grid.getCell({x:n,y:e});if(r&&!this.grid.isCellActive(r)){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++){var r=this.grid.getCell({x:e,y:n});if(r&&!this.grid.isCellActive(r)){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};if(i.grid.isCoordinateValid(r)){var o=i.grid.getCell(r);o&&n.push(o)}}),n},t.prototype.findConnectedCells=function(t){var e=this,i=this.grid.getCell(t);if(!i||!this.grid.isCellActive(i))return[];var n=i.value,r=[],o=new Set,s=[t],a=function(t){return"".concat(t.x,",").concat(t.y)};for(o.add(a(t));s.length>0;){var u=s.shift(),c=this.grid.getCell(u);c.value===n&&(r.push(c),[{x:u.x-1,y:u.y},{x:u.x+1,y:u.y},{x:u.x,y:u.y-1},{x:u.x,y:u.y+1}].forEach(function(t){var i=a(t),n=e.grid.getCell(t);e.grid.isCoordinateValid(t)&&!o.has(i)&&n&&e.grid.isCellActive(n)&&(o.add(i),s.push(t))}))}return r},t.prototype.swapCells=function(t,e){var i=O({},this.grid.getCell(t)),n=O({},this.grid.getCell(e));this.grid.stampCell(O(O({},n),{coordinate:t})),this.grid.stampCell(O(O({},i),{coordinate:e}))},t}();const A=T;var I=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]=E.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]=E.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 L=I;var M=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){if(!e.grid.isCoordinateValid(t))return!0;var i=e.grid.getCell(t);return i&&e.grid.isCellActive(i)})},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=M;var G=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new P(this),this._transformEngine=new x(this),this._analysisEngine=new A(this),this._lineEngine=new L(this),this._regionEngine=new D(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return p.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return p.screenLayout.grid.rows},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topRow",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomRow",{get:function(){return this.height-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftColumn",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightColumn",{get:function(){return this.width-1},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]=E.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.isCoordinateValid=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isCoordinateValid(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){return null!==t&&t.value>0},t.prototype.isCellInactive=function(t){return null!==t&&0===t.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 JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},t}();const k=G,B=function(){function t(){}return t.init=function(t){this._p?console.warn("[BrickEngine] RendererContext is already initialized. Ignoring subsequent initialization."):this._p=t},Object.defineProperty(t,"p",{get:function(){if(!this._p)throw new Error("RendererContext not initialized yet. Ensure the Game object has been created.");return this._p},enumerable:!1,configurable:!0}),t.reset=function(){this._p=void 0},t}(),N=function(){function t(){}return t.getRelativeWidth=function(t){return t*B.p.width},t.getRelativeHeight=function(t){return t*B.p.height},t}();var z=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=p.screenLayout.cell,i=e.margin,n=e.padding,r=e.strokeWeight,o=this._rendererMetrics.cell.size;this._cellPreCalculatedGeometry={innerOffset:i*o,innerSize:o-i*o*2,paddingOffset:n*o,paddingSize:o-n*o*2,strokeWeight:r*o},this._renderStaticElements()},t.prototype.render=function(t,e){var i=B.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=B.p,e=p.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(p.colors.background),this._staticGraphics.strokeWeight(N.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(p.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,o=t.value,s=B.p,a=i.x,u=i.y,c=this._cellPreCalculatedGeometry,l=c.innerOffset,h=c.innerSize,d=c.paddingOffset,p=c.paddingSize,f=c.strokeWeight;n=0===o||!e.isPlaying()&&!e.isPaused()?r.INACTIVE:e.isColorEnabled()?n:r.DEFAULT,s.push(),s.translate(this._rendererMetrics.display.origin.x+a*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+u*this._rendererMetrics.cell.size),s.strokeWeight(f),s.stroke(n),s.noFill(),s.rect(l,l,h,h),s.fill(n),s.rect(d,d,p,p),s.pop()},t.prototype.renderGrid=function(t,e){var i=this;t.forEach(function(t){t.forEach(function(t){i.renderCell(t,e)})})},t}();const F=z;var H=function(){function t(){}return t.getRelativeCoordinate=function(t){return{x:N.getRelativeWidth(t.x),y:N.getRelativeHeight(t.y)}},t.getDisplayPosX=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=B.p,n=p.screenLayout.display.margin,r=N.getRelativeWidth(n),o=e+2*r;return(i.width-o-r)*t+o},t.getHudPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t}();const U=H;var j=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:U.getHudPosX(.078,t.display.width),y:U.getHudPosY(.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-N.getRelativeWidth(.005),y:this._gridOrigin.y-N.getRelativeHeight(.005),w:4*this._cellSize+N.getRelativeWidth(.01),h:4*this._cellSize+N.getRelativeHeight(.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=B.p,i=t.text,n=t.state,r=t.score;e.push(),i.setTextSize(s.SMALL),i.setInactiveText(),i.setTextAlign(o.LEFT,a.BOTTOM),i.textOnHud("88888888",{x:.05,y:.13}),i.textOnHud("88888888",{x:.05,y:.3}),i.textOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.textOnHud("Score",{x:.05,y:.06}),i.textOnHud(r.score.toString(),{x:.05,y:.13}),i.textOnHud("Hi-Score",{x:.05,y:.23}),i.textOnHud(r.highScore.toString(),{x:.05,y:.3}),i.textOnHud("Level",{x:.05,y:.72});var u="".concat(r.level<10?"0"+r.level:r.level," - ").concat(r.maxLevel);i.textOnHud(u,{x:.05,y:.8}),i.setTextAlign(o.CENTER,a.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.textOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.textOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=B.p,n=t.hudGrid,o=t.state;i.push(),n.forEach(function(t){var i=t.coordinate,n=i.x,s=i.y;o.isOff()&&!o.isPlaying()&&(t.value=0);var a=0!==t.value?r.DEFAULT:r.INACTIVE;o.isColorEnabled()&&0!==t.value&&(a=t.color),e.drawCellElement({w:e._cellSize,h:e._cellSize,posX:e._gridOrigin.x+e._cellSize*n,posY:e._gridOrigin.y+e._cellSize*s,color:a})}),i.noFill(),i.stroke(o.isOn()?r.DEFAULT:r.INACTIVE),i.rect(this._hudBorderRect.x,this._hudBorderRect.y,this._hudBorderRect.w,this._hudBorderRect.h),i.pop()},t.prototype.drawCellElement=function(t){var e=t.w,i=t.posX,n=t.posY,r=t.color,o=B.p,s=p.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,f=s.strokeWeight*e;o.push(),o.translate(i,n),o.strokeWeight(f),o.stroke(r),o.noFill(),o.rect(c,c,l,l),o.fill(r),o.rect(h,h,d,d),o.pop()},t}();const V=j;var W=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new F,this._hudRenderer=new V,this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=p.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=p.screenLayout.grid.columns,o=N.getRelativeWidth(e),s=N.getRelativeHeight(i),a=U.getRelativeCoordinate({x:n,y:n}),u=o/r,c={x:U.getHudPosX(0,o),y:U.getHudPosY(0,s)},l=U.getHudPosX(1,o)-c.x,h=U.getHudPosY(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 Y=W;var K,X=((K={})[h.ON]={defaultValue:!1},K[h.START]={defaultValue:!1},K[h.PLAYING]={defaultValue:!1},K[h.GAME_OVER]={defaultValue:!1},K[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},K[h.MUTED]={defaultValue:!1,storageKey:"muted"},K);const J=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=X[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=X[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this.notify(t)}},t.prototype.notify=function(t){var e=this._state.get(t);m.notifyContextual(t,e,this)},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){this._subscribe(t,e)},t.prototype.unsubscribe=function(t,e){this._unsubscribe(t,e)},t.prototype.subscribeForTitleScreen=function(t,e){this._subscribe(t,e,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e){this._unsubscribe(t,e,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e){this._subscribe(t,e,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e){this._unsubscribe(t,e,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e){this._subscribe(t,e,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e){this._unsubscribe(t,e,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e){this._subscribe(t,e,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e){this._unsubscribe(t,e,v.PAUSED)},t.prototype._subscribe=function(t,e,i){m.subscribe(t,e,i)},t.prototype._unsubscribe=function(t,e,i){m.unsubscribe(t,e,i)},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}();var q=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=B.p,e=p.screenLayout.fontSize,i=e.extraSmall,n=e.small,r=e.medium,o=e.large,a=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=N.getRelativeWidth(i),this.fontSizes[s.SMALL]=N.getRelativeWidth(n),this.fontSizes[s.MEDIUM]=N.getRelativeWidth(r),this.fontSizes[s.LARGE]=N.getRelativeWidth(o),this.fontSizes[s.EXTRA_LARGE]=N.getRelativeWidth(a)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=B.p,i=p.colors,n=i.active,r=i.inactive;e.fill(t?n:r)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setTextSize=function(t){B.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){B.p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=B.p,n=U.getHudPosX(e.x,this._rendererMetrics.display.width),r=U.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.textOnDisplay=function(t,e){var i=B.p,n=U.getDisplayPosX(e.x,this._rendererMetrics.display.width),r=U.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const Q=q,$=function(){function t(){this._tickAccumulator=0,this._initialTickInterval=p.game.tickInterval,this._minTickInterval=p.game.minTickInterval,this._tickInterval=p.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._tickAccumulator+=t,this._totalElapsedTime+=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._tickAccumulator>=this._tickInterval&&(this._tickAccumulator-=this._tickInterval,this._tickCounter++,this._totalTicks++,!0)},t.prototype.reset=function(){this._tickAccumulator=0,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=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),tick_accumulator:this._tickAccumulator.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},Object.defineProperty(t.prototype,"totalTicks",{get:function(){return this._totalTicks},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"elapsedTime",{get:function(){return this._totalElapsedTime},enumerable:!1,configurable:!0}),t.prototype.isTickEvery=function(t){return this._totalTicks>0&&this._totalTicks%t===0},t.prototype.captureInitialState=function(){this._initialTickInterval=this._tickInterval},t}();var Z=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())})},tt=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])}}},et=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=p.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return Z(this,void 0,void 0,function(){var e,i,n;return tt(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 Z(this,void 0,void 0,function(){var e;return tt(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 Z(this,void 0,void 0,function(){var t,e,i,n;return tt(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 Z(this,void 0,void 0,function(){var t,e=this;return tt(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return Z(e,void 0,void 0,function(){var e,i,n;return tt(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 it=et,nt=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this._gameId="unknown",this.serialId="score"}return t.prototype.setupGameHighScore=function(t){this._gameId=t,this._highScore=Number(localStorage.getItem("".concat(this._gameId,"::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("".concat(this._gameId,"::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 rt,ot=(rt=function(t,e){return rt=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])},rt(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}rt(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const st=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return ot(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}(k),at=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 J)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ut=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{if(n&&"object"==typeof n){var o=Object.getPrototypeOf(n)===Object.prototype||null===Object.getPrototypeOf(n),s=Array.isArray(n);o||s?r=structuredClone(n):(console.warn("[BrickEngine] Property '".concat(i,"' is a complex object without a clone() or copy() method. A reference will be saved. State reset might not work for its internal properties.")),r=n)}else r=n;console.log("capturing property",i,r)}catch(t){console.error("Failed to clone property '".concat(i,"' (value: ").concat(String(n),"). Saving reference instead. Reset may not work as expected for this property. Error:"),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 ct=ut,lt=function(){function t(){this._isSessionResolved=!1,this._isModalOpen=!1,this._isEnabled=!0,this._resetFn=function(){},this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isSessionResolved&&this._isEnabled&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype.setResetFunction=function(t){this._resetFn=t},t.prototype.setSessionEnabled=function(t){this._isEnabled=t},t.prototype.isModalOpen=function(){return this._isModalOpen},t.prototype.isSessionResolved=function(){return this._isSessionResolved},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.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0})}}),t.subscribe(h.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(h.START,function(t){t||(e._isSessionResolved=!1)})},t.prototype.getDebugData=function(){return{game_id:this.gameId,is_session_resolved:this._isSessionResolved,is_modal_open:this._isModalOpen,is_enabled:this._isEnabled,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}(),ht=function(){function t(){}return t.setupControlEvents=function(t,e){var i=t.control,n=t.state,r=t.session,o=t.sound;i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.EXIT,l.PRESSED,function(){return r.clearSession()}),i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),o.stopAll()):n.turnOn()}),i.subscribeForGameOverScreen(c.POWER,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForTitleScreen(c.START_PAUSE,l.PRESSED,function(){return n.startGame()}),i.subscribeForPlayingScreen(c.START_PAUSE,l.PRESSED,function(){return n.pause()}),i.subscribeForGameOverScreen(c.START_PAUSE,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForPausedScreen(c.START_PAUSE,l.PRESSED,function(){return n.resume()}),i.subscribeForPlayingScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()}),i.subscribeForPausedScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()})},t.setupStateEvents=function(t){var e=t.state,i=t.session;e.subscribe(h.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),e.subscribeForGameOverScreen(h.GAME_OVER,function(){i.clearSession()})},t}();var dt=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new ct,this._gameId="unknown",this._view=t,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"p",{get:function(){return B.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new Y,grid:new k,hudGrid:new st,text:new Q,state:new J,control:new b,time:new $,sound:new it,score:new nt,session:new lt},Object.values(this._modules).forEach(function(t){at.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){at.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){at.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,r=e.renderer,o=e.session,s=e.score;o.gameId=this.gameId,o.setShowModalFunction(this._view.showSessionModal.bind(this._view)),o.setResetFunction(this.reset.bind(this)),n.setModules(this._modules),i.setRendererMetrics(r.rendererMetrics),s.setupGameHighScore(this.gameId),this.setupGame(),ht.setupControlEvents(this._modules,this.reset.bind(this)),ht.setupStateEvents(this._modules),this._view.bindControls(n),this._modules.time.captureInitialState(),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=B.p;if(this._modules){var e=this._modules,i=e.renderer,n=e.grid,r=e.time,o=e.state,s=e.session;s.isModalOpen()||o.isPlaying()&&!s.isSessionResolved()||(i.render(n.getGrid(),this._modules),o.isOn()&&(o.isStarted()?o.isPlaying()?(r.update(t.deltaTime),r.shouldTick()&&(this.update(t.deltaTime),this._modules.session.saveSession()),this.render()):o.isPaused()&&this.render():this.drawTitleScreen(),o.isGameOver()&&this.drawGameOverScreen()))}},t.prototype.destroy=function(){B.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},t.prototype.reset=function(){this._modules.grid.resetGrid(),this._modules.score.resetScore(),this._modules.score.resetLevel(),this._modules.time.reset(),this._modules.session.clearSession(),this._initialStateSnapshot.restoreInitialState(this)},t}();const pt=dt;var ft={grad:.9,turn:360,rad:360/(2*Math.PI)},gt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},yt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},vt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},mt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:vt(t.r,0,255),g:vt(t.g,0,255),b:vt(t.b,0,255),a:vt(t.a)}},bt=function(t){return{r:yt(t.r),g:yt(t.g),b:yt(t.b),a:yt(t.a,3)}},Et=/^#([0-9a-f]{3,8})$/i,St=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}},Pt=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}},Rt=function(t){return{h:mt(t.h),s:vt(t.s,0,100),l:vt(t.l,0,100),a:vt(t.a)}},Ct=function(t){return{h:yt(t.h),s:yt(t.s),l:yt(t.l),a:yt(t.a,3)}},xt=function(t){return Pt((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},Ot=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},Tt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,At=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt={string:[[function(t){var e=Et.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?yt(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?yt(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=It.exec(t)||Lt.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=Tt.exec(t)||At.exec(t);if(!e)return null;var i,n,r=Rt({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(ft[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return xt(r)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,r=t.a,o=void 0===r?1:r;return gt(e)&&gt(i)&&gt(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(!gt(e)||!gt(i)||!gt(n))return null;var s=Rt({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return xt(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!gt(e)||!gt(i)||!gt(n))return null;var s=function(t){return{h:mt(t.h),s:vt(t.s,0,100),v:vt(t.v,0,100),a:vt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(o)});return Pt(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]},Gt=function(t,e){var i=Ot(t);return{h:i.h,s:vt(i.s+100*e,0,100),l:i.l,a:i.a}},kt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Bt=function(t,e){var i=Ot(t);return{h:i.h,s:i.s,l:vt(i.l+100*e,0,100),a:i.a}},Nt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Dt(t.trim(),Mt.string):"object"==typeof t&&null!==t?Dt(t,Mt.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 yt(kt(this.rgba),2)},t.prototype.isDark=function(){return kt(this.rgba)<.5},t.prototype.isLight=function(){return kt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?St(yt(255*r)):"","#"+St(e)+St(i)+St(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return bt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+n+", "+r+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,r},t.prototype.toHsl=function(){return Ct(Ot(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ct(Ot(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:yt(t.h),s:yt(t.s),v:yt(t.v),a:yt(t.a,3)};var t},t.prototype.invert=function(){return zt({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),zt(Gt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,-t))},t.prototype.grayscale=function(){return zt(Gt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),zt(Bt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),zt(Bt(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?zt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):yt(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Ot(this.rgba);return"number"==typeof t?zt({h:t,s:e.s,l:e.l,a:e.a}):yt(e.h)},t.prototype.isEqual=function(t){return this.toHex()===zt(t).toHex()},t}(),zt=function(t){return t instanceof Nt?t:new Nt(t)};function Ft(t,e){var i=B.p,n=i.createDiv();n.parent(t),n.addClass("btn-container");var r=i.createButton(e);return r.parent(n),r.addClass("btn"),r}function Ht(t,e,i){var n=B.p,r=n.createDiv();r.parent(t),r.addClass("sm-btn-container"),r.addClass(i?"sm-btn-container-top":"sm-btn-container-bottom");var o=n.createButton("");o.parent(r),o.addClass("sm-btn");var s=n.createP(e);return s.parent(r),s.addClass("sm-btn-p"),o}var Ut=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(p.game.debugger.enabled){var e=B.p,i=e.select("#debugger"),n=!!i&&i.elt.hasAttribute("open"),r=new Set;i&&(e.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&r.add(t.id())}),i.remove()),this._moduleElements=[];var o=e.createElement("details");o.id("debugger"),n&&o.attribute("open",""),o.parent(e.select("body"));var s=e.createElement("summary");s.id("debugger-summary"),s.html("Debug"),s.parent(o),Object.entries(this._gameModules).forEach(function(i){var n=i[0],s=i[1];if("getDebugData"in s){var a={module:s,properties:[]},u=e.createElement("details");u.class("debugger-module"),u.id("debugger-".concat(n)),r.has("debugger-".concat(n))&&u.attribute("open",""),u.parent(o);var c=e.createElement("summary");c.id("debugger-".concat(n,"-summary")),c.html(n),c.class("debugger-module-summary"),c.parent(u);var l=s.getDebugData();Object.entries(l).forEach(function(t){var i=t[0],n=t[1],r=e.createElement("div");r.class("debugger-container"),r.id("debugger-container-".concat(i,"-").concat(n)),r.parent(u),r.mouseClicked(function(){r.toggleClass("highlight")});var o=e.createElement("p");o.id("debugger-".concat(i,"-").concat(n)),o.html("".concat(i,":")),o.parent(r);var s=e.createElement("span");s.id("debugger-".concat(i,"-").concat(n,"-value")),s.html("".concat(n)),s.parent(r),a.properties.push({key:i,element:s})}),t._moduleElements.push(a)}})}},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 jt=Ut;var Vt=function(){function t(){}return t.prototype.setup=function(){var t=B.p;this._container=t.createDiv(),this._container.parent(t.select("body")),this._container.id("modal-background"),this._container.class("hidden");var e=t.createDiv();e.parent(this._container),e.id("session-modal");var i=t.createDiv();i.parent(e),i.id("session-modal-frame");var n=t.createP();n.parent(i),n.html("Brick Engine Session");var r=t.createDiv();r.parent(i),r.id("session-modal-screen");var o=t.createP();o.parent(r),o.html("<span>Looks like you have an active session.</span><br><br>Do you want to continue?");var s=t.createDiv();s.parent(e),s.id("session-modal-buttons"),this._cancelButton=t.createButton("Cancel"),this._cancelButton.parent(s),this._cancelButton.class("session-modal-button"),this._confirmButton=t.createButton("Confirm"),this._confirmButton.parent(s),this._confirmButton.class("session-modal-button")},t.prototype.show=function(t,e){var i=this;this._confirmButton.mousePressed(function(){t(),i._hide()}),this._cancelButton.mousePressed(function(){e(),i._hide()}),this._container.removeClass("hidden")},t.prototype._hide=function(){this._confirmButton.mousePressed(null),this._cancelButton.mousePressed(null),this._container.addClass("hidden")},t}();const Wt=Vt;var Yt=function(){function t(t){this._parent=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,r;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(p.inputQueryParams.mainColor)?i.get(p.inputQueryParams.mainColor):p.colors.bodyMain,r=i.has(p.inputQueryParams.buttonColor)?i.get(p.inputQueryParams.buttonColor):p.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",zt(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",zt(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",zt(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",zt(r).darken(.15).toHex());var o=function(t){var e,i=B.p.createDiv();if(i.parent(p.selectors.parent),i.id(p.selectors.viewElementIds.container),t.clientWidth<=p.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*p.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*p.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=o.container,a=o.height,u=o.width,c=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.frame);var n=e.createDiv();return n.parent(i),e.createP("Brick Engine").parent(n),i}(s),l=function(t,e){var i=B.p,n=e*p.viewLayout.canvas.widthRatio,r=n*p.viewLayout.canvas.aspectRatio,o=i.createCanvas(n,r);return o.parent(t),o.id(p.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:r,canvas:o}}(c,u),h=l.canvas,d=l.canvasHeight,f=l.canvasWidth,g=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.buttonContainer);var n=e.createDiv();n.parent(i),n.id(p.selectors.viewElementIds.smallButtonContainer);var r=e.createDiv();r.parent(i),r.id(p.selectors.viewElementIds.innerButtonContainer);var o=e.createDiv();o.parent(r),o.id(p.selectors.viewElementIds.mediumButtonContainer);var s=e.createDiv();s.parent(o),s.id(p.selectors.viewElementIds.directionVerticalContainer);var a=e.createDiv();a.parent(o),a.id(p.selectors.viewElementIds.directionHorizontalContainer);var u=e.createDiv();return u.parent(r),u.id(p.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(s),y=g.largeButtonContainer,v=g.smallButtonContainer,m=g.directionHorizontalContainer,_=g.directionVerticalContainer;return this._onOffBtn=Ht(v,"On<br/>Off",!0),this._startPauseBtn=Ht(v,"Start<br/>Pause",!1),this._soundBtn=Ht(v,"Sound",!0),this._resetBtn=Ht(v,"Reset",!1),this._exitBtn=Ht(v,"Exit",!0),this._enableColorBtn=Ht(v,"Enable<br/>Colors",!1),this._upBtn=Ft(_,"UP"),this._leftBtn=Ft(m,"LEFT"),this._downBtn=Ft(_,"DOWN"),this._rightBtn=Ft(m,"RIGHT"),this._actionBtn=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.addClass("lg-btn-container");var n=e.createButton("Action");return n.parent(i),n.addClass("lg-btn"),n}(y),function(t,e,i,n){var r=document.querySelector(":root");r.style.setProperty("--dispersion",p.viewLayout.shadowDispersion),r.style.setProperty("--width","".concat(t,"px")),r.style.setProperty("--height","".concat(e,"px")),r.style.setProperty("--canvas-width","".concat(i,"px")),r.style.setProperty("--canvas-height","".concat(n,"px")),r.style.setProperty("--border-radius","".concat(t*p.viewLayout.dimensions.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*p.viewLayout.dimensions.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*p.viewLayout.dimensions.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*p.viewLayout.dimensions.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*p.viewLayout.dimensions.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*p.viewLayout.dimensions.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*p.viewLayout.dimensions.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",p.viewLayout.dimensions.button.animationDuration)}(u,a,f,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Wt,this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new jt(t),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=p.viewLayout.splashHideDelayMs);var e=document.querySelector(p.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Kt=Yt;var Xt,Jt=n(991),qt=n.n(Jt);function Qt(t){Xt=t}function $t(t){return window.BrickEngineGame=t,new(qt())(function(e){B.init(e);var i=new Kt(document.body);Qt(new t(i)),"unknown"===Xt.gameId&&(Xt.gameId="game"),e.setup=function(){Xt.setup(),Xt.view.setupDebugger(Xt.modules),Xt.view.setupSessionModal()},e.draw=function(){Xt.draw(),Xt.view.updateDebugger()}})}return d})());
@@ -2,7 +2,7 @@ import p5 from 'p5';
2
2
  /**
3
3
  * Creates the decorative frame for the game.
4
4
  *
5
- * Adds a visual frame around the game area and includes the branding text "Brick Game".
5
+ * Adds a visual frame around the game area and includes the branding text "Brick Engine".
6
6
  *
7
7
  * @param p - The p5 instance.
8
8
  * @param container - The parent container element.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-engine-js",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A lightweight brick engine built with p5.js and TypeScript",
5
5
  "type": "commonjs",
6
6
  "main": "dist/brick-engine.js",