import { Container } from '@pixi/display'; import { DynamicReel, Grid } from '.'; import { ColumnState, GridProps } from './types'; export class DynamicGridCollection extends Container { private _gridA: Grid; private _gridB: Grid; private _columnsStates: ColumnState[]; public get columnsStates(): ColumnState[] { return this._columnsStates; } public set columnsStates(value: ColumnState[]) { this._columnsStates = value; } public get gridA() { return this._gridA; } public get gridB() { return this._gridB; } constructor( private _staticGrid: Grid, private _dynamicGridsProps: GridProps ) { super(); this.createGrids(); this.moveGridToInitTopPos(this._gridA, this._gridB); this._gridA.copySymbols(this._staticGrid); this._columnsStates = Array(this._dynamicGridsProps.reelProps.length).fill(ColumnState.Ready); } /** * Creates the two dynamic grids */ private createGrids() { this._gridA = new Grid(DynamicReel, {...this._dynamicGridsProps}); this._gridB = new Grid(DynamicReel, {...this._dynamicGridsProps}); this.addChild(this._gridA, this._gridB); } /** * Moves the grid to the initial top position * @param base the base grid * @param gridToMove grid that will be moved on top of the base grid */ private moveGridToInitTopPos(base: Grid, gridToMove: Grid) { base.reels.forEach((reel, index) => { const delta = (gridToMove.reels[index].getBounds().bottom - reel.getBounds().top) + this._dynamicGridsProps.reelProps[index].stepY; gridToMove.reels[index].position.y -= delta; }); gridToMove.setResetPositions(); } public setColumnVisibility(columnIndex: number, visible: boolean) { this._gridA.setReelVisibility(columnIndex, visible); this._gridB.setReelVisibility(columnIndex, visible); } public resetColumns() { this._gridA.reset(); this._gridB.reset(); this._gridA.copySymbols(this._staticGrid); } }