2023-11-19 18:28:44 +02:00
|
|
|
extends Node3D
|
|
|
|
|
2023-11-26 01:02:03 +02:00
|
|
|
const ball_scene = preload("./ball.tscn")
|
|
|
|
const credits_scene = preload("./credits.tscn")
|
2023-11-19 18:28:44 +02:00
|
|
|
|
2023-11-28 00:46:05 +02:00
|
|
|
@onready var ball_button = $Content/Button
|
2023-11-20 00:58:26 +02:00
|
|
|
@onready var connection_status = $Content/ConnectionStatus
|
2023-11-19 18:28:44 +02:00
|
|
|
|
2023-11-23 04:41:13 +02:00
|
|
|
@onready var input_url = $Content/InputURL
|
|
|
|
@onready var input_token = $Content/InputToken
|
|
|
|
@onready var button_connect = $Content/Connect
|
2023-11-26 01:02:03 +02:00
|
|
|
@onready var credits = $Content/Credits/Clickable
|
|
|
|
@onready var background = $Background
|
2023-11-23 04:41:13 +02:00
|
|
|
|
2023-11-19 18:28:44 +02:00
|
|
|
func _ready():
|
2023-11-26 01:02:03 +02:00
|
|
|
background.visible = false
|
|
|
|
|
2023-11-28 00:46:05 +02:00
|
|
|
ball_button.on_button_down.connect(func():
|
2023-11-19 18:28:44 +02:00
|
|
|
var ball = ball_scene.instantiate()
|
2023-11-28 00:46:05 +02:00
|
|
|
var controller = XRHelpers.get_right_controller(self)
|
|
|
|
|
|
|
|
ball.transform = controller.transform
|
|
|
|
ball.linear_velocity = -controller.transform.basis.z * 5 + Vector3(0, 5, 0)
|
2023-11-19 18:28:44 +02:00
|
|
|
get_tree().root.add_child(ball)
|
|
|
|
)
|
2023-11-20 00:58:26 +02:00
|
|
|
|
2023-11-26 01:02:03 +02:00
|
|
|
credits.on_click.connect(func(_event):
|
|
|
|
print("_active_controller")
|
|
|
|
var credits_instance = credits_scene.instantiate()
|
|
|
|
get_tree().root.add_child(credits_instance)
|
|
|
|
var label = $Content/Credits/Label
|
|
|
|
credits_instance.global_position = + label.to_global(label.position + Vector3(0.1, 0, -0.15))
|
|
|
|
)
|
|
|
|
|
2023-11-23 04:41:13 +02:00
|
|
|
var config = ConfigData.load_config()
|
|
|
|
|
|
|
|
if config.has("url"):
|
|
|
|
input_url.text = config["url"]
|
|
|
|
if config.has("token"):
|
|
|
|
input_token.text = config["token"]
|
|
|
|
|
|
|
|
button_connect.on_button_down.connect(func():
|
2023-11-24 02:36:31 +02:00
|
|
|
var url = input_url.text + "/api/websocket"
|
|
|
|
var token = input_token.text
|
|
|
|
|
|
|
|
HomeApi.start_adapter("hass_ws", url, token)
|
2023-11-23 04:41:13 +02:00
|
|
|
|
|
|
|
ConfigData.save_config({
|
2023-11-24 02:36:31 +02:00
|
|
|
"api_type": "hass_ws",
|
2023-11-23 04:41:13 +02:00
|
|
|
"url": input_url.text,
|
|
|
|
"token": input_token.text
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-11-24 02:36:31 +02:00
|
|
|
HomeApi.on_connect.connect(func():
|
2023-11-20 00:58:26 +02:00
|
|
|
connection_status.text = "Connected"
|
|
|
|
)
|
|
|
|
|
2023-11-24 02:36:31 +02:00
|
|
|
HomeApi.on_disconnect.connect(func():
|
2023-11-20 00:58:26 +02:00
|
|
|
connection_status.text = "Disconnected"
|
|
|
|
)
|
|
|
|
|