Skip to content

Commit

Permalink
fix bugs with areas
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitwel committed Jun 11, 2024
1 parent fc87909 commit 7e01b99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
11 changes: 3 additions & 8 deletions app/content/system/areas/area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ var edges = []
var corners = []
var grabbing = null
var id: int = 0
var display_name: String = "Area"

@export var size = Vector3(1, 1, 1):
set(value):
if size == value: return

size = value

if is_node_ready() == false:
Expand All @@ -30,8 +29,6 @@ var id: int = 0

@export var edit: bool = false:
set(value):
if edit == value: return

edit = value

if is_node_ready() == false:
Expand All @@ -44,12 +41,10 @@ var id: int = 0
generate_nodes()
update_nodes()
if Engine.is_editor_hint() == false: add_child(name_input)
else:
save_to_store()

func _ready():
remove_child(name_input)
name_input.text = name
name_input.text = display_name
Update.props(self, ["size", "edit"])

func opposite_corner(corner):
Expand Down Expand Up @@ -89,7 +84,7 @@ func save_to_store():
"size": size
})
else:
areas[existing].name = name
areas[existing].name = display_name
areas[existing].position = global_position
areas[existing].rotation = global_rotation
areas[existing].size = size
Expand Down
11 changes: 6 additions & 5 deletions app/content/system/areas/areas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var editing = false:

for area in get_children():
area.edit = value
if value == false: area.save_to_store()

Store.house.save_local()

Expand All @@ -33,21 +34,21 @@ func load_areas():
var area_scene = AreaScene.instantiate()
area_scene.id = area.id
area_scene.edit = editing
area_scene.name = area.name
area_scene.display_name = area.name
add_child(area_scene)
area_scene.global_position = area.position
area_scene.global_rotation = area.rotation
area_scene.size = area.size

if HomeApi.has_integration() == false:
return
continue

HomeApi.api.integration_handler.create_area.call_deferred(area.id, area.name)
HomeApi.api.integration_handler.create_area.call_deferred(area.id, area.display_name)

func create_area(name: String):
var area = AreaScene.instantiate()
area.id = next_valid_id()
area.name = name
area.display_name = name
area.position = App.camera.global_position + App.camera.global_transform.basis.z * - 1
area.size = Vector3(0.5, 0.5, 0.5)
area.edit = true
Expand All @@ -61,7 +62,7 @@ func create_area(name: String):
func rename_area(id: int, name: String):
for area in get_children():
if area is AreaNode&&area.id == id:
area.name = name
area.display_name = name
area.save_to_store()
break

Expand Down
2 changes: 2 additions & 0 deletions app/lib/stores/house.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func _init():
func clear():
self.state.rooms = []
self.state.entities = []
self.state.doors = []
self.state.areas = []

func get_room(name):
for room in self.state.rooms:
Expand Down

0 comments on commit 7e01b99

Please sign in to comment.