From 2cb35ef02bb213876f0030287c5aeca645c58077 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 9 Apr 2024 17:46:59 +0200 Subject: [PATCH] fix store references --- app/addons/rdot/Rdot.gd | 2 +- app/content/main.gd | 20 ++++++++----- app/content/system/house/align_reference.gd | 8 ++--- app/content/system/house/house.gd | 18 ++++++------ app/content/system/house/mini/miniature.gd | 4 +-- app/content/ui/menu/room/views/rooms.gd | 2 +- app/content/ui/menu/settings/settings_menu.gd | 29 ++++++++++--------- app/content/ui/onboarding/onboarding.gd | 4 +-- app/lib/globals/home_api.gd | 3 +- app/lib/stores/settings.gd | 2 +- app/lib/stores/store.gd | 6 ++-- 11 files changed, 53 insertions(+), 45 deletions(-) diff --git a/app/addons/rdot/Rdot.gd b/app/addons/rdot/Rdot.gd index e0e2d33..6428a86 100644 --- a/app/addons/rdot/Rdot.gd +++ b/app/addons/rdot/Rdot.gd @@ -23,7 +23,7 @@ static func bind(target, prop, value, arg1=null, arg2=null): if value is RdotState or value is RdotComputed: return _bind_state(target, prop, value, arg1) - assert(false, "Invalid arguments to bind, value must be a R.State or a RdotStore") + assert(false, "Invalid arguments to bind, value must be a RdotState, a RdotComputed or a RdotStore") static func _bind_store(target, prop, store: RdotStore, key, watch_signal=null): store._access_property(key) diff --git a/app/content/main.gd b/app/content/main.gd index dbf478b..75a43b2 100644 --- a/app/content/main.gd +++ b/app/content/main.gd @@ -22,7 +22,7 @@ func _ready(): else: RenderingServer.set_debug_generate_wireframes(true) - update_voice_assistant() + create_voice_assistant() controller_left.button_pressed.connect(func(name): _emit_action(name, true, false) @@ -65,16 +65,20 @@ func _ready(): remove_child(keyboard) ) -func update_voice_assistant(): +func create_voice_assistant(): if Store.settings.is_loaded() == false: await Store.settings.on_loaded - if Store.settings.voice_assistant&&voice_assistant == null: - voice_assistant = VoiceAssistant.instantiate() - add_child(voice_assistant) - elif !Store.settings.voice_assistant&&voice_assistant != null: - remove_child(voice_assistant) - voice_assistant.queue_free() + var settings_store = Store.settings.state + + R.effect(func(_arg): + if settings_store.voice_assistant == true&&voice_assistant == null: + voice_assistant=VoiceAssistant.instantiate() + add_child(voice_assistant) + elif settings_store.voice_assistant == false&&voice_assistant != null: + remove_child(voice_assistant) + voice_assistant.queue_free() + ) func toggle_menu(): if menu.show_menu == false: diff --git a/app/content/system/house/align_reference.gd b/app/content/system/house/align_reference.gd index 0118f58..c4e1242 100644 --- a/app/content/system/house/align_reference.gd +++ b/app/content/system/house/align_reference.gd @@ -48,8 +48,8 @@ func get_new_transform(): return marker.global_transform func update_align_reference(): - corner1.global_position = Store.house.align_position1 - corner2.global_position = Store.house.align_position2 + corner1.global_position = Store.house.state.align_position1 + corner2.global_position = Store.house.state.align_position2 corner2.look_at(corner1.global_position, Vector3.UP) corner2.rotate(Vector3.UP, deg_to_rad( - 90)) @@ -57,5 +57,5 @@ func update_align_reference(): edge.align_to_corners(corner1.global_position, corner2.global_position) func update_store(): - Store.house.align_position1 = corner1.global_position - Store.house.align_position2 = corner2.global_position \ No newline at end of file + Store.house.state.align_position1 = corner1.global_position + Store.house.state.align_position2 = corner2.global_position \ No newline at end of file diff --git a/app/content/system/house/house.gd b/app/content/system/house/house.gd index 9d8392b..c5517fa 100644 --- a/app/content/system/house/house.gd +++ b/app/content/system/house/house.gd @@ -23,18 +23,18 @@ func update_house(): align_reference.update_align_reference() - for index in range(Store.house.rooms.size() - 1, -1, -1): - var new_room = Store.house.rooms[index] + for index in range(Store.house.state.rooms.size() - 1, -1, -1): + var new_room = Store.house.state.rooms[index] if new_room.corners.size() == 0: - Store.house.rooms.remove_at(index) + Store.house.state.rooms.remove_at(index) Store.house.save_local() continue create_room(new_room.name, 0) - for entity_index in range(Store.house.entities.size()): - var entity = Store.house.entities[entity_index] + for entity_index in range(Store.house.state.entities.size()): + var entity = Store.house.state.entities[entity_index] var entity_instance = create_entity_in(entity.id, entity.room) @@ -48,7 +48,7 @@ func create_room(room_name: String, level: int) -> RoomType: var existing_room = Store.house.get_room(room_name) if existing_room == null: - Store.house.rooms.append({ + Store.house.state.rooms.append({ "name": room_name, "height": 2.0, "corners": [], @@ -98,7 +98,7 @@ func delete_room(room_name): var store_room = Store.house.get_room(room_name) if store_room != null: - Store.house.rooms.erase(store_room) + Store.house.state.rooms.erase(store_room) Store.house.save_local() @@ -229,7 +229,7 @@ func save_reference(): Store.house.save_local() func save_all_entities(): - Store.house.entities.clear() + Store.house.state.entities.clear() for room in get_rooms(0): for entity in room.get_node("Entities").get_children(): @@ -240,6 +240,6 @@ func save_all_entities(): "room": String(room.name) } - Store.house.entities.append(entity_data) + Store.house.state.entities.append(entity_data) Store.house.save_local() diff --git a/app/content/system/house/mini/miniature.gd b/app/content/system/house/mini/miniature.gd index 74413f7..7cd4b08 100644 --- a/app/content/system/house/mini/miniature.gd +++ b/app/content/system/house/mini/miniature.gd @@ -22,10 +22,10 @@ func _ready(): if Store.house.is_loaded() == false: await Store.house.on_loaded - if Store.house.rooms.size() == 0: + if Store.house.state.rooms.size() == 0: return - var room = Store.house.rooms[0] + var room = Store.house.state.rooms[0] var corners = room.corners var height = room.height diff --git a/app/content/ui/menu/room/views/rooms.gd b/app/content/ui/menu/room/views/rooms.gd index 298e13c..967583f 100644 --- a/app/content/ui/menu/room/views/rooms.gd +++ b/app/content/ui/menu/room/views/rooms.gd @@ -102,7 +102,7 @@ func _on_click(event: EventPointer): selected_room = room_name func _generate_room_map(): - var rooms = Store.house.rooms + var rooms = Store.house.state.rooms var target_size = Vector2(0.2, 0.24) var target_offset = Vector2(0, 0.05) diff --git a/app/content/ui/menu/settings/settings_menu.gd b/app/content/ui/menu/settings/settings_menu.gd index 51e3afc..226f03f 100644 --- a/app/content/ui/menu/settings/settings_menu.gd +++ b/app/content/ui/menu/settings/settings_menu.gd @@ -3,7 +3,6 @@ extends Node3D const credits_scene = preload ("./credits.tscn") @onready var connection_status = $Content/ConnectionStatus -@onready var main = $"/root/Main" @onready var input_url = $Content/InputURL @onready var input_token = $Content/InputToken @@ -15,6 +14,8 @@ const credits_scene = preload ("./credits.tscn") @onready var voice_assist = $Content/VoiceAssist func _ready(): + var settings_store = Store.settings.state + background.visible = false credits.on_click.connect(func(_event): @@ -25,12 +26,12 @@ func _ready(): ) if Store.settings.is_loaded(): - input_url.text = Store.settings.url - input_token.text = Store.settings.token + input_url.text = settings_store.url + input_token.text = settings_store.token else: Store.settings.on_loaded.connect(func(): - input_url.text=Store.settings.url - input_token.text=Store.settings.token + input_url.text=settings_store.url + input_token.text=settings_store.token ) button_connect.on_button_down.connect(func(): @@ -39,8 +40,8 @@ func _ready(): HomeApi.start_adapter("hass_ws", url, token) - Store.settings.url=url - Store.settings.token=token + settings_store.url=url + settings_store.token=token Store.settings.save_local() ) @@ -63,8 +64,7 @@ func _ready(): voice_assist.label="mic" - Store.settings.voice_assistant=true - main.update_voice_assistant() + settings_store.voice_assistant=true Store.settings.save_local() ) @@ -74,8 +74,7 @@ func _ready(): voice_assist.label="mic_off" - Store.settings.voice_assistant=false - main.update_voice_assistant() + settings_store.voice_assistant=false Store.settings.save_local() ) @@ -91,5 +90,9 @@ func _ready(): if Store.settings.is_loaded() == false: await Store.settings.on_loaded - voice_assist.label = "mic_off" if Store.settings.voice_assistant == false else "mic" - voice_assist.active = Store.settings.voice_assistant + 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") diff --git a/app/content/ui/onboarding/onboarding.gd b/app/content/ui/onboarding/onboarding.gd index b30bf4d..d917341 100644 --- a/app/content/ui/onboarding/onboarding.gd +++ b/app/content/ui/onboarding/onboarding.gd @@ -9,7 +9,7 @@ func _ready(): if Store.settings.is_loaded() == false: await Store.settings.on_loaded - if (Store.settings.url != ""&&Store.settings.url != null)||Store.settings.onboarding_complete: + if (Store.settings.state.url != ""&&Store.settings.state.url != null)||Store.settings.state.onboarding_complete: close() return @@ -24,7 +24,7 @@ func _ready(): EventSystem.on_slow_tick.connect(_slow_tick) func close(): - Store.settings.onboarding_complete = true + Store.settings.state.onboarding_complete = true Store.settings.save_local() queue_free() diff --git a/app/lib/globals/home_api.gd b/app/lib/globals/home_api.gd index 1b37a7a..fbaa024 100644 --- a/app/lib/globals/home_api.gd +++ b/app/lib/globals/home_api.gd @@ -33,7 +33,8 @@ func _ready(): var success = Store.settings.load_local() if success: - start_adapter(Store.settings.type.to_lower(), Store.settings.url, Store.settings.token) + print(Store.settings) + start_adapter(Store.settings.state.type.to_lower(), Store.settings.state.url, Store.settings.state.token) ## Starts the adapter for the given type and url func start_adapter(type: String, url: String, token: String): diff --git a/app/lib/stores/settings.gd b/app/lib/stores/settings.gd index f24c16b..4ec83c2 100644 --- a/app/lib/stores/settings.gd +++ b/app/lib/stores/settings.gd @@ -22,4 +22,4 @@ func clear(): self.state.url = "" self.state.token = "" self.state.voice_assistant = false - self.state.onboarding_complete = false \ No newline at end of file + self.state.onboarding_complete = false diff --git a/app/lib/stores/store.gd b/app/lib/stores/store.gd index e00bcea..a85e1a0 100644 --- a/app/lib/stores/store.gd +++ b/app/lib/stores/store.gd @@ -24,7 +24,7 @@ func clear(): func sanitizeState(dict=state): var data = {} - for prop_info in get_property_list(): + for prop_info in state.get_property_list(): var key = prop_info.name if key.begins_with("_")||(prop_info.has("hint_string")&&prop_info.hint_string != ""): @@ -38,12 +38,12 @@ func sanitizeState(dict=state): return data func use_dict(dict: Dictionary, target=state): - for prop_info in get_property_list(): + for prop_info in state.get_property_list(): var key = prop_info.name if key.begins_with("_")||(prop_info.has("hint_string")&&prop_info.hint_string != ""): continue - + if dict.has(key) == false: continue