import GetForwardVector from 'Assets/Library/GetForwardVector';
import * as RE from 'rogue-engine';
import * as THREE from 'three'

export default class MovementController extends RE.Component {
  @RE.props.num() speed: number = 1
  vectorCalculator: GetForwardVector

  awake() {

  }

  start() {
    this.vectorCalculator = new GetForwardVector(RE.Runtime.camera)
  }

  update() {
    if (RE.Input.keyboard.getKeyPressed("KeyW")) {
      this.moveForward(1 * this.speed)
    }
    if (RE.Input.keyboard.getKeyPressed("KeyA")) {
      this.moveRight(-1* this.speed)
    }
    if (RE.Input.keyboard.getKeyPressed("KeyS")) {
      this.moveForward(-1* this.speed)
    }
    if (RE.Input.keyboard.getKeyPressed("KeyD")) {
      this.moveRight(1* this.speed)
    }
  }

  moveForward(distance) {
    this.object3d.position.addScaledVector(this.vectorCalculator.getForward(), distance);
  }

  moveRight(distance) {
    this.object3d.position.addScaledVector(this.vectorCalculator.getRight(), distance);
  }
}



RE.registerComponent(MovementController);
