brick-engine-js 1.0.38 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.adoc CHANGED
@@ -80,7 +80,7 @@ The engine is organized into the following core modules:
80
80
  | Manages audio playback using the Web Audio API, supporting simultaneous sounds and volume control.
81
81
 
82
82
  | xref:docs/reference/modules/GameScore.adoc[GameScore]
83
- | Tracks session score, level logic, and syncs high scores with `GameState`.
83
+ | Tracks session score and level logic, managing persistent high scores independently.
84
84
  |===
85
85
 
86
86
  == Core Utilities
@@ -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,p={};n.r(p),n.d(p,{Color:()=>r,ControlEventType:()=>h,ControlKey:()=>l,EventEmitter:()=>m,FontAlign:()=>o,FontSize:()=>a,FontVerticalAlign:()=>u,Game:()=>ft,GameView:()=>$t,RendererContext:()=>H,Sound:()=>c,StateProperty:()=>d,TextTheme:()=>s,bootstrap:()=>ne,configs:()=>f,setActiveGame:()=>ie}),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.ACTIVE="active",t.INACTIVE="inactive",t.SHADOW="shadow"}(s||(s={})),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"}(a||(a={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(u||(u={})),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"}(c||(c={})),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",t.TRACKPAD="trackpad;system",t.SHORTCUTS="shortcuts;system"}(l||(l={})),function(t){t.PRESSED="pressed",t.HELD="held"}(h||(h={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted",t.TRACKPAD="trackpadEnabled"}(d||(d={}));const f={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},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"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{enabled:!0},sound:{volume:.025}}},g=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,h.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,h.HELD)},f.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},f.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 y={ArrowUp:l.UP,ArrowDown:l.DOWN,ArrowLeft:l.LEFT,ArrowRight:l.RIGHT,KeyW:l.UP,KeyS:l.DOWN,KeyA:l.LEFT,KeyD:l.RIGHT,KeyJ:l.ACTION,Digit1:l.POWER,Digit2:l.START_PAUSE,Digit3:l.SOUND,Digit4:l.RESET,Digit5:l.EXIT,Digit6:l.COLOR,Digit7:l.TRACKPAD,KeyH:l.SHORTCUTS};const _=function(){function t(t){this._inputHandler=new g(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=y[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=y[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 b=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new _(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=[l.POWER,l.TRACKPAD,l.SHORTCUTS].includes(t):!n.isStarted()||n.isPlaying()||n.isGameOver()?o=!0:n.isPaused()&&(o=t.endsWith(";system")||t===l.SHORTCUTS),o&&m.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const E=b,S=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:r.DEFAULT,coordinate:t}},t}();var w=function(){return w=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},w.apply(this,arguments)},P=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return w(w({},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:w(w({},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 R=P;var C=function(){return C=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},C.apply(this,arguments)},x=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var r=t.map(function(t){var n=t.coordinate.x-e.x,r=t.coordinate.y-e.y,o=i?-r:r,s=i?n:-n;return C(C({},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 C(C({},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 O=x;var T=function(){return T=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},T.apply(this,arguments)},A=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=T({},this.grid.getCell(t)),n=T({},this.grid.getCell(e));this.grid.stampCell(T(T({},n),{coordinate:t})),this.grid.stampCell(T(T({},i),{coordinate:e}))},t}();const D=A;var k=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]=S.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]=S.emptyCell({x:t,y:i})},t.prototype.shiftColumnsRight=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.height;n++){var r=e[n][i-1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(0)},t.prototype.shiftColumnsLeft=function(t){for(var e=this.grid.getGrid(),i=t;i<this.grid.width-1;i++)for(var n=0;n<this.grid.height;n++){var r=e[n][i+1];e[n][i].value=r.value,e[n][i].color=r.color}this.clearColumn(this.grid.width-1)},t.prototype.clearFullColumns=function(){for(var t=0,e=this.grid.width-1;e>=0;e--)this.isColumnFull(e)&&(this.clearColumn(e),this.shiftColumnsRight(e),t++,e++);return t},t}();const M=k;var L=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 I=L;var G=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new R(this),this._transformEngine=new O(this),this._analysisEngine=new D(this),this._lineEngine=new M(this),this._regionEngine=new I(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return f.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return f.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]=S.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 B=G,H=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*H.p.width},t.getRelativeHeight=function(t){return t*H.p.height},t}();var F=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=f.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=H.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=H.p,e=f.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(f.colors.background),this._staticGraphics.strokeWeight(N.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(f.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=H.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.SHADOW?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 z=F;var U=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=f.screenLayout.display.margin;return e*t+N.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=f.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=H.p,n=f.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=f.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t}();const j=U;var W=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:j.getHudPosX(.078,t.display.width),y:j.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=H.p,i=t.text,n=t.state,r=t.score;e.push(),i.setTextSize(a.SMALL),i.setInactiveText(),i.setTextAlign(o.LEFT,u.BOTTOM),i.writeOnHud("88888888",{x:.05,y:.13}),i.writeOnHud("88888888",{x:.05,y:.3}),i.writeOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.writeOnHud("Score",{x:.05,y:.06}),i.writeOnHud(r.score.toString(),{x:.05,y:.13}),i.writeOnHud("Hi-Score",{x:.05,y:.23}),i.writeOnHud(r.highScore.toString(),{x:.05,y:.3}),i.writeOnHud("Level",{x:.05,y:.72});var s="".concat(r.level<10?"0"+r.level:r.level," - ").concat(r.maxLevel);i.writeOnHud(s,{x:.05,y:.8}),i.setTextAlign(o.CENTER,u.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.writeOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.writeOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=H.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=H.p,s=f.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,p=s.strokeWeight*e;o.push(),o.translate(i,n),o.strokeWeight(p),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=W;var K=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new z,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=f.screenLayout.display,e=t.width,i=t.height,n=t.margin,r=f.screenLayout.grid.columns,o=N.getRelativeWidth(e),s=N.getRelativeHeight(i),a=j.getRelativeCoordinate({x:n,y:n}),u=o/r,c={x:j.getHudPosX(0,o),y:j.getHudPosY(0,s)},l=j.getHudPosX(1,o)-c.x,h=j.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=K;var X,J=((X={})[d.ON]={defaultValue:!1},X[d.START]={defaultValue:!1},X[d.PLAYING]={defaultValue:!1},X[d.GAME_OVER]={defaultValue:!1},X[d.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},X[d.MUTED]={defaultValue:!1,storageKey:"muted"},X[d.TRACKPAD]={defaultValue:!1,storageKey:"trackpadEnabled"},X);const q=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(d).forEach(function(e){var i=J[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(d).forEach(function(e){var i=J[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=J[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(d.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(d.START)},t.prototype.isPlaying=function(){return this._state.get(d.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(d.GAME_OVER)},t.prototype.turnOn=function(){this._set(d.ON,!0),this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(d.ON,!1),this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(d.START,!0),this._set(d.PLAYING,!0),this._set(d.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(d.GAME_OVER,!1),this._set(d.START,!0),this._set(d.PLAYING,!0)},t.prototype.exitGame=function(){this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(d.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(d.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(d.GAME_OVER,!1),this._set(d.START,!0),this._set(d.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(d.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(d.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(d.MUTED)},t.prototype.setMuted=function(t){this._set(d.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.isTrackpadEnabled=function(){return this._state.get(d.TRACKPAD)},t.prototype.setTrackpadEnabled=function(t){this._set(d.TRACKPAD,t)},t.prototype.toggleTrackpadEnabled=function(){this.setTrackpadEnabled(!this.isTrackpadEnabled())},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(),trackpad:this.isTrackpadEnabled()}},t}();var Q=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=H.p,e=f.screenLayout.fontSize,i=e.extraSmall,n=e.small,r=e.medium,o=e.large,s=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[a.EXTRA_SMALL]=N.getRelativeWidth(i),this.fontSizes[a.SMALL]=N.getRelativeWidth(n),this.fontSizes[a.MEDIUM]=N.getRelativeWidth(r),this.fontSizes[a.LARGE]=N.getRelativeWidth(o),this.fontSizes[a.EXTRA_LARGE]=N.getRelativeWidth(s)},t.prototype.setTime=function(t){this._time=t},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=H.p,i=f.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.setShadowText=function(){H.p.fill(r.SHADOW)},t.prototype.setTextTheme=function(t){switch(t){case s.ACTIVE:this.setActiveText();break;case s.INACTIVE:this.setInactiveText();break;case s.SHADOW:this.setShadowText()}},t.prototype.setTextSize=function(t){H.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){H.p.textAlign(t,e)},t.prototype.writeOnHud=function(t,e){var i=H.p,n=j.getHudPosX(e.x,this._rendererMetrics.display.width),r=j.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.writeOnDisplay=function(t,e){var i=H.p,n=j.getDisplayPosX(e.x,this._rendererMetrics.display.width),r=j.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,r)},t.prototype.writePulsingTextOnHud=function(t,e,i){void 0===i&&(i=1e3);var n=Math.floor(this._time.elapsedTime%i/(i/4));0===n?(this.setActiveText(),this.writeOnHud(t,e)):1!==n&&3!==n||(this.setShadowText(),this.writeOnHud(t,e))},t.prototype.writePulsingTextOnDisplay=function(t,e,i){void 0===i&&(i=1e3);var n=Math.floor(this._time.elapsedTime%i/(i/4));0===n?(this.setActiveText(),this.writeOnDisplay(t,e)):1!==n&&3!==n||(this.setShadowText(),this.writeOnDisplay(t,e))},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const $=Q,Z=function(){function t(){this._tickAccumulator=0,this._initialTickInterval=f.game.tickInterval,this._minTickInterval=f.game.minTickInterval,this._tickInterval=f.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(){if(this._tickAccumulator>=this._tickInterval){for(;this._tickAccumulator>=this._tickInterval;)this._tickAccumulator-=this._tickInterval;return this._tickCounter++,this._totalTicks++,!0}return!1},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 tt=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())})},et=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])}}},it=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=f.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 tt(this,void 0,void 0,function(){var e,i,n;return et(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 tt(this,void 0,void 0,function(){var e;return et(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 tt(this,void 0,void 0,function(){var t,e,i,n;return et(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 tt(this,void 0,void 0,function(){var t,e=this;return et(this,function(i){switch(i.label){case 0:return t=Object.values(c).map(function(t){return tt(e,void 0,void 0,function(){var e,i,n;return et(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(d.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 nt=it,rt=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 ot,st=(ot=function(t,e){return ot=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])},ot(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}ot(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const at=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return st(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}(B),ut=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 q)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ct=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 lt=ct,ht=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._state.isGameOver()&&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;this._state=t,t.subscribe(d.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,H.p.noLoop(),e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0,H.p.loop()},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0,H.p.loop()})}}),t.subscribe(d.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(d.START,function(t){t||(e._isSessionResolved=!1)}),t.subscribe(d.GAME_OVER,function(t){t&&e.clearSession()})},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}(),dt=function(){function t(){}return t.setupControlEvents=function(t,e,i){var n=t.control,r=t.state,o=t.session,s=t.sound;n.subscribe(l.SOUND,h.PRESSED,function(){return r.toggleMuted()}),n.subscribe(l.COLOR,h.PRESSED,function(){return r.toggleColorEnabled()}),n.subscribe(l.EXIT,h.PRESSED,function(){return o.clearSession()}),n.subscribe(l.TRACKPAD,h.PRESSED,function(){return r.toggleTrackpadEnabled()}),n.subscribe(l.SHORTCUTS,h.PRESSED,function(){return e.toggleShortcutsModal()}),n.subscribe(l.POWER,h.PRESSED,function(){r.isOn()?(r.turnOff(),s.stopAll()):r.turnOn()}),n.subscribeForGameOverScreen(l.POWER,h.PRESSED,function(){i(),r.resetGameOver()}),n.subscribeForTitleScreen(l.START_PAUSE,h.PRESSED,function(){return r.startGame()}),n.subscribeForPlayingScreen(l.START_PAUSE,h.PRESSED,function(){return r.pause()}),n.subscribeForGameOverScreen(l.START_PAUSE,h.PRESSED,function(){i(),r.resetGameOver()}),n.subscribeForPausedScreen(l.START_PAUSE,h.PRESSED,function(){return r.resume()}),n.subscribeForPlayingScreen(l.RESET,h.PRESSED,function(){i(),r.resetGame()}),n.subscribeForPausedScreen(l.RESET,h.PRESSED,function(){i(),r.resetGame()})},t.setupStateEvents=function(t,e){var i=t.state,n=t.session;i.subscribe(d.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),i.subscribeForGameOverScreen(d.GAME_OVER,function(){n.clearSession()}),i.subscribe(d.TRACKPAD,function(t){e.applyTrackpadState(t)}),e.applyTrackpadState(i.isTrackpadEnabled())},t}();var pt=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new lt,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 H.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;m.clear(),this._view.build(),this._modules={renderer:new Y,grid:new B,hudGrid:new at,text:new $,state:new q,control:new E,time:new Z,sound:new nt,score:new rt,session:new ht},Object.values(this._modules).forEach(function(t){ut.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){ut.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){ut.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,a=e.time;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),i.setTime(a),s.setupGameHighScore(this.gameId),this.setupGame(),dt.setupControlEvents(this._modules,this._view,this.reset.bind(this)),dt.setupStateEvents(this._modules,this._view),this._view.bindControls(n),this._modules.time.captureInitialState(),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=H.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()||(r.update(t.deltaTime),i.render(n.getGrid(),this._modules),o.isOn()&&(o.isStarted()?o.isPlaying()?(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(){H.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll()),m.clear()},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 ft=pt;var gt={grad:.9,turn:360,rad:360/(2*Math.PI)},yt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},_t=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},bt=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)}},Et=function(t){return{r:_t(t.r),g:_t(t.g),b:_t(t.b),a:_t(t.a,3)}},St=/^#([0-9a-f]{3,8})$/i,wt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Pt=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}},Rt=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}},Ct=function(t){return{h:mt(t.h),s:vt(t.s,0,100),l:vt(t.l,0,100),a:vt(t.a)}},xt=function(t){return{h:_t(t.h),s:_t(t.s),l:_t(t.l),a:_t(t.a,3)}},Ot=function(t){return Rt((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},Tt=function(t){return{h:(e=Pt(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},At=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Dt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,kt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt={string:[[function(t){var e=St.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?_t(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?_t(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=kt.exec(t)||Mt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:bt({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=At.exec(t)||Dt.exec(t);if(!e)return null;var i,n,r=Ct({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(gt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Ot(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 yt(e)&&yt(i)&&yt(n)?bt({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(!yt(e)||!yt(i)||!yt(n))return null;var s=Ct({h:Number(e),s:Number(i),l:Number(n),a:Number(o)});return Ot(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,r=t.a,o=void 0===r?1:r;if(!yt(e)||!yt(i)||!yt(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 Rt(s)},"hsv"]]},It=function(t,e){for(var i=0;i<e.length;i++){var n=e[i][0](t);if(n)return[n,e[i][1]]}return[null,void 0]},Gt=function(t,e){var i=Tt(t);return{h:i.h,s:vt(i.s+100*e,0,100),l:i.l,a:i.a}},Bt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Ht=function(t,e){var i=Tt(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?It(t.trim(),Lt.string):"object"==typeof t&&null!==t?It(t,Lt.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 _t(Bt(this.rgba),2)},t.prototype.isDark=function(){return Bt(this.rgba)<.5},t.prototype.isLight=function(){return Bt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=Et(this.rgba)).r,i=t.g,n=t.b,o=(r=t.a)<1?wt(_t(255*r)):"","#"+wt(e)+wt(i)+wt(n)+o;var t,e,i,n,r,o},t.prototype.toRgb=function(){return Et(this.rgba)},t.prototype.toRgbString=function(){return e=(t=Et(this.rgba)).r,i=t.g,n=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+n+", "+r+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,r},t.prototype.toHsl=function(){return xt(Tt(this.rgba))},t.prototype.toHslString=function(){return e=(t=xt(Tt(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=Pt(this.rgba),{h:_t(t.h),s:_t(t.s),v:_t(t.v),a:_t(t.a,3)};var t},t.prototype.invert=function(){return Ft({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),Ft(Gt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),Ft(Gt(this.rgba,-t))},t.prototype.grayscale=function(){return Ft(Gt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),Ft(Ht(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),Ft(Ht(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?Ft({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):_t(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Tt(this.rgba);return"number"==typeof t?Ft({h:t,s:e.s,l:e.l,a:e.a}):_t(e.h)},t.prototype.isEqual=function(t){return this.toHex()===Ft(t).toHex()},t}(),Ft=function(t){return t instanceof Nt?t:new Nt(t)};function zt(t,e){var i=H.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 Ut(t,e,i){var n=H.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 jt=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(f.game.debugger.enabled){var e=H.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 Wt=jt;var Vt=function(){function t(){}return t.prototype.setup=function(){var t=H.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 Kt=Vt;var Yt=function(){function t(){}return t.prototype.setup=function(){var t=this,e=H.p;this._externalToggleButton=e.createButton("Shortcuts [H]"),this._externalToggleButton.parent(e.select("body")),this._externalToggleButton.id("btn-shortcuts-external"),this._externalToggleButton.mousePressed(function(){return t.toggle()}),this._container=e.createDiv(),this._container.parent(e.select("body")),this._container.id("shortcuts-modal-background"),this._container.class("hidden");var i=e.createDiv();i.parent(this._container),i.id("shortcuts-modal");var n=e.createDiv();n.parent(i),n.id("shortcuts-modal-frame");var r=e.createElement("h2");r.parent(n),r.html("Keyboard Shortcuts");var o=e.createDiv();o.parent(n),o.id("shortcuts-modal-screen");var s=e.createDiv();s.parent(o),s.class("shortcuts-grid"),[{key:"Arrows / WASD",action:"Move"},{key:"J",action:"Action"},{key:"1",action:"Power"},{key:"2",action:"Start / Pause"},{key:"3",action:"Sound"},{key:"4",action:"Reset"},{key:"5",action:"Exit"},{key:"6",action:"Enable Colors"},{key:"7",action:"Enable Trackpad"},{key:"H",action:"Help (Shortcuts)"}].forEach(function(t){var i=e.createDiv();i.parent(s),i.class("shortcut-item");var n=e.createSpan();n.parent(i),n.class("shortcut-key"),n.html(t.key);var r=e.createSpan();r.parent(i),r.class("shortcut-action"),r.html(t.action)}),this._closeButton=e.createButton("Close"),this._closeButton.parent(i),this._closeButton.id("close-shortcuts"),this._closeButton.mousePressed(function(){return t._hide()})},t.prototype.toggle=function(){this._container.hasClass("hidden")?this._show():this._hide()},t.prototype._show=function(){this._container.removeClass("hidden")},t.prototype._hide=function(){this._container.addClass("hidden")},t}();const Xt=Yt;var Jt=function(){function t(t,e){var i=this;this._isDrawing=!1,this._startX=0,this._startY=0,this._maxDist=0,this._lastDirection=null,this._threshold=30,this._tapThreshold=10,this._points=[],this._loop=function(){if(i._ctx&&(i._ctx.globalCompositeOperation="destination-out",i._ctx.fillStyle="rgba(255, 255, 255, 0.1)",i._ctx.fillRect(0,0,i._canvas.width,i._canvas.height),i._ctx.globalCompositeOperation="source-over",i._isDrawing&&i._points.length>1)){i._ctx.beginPath(),i._ctx.strokeStyle=f.colors.bodyButton,i._ctx.lineWidth=6,i._ctx.lineCap="round",i._ctx.lineJoin="round";var t=i._points[i._points.length-1],e=i._points[i._points.length-2];i._ctx.moveTo(e.x,e.y),i._ctx.lineTo(t.x,t.y),i._ctx.stroke()}i._animationFrameId=requestAnimationFrame(i._loop)},this._inputHandler=e;var n=H.p;this._container=n.createDiv(),this._container.parent(t),this._container.addClass("trackpad-surface");var r=n.createP("Swipe for Directions<br/>Tap for Action");r.parent(this._container),r.addClass("trackpad-hint"),this._canvas=document.createElement("canvas"),this._canvas.classList.add("trackpad-canvas"),this._container.elt.appendChild(this._canvas),this._ctx=this._canvas.getContext("2d"),new ResizeObserver(function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];i._canvas.width=r.contentRect.width,i._canvas.height=r.contentRect.height}}).observe(this._container.elt),this._bindEvents(),this._loop()}return t.prototype._bindEvents=function(){var t=this._container.elt;t.addEventListener("pointerdown",this._onPointerDown.bind(this)),t.addEventListener("pointermove",this._onPointerMove.bind(this)),t.addEventListener("pointerup",this._onPointerUp.bind(this)),t.addEventListener("pointercancel",this._onPointerUp.bind(this)),t.addEventListener("pointerout",this._onPointerUp.bind(this)),t.addEventListener("contextmenu",function(t){return t.preventDefault()})},t.prototype._getCoords=function(t){var e=this._container.elt.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}},t.prototype._onPointerDown=function(t){this._isDrawing=!0;var e=this._getCoords(t),i=e.x,n=e.y;this._startX=i,this._startY=n,this._maxDist=0,this._lastDirection=null,this._points=[{x:i,y:n}],t.preventDefault(),this._container.elt.setPointerCapture(t.pointerId)},t.prototype._onPointerMove=function(t){if(this._isDrawing){var e=this._getCoords(t),i=e.x,n=e.y;this._points.push({x:i,y:n});var r=i-this._startX,o=n-this._startY,s=Math.sqrt(r*r+o*o);if(s>this._maxDist&&(this._maxDist=s),s>this._threshold){var a;a=Math.abs(r)>Math.abs(o)?r>0?l.RIGHT:l.LEFT:o>0?l.DOWN:l.UP,this._lastDirection!==a&&(this._lastDirection&&this._inputHandler.handleRelease(this._lastDirection),this._inputHandler.handlePress(a),this._lastDirection=a)}t.preventDefault()}},t.prototype._onPointerUp=function(t){var e=this;this._isDrawing&&(this._isDrawing=!1,this._lastDirection?(this._inputHandler.handleRelease(this._lastDirection),this._lastDirection=null):this._maxDist<this._tapThreshold&&(this._inputHandler.handlePress(l.ACTION),setTimeout(function(){return e._inputHandler.handleRelease(l.ACTION)},50)),this._container.elt.releasePointerCapture(t.pointerId))},t.prototype.destroy=function(){cancelAnimationFrame(this._animationFrameId),this._container.remove()},t}();const qt=Jt;var Qt=function(){function t(t){this._trackpad=null,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(f.inputQueryParams.mainColor)?i.get(f.inputQueryParams.mainColor):f.colors.bodyMain,r=i.has(f.inputQueryParams.buttonColor)?i.get(f.inputQueryParams.buttonColor):f.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",r),t.style.setProperty("--color-shadow",Ft(n).darken(.15).toHex()),t.style.setProperty("--color-shadow-reflexion",Ft(n).lighten(.15).toHex()),t.style.setProperty("--button-color-reflexion",Ft(r).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",Ft(r).darken(.15).toHex());var o=function(t){var e,i=H.p.createDiv();if(i.parent("#brick-game"),i.id("container"),t.clientWidth<=f.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*f.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*f.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=o.container,a=o.height,u=o.width,c=function(t){var e=H.p,i=e.createDiv();i.parent(t),i.id("frame");var n=e.createDiv();return n.parent(i),e.createP("Brick Engine").parent(n),i}(s),l=function(t,e){var i=H.p,n=e*f.viewLayout.canvas.widthRatio,r=n*f.viewLayout.canvas.aspectRatio,o=i.createCanvas(n,r);return o.parent(t),o.id("brick-game-canvas"),{canvasWidth:n,canvasHeight:r,canvas:o}}(c,u),h=l.canvas,d=l.canvasHeight,p=l.canvasWidth,g=function(t){var e=H.p,i=e.createDiv();i.parent(t),i.id("button-container");var n=e.createDiv();n.parent(i),n.id("small-button-container");var r=e.createDiv();r.parent(i),r.id("inner-button-container");var o=e.createDiv();o.parent(r),o.id("medium-button-container");var s=e.createDiv();s.parent(o),s.id("direction-vertical-container");var a=e.createDiv();a.parent(o),a.id("direction-horizontal-container");var u=e.createDiv();u.parent(r),u.id("large-button-container");var c=e.createDiv();return c.parent(r),c.id("trackpad-container"),{smallButtonContainer:n,mediumButtonContainer:o,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a,trackpadContainer:c}}(s),y=g.largeButtonContainer,_=g.smallButtonContainer,v=g.directionHorizontalContainer,m=g.directionVerticalContainer,b=g.mediumButtonContainer,E=g.trackpadContainer;return this._mediumButtonContainer=b,this._largeButtonContainer=y,this._trackpadContainer=E,this._onOffBtn=Ut(_,"On<br/>Off",!0),this._startPauseBtn=Ut(_,"Start<br/>Pause",!1),this._soundBtn=Ut(_,"Sound",!0),this._resetBtn=Ut(_,"Reset",!1),this._exitBtn=Ut(_,"Exit",!0),this._enableColorBtn=Ut(_,"Enable<br/>Colors",!1),this._trackpadBtn=Ut(_,"Track<br/>Pad",!0),this._upBtn=zt(m,"UP"),this._leftBtn=zt(v,"LEFT"),this._downBtn=zt(m,"DOWN"),this._rightBtn=zt(v,"RIGHT"),this._actionBtn=function(t){var e=H.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",f.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*f.viewLayout.dimensions.borderRadiusRatio,"px")),r.style.setProperty("--border","".concat(t*f.viewLayout.dimensions.borderWidthRatio,"px solid black")),r.style.setProperty("--sm-button-size","".concat(t*f.viewLayout.dimensions.button.smSizeRatio,"px")),r.style.setProperty("--button-size","".concat(t*f.viewLayout.dimensions.button.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size","".concat(t*f.viewLayout.dimensions.button.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile","".concat(t*f.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),r.style.setProperty("--button-size-mobile","".concat(t*f.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),r.style.setProperty("--lg-button-size-mobile","".concat(t*f.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),r.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*f.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*f.viewLayout.dimensions.button.mobile.smFontRatio,"px")),r.style.setProperty("--button-size-mobile-font-size","".concat(t*f.viewLayout.dimensions.button.mobile.fontRatio,"px")),r.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*f.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),r.style.setProperty("--button-size-mobile-spacing","".concat(t*f.viewLayout.dimensions.button.mobile.spacingRatio,"px")),r.style.setProperty("--button-border","".concat(t*f.viewLayout.dimensions.button.borderRatio,"px solid black")),r.style.setProperty("--button-animation-duration",f.viewLayout.dimensions.button.animationDuration)}(u,a,p,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:p,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Kt,this._sessionModal.setup(),this._shortcutsModal=new Xt,this._shortcutsModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.toggleShortcutsModal=function(){this._shortcutsModal.toggle()},t.prototype.setupDebugger=function(t){this._debugger=new Wt(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 g(t),this._trackpad&&this._trackpad.destroy(),this._trackpad=new qt(this._trackpadContainer,this._inputHandler),this._bindButtonEvents(this._onOffBtn,l.POWER),this._bindButtonEvents(this._startPauseBtn,l.START_PAUSE),this._bindButtonEvents(this._soundBtn,l.SOUND),this._bindButtonEvents(this._resetBtn,l.RESET),this._bindButtonEvents(this._exitBtn,l.EXIT),this._bindButtonEvents(this._enableColorBtn,l.COLOR),this._bindButtonEvents(this._trackpadBtn,l.TRACKPAD),this._bindButtonEvents(this._upBtn,l.UP),this._bindButtonEvents(this._downBtn,l.DOWN),this._bindButtonEvents(this._rightBtn,l.RIGHT),this._bindButtonEvents(this._leftBtn,l.LEFT),this._bindButtonEvents(this._actionBtn,l.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._trackpadBtn.mousePressed(function(){}).mouseReleased(function(){}),this._trackpad&&(this._trackpad.destroy(),this._trackpad=null),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=f.viewLayout.splashHideDelayMs);var e=document.querySelector("#splash");setTimeout(function(){e.style.display="none"},t)},t.prototype.applyTrackpadState=function(t){t?(this._mediumButtonContainer.style("display","none"),this._largeButtonContainer.style("display","none"),this._trackpadContainer.style("display","flex")):(this._mediumButtonContainer.style("display","flex"),this._largeButtonContainer.style("display","flex"),this._trackpadContainer.style("display","none"))},t}();const $t=Qt;var Zt,te=n(991),ee=n.n(te);function ie(t){Zt=t}function ne(t){return window.BrickEngineGame=t,new(ee())(function(e){H.init(e);var i=new $t(document.body);ie(new t(i)),"unknown"===Zt.gameId&&(Zt.gameId="game"),e.setup=function(){Zt.setup(),Zt.view.setupDebugger(Zt.modules),Zt.view.setupSessionModal()},e.draw=function(){Zt.draw(),Zt.view.updateDebugger()}})}return p})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var o=i[t];if(void 0!==o)return o.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,n),r.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 o,r,s,a,u,c,l,h,d,p,f={};n.r(f),n.d(f,{Color:()=>o,ControlEventType:()=>h,ControlKey:()=>l,EventEmitter:()=>b,FontAlign:()=>r,FontSize:()=>a,FontVerticalAlign:()=>u,Game:()=>yt,GameView:()=>Zt,RendererContext:()=>N,ScoreProperty:()=>p,Sound:()=>c,StateProperty:()=>d,TextTheme:()=>s,bootstrap:()=>oe,configs:()=>y,setActiveGame:()=>ne}),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)"}(o||(o={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(r||(r={})),function(t){t.ACTIVE="active",t.INACTIVE="inactive",t.SHADOW="shadow"}(s||(s={})),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"}(a||(a={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(u||(u={})),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"}(c||(c={})),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",t.TRACKPAD="trackpad;system",t.SHORTCUTS="shortcuts;system"}(l||(l={})),function(t){t.PRESSED="pressed",t.HELD="held"}(h||(h={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted",t.TRACKPAD="trackpadEnabled"}(d||(d={})),function(t){t.SCORE="score",t.LEVEL="level",t.MULTIPLIER="multiplier",t.MAX_LEVEL="maxLevel",t.HIGH_SCORE="highScore"}(p||(p={}));const y={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},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"},buttonHold:{holdDelayMs:267,holdIntervalMs:100},game:{tickInterval:1e3/60,debugger:{enabled:!0},sound:{volume:.025}}},g=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,h.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,h.HELD)},y.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},y.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 _={ArrowUp:l.UP,ArrowDown:l.DOWN,ArrowLeft:l.LEFT,ArrowRight:l.RIGHT,KeyW:l.UP,KeyS:l.DOWN,KeyA:l.LEFT,KeyD:l.RIGHT,KeyJ:l.ACTION,Digit1:l.POWER,Digit2:l.START_PAUSE,Digit3:l.SOUND,Digit4:l.RESET,Digit5:l.EXIT,Digit6:l.COLOR,Digit7:l.TRACKPAD,KeyH:l.SHORTCUTS};const v=function(){function t(t){this._inputHandler=new g(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=_[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=_[t.code];e&&this._inputHandler.handleRelease(e)},t}();var m;!function(t){t.TITLE="title",t.PLAYING="playing",t.GAMEOVER="gameover",t.PAUSED="paused"}(m||(m={}));const b=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,m.PLAYING),e):i.isPaused()?this.notify(this._formatName(t,m.PAUSED),e):i.isOn()&&!i.isStarted()?this.notify(this._formatName(t,m.TITLE),e):i.isGameOver()&&this.notify(this._formatName(t,m.GAMEOVER),e)},t._formatName=function(t,e){return e?"".concat(t,":").concat(e):t},t.clear=function(){this._events={}},t._events={},t}();var E=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new v(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._activeListeners.forEach(function(t){var e=t.event,i=t.callback;b.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,m.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e,i){this._unsubscribe(t,e,i,m.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e,i){this._subscribe(t,e,i,m.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e,i){this._unsubscribe(t,e,i,m.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e,i){this._subscribe(t,e,i,m.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e,i){this._unsubscribe(t,e,i,m.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e,i){this._subscribe(t,e,i,m.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e,i){this._unsubscribe(t,e,i,m.PAUSED)},t.prototype._subscribe=function(t,e,i,n){var o="".concat(t,":").concat(e);b.subscribe(o,i,n);var r=n?"".concat(o,":").concat(n):o;this._activeListeners.push({event:r,callback:i})},t.prototype._unsubscribe=function(t,e,i,n){var o="".concat(t,":").concat(e);b.unsubscribe(o,i,n);var r=n?"".concat(o,":").concat(n):o;this._activeListeners=this._activeListeners.filter(function(t){return!(t.event===r&&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,o=this._modules.session,r=!1;o.isModalOpen()||n.isPlaying()&&!o.isSessionResolved()?r=!1:n.isOff()?r=[l.POWER,l.TRACKPAD,l.SHORTCUTS].includes(t):!n.isStarted()||n.isPlaying()||n.isGameOver()?r=!0:n.isPaused()&&(r=t.endsWith(";system")||t===l.SHORTCUTS),r&&b.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const S=E,w=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:o.DEFAULT,coordinate:t}},t}();var P=function(){return P=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},P.apply(this,arguments)},R=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return P(P({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),o=n.some(function(e){if(!i.grid.isCoordinateValid(e.coordinate))return!0;var n,o=i.grid.getCell(e.coordinate);return o&&i.grid.isCellActive(o)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}))});return o?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:P(P({},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 C=R;var x=function(){return x=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},x.apply(this,arguments)},O=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var o=t.map(function(t){var n=t.coordinate.x-e.x,o=t.coordinate.y-e.y,r=i?-o:o,s=i?n:-n;return x(x({},t),{coordinate:{x:e.x+r,y:e.y+s}})}),r=o.some(function(e){if(!n.grid.isCoordinateValid(e.coordinate))return!0;var i,o=n.grid.getCell(e.coordinate);return o&&n.grid.isCellActive(o)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}))});return r?t:o},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 x(x({},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 T=O;var A=function(){return A=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},A.apply(this,arguments)},D=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 o=this.grid.getCell({x:n,y:e});if(o&&!this.grid.isCellActive(o)){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 o=this.grid.getCell({x:e,y:n});if(o&&!this.grid.isCellActive(o)){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=[],o=[{x:-1,y:0},{x:1,y:0},{x:0,y:-1},{x:0,y:1}];return e&&o.push({x:-1,y:-1},{x:1,y:-1},{x:-1,y:1},{x:1,y:1}),o.forEach(function(e){var o={x:t.x+e.x,y:t.y+e.y};if(i.grid.isCoordinateValid(o)){var r=i.grid.getCell(o);r&&n.push(r)}}),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,o=[],r=new Set,s=[t],a=function(t){return"".concat(t.x,",").concat(t.y)};for(r.add(a(t));s.length>0;){var u=s.shift(),c=this.grid.getCell(u);c.value===n&&(o.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)&&!r.has(i)&&n&&e.grid.isCellActive(n)&&(r.add(i),s.push(t))}))}return o},t.prototype.swapCells=function(t,e){var i=A({},this.grid.getCell(t)),n=A({},this.grid.getCell(e));this.grid.stampCell(A(A({},n),{coordinate:t})),this.grid.stampCell(A(A({},i),{coordinate:e}))},t}();const L=D;var M=function(){function t(t){this.grid=t}return t.prototype.isRowFull=function(t){var e=this.grid.getGrid();return!(t<0||t>=this.grid.height)&&e[t].every(function(t){return t.value>0})},t.prototype.isRowEmpty=function(t){var e=this.grid.getGrid();return t<0||t>=this.grid.height||e[t].every(function(t){return 0===t.value})},t.prototype.clearRow=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.height))for(var i=0;i<this.grid.width;i++)e[t][i]=w.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 o=e[i-1][n];e[i][n].value=o.value,e[i][n].color=o.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 o=e[i+1][n];e[i][n].value=o.value,e[i][n].color=o.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]=w.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 o=e[n][i-1];e[n][i].value=o.value,e[n][i].color=o.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 o=e[n][i+1];e[n][i].value=o.value,e[n][i].color=o.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 k=M;var I=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 o=Math.max(0,Math.min(t.x,e.x)),r=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=o;c<=r;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 G=I;var B=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new C(this),this._transformEngine=new T(this),this._analysisEngine=new L(this),this._lineEngine=new k(this),this._regionEngine=new G(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return y.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return y.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]=w.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 H=B,N=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}(),F=function(){function t(){}return t.getRelativeWidth=function(t){return t*N.p.width},t.getRelativeHeight=function(t){return t*N.p.height},t}();var z=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=y.screenLayout.cell,i=e.margin,n=e.padding,o=e.strokeWeight,r=this._rendererMetrics.cell.size;this._cellPreCalculatedGeometry={innerOffset:i*r,innerSize:r-i*r*2,paddingOffset:n*r,paddingSize:r-n*r*2,strokeWeight:o*r},this._renderStaticElements()},t.prototype.render=function(t,e){var i=N.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=N.p,e=y.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(y.colors.background),this._staticGraphics.strokeWeight(F.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(y.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,r=t.value,s=N.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===r||!e.isPlaying()&&!e.isPaused()?o.INACTIVE:e.isColorEnabled()||n===o.SHADOW?n:o.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 U=z;var j=function(){function t(){}return t.getRelativeCoordinate=function(t){return{x:F.getRelativeWidth(t.x),y:F.getRelativeHeight(t.y)}},t.getDisplayPosX=function(t,e){var i=y.screenLayout.display.margin;return e*t+F.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=y.screenLayout.display.margin;return e*t+F.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=N.p,n=y.screenLayout.display.margin,o=F.getRelativeWidth(n),r=e+2*o;return(i.width-r-o)*t+r},t.getHudPosY=function(t,e){var i=y.screenLayout.display.margin;return e*t+F.getRelativeHeight(i)},t}();const V=j;var W=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:V.getHudPosX(.078,t.display.width),y:V.getHudPosY(.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-F.getRelativeWidth(.005),y:this._gridOrigin.y-F.getRelativeHeight(.005),w:4*this._cellSize+F.getRelativeWidth(.01),h:4*this._cellSize+F.getRelativeHeight(.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=N.p,i=t.text,n=t.state,o=t.score;e.push(),i.setTextSize(a.SMALL),i.setInactiveText(),i.setTextAlign(r.LEFT,u.BOTTOM),i.writeOnHud("88888888",{x:.05,y:.13}),i.writeOnHud("88888888",{x:.05,y:.3}),i.writeOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.writeOnHud("Score",{x:.05,y:.06}),i.writeOnHud(o.score.toString(),{x:.05,y:.13}),i.writeOnHud("Hi-Score",{x:.05,y:.23}),i.writeOnHud(o.highScore.toString(),{x:.05,y:.3}),i.writeOnHud("Level",{x:.05,y:.72});var s="".concat(o.level<10?"0"+o.level:o.level," - ").concat(o.maxLevel);i.writeOnHud(s,{x:.05,y:.8}),i.setTextAlign(r.CENTER,u.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.writeOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.writeOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=N.p,n=t.hudGrid,r=t.state;i.push(),n.forEach(function(t){var i=t.coordinate,n=i.x,s=i.y;r.isOff()&&!r.isPlaying()&&(t.value=0);var a=0!==t.value?o.DEFAULT:o.INACTIVE;r.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(r.isOn()?o.DEFAULT:o.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,o=t.color,r=N.p,s=y.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,p=s.strokeWeight*e;r.push(),r.translate(i,n),r.strokeWeight(p),r.stroke(o),r.noFill(),r.rect(c,c,l,l),r.fill(o),r.rect(h,h,d,d),r.pop()},t}();const K=W;var Y=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new U,this._hudRenderer=new K,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=y.screenLayout.display,e=t.width,i=t.height,n=t.margin,o=y.screenLayout.grid.columns,r=F.getRelativeWidth(e),s=F.getRelativeHeight(i),a=V.getRelativeCoordinate({x:n,y:n}),u=r/o,c={x:V.getHudPosX(0,r),y:V.getHudPosY(0,s)},l=V.getHudPosX(1,r)-c.x,h=V.getHudPosY(1,s)-c.y;this._rendererMetrics={display:{width:r,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 X=Y;var J,q=((J={})[d.ON]={defaultValue:!1},J[d.START]={defaultValue:!1},J[d.PLAYING]={defaultValue:!1},J[d.GAME_OVER]={defaultValue:!1},J[d.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},J[d.MUTED]={defaultValue:!1,storageKey:"muted"},J[d.TRACKPAD]={defaultValue:!1,storageKey:"trackpadEnabled"},J);const Q=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(d).forEach(function(e){var i=q[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(d).forEach(function(e){var i=q[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=q[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this.notify(t)}},t.prototype.notify=function(t){var e=this._state.get(t);b.notifyContextual(t,e,this)},t.prototype.isOn=function(){return this._state.get(d.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(d.START)},t.prototype.isPlaying=function(){return this._state.get(d.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(d.GAME_OVER)},t.prototype.turnOn=function(){this._set(d.ON,!0),this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(d.ON,!1),this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(d.START,!0),this._set(d.PLAYING,!0),this._set(d.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(d.GAME_OVER,!1),this._set(d.START,!0),this._set(d.PLAYING,!0)},t.prototype.exitGame=function(){this._set(d.START,!1),this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(d.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(d.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(d.PLAYING,!1),this._set(d.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(d.GAME_OVER,!1),this._set(d.START,!0),this._set(d.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(d.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(d.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(d.MUTED)},t.prototype.setMuted=function(t){this._set(d.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.isTrackpadEnabled=function(){return this._state.get(d.TRACKPAD)},t.prototype.setTrackpadEnabled=function(t){this._set(d.TRACKPAD,t)},t.prototype.toggleTrackpadEnabled=function(){this.setTrackpadEnabled(!this.isTrackpadEnabled())},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,m.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e){this._unsubscribe(t,e,m.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e){this._subscribe(t,e,m.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e){this._unsubscribe(t,e,m.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e){this._subscribe(t,e,m.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e){this._unsubscribe(t,e,m.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e){this._subscribe(t,e,m.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e){this._unsubscribe(t,e,m.PAUSED)},t.prototype._subscribe=function(t,e,i){b.subscribe(t,e,i)},t.prototype._unsubscribe=function(t,e,i){b.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(),trackpad:this.isTrackpadEnabled()}},t}();var $=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=N.p,e=y.screenLayout.fontSize,i=e.extraSmall,n=e.small,o=e.medium,r=e.large,s=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[a.EXTRA_SMALL]=F.getRelativeWidth(i),this.fontSizes[a.SMALL]=F.getRelativeWidth(n),this.fontSizes[a.MEDIUM]=F.getRelativeWidth(o),this.fontSizes[a.LARGE]=F.getRelativeWidth(r),this.fontSizes[a.EXTRA_LARGE]=F.getRelativeWidth(s)},t.prototype.setTime=function(t){this._time=t},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=N.p,i=y.colors,n=i.active,o=i.inactive;e.fill(t?n:o)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setShadowText=function(){N.p.fill(o.SHADOW)},t.prototype.setTextTheme=function(t){switch(t){case s.ACTIVE:this.setActiveText();break;case s.INACTIVE:this.setInactiveText();break;case s.SHADOW:this.setShadowText()}},t.prototype.setTextSize=function(t){N.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){N.p.textAlign(t,e)},t.prototype.writeOnHud=function(t,e){var i=N.p,n=V.getHudPosX(e.x,this._rendererMetrics.display.width),o=V.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.writeOnDisplay=function(t,e){var i=N.p,n=V.getDisplayPosX(e.x,this._rendererMetrics.display.width),o=V.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.writePulsingTextOnHud=function(t,e,i){void 0===i&&(i=1e3);var n=Math.floor(this._time.elapsedTime%i/(i/4));0===n?(this.setActiveText(),this.writeOnHud(t,e)):1!==n&&3!==n||(this.setShadowText(),this.writeOnHud(t,e))},t.prototype.writePulsingTextOnDisplay=function(t,e,i){void 0===i&&(i=1e3);var n=Math.floor(this._time.elapsedTime%i/(i/4));0===n?(this.setActiveText(),this.writeOnDisplay(t,e)):1!==n&&3!==n||(this.setShadowText(),this.writeOnDisplay(t,e))},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const Z=$,tt=function(){function t(){this._tickAccumulator=0,this._initialTickInterval=y.game.tickInterval,this._tickInterval=y.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=0,this.serialId="time"}return 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.setup=function(){this.reset()},t.prototype.update=function(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.accumulate=function(t){this._tickAccumulator+=t},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},t.prototype.atInterval=function(t){return 0!==this._totalTicks&&Math.floor(this._totalTicks*this._tickInterval/t)>Math.floor((this._totalTicks-1)*this._tickInterval/t)},t.prototype.every=function(t,e){this.atInterval(t)&&e()},t.prototype.getDebugData=function(){return{fps:Math.round(this._fps),tps:this._tps,elapsedTime:this._totalElapsedTime}},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}();var et=function(t,e,i,n){return new(i||(i=Promise))(function(o,r){function s(t){try{u(n.next(t))}catch(t){r(t)}}function a(t){try{u(n.throw(t))}catch(t){r(t)}}function u(t){var e;t.done?o(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())})},it=function(t,e){var i,n,o,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[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]&&(r=0)),r;)try{if(i=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!((o=(o=r.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){r.label=a[1];break}if(6===a[0]&&r.label<o[1]){r.label=o[1],o=a;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(a);break}o[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(t){a=[6,t],n=0}finally{i=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},nt=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=y.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 et(this,void 0,void 0,function(){var e,i,n;return it(this,function(o){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 et(this,void 0,void 0,function(){var e;return it(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 et(this,void 0,void 0,function(){var t,e,i,n;return it(this,function(o){switch(o.label){case 0:t=Array.from(this._activeSources.keys()),e=0,i=t,o.label=1;case 1:return e<i.length?(n=i[e],[4,this.stop(n)]):[3,4];case 2:o.sent(),o.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 et(this,void 0,void 0,function(){var t,e=this;return it(this,function(i){switch(i.label){case 0:return t=Object.values(c).map(function(t){return et(e,void 0,void 0,function(){var e,i,n;return it(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,fetch(t)];case 1:return[4,o.sent().arrayBuffer()];case 2:return e=o.sent(),[4,this._audioContext.decodeAudioData(e)];case 3:return i=o.sent(),this._buffers.set(t,i),[3,5];case 4:return n=o.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(d.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 ot=nt,rt=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._notify(p.SCORE),this._score>this._highScore&&(this.highScore=this._score)},t.prototype.resetScore=function(){this._score=0,this._notify(p.SCORE)},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,this._notify(p.LEVEL)},t.prototype.resetLevel=function(){this._level=1,this._notify(p.LEVEL)},Object.defineProperty(t.prototype,"multiplier",{get:function(){return this._multiplier},set:function(t){this._multiplier!==t&&(this._multiplier=t,this._notify(p.MULTIPLIER))},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&&(this._maxLevel=t,this._notify(p.MAX_LEVEL))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"highScore",{get:function(){return this._highScore},set:function(t){this._highScore!==t&&(this._highScore=t,localStorage.setItem("".concat(this._gameId,"::highScore"),t.toString()),this._notify(p.HIGH_SCORE))},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){b.subscribe(p.SCORE,t)},t.prototype.unsubscribe=function(t){b.unsubscribe(p.SCORE,t)},t.prototype._notify=function(t){var e=this[t];b.notify(t,e)},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 st,at=(st=function(t,e){return st=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])},st(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}st(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)});const ut=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return at(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}(H),ct=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,o="string"==typeof e.serialId;return i&&n&&o},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 Q)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var lt=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 o=n;try{if(n&&"object"==typeof n){var r=Object.getPrototypeOf(n)===Object.prototype||null===Object.getPrototypeOf(n),s=Array.isArray(n);r||s?o=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.")),o=n)}else o=n;console.log("capturing property",i,o)}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,o)}})},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 ht=lt,dt=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._state.isGameOver()&&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;this._state=t,t.subscribe(d.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,N.p.noLoop(),e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0,N.p.loop()},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0,N.p.loop()})}}),t.subscribe(d.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(d.START,function(t){t||(e._isSessionResolved=!1)}),t.subscribe(d.GAME_OVER,function(t){t&&e.clearSession()})},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}(),pt=function(){function t(){}return t.setupControlEvents=function(t,e,i){var n=t.control,o=t.state,r=t.session,s=t.sound;n.subscribe(l.SOUND,h.PRESSED,function(){return o.toggleMuted()}),n.subscribe(l.COLOR,h.PRESSED,function(){return o.toggleColorEnabled()}),n.subscribe(l.EXIT,h.PRESSED,function(){return r.clearSession()}),n.subscribe(l.TRACKPAD,h.PRESSED,function(){return o.toggleTrackpadEnabled()}),n.subscribe(l.SHORTCUTS,h.PRESSED,function(){return e.toggleShortcutsModal()}),n.subscribe(l.POWER,h.PRESSED,function(){o.isOn()?(o.turnOff(),s.stopAll()):o.turnOn()}),n.subscribeForGameOverScreen(l.POWER,h.PRESSED,function(){i(),o.resetGameOver()}),n.subscribeForTitleScreen(l.START_PAUSE,h.PRESSED,function(){return o.startGame()}),n.subscribeForPlayingScreen(l.START_PAUSE,h.PRESSED,function(){return o.pause()}),n.subscribeForGameOverScreen(l.START_PAUSE,h.PRESSED,function(){i(),o.resetGameOver()}),n.subscribeForPausedScreen(l.START_PAUSE,h.PRESSED,function(){return o.resume()}),n.subscribeForPlayingScreen(l.RESET,h.PRESSED,function(){i(),o.resetGame()}),n.subscribeForPausedScreen(l.RESET,h.PRESSED,function(){i(),o.resetGame()})},t.setupStateEvents=function(t,e){var i=t.state,n=t.session;i.subscribe(d.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),i.subscribeForGameOverScreen(d.GAME_OVER,function(){n.clearSession()}),i.subscribe(d.TRACKPAD,function(t){e.applyTrackpadState(t)}),e.applyTrackpadState(i.isTrackpadEnabled())},t}();var ft=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new ht,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 N.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;b.clear(),this._view.build(),this._modules={renderer:new X,grid:new H,hudGrid:new ut,text:new Z,state:new Q,control:new S,time:new tt,sound:new ot,score:new rt,session:new dt},Object.values(this._modules).forEach(function(t){ct.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){ct.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){ct.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,o=e.renderer,r=e.session,s=e.score,a=e.time;r.gameId=this.gameId,r.setShowModalFunction(this._view.showSessionModal.bind(this._view)),r.setResetFunction(this.reset.bind(this)),n.setModules(this._modules),i.setRendererMetrics(o.rendererMetrics),i.setTime(a),s.setupGameHighScore(this.gameId),this.setupGame(),pt.setupControlEvents(this._modules,this._view,this.reset.bind(this)),pt.setupStateEvents(this._modules,this._view),this._view.bindControls(n),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=N.p;if(this._modules){var e=this._modules,i=e.renderer,n=e.grid,o=e.time,r=e.state,s=e.session;if(!(s.isModalOpen()||r.isPlaying()&&!s.isSessionResolved())&&(o.update(t.deltaTime),i.render(n.getGrid(),this._modules),r.isOn())){if(r.isStarted())if(r.isPlaying()){for(o.accumulate(t.deltaTime);o.shouldTick();)this.update(t.deltaTime),this._modules.session.saveSession();this.render()}else r.isPaused()&&this.render();else this.drawTitleScreen();r.isGameOver()&&this.drawGameOverScreen()}}},t.prototype.destroy=function(){N.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll()),b.clear()},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 yt=ft;var gt={grad:.9,turn:360,rad:360/(2*Math.PI)},_t=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},vt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},mt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},bt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},Et=function(t){return{r:mt(t.r,0,255),g:mt(t.g,0,255),b:mt(t.b,0,255),a:mt(t.a)}},St=function(t){return{r:vt(t.r),g:vt(t.g),b:vt(t.b),a:vt(t.a,3)}},wt=/^#([0-9a-f]{3,8})$/i,Pt=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Rt=function(t){var e=t.r,i=t.g,n=t.b,o=t.a,r=Math.max(e,i,n),s=r-Math.min(e,i,n),a=s?r===e?(i-n)/s:r===i?2+(n-e)/s:4+(e-i)/s:0;return{h:60*(a<0?a+6:a),s:r?s/r*100:0,v:r/255*100,a:o}},Ct=function(t){var e=t.h,i=t.s,n=t.v,o=t.a;e=e/360*6,i/=100,n/=100;var r=Math.floor(e),s=n*(1-i),a=n*(1-(e-r)*i),u=n*(1-(1-e+r)*i),c=r%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:o}},xt=function(t){return{h:bt(t.h),s:mt(t.s,0,100),l:mt(t.l,0,100),a:mt(t.a)}},Ot=function(t){return{h:vt(t.h),s:vt(t.s),l:vt(t.l),a:vt(t.a,3)}},Tt=function(t){return Ct((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},At=function(t){return{h:(e=Rt(t)).h,s:(o=(200-(i=e.s))*(n=e.v)/100)>0&&o<200?i*n/100/(o<=100?o:200-o)*100:0,l:o/2,a:e.a};var e,i,n,o},Dt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,kt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It={string:[[function(t){var e=wt.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?vt(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?vt(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Mt.exec(t)||kt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:Et({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=Dt.exec(t)||Lt.exec(t);if(!e)return null;var i,n,o=xt({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(gt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Tt(o)},"hsl"]],object:[[function(t){var e=t.r,i=t.g,n=t.b,o=t.a,r=void 0===o?1:o;return _t(e)&&_t(i)&&_t(n)?Et({r:Number(e),g:Number(i),b:Number(n),a:Number(r)}):null},"rgb"],[function(t){var e=t.h,i=t.s,n=t.l,o=t.a,r=void 0===o?1:o;if(!_t(e)||!_t(i)||!_t(n))return null;var s=xt({h:Number(e),s:Number(i),l:Number(n),a:Number(r)});return Tt(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,o=t.a,r=void 0===o?1:o;if(!_t(e)||!_t(i)||!_t(n))return null;var s=function(t){return{h:bt(t.h),s:mt(t.s,0,100),v:mt(t.v,0,100),a:mt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(r)});return Ct(s)},"hsv"]]},Gt=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]},Bt=function(t,e){var i=At(t);return{h:i.h,s:mt(i.s+100*e,0,100),l:i.l,a:i.a}},Ht=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Nt=function(t,e){var i=At(t);return{h:i.h,s:i.s,l:mt(i.l+100*e,0,100),a:i.a}},Ft=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Gt(t.trim(),It.string):"object"==typeof t&&null!==t?Gt(t,It.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return vt(Ht(this.rgba),2)},t.prototype.isDark=function(){return Ht(this.rgba)<.5},t.prototype.isLight=function(){return Ht(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=St(this.rgba)).r,i=t.g,n=t.b,r=(o=t.a)<1?Pt(vt(255*o)):"","#"+Pt(e)+Pt(i)+Pt(n)+r;var t,e,i,n,o,r},t.prototype.toRgb=function(){return St(this.rgba)},t.prototype.toRgbString=function(){return e=(t=St(this.rgba)).r,i=t.g,n=t.b,(o=t.a)<1?"rgba("+e+", "+i+", "+n+", "+o+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,o},t.prototype.toHsl=function(){return Ot(At(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ot(At(this.rgba))).h,i=t.s,n=t.l,(o=t.a)<1?"hsla("+e+", "+i+"%, "+n+"%, "+o+")":"hsl("+e+", "+i+"%, "+n+"%)";var t,e,i,n,o},t.prototype.toHsv=function(){return t=Rt(this.rgba),{h:vt(t.h),s:vt(t.s),v:vt(t.v),a:vt(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(Bt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),zt(Bt(this.rgba,-t))},t.prototype.grayscale=function(){return zt(Bt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),zt(Nt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),zt(Nt(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}):vt(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=At(this.rgba);return"number"==typeof t?zt({h:t,s:e.s,l:e.l,a:e.a}):vt(e.h)},t.prototype.isEqual=function(t){return this.toHex()===zt(t).toHex()},t}(),zt=function(t){return t instanceof Ft?t:new Ft(t)};function Ut(t,e){var i=N.p,n=i.createDiv();n.parent(t),n.addClass("btn-container");var o=i.createButton(e);return o.parent(n),o.addClass("btn"),o}function jt(t,e,i){var n=N.p,o=n.createDiv();o.parent(t),o.addClass("sm-btn-container"),o.addClass(i?"sm-btn-container-top":"sm-btn-container-bottom");var r=n.createButton("");r.parent(o),r.addClass("sm-btn");var s=n.createP(e);return s.parent(o),s.addClass("sm-btn-p"),r}var Vt=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(y.game.debugger.enabled){var e=N.p,i=e.select("#debugger"),n=!!i&&i.elt.hasAttribute("open"),o=new Set;i&&(e.selectAll(".debugger-module").forEach(function(t){t.elt.hasAttribute("open")&&o.add(t.id())}),i.remove()),this._moduleElements=[];var r=e.createElement("details");r.id("debugger"),n&&r.attribute("open",""),r.parent(e.select("body"));var s=e.createElement("summary");s.id("debugger-summary"),s.html("Debug"),s.parent(r),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)),o.has("debugger-".concat(n))&&u.attribute("open",""),u.parent(r);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],o=e.createElement("div");o.class("debugger-container"),o.id("debugger-container-".concat(i,"-").concat(n)),o.parent(u),o.mouseClicked(function(){o.toggleClass("highlight")});var r=e.createElement("p");r.id("debugger-".concat(i,"-").concat(n)),r.html("".concat(i,":")),r.parent(o);var s=e.createElement("span");s.id("debugger-".concat(i,"-").concat(n,"-value")),s.html("".concat(n)),s.parent(o),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 Wt=Vt;var Kt=function(){function t(){}return t.prototype.setup=function(){var t=N.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 o=t.createDiv();o.parent(i),o.id("session-modal-screen");var r=t.createP();r.parent(o),r.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 Yt=Kt;var Xt=function(){function t(){}return t.prototype.setup=function(){var t=this,e=N.p;this._externalToggleButton=e.createButton("Shortcuts [H]"),this._externalToggleButton.parent(e.select("body")),this._externalToggleButton.id("btn-shortcuts-external"),this._externalToggleButton.mousePressed(function(){return t.toggle()}),this._container=e.createDiv(),this._container.parent(e.select("body")),this._container.id("shortcuts-modal-background"),this._container.class("hidden");var i=e.createDiv();i.parent(this._container),i.id("shortcuts-modal");var n=e.createDiv();n.parent(i),n.id("shortcuts-modal-frame");var o=e.createElement("h2");o.parent(n),o.html("Keyboard Shortcuts");var r=e.createDiv();r.parent(n),r.id("shortcuts-modal-screen");var s=e.createDiv();s.parent(r),s.class("shortcuts-grid"),[{key:"Arrows / WASD",action:"Move"},{key:"J",action:"Action"},{key:"1",action:"Power"},{key:"2",action:"Start / Pause"},{key:"3",action:"Sound"},{key:"4",action:"Reset"},{key:"5",action:"Exit"},{key:"6",action:"Enable Colors"},{key:"7",action:"Enable Trackpad"},{key:"H",action:"Help (Shortcuts)"}].forEach(function(t){var i=e.createDiv();i.parent(s),i.class("shortcut-item");var n=e.createSpan();n.parent(i),n.class("shortcut-key"),n.html(t.key);var o=e.createSpan();o.parent(i),o.class("shortcut-action"),o.html(t.action)}),this._closeButton=e.createButton("Close"),this._closeButton.parent(i),this._closeButton.id("close-shortcuts"),this._closeButton.mousePressed(function(){return t._hide()})},t.prototype.toggle=function(){this._container.hasClass("hidden")?this._show():this._hide()},t.prototype._show=function(){this._container.removeClass("hidden")},t.prototype._hide=function(){this._container.addClass("hidden")},t}();const Jt=Xt;var qt=function(){function t(t,e){var i=this;this._isDrawing=!1,this._startX=0,this._startY=0,this._maxDist=0,this._lastDirection=null,this._threshold=30,this._tapThreshold=10,this._points=[],this._loop=function(){if(i._ctx&&(i._ctx.globalCompositeOperation="destination-out",i._ctx.fillStyle="rgba(255, 255, 255, 0.1)",i._ctx.fillRect(0,0,i._canvas.width,i._canvas.height),i._ctx.globalCompositeOperation="source-over",i._isDrawing&&i._points.length>1)){i._ctx.beginPath(),i._ctx.strokeStyle=y.colors.bodyButton,i._ctx.lineWidth=6,i._ctx.lineCap="round",i._ctx.lineJoin="round";var t=i._points[i._points.length-1],e=i._points[i._points.length-2];i._ctx.moveTo(e.x,e.y),i._ctx.lineTo(t.x,t.y),i._ctx.stroke()}i._animationFrameId=requestAnimationFrame(i._loop)},this._inputHandler=e;var n=N.p;this._container=n.createDiv(),this._container.parent(t),this._container.addClass("trackpad-surface");var o=n.createP("Swipe for Directions<br/>Tap for Action");o.parent(this._container),o.addClass("trackpad-hint"),this._canvas=document.createElement("canvas"),this._canvas.classList.add("trackpad-canvas"),this._container.elt.appendChild(this._canvas),this._ctx=this._canvas.getContext("2d"),new ResizeObserver(function(t){for(var e=0,n=t;e<n.length;e++){var o=n[e];i._canvas.width=o.contentRect.width,i._canvas.height=o.contentRect.height}}).observe(this._container.elt),this._bindEvents(),this._loop()}return t.prototype._bindEvents=function(){var t=this._container.elt;t.addEventListener("pointerdown",this._onPointerDown.bind(this)),t.addEventListener("pointermove",this._onPointerMove.bind(this)),t.addEventListener("pointerup",this._onPointerUp.bind(this)),t.addEventListener("pointercancel",this._onPointerUp.bind(this)),t.addEventListener("pointerout",this._onPointerUp.bind(this)),t.addEventListener("contextmenu",function(t){return t.preventDefault()})},t.prototype._getCoords=function(t){var e=this._container.elt.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}},t.prototype._onPointerDown=function(t){this._isDrawing=!0;var e=this._getCoords(t),i=e.x,n=e.y;this._startX=i,this._startY=n,this._maxDist=0,this._lastDirection=null,this._points=[{x:i,y:n}],t.preventDefault(),this._container.elt.setPointerCapture(t.pointerId)},t.prototype._onPointerMove=function(t){if(this._isDrawing){var e=this._getCoords(t),i=e.x,n=e.y;this._points.push({x:i,y:n});var o=i-this._startX,r=n-this._startY,s=Math.sqrt(o*o+r*r);if(s>this._maxDist&&(this._maxDist=s),s>this._threshold){var a;a=Math.abs(o)>Math.abs(r)?o>0?l.RIGHT:l.LEFT:r>0?l.DOWN:l.UP,this._lastDirection!==a&&(this._lastDirection&&this._inputHandler.handleRelease(this._lastDirection),this._inputHandler.handlePress(a),this._lastDirection=a)}t.preventDefault()}},t.prototype._onPointerUp=function(t){var e=this;this._isDrawing&&(this._isDrawing=!1,this._lastDirection?(this._inputHandler.handleRelease(this._lastDirection),this._lastDirection=null):this._maxDist<this._tapThreshold&&(this._inputHandler.handlePress(l.ACTION),setTimeout(function(){return e._inputHandler.handleRelease(l.ACTION)},50)),this._container.elt.releasePointerCapture(t.pointerId))},t.prototype.destroy=function(){cancelAnimationFrame(this._animationFrameId),this._container.remove()},t}();const Qt=qt;var $t=function(){function t(t){this._trackpad=null,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,o;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(y.inputQueryParams.mainColor)?i.get(y.inputQueryParams.mainColor):y.colors.bodyMain,o=i.has(y.inputQueryParams.buttonColor)?i.get(y.inputQueryParams.buttonColor):y.colors.bodyButton,t.style.setProperty("--main-color",n),t.style.setProperty("--button-color",o),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(o).lighten(.15).toHex()),t.style.setProperty("--button-color-shadow",zt(o).darken(.15).toHex());var r=function(t){var e,i=N.p.createDiv();if(i.parent("#brick-game"),i.id("container"),t.clientWidth<=y.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*y.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*y.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=r.container,a=r.height,u=r.width,c=function(t){var e=N.p,i=e.createDiv();i.parent(t),i.id("frame");var n=e.createDiv();return n.parent(i),e.createP("Brick Engine").parent(n),i}(s),l=function(t,e){var i=N.p,n=e*y.viewLayout.canvas.widthRatio,o=n*y.viewLayout.canvas.aspectRatio,r=i.createCanvas(n,o);return r.parent(t),r.id("brick-game-canvas"),{canvasWidth:n,canvasHeight:o,canvas:r}}(c,u),h=l.canvas,d=l.canvasHeight,p=l.canvasWidth,f=function(t){var e=N.p,i=e.createDiv();i.parent(t),i.id("button-container");var n=e.createDiv();n.parent(i),n.id("small-button-container");var o=e.createDiv();o.parent(i),o.id("inner-button-container");var r=e.createDiv();r.parent(o),r.id("medium-button-container");var s=e.createDiv();s.parent(r),s.id("direction-vertical-container");var a=e.createDiv();a.parent(r),a.id("direction-horizontal-container");var u=e.createDiv();u.parent(o),u.id("large-button-container");var c=e.createDiv();return c.parent(o),c.id("trackpad-container"),{smallButtonContainer:n,mediumButtonContainer:r,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a,trackpadContainer:c}}(s),g=f.largeButtonContainer,_=f.smallButtonContainer,v=f.directionHorizontalContainer,m=f.directionVerticalContainer,b=f.mediumButtonContainer,E=f.trackpadContainer;return this._mediumButtonContainer=b,this._largeButtonContainer=g,this._trackpadContainer=E,this._onOffBtn=jt(_,"On<br/>Off",!0),this._startPauseBtn=jt(_,"Start<br/>Pause",!1),this._soundBtn=jt(_,"Sound",!0),this._resetBtn=jt(_,"Reset",!1),this._exitBtn=jt(_,"Exit",!0),this._enableColorBtn=jt(_,"Enable<br/>Colors",!1),this._trackpadBtn=jt(_,"Track<br/>Pad",!0),this._upBtn=Ut(m,"UP"),this._leftBtn=Ut(v,"LEFT"),this._downBtn=Ut(m,"DOWN"),this._rightBtn=Ut(v,"RIGHT"),this._actionBtn=function(t){var e=N.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}(g),function(t,e,i,n){var o=document.querySelector(":root");o.style.setProperty("--dispersion",y.viewLayout.shadowDispersion),o.style.setProperty("--width","".concat(t,"px")),o.style.setProperty("--height","".concat(e,"px")),o.style.setProperty("--canvas-width","".concat(i,"px")),o.style.setProperty("--canvas-height","".concat(n,"px")),o.style.setProperty("--border-radius","".concat(t*y.viewLayout.dimensions.borderRadiusRatio,"px")),o.style.setProperty("--border","".concat(t*y.viewLayout.dimensions.borderWidthRatio,"px solid black")),o.style.setProperty("--sm-button-size","".concat(t*y.viewLayout.dimensions.button.smSizeRatio,"px")),o.style.setProperty("--button-size","".concat(t*y.viewLayout.dimensions.button.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size","".concat(t*y.viewLayout.dimensions.button.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile","".concat(t*y.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),o.style.setProperty("--button-size-mobile","".concat(t*y.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size-mobile","".concat(t*y.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*y.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*y.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--button-size-mobile-font-size","".concat(t*y.viewLayout.dimensions.button.mobile.fontRatio,"px")),o.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*y.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),o.style.setProperty("--button-size-mobile-spacing","".concat(t*y.viewLayout.dimensions.button.mobile.spacingRatio,"px")),o.style.setProperty("--button-border","".concat(t*y.viewLayout.dimensions.button.borderRatio,"px solid black")),o.style.setProperty("--button-animation-duration",y.viewLayout.dimensions.button.animationDuration)}(u,a,p,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:p,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Yt,this._sessionModal.setup(),this._shortcutsModal=new Jt,this._shortcutsModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.toggleShortcutsModal=function(){this._shortcutsModal.toggle()},t.prototype.setupDebugger=function(t){this._debugger=new Wt(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 g(t),this._trackpad&&this._trackpad.destroy(),this._trackpad=new Qt(this._trackpadContainer,this._inputHandler),this._bindButtonEvents(this._onOffBtn,l.POWER),this._bindButtonEvents(this._startPauseBtn,l.START_PAUSE),this._bindButtonEvents(this._soundBtn,l.SOUND),this._bindButtonEvents(this._resetBtn,l.RESET),this._bindButtonEvents(this._exitBtn,l.EXIT),this._bindButtonEvents(this._enableColorBtn,l.COLOR),this._bindButtonEvents(this._trackpadBtn,l.TRACKPAD),this._bindButtonEvents(this._upBtn,l.UP),this._bindButtonEvents(this._downBtn,l.DOWN),this._bindButtonEvents(this._rightBtn,l.RIGHT),this._bindButtonEvents(this._leftBtn,l.LEFT),this._bindButtonEvents(this._actionBtn,l.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._trackpadBtn.mousePressed(function(){}).mouseReleased(function(){}),this._trackpad&&(this._trackpad.destroy(),this._trackpad=null),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=y.viewLayout.splashHideDelayMs);var e=document.querySelector("#splash");setTimeout(function(){e.style.display="none"},t)},t.prototype.applyTrackpadState=function(t){t?(this._mediumButtonContainer.style("display","none"),this._largeButtonContainer.style("display","none"),this._trackpadContainer.style("display","flex")):(this._mediumButtonContainer.style("display","flex"),this._largeButtonContainer.style("display","flex"),this._trackpadContainer.style("display","none"))},t}();const Zt=$t;var te,ee=n(991),ie=n.n(ee);function ne(t){te=t}function oe(t){return window.BrickEngineGame=t,new(ie())(function(e){N.init(e);var i=new Zt(document.body);ne(new t(i)),"unknown"===te.gameId&&(te.gameId="game"),e.setup=function(){te.setup(),te.view.setupDebugger(te.modules),te.view.setupSessionModal()},e.draw=function(){te.draw(),te.view.updateDebugger()}})}return f})());
@@ -104,16 +104,14 @@ declare const _default: {
104
104
  /** Button hold settings. */
105
105
  readonly buttonHold: {
106
106
  /** Initial delay before a held button starts repeating (in milliseconds). */
107
- readonly holdDelayMs: 250;
107
+ readonly holdDelayMs: 267;
108
108
  /** Interval between repeated actions while a button is held (in milliseconds). */
109
- readonly holdIntervalMs: 50;
109
+ readonly holdIntervalMs: 100;
110
110
  };
111
111
  /** Game settings. */
112
112
  readonly game: {
113
113
  /** Interval between game ticks (in milliseconds). */
114
114
  readonly tickInterval: number;
115
- /** Minimum interval between game ticks (in milliseconds). */
116
- readonly minTickInterval: number;
117
115
  /** Performance Monitor settings. */
118
116
  readonly debugger: {
119
117
  /** Enable performance overlay. */
@@ -3,11 +3,13 @@ import { Initializable } from './types/Interfaces';
3
3
  import { GameModules } from './types/Types';
4
4
  import p5 from 'p5';
5
5
  /**
6
- * The Central integration boundary encapsulating physical logic away from native visual outputs.
6
+ * The core engine orchestrator and central integration boundary.
7
7
  *
8
- * Implements the {@link Initializable} configuration pipeline orchestrating completely synchronous
9
- * frame drawing metrics while processing isolated state iterations without corrupting data models
10
- * dynamically mapped across various internal UI states.
8
+ * Designed to encapsulate physical game logic away from native visual outputs
9
+ * and hardware-specific events. It implements the {@link Initializable} contract
10
+ * to manage the lifecycle of all internal modules, ensuring that state
11
+ * iterations, physics updates, and rendering frames are synchronized
12
+ * and deterministic.
11
13
  */
12
14
  export default abstract class Game implements Initializable {
13
15
  protected _view: GameView;
@@ -52,17 +54,23 @@ export default abstract class Game implements Initializable {
52
54
  */
53
55
  get p(): p5;
54
56
  /**
55
- * Triggers sequential logic parsing across dynamically subscribed execution containers internally.
57
+ * Initializes the engine and its constituent modules.
56
58
  *
57
- * Internally synchronizes active memory payloads tracking initialization boundaries automatically.
59
+ * Orchestrates the setup of the internal module registry, links state
60
+ * synchronization, and prepares the event system. This method must
61
+ * be called once before starting the game loop.
58
62
  *
59
- * @returns {void} Returns nothing.
63
+ * @returns {void}
60
64
  */
61
65
  setup(): void;
62
66
  /**
63
- * Loops mathematically calculating pixel mutations exactly and logically evaluating system limits.
67
+ * The primary game loop executed on every visual frame.
64
68
  *
65
- * @returns {void} Returns nothing.
69
+ * Synchronizes the physical time delta with the logical time module.
70
+ * If the current state allows, it orchestrates the logical update
71
+ * ticks and the independent rendering pass.
72
+ *
73
+ * @returns {void}
66
74
  */
67
75
  draw(): void;
68
76
  /**
@@ -80,7 +88,6 @@ export default abstract class Game implements Initializable {
80
88
  /**
81
89
  * Subclass abstract delegator resolving physics mathematically based directly on relative speeds.
82
90
  *
83
- * @param {number} deltaTime - Fast ticking number representation capturing elapsed frametimes safely.
84
91
  * @returns {void} Returns nothing.
85
92
  */
86
93
  abstract update(deltaTime: number): void;
@@ -106,6 +106,27 @@ export default class GameScore implements Score, Debuggable, Serializable {
106
106
  * @param {number} value - The new high score.
107
107
  */
108
108
  set highScore(value: number);
109
+ /**
110
+ * Subscribes a callback to score changes.
111
+ *
112
+ * @param {function(number): void} callback - The function to execute when the score changes.
113
+ * @returns {void} Returns nothing.
114
+ */
115
+ subscribe(callback: (score: number) => void): void;
116
+ /**
117
+ * Unsubscribes a callback from score changes.
118
+ *
119
+ * @param {function(number): void} callback - The callback reference to remove.
120
+ * @returns {void} Returns nothing.
121
+ */
122
+ unsubscribe(callback: (score: number) => void): void;
123
+ /**
124
+ * Notifies all subscribers of a property change via the {@link EventEmitter}.
125
+ *
126
+ * @param {ScoreProperty} property - The property enum string that dictates the notification channel.
127
+ * @returns {void} Returns nothing.
128
+ */
129
+ private _notify;
109
130
  /**
110
131
  * Retrieves debug information about the score status.
111
132
  *
@@ -2,18 +2,21 @@ import { Debuggable } from '../../types/Interfaces';
2
2
  import { Time } from '../../types/modules';
3
3
  import { Serializable } from '../../types/Interfaces';
4
4
  /**
5
- * Module responsible for managing the logical engine clock, hardware frame rates, and tick intervals.
5
+ * Orchestrates the engine's logical clock and performance metrics.
6
6
  *
7
- * It decouples the deterministic game logic "ticks" from the unpredictable visual frame rate
8
- * of the browser canvas. By separating `update` loops from visual rendering, it ensures
9
- * consistent gameplay speed calculations (like difficulty progression) regardless of the
10
- * host device's performance capabilities.
7
+ * Designed to decouple deterministic game logic "ticks" from the unpredictable
8
+ * visual frame rate of the browser. By maintaining an internal time accumulator,
9
+ * it ensures that gameplay events (like physics, timers, and difficulty scaling)
10
+ * execute at a consistent speed regardless of the host device's hardware
11
+ * performance or FPS fluctuations.
12
+ *
13
+ * Implements the {@link Time} interface to provide a standardized timing
14
+ * contract for all engine modules.
11
15
  */
12
16
  export default class GameTime implements Time, Debuggable, Serializable {
13
17
  protected _tickAccumulator: number;
14
18
  /** The tick interval at the start of the game session. Used for resets. */
15
19
  private _initialTickInterval;
16
- private _minTickInterval;
17
20
  private _tickInterval;
18
21
  private _fps;
19
22
  private _tps;
@@ -22,26 +25,58 @@ export default class GameTime implements Time, Debuggable, Serializable {
22
25
  private _timeSinceLastTpsUpdate;
23
26
  private _totalElapsedTime;
24
27
  serialId: string;
28
+ /**
29
+ * Gets the total number of ticks since the game started.
30
+ *
31
+ * @returns {number} Total tick count.
32
+ */
33
+ get totalTicks(): number;
34
+ /**
35
+ * Gets the total elapsed time in milliseconds.
36
+ *
37
+ * @returns {number} Elapsed time in ms.
38
+ */
39
+ get elapsedTime(): number;
25
40
  /**
26
41
  * Initializes the time module's core state.
27
- * Resets all internal timers and statistical accumulators securely.
28
42
  *
29
- * @returns {void} Returns nothing.
43
+ * Resets all internal timers and statistical accumulators to their
44
+ * baseline values, ensuring a clean state for a new game session.
45
+ *
46
+ * @returns {void}
30
47
  */
31
48
  setup(): void;
32
49
  /**
33
- * Updates the internal time accumulator and calculates physical FPS/TPS.
34
- * Must be invoked strictly once per hardware visual frame.
50
+ * Updates the physical performance metrics.
35
51
  *
36
- * @param {number} deltaTime - Time physically elapsed since the last rendering frame in milliseconds.
37
- * @returns {void} Returns nothing.
52
+ * Calculates the current Frames Per Second (FPS) and updates the Ticks
53
+ * Per Second (TPS) statistics. This method should be called exactly
54
+ * once per visual frame in the main loop.
55
+ *
56
+ * @param {number} deltaTime - The physical time physically elapsed since the last rendering frame in milliseconds.
57
+ * @returns {void}
38
58
  */
39
59
  update(deltaTime: number): void;
40
60
  /**
41
- * Checks if enough time has passed for a game tick.
42
- * Consumes accumulated time if a tick occurs.
61
+ * Adds elapsed time to the simulation accumulator.
62
+ *
63
+ * This time is used to determine when the next logical tick should
64
+ * be processed. It allows the engine to "catch up" if the frame
65
+ * rate drops below the target tick rate.
66
+ *
67
+ * @param {number} deltaTime - Time in milliseconds to add to the logic simulation.
68
+ * @returns {void}
69
+ */
70
+ accumulate(deltaTime: number): void;
71
+ /**
72
+ * Evaluates if the engine should execute a logical simulation tick.
43
73
  *
44
- * @returns {boolean} True if a tick should occur.
74
+ * Checks if the accumulated time exceeds the required tick interval.
75
+ * If so, it consumes all pending time in the accumulator and
76
+ * increments the logical counters.
77
+ *
78
+ * @internal Used specifically by the engine's core orchestration loop.
79
+ * @returns {boolean} `true` if at least one tick's worth of time was consumed.
45
80
  */
46
81
  shouldTick(): boolean;
47
82
  /**
@@ -51,30 +86,24 @@ export default class GameTime implements Time, Debuggable, Serializable {
51
86
  */
52
87
  reset(): void;
53
88
  /**
54
- * Gets the current tick interval.
89
+ * Checks if enough logical time has passed based on a specific millisecond interval.
90
+ * Use for time-based triggers that need to be stable even if the frame rate varies.
55
91
  *
56
- * @returns {number} The tick interval in milliseconds.
92
+ * @param {number} ms - The millisecond interval to check.
93
+ * @returns {boolean} True if the logical clock just crossed a multiple of the interval.
57
94
  */
58
- get tickInterval(): number;
95
+ atInterval(ms: number): boolean;
59
96
  /**
60
- * Sets the tick interval and resets timing.
97
+ * Executes a callback function every N milliseconds of logical game time.
61
98
  *
62
- * @param {number} interval - The new tick interval in milliseconds.
63
- */
64
- set tickInterval(interval: number);
65
- /**
66
- * Increments the tick interval (slowing down the game).
99
+ * Provides a declarative functional approach to handling recurring game logic,
100
+ * such as spawning enemies or updating timers.
67
101
  *
68
- * @param {number} amount - The amount to add to the interval.
102
+ * @param {number} ms - The millisecond interval between executions.
103
+ * @param {() => void} action - The callback function to execute if the interval is crossed.
104
+ * @returns {void}
69
105
  */
70
- incrementTickInterval(amount: number): void;
71
- /**
72
- * Decrements the tick interval (speeding up the game).
73
- * Enforces a minimum interval of 10ms.
74
- *
75
- * @param {number} amount - The amount to subtract from the interval.
76
- */
77
- decrementTickInterval(amount: number): void;
106
+ every(ms: number, action: () => void): void;
78
107
  /**
79
108
  * Retrieves debug information about the time system.
80
109
  *
@@ -83,34 +112,4 @@ export default class GameTime implements Time, Debuggable, Serializable {
83
112
  getDebugData(): Record<string, string | number | boolean>;
84
113
  serialize(): string;
85
114
  deserialize(data: string): void;
86
- setTickInterval(interval: number): void;
87
- setMinTickInterval(interval: number): void;
88
- /**
89
- * Gets the total number of ticks since the game started.
90
- *
91
- * @returns {number} Total tick count.
92
- */
93
- get totalTicks(): number;
94
- /**
95
- * Gets the total elapsed time in milliseconds.
96
- *
97
- * @returns {number} Elapsed time in ms.
98
- */
99
- get elapsedTime(): number;
100
- /**
101
- * Checks if the current total tick count is a multiple of the provided interval.
102
- *
103
- * @param {number} interval - The tick interval to check.
104
- * @returns {boolean} True if the current tick is a multiple of the interval.
105
- */
106
- isTickEvery(interval: number): boolean;
107
- /**
108
- * Captures the current tick interval as the deterministic initial baseline state.
109
- *
110
- * This is useful for restoring the intended baseline game speed on session
111
- * resets rather than reverting to the engine's hardcoded default.
112
- *
113
- * @returns {void} Returns nothing.
114
- */
115
- captureInitialState(): void;
116
115
  }
@@ -116,3 +116,14 @@ export declare enum StateProperty {
116
116
  MUTED = "muted",
117
117
  TRACKPAD = "trackpadEnabled"
118
118
  }
119
+ /**
120
+ * Enumerates all observable score and progression properties.
121
+ * These keys are used for score subscriptions.
122
+ */
123
+ export declare enum ScoreProperty {
124
+ SCORE = "score",
125
+ LEVEL = "level",
126
+ MULTIPLIER = "multiplier",
127
+ MAX_LEVEL = "maxLevel",
128
+ HIGH_SCORE = "highScore"
129
+ }
@@ -583,58 +583,66 @@ export interface State extends Initializable {
583
583
  */
584
584
  unsubscribe(property: StateProperty, callback: (value: boolean | number) => void): void;
585
585
  /**
586
- * Registers a callback for a specific state change ONLY during the title screen.
586
+ * Subscribes to changes in a specific state property only when in the Title Screen.
587
+ *
587
588
  * @param {StateProperty} property - The state property to monitor.
588
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
589
+ * @param {function(boolean | number): void} callback - The function to execute.
589
590
  * @returns {void} Returns nothing.
590
591
  */
591
592
  subscribeForTitleScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
592
593
  /**
593
- * Removes an existing title screen subscription.
594
- * @param {StateProperty} property - The state property to monitor.
595
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
594
+ * Unsubscribes a callback from Title Screen scoped notifications.
595
+ *
596
+ * @param {StateProperty} property - The state property being monitored.
597
+ * @param {function(boolean | number): void} callback - The callback to remove.
596
598
  * @returns {void} Returns nothing.
597
599
  */
598
600
  unsubscribeForTitleScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
599
601
  /**
600
- * Registers a callback for a specific state change ONLY during the game over screen.
602
+ * Subscribes to changes in a specific state property only when in the Game Over screen.
603
+ *
601
604
  * @param {StateProperty} property - The state property to monitor.
602
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
605
+ * @param {function(boolean | number): void} callback - The function to execute.
603
606
  * @returns {void} Returns nothing.
604
607
  */
605
608
  subscribeForGameOverScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
606
609
  /**
607
- * Removes an existing game over screen subscription.
608
- * @param {StateProperty} property - The state property to monitor.
609
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
610
+ * Unsubscribes a callback from Game Over scoped notifications.
611
+ *
612
+ * @param {StateProperty} property - The state property being monitored.
613
+ * @param {function(boolean | number): void} callback - The callback to remove.
610
614
  * @returns {void} Returns nothing.
611
615
  */
612
616
  unsubscribeForGameOverScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
613
617
  /**
614
- * Registers a callback for a specific state change ONLY during active gameplay.
618
+ * Subscribes to changes in a specific state property only during active Gameplay.
619
+ *
615
620
  * @param {StateProperty} property - The state property to monitor.
616
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
621
+ * @param {function(boolean | number): void} callback - The function to execute.
617
622
  * @returns {void} Returns nothing.
618
623
  */
619
624
  subscribeForPlayingScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
620
625
  /**
621
- * Removes an existing playing screen subscription.
622
- * @param {StateProperty} property - The state property to monitor.
623
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
626
+ * Unsubscribes a callback from Playing scoped notifications.
627
+ *
628
+ * @param {StateProperty} property - The state property being monitored.
629
+ * @param {function(boolean | number): void} callback - The callback to remove.
624
630
  * @returns {void} Returns nothing.
625
631
  */
626
632
  unsubscribeForPlayingScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
627
633
  /**
628
- * Registers a callback for a specific state change ONLY during the paused screen.
634
+ * Subscribes to changes in a specific state property only when the game is Paused.
635
+ *
629
636
  * @param {StateProperty} property - The state property to monitor.
630
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
637
+ * @param {function(boolean | number): void} callback - The function to execute.
631
638
  * @returns {void} Returns nothing.
632
639
  */
633
640
  subscribeForPausedScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
634
641
  /**
635
- * Removes an existing paused screen subscription.
636
- * @param {StateProperty} property - The state property to monitor.
637
- * @param {function(boolean | number): void} callback - The function to execute when the property changes.
642
+ * Unsubscribes a callback from Paused scoped notifications.
643
+ *
644
+ * @param {StateProperty} property - The state property being monitored.
645
+ * @param {function(boolean | number): void} callback - The callback to remove.
638
646
  * @returns {void} Returns nothing.
639
647
  */
640
648
  unsubscribeForPausedScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
@@ -814,73 +822,61 @@ export interface Control extends Initializable {
814
822
  * Manages the game loop timing, ticks, and delta time.
815
823
  */
816
824
  export interface Time extends Initializable {
817
- /** The interval between logic ticks in milliseconds. */
818
- tickInterval: number;
819
825
  /** The total number of ticks since the game started. */
820
826
  readonly totalTicks: number;
821
827
  /** Total elapsed time in milliseconds since the game started. */
822
828
  readonly elapsedTime: number;
823
829
  /**
824
- * Checks if enough time has passed for a game tick based on a specific interval.
830
+ * Checks if enough time has passed based on a specific millisecond interval.
825
831
  *
826
- * @param {number} interval - The tick interval to check.
827
- * @returns {boolean} `true` if the current tick is a multiple of the interval.
832
+ * @param {number} ms - The millisecond interval to check.
833
+ * @returns {boolean} `true` if the logical clock just crossed a multiple of the interval.
828
834
  */
829
- isTickEvery(interval: number): boolean;
835
+ atInterval(ms: number): boolean;
830
836
  /**
831
- * Accumulates passed time and calculates FPS/TPS.
837
+ * Executes a callback function every N milliseconds of logical game time.
832
838
  *
833
- * @param {number} deltaTime - Time elapsed since last frame in milliseconds.
834
- * @returns {void} Returns nothing.
835
- */
836
- update(deltaTime: number): void;
837
- /**
838
- * Determines if a logic tick should occur based on the accumulator.
839
+ * Provides a declarative functional approach to handling recurring game logic,
840
+ * such as spawning enemies or updating timers.
839
841
  *
840
- * @returns {boolean} `true` if a tick is due.
842
+ * @param {number} ms - The millisecond interval between executions.
843
+ * @param {() => void} action - The callback function to execute if the interval is crossed.
844
+ * @returns {void}
841
845
  */
842
- shouldTick(): boolean;
846
+ every(ms: number, action: () => void): void;
843
847
  /**
844
- * Resets internal time accumulators and counters.
848
+ * Updates the system clock, total elapsed time, and performance metrics (FPS/TPS).
845
849
  *
846
- * @returns {void} Returns nothing.
847
- */
848
- reset(): void;
849
- /**
850
- * Increases the tick interval (slowing down the game logic).
850
+ * Should be invoked strictly once per hardware visual frame, even when the
851
+ * game is paused, to maintain accurate UI animations and performance tracking.
851
852
  *
852
- * @param {number} amount - Milliseconds to add.
853
+ * @param {number} deltaTime - Time elapsed since last frame in milliseconds.
853
854
  * @returns {void} Returns nothing.
854
855
  */
855
- incrementTickInterval(amount: number): void;
856
+ update(deltaTime: number): void;
856
857
  /**
857
- * Decreases the tick interval (speeding up the game logic).
858
+ * Accumulates time specifically for the logical engine ticks.
858
859
  *
859
- * @param {number} amount - Milliseconds to subtract.
860
- * @returns {void} Returns nothing.
861
- */
862
- decrementTickInterval(amount: number): void;
863
- /**
864
- * Sets the tick interval.
860
+ * This should only be invoked when the game logic is active (not paused
861
+ * or on title screens) to prevent the logic from "catching up" after
862
+ * periods of inactivity.
865
863
  *
866
- * @param {number} interval - The new tick interval in milliseconds.
864
+ * @param {number} deltaTime - Time to add to the logic accumulator.
867
865
  * @returns {void} Returns nothing.
868
866
  */
869
- setTickInterval(interval: number): void;
867
+ accumulate(deltaTime: number): void;
870
868
  /**
871
- * Sets the minimum tick interval.
869
+ * Determines if a logic tick should occur based on the accumulator.
872
870
  *
873
- * @param {number} interval - The new minimum tick interval in milliseconds.
874
- * @returns {void} Returns nothing.
871
+ * @returns {boolean} `true` if a tick is due.
875
872
  */
876
- setMinTickInterval(interval: number): void;
873
+ shouldTick(): boolean;
877
874
  /**
878
- * Captures the current tick interval as the initial state.
879
- * Use this after games have set their starting speed.
875
+ * Resets internal time accumulators and counters.
880
876
  *
881
877
  * @returns {void} Returns nothing.
882
878
  */
883
- captureInitialState(): void;
879
+ reset(): void;
884
880
  }
885
881
  /**
886
882
  * Interface for the audio module.
@@ -993,6 +989,18 @@ export interface Score {
993
989
  * @returns {void} Returns nothing.
994
990
  */
995
991
  setupGameHighScore(id: string): void;
992
+ /**
993
+ * Subscribes a callback to score changes.
994
+ * @param {function} callback - The callback function.
995
+ * @returns {void} Returns nothing.
996
+ */
997
+ subscribe(callback: (score: number) => void): void;
998
+ /**
999
+ * Unsubscribes a callback from score changes.
1000
+ * @param {function} callback - The callback function.
1001
+ * @returns {void} Returns nothing.
1002
+ */
1003
+ unsubscribe(callback: (score: number) => void): void;
996
1004
  }
997
1005
  export interface Session extends StateSyncable, Debuggable {
998
1006
  gameId: string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-engine-js",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "A lightweight brick engine built with p5.js and TypeScript",
5
5
  "type": "commonjs",
6
6
  "main": "dist/brick-engine.js",