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

export default class SceneLinkRaycastReceiver extends RaycastReceiver {
  @RE.Prop("String") targetScene

  awake() {

  }

  start() {

  }

  update() {
    if (this.isHovered && (RE.Input.mouse.getButtonUp(0) || RE.Input.touch.endTouches.length > 0)) {
      RE.Runtime.rogueDOMContainer.style.cursor = "default"
      RE.App.loadScene(this.targetScene)
    }
  }

  onMouseOver(intersect) {
    this.isHovered = true
    RE.Runtime.rogueDOMContainer.style.cursor = "pointer"
  }

  onMouseOut(){
    this.isHovered = false
    RE.Runtime.rogueDOMContainer.style.cursor = "default"
  }
}

RE.registerComponent(SceneLinkRaycastReceiver);
