fix store references
This commit is contained in:
parent
b716f950bc
commit
2cb35ef02b
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
Store.house.state.align_position1 = corner1.global_position
|
||||
Store.house.state.align_position2 = corner2.global_position
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -22,4 +22,4 @@ func clear():
|
|||
self.state.url = ""
|
||||
self.state.token = ""
|
||||
self.state.voice_assistant = false
|
||||
self.state.onboarding_complete = false
|
||||
self.state.onboarding_complete = false
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user