import * as RE from 'rogue-engine';
import RapierMovementController from './RapierMovementController.re';

export default class PlayerPawnInput extends RE.Component {
  movementController:RapierMovementController
  @RE.props.checkbox() useStrafe: boolean = false
  awake() {

  }

  start() {

    this.object3d.traverse(obj => {
      const components = RE.getObjectComponents(obj);

      components.forEach(comp => {
        if (comp instanceof RapierMovementController) {
          this.movementController = comp
        }
      });
    });

    this.object3d.traverse(obj => {
      const components = RE.getObjectComponents(obj);

      components.forEach(comp => {
        
      });
    });
  }

  update() {
    if (RE.Input.keyboard.getKeyPressed("KeyW")) {
      this.movementController.thrust = true
    }
    if (RE.Input.keyboard.getKeyPressed("KeyA")) {
      if(this.useStrafe) {
        this.movementController.strafeLeft = true
      } else {
        this.movementController.rotateLeft = true
      }
    }
    if (RE.Input.keyboard.getKeyPressed("KeyS")) {
      this.movementController.brake = true
    }
    if (RE.Input.keyboard.getKeyPressed("KeyD")) {
      if(this.useStrafe) {
        this.movementController.strafeRight = true
      } else {
      this.movementController.rotateRight = true
      }
    }
  }
}

RE.registerComponent(PlayerPawnInput);
        