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

export default class HouseRaycastReceiver extends RaycastReceiver {
	isHovered = false
	elapsed = 0
	clearHoverId = 0
	awake() {

	}

	start() {
		this.elapsed = 0
	}

	update() {
		if (this.isHovered) {
			this.elapsed += RE.Runtime.deltaTime
			this.object3d.position.y = 0.5 * Math.sin(4 * this.elapsed) + 1

			if (RE.Input.mouse.getButtonUp(0) || RE.Input.touch.endTouches.length > 0) {
				RE.Runtime.rogueDOMContainer.style.cursor = "default"
				RE.App.loadScene("World Map")
			}
		} else {
			if (this.object3d.position.y != 0) {
				this.object3d.position.y = 0
			}
		}

	}

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

	onMouseOut() {
		if (!this.isHovered) {
			return
		}
		this.isHovered = false
		// this.object3d.position.y = 0
		RE.Runtime.rogueDOMContainer.style.cursor = "default"
	}
}

RE.registerComponent(HouseRaycastReceiver);
