2023-11-19 18:28:44 +02:00
|
|
|
extends Node3D
|
|
|
|
|
2024-03-07 15:21:31 +02:00
|
|
|
const credits_scene = preload ("./credits.tscn")
|
2023-11-19 18:28:44 +02:00
|
|
|
|
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
|
2023-12-10 02:47:21 +02:00
|
|
|
@onready var save = $Content/Save
|
|
|
|
@onready var clear_save = $Content/ClearSave
|
2023-11-26 01:02:03 +02:00
|
|
|
@onready var background = $Background
|
2024-03-15 20:27:45 +02:00
|
|
|
@onready var voice_assist = $Content/VoiceAssist
|
2023-11-23 04:41:13 +02:00
|
|
|
|
2023-11-19 18:28:44 +02:00
|
|
|
func _ready():
|
2024-04-09 18:46:59 +03:00
|
|
|
var settings_store = Store.settings.state
|
|
|
|
|
2023-11-26 01:02:03 +02:00
|
|
|
background.visible = false
|
|
|
|
|
|
|
|
credits.on_click.connect(func(_event):
|
2024-03-07 15:21:31 +02:00
|
|
|
var credits_instance=credits_scene.instantiate()
|
2023-11-26 01:02:03 +02:00
|
|
|
get_tree().root.add_child(credits_instance)
|
2024-03-07 15:21:31 +02:00
|
|
|
var label=$Content/Credits/Label
|
|
|
|
credits_instance.global_position=+ label.to_global(label.position + Vector3(0.1, 0, -0.15))
|
2023-11-26 01:02:03 +02:00
|
|
|
)
|
|
|
|
|
2024-01-29 13:37:25 +02:00
|
|
|
if Store.settings.is_loaded():
|
2024-04-09 18:46:59 +03:00
|
|
|
input_url.text = settings_store.url
|
|
|
|
input_token.text = settings_store.token
|
2024-01-29 13:37:25 +02:00
|
|
|
else:
|
|
|
|
Store.settings.on_loaded.connect(func():
|
2024-04-09 18:46:59 +03:00
|
|
|
input_url.text=settings_store.url
|
|
|
|
input_token.text=settings_store.token
|
2024-01-29 13:37:25 +02:00
|
|
|
)
|
2023-11-23 04:41:13 +02:00
|
|
|
|
|
|
|
button_connect.on_button_down.connect(func():
|
2024-03-07 15:21:31 +02:00
|
|
|
var url=input_url.text
|
|
|
|
var token=input_token.text
|
2023-11-24 02:36:31 +02:00
|
|
|
|
|
|
|
HomeApi.start_adapter("hass_ws", url, token)
|
2023-11-23 04:41:13 +02:00
|
|
|
|
2024-04-09 18:46:59 +03:00
|
|
|
settings_store.url=url
|
|
|
|
settings_store.token=token
|
2024-01-25 17:29:33 +02:00
|
|
|
|
|
|
|
Store.settings.save_local()
|
2023-11-23 04:41:13 +02:00
|
|
|
)
|
|
|
|
|
2023-12-10 02:47:21 +02:00
|
|
|
save.on_button_down.connect(func():
|
2024-01-25 17:29:33 +02:00
|
|
|
House.body.save_all_entities()
|
|
|
|
Store.house.save_local()
|
2023-12-10 02:47:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
clear_save.on_button_down.connect(func():
|
2024-01-25 17:29:33 +02:00
|
|
|
Store.house.clear()
|
|
|
|
House.body.update_house()
|
2023-12-10 02:47:21 +02:00
|
|
|
)
|
|
|
|
|
2024-03-15 20:27:45 +02:00
|
|
|
voice_assist.on_button_down.connect(func():
|
|
|
|
if Store.settings.is_loaded() == false:
|
|
|
|
await Store.settings.on_loaded
|
|
|
|
|
|
|
|
OS.request_permissions()
|
|
|
|
|
|
|
|
voice_assist.label="mic"
|
|
|
|
|
2024-04-09 18:46:59 +03:00
|
|
|
settings_store.voice_assistant=true
|
2024-03-15 20:27:45 +02:00
|
|
|
Store.settings.save_local()
|
|
|
|
)
|
|
|
|
|
|
|
|
voice_assist.on_button_up.connect(func():
|
|
|
|
if Store.settings.is_loaded() == false:
|
|
|
|
await Store.settings.on_loaded
|
|
|
|
|
|
|
|
voice_assist.label="mic_off"
|
|
|
|
|
2024-04-09 18:46:59 +03:00
|
|
|
settings_store.voice_assistant=false
|
2024-03-15 20:27:45 +02:00
|
|
|
Store.settings.save_local()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
2023-11-24 02:36:31 +02:00
|
|
|
HomeApi.on_connect.connect(func():
|
2024-03-07 15:21:31 +02:00
|
|
|
connection_status.text="Connected"
|
2023-11-20 00:58:26 +02:00
|
|
|
)
|
|
|
|
|
2023-11-24 02:36:31 +02:00
|
|
|
HomeApi.on_disconnect.connect(func():
|
2024-03-07 15:21:31 +02:00
|
|
|
connection_status.text="Disconnected"
|
2023-11-20 00:58:26 +02:00
|
|
|
)
|
2024-03-15 20:27:45 +02:00
|
|
|
|
|
|
|
if Store.settings.is_loaded() == false:
|
|
|
|
await Store.settings.on_loaded
|
|
|
|
|
2024-04-09 18:46:59 +03:00
|
|
|
var button_label = R.computed(func(_arg):
|
|
|
|
return "mic_off" if settings_store.voice_assistant == false else "mic"
|
|
|
|
)
|
|
|
|
|
|
|
|
R.bind(voice_assist, "label", button_label)
|
|
|
|
R.bind(voice_assist, "active", settings_store, "voice_assistant")
|