brick-engine-js 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/game.bundle.js
CHANGED
|
@@ -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 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={};n.r(d),n.d(d,{Color:()=>o,ControlEventType:()=>l,ControlKey:()=>c,EventEmitter:()=>m,FontAlign:()=>r,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>pt,GameView:()=>Kt,RendererContext:()=>k,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>$t,configs:()=>p,setActiveGame:()=>Qt}),function(t){t.DEFAULT="rgb(19, 26, 18)",t.BLUE="rgb(0, 0, 128)",t.CYAN="rgb(0, 128, 128)",t.GRAY="rgb(128, 128, 128)",t.GREEN="rgb(0, 128, 0)",t.PURPLE="rgb(128, 0, 128)",t.RED="rgb(128, 0, 0)",t.YELLOW="rgb(128, 128, 0)",t.INACTIVE="rgb(166, 183, 165)"}(o||(o={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(r||(r={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const p={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},p.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},p.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var v;!function(t){t.TITLE="title",t.PLAYING="playing",t.GAMEOVER="gameover",t.PAUSED="paused"}(v||(v={}));const m=function(){function t(){}return t.subscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]||(this._events[n]=[]),this._events[n].push(e)},t.unsubscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]&&(this._events[n]=this._events[n].filter(function(t){return t!==e}))},t.notify=function(t,e){this._events[t]&&this._events[t].forEach(function(t){return t(e)})},t.notifyContextual=function(t,e,i){this.notify(t,e),i.isPlaying()?this.notify(this._formatName(t,v.PLAYING),e):i.isPaused()?this.notify(this._formatName(t,v.PAUSED),e):i.isOn()&&!i.isStarted()?this.notify(this._formatName(t,v.TITLE),e):i.isGameOver()&&this.notify(this._formatName(t,v.GAMEOVER),e)},t._formatName=function(t,e){return e?"".concat(t,":").concat(e):t},t.clear=function(){this._events={}},t._events={},t}();var _=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._activeListeners.forEach(function(t){var e=t.event,i=t.callback;m.unsubscribe(e,i)}),this._activeListeners=[]},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribe(t,e,i)},t.prototype.unsubscribe=function(t,e,i){this._unsubscribe(t,e,i)},t.prototype.subscribeForTitleScreen=function(t,e,i){this._subscribe(t,e,i,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e,i){this._unsubscribe(t,e,i,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e,i){this._subscribe(t,e,i,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e,i){this._unsubscribe(t,e,i,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e,i){this._subscribe(t,e,i,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e,i){this._subscribe(t,e,i,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PAUSED)},t.prototype._subscribe=function(t,e,i,n){var o="".concat(t,":").concat(e);m.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);m.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=t===c.POWER:!n.isStarted()||n.isPlaying()||n.isGameOver()?r=!0:n.isPaused()&&(r=t.endsWith(";system")),r&&m.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const b=_,E=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:o.DEFAULT,coordinate:t}},t}();var S=function(){return S=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},S.apply(this,arguments)},w=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return S(S({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),o=n.some(function(e){return!i.grid.isValidCoordinate(e.coordinate)||i.grid.isCellActive(e.coordinate)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}));var n});return o?null:n},t.prototype.movePieceLeft=function(t){return this.movePiece(t,{x:-1,y:0})},t.prototype.movePieceRight=function(t){return this.movePiece(t,{x:1,y:0})},t.prototype.movePieceUp=function(t){return this.movePiece(t,{x:0,y:-1})},t.prototype.movePieceDown=function(t){return this.movePiece(t,{x:0,y:1})},t.prototype.moveCell=function(t,e){var i={x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)};return!this.grid.isValidCoordinate(i)||this.grid.isCellActive(i)?null:S(S({},t),{coordinate:i})},t.prototype.moveCellLeft=function(t){return this.moveCell(t,{x:-1,y:0})},t.prototype.moveCellRight=function(t){return this.moveCell(t,{x:1,y:0})},t.prototype.moveCellUp=function(t){return this.moveCell(t,{x:0,y:-1})},t.prototype.moveCellDown=function(t){return this.moveCell(t,{x:0,y:1})},t.prototype.getDropPath=function(t){for(var e=t,i=this.movePieceDown(e);null!==i;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);null!==i;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);null!==i;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);null!==i;)e=i,i=this.movePieceRight(e);return e},t}();const R=w;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)},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 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 P(P({},t),{coordinate:{x:e.x+r,y:e.y+s}})}),r=o.some(function(e){return!n.grid.isValidCoordinate(e.coordinate)||n.grid.isCellActive(e.coordinate)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}));var i});return r?null: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 P(P({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const C=x;var O=function(){return O=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},O.apply(this,arguments)},T=function(){function t(t){this.grid=t}return t.prototype.getFullRows=function(){for(var t=[],e=0;e<this.grid.height;e++){for(var i=!0,n=0;n<this.grid.width;n++)if(!this.grid.isCellActive({x:n,y:e})){i=!1;break}i&&t.push(e)}return t},t.prototype.getFullColumns=function(){for(var t=[],e=0;e<this.grid.width;e++){for(var i=!0,n=0;n<this.grid.height;n++)if(!this.grid.isCellActive({x:e,y:n})){i=!1;break}i&&t.push(e)}return t},t.prototype.getNeighbors=function(t,e){var i=this;void 0===e&&(e=!1);var n=[],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};i.grid.isValidCoordinate(o)&&n.push(i.grid.getCell(o))}),n},t.prototype.findConnectedCells=function(t){var e=this;if(!this.grid.isCellActive(t))return[];var i=this.grid.getCell(t).value,n=[],o=new Set,r=[t],s=function(t){return"".concat(t.x,",").concat(t.y)};for(o.add(s(t));r.length>0;){var a=r.shift(),u=this.grid.getCell(a);u.value===i&&(n.push(u),[{x:a.x-1,y:a.y},{x:a.x+1,y:a.y},{x:a.x,y:a.y-1},{x:a.x,y:a.y+1}].forEach(function(t){var i=s(t);e.grid.isValidCoordinate(t)&&!o.has(i)&&e.grid.isCellActive(t)&&(o.add(i),r.push(t))}))}return n},t.prototype.swapCells=function(t,e){var i=O({},this.grid.getCell(t)),n=O({},this.grid.getCell(e));this.grid.stampCell(O(O({},n),{coordinate:t})),this.grid.stampCell(O(O({},i),{coordinate:e}))},t}();const A=T;var L=function(){function t(t){this.grid=t}return t.prototype.isRowFull=function(t){var e=this.grid.getGrid();return!(t<0||t>=this.grid.height)&&e[t].every(function(t){return t.value>0})},t.prototype.isRowEmpty=function(t){var e=this.grid.getGrid();return t<0||t>=this.grid.height||e[t].every(function(t){return 0===t.value})},t.prototype.clearRow=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.height))for(var i=0;i<this.grid.width;i++)e[t][i]=E.emptyCell({x:i,y:t})},t.prototype.shiftRowsDown=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.width;n++){var 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]=E.emptyCell({x:t,y:i})},t.prototype.shiftColumnsRight=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.height;n++){var 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 M=L;var I=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){return!e.grid.isValidCoordinate(t)||e.grid.isCellActive(t)})},t.prototype.fillArea=function(t,e,i,n){for(var 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 D=I;var G=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new R(this),this._transformEngine=new C(this),this._analysisEngine=new A(this),this._lineEngine=new M(this),this._regionEngine=new D(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return p.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return p.screenLayout.grid.rows},enumerable:!1,configurable:!0}),t.prototype.setup=function(){this.resetGrid()},t.prototype.resetGrid=function(){this._grid=[];for(var t=0;t<this.height;t++){this._grid[t]=[];for(var e=0;e<this.width;e++)this._grid[t][e]=E.emptyCell({x:e,y:t})}},t.prototype.forEach=function(t){for(var e=0;e<this.height;e++)for(var i=0;i<this.width;i++)t(this._grid[e][i])},t.prototype.isValidCoordinate=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isValidCoordinate(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isValidCoordinate(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){var e=this.getCell(t);return null!==e&&e.value>0},t.prototype.isCellInactive=function(t){var e=this.getCell(t);return null!==e&&0===e.value},t.prototype.isRowFull=function(t){return this._lineEngine.isRowFull(t)},t.prototype.isRowEmpty=function(t){return this._lineEngine.isRowEmpty(t)},t.prototype.clearRow=function(t){this._lineEngine.clearRow(t)},t.prototype.shiftRowsDown=function(t){this._lineEngine.shiftRowsDown(t)},t.prototype.shiftRowsUp=function(t){this._lineEngine.shiftRowsUp(t)},t.prototype.clearFullRows=function(){return this._lineEngine.clearFullRows()},t.prototype.isColumnFull=function(t){return this._lineEngine.isColumnFull(t)},t.prototype.isColumnEmpty=function(t){return this._lineEngine.isColumnEmpty(t)},t.prototype.clearColumn=function(t){this._lineEngine.clearColumn(t)},t.prototype.shiftColumnsRight=function(t){this._lineEngine.shiftColumnsRight(t)},t.prototype.shiftColumnsLeft=function(t){this._lineEngine.shiftColumnsLeft(t)},t.prototype.clearFullColumns=function(){return this._lineEngine.clearFullColumns()},t.prototype.isAreaOccupied=function(t){return this._regionEngine.isAreaOccupied(t)},t.prototype.fillArea=function(t,e,i,n){this._regionEngine.fillArea(t,e,i,n)},t.prototype.stampPiece=function(t){this._regionEngine.stampPiece(t)},t.prototype.stampCell=function(t){this._regionEngine.stampCell(t)},t.prototype.movePiece=function(t,e){return this._movementEngine.movePiece(t,e)},t.prototype.movePieceLeft=function(t){return this._movementEngine.movePieceLeft(t)},t.prototype.movePieceRight=function(t){return this._movementEngine.movePieceRight(t)},t.prototype.movePieceUp=function(t){return this._movementEngine.movePieceUp(t)},t.prototype.movePieceDown=function(t){return this._movementEngine.movePieceDown(t)},t.prototype.moveCell=function(t,e){return this._movementEngine.moveCell(t,e)},t.prototype.moveCellLeft=function(t){return this._movementEngine.moveCellLeft(t)},t.prototype.moveCellRight=function(t){return this._movementEngine.moveCellRight(t)},t.prototype.moveCellUp=function(t){return this._movementEngine.moveCellUp(t)},t.prototype.moveCellDown=function(t){return this._movementEngine.moveCellDown(t)},t.prototype.rotatePiece=function(t,e,i){return void 0===i&&(i=!0),this._transformEngine.rotatePiece(t,e,i)},t.prototype.getFullRows=function(){return this._analysisEngine.getFullRows()},t.prototype.getFullColumns=function(){return this._analysisEngine.getFullColumns()},t.prototype.getDropPath=function(t){return this._movementEngine.getDropPath(t)},t.prototype.getRisePath=function(t){return this._movementEngine.getRisePath(t)},t.prototype.getReachPathLeft=function(t){return this._movementEngine.getReachPathLeft(t)},t.prototype.getReachPathRight=function(t){return this._movementEngine.getReachPathRight(t)},t.prototype.getNeighbors=function(t,e){return void 0===e&&(e=!1),this._analysisEngine.getNeighbors(t,e)},t.prototype.findConnectedCells=function(t){return this._analysisEngine.findConnectedCells(t)},t.prototype.mirrorPiece=function(t,e){return this._transformEngine.mirrorPiece(t,e)},t.prototype.swapCells=function(t,e){this._analysisEngine.swapCells(t,e)},t.prototype.getPieceBounds=function(t){return this._transformEngine.getPieceBounds(t)},t.prototype.getDebugData=function(){return{width:this.width,height:this.height,activeCells:this._grid.flat().filter(function(t){return t.value>0}).length}},t.prototype.serialize=function(){return console.log("serialize"),JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){console.log("deserialize");var e=JSON.parse(t);this._grid=e.grid},t}();const B=G,k=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*k.p.width},t.getRelativeHeight=function(t){return t*k.p.height},t}();var z=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=p.screenLayout.cell,i=e.margin,n=e.padding,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=k.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=k.p,e=p.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(p.colors.background),this._staticGraphics.strokeWeight(N.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(p.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,r=t.value,s=k.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.DEFAULT,s.push(),s.translate(this._rendererMetrics.display.origin.x+a*this._rendererMetrics.cell.size,this._rendererMetrics.display.origin.y+u*this._rendererMetrics.cell.size),s.strokeWeight(f),s.stroke(n),s.noFill(),s.rect(l,l,h,h),s.fill(n),s.rect(d,d,p,p),s.pop()},t.prototype.renderGrid=function(t,e){var i=this;t.forEach(function(t){t.forEach(function(t){i.renderCell(t,e)})})},t}();const F=z;var H=function(){function t(){}return t.getRelativeCoordinate=function(t){return{x:N.getRelativeWidth(t.x),y:N.getRelativeHeight(t.y)}},t.getDisplayPosX=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=k.p,n=p.screenLayout.display.margin,o=N.getRelativeWidth(n),r=e+2*o;return(i.width-r-o)*t+r},t.getHudPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t}();const U=H;var j=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:U.getHudPosX(.078,t.display.width),y:U.getHudPosY(.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-N.getRelativeWidth(.005),y:this._gridOrigin.y-N.getRelativeHeight(.005),w:4*this._cellSize+N.getRelativeWidth(.01),h:4*this._cellSize+N.getRelativeHeight(.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=k.p,i=t.text,n=t.state,o=t.score;e.push(),i.setTextSize(s.SMALL),i.setInactiveText(),i.setTextAlign(r.LEFT,a.BOTTOM),i.textOnHud("88888888",{x:.05,y:.13}),i.textOnHud("88888888",{x:.05,y:.3}),i.textOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.textOnHud("Score",{x:.05,y:.06}),i.textOnHud(o.score.toString(),{x:.05,y:.13}),i.textOnHud("Hi-Score",{x:.05,y:.23}),i.textOnHud(o.highScore.toString(),{x:.05,y:.3}),i.textOnHud("Level",{x:.05,y:.72});var u="".concat(o.level<10?"0"+o.level:o.level," - ").concat(o.maxLevel);i.textOnHud(u,{x:.05,y:.8}),i.setTextAlign(r.CENTER,a.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.textOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.textOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=k.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=k.p,s=p.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,f=s.strokeWeight*e;r.push(),r.translate(i,n),r.strokeWeight(f),r.stroke(o),r.noFill(),r.rect(c,c,l,l),r.fill(o),r.rect(h,h,d,d),r.pop()},t}();const V=j;var W=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new F,this._hudRenderer=new V,this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=p.screenLayout.display,e=t.width,i=t.height,n=t.margin,o=p.screenLayout.grid.columns,r=N.getRelativeWidth(e),s=N.getRelativeHeight(i),a=U.getRelativeCoordinate({x:n,y:n}),u=r/o,c={x:U.getHudPosX(0,r),y:U.getHudPosY(0,s)},l=U.getHudPosX(1,r)-c.x,h=U.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 Y=W;var K,X=((K={})[h.ON]={defaultValue:!1},K[h.START]={defaultValue:!1},K[h.PLAYING]={defaultValue:!1},K[h.GAME_OVER]={defaultValue:!1},K[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},K[h.MUTED]={defaultValue:!1,storageKey:"muted"},K);const J=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];if(i.storageKey){var n=localStorage.getItem(i.storageKey);null!==n&&t._state.set(e,JSON.parse(n))}})},t.prototype._set=function(t,e){if(this._state.get(t)!==e){this._state.set(t,e);var i=X[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this.notify(t)}},t.prototype.notify=function(t){var e=this._state.get(t);m.notifyContextual(t,e,this)},t.prototype.isOn=function(){return this._state.get(h.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(h.START)},t.prototype.isPlaying=function(){return this._state.get(h.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(h.GAME_OVER)},t.prototype.turnOn=function(){this._set(h.ON,!0),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(h.ON,!1),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(h.START,!0),this._set(h.PLAYING,!0),this._set(h.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0)},t.prototype.exitGame=function(){this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(h.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(h.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(h.MUTED)},t.prototype.setMuted=function(t){this._set(h.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.subscribe=function(t,e){this._subscribe(t,e)},t.prototype.unsubscribe=function(t,e){this._unsubscribe(t,e)},t.prototype.subscribeForTitleScreen=function(t,e){this._subscribe(t,e,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e){this._unsubscribe(t,e,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e){this._subscribe(t,e,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e){this._unsubscribe(t,e,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e){this._subscribe(t,e,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e){this._unsubscribe(t,e,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e){this._subscribe(t,e,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e){this._unsubscribe(t,e,v.PAUSED)},t.prototype._subscribe=function(t,e,i){m.subscribe(t,e,i)},t.prototype._unsubscribe=function(t,e,i){m.unsubscribe(t,e,i)},t.prototype.getDebugData=function(){return{on:this.isOn(),start:this.isStarted(),playing:this.isPlaying(),paused:this.isPaused(),game_over:this.isGameOver(),color_enabled:this.isColorEnabled(),muted:this.isMuted()}},t}();var q=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=k.p,e=p.screenLayout.fontSize,i=e.extraSmall,n=e.small,o=e.medium,r=e.large,a=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=N.getRelativeWidth(i),this.fontSizes[s.SMALL]=N.getRelativeWidth(n),this.fontSizes[s.MEDIUM]=N.getRelativeWidth(o),this.fontSizes[s.LARGE]=N.getRelativeWidth(r),this.fontSizes[s.EXTRA_LARGE]=N.getRelativeWidth(a)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=k.p,i=p.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.setTextSize=function(t){k.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){k.p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=k.p,n=U.getHudPosX(e.x,this._rendererMetrics.display.width),o=U.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.textOnDisplay=function(t,e){var i=k.p,n=U.getDisplayPosX(e.x,this._rendererMetrics.display.width),o=U.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const Q=q,$=function(){function t(){this._accumulatedTime=0,this._initialTickInterval=p.game.tickInterval,this._minTickInterval=p.game.minTickInterval,this._tickInterval=p.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._accumulatedTime+=t,this._fps=1e3/t,this._timeSinceLastTpsUpdate+=t,this._timeSinceLastTpsUpdate>=1e3&&(this._tps=this._tickCounter,this._tickCounter=0,this._timeSinceLastTpsUpdate-=1e3)},t.prototype.shouldTick=function(){return this._accumulatedTime>=this._tickInterval&&(this._accumulatedTime-=this._tickInterval,this._tickCounter++,!0)},t.prototype.reset=function(){this._accumulatedTime=0,this._fps=0,this._tps=0,this._tickCounter=0,this._timeSinceLastTpsUpdate=0,this._tickInterval=this._initialTickInterval},Object.defineProperty(t.prototype,"tickInterval",{get:function(){return this._tickInterval},set:function(t){this._tickInterval=t},enumerable:!1,configurable:!0}),t.prototype.incrementTickInterval=function(t){this.tickInterval=this._tickInterval+t},t.prototype.decrementTickInterval=function(t){var e=Math.max(this._minTickInterval,this._tickInterval-t);this.tickInterval=e},t.prototype.getDebugData=function(){return{fps:Math.round(this._fps),tps:this._tps,tick_interval:this._tickInterval.toFixed(2),accumulated_time:this._accumulatedTime.toFixed(2)}},t.prototype.serialize=function(){return JSON.stringify({tickInterval:this._tickInterval})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._tickInterval=e.tickInterval},t.prototype.setTickInterval=function(t){this._tickInterval=t},t.prototype.setMinTickInterval=function(t){this._minTickInterval=t},t}();var Z=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())})},tt=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])}}},et=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=p.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return Z(this,void 0,void 0,function(){var e,i,n;return tt(this,function(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 Z(this,void 0,void 0,function(){var e;return tt(this,function(i){return(e=this._activeSources.get(t))&&(e.forEach(function(t){try{t.stop()}catch(t){}}),e.length=0),[2]})})},t.prototype.stopAll=function(){return Z(this,void 0,void 0,function(){var t,e,i,n;return tt(this,function(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 Z(this,void 0,void 0,function(){var t,e=this;return tt(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return Z(e,void 0,void 0,function(){var e,i,n;return tt(this,function(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(h.MUTED,function(){e._updateGain()}),this._updateGain()},t.prototype.getDebugData=function(){var t=0;return this._activeSources.forEach(function(e){return t+=e.length}),{muted:!!this._state&&this._state.isMuted(),volume:this._volume,active_sources:t,loaded_buffers:this._buffers.size}},t}();const it=et,nt=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this._gameId="unknown",this.serialId="score"}return t.prototype.setupGameHighScore=function(t){this._gameId=t,this._highScore=Number(localStorage.getItem("".concat(this._gameId,"::highScore")))},t.prototype.increaseScore=function(t){this._score+=t*this._multiplier,this._score>this._highScore&&(this.highScore=this._score)},t.prototype.resetScore=function(){this._score=0},t.prototype.getFormattedScore=function(t){return void 0===t&&(t=6),this._score.toString().padStart(t,"0")},t.prototype.increaseLevel=function(t){this._level+=t},t.prototype.resetLevel=function(){this._level=1},Object.defineProperty(t.prototype,"multiplier",{get:function(){return this._multiplier},set:function(t){this._multiplier=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"level",{get:function(){return this._level},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxLevel",{get:function(){return this._maxLevel},set:function(t){this._maxLevel=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"highScore",{get:function(){return this._highScore},set:function(t){this._highScore=t,localStorage.setItem("".concat(this._gameId,"::highScore"),t.toString())},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel}},t.prototype.serialize=function(){return JSON.stringify({score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._score=e.score,this._multiplier=e.multiplier,this._level=e.level,this._maxLevel=e.max_level},t}();var ot,rt=(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 st=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return rt(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return 4},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return 4},enumerable:!1,configurable:!0}),e.prototype.serialize=function(){return JSON.stringify({grid:this._grid})},e.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},e}(B),at=function(){function t(){}return t.isSerializable=function(t){if(null==t)return!1;var e=t,i="function"==typeof e.serialize,n="function"==typeof e.deserialize,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 J)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ut=function(){function t(){this._initialState=new Map,this._baseProperties=[]}return t.prototype.captureBaseProperties=function(t){this._baseProperties=Object.keys(t)},t.prototype.captureInitialState=function(t){var e=this;console.log("capturing initial state for snapshot"),Object.entries(t).forEach(function(t){var i=t[0],n=t[1];if(!e._baseProperties.includes(i)&&"function"!=typeof n){var 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 ct=ut,lt=function(){function t(){this._isSessionResolved=!1,this._isModalOpen=!1,this._isEnabled=!0,this._resetFn=function(){},this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isSessionResolved&&this._isEnabled&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype.setResetFunction=function(t){this._resetFn=t},t.prototype.setSessionEnabled=function(t){this._isEnabled=t},t.prototype.isModalOpen=function(){return this._isModalOpen},t.prototype.isSessionResolved=function(){return this._isSessionResolved},t.prototype._hasSession=function(){var t=this;return this._serializables.every(function(e){return null!==localStorage.getItem(t._key(e.serialId))})},t.prototype._loadSession=function(){var t=this;this._serializables.forEach(function(e){var i=localStorage.getItem(t._key(e.serialId));i&&e.deserialize(i)})},t.prototype.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0})}}),t.subscribe(h.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(h.START,function(t){t||(e._isSessionResolved=!1)})},t.prototype.getDebugData=function(){return{game_id:this.gameId,is_session_resolved:this._isSessionResolved,is_modal_open:this._isModalOpen,is_enabled:this._isEnabled,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}(),ht=function(){function t(){}return t.setupControlEvents=function(t,e){var i=t.control,n=t.state,o=t.session,r=t.sound;i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.EXIT,l.PRESSED,function(){return o.clearSession()}),i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),r.stopAll()):n.turnOn()}),i.subscribeForGameOverScreen(c.POWER,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForTitleScreen(c.START_PAUSE,l.PRESSED,function(){return n.startGame()}),i.subscribeForPlayingScreen(c.START_PAUSE,l.PRESSED,function(){return n.pause()}),i.subscribeForGameOverScreen(c.START_PAUSE,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForPausedScreen(c.START_PAUSE,l.PRESSED,function(){return n.resume()}),i.subscribeForPlayingScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()}),i.subscribeForPausedScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()})},t.setupStateEvents=function(t){var e=t.state,i=t.session;e.subscribe(h.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),e.subscribeForGameOverScreen(h.GAME_OVER,function(){i.clearSession()})},t}();var dt=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new ct,this._gameId="unknown",this._view=t,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"p",{get:function(){return k.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new Y,grid:new B,hudGrid:new st,text:new Q,state:new J,control:new b,time:new $,sound:new it,score:new nt,session:new lt},Object.values(this._modules).forEach(function(t){at.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){at.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){at.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,o=e.renderer,r=e.session,s=e.score;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),s.setupGameHighScore(this.gameId),this.setupGame(),ht.setupControlEvents(this._modules,this.reset.bind(this)),ht.setupStateEvents(this._modules),this._view.bindControls(n),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=k.p;if(this._modules){var e=this._modules,i=e.renderer,n=e.grid,o=e.time,r=e.state,s=e.session;s.isModalOpen()||r.isPlaying()&&!s.isSessionResolved()||(i.render(n.getGrid(),this._modules),r.isOn()&&(r.isStarted()?r.isPlaying()?(o.update(t.deltaTime),o.shouldTick()&&(this.update(t.deltaTime),this._modules.session.saveSession()),this.render()):r.isPaused()&&this.render():this.drawTitleScreen(),r.isGameOver()&&this.drawGameOverScreen()))}},t.prototype.destroy=function(){k.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},t.prototype.reset=function(){this._modules.grid.resetGrid(),this._modules.score.resetScore(),this._modules.score.resetLevel(),this._modules.time.reset(),this._modules.session.clearSession(),this._initialStateSnapshot.restoreInitialState(this)},t}();const pt=dt;var ft={grad:.9,turn:360,rad:360/(2*Math.PI)},gt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},yt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},vt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},mt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:vt(t.r,0,255),g:vt(t.g,0,255),b:vt(t.b,0,255),a:vt(t.a)}},bt=function(t){return{r:yt(t.r),g:yt(t.g),b:yt(t.b),a:yt(t.a,3)}},Et=/^#([0-9a-f]{3,8})$/i,St=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},wt=function(t){var e=t.r,i=t.g,n=t.b,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}},Rt=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}},Pt=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:yt(t.h),s:yt(t.s),l:yt(t.l),a:yt(t.a,3)}},Ct=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},Ot=function(t){return{h:(e=wt(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},Tt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,At=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It={string:[[function(t){var e=Et.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?yt(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?yt(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Lt.exec(t)||Mt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:_t({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Tt.exec(t)||At.exec(t);if(!e)return null;var i,n,o=Pt({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(ft[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return Ct(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 gt(e)&>(i)&>(n)?_t({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(!gt(e)||!gt(i)||!gt(n))return null;var s=Pt({h:Number(e),s:Number(i),l:Number(n),a:Number(r)});return Ct(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,o=t.a,r=void 0===o?1:o;if(!gt(e)||!gt(i)||!gt(n))return null;var s=function(t){return{h:mt(t.h),s:vt(t.s,0,100),v:vt(t.v,0,100),a:vt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(r)});return Rt(s)},"hsv"]]},Dt=function(t,e){for(var i=0;i<e.length;i++){var n=e[i][0](t);if(n)return[n,e[i][1]]}return[null,void 0]},Gt=function(t,e){var i=Ot(t);return{h:i.h,s:vt(i.s+100*e,0,100),l:i.l,a:i.a}},Bt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},kt=function(t,e){var i=Ot(t);return{h:i.h,s:i.s,l:vt(i.l+100*e,0,100),a:i.a}},Nt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Dt(t.trim(),It.string):"object"==typeof t&&null!==t?Dt(t,It.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return yt(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=bt(this.rgba)).r,i=t.g,n=t.b,r=(o=t.a)<1?St(yt(255*o)):"","#"+St(e)+St(i)+St(n)+r;var t,e,i,n,o,r},t.prototype.toRgb=function(){return bt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,(o=t.a)<1?"rgba("+e+", "+i+", "+n+", "+o+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,o},t.prototype.toHsl=function(){return xt(Ot(this.rgba))},t.prototype.toHslString=function(){return e=(t=xt(Ot(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=wt(this.rgba),{h:yt(t.h),s:yt(t.s),v:yt(t.v),a:yt(t.a,3)};var t},t.prototype.invert=function(){return zt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,-t))},t.prototype.grayscale=function(){return zt(Gt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),zt(kt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),zt(kt(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?zt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):yt(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Ot(this.rgba);return"number"==typeof t?zt({h:t,s:e.s,l:e.l,a:e.a}):yt(e.h)},t.prototype.isEqual=function(t){return this.toHex()===zt(t).toHex()},t}(),zt=function(t){return t instanceof Nt?t:new Nt(t)};function Ft(t,e){var i=k.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 Ht(t,e,i){var n=k.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 Ut=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(p.game.debugger.enabled){var e=k.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 jt=Ut;var Vt=function(){function t(){}return t.prototype.setup=function(){var t=k.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 Wt=Vt;var Yt=function(){function t(t){this._parent=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,o;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(p.inputQueryParams.mainColor)?i.get(p.inputQueryParams.mainColor):p.colors.bodyMain,o=i.has(p.inputQueryParams.buttonColor)?i.get(p.inputQueryParams.buttonColor):p.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=k.p.createDiv();if(i.parent(p.selectors.parent),i.id(p.selectors.viewElementIds.container),t.clientWidth<=p.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*p.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*p.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=r.container,a=r.height,u=r.width,c=function(t){var e=k.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.frame);var n=e.createDiv();return n.parent(i),e.createP("Brick Game").parent(n),i}(s),l=function(t,e){var i=k.p,n=e*p.viewLayout.canvas.widthRatio,o=n*p.viewLayout.canvas.aspectRatio,r=i.createCanvas(n,o);return r.parent(t),r.id(p.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:o,canvas:r}}(c,u),h=l.canvas,d=l.canvasHeight,f=l.canvasWidth,g=function(t){var e=k.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.buttonContainer);var n=e.createDiv();n.parent(i),n.id(p.selectors.viewElementIds.smallButtonContainer);var o=e.createDiv();o.parent(i),o.id(p.selectors.viewElementIds.innerButtonContainer);var r=e.createDiv();r.parent(o),r.id(p.selectors.viewElementIds.mediumButtonContainer);var s=e.createDiv();s.parent(r),s.id(p.selectors.viewElementIds.directionVerticalContainer);var a=e.createDiv();a.parent(r),a.id(p.selectors.viewElementIds.directionHorizontalContainer);var u=e.createDiv();return u.parent(o),u.id(p.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:r,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(s),y=g.largeButtonContainer,v=g.smallButtonContainer,m=g.directionHorizontalContainer,_=g.directionVerticalContainer;return this._onOffBtn=Ht(v,"On<br/>Off",!0),this._startPauseBtn=Ht(v,"Start<br/>Pause",!1),this._soundBtn=Ht(v,"Sound",!0),this._resetBtn=Ht(v,"Reset",!1),this._exitBtn=Ht(v,"Exit",!0),this._enableColorBtn=Ht(v,"Enable<br/>Colors",!1),this._upBtn=Ft(_,"UP"),this._leftBtn=Ft(m,"LEFT"),this._downBtn=Ft(_,"DOWN"),this._rightBtn=Ft(m,"RIGHT"),this._actionBtn=function(t){var e=k.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 o=document.querySelector(":root");o.style.setProperty("--dispersion",p.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*p.viewLayout.dimensions.borderRadiusRatio,"px")),o.style.setProperty("--border","".concat(t*p.viewLayout.dimensions.borderWidthRatio,"px solid black")),o.style.setProperty("--sm-button-size","".concat(t*p.viewLayout.dimensions.button.smSizeRatio,"px")),o.style.setProperty("--button-size","".concat(t*p.viewLayout.dimensions.button.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size","".concat(t*p.viewLayout.dimensions.button.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),o.style.setProperty("--button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.fontRatio,"px")),o.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),o.style.setProperty("--button-size-mobile-spacing","".concat(t*p.viewLayout.dimensions.button.mobile.spacingRatio,"px")),o.style.setProperty("--button-border","".concat(t*p.viewLayout.dimensions.button.borderRatio,"px solid black")),o.style.setProperty("--button-animation-duration",p.viewLayout.dimensions.button.animationDuration)}(u,a,f,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Wt,this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new jt(t),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=p.viewLayout.splashHideDelayMs);var e=document.querySelector(p.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Kt=Yt;var Xt,Jt=n(991),qt=n.n(Jt);function Qt(t){Xt=t}function $t(t){return window.BrickEngineGame=t,new(qt())(function(e){k.init(e);var i=new Kt(document.body);Qt(new t(i)),"unknown"===Xt.gameId&&(Xt.gameId="game"),e.setup=function(){Xt.setup(),Xt.view.setupDebugger(Xt.modules),Xt.view.setupSessionModal()},e.draw=function(){Xt.draw(),Xt.view.updateDebugger()}})}return d})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("p5")):"function"==typeof define&&define.amd?define(["p5"],e):"object"==typeof exports?exports.BrickEngine=e(require("p5")):t.BrickEngine=e(t.p5)}(self,t=>(()=>{"use strict";var e={991(e){e.exports=t}},i={};function n(t){var 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={};n.r(d),n.d(d,{Color:()=>o,ControlEventType:()=>l,ControlKey:()=>c,EventEmitter:()=>m,FontAlign:()=>r,FontSize:()=>s,FontVerticalAlign:()=>a,Game:()=>pt,GameView:()=>Kt,RendererContext:()=>B,Sound:()=>u,StateProperty:()=>h,bootstrap:()=>$t,configs:()=>p,setActiveGame:()=>Qt}),function(t){t.DEFAULT="rgb(19, 26, 18)",t.BLUE="rgb(0, 0, 128)",t.CYAN="rgb(0, 128, 128)",t.GRAY="rgb(128, 128, 128)",t.GREEN="rgb(0, 128, 0)",t.PURPLE="rgb(128, 0, 128)",t.RED="rgb(128, 0, 0)",t.YELLOW="rgb(128, 128, 0)",t.INACTIVE="rgb(166, 183, 165)"}(o||(o={})),function(t){t.CENTER="center",t.LEFT="left",t.RIGHT="right"}(r||(r={})),function(t){t[t.EXTRA_SMALL=0]="EXTRA_SMALL",t[t.SMALL=1]="SMALL",t[t.MEDIUM=2]="MEDIUM",t[t.LARGE=3]="LARGE",t[t.EXTRA_LARGE=4]="EXTRA_LARGE"}(s||(s={})),function(t){t.CENTER="center",t.TOP="top",t.BOTTOM="bottom"}(a||(a={})),function(t){t.SPAWN="./sounds/sound_01.wav",t.SCORE_1="./sounds/sound_15.wav",t.SCORE_2="./sounds/sound_03.wav",t.SCORE_3="./sounds/sound_02.wav",t.KEY_PRESS="./sounds/sound_14.wav",t.ACTION_1="./sounds/sound_05.wav",t.ACTION_2="./sounds/sound_13.wav",t.HIT_1="./sounds/sound_06.wav",t.HIT_2="./sounds/sound_08.wav",t.DODGE="./sounds/sound_07.wav",t.DROP="./sounds/sound_11.wav",t.EXPLOSION="./sounds/sound_09.wav",t.GAME_START="./sounds/sound_04.wav",t.SHOT="./sounds/sound_12.wav",t.START_THEME="./sounds/sound_10.wav"}(u||(u={})),function(t){t.UP="up;control",t.DOWN="down;control",t.LEFT="left;control",t.RIGHT="right;control",t.ACTION="action;control",t.POWER="power;system",t.START_PAUSE="start_pause;system",t.SOUND="sound;system",t.RESET="reset;system",t.EXIT="exit;system",t.COLOR="color;system"}(c||(c={})),function(t){t.PRESSED="pressed",t.HELD="held"}(l||(l={})),function(t){t.ON="on",t.START="start",t.PLAYING="playing",t.GAME_OVER="gameOver",t.COLOR_ENABLED="colorEnabled",t.MUTED="muted"}(h||(h={}));const p={colors:{background:"rgb(172, 189, 173)",active:"rgb(19, 26, 18)",inactive:"rgba(161, 178, 160, 1)",bodyMain:"rgb(0, 68, 187)",bodyButton:"rgb(247, 222, 57)"},screenLayout:{grid:{columns:11,rows:18},hudGrid:{columns:4,rows:4},display:{width:.65,height:.956,margin:.022,borderWeight:.0075},fontSize:{extraSmall:.05,small:.065,medium:.1,large:.125,extraLarge:.15},cell:{margin:.1,padding:.3,strokeWeight:.075}},viewLayout:{bodyHeightWidthMultiplier:1.9,mobileBreakpoint:600,canvas:{widthRatio:.7,aspectRatio:1.114},splashHideDelayMs:250,dimensions:{borderRadiusRatio:.05,borderWidthRatio:.006,button:{smSizeRatio:.08,mdSizeRatio:.18,lgSizeRatio:.25,mobile:{smSizeRatio:.13,mdSizeRatio:.26,lgSizeRatio:.35,fontRatio:.05,smFontRatio:.04,lgFontRatio:.055,spacingRatio:.018},borderRatio:.0045,animationDuration:"0.15s"}},shadowDispersion:"3px"},inputQueryParams:{mainColor:"body-color",buttonColor:"button-color",runningOnApp:"mobile"},selectors:{parent:"#brick-game",splash:"#splash",modalIds:{sessionModal:"#session-modal",sessionContinueYes:"#session-modal-yes",sessionContinueNo:"#session-modal-no"},viewElementIds:{canvas:"brick-game-canvas",container:"container",frame:"frame",buttonContainer:"button-container",smallButtonContainer:"small-button-container",innerButtonContainer:"inner-button-container",mediumButtonContainer:"medium-button-container",directionVerticalContainer:"direction-vertical-container",directionHorizontalContainer:"direction-horizontal-container",largeButtonContainer:"large-button-container"}},storageKeys:{muted:"STATE.MUTED",colorEnabled:"STATE.COLOR_ENABLED",grid:"GAME.GRID",hudGrid:"GAME.HUD_GRID",tickInterval:"GAME.TICK_INTERVAL",score:"GAME.SCORE"},buttonHold:{holdDelayMs:250,holdIntervalMs:50},game:{tickInterval:1e3/30,minTickInterval:1e3/60,debugger:{msInterval:100,enabled:!0},sound:{volume:.025}}},f=function(){function t(t){this._activeKeys=new Map,this._control=t}return t.prototype.handlePress=function(t){var e=this;if(!this._activeKeys.has(t)){this._control.notify(t,l.PRESSED);var i=setTimeout(function(){var i=setInterval(function(){e._control.notify(t,l.HELD)},p.buttonHold.holdIntervalMs),n=e._activeKeys.get(t);n&&(n.hold=i)},p.buttonHold.holdDelayMs);this._activeKeys.set(t,{delay:i,hold:null})}},t.prototype.handleRelease=function(t){var e=this._activeKeys.get(t);e&&(clearTimeout(e.delay),e.hold&&clearInterval(e.hold),this._activeKeys.delete(t))},t}();var g={ArrowUp:c.UP,ArrowDown:c.DOWN,ArrowLeft:c.LEFT,ArrowRight:c.RIGHT,KeyW:c.UP,KeyS:c.DOWN,KeyA:c.LEFT,KeyD:c.RIGHT,KeyJ:c.ACTION,Digit1:c.POWER,Digit2:c.START_PAUSE,Digit3:c.SOUND,Digit4:c.RESET,Digit5:c.EXIT,Digit6:c.COLOR};const y=function(){function t(t){this._inputHandler=new f(t),this._boundHandleKeyDown=this._handleKeyDown.bind(this),this._boundHandleKeyUp=this._handleKeyUp.bind(this)}return t.prototype.bindControls=function(){window.addEventListener("keydown",this._boundHandleKeyDown),window.addEventListener("keyup",this._boundHandleKeyUp)},t.prototype.unbindControls=function(){window.removeEventListener("keydown",this._boundHandleKeyDown),window.removeEventListener("keyup",this._boundHandleKeyUp)},t.prototype._handleKeyDown=function(t){var e=g[t.code];e&&(t.repeat||this._inputHandler.handlePress(e))},t.prototype._handleKeyUp=function(t){var e=g[t.code];e&&this._inputHandler.handleRelease(e)},t}();var v;!function(t){t.TITLE="title",t.PLAYING="playing",t.GAMEOVER="gameover",t.PAUSED="paused"}(v||(v={}));const m=function(){function t(){}return t.subscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]||(this._events[n]=[]),this._events[n].push(e)},t.unsubscribe=function(t,e,i){var n=this._formatName(t,i);this._events[n]&&(this._events[n]=this._events[n].filter(function(t){return t!==e}))},t.notify=function(t,e){this._events[t]&&this._events[t].forEach(function(t){return t(e)})},t.notifyContextual=function(t,e,i){this.notify(t,e),i.isPlaying()?this.notify(this._formatName(t,v.PLAYING),e):i.isPaused()?this.notify(this._formatName(t,v.PAUSED),e):i.isOn()&&!i.isStarted()?this.notify(this._formatName(t,v.TITLE),e):i.isGameOver()&&this.notify(this._formatName(t,v.GAMEOVER),e)},t._formatName=function(t,e){return e?"".concat(t,":").concat(e):t},t.clear=function(){this._events={}},t._events={},t}();var _=function(){function t(){this._activeListeners=[]}return t.prototype.setup=function(){this._keyBinding=new y(this),this._keyBinding.bindControls()},t.prototype.unbindControls=function(){this._keyBinding.unbindControls(),this._activeListeners.forEach(function(t){var e=t.event,i=t.callback;m.unsubscribe(e,i)}),this._activeListeners=[]},t.prototype.bindControls=function(){this._keyBinding.bindControls()},t.prototype.setModules=function(t){this._modules=t},t.prototype.subscribe=function(t,e,i){this._subscribe(t,e,i)},t.prototype.unsubscribe=function(t,e,i){this._unsubscribe(t,e,i)},t.prototype.subscribeForTitleScreen=function(t,e,i){this._subscribe(t,e,i,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e,i){this._unsubscribe(t,e,i,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e,i){this._subscribe(t,e,i,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e,i){this._unsubscribe(t,e,i,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e,i){this._subscribe(t,e,i,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e,i){this._subscribe(t,e,i,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e,i){this._unsubscribe(t,e,i,v.PAUSED)},t.prototype._subscribe=function(t,e,i,n){var o="".concat(t,":").concat(e);m.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);m.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=t===c.POWER:!n.isStarted()||n.isPlaying()||n.isGameOver()?r=!0:n.isPaused()&&(r=t.endsWith(";system")),r&&m.notifyContextual("".concat(t,":").concat(e),i,n)},t.prototype.getDebugData=function(){return{total_active_listeners:this._activeListeners.length}},t}();const b=_,E=function(){function t(){}return t.emptyCell=function(t){return{value:0,color:o.DEFAULT,coordinate:t}},t}();var S=function(){return S=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},S.apply(this,arguments)},w=function(){function t(t){this.grid=t}return t.prototype.movePiece=function(t,e){var i=this,n=t.map(function(t){return S(S({},t),{coordinate:{x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)}})}),o=n.some(function(e){return!i.grid.isCoordinateValid(e.coordinate)||i.grid.isCellActive(e.coordinate)&&(n=e.coordinate,!t.some(function(t){return t.coordinate.x===n.x&&t.coordinate.y===n.y}));var n});return o?null:n},t.prototype.movePieceLeft=function(t){return this.movePiece(t,{x:-1,y:0})},t.prototype.movePieceRight=function(t){return this.movePiece(t,{x:1,y:0})},t.prototype.movePieceUp=function(t){return this.movePiece(t,{x:0,y:-1})},t.prototype.movePieceDown=function(t){return this.movePiece(t,{x:0,y:1})},t.prototype.moveCell=function(t,e){var i={x:t.coordinate.x+(e.x||0),y:t.coordinate.y+(e.y||0)};return!this.grid.isCoordinateValid(i)||this.grid.isCellActive(i)?null:S(S({},t),{coordinate:i})},t.prototype.moveCellLeft=function(t){return this.moveCell(t,{x:-1,y:0})},t.prototype.moveCellRight=function(t){return this.moveCell(t,{x:1,y:0})},t.prototype.moveCellUp=function(t){return this.moveCell(t,{x:0,y:-1})},t.prototype.moveCellDown=function(t){return this.moveCell(t,{x:0,y:1})},t.prototype.getDropPath=function(t){for(var e=t,i=this.movePieceDown(e);null!==i;)e=i,i=this.movePieceDown(e);return e},t.prototype.getRisePath=function(t){for(var e=t,i=this.movePieceUp(e);null!==i;)e=i,i=this.movePieceUp(e);return e},t.prototype.getReachPathLeft=function(t){for(var e=t,i=this.movePieceLeft(e);null!==i;)e=i,i=this.movePieceLeft(e);return e},t.prototype.getReachPathRight=function(t){for(var e=t,i=this.movePieceRight(e);null!==i;)e=i,i=this.movePieceRight(e);return e},t}();const P=w;var R=function(){return R=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},R.apply(this,arguments)},C=function(){function t(t){this.grid=t}return t.prototype.rotatePiece=function(t,e,i){var n=this;void 0===i&&(i=!0);var 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 R(R({},t),{coordinate:{x:e.x+r,y:e.y+s}})}),r=o.some(function(e){return!n.grid.isCoordinateValid(e.coordinate)||n.grid.isCellActive(e.coordinate)&&(i=e.coordinate,!t.some(function(t){return t.coordinate.x===i.x&&t.coordinate.y===i.y}));var i});return r?null: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 R(R({},t),{coordinate:{x:"x"===e?Math.round(2*n-t.coordinate.x):t.coordinate.x,y:"y"===e?Math.round(2*n-t.coordinate.y):t.coordinate.y}})})},t.prototype.getPieceBounds=function(t){var e=t.map(function(t){return t.coordinate.x}),i=t.map(function(t){return t.coordinate.y});return{min:{x:Math.min.apply(Math,e),y:Math.min.apply(Math,i)},max:{x:Math.max.apply(Math,e),y:Math.max.apply(Math,i)}}},t}();const x=C;var O=function(){return O=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},O.apply(this,arguments)},T=function(){function t(t){this.grid=t}return t.prototype.getFullRows=function(){for(var t=[],e=0;e<this.grid.height;e++){for(var i=!0,n=0;n<this.grid.width;n++)if(!this.grid.isCellActive({x:n,y:e})){i=!1;break}i&&t.push(e)}return t},t.prototype.getFullColumns=function(){for(var t=[],e=0;e<this.grid.width;e++){for(var i=!0,n=0;n<this.grid.height;n++)if(!this.grid.isCellActive({x:e,y:n})){i=!1;break}i&&t.push(e)}return t},t.prototype.getNeighbors=function(t,e){var i=this;void 0===e&&(e=!1);var n=[],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};i.grid.isCoordinateValid(o)&&n.push(i.grid.getCell(o))}),n},t.prototype.findConnectedCells=function(t){var e=this;if(!this.grid.isCellActive(t))return[];var i=this.grid.getCell(t).value,n=[],o=new Set,r=[t],s=function(t){return"".concat(t.x,",").concat(t.y)};for(o.add(s(t));r.length>0;){var a=r.shift(),u=this.grid.getCell(a);u.value===i&&(n.push(u),[{x:a.x-1,y:a.y},{x:a.x+1,y:a.y},{x:a.x,y:a.y-1},{x:a.x,y:a.y+1}].forEach(function(t){var i=s(t);e.grid.isCoordinateValid(t)&&!o.has(i)&&e.grid.isCellActive(t)&&(o.add(i),r.push(t))}))}return n},t.prototype.swapCells=function(t,e){var i=O({},this.grid.getCell(t)),n=O({},this.grid.getCell(e));this.grid.stampCell(O(O({},n),{coordinate:t})),this.grid.stampCell(O(O({},i),{coordinate:e}))},t}();const A=T;var I=function(){function t(t){this.grid=t}return t.prototype.isRowFull=function(t){var e=this.grid.getGrid();return!(t<0||t>=this.grid.height)&&e[t].every(function(t){return t.value>0})},t.prototype.isRowEmpty=function(t){var e=this.grid.getGrid();return t<0||t>=this.grid.height||e[t].every(function(t){return 0===t.value})},t.prototype.clearRow=function(t){var e=this.grid.getGrid();if(!(t<0||t>=this.grid.height))for(var i=0;i<this.grid.width;i++)e[t][i]=E.emptyCell({x:i,y:t})},t.prototype.shiftRowsDown=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.width;n++){var 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]=E.emptyCell({x:t,y:i})},t.prototype.shiftColumnsRight=function(t){for(var e=this.grid.getGrid(),i=t;i>0;i--)for(var n=0;n<this.grid.height;n++){var 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 L=I;var M=function(){function t(t){this.grid=t}return t.prototype.isAreaOccupied=function(t){var e=this;return t.some(function(t){return!e.grid.isCoordinateValid(t)||e.grid.isCellActive(t)})},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 D=M;var G=function(){function t(){this._grid=[],this.serialId="grid",this._movementEngine=new P(this),this._transformEngine=new x(this),this._analysisEngine=new A(this),this._lineEngine=new L(this),this._regionEngine=new D(this)}return t.prototype.getGrid=function(){return this._grid},Object.defineProperty(t.prototype,"width",{get:function(){return p.screenLayout.grid.columns},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return p.screenLayout.grid.rows},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"topRow",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottomRow",{get:function(){return this.height-1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"leftColumn",{get:function(){return 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rightColumn",{get:function(){return this.width-1},enumerable:!1,configurable:!0}),t.prototype.setup=function(){this.resetGrid()},t.prototype.resetGrid=function(){this._grid=[];for(var t=0;t<this.height;t++){this._grid[t]=[];for(var e=0;e<this.width;e++)this._grid[t][e]=E.emptyCell({x:e,y:t})}},t.prototype.forEach=function(t){for(var e=0;e<this.height;e++)for(var i=0;i<this.width;i++)t(this._grid[e][i])},t.prototype.isCoordinateValid=function(t){return t.x>=0&&t.x<this.width&&t.y>=0&&t.y<this.height},t.prototype.getCell=function(t){return this.isCoordinateValid(t)?this._grid[t.y][t.x]:null},t.prototype.setCellValue=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].value=e)},t.prototype.setCellColor=function(t,e){this.isCoordinateValid(t)&&(this._grid[t.y][t.x].color=e)},t.prototype.isCellActive=function(t){var e=this.getCell(t);return null!==e&&e.value>0},t.prototype.isCellInactive=function(t){var e=this.getCell(t);return null!==e&&0===e.value},t.prototype.isRowFull=function(t){return this._lineEngine.isRowFull(t)},t.prototype.isRowEmpty=function(t){return this._lineEngine.isRowEmpty(t)},t.prototype.clearRow=function(t){this._lineEngine.clearRow(t)},t.prototype.shiftRowsDown=function(t){this._lineEngine.shiftRowsDown(t)},t.prototype.shiftRowsUp=function(t){this._lineEngine.shiftRowsUp(t)},t.prototype.clearFullRows=function(){return this._lineEngine.clearFullRows()},t.prototype.isColumnFull=function(t){return this._lineEngine.isColumnFull(t)},t.prototype.isColumnEmpty=function(t){return this._lineEngine.isColumnEmpty(t)},t.prototype.clearColumn=function(t){this._lineEngine.clearColumn(t)},t.prototype.shiftColumnsRight=function(t){this._lineEngine.shiftColumnsRight(t)},t.prototype.shiftColumnsLeft=function(t){this._lineEngine.shiftColumnsLeft(t)},t.prototype.clearFullColumns=function(){return this._lineEngine.clearFullColumns()},t.prototype.isAreaOccupied=function(t){return this._regionEngine.isAreaOccupied(t)},t.prototype.fillArea=function(t,e,i,n){this._regionEngine.fillArea(t,e,i,n)},t.prototype.stampPiece=function(t){this._regionEngine.stampPiece(t)},t.prototype.stampCell=function(t){this._regionEngine.stampCell(t)},t.prototype.movePiece=function(t,e){return this._movementEngine.movePiece(t,e)},t.prototype.movePieceLeft=function(t){return this._movementEngine.movePieceLeft(t)},t.prototype.movePieceRight=function(t){return this._movementEngine.movePieceRight(t)},t.prototype.movePieceUp=function(t){return this._movementEngine.movePieceUp(t)},t.prototype.movePieceDown=function(t){return this._movementEngine.movePieceDown(t)},t.prototype.moveCell=function(t,e){return this._movementEngine.moveCell(t,e)},t.prototype.moveCellLeft=function(t){return this._movementEngine.moveCellLeft(t)},t.prototype.moveCellRight=function(t){return this._movementEngine.moveCellRight(t)},t.prototype.moveCellUp=function(t){return this._movementEngine.moveCellUp(t)},t.prototype.moveCellDown=function(t){return this._movementEngine.moveCellDown(t)},t.prototype.rotatePiece=function(t,e,i){return void 0===i&&(i=!0),this._transformEngine.rotatePiece(t,e,i)},t.prototype.getFullRows=function(){return this._analysisEngine.getFullRows()},t.prototype.getFullColumns=function(){return this._analysisEngine.getFullColumns()},t.prototype.getDropPath=function(t){return this._movementEngine.getDropPath(t)},t.prototype.getRisePath=function(t){return this._movementEngine.getRisePath(t)},t.prototype.getReachPathLeft=function(t){return this._movementEngine.getReachPathLeft(t)},t.prototype.getReachPathRight=function(t){return this._movementEngine.getReachPathRight(t)},t.prototype.getNeighbors=function(t,e){return void 0===e&&(e=!1),this._analysisEngine.getNeighbors(t,e)},t.prototype.findConnectedCells=function(t){return this._analysisEngine.findConnectedCells(t)},t.prototype.mirrorPiece=function(t,e){return this._transformEngine.mirrorPiece(t,e)},t.prototype.swapCells=function(t,e){this._analysisEngine.swapCells(t,e)},t.prototype.getPieceBounds=function(t){return this._transformEngine.getPieceBounds(t)},t.prototype.getDebugData=function(){return{width:this.width,height:this.height,activeCells:this._grid.flat().filter(function(t){return t.value>0}).length}},t.prototype.serialize=function(){return console.log("serialize"),JSON.stringify({grid:this._grid})},t.prototype.deserialize=function(t){console.log("deserialize");var e=JSON.parse(t);this._grid=e.grid},t}();const k=G,B=function(){function t(){}return t.init=function(t){this._p?console.warn("[BrickEngine] RendererContext is already initialized. Ignoring subsequent initialization."):this._p=t},Object.defineProperty(t,"p",{get:function(){if(!this._p)throw new Error("RendererContext not initialized yet. Ensure the Game object has been created.");return this._p},enumerable:!1,configurable:!0}),t.reset=function(){this._p=void 0},t}(),N=function(){function t(){}return t.getRelativeWidth=function(t){return t*B.p.width},t.getRelativeHeight=function(t){return t*B.p.height},t}();var z=function(){function t(){}return t.prototype.setup=function(t){this._rendererMetrics=t;var e=p.screenLayout.cell,i=e.margin,n=e.padding,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=B.p;i.push(),i.image(this._staticGraphics,0,0),this.renderGrid(t,e.state),i.pop()},t.prototype._renderStaticElements=function(){var t=B.p,e=p.screenLayout.display.borderWeight;this._staticGraphics=t.createGraphics(t.width,t.height),this._staticGraphics.background(p.colors.background),this._staticGraphics.strokeWeight(N.getRelativeWidth(e)),this._staticGraphics.noFill(),this._staticGraphics.stroke(p.colors.active),this._staticGraphics.rect(this._rendererMetrics.display.origin.x,this._rendererMetrics.display.origin.y,this._rendererMetrics.display.width,this._rendererMetrics.display.height)},t.prototype.renderCell=function(t,e){var i=t.coordinate,n=t.color,r=t.value,s=B.p,a=i.x,u=i.y,c=this._cellPreCalculatedGeometry,l=c.innerOffset,h=c.innerSize,d=c.paddingOffset,p=c.paddingSize,f=c.strokeWeight;n=0===r||!e.isPlaying()&&!e.isPaused()?o.INACTIVE:e.isColorEnabled()?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 F=z;var H=function(){function t(){}return t.getRelativeCoordinate=function(t){return{x:N.getRelativeWidth(t.x),y:N.getRelativeHeight(t.y)}},t.getDisplayPosX=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeWidth(i)},t.getDisplayPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t.getHudPosX=function(t,e){var i=B.p,n=p.screenLayout.display.margin,o=N.getRelativeWidth(n),r=e+2*o;return(i.width-r-o)*t+r},t.getHudPosY=function(t,e){var i=p.screenLayout.display.margin;return e*t+N.getRelativeHeight(i)},t}();const U=H;var j=function(){function t(){}return t.prototype.setup=function(t){this._cellSize=t.cell.size,this._gridOrigin={x:U.getHudPosX(.078,t.display.width),y:U.getHudPosY(.375,t.display.height)},this._hudBorderRect={x:this._gridOrigin.x-N.getRelativeWidth(.005),y:this._gridOrigin.y-N.getRelativeHeight(.005),w:4*this._cellSize+N.getRelativeWidth(.01),h:4*this._cellSize+N.getRelativeHeight(.01)}},t.prototype.render=function(t,e){this._renderHud(e),this._drawHudGrid(e)},t.prototype._renderHud=function(t){var e=B.p,i=t.text,n=t.state,o=t.score;e.push(),i.setTextSize(s.SMALL),i.setInactiveText(),i.setTextAlign(r.LEFT,a.BOTTOM),i.textOnHud("88888888",{x:.05,y:.13}),i.textOnHud("88888888",{x:.05,y:.3}),i.textOnHud("88 - 88",{x:.05,y:.8}),n.isOn()&&i.setActiveText(),i.textOnHud("Score",{x:.05,y:.06}),i.textOnHud(o.score.toString(),{x:.05,y:.13}),i.textOnHud("Hi-Score",{x:.05,y:.23}),i.textOnHud(o.highScore.toString(),{x:.05,y:.3}),i.textOnHud("Level",{x:.05,y:.72});var u="".concat(o.level<10?"0"+o.level:o.level," - ").concat(o.maxLevel);i.textOnHud(u,{x:.05,y:.8}),i.setTextAlign(r.CENTER,a.BOTTOM),n.isPaused()?i.setActiveText():i.setInactiveText(),i.textOnHud("Paused",{x:.5,y:.9}),n.isOn()&&n.isMuted()?i.setActiveText():i.setInactiveText(),i.textOnHud("Muted",{x:.5,y:.97}),e.pop(),this._drawHudGrid(t)},t.prototype._drawHudGrid=function(t){var e=this,i=B.p,n=t.hudGrid,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=B.p,s=p.screenLayout.cell,a=s.margin,u=s.padding,c=a*e,l=e-a*e*2,h=u*e,d=e-u*e*2,f=s.strokeWeight*e;r.push(),r.translate(i,n),r.strokeWeight(f),r.stroke(o),r.noFill(),r.rect(c,c,l,l),r.fill(o),r.rect(h,h,d,d),r.pop()},t}();const V=j;var W=function(){function t(){}return t.prototype.addRenderer=function(t){this._renderers.push(t)},t.prototype.setup=function(){var t=this;this._displayRenderer=new F,this._hudRenderer=new V,this._renderers=[],this.addRenderer(this._displayRenderer),this.addRenderer(this._hudRenderer),this._calculateMetrics(),this._renderers.forEach(function(e){return e.setup(t.rendererMetrics)})},t.prototype._calculateMetrics=function(){var t=p.screenLayout.display,e=t.width,i=t.height,n=t.margin,o=p.screenLayout.grid.columns,r=N.getRelativeWidth(e),s=N.getRelativeHeight(i),a=U.getRelativeCoordinate({x:n,y:n}),u=r/o,c={x:U.getHudPosX(0,r),y:U.getHudPosY(0,s)},l=U.getHudPosX(1,r)-c.x,h=U.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 Y=W;var K,X=((K={})[h.ON]={defaultValue:!1},K[h.START]={defaultValue:!1},K[h.PLAYING]={defaultValue:!1},K[h.GAME_OVER]={defaultValue:!1},K[h.COLOR_ENABLED]={defaultValue:!0,storageKey:"colorEnabled"},K[h.MUTED]={defaultValue:!1,storageKey:"muted"},K);const J=function(){function t(){this._state=new Map}return t.prototype.setup=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];t._state.set(e,i.defaultValue)}),this._loadPersistentState()},t.prototype._loadPersistentState=function(){var t=this;Object.values(h).forEach(function(e){var i=X[e];if(i.storageKey){var n=localStorage.getItem(i.storageKey);null!==n&&t._state.set(e,JSON.parse(n))}})},t.prototype._set=function(t,e){if(this._state.get(t)!==e){this._state.set(t,e);var i=X[t];i.storageKey&&localStorage.setItem(i.storageKey,JSON.stringify(e)),this.notify(t)}},t.prototype.notify=function(t){var e=this._state.get(t);m.notifyContextual(t,e,this)},t.prototype.isOn=function(){return this._state.get(h.ON)},t.prototype.isOff=function(){return!this.isOn()},t.prototype.isStarted=function(){return this._state.get(h.START)},t.prototype.isPlaying=function(){return this._state.get(h.PLAYING)},t.prototype.isPaused=function(){return this.isStarted()&&!this.isPlaying()&&!this.isGameOver()},t.prototype.isGameOver=function(){return this._state.get(h.GAME_OVER)},t.prototype.turnOn=function(){this._set(h.ON,!0),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.turnOff=function(){this._set(h.ON,!1),this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.startGame=function(){this.isOn()&&(this._set(h.START,!0),this._set(h.PLAYING,!0),this._set(h.GAME_OVER,!1))},t.prototype.resetGameOver=function(){this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0)},t.prototype.exitGame=function(){this._set(h.START,!1),this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!1)},t.prototype.pause=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!1)},t.prototype.resume=function(){this.isStarted()&&!this.isGameOver()&&this._set(h.PLAYING,!0)},t.prototype.triggerGameOver=function(){this._set(h.PLAYING,!1),this._set(h.GAME_OVER,!0)},t.prototype.resetGame=function(){this.isOn()&&(this._set(h.GAME_OVER,!1),this._set(h.START,!0),this._set(h.PLAYING,!0))},t.prototype.isColorEnabled=function(){return this._state.get(h.COLOR_ENABLED)},t.prototype.setColorEnabled=function(t){this._set(h.COLOR_ENABLED,t)},t.prototype.isMuted=function(){return this._state.get(h.MUTED)},t.prototype.setMuted=function(t){this._set(h.MUTED,t)},t.prototype.toggleColorEnabled=function(){this.setColorEnabled(!this.isColorEnabled())},t.prototype.toggleMuted=function(){this.setMuted(!this.isMuted())},t.prototype.subscribe=function(t,e){this._subscribe(t,e)},t.prototype.unsubscribe=function(t,e){this._unsubscribe(t,e)},t.prototype.subscribeForTitleScreen=function(t,e){this._subscribe(t,e,v.TITLE)},t.prototype.unsubscribeForTitleScreen=function(t,e){this._unsubscribe(t,e,v.TITLE)},t.prototype.subscribeForGameOverScreen=function(t,e){this._subscribe(t,e,v.GAMEOVER)},t.prototype.unsubscribeForGameOverScreen=function(t,e){this._unsubscribe(t,e,v.GAMEOVER)},t.prototype.subscribeForPlayingScreen=function(t,e){this._subscribe(t,e,v.PLAYING)},t.prototype.unsubscribeForPlayingScreen=function(t,e){this._unsubscribe(t,e,v.PLAYING)},t.prototype.subscribeForPausedScreen=function(t,e){this._subscribe(t,e,v.PAUSED)},t.prototype.unsubscribeForPausedScreen=function(t,e){this._unsubscribe(t,e,v.PAUSED)},t.prototype._subscribe=function(t,e,i){m.subscribe(t,e,i)},t.prototype._unsubscribe=function(t,e,i){m.unsubscribe(t,e,i)},t.prototype.getDebugData=function(){return{on:this.isOn(),start:this.isStarted(),playing:this.isPlaying(),paused:this.isPaused(),game_over:this.isGameOver(),color_enabled:this.isColorEnabled(),muted:this.isMuted()}},t}();var q=function(){function t(){this.defaultFontFamily="retro-gamming",this.fontSizes=[0]}return t.prototype.setup=function(){var t=B.p,e=p.screenLayout.fontSize,i=e.extraSmall,n=e.small,o=e.medium,r=e.large,a=e.extraLarge;t.textFont(this.defaultFontFamily),this.fontSizes=[],this.fontSizes[s.EXTRA_SMALL]=N.getRelativeWidth(i),this.fontSizes[s.SMALL]=N.getRelativeWidth(n),this.fontSizes[s.MEDIUM]=N.getRelativeWidth(o),this.fontSizes[s.LARGE]=N.getRelativeWidth(r),this.fontSizes[s.EXTRA_LARGE]=N.getRelativeWidth(a)},t.prototype.setRendererMetrics=function(t){this._rendererMetrics=t},t.prototype.setTextState=function(t){var e=B.p,i=p.colors,n=i.active,o=i.inactive;e.fill(t?n:o)},t.prototype.setActiveText=function(){this.setTextState(!0)},t.prototype.setInactiveText=function(){this.setTextState(!1)},t.prototype.setTextSize=function(t){B.p.textSize(this.fontSizes[t])},t.prototype.setTextAlign=function(t,e){B.p.textAlign(t,e)},t.prototype.textOnHud=function(t,e){var i=B.p,n=U.getHudPosX(e.x,this._rendererMetrics.display.width),o=U.getHudPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.textOnDisplay=function(t,e){var i=B.p,n=U.getDisplayPosX(e.x,this._rendererMetrics.display.width),o=U.getDisplayPosY(e.y,this._rendererMetrics.display.height);i.text(t,n,o)},t.prototype.getDebugData=function(){return{current_font_family:this.defaultFontFamily,font_sizes_count:this.fontSizes.length}},t}();const Q=q,$=function(){function t(){this._tickAccumulator=0,this._initialTickInterval=p.game.tickInterval,this._minTickInterval=p.game.minTickInterval,this._tickInterval=p.game.tickInterval,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=0,this.serialId="time"}return t.prototype.setup=function(){this.reset()},t.prototype.update=function(t){this._tickAccumulator+=t,this._totalElapsedTime+=t,this._fps=1e3/t,this._timeSinceLastTpsUpdate+=t,this._timeSinceLastTpsUpdate>=1e3&&(this._tps=this._tickCounter,this._tickCounter=0,this._timeSinceLastTpsUpdate-=1e3)},t.prototype.shouldTick=function(){return this._tickAccumulator>=this._tickInterval&&(this._tickAccumulator-=this._tickInterval,this._tickCounter++,this._totalTicks++,!0)},t.prototype.reset=function(){this._tickAccumulator=0,this._fps=0,this._tps=0,this._tickCounter=0,this._totalTicks=0,this._timeSinceLastTpsUpdate=0,this._totalElapsedTime=0,this._tickInterval=this._initialTickInterval},Object.defineProperty(t.prototype,"tickInterval",{get:function(){return this._tickInterval},set:function(t){this._tickInterval=t},enumerable:!1,configurable:!0}),t.prototype.incrementTickInterval=function(t){this.tickInterval=this._tickInterval+t},t.prototype.decrementTickInterval=function(t){var e=Math.max(this._minTickInterval,this._tickInterval-t);this.tickInterval=e},t.prototype.getDebugData=function(){return{fps:Math.round(this._fps),tps:this._tps,tick_interval:this._tickInterval.toFixed(2),tick_accumulator:this._tickAccumulator.toFixed(2)}},t.prototype.serialize=function(){return JSON.stringify({tickInterval:this._tickInterval})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._tickInterval=e.tickInterval},t.prototype.setTickInterval=function(t){this._tickInterval=t},t.prototype.setMinTickInterval=function(t){this._minTickInterval=t},Object.defineProperty(t.prototype,"totalTicks",{get:function(){return this._totalTicks},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"elapsedTime",{get:function(){return this._totalElapsedTime},enumerable:!1,configurable:!0}),t.prototype.isTickEvery=function(t){return this._totalTicks>0&&this._totalTicks%t===0},t.prototype.captureInitialState=function(){this._initialTickInterval=this._tickInterval},t}();var Z=function(t,e,i,n){return new(i||(i=Promise))(function(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())})},tt=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])}}},et=function(){function t(){this._buffers=new Map,this._activeSources=new Map,this._volume=1}return t.prototype.setup=function(){var t=p.game.sound.volume;this._volume=t;var e=window.AudioContext||window.webkitAudioContext;this._audioContext=new e({latencyHint:"interactive"}),this._gainNode=this._audioContext.createGain(),this._gainNode.connect(this._audioContext.destination),this._updateGain(),this._loadAll()},t.prototype.play=function(t){return Z(this,void 0,void 0,function(){var e,i,n;return tt(this,function(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 Z(this,void 0,void 0,function(){var e;return tt(this,function(i){return(e=this._activeSources.get(t))&&(e.forEach(function(t){try{t.stop()}catch(t){}}),e.length=0),[2]})})},t.prototype.stopAll=function(){return Z(this,void 0,void 0,function(){var t,e,i,n;return tt(this,function(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 Z(this,void 0,void 0,function(){var t,e=this;return tt(this,function(i){switch(i.label){case 0:return t=Object.values(u).map(function(t){return Z(e,void 0,void 0,function(){var e,i,n;return tt(this,function(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(h.MUTED,function(){e._updateGain()}),this._updateGain()},t.prototype.getDebugData=function(){var t=0;return this._activeSources.forEach(function(e){return t+=e.length}),{muted:!!this._state&&this._state.isMuted(),volume:this._volume,active_sources:t,loaded_buffers:this._buffers.size}},t}();const it=et,nt=function(){function t(){this._score=0,this._multiplier=1,this._level=1,this._maxLevel=10,this._highScore=0,this._gameId="unknown",this.serialId="score"}return t.prototype.setupGameHighScore=function(t){this._gameId=t,this._highScore=Number(localStorage.getItem("".concat(this._gameId,"::highScore")))},t.prototype.increaseScore=function(t){this._score+=t*this._multiplier,this._score>this._highScore&&(this.highScore=this._score)},t.prototype.resetScore=function(){this._score=0},t.prototype.getFormattedScore=function(t){return void 0===t&&(t=6),this._score.toString().padStart(t,"0")},t.prototype.increaseLevel=function(t){this._level+=t},t.prototype.resetLevel=function(){this._level=1},Object.defineProperty(t.prototype,"multiplier",{get:function(){return this._multiplier},set:function(t){this._multiplier=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"level",{get:function(){return this._level},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"score",{get:function(){return this._score},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxLevel",{get:function(){return this._maxLevel},set:function(t){this._maxLevel=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"highScore",{get:function(){return this._highScore},set:function(t){this._highScore=t,localStorage.setItem("".concat(this._gameId,"::highScore"),t.toString())},enumerable:!1,configurable:!0}),t.prototype.getDebugData=function(){return{score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel}},t.prototype.serialize=function(){return JSON.stringify({score:this._score,multiplier:this._multiplier,level:this._level,max_level:this._maxLevel})},t.prototype.deserialize=function(t){var e=JSON.parse(t);this._score=e.score,this._multiplier=e.multiplier,this._level=e.level,this._maxLevel=e.max_level},t}();var ot,rt=(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 st=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.serialId="hud_grid",e}return rt(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return 4},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return 4},enumerable:!1,configurable:!0}),e.prototype.serialize=function(){return JSON.stringify({grid:this._grid})},e.prototype.deserialize=function(t){var e=JSON.parse(t);this._grid=e.grid},e}(k),at=function(){function t(){}return t.isSerializable=function(t){if(null==t)return!1;var e=t,i="function"==typeof e.serialize,n="function"==typeof e.deserialize,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 J)},t.isDebuggable=function(t){return null!=t&&"function"==typeof t.getDebugData},t}();var ut=function(){function t(){this._initialState=new Map,this._baseProperties=[]}return t.prototype.captureBaseProperties=function(t){this._baseProperties=Object.keys(t)},t.prototype.captureInitialState=function(t){var e=this;console.log("capturing initial state for snapshot"),Object.entries(t).forEach(function(t){var i=t[0],n=t[1];if(!e._baseProperties.includes(i)&&"function"!=typeof n){var 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 ct=ut,lt=function(){function t(){this._isSessionResolved=!1,this._isModalOpen=!1,this._isEnabled=!0,this._resetFn=function(){},this._serializables=[]}return t.prototype.register=function(t){this._serializables.push(t)},t.prototype.saveSession=function(){var t=this;this._isSessionResolved&&this._isEnabled&&this._serializables.forEach(function(e){localStorage.setItem(t._key(e.serialId),e.serialize())})},t.prototype.clearSession=function(){var t=this;this._serializables.forEach(function(e){localStorage.removeItem(t._key(e.serialId))})},t.prototype.setShowModalFunction=function(t){this._showSessionModal=t},t.prototype.setResetFunction=function(t){this._resetFn=t},t.prototype.setSessionEnabled=function(t){this._isEnabled=t},t.prototype.isModalOpen=function(){return this._isModalOpen},t.prototype.isSessionResolved=function(){return this._isSessionResolved},t.prototype._hasSession=function(){var t=this;return this._serializables.every(function(e){return null!==localStorage.getItem(t._key(e.serialId))})},t.prototype._loadSession=function(){var t=this;this._serializables.forEach(function(e){var i=localStorage.getItem(t._key(e.serialId));i&&e.deserialize(i)})},t.prototype.syncState=function(t){var e=this;t.subscribe(h.PLAYING,function(t){if(t&&!e._isSessionResolved){if(!e._hasSession()||!e._isEnabled)return void(e._isSessionResolved=!0);e._isModalOpen=!0,e._showSessionModal(function(){e._loadSession(),e._isModalOpen=!1,e._isSessionResolved=!0},function(){e.clearSession(),e._resetFn(),e._isModalOpen=!1,e._isSessionResolved=!0})}}),t.subscribe(h.ON,function(t){t||(e._isModalOpen=!1,e._isSessionResolved=!1)}),t.subscribe(h.START,function(t){t||(e._isSessionResolved=!1)})},t.prototype.getDebugData=function(){return{game_id:this.gameId,is_session_resolved:this._isSessionResolved,is_modal_open:this._isModalOpen,is_enabled:this._isEnabled,serializables:this._serializables.map(function(t){return t.serialId}).join(", ")}},t.prototype._key=function(t){return"".concat(this.gameId,"::").concat(t)},t}(),ht=function(){function t(){}return t.setupControlEvents=function(t,e){var i=t.control,n=t.state,o=t.session,r=t.sound;i.subscribe(c.SOUND,l.PRESSED,function(){return n.toggleMuted()}),i.subscribe(c.COLOR,l.PRESSED,function(){return n.toggleColorEnabled()}),i.subscribe(c.EXIT,l.PRESSED,function(){return o.clearSession()}),i.subscribe(c.POWER,l.PRESSED,function(){n.isOn()?(n.turnOff(),r.stopAll()):n.turnOn()}),i.subscribeForGameOverScreen(c.POWER,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForTitleScreen(c.START_PAUSE,l.PRESSED,function(){return n.startGame()}),i.subscribeForPlayingScreen(c.START_PAUSE,l.PRESSED,function(){return n.pause()}),i.subscribeForGameOverScreen(c.START_PAUSE,l.PRESSED,function(){e(),n.resetGameOver()}),i.subscribeForPausedScreen(c.START_PAUSE,l.PRESSED,function(){return n.resume()}),i.subscribeForPlayingScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()}),i.subscribeForPausedScreen(c.RESET,l.PRESSED,function(){e(),n.resetGame()})},t.setupStateEvents=function(t){var e=t.state,i=t.session;e.subscribe(h.ON,function(e){e||(t.grid.resetGrid(),t.score.resetScore(),t.score.resetLevel(),t.time.reset())}),e.subscribeForGameOverScreen(h.GAME_OVER,function(){i.clearSession()})},t}();var dt=function(){function t(t){this._modules=void 0,this._initialStateSnapshot=new ct,this._gameId="unknown",this._view=t,this._initialStateSnapshot.captureBaseProperties(this)}return Object.defineProperty(t.prototype,"gameId",{get:function(){return this._gameId},set:function(t){this._gameId=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"modules",{get:function(){return this._modules},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"p",{get:function(){return B.p},enumerable:!1,configurable:!0}),t.prototype.setup=function(){var t=this;this._view.build(),this._modules={renderer:new Y,grid:new k,hudGrid:new st,text:new Q,state:new J,control:new b,time:new $,sound:new it,score:new nt,session:new lt},Object.values(this._modules).forEach(function(t){at.isInitializable(t)&&t.setup()}),Object.values(this._modules).forEach(function(e){at.isStateSyncable(e)&&e.syncState(t._modules.state)}),Object.values(this._modules).forEach(function(e){at.isSerializable(e)&&t._modules.session.register(e)});var e=this._modules,i=e.text,n=e.control,o=e.renderer,r=e.session,s=e.score;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),s.setupGameHighScore(this.gameId),this.setupGame(),ht.setupControlEvents(this._modules,this.reset.bind(this)),ht.setupStateEvents(this._modules),this._view.bindControls(n),this._modules.time.captureInitialState(),this._initialStateSnapshot.captureInitialState(this)},t.prototype.draw=function(){var t=B.p;if(this._modules){var e=this._modules,i=e.renderer,n=e.grid,o=e.time,r=e.state,s=e.session;s.isModalOpen()||r.isPlaying()&&!s.isSessionResolved()||(i.render(n.getGrid(),this._modules),r.isOn()&&(r.isStarted()?r.isPlaying()?(o.update(t.deltaTime),o.shouldTick()&&(this.update(t.deltaTime),this._modules.session.saveSession()),this.render()):r.isPaused()&&this.render():this.drawTitleScreen(),r.isGameOver()&&this.drawGameOverScreen()))}},t.prototype.destroy=function(){B.p.noLoop(),this._modules&&(this._modules.control.unbindControls(),this._modules.sound.stopAll())},t.prototype.reset=function(){this._modules.grid.resetGrid(),this._modules.score.resetScore(),this._modules.score.resetLevel(),this._modules.time.reset(),this._modules.session.clearSession(),this._initialStateSnapshot.restoreInitialState(this)},t}();const pt=dt;var ft={grad:.9,turn:360,rad:360/(2*Math.PI)},gt=function(t){return"string"==typeof t?t.length>0:"number"==typeof t},yt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=Math.pow(10,e)),Math.round(i*t)/i+0},vt=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),t>i?i:t>e?t:e},mt=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},_t=function(t){return{r:vt(t.r,0,255),g:vt(t.g,0,255),b:vt(t.b,0,255),a:vt(t.a)}},bt=function(t){return{r:yt(t.r),g:yt(t.g),b:yt(t.b),a:yt(t.a,3)}},Et=/^#([0-9a-f]{3,8})$/i,St=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},wt=function(t){var e=t.r,i=t.g,n=t.b,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}},Pt=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}},Rt=function(t){return{h:mt(t.h),s:vt(t.s,0,100),l:vt(t.l,0,100),a:vt(t.a)}},Ct=function(t){return{h:yt(t.h),s:yt(t.s),l:yt(t.l),a:yt(t.a,3)}},xt=function(t){return Pt((i=(e=t).s,{h:e.h,s:(i*=((n=e.l)<50?n:100-n)/100)>0?2*i/(n+i)*100:0,v:n+i,a:e.a}));var e,i,n},Ot=function(t){return{h:(e=wt(t)).h,s:(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},Tt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,At=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,It=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mt={string:[[function(t){var e=Et.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:4===t.length?yt(parseInt(t[3]+t[3],16)/255,2):1}:6===t.length||8===t.length?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:8===t.length?yt(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=It.exec(t)||Lt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:_t({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:void 0===e[7]?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Tt.exec(t)||At.exec(t);if(!e)return null;var i,n,o=Rt({h:(i=e[1],n=e[2],void 0===n&&(n="deg"),Number(i)*(ft[n]||1)),s:Number(e[3]),l:Number(e[4]),a:void 0===e[5]?1:Number(e[5])/(e[6]?100:1)});return xt(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 gt(e)&>(i)&>(n)?_t({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(!gt(e)||!gt(i)||!gt(n))return null;var s=Rt({h:Number(e),s:Number(i),l:Number(n),a:Number(r)});return xt(s)},"hsl"],[function(t){var e=t.h,i=t.s,n=t.v,o=t.a,r=void 0===o?1:o;if(!gt(e)||!gt(i)||!gt(n))return null;var s=function(t){return{h:mt(t.h),s:vt(t.s,0,100),v:vt(t.v,0,100),a:vt(t.a)}}({h:Number(e),s:Number(i),v:Number(n),a:Number(r)});return Pt(s)},"hsv"]]},Dt=function(t,e){for(var i=0;i<e.length;i++){var n=e[i][0](t);if(n)return[n,e[i][1]]}return[null,void 0]},Gt=function(t,e){var i=Ot(t);return{h:i.h,s:vt(i.s+100*e,0,100),l:i.l,a:i.a}},kt=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},Bt=function(t,e){var i=Ot(t);return{h:i.h,s:i.s,l:vt(i.l+100*e,0,100),a:i.a}},Nt=function(){function t(t){this.parsed=function(t){return"string"==typeof t?Dt(t.trim(),Mt.string):"object"==typeof t&&null!==t?Dt(t,Mt.object):[null,void 0]}(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return null!==this.parsed},t.prototype.brightness=function(){return yt(kt(this.rgba),2)},t.prototype.isDark=function(){return kt(this.rgba)<.5},t.prototype.isLight=function(){return kt(this.rgba)>=.5},t.prototype.toHex=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,r=(o=t.a)<1?St(yt(255*o)):"","#"+St(e)+St(i)+St(n)+r;var t,e,i,n,o,r},t.prototype.toRgb=function(){return bt(this.rgba)},t.prototype.toRgbString=function(){return e=(t=bt(this.rgba)).r,i=t.g,n=t.b,(o=t.a)<1?"rgba("+e+", "+i+", "+n+", "+o+")":"rgb("+e+", "+i+", "+n+")";var t,e,i,n,o},t.prototype.toHsl=function(){return Ct(Ot(this.rgba))},t.prototype.toHslString=function(){return e=(t=Ct(Ot(this.rgba))).h,i=t.s,n=t.l,(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=wt(this.rgba),{h:yt(t.h),s:yt(t.s),v:yt(t.v),a:yt(t.a,3)};var t},t.prototype.invert=function(){return zt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},t.prototype.saturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,t))},t.prototype.desaturate=function(t){return void 0===t&&(t=.1),zt(Gt(this.rgba,-t))},t.prototype.grayscale=function(){return zt(Gt(this.rgba,-1))},t.prototype.lighten=function(t){return void 0===t&&(t=.1),zt(Bt(this.rgba,t))},t.prototype.darken=function(t){return void 0===t&&(t=.1),zt(Bt(this.rgba,-t))},t.prototype.rotate=function(t){return void 0===t&&(t=15),this.hue(this.hue()+t)},t.prototype.alpha=function(t){return"number"==typeof t?zt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):yt(this.rgba.a,3);var e},t.prototype.hue=function(t){var e=Ot(this.rgba);return"number"==typeof t?zt({h:t,s:e.s,l:e.l,a:e.a}):yt(e.h)},t.prototype.isEqual=function(t){return this.toHex()===zt(t).toHex()},t}(),zt=function(t){return t instanceof Nt?t:new Nt(t)};function Ft(t,e){var i=B.p,n=i.createDiv();n.parent(t),n.addClass("btn-container");var o=i.createButton(e);return o.parent(n),o.addClass("btn"),o}function Ht(t,e,i){var n=B.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 Ut=function(){function t(t){this._moduleElements=[],this._gameModules=t}return t.prototype.setup=function(){var t=this;if(p.game.debugger.enabled){var e=B.p,i=e.select("#debugger"),n=!!i&&i.elt.hasAttribute("open"),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 jt=Ut;var Vt=function(){function t(){}return t.prototype.setup=function(){var t=B.p;this._container=t.createDiv(),this._container.parent(t.select("body")),this._container.id("modal-background"),this._container.class("hidden");var e=t.createDiv();e.parent(this._container),e.id("session-modal");var i=t.createDiv();i.parent(e),i.id("session-modal-frame");var n=t.createP();n.parent(i),n.html("Brick Engine Session");var 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 Wt=Vt;var Yt=function(){function t(t){this._parent=t}return t.prototype.isBodyBuilt=function(){return null!=this._cachedCanvas},t.prototype.build=function(){if(this._cachedCanvas)return this._cachedCanvas;var t,e,i,n,o;t=document.querySelector(":root"),e=window.location.href.substring(window.location.href.indexOf("?")+1),n=(i=new URLSearchParams(e)).has(p.inputQueryParams.mainColor)?i.get(p.inputQueryParams.mainColor):p.colors.bodyMain,o=i.has(p.inputQueryParams.buttonColor)?i.get(p.inputQueryParams.buttonColor):p.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=B.p.createDiv();if(i.parent(p.selectors.parent),i.id(p.selectors.viewElementIds.container),t.clientWidth<=p.viewLayout.mobileBreakpoint)return{container:i,width:e=t.clientWidth,height:t.clientHeight};var n=t.clientHeight/(1.05*p.viewLayout.bodyHeightWidthMultiplier);return{container:i,width:e=Math.min(t.clientWidth,n),height:e*p.viewLayout.bodyHeightWidthMultiplier}}(this._parent),s=r.container,a=r.height,u=r.width,c=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.frame);var n=e.createDiv();return n.parent(i),e.createP("Brick Game").parent(n),i}(s),l=function(t,e){var i=B.p,n=e*p.viewLayout.canvas.widthRatio,o=n*p.viewLayout.canvas.aspectRatio,r=i.createCanvas(n,o);return r.parent(t),r.id(p.selectors.viewElementIds.canvas),{canvasWidth:n,canvasHeight:o,canvas:r}}(c,u),h=l.canvas,d=l.canvasHeight,f=l.canvasWidth,g=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.id(p.selectors.viewElementIds.buttonContainer);var n=e.createDiv();n.parent(i),n.id(p.selectors.viewElementIds.smallButtonContainer);var o=e.createDiv();o.parent(i),o.id(p.selectors.viewElementIds.innerButtonContainer);var r=e.createDiv();r.parent(o),r.id(p.selectors.viewElementIds.mediumButtonContainer);var s=e.createDiv();s.parent(r),s.id(p.selectors.viewElementIds.directionVerticalContainer);var a=e.createDiv();a.parent(r),a.id(p.selectors.viewElementIds.directionHorizontalContainer);var u=e.createDiv();return u.parent(o),u.id(p.selectors.viewElementIds.largeButtonContainer),{smallButtonContainer:n,mediumButtonContainer:r,largeButtonContainer:u,directionVerticalContainer:s,directionHorizontalContainer:a}}(s),y=g.largeButtonContainer,v=g.smallButtonContainer,m=g.directionHorizontalContainer,_=g.directionVerticalContainer;return this._onOffBtn=Ht(v,"On<br/>Off",!0),this._startPauseBtn=Ht(v,"Start<br/>Pause",!1),this._soundBtn=Ht(v,"Sound",!0),this._resetBtn=Ht(v,"Reset",!1),this._exitBtn=Ht(v,"Exit",!0),this._enableColorBtn=Ht(v,"Enable<br/>Colors",!1),this._upBtn=Ft(_,"UP"),this._leftBtn=Ft(m,"LEFT"),this._downBtn=Ft(_,"DOWN"),this._rightBtn=Ft(m,"RIGHT"),this._actionBtn=function(t){var e=B.p,i=e.createDiv();i.parent(t),i.addClass("lg-btn-container");var n=e.createButton("Action");return n.parent(i),n.addClass("lg-btn"),n}(y),function(t,e,i,n){var o=document.querySelector(":root");o.style.setProperty("--dispersion",p.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*p.viewLayout.dimensions.borderRadiusRatio,"px")),o.style.setProperty("--border","".concat(t*p.viewLayout.dimensions.borderWidthRatio,"px solid black")),o.style.setProperty("--sm-button-size","".concat(t*p.viewLayout.dimensions.button.smSizeRatio,"px")),o.style.setProperty("--button-size","".concat(t*p.viewLayout.dimensions.button.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size","".concat(t*p.viewLayout.dimensions.button.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.smSizeRatio,"px")),o.style.setProperty("--button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.mdSizeRatio,"px")),o.style.setProperty("--lg-button-size-mobile","".concat(t*p.viewLayout.dimensions.button.mobile.lgSizeRatio,"px")),o.style.setProperty("--sm-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--sm-button-size-mobile-line-height","".concat(t*p.viewLayout.dimensions.button.mobile.smFontRatio,"px")),o.style.setProperty("--button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.fontRatio,"px")),o.style.setProperty("--lg-button-size-mobile-font-size","".concat(t*p.viewLayout.dimensions.button.mobile.lgFontRatio,"px")),o.style.setProperty("--button-size-mobile-spacing","".concat(t*p.viewLayout.dimensions.button.mobile.spacingRatio,"px")),o.style.setProperty("--button-border","".concat(t*p.viewLayout.dimensions.button.borderRatio,"px solid black")),o.style.setProperty("--button-animation-duration",p.viewLayout.dimensions.button.animationDuration)}(u,a,f,d),this._hideSplash(),this._cachedCanvas={canvas:h,canvasWidth:f,canvasHeight:d},this._cachedCanvas},t.prototype.setupSessionModal=function(){this._sessionModal=new Wt,this._sessionModal.setup()},t.prototype.showSessionModal=function(t,e){this._sessionModal.show(t,e)},t.prototype.setupDebugger=function(t){this._debugger=new jt(t),this._debugger.setup()},t.prototype.updateDebuggerGameModules=function(t){this._debugger.setGameModules(t)},t.prototype.updateDebugger=function(){this._debugger.update()},t.prototype.bindControls=function(t){this._inputHandler=new f(t),this._bindButtonEvents(this._onOffBtn,c.POWER),this._bindButtonEvents(this._startPauseBtn,c.START_PAUSE),this._bindButtonEvents(this._soundBtn,c.SOUND),this._bindButtonEvents(this._resetBtn,c.RESET),this._bindButtonEvents(this._exitBtn,c.EXIT),this._bindButtonEvents(this._enableColorBtn,c.COLOR),this._bindButtonEvents(this._upBtn,c.UP),this._bindButtonEvents(this._downBtn,c.DOWN),this._bindButtonEvents(this._rightBtn,c.RIGHT),this._bindButtonEvents(this._leftBtn,c.LEFT),this._bindButtonEvents(this._actionBtn,c.ACTION)},t.prototype.unbindControls=function(){this._onOffBtn.mousePressed(function(){}).mouseReleased(function(){}),this._startPauseBtn.mousePressed(function(){}).mouseReleased(function(){}),this._soundBtn.mousePressed(function(){}).mouseReleased(function(){}),this._resetBtn.mousePressed(function(){}).mouseReleased(function(){}),this._exitBtn.mousePressed(function(){}).mouseReleased(function(){}),this._enableColorBtn.mousePressed(function(){}).mouseReleased(function(){}),this._upBtn.mousePressed(function(){}).mouseReleased(function(){}),this._downBtn.mousePressed(function(){}).mouseReleased(function(){}),this._rightBtn.mousePressed(function(){}).mouseReleased(function(){}),this._leftBtn.mousePressed(function(){}).mouseReleased(function(){}),this._actionBtn.mousePressed(function(){}).mouseReleased(function(){})},t.prototype._bindButtonEvents=function(t,e){var i=this;t.mousePressed(function(){return i._inputHandler.handlePress(e)}),t.mouseReleased(function(){return i._inputHandler.handleRelease(e)}),t.mouseOut(function(){return i._inputHandler.handleRelease(e)})},t.prototype._hideSplash=function(t){void 0===t&&(t=p.viewLayout.splashHideDelayMs);var e=document.querySelector(p.selectors.splash);setTimeout(function(){e.style.display="none"},t)},t}();const Kt=Yt;var Xt,Jt=n(991),qt=n.n(Jt);function Qt(t){Xt=t}function $t(t){return window.BrickEngineGame=t,new(qt())(function(e){B.init(e);var i=new Kt(document.body);Qt(new t(i)),"unknown"===Xt.gameId&&(Xt.gameId="game"),e.setup=function(){Xt.setup(),Xt.view.setupDebugger(Xt.modules),Xt.view.setupSessionModal()},e.draw=function(){Xt.draw(),Xt.view.updateDebugger()}})}return d})());
|
|
@@ -39,6 +39,30 @@ export default class GameGrid implements Grid, Debuggable, Serializable {
|
|
|
39
39
|
* @returns {number} The grid height.
|
|
40
40
|
*/
|
|
41
41
|
get height(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the index of the top-most row.
|
|
44
|
+
*
|
|
45
|
+
* @returns {number} The top row index.
|
|
46
|
+
*/
|
|
47
|
+
get topRow(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the index of the bottom-most row.
|
|
50
|
+
*
|
|
51
|
+
* @returns {number} The bottom row index.
|
|
52
|
+
*/
|
|
53
|
+
get bottomRow(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the index of the left-most column.
|
|
56
|
+
*
|
|
57
|
+
* @returns {number} The left column index.
|
|
58
|
+
*/
|
|
59
|
+
get leftColumn(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the index of the right-most column.
|
|
62
|
+
*
|
|
63
|
+
* @returns {number} The right column index.
|
|
64
|
+
*/
|
|
65
|
+
get rightColumn(): number;
|
|
42
66
|
/**
|
|
43
67
|
* Initializes the grid by resetting its content to an empty state.
|
|
44
68
|
*
|
|
@@ -66,7 +90,7 @@ export default class GameGrid implements Grid, Debuggable, Serializable {
|
|
|
66
90
|
* @param {Coordinate} coordinate - The coordinate to validate.
|
|
67
91
|
* @returns {boolean} True if the coordinate is valid, false otherwise.
|
|
68
92
|
*/
|
|
69
|
-
|
|
93
|
+
isCoordinateValid(coordinate: Coordinate): boolean;
|
|
70
94
|
/**
|
|
71
95
|
* Retrieves a cell at a specific coordinate.
|
|
72
96
|
*
|
|
@@ -6,14 +6,17 @@ import { Serializable } from '../../types/Interfaces';
|
|
|
6
6
|
* Handles the game loop timing and debug statistics (FPS, TPS).
|
|
7
7
|
*/
|
|
8
8
|
export default class GameTime implements Time, Debuggable, Serializable {
|
|
9
|
-
protected
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
protected _tickAccumulator: number;
|
|
10
|
+
/** The tick interval at the start of the game session. Used for resets. */
|
|
11
|
+
private _initialTickInterval;
|
|
12
|
+
private _minTickInterval;
|
|
13
|
+
private _tickInterval;
|
|
14
|
+
private _fps;
|
|
15
|
+
private _tps;
|
|
16
|
+
private _tickCounter;
|
|
17
|
+
private _totalTicks;
|
|
18
|
+
private _timeSinceLastTpsUpdate;
|
|
19
|
+
private _totalElapsedTime;
|
|
17
20
|
serialId: string;
|
|
18
21
|
/**
|
|
19
22
|
* Initializes the time module.
|
|
@@ -73,4 +76,28 @@ export default class GameTime implements Time, Debuggable, Serializable {
|
|
|
73
76
|
deserialize(data: string): void;
|
|
74
77
|
setTickInterval(interval: number): void;
|
|
75
78
|
setMinTickInterval(interval: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the total number of ticks since the game started.
|
|
81
|
+
*
|
|
82
|
+
* @returns {number} Total tick count.
|
|
83
|
+
*/
|
|
84
|
+
get totalTicks(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the total elapsed time in milliseconds.
|
|
87
|
+
*
|
|
88
|
+
* @returns {number} Elapsed time in ms.
|
|
89
|
+
*/
|
|
90
|
+
get elapsedTime(): number;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if the current total tick count is a multiple of the provided interval.
|
|
93
|
+
*
|
|
94
|
+
* @param {number} interval - The tick interval to check.
|
|
95
|
+
* @returns {boolean} True if the current tick is a multiple of the interval.
|
|
96
|
+
*/
|
|
97
|
+
isTickEvery(interval: number): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Captures the current tick interval as the initial state.
|
|
100
|
+
* This is useful for restoring the game speed on reset.
|
|
101
|
+
*/
|
|
102
|
+
captureInitialState(): void;
|
|
76
103
|
}
|
|
@@ -96,9 +96,17 @@ export interface Grid extends Initializable {
|
|
|
96
96
|
*/
|
|
97
97
|
getGrid(): Cell[][];
|
|
98
98
|
/** The number of columns in the grid. */
|
|
99
|
-
width: number;
|
|
99
|
+
readonly width: number;
|
|
100
100
|
/** The number of rows in the grid. */
|
|
101
|
-
height: number;
|
|
101
|
+
readonly height: number;
|
|
102
|
+
/** The index of the top-most row (always 0). */
|
|
103
|
+
readonly topRow: number;
|
|
104
|
+
/** The index of the bottom-most row. */
|
|
105
|
+
readonly bottomRow: number;
|
|
106
|
+
/** The index of the left-most column (always 0). */
|
|
107
|
+
readonly leftColumn: number;
|
|
108
|
+
/** The index of the right-most column. */
|
|
109
|
+
readonly rightColumn: number;
|
|
102
110
|
/**
|
|
103
111
|
* Resets the entire grid to its empty state.
|
|
104
112
|
*/
|
|
@@ -115,7 +123,7 @@ export interface Grid extends Initializable {
|
|
|
115
123
|
* @param {Coordinate} coordinate - The coordinate to check.
|
|
116
124
|
* @returns {boolean} `true` if valid, `false` otherwise.
|
|
117
125
|
*/
|
|
118
|
-
|
|
126
|
+
isCoordinateValid(coordinate: Coordinate): boolean;
|
|
119
127
|
/**
|
|
120
128
|
* Retrieves a cell at a specific location.
|
|
121
129
|
*
|
|
@@ -625,6 +633,17 @@ export interface Control extends Initializable {
|
|
|
625
633
|
export interface Time extends Initializable {
|
|
626
634
|
/** The interval between logic ticks in milliseconds. */
|
|
627
635
|
tickInterval: number;
|
|
636
|
+
/** The total number of ticks since the game started. */
|
|
637
|
+
readonly totalTicks: number;
|
|
638
|
+
/** Total elapsed time in milliseconds since the game started. */
|
|
639
|
+
readonly elapsedTime: number;
|
|
640
|
+
/**
|
|
641
|
+
* Checks if enough time has passed for a game tick based on a specific interval.
|
|
642
|
+
*
|
|
643
|
+
* @param {number} interval - The tick interval to check.
|
|
644
|
+
* @returns {boolean} `true` if the current tick is a multiple of the interval.
|
|
645
|
+
*/
|
|
646
|
+
isTickEvery(interval: number): boolean;
|
|
628
647
|
/**
|
|
629
648
|
* Accumulates passed time and calculates FPS/TPS.
|
|
630
649
|
*
|
|
@@ -665,6 +684,11 @@ export interface Time extends Initializable {
|
|
|
665
684
|
* @param {number} interval - The new minimum tick interval in milliseconds.
|
|
666
685
|
*/
|
|
667
686
|
setMinTickInterval(interval: number): void;
|
|
687
|
+
/**
|
|
688
|
+
* Captures the current tick interval as the initial state.
|
|
689
|
+
* Use this after games have set their starting speed.
|
|
690
|
+
*/
|
|
691
|
+
captureInitialState(): void;
|
|
668
692
|
}
|
|
669
693
|
/**
|
|
670
694
|
* Interface for the audio module.
|