import { Area3D, Camera3D, NodePath, PhysicsBody3D, Variant } from 'godot'
import { export_ } from 'godot.annotations'
import Player from './player'
import MessageBus from './message_bus'

export default class CameraTrigger extends Area3D {
  @export_(Variant.Type.TYPE_NODE_PATH)
  camera!: NodePath
  _camera!: Camera3D

  _ready(): void {
    this._camera = this.get_node(this.camera) as Camera3D
  }

  _on_body_entered(body: PhysicsBody3D) {
    if (body instanceof Player) {
      this._camera?.make_current()
      console.log(MessageBus.instance.active_camera_changed)
      MessageBus.instance.active_camera_changed.emit(this._camera)
    }
  }
}
