finish implementing basic save system

This commit is contained in:
Nitwel 2024-01-27 15:13:43 +01:00
parent b4cb70a798
commit bcec4d8643
17 changed files with 250 additions and 173 deletions

View File

@ -1,9 +1,12 @@
extends Node3D extends Entity
const Entity = preload("../entity.gd")
var entity_id = "button.plug_printer_2"
@onready var button = $Button @onready var button = $Button
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
if stateInfo == null: if stateInfo == null:

View File

@ -1,6 +1,7 @@
extends StaticBody3D extends Entity
const Entity = preload("../entity.gd")
@export var entity_id = "camera.bedroomspeaker"
@export var view_width = 0.15 @export var view_width = 0.15
@onready var view = $View @onready var view = $View
@ -10,6 +11,8 @@ extends StaticBody3D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
set_state(stateInfo) set_state(stateInfo)

View File

@ -0,0 +1,11 @@
extends StaticBody3D
var entity_id: String
func _ready():
var movable = get_node("Movable")
if movable:
movable.on_moved.connect(func():
House.body.save_all_entities()
)

View File

@ -1,6 +1,7 @@
extends StaticBody3D extends Entity
const Entity = preload("../entity.gd")
@export var entity_id = "switch.plug_printer_2"
@export var color_off = Color(0.23, 0.23, 0.23) @export var color_off = Color(0.23, 0.23, 0.23)
@export var color_on = Color(1.0, 0.85, 0.0) @export var color_on = Color(1.0, 0.85, 0.0)
@ -12,6 +13,8 @@ var brightness = 0 # 0-255
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
set_state(stateInfo["state"] == "on") set_state(stateInfo["state"] == "on")

View File

@ -1,6 +1,7 @@
extends StaticBody3D extends Entity
const Entity = preload("../entity.gd")
@export var entity_id = "media_player.bedroomspeaker"
@export var image_width = 0.15 @export var image_width = 0.15
@onready var previous = $Previous @onready var previous = $Previous
@ -18,6 +19,8 @@ var volume = 50
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
set_state(stateInfo) set_state(stateInfo)

View File

@ -1,10 +1,13 @@
extends StaticBody3D extends Entity
const Entity = preload("../entity.gd")
@export var entity_id = "sensor.sun_next_dawn"
@onready var label: Label3D = $Label @onready var label: Label3D = $Label
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
set_text(stateInfo) set_text(stateInfo)

View File

@ -1,10 +1,13 @@
extends StaticBody3D extends Entity
const Entity = preload("../entity.gd")
@export var entity_id = "switch.plug_printer_2"
@onready var sprite: AnimatedSprite3D = $Icon @onready var sprite: AnimatedSprite3D = $Icon
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
super()
var stateInfo = await HomeApi.get_state(entity_id) var stateInfo = await HomeApi.get_state(entity_id)
if stateInfo == null: if stateInfo == null:
return return

View File

@ -3,6 +3,7 @@ extends Function
class_name Movable class_name Movable
signal on_move(position: Vector3, rotation: Vector3) signal on_move(position: Vector3, rotation: Vector3)
signal on_moved()
@export var restricted: bool = false @export var restricted: bool = false
@export var restrict_movement: Callable @export var restrict_movement: Callable
@ -33,6 +34,7 @@ func _on_grab_move(_event: EventPointer):
func _on_grab_up(event: EventPointer): func _on_grab_up(event: EventPointer):
event.initiator.node.remove_child(hit_node) event.initiator.node.remove_child(hit_node)
on_moved.emit()
func _get_configuration_warnings() -> PackedStringArray: func _get_configuration_warnings() -> PackedStringArray:
var warnings := PackedStringArray() var warnings := PackedStringArray()

View File

@ -27,37 +27,35 @@ func _physics_process(delta):
levels.scale.z = lerp(levels.scale.z, target_size, 10.0 * delta) levels.scale.z = lerp(levels.scale.z, target_size, 10.0 * delta)
func update_house(): func update_house():
for room in get_rooms(0): for old_room in get_rooms(0):
room.queue_free() old_room.queue_free()
await old_room.tree_exited
align_reference.update_align_reference() align_reference.update_align_reference()
for room in Store.house.rooms: for index in range(Store.house.rooms.size()):
create_room(room.name, 0) var new_room = Store.house.rooms[index]
# TODO: Make room load itself! create_room(new_room.name, 0)
for entity in Store.house.entities: for entity in Store.house.entities:
var entity_instance = create_entity(entity.id, entity.position) var entity_instance = create_entity(entity.id, entity.position)
entity_instance.global_rotation = entity.rotation entity_instance.global_rotation = entity.rotation
func create_room(room_name: String, level: int) -> RoomType: func create_room(room_name: String, level: int) -> RoomType:
if editing_room != null: var existing_room = Store.house.get_room(room_name)
editing_room.editable = false
editing_room = null
var room = Room.instantiate()
room.name = room_name
room.editable = true
editing_room = room
get_level(level).add_child(room)
if existing_room == null:
Store.house.rooms.append({ Store.house.rooms.append({
"name": room_name, "name": room_name,
"height": 2.0, "height": 2.0,
"corners": [], "corners": [],
}) })
var room = Room.instantiate()
room.name = room_name
get_level(level).add_child(room)
return room return room
func edit_room(room_name): func edit_room(room_name):
@ -152,6 +150,8 @@ func create_entity(entity_id: String, entity_position: Vector3):
room.get_node("Entities").add_child(entity) room.get_node("Entities").add_child(entity)
entity.global_position = entity_position entity.global_position = entity_position
save_all_entities()
return entity return entity
func update_mini_view(): func update_mini_view():
@ -203,8 +203,9 @@ func save_all_entities():
"id": entity.entity_id, "id": entity.entity_id,
"position": entity.global_position, "position": entity.global_position,
"rotation": entity.global_rotation, "rotation": entity.global_rotation,
"room": room.name "room": String(room.name)
} }
Store.house.entities.append(entity_data) Store.house.entities.append(entity_data)
Store.house.save_local()

View File

@ -20,47 +20,103 @@ var editable: bool = false:
else: else:
state_machine.change_to("View") state_machine.change_to("View")
func get_corner(index: int) -> MeshInstance3D:
return wall_corners.get_child(index % wall_corners.get_child_count())
func get_edge(index: int) -> MeshInstance3D:
return wall_edges.get_child(index % wall_edges.get_child_count())
func has_point(point: Vector3) -> bool: func has_point(point: Vector3) -> bool:
return get_aabb().has_point(point) return get_aabb().has_point(point)
func remove_corner(index: int):
get_corner(index).queue_free()
get_edge(index).queue_free()
func get_aabb(): func get_aabb():
if wall_corners.get_child_count() == 0: var room_store = Store.house.get_room(name)
var corners = room_store.corners
if corners.size() == 0:
return AABB() return AABB()
var min_pos = wall_corners.get_child(0).position var min_pos = Vector3(corners[0].x, 0, corners[0].y)
var max_pos = wall_corners.get_child(0).position var max_pos = min_pos
for corner in wall_corners.get_children(): for corner in corners:
min_pos.x = min(min_pos.x, corner.position.x) min_pos.x = min(min_pos.x, corner.x)
min_pos.z = min(min_pos.z, corner.position.z) min_pos.z = min(min_pos.z, corner.y)
max_pos.x = max(max_pos.x, corner.position.x) max_pos.x = max(max_pos.x, corner.x)
max_pos.z = max(max_pos.z, corner.position.z) max_pos.z = max(max_pos.z, corner.y)
min_pos.y = room_floor.position.y min_pos.y = 0
max_pos.y = room_ceiling.position.y max_pos.y = room_store.height
return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos))
func update_store(): static func generate_wall_mesh(room_store: Dictionary):
var store_room = Store.house.get_room(name) if room_store.corners.size() < 2:
return null
var corners = [] var st = SurfaceTool.new()
var wall_up = Vector3.UP * room_store.height
for corner in wall_corners.get_children(): st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
corners.append(Vector2(corner.position.x, corner.position.z))
store_room.corners = corners for corner in room_store.corners:
store_room.height = room_ceiling.position.y var corner3D = Vector3(corner.x, 0, corner.y)
st.add_vertex(corner3D)
st.add_vertex(corner3D + wall_up)
var first_corner = Vector3(room_store.corners[0].x, 0, room_store.corners[0].y)
st.add_vertex(first_corner)
st.add_vertex(first_corner + wall_up)
st.index()
st.generate_normals()
st.generate_tangents()
var mesh = st.commit()
return mesh
static func generate_ceiling_mesh(room_store: Dictionary):
var points: PackedVector2Array = PackedVector2Array()
var edges: PackedInt32Array = PackedInt32Array()
var triangles: PackedInt32Array
var corners = room_store.corners
if corners.size() < 3:
return null
for i in range(corners.size()):
var corner = corners[i]
points.append(Vector2(corner.x, corner.y))
edges.append(i)
edges.append((i + 1) % corners.size())
var cdt: ConstrainedTriangulation = ConstrainedTriangulation.new()
cdt.init(true, true, 0.1)
cdt.insert_vertices(points)
cdt.insert_edges(edges)
cdt.erase_outer_triangles()
points = cdt.get_all_vertices()
triangles = cdt.get_all_triangles()
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
for i in range(points.size()):
st.add_vertex(Vector3(points[i].x, 0, points[i].y))
for i in range(triangles.size()):
st.add_index(triangles[i])
st.index()
st.generate_normals()
st.generate_tangents()
var mesh = st.commit()
return mesh
Store.house.save_local()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://bswgmclohuqui"] [gd_scene load_steps=10 format=3 uid="uid://bswgmclohuqui"]
[ext_resource type="Script" path="res://content/system/house/room/room.gd" id="1_fccq0"] [ext_resource type="Script" path="res://content/system/house/room/room.gd" id="1_fccq0"]
[ext_resource type="Script" path="res://content/functions/clickable.gd" id="1_ugebq"] [ext_resource type="Script" path="res://content/functions/clickable.gd" id="1_ugebq"]
@ -10,8 +10,6 @@
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_08sv0"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_08sv0"]
[sub_resource type="ArrayMesh" id="ArrayMesh_7dibq"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_ap613"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_ap613"]
plane = Plane(0, -1, 0, 0) plane = Plane(0, -1, 0, 0)
@ -30,7 +28,6 @@ script = ExtResource("1_ugebq")
[node name="WallMesh" type="MeshInstance3D" parent="."] [node name="WallMesh" type="MeshInstance3D" parent="."]
material_override = ExtResource("3_al1ev") material_override = ExtResource("3_al1ev")
mesh = SubResource("ArrayMesh_7dibq")
[node name="CeilingMesh" type="MeshInstance3D" parent="."] [node name="CeilingMesh" type="MeshInstance3D" parent="."]
material_override = ExtResource("3_al1ev") material_override = ExtResource("3_al1ev")

View File

@ -11,13 +11,20 @@ var height_corner: StaticBody3D = null
var height_edge: StaticBody3D = null var height_edge: StaticBody3D = null
func _on_enter(): func _on_enter():
room.wall_corners.visible = true var room_store = Store.house.get_room(room.name)
room.wall_edges.visible = true
if floor_corner != null: if room_store == null:
floor_corner.visible = true return
height_corner.visible = true
height_edge.visible = true var corners = room_store.corners
if corners.size() > 0:
add_floor_corner(Vector3(corners[0].x, 0, corners[0].y))
add_height_corner(Vector3(corners[0].x, 0, corners[0].y))
room.room_ceiling.position.y = room_store.height
for i in range(1, corners.size()):
add_corner(Vector3(corners[i].x, 0, corners[i].y))
room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null && height_corner == null) room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null && height_corner == null)
room.room_floor.get_node("CollisionShape3D").disabled = false room.room_floor.get_node("CollisionShape3D").disabled = false
@ -32,15 +39,21 @@ func _on_enter():
room.room_floor.get_node("Clickable").on_click.connect(_on_click_floor) room.room_floor.get_node("Clickable").on_click.connect(_on_click_floor)
func _on_leave(): func _on_leave():
room.update_store() update_store()
room.wall_corners.visible = false for child in room.wall_corners.get_children():
room.wall_edges.visible = false child.queue_free()
await child.tree_exited
for child in room.wall_edges.get_children():
child.queue_free()
await child.tree_exited
if floor_corner != null: if floor_corner != null:
floor_corner.visible = false floor_corner.queue_free()
height_corner.visible = false await floor_corner.tree_exited
height_edge.visible = false height_edge.queue_free()
await height_edge.tree_exited
room.room_ceiling.get_node("CollisionShape3D").disabled = true room.room_ceiling.get_node("CollisionShape3D").disabled = true
room.room_floor.get_node("CollisionShape3D").disabled = true room.room_floor.get_node("CollisionShape3D").disabled = true
@ -48,6 +61,16 @@ func _on_leave():
room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling) room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling)
room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor) room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor)
func get_corner(index: int) -> MeshInstance3D:
return room.wall_corners.get_child(index % room.wall_corners.get_child_count())
func get_edge(index: int) -> MeshInstance3D:
return room.wall_edges.get_child(index % room.wall_edges.get_child_count())
func remove_corner(index: int):
get_corner(index).queue_free()
get_edge(index).queue_free()
func _on_click_floor(event): func _on_click_floor(event):
if floor_corner != null && height_corner != null: if floor_corner != null && height_corner != null:
return return
@ -238,3 +261,16 @@ func add_edge(from_pos: Vector3, to_pos: Vector3, index: int = -1):
room.wall_edges.add_child(edge) room.wall_edges.add_child(edge)
room.wall_edges.move_child(edge, index) room.wall_edges.move_child(edge, index)
return edge return edge
func update_store():
var store_room = Store.house.get_room(room.name)
var corners = []
for corner in room.wall_corners.get_children():
corners.append(Vector2(corner.position.x, corner.position.z))
store_room.corners = corners
store_room.height = room.room_ceiling.position.y
Store.house.save_local()

View File

@ -2,20 +2,17 @@ extends RoomState
const RoomState = preload("./room_state.gd") const RoomState = preload("./room_state.gd")
var room_height = 3
var corner_count = 0
func _on_enter(): func _on_enter():
corner_count = room.wall_corners.get_child_count() var room_store = Store.house.get_room(room.name)
if corner_count < 3: if room_store == null || room_store.corners.size() < 3:
return return
room_height = room.room_ceiling.position.y
room.wall_mesh.visible = true room.wall_mesh.visible = true
room.ceiling_mesh.visible = true room.ceiling_mesh.visible = true
room.wall_mesh.mesh = generate_mesh()
room.wall_mesh.mesh = Room.generate_wall_mesh(room_store)
if room.wall_mesh.mesh == null: if room.wall_mesh.mesh == null:
return return
@ -26,7 +23,7 @@ func _on_enter():
ceiling_shape.disabled = false ceiling_shape.disabled = false
floor_shape.disabled = false floor_shape.disabled = false
room.ceiling_mesh.mesh = generate_ceiling_mesh() room.ceiling_mesh.mesh = Room.generate_ceiling_mesh(room_store)
ceiling_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape() ceiling_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape()
floor_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape() floor_shape.shape = room.ceiling_mesh.mesh.create_trimesh_shape()
ceiling_shape.shape.backface_collision = true ceiling_shape.shape.backface_collision = true
@ -52,87 +49,28 @@ func _on_leave():
for collision in room.wall_collisions.get_children(): for collision in room.wall_collisions.get_children():
collision.queue_free() collision.queue_free()
await collision.tree_exited
func generate_mesh():
var st = SurfaceTool.new()
var wall_up = Vector3.UP * room_height
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for i in range(corner_count):
var corner = room.get_corner(i)
st.add_vertex(corner.position)
st.add_vertex(corner.position + wall_up)
var first_corner = room.get_corner(0)
st.add_vertex(first_corner.position)
st.add_vertex(first_corner.position + wall_up)
st.index()
st.generate_normals()
st.generate_tangents()
var mesh = st.commit()
return mesh
func generate_ceiling_mesh():
var points: PackedVector2Array = PackedVector2Array()
var edges: PackedInt32Array = PackedInt32Array()
var triangles: PackedInt32Array
for i in range(corner_count):
var corner = room.get_corner(i)
points.append(Vector2(corner.position.x, corner.position.z))
edges.append(i)
edges.append((i + 1) % corner_count)
var cdt: ConstrainedTriangulation = ConstrainedTriangulation.new()
cdt.init(true, true, 0.1)
cdt.insert_vertices(points)
cdt.insert_edges(edges)
cdt.erase_outer_triangles()
points = cdt.get_all_vertices()
triangles = cdt.get_all_triangles()
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
for i in range(points.size()):
st.add_vertex(Vector3(points[i].x, 0, points[i].y))
for i in range(triangles.size()):
st.add_index(triangles[i])
st.index()
st.generate_normals()
st.generate_tangents()
var mesh = st.commit()
return mesh
func generate_collision(): func generate_collision():
var room_store = Store.house.get_room(room.name)
var collision_shapes: Array[CollisionShape3D] = [] var collision_shapes: Array[CollisionShape3D] = []
for i in range(corner_count): var corners = room_store.corners
var corner = room.get_corner(i)
var next_corner = room.get_corner(i + 1) for i in range(corners.size()):
var corner = Vector3(corners[i].x, 0, corners[i].y)
var next_corner_index = (i + 1) % corners.size()
var next_corner = Vector3(corners[next_corner_index].x, 0, corners[next_corner_index].y)
var shape = BoxShape3D.new() var shape = BoxShape3D.new()
shape.size = Vector3((next_corner.position - corner.position).length(), room_height, 0.04) shape.size = Vector3((next_corner - corner).length(), room_store.height, 0.04)
var transform = Transform3D() var transform = Transform3D()
var back_vector = (corner.position - next_corner.position).cross(Vector3.UP).normalized() * shape.size.z / 2 var back_vector = (corner - next_corner).cross(Vector3.UP).normalized() * shape.size.z / 2
transform.basis = Basis((next_corner.position - corner.position).normalized(), Vector3.UP, back_vector.normalized()) transform.basis = Basis((next_corner - corner).normalized(), Vector3.UP, back_vector.normalized())
transform.origin = corner.position + (next_corner.position - corner.position) / 2 + back_vector + Vector3.UP * shape.size.y / 2 transform.origin = corner + (next_corner - corner) / 2 + back_vector + Vector3.UP * shape.size.y / 2
var collision_shape = CollisionShape3D.new() var collision_shape = CollisionShape3D.new()

View File

@ -41,6 +41,9 @@ var edit_room = false:
room_button.label = "edit" room_button.label = "edit"
func _ready(): func _ready():
Store.house.on_loaded.connect(func():
_generate_room_map()
)
room_button.on_button_down.connect(func(): room_button.on_button_down.connect(func():
if selected_room == null: if selected_room == null:
@ -50,6 +53,7 @@ func _ready():
return return
House.body.create_room(room_name, 0) House.body.create_room(room_name, 0)
House.body.edit_room(room_name)
selected_room = room_name selected_room = room_name
edit_room = true edit_room = true
else: else:
@ -84,27 +88,33 @@ func _on_click(event: EventPointer):
selected_room = room_name selected_room = room_name
func _generate_room_map(): func _generate_room_map():
var rooms = House.body.get_rooms(0) var rooms = Store.house.rooms
var target_size = Vector3(0.3, 1, 0.24) var target_size = Vector2(0.3, 0.24)
for old_room in rooms_map.get_children(): for old_room in rooms_map.get_children():
old_room.queue_free() old_room.queue_free()
await old_room.tree_exited await old_room.tree_exited
var aabb = House.body.get_level_aabb(0) var current_min = Vector2(rooms[0].corners[0].x, rooms[0].corners[0].y)
var current_min = aabb.position var current_max = current_min
var current_max = aabb.position + aabb.size
for room in rooms: for room in rooms:
var mesh = room.ceiling_mesh.mesh for corner in room.corners:
current_min.x = min(current_min.x, corner.x)
current_min.y = min(current_min.y, corner.y)
current_max.x = max(current_max.x, corner.x)
current_max.y = max(current_max.y, corner.y)
for room in rooms:
var mesh = RoomType.generate_ceiling_mesh(room)
if mesh == null: if mesh == null:
continue continue
var body = StaticBody3D.new() var body = StaticBody3D.new()
body.name = room.name body.name = room.name
var mesh_instance = MeshInstance3D.new() var mesh_instance = MeshInstance3D.new()
mesh_instance.name = "MeshInstance3D" mesh_instance.name = "MeshInstance3D"
mesh_instance.mesh = mesh mesh_instance.mesh = mesh
@ -122,9 +132,9 @@ func _generate_room_map():
var current_size = current_max - current_min var current_size = current_max - current_min
var target_scale = target_size / current_size var target_scale = target_size / current_size
var scale_value = min(target_scale.x, target_scale.z) var scale_value = min(target_scale.x, target_scale.y)
rooms_map.position.x = -current_min.x * scale_value rooms_map.position.x = -current_min.x * scale_value
rooms_map.position.z = -current_min.z * scale_value rooms_map.position.z = -current_min.y * scale_value
rooms_map.scale = Vector3(scale_value, scale_value, scale_value) rooms_map.scale = Vector3(scale_value, scale_value, scale_value)

View File

@ -27,15 +27,16 @@ func _ready():
) )
credits.on_click.connect(func(_event): credits.on_click.connect(func(_event):
print("_active_controller")
var credits_instance = credits_scene.instantiate() var credits_instance = credits_scene.instantiate()
get_tree().root.add_child(credits_instance) get_tree().root.add_child(credits_instance)
var label = $Content/Credits/Label var label = $Content/Credits/Label
credits_instance.global_position = + label.to_global(label.position + Vector3(0.1, 0, -0.15)) credits_instance.global_position = + label.to_global(label.position + Vector3(0.1, 0, -0.15))
) )
Store.settings.on_loaded.connect(func():
input_url.text = Store.settings.url input_url.text = Store.settings.url
input_token.text = Store.settings.token input_token.text = Store.settings.token
)
button_connect.on_button_down.connect(func(): button_connect.on_button_down.connect(func():
var url = input_url.text var url = input_url.text

View File

@ -27,7 +27,7 @@ func _ready():
var success = Store.settings.load_local() var success = Store.settings.load_local()
if success: if success:
start_adapter(Store.settings.type, Store.settings.url, Store.settings.token) start_adapter(Store.settings.type.to_lower(), Store.settings.url, Store.settings.token)
func start_adapter(type: String, url: String, token: String): func start_adapter(type: String, url: String, token: String):

View File

@ -32,7 +32,7 @@ func create_dict():
func use_dict(dict: Dictionary): func use_dict(dict: Dictionary):
for prop_info in get_property_list(): for prop_info in get_property_list():
if prop_info.name.begins_with("_"): if prop_info.name.begins_with("_") || prop_info.hint_string != "":
continue continue
var prop = get(prop_info.name) var prop = get(prop_info.name)
@ -57,8 +57,7 @@ func save_local(path = _save_path):
var json_text = JSON.stringify(data) var json_text = JSON.stringify(data)
save_file.store_line(json_text) save_file.store_line(json_text)
_loaded = true on_saved.emit()
on_loaded.emit()
return true return true
@ -71,7 +70,15 @@ func load_local(path = _save_path):
if save_file == null: if save_file == null:
return false return false
var json_text = save_file.get_line() var json_text = save_file.get_as_text()
var save_data = VariantSerializer.parse_value(JSON.parse_string(json_text)) var save_data = VariantSerializer.parse_value(JSON.parse_string(json_text))
if save_data == null:
return false
use_dict(save_data) use_dict(save_data)
_loaded = true
on_loaded.emit()
return true