<commit_before>import { GameStateEntities } from '../types/states/game/entities';
import { GameStateSpawners } from '../types/states/game/spawners';
import { GameStatePools } from '../types/states/game/pools';
import { GameStateBoundaries } from '../types/states/game/boundaries';
import { GameStateCounters } from '../types/states/game/counters';
import { GameStateGui } from '../types/states/game/gui';

import { FloorSpawner } from '../spawners/floor-spawner';
import { FloorPool } from '../pools/floor-pool';
import { Floor } from '../entities/floor';
import { Dinosaur } from '../entities/dinosaur';
import { Boundary } from '../entities/boundary';

import { DepthCounter } from '../gui/counters/depth-counter';
import { DepthText } from '../gui/text/depth-text';

import { LevelStates } from '../state-machines/level-states';

export class LevelState extends Phaser.State {
  private counters: GameStateCounters;
  private entities: GameStateEntities;
  private spawners: GameStateSpawners;
  private pools: GameStatePools;
  private boundaries: GameStateBoundaries;
  private gui: GameStateGui;

  private currentState: LevelStates;

  public init(): void {
    this.currentState = LevelStates.FALLING;
  }

  public preload(): void {
    this.game.load.image('ground', 'assets/abstract-platformer/PNG/Tiles/Brown tiles/tileBrown_02.png');
    this.game.load.spritesheet('dinosaur', 'assets/characters/dinosaur-spritesheet.png', 93, 128);
    this.game.load.bitmapFont('gemFont', 'assets/fonts/gem.png', 'assets/fonts/gem.xml');
  }

  public create(): void {
    this.counters = this.createCounters();
    this.entities = this.createEntities();
    this.pools = this.createPools();
    this.spawners = this.createSpawners(this.pools.floorPool);
    this.boundaries = this.createBoundaries();
    this.gui = this.createGui(this.counters.depth);

    this.enablePhysics();

    this.addEntities();
    this.positionEntities();

    this.addGui();

    this.enableInput();

    this.start();
  }

  public update(): void {
    if (this.currentState === LevelStates.FALLING) {
      this.pools.floorPool.forEach((floor: Floor) => {
        this.physics.arcade.collide(floor, this.entities.dinosaur);
      }, null);

      this.physics.arcade.overlap(this.entities.dinosaur, this.boundaries.bottom, () => {
        this.currentState = LevelStates.BOOSTING;
        const boostDuration = 2000;

        this.entities.dinosaur.boost(boostDuration, () => { this.currentState = LevelStates.FALLING; });
        this.spawners.floorSpawner.boost(boostDuration);
      });

      this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.top, () => {
        this.game.state.start('title');
      });
    }

    this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.left);
    this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.right);

    this.gui.depthText.updateDepthValue();
  }

  private createCounters(): GameStateCounters {
    const depth = new DepthCounter(this.game);

    return {
      depth,
    };
  }

  private createEntities(): GameStateEntities {
    const dinosaur: Dinosaur = new Dinosaur(this.game);

    return {
      dinosaur,
    };
  }

  private createPools(): GameStatePools {
    const floorPool: FloorPool = new FloorPool(this.game);
    floorPool.createFloors();

    return {
      floorPool,
    };
  }

  private createSpawners(floorPool: FloorPool): GameStateSpawners {
    const floorSpawner: FloorSpawner = new FloorSpawner(this.game, floorPool);

    return {
      floorSpawner,
    };
  }

  private createBoundaries(): GameStateBoundaries {
    const left = new Boundary(this.game, Phaser.LEFT);
    const right = new Boundary(this.game, Phaser.RIGHT);
    const top = new Boundary(this.game, Phaser.UP);
    const bottom = new Boundary(this.game, Phaser.DOWN);

    return {
      left,
      right,
      top,
      bottom,
    };
  }

  private createGui(depthCounter: DepthCounter): GameStateGui {
    const depthText = new DepthText(this.game, depthCounter);

    return {
      depthText,
    };
  }

  private enablePhysics(): void {
    this.physics.startSystem(Phaser.Physics.ARCADE);

    this.physics.enable(this.entities.dinosaur);

    this.pools.floorPool.enablePhysics();

    this.physics.enable(this.boundaries.left);
    this.physics.enable(this.boundaries.right);
    this.physics.enable(this.boundaries.top);
    this.physics.enable(this.boundaries.bottom);
    this.boundaries.left.initPhysics();
    this.boundaries.right.initPhysics();
    this.boundaries.top.initPhysics();
    this.boundaries.bottom.initPhysics();
  }

  private addEntities(): void {
    this.game.add.existing(this.entities.dinosaur);
    this.game.add.existing(this.pools.floorPool);
    this.game.add.existing(this.boundaries.left);
    this.game.add.existing(this.boundaries.right);
    this.game.add.existing(this.boundaries.top);
    this.game.add.existing(this.boundaries.bottom);
  }

  private positionEntities(): void {
    this.spawners.floorSpawner.initPosition();

    this.entities.dinosaur.centerX = this.world.width - 200;
    this.entities.dinosaur.centerY = this.world.centerY - 200;
  }

  private addGui(): void {
    this.game.add.existing(this.gui.depthText);
  }

  private enableInput(): void {
    this.input.onDown.add(() => {
      if (this.currentState === LevelStates.FALLING) {
        if (this.input.activePointer.x < this.world.centerX) {
          this.entities.dinosaur.goLeft();
        } else {<commit_msg>add keyboard inputs for development<commit_after>import { GameStateEntities } from '../types/states/game/entities';
import { GameStateSpawners } from '../types/states/game/spawners';
import { GameStatePools } from '../types/states/game/pools';
import { GameStateBoundaries } from '../types/states/game/boundaries';
import { GameStateCounters } from '../types/states/game/counters';
import { GameStateGui } from '../types/states/game/gui';

import { FloorSpawner } from '../spawners/floor-spawner';
import { FloorPool } from '../pools/floor-pool';
import { Floor } from '../entities/floor';
import { Dinosaur } from '../entities/dinosaur';
import { Boundary } from '../entities/boundary';

import { DepthCounter } from '../gui/counters/depth-counter';
import { DepthText } from '../gui/text/depth-text';

import { LevelStates } from '../state-machines/level-states';

export class LevelState extends Phaser.State {
  private counters: GameStateCounters;
  private entities: GameStateEntities;
  private spawners: GameStateSpawners;
  private pools: GameStatePools;
  private boundaries: GameStateBoundaries;
  private gui: GameStateGui;

  private currentState: LevelStates;

  public init(): void {
    this.currentState = LevelStates.FALLING;
  }

  public preload(): void {
    this.game.load.image('ground', 'assets/abstract-platformer/PNG/Tiles/Brown tiles/tileBrown_02.png');
    this.game.load.spritesheet('dinosaur', 'assets/characters/dinosaur-spritesheet.png', 93, 128);
    this.game.load.bitmapFont('gemFont', 'assets/fonts/gem.png', 'assets/fonts/gem.xml');
  }

  public create(): void {
    this.counters = this.createCounters();
    this.entities = this.createEntities();
    this.pools = this.createPools();
    this.spawners = this.createSpawners(this.pools.floorPool);
    this.boundaries = this.createBoundaries();
    this.gui = this.createGui(this.counters.depth);

    this.enablePhysics();

    this.addEntities();
    this.positionEntities();

    this.addGui();

    this.enableInput();

    this.start();
  }

  public update(): void {
    if (this.currentState === LevelStates.FALLING) {
      this.pools.floorPool.forEach((floor: Floor) => {
        this.physics.arcade.collide(floor, this.entities.dinosaur);
      }, null);

      this.physics.arcade.overlap(this.entities.dinosaur, this.boundaries.bottom, () => {
        this.currentState = LevelStates.BOOSTING;
        const boostDuration = 2000;

        this.entities.dinosaur.boost(boostDuration, () => { this.currentState = LevelStates.FALLING; });
        this.spawners.floorSpawner.boost(boostDuration);
      });

      this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.top, () => {
        this.game.state.start('title');
      });
    }

    this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.left);
    this.physics.arcade.collide(this.entities.dinosaur, this.boundaries.right);

    this.gui.depthText.updateDepthValue();
  }

  private createCounters(): GameStateCounters {
    const depth = new DepthCounter(this.game);

    return {
      depth,
    };
  }

  private createEntities(): GameStateEntities {
    const dinosaur: Dinosaur = new Dinosaur(this.game);

    return {
      dinosaur,
    };
  }

  private createPools(): GameStatePools {
    const floorPool: FloorPool = new FloorPool(this.game);
    floorPool.createFloors();

    return {
      floorPool,
    };
  }

  private createSpawners(floorPool: FloorPool): GameStateSpawners {
    const floorSpawner: FloorSpawner = new FloorSpawner(this.game, floorPool);

    return {
      floorSpawner,
    };
  }

  private createBoundaries(): GameStateBoundaries {
    const left = new Boundary(this.game, Phaser.LEFT);
    const right = new Boundary(this.game, Phaser.RIGHT);
    const top = new Boundary(this.game, Phaser.UP);
    const bottom = new Boundary(this.game, Phaser.DOWN);

    return {
      left,
      right,
      top,
      bottom,
    };
  }

  private createGui(depthCounter: DepthCounter): GameStateGui {
    const depthText = new DepthText(this.game, depthCounter);

    return {
      depthText,
    };
  }

  private enablePhysics(): void {
    this.physics.startSystem(Phaser.Physics.ARCADE);

    this.physics.enable(this.entities.dinosaur);

    this.pools.floorPool.enablePhysics();

    this.physics.enable(this.boundaries.left);
    this.physics.enable(this.boundaries.right);
    this.physics.enable(this.boundaries.top);
    this.physics.enable(this.boundaries.bottom);
    this.boundaries.left.initPhysics();
    this.boundaries.right.initPhysics();
    this.boundaries.top.initPhysics();
    this.boundaries.bottom.initPhysics();
  }

  private addEntities(): void {
    this.game.add.existing(this.entities.dinosaur);
    this.game.add.existing(this.pools.floorPool);
    this.game.add.existing(this.boundaries.left);
    this.game.add.existing(this.boundaries.right);
    this.game.add.existing(this.boundaries.top);
    this.game.add.existing(this.boundaries.bottom);
  }

  private positionEntities(): void {
    this.spawners.floorSpawner.initPosition();

    this.entities.dinosaur.centerX = this.world.width - 200;
    this.entities.dinosaur.centerY = this.world.centerY - 200;
  }

  private addGui(): void {
    this.game.add.existing(this.gui.depthText);
  }

  private enableInput(): void {
    this.input.keyboard.addCallbacks(this, (e: KeyboardEvent) => {
      if (this.currentState === LevelStates.FALLING) {
        if (e.keyCode === Phaser.Keyboard.A || e.keyCode === Phaser.Keyboard.LEFT) {
          this.entities.dinosaur.goLeft();
        } else if (e.keyCode === Phaser.Keyboard.D || e.keyCode === Phaser.Keyboard.RIGHT) {
          this.entities.dinosaur.goRight();
        }
      }
    });

    this.input.onDown.add(() => {
      if (this.currentState === LevelStates.FALLING) {
        if (this.input.activePointer.x < this.world.centerX) {
          this.entities.dinosaur.goLeft();
        } else {
{'fraction_non_alphanumeric': 0.14047785141262645, 'fraction_numerical': 0.002964771538193233, 'mean_word_length': 3.404377880184332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5032820', 'n_tokens_mistral': 3750, 'n_tokens_neox': 3694, 'n_words': 585}