import FD from '../core/factorioData' ; import { Tile } from '../core/Tile' ; import { TileContainer } from './TileContainer' ; import { PaintContainer } from './PaintContainer' ; import { BlueprintContainer } from './BlueprintContainer' ; export class PaintTileContainer extends PaintContainer { private static size = 2 ; public constructor ( bpc , name ) { super ( bpc , name ) ; this . bpc . transparentEntities ( ) ; this . moveAtCursor ( ) ; this . redraw ( ) ; } private static getTilePositions ( ) { return [ ... Array ( Math . pow ( PaintTileContainer . size , 2 ) ) . keys ( ) ] . map ( i => { const offset = PaintTileContainer . size / 2 - 0.5 ; return { x : ( i % PaintTileContainer . size ) - offset , y : ( i - ( i % PaintTileContainer . size ) ) / PaintTileContainer . size - offset , } ; } ) ; } public hide ( ) { this . bpc . transparentEntities ( false ) ; super . hide ( ) ; } public show ( ) { this . bpc . transparentEntities ( ) ; super . show ( ) ; } public destroy ( ) { this . bpc . transparentEntities ( false ) ; super . destroy ( ) ; } public getItemName ( ) { return Tile . getItemName ( this . name ) ; } public increaseSize ( ) { if ( PaintTileContainer . size === 20 ) return ; PaintTileContainer . size += 1 ; this . moveAtCursor ( ) ; this . redraw ( ) ; } public decreaseSize ( ) { if ( PaintTileContainer . size === 1 ) return ; PaintTileContainer . size -= 1 ; this . moveAtCursor ( ) ; this . redraw ( ) ; } public rotate ( ) { const nD = FD . tiles [ this . name ] . next_direction ; if ( nD ) { this . name = nD ; this . redraw ( ) ; } } protected redraw ( ) { this . removeChildren ( ) ; const sprites = TileContainer . generateSprites ( this . name , this . position , PaintTileContainer . getTilePositions ( ) ) ; this . addChild ( ... sprites ) ; } public moveAtCursor ( ) { this . setNewPosition ( { x : PaintTileContainer . size , y : PaintTileContainer . size , } ) ; } public removeContainerUnder ( ) { if ( ! this . visible ) return ; const position = this . getGridPosition ( ) ; this . bpc . bp . removeTiles ( PaintTileContainer . getTilePositions ( ) . map ( p => ( { x : p . x + position . x , y : p . y + position . y , } ) ) ) ; } public placeEntityContainer ( ) { if ( ! this . visible ) return ; const position = this . getGridPosition ( ) ; this . bpc . bp . createTiles ( this . name , PaintTileContainer . getTilePositions ( ) . map ( p => ( { x : p . x + position . x , y : p . y + position . y , } ) ) ) ; } }