import F from '../UI/controls/functions' ; import { Entity } from '../core/Entity' ; import { Blueprint } from '../core/Blueprint' ; import { EntitySprite } from './EntitySprite' ; import { VisualizationArea } from './VisualizationArea' ; import { BlueprintContainer } from './BlueprintContainer' ; import { PaintBlueprintContainer } from './PaintBlueprintContainer' ; export class PaintBlueprintEntityContainer { private readonly pbpc : PaintBlueprintContainer ; private readonly bpc : BlueprintContainer ; private readonly bp : Blueprint ; private readonly entity : Entity ; private readonly visualizationArea : VisualizationArea ; public readonly entitySprites : EntitySprite [ ] ; /** This is only a reference */ private undergroundLine : PIXI . Container ; public constructor ( pbpc , bpc , bp , entity ) { this . pbpc = pbpc ; this . bpc = bpc ; this . bp = bp ; this . entity = entity ; this . visualizationArea = this . bpc . underlayContainer . create ( this . entity . name , this . position ) ; this . entitySprites = EntitySprite . getParts ( this . entity , { x : this . entity . position . x * 32 , y : this . entity . position . y * 32 , } , this . bp . entityPositionGrid ) ; } private get entityPosition ( ) : IPoint { return { x : this . pbpc . x / 32 + this . entity . position . x , y : this . pbpc . y / 32 + this . entity . position . y , } ; } private get position ( ) : IPoint { return { x : this . pbpc . x + this . entity . position . x , y : this . pbpc . y + this . entity . position . y , } ; } public destroy ( ) { this . visualizationArea . destroy ( ) ; this . destroyUndergroundLine ( ) ; } private checkBuildable ( ) { const position = this . entityPosition ; const direction = this . entity . direction ; const allow = this . bpc . bp . entityPositionGrid . checkFastReplaceableGroup ( this . entity . name , direction , position ) || this . bpc . bp . entityPositionGrid . checkSameEntityAndDifferentDirection ( this . entity . name , direction , position ) || this . bpc . bp . entityPositionGrid . isAreaAvalible ( this . entity . name , position , direction ) ; for ( const s of this . entitySprites ) { F . applyTint ( s , { r : allow ? 0.4 : 1 , g : allow ? 1 : 0.4 , b : 0.4 , a : 1 , } ) ; } } private updateUndergroundLine ( ) { this . destroyUndergroundLine ( ) ; this . undergroundLine = this . bpc . overlayContainer . createUndergroundLine ( this . entity . name , this . entityPosition , this . entity . directionType === 'input' ? this . entity . direction : ( this . entity . direction + 4 ) % 8 , this . entity . name === 'pipe_to_ground' || this . entity . directionType === 'output' ? ( this . entity . direction + 4 ) % 8 : this . entity . direction ) ; } private destroyUndergroundLine ( ) { if ( this . undergroundLine ) { this . undergroundLine . destroy ( ) ; } } public moveAtCursor ( ) { this . updateUndergroundLine ( ) ; this . visualizationArea . moveTo ( this . position ) ; this . checkBuildable ( ) ; } public removeContainerUnder ( ) { const size = this . entity . size ; const entities = this . bpc . bp . entityPositionGrid . getEntitiesInArea ( { ... this . entityPosition , w : size . x , h : size . y , } ) ; this . bpc . bp . removeEntities ( entities ) ; this . checkBuildable ( ) ; } public placeEntityContainer ( ) { const position = this . entityPosition ; const direction = this . entity . direction ; if ( this . bpc . bp . fastReplaceEntity ( this . entity . name , direction , position ) ) return ; const snEnt = this . bpc . bp . entityPositionGrid . checkSameEntityAndDifferentDirection ( this . entity . name , direction , position ) ; if ( snEnt ) { snEnt . direction = direction ; return ; } let ent ; if ( this . bpc . bp . entityPositionGrid . isAreaAvalible ( this . entity . name , position , direction ) ) { ent = this . bpc . bp . createEntity ( { ... this . entity . serialize ( ) , entity_number : undefined , connections : undefined , neighbours : undefined , position , } ) ; } this . checkBuildable ( ) ; return ent ; } }