From eab54b5850aff5393dfd25ea7024558abb8d80f5 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Mon, 18 Dec 2023 23:15:48 +0100 Subject: [PATCH 01/17] add possibility to configure height --- .gitignore | 1 + assets/design.afdesign | 4 +- assets/materials/pointer.png | 4 +- content/system/room/room.gd | 192 ++------------------ content/system/room/room.tscn | 42 +++-- content/system/room/states/edit.gd | 213 +++++++++++++++++++++++ content/system/room/states/room_state.gd | 7 + content/system/room/states/view.gd | 86 +++++++++ export_presets.cfg | 2 +- lib/utils/state_machine/state.gd | 13 ++ lib/utils/state_machine/state_machine.gd | 32 ++++ 11 files changed, 401 insertions(+), 195 deletions(-) create mode 100644 content/system/room/states/edit.gd create mode 100644 content/system/room/states/room_state.gd create mode 100644 content/system/room/states/view.gd create mode 100644 lib/utils/state_machine/state.gd create mode 100644 lib/utils/state_machine/state_machine.gd diff --git a/.gitignore b/.gitignore index 3d6cd30..e6dcc6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Godot 4+ specific ignores .godot/ android/build/ +builds/ # Godot-specific ignores .import/ diff --git a/assets/design.afdesign b/assets/design.afdesign index 768cfee..c636778 100644 --- a/assets/design.afdesign +++ b/assets/design.afdesign @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e54002ccb9b04b9b4fb4642cc3b5fd6512f910e65ecb52e41c117a2345d1d22b -size 17810864 +oid sha256:b117dc5a7537a60ff341010636802131c9aa3b80982130e63d5d94902c002d07 +size 13505995 diff --git a/assets/materials/pointer.png b/assets/materials/pointer.png index 0ba72b0..5a92f4d 100644 --- a/assets/materials/pointer.png +++ b/assets/materials/pointer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:68e2b9d5e723a2009f341e45e2968893dd2a1dd5077fe1d9ba970f01d0d75e02 -size 56989 +oid sha256:9738010a57d2157a53e4f537afbcfb50dd28e9de40bae510621d0ea8c94c5844 +size 51682 diff --git a/content/system/room/room.gd b/content/system/room/room.gd index aa1e171..2c20233 100644 --- a/content/system/room/room.gd +++ b/content/system/room/room.gd @@ -1,172 +1,21 @@ extends Node3D -const wall_corner_scene = preload("./wall_corner.tscn") -const wall_edge_scene = preload("./wall_edge.tscn") - -@onready var wall_corners = $WallCorners -@onready var wall_edges = $WallEdges +@onready var wall_corners = $Ceiling/WallCorners +@onready var wall_edges = $Ceiling/WallEdges @onready var wall_mesh = $WallMesh @onready var wall_collisions = $WallCollisions -@onready var ground = $Ground/Clickable +@onready var room_floor = $Floor +@onready var room_ceiling = $Ceiling -var moving = null -var editable := false: +@onready var state_machine = $StateMachine + +var editable: bool = false: set(value): - if value == editable: - return - - editable = value if value: - _start_edit_mode() + state_machine.change_to("Edit") else: - _end_edit_mode() -var ground_plane = Plane(Vector3.UP, Vector3.ZERO) - - -func _ready(): - ground.on_click.connect(func(event): - if !editable: - return - - add_corner(event.ray.get_collision_point()) - ) - -func _start_edit_mode(): - wall_corners.visible = true - wall_edges.visible = true - wall_mesh.visible = false - wall_mesh.mesh = null - - for old_coll in wall_collisions.get_children(): - old_coll.queue_free() - -func _end_edit_mode(): - wall_corners.visible = false - wall_edges.visible = false - wall_mesh.mesh = generate_mesh() - - if wall_mesh.mesh == null: - return - - var collisions = generate_collision(wall_mesh.mesh) - - for collision in collisions: - var static_body = StaticBody3D.new() - static_body.set_collision_layer_value(4, true) - static_body.set_collision_layer_value(5, true) - static_body.collision_mask = 0 - static_body.add_child(collision) - wall_collisions.add_child(static_body) - - wall_mesh.visible = true - -func generate_mesh(): - var corner_count = wall_corners.get_child_count() - - if corner_count < 3: - return - - var st = SurfaceTool.new() - var wall_up = Vector3.UP * 3 - - st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP) - - for i in range(corner_count): - var corner = get_corner(i) - - st.add_vertex(corner.position) - st.add_vertex(corner.position + wall_up) - - var first_corner = 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_collision(mesh: ArrayMesh): - var corner_count = wall_corners.get_child_count() - - if corner_count < 3: - return - - var collision_shapes: Array[CollisionShape3D] = [] - - for i in range(corner_count): - var corner = get_corner(i) - var next_corner = get_corner(i + 1) - - var shape = BoxShape3D.new() - shape.size = Vector3((next_corner.position - corner.position).length(), 3, 0.04) - - var transform = Transform3D() - var back_vector = (corner.position - next_corner.position).cross(Vector3.UP).normalized() * shape.size.z / 2 - - transform.basis = Basis((next_corner.position - corner.position).normalized(), Vector3.UP, back_vector.normalized()) - transform.origin = corner.position + (next_corner.position - corner.position) / 2 + back_vector + Vector3.UP * shape.size.y / 2 - - var collision_shape = CollisionShape3D.new() - - collision_shape.shape = shape - collision_shape.transform = transform - - collision_shapes.append(collision_shape) - - return collision_shapes - -func add_corner(position: Vector3): - var corner = wall_corner_scene.instantiate() - corner.position = position - - corner.get_node("Clickable").on_grab_down.connect(func(event): - if !editable: - return - - moving = event.target - ) - - corner.get_node("Clickable").on_grab_move.connect(func(event): - if moving == null: - return - - var direction = -event.ray.global_transform.basis.z - var new_position = ground_plane.intersects_ray(event.ray.global_position, direction) - - if new_position == null: - return - - moving.position = new_position - var moving_index = moving.get_index() - - get_edge(moving_index).transform = corners_to_edge_transform(new_position, get_corner(moving_index + 1).position) - get_edge(moving_index - 1).transform = corners_to_edge_transform(get_corner(moving_index - 1).position, new_position) - ) - - corner.get_node("Clickable").on_grab_up.connect(func(_event): - moving = null - ) - - wall_corners.add_child(corner) - - - var num_corners = wall_corners.get_child_count() - var edge - - if num_corners > 1: - edge = add_edge(wall_corners.get_child(num_corners - 2).position, position) - - if num_corners > 2: - if num_corners != wall_edges.get_child_count(): - add_edge(position, wall_corners.get_child(0).position) - else: - wall_edges.move_child(edge, num_corners - 2) - get_edge(-1).transform = corners_to_edge_transform(position, get_corner(0).position) + state_machine.change_to("View") func get_corner(index: int) -> MeshInstance3D: return wall_corners.get_child(index % wall_corners.get_child_count()) @@ -175,22 +24,6 @@ func get_edge(index: int) -> MeshInstance3D: return wall_edges.get_child(index % wall_edges.get_child_count()) -func add_edge(from_pos: Vector3, to_pos: Vector3): - var edge: MeshInstance3D = wall_edge_scene.instantiate() - edge.transform = corners_to_edge_transform(from_pos, to_pos) - wall_edges.add_child(edge) - return edge - -func corners_to_edge_transform(from_pos: Vector3, to_pos: Vector3) -> Transform3D: - var diff = to_pos - from_pos - var direction = diff.normalized() - - var edge_position = from_pos + diff / 2 - var edge_basis = Basis(Vector3.UP, diff, direction.cross(Vector3.UP)) - - var edge_transform = Transform3D(edge_basis, edge_position) - return edge_transform - func _save(): return { "corners": wall_corners.get_children().map(func(corner): return corner.position), @@ -198,8 +31,11 @@ func _save(): func _load(data): await ready + return + + state_machine.change_to("Edit") for corner in data["corners"]: - add_corner(corner) + state_machine.current_state.add_corner(corner) - _end_edit_mode() + state_machine.change_to("View") diff --git a/content/system/room/room.tscn b/content/system/room/room.tscn index 6270f6a..25eda74 100644 --- a/content/system/room/room.tscn +++ b/content/system/room/room.tscn @@ -1,42 +1,60 @@ -[gd_scene load_steps=7 format=3 uid="uid://bswgmclohuqui"] +[gd_scene load_steps=10 format=3 uid="uid://bswgmclohuqui"] [ext_resource type="Script" path="res://content/system/room/room.gd" id="1_fccq0"] [ext_resource type="Script" path="res://content/functions/clickable.gd" id="1_ugebq"] [ext_resource type="Material" uid="uid://bbx6fv7jq50tr" path="res://content/system/room/walls.tres" id="3_al1ev"] +[ext_resource type="Script" path="res://lib/utils/state_machine/state_machine.gd" id="4_nbbo6"] +[ext_resource type="Script" path="res://content/system/room/states/view.gd" id="6_g066t"] +[ext_resource type="Script" path="res://content/system/room/states/edit.gd" id="7_ap14h"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_08sv0"] [sub_resource type="ArrayMesh" id="ArrayMesh_7dibq"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_ap613"] +plane = Plane(0, -1, 0, 0) [node name="Room" type="Node3D"] script = ExtResource("1_fccq0") -[node name="Ground" type="StaticBody3D" parent="."] +[node name="Floor" type="StaticBody3D" parent="."] collision_layer = 24 collision_mask = 0 -[node name="CollisionShape3D" type="CollisionShape3D" parent="Ground"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor"] shape = SubResource("WorldBoundaryShape3D_08sv0") -[node name="Clickable" type="Node" parent="Ground"] +[node name="Clickable" type="Node" parent="Floor"] script = ExtResource("1_ugebq") -[node name="WallCorners" type="Node3D" parent="."] - -[node name="WallEdges" type="Node3D" parent="."] - [node name="WallMesh" type="MeshInstance3D" parent="."] material_override = ExtResource("3_al1ev") mesh = SubResource("ArrayMesh_7dibq") [node name="WallCollisions" type="Node3D" parent="."] -[node name="Celing" type="StaticBody3D" parent="."] -transform = Transform3D(-1, 8.74228e-08, 0, -8.74228e-08, -1, 0, 0, 0, 1, 0, 3.07, 0) -collision_layer = 0 +[node name="Ceiling" type="StaticBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) +collision_layer = 24 collision_mask = 0 -[node name="CollisionShape3D" type="CollisionShape3D" parent="Celing"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="Ceiling"] shape = SubResource("WorldBoundaryShape3D_ap613") +disabled = true + +[node name="Clickable" type="Node" parent="Ceiling"] +script = ExtResource("1_ugebq") + +[node name="WallCorners" type="Node3D" parent="Ceiling"] + +[node name="WallEdges" type="Node3D" parent="Ceiling"] + +[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")] +script = ExtResource("4_nbbo6") +current_state = NodePath("View") + +[node name="View" type="Node" parent="StateMachine"] +script = ExtResource("6_g066t") + +[node name="Edit" type="Node" parent="StateMachine"] +script = ExtResource("7_ap14h") diff --git a/content/system/room/states/edit.gd b/content/system/room/states/edit.gd new file mode 100644 index 0000000..330ab10 --- /dev/null +++ b/content/system/room/states/edit.gd @@ -0,0 +1,213 @@ +extends RoomState + +const wall_corner_scene = preload("../wall_corner.tscn") +const wall_edge_scene = preload("../wall_edge.tscn") +const RoomState = preload("./room_state.gd") + +var moving = null +var floor_corner: StaticBody3D = null +var height_corner: StaticBody3D = null +var height_edge: MeshInstance3D = null + +func _on_enter(): + room.wall_corners.visible = true + room.wall_edges.visible = true + + if floor_corner != null: + floor_corner.visible = true + height_corner.visible = true + height_edge.visible = true + + room.room_ceiling.get_node("Clickable").on_click.connect(_on_click_ceiling) + room.room_floor.get_node("Clickable").on_click.connect(_on_click_floor) + +func _on_leave(): + room.wall_corners.visible = false + room.wall_edges.visible = false + + if floor_corner != null: + floor_corner.visible = false + height_corner.visible = false + height_edge.visible = false + + room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling) + room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor) + +func _on_click_floor(event): + if floor_corner != null && height_corner != null: + return + + add_floor_corner(event.ray.get_collision_point()) + add_height_corner(event.ray.get_collision_point()) + room.room_ceiling.get_node("CollisionShape3D").disabled = false + +func _on_click_ceiling(event): + if floor_corner == null || height_corner == null: + return + + var pos = event.ray.get_collision_point() + pos.y = 0 + + add_corner(pos) + +func add_floor_corner(position: Vector3): + floor_corner = wall_corner_scene.instantiate() + floor_corner.position = position + + height_edge = wall_edge_scene.instantiate() + height_edge.transform = corners_to_edge_transform(position, position + Vector3.UP * room.room_ceiling.global_position.y) + + floor_corner.get_node("Clickable").on_grab_down.connect(func(event): + if !is_active(): + return + + moving = event.target + ) + + floor_corner.get_node("Clickable").on_grab_move.connect(func(event): + if moving == null: + return + + var direction = -event.ray.global_transform.basis.z + var new_position = room.room_floor.get_node("CollisionShape3D").shape.plane.intersects_ray(event.ray.global_position, direction) + + if new_position == null: + # mark for deletion + return + + moving.position = new_position + var moving_index = height_corner.get_index() + + height_edge.transform = corners_to_edge_transform(new_position, new_position + Vector3.UP * room.room_ceiling.global_position.y) + + room.get_corner(moving_index).position.x = new_position.x + room.get_corner(moving_index).position.z = new_position.z + + if room.wall_edges.get_child_count() == 0: + return + + room.get_edge(moving_index).transform = corners_to_edge_transform(new_position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index - 1).transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, new_position) + ) + + floor_corner.get_node("Clickable").on_grab_up.connect(func(_event): + moving = null + ) + + room.add_child(floor_corner) + room.add_child(height_edge) + +func add_height_corner(position: Vector3): + height_corner = wall_corner_scene.instantiate() + height_corner.position.x = position.x + height_corner.position.z = position.z + + height_corner.get_node("Clickable").on_grab_down.connect(func(event): + if !is_active(): + return + + moving = event.target + ) + + height_corner.get_node("Clickable").on_grab_move.connect(func(event): + if moving == null: + return + + var direction = -event.ray.global_transform.basis.z + var plane_direction = direction + plane_direction.y = 0 + plane_direction = plane_direction.normalized() * -1 + + var plane = Plane(plane_direction, moving.position) + + var new_position = plane.intersects_ray(event.ray.global_position, direction) + + if new_position == null: + return + + room.room_ceiling.position.y = new_position.y + height_edge.transform = corners_to_edge_transform(floor_corner.global_position, height_corner.global_position) + + ) + + height_corner.get_node("Clickable").on_grab_up.connect(func(_event): + moving = null + ) + + room.wall_corners.add_child(height_corner) + +func add_corner(position: Vector3): + var corner = wall_corner_scene.instantiate() + corner.position.x = position.x + corner.position.z = position.z + + corner.get_node("Clickable").on_grab_down.connect(func(event): + if !is_active(): + return + + moving = event.target + ) + + corner.get_node("Clickable").on_grab_move.connect(func(event): + if moving == null: + return + + var direction = -event.ray.global_transform.basis.z + var ceiling_plane = Plane(Vector3.DOWN, room.room_ceiling.global_position) + var new_position = ceiling_plane.intersects_ray(event.ray.global_position, direction) + + if new_position == null: + return + + new_position.y = 0 + + moving.position = new_position + var moving_index = moving.get_index() + + if room.wall_edges.get_child_count() == 0: + return + + room.get_edge(moving_index).transform = corners_to_edge_transform(new_position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index - 1).transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, new_position) + ) + + corner.get_node("Clickable").on_grab_up.connect(func(_event): + moving = null + ) + + room.wall_corners.add_child(corner) + + + var num_corners = room.wall_corners.get_child_count() + var edge + + if num_corners > 1: + edge = add_edge(room.wall_corners.get_child(num_corners - 2).position, position) + + if num_corners > 2: + if num_corners != room.wall_edges.get_child_count(): + add_edge(position, room.wall_corners.get_child(0).position) + else: + room.wall_edges.move_child(edge, num_corners - 2) + room.get_edge(-1).transform = corners_to_edge_transform(position, room.get_corner(0).position) + +func add_edge(from_pos: Vector3, to_pos: Vector3): + var edge: MeshInstance3D = wall_edge_scene.instantiate() + edge.transform = corners_to_edge_transform(from_pos, to_pos) + room.wall_edges.add_child(edge) + return edge + +func corners_to_edge_transform(from_pos: Vector3, to_pos: Vector3) -> Transform3D: + var diff = to_pos - from_pos + var direction = diff.normalized() + var tangent = Vector3(direction.z, 0, -direction.x).normalized() + + if tangent == Vector3.ZERO: + tangent = Vector3(1, 0, 0) + + var edge_position = from_pos + diff / 2 + + var edge_basis = Basis(tangent, diff, tangent.cross(direction)) + + var edge_transform = Transform3D(edge_basis, edge_position) + return edge_transform diff --git a/content/system/room/states/room_state.gd b/content/system/room/states/room_state.gd new file mode 100644 index 0000000..fa136b4 --- /dev/null +++ b/content/system/room/states/room_state.gd @@ -0,0 +1,7 @@ +extends State +const Room = preload("res://content/system/room/room.gd") + +var room: Room + +func _ready(): + room = get_parent().get_parent() diff --git a/content/system/room/states/view.gd b/content/system/room/states/view.gd new file mode 100644 index 0000000..e236d1e --- /dev/null +++ b/content/system/room/states/view.gd @@ -0,0 +1,86 @@ +extends RoomState + +const RoomState = preload("./room_state.gd") + +var room_height = 3 +var corner_count = 0 + +func _on_enter(): + corner_count = room.wall_corners.get_child_count() + + if corner_count < 3: + return + + room_height = room.get_corner(0).global_position.y + + room.wall_mesh.mesh = generate_mesh() + + if room.wall_mesh.mesh == null: + return + + var collisions = generate_collision() + + for collision in collisions: + var static_body = StaticBody3D.new() + static_body.set_collision_layer_value(4, true) + static_body.set_collision_layer_value(5, true) + static_body.collision_mask = 0 + static_body.add_child(collision) + room.wall_collisions.add_child(static_body) + + room.wall_mesh.visible = true + +func _on_leave(): + room.wall_mesh.mesh = null + + for collision in room.wall_collisions.get_children(): + collision.queue_free() + +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_collision(): + var collision_shapes: Array[CollisionShape3D] = [] + + for i in range(corner_count): + var corner = room.get_corner(i) + var next_corner = room.get_corner(i + 1) + + var shape = BoxShape3D.new() + shape.size = Vector3((next_corner.position - corner.position).length(), room_height, 0.04) + + var transform = Transform3D() + var back_vector = (corner.position - next_corner.position).cross(Vector3.UP).normalized() * shape.size.z / 2 + + transform.basis = Basis((next_corner.position - corner.position).normalized(), Vector3.UP, back_vector.normalized()) + transform.origin = corner.position + (next_corner.position - corner.position) / 2 + back_vector + Vector3.UP * shape.size.y / 2 + + var collision_shape = CollisionShape3D.new() + + collision_shape.shape = shape + collision_shape.transform = transform + + collision_shapes.append(collision_shape) + + return collision_shapes diff --git a/export_presets.cfg b/export_presets.cfg index 5c00108..6d05a01 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -248,7 +248,7 @@ architectures/armeabi-v7a=false architectures/arm64-v8a=true architectures/x86=false architectures/x86_64=false -version/code=6 +version/code=7 version/name="v0.2.0" package/unique_name="de.nitwel.$genname" package/name="Immersive Home" diff --git a/lib/utils/state_machine/state.gd b/lib/utils/state_machine/state.gd new file mode 100644 index 0000000..521d0ea --- /dev/null +++ b/lib/utils/state_machine/state.gd @@ -0,0 +1,13 @@ +extends Node +class_name State + +var state_machine: StateMachine + +func is_active(): + return state_machine.current_state == self + +func _on_enter(): + pass + +func _on_leave(): + pass \ No newline at end of file diff --git a/lib/utils/state_machine/state_machine.gd b/lib/utils/state_machine/state_machine.gd new file mode 100644 index 0000000..6fb7f7a --- /dev/null +++ b/lib/utils/state_machine/state_machine.gd @@ -0,0 +1,32 @@ +class_name StateMachine +extends Node + +signal changed(state_name: String, old_state: String) + +@export var current_state: Node +var states: Dictionary = {} + +func _ready() -> void: + for state in get_children(): + states[state.get_name()] = state + state.state_machine = self + + if state != current_state: + remove_child(state) + + await get_parent().ready + + current_state._on_enter() + +func change_to(new_state: String) -> void: + if states.has(new_state) == false: + return + + var old_state = current_state.get_name() + + current_state._on_leave() + remove_child(current_state) + current_state = states[new_state] + add_child(current_state) + current_state._on_enter() + changed.emit(new_state, old_state) \ No newline at end of file From 9b116a97ab7e24203f11b39e7a15a52c7a8e99d7 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 20 Dec 2023 01:54:22 +0100 Subject: [PATCH 02/17] implement foundation for a room system --- content/main.tscn | 7 +- content/system/house/house.gd | 67 +++++++++++++++++++ content/system/house/house.tscn | 10 +++ content/system/{ => house}/room/room.gd | 4 +- content/system/{ => house}/room/room.tscn | 8 +-- .../system/{ => house}/room/states/edit.gd | 0 .../{ => house}/room/states/room_state.gd | 2 +- .../system/{ => house}/room/states/view.gd | 2 + .../system/{ => house}/room/wall_corner.tscn | 0 .../system/{ => house}/room/wall_edge.tscn | 0 content/system/{ => house}/room/walls.tres | 0 content/ui/menu/edit/edit_menu.gd | 16 +---- content/ui/menu/room/room_menu.gd | 32 ++------- content/ui/menu/room/room_menu.tscn | 38 +++-------- lib/globals/house_body.gd | 3 + lib/globals/save_system.gd | 10 +++ .../utils/entity_factory.gd | 4 +- project.godot | 1 + 18 files changed, 123 insertions(+), 81 deletions(-) create mode 100644 content/system/house/house.gd create mode 100644 content/system/house/house.tscn rename content/system/{ => house}/room/room.gd (87%) rename content/system/{ => house}/room/room.tscn (85%) rename content/system/{ => house}/room/states/edit.gd (100%) rename content/system/{ => house}/room/states/room_state.gd (55%) rename content/system/{ => house}/room/states/view.gd (96%) rename content/system/{ => house}/room/wall_corner.tscn (100%) rename content/system/{ => house}/room/wall_edge.tscn (100%) rename content/system/{ => house}/room/walls.tres (100%) create mode 100644 lib/globals/house_body.gd rename content/ui/menu/edit/entity_creator.gd => lib/utils/entity_factory.gd (89%) diff --git a/content/main.tscn b/content/main.tscn index 6c09599..01c5320 100644 --- a/content/main.tscn +++ b/content/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=3 uid="uid://eecv28y6jxk4"] +[gd_scene load_steps=13 format=3 uid="uid://eecv28y6jxk4"] [ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="1_i4c04"] [ext_resource type="Script" path="res://content/main.gd" id="1_uvrd4"] @@ -7,7 +7,6 @@ [ext_resource type="PackedScene" uid="uid://bsx12q23v8apy" path="res://content/system/hands/hands.tscn" id="4_v8xu6"] [ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="5_3qc8g"] [ext_resource type="Material" uid="uid://bf5ina366dwm6" path="res://assets/materials/sky.material" id="5_wgwf8"] -[ext_resource type="PackedScene" uid="uid://83lb5p4e0qk0" path="res://content/scenes/house.tscn" id="8_qkrg7"] [ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m58yb"] @@ -71,10 +70,6 @@ shadow_enabled = true [node name="XRSimulator" parent="." instance=ExtResource("5_3qc8g")] xr_origin = NodePath("../XROrigin3D") -[node name="House" parent="." instance=ExtResource("8_qkrg7")] -transform = Transform3D(0.404247, 0.000180645, 0.914648, 0.00017221, 0.999999, -0.000273614, -0.914648, 0.00026812, 0.404247, -0.343479, 0.000110551, 1.91547) -visible = false - [node name="Keyboard" parent="." instance=ExtResource("9_e5n3p")] transform = Transform3D(0.499999, -6.98142e-12, 0, 4.74065e-12, 0.5, -2.27374e-13, 0, 2.27374e-13, 0.5, -0.125313, 0.424282, -0.263966) diff --git a/content/system/house/house.gd b/content/system/house/house.gd new file mode 100644 index 0000000..99aba60 --- /dev/null +++ b/content/system/house/house.gd @@ -0,0 +1,67 @@ +extends Node3D + +const Room = preload("./room/room.tscn") +const RoomType = preload("./room/room.gd") + +@onready var levels = $Levels + +var editing_room: RoomType = null + +func create_room(room_name: String, level: int) -> RoomType: + if editing_room != null: + 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) + + return room + +func edit_room(room_name: String): + if editing_room != null: + editing_room.editable = false + editing_room = null + + var room = find_room(room_name) + room.editable = true + editing_room = room + +func find_room(room_name: String): + for level in levels.get_children(): + for room in level.get_children(): + if room.name == room_name: + return room + return null + +func find_room_at(entity_position: Vector3): + for level in levels.get_children(): + for room in level.get_children(): + if room.has_point(entity_position): + return room + return null + +func get_level(level: int): + return levels.get_index(level) + +func get_rooms(level: int): + return get_level(level).get_children() + +func create_entity(entity_id: String, entity_position: Vector3): + var room = find_room_at(entity_position) + + if room == null: + return + + var entity = EntityFactory.create_entity(entity_id) + + if entity == null: + return + + room.add_child(entity) + entity.global_position = entity_position + + diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn new file mode 100644 index 0000000..d2de65c --- /dev/null +++ b/content/system/house/house.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://cbemihbxkd4ll"] + +[ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"] + +[node name="House" type="Node3D"] +script = ExtResource("1_p8amj") + +[node name="Levels" type="Node3D" parent="."] + +[node name="Level0" type="Node3D" parent="Levels"] diff --git a/content/system/room/room.gd b/content/system/house/room/room.gd similarity index 87% rename from content/system/room/room.gd rename to content/system/house/room/room.gd index 2c20233..5ed71f5 100644 --- a/content/system/room/room.gd +++ b/content/system/house/room/room.gd @@ -2,7 +2,7 @@ extends Node3D @onready var wall_corners = $Ceiling/WallCorners @onready var wall_edges = $Ceiling/WallEdges -@onready var wall_mesh = $WallMesh +@onready var wall_mesh: MeshInstance3D = $WallMesh @onready var wall_collisions = $WallCollisions @onready var room_floor = $Floor @@ -23,6 +23,8 @@ func get_corner(index: int) -> MeshInstance3D: func get_edge(index: int) -> MeshInstance3D: return wall_edges.get_child(index % wall_edges.get_child_count()) +func has_point(point: Vector3) -> bool: + return wall_mesh.get_aabb().has_point(point) func _save(): return { diff --git a/content/system/room/room.tscn b/content/system/house/room/room.tscn similarity index 85% rename from content/system/room/room.tscn rename to content/system/house/room/room.tscn index 25eda74..798df01 100644 --- a/content/system/room/room.tscn +++ b/content/system/house/room/room.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=10 format=3 uid="uid://bswgmclohuqui"] -[ext_resource type="Script" path="res://content/system/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="Material" uid="uid://bbx6fv7jq50tr" path="res://content/system/room/walls.tres" id="3_al1ev"] +[ext_resource type="Material" uid="uid://bbx6fv7jq50tr" path="res://content/system/house/room/walls.tres" id="3_al1ev"] [ext_resource type="Script" path="res://lib/utils/state_machine/state_machine.gd" id="4_nbbo6"] -[ext_resource type="Script" path="res://content/system/room/states/view.gd" id="6_g066t"] -[ext_resource type="Script" path="res://content/system/room/states/edit.gd" id="7_ap14h"] +[ext_resource type="Script" path="res://content/system/house/room/states/view.gd" id="6_g066t"] +[ext_resource type="Script" path="res://content/system/house/room/states/edit.gd" id="7_ap14h"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_08sv0"] diff --git a/content/system/room/states/edit.gd b/content/system/house/room/states/edit.gd similarity index 100% rename from content/system/room/states/edit.gd rename to content/system/house/room/states/edit.gd diff --git a/content/system/room/states/room_state.gd b/content/system/house/room/states/room_state.gd similarity index 55% rename from content/system/room/states/room_state.gd rename to content/system/house/room/states/room_state.gd index fa136b4..31e6877 100644 --- a/content/system/room/states/room_state.gd +++ b/content/system/house/room/states/room_state.gd @@ -1,5 +1,5 @@ extends State -const Room = preload("res://content/system/room/room.gd") +const Room = preload("res://content/system/house/room/room.gd") var room: Room diff --git a/content/system/room/states/view.gd b/content/system/house/room/states/view.gd similarity index 96% rename from content/system/room/states/view.gd rename to content/system/house/room/states/view.gd index e236d1e..6db4e1a 100644 --- a/content/system/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -53,6 +53,8 @@ func generate_mesh(): st.add_vertex(first_corner.position) st.add_vertex(first_corner.position + wall_up) + # TODO: Implement Rust Binding for cdt algorithm to fill floor and ceiling + st.index() st.generate_normals() st.generate_tangents() diff --git a/content/system/room/wall_corner.tscn b/content/system/house/room/wall_corner.tscn similarity index 100% rename from content/system/room/wall_corner.tscn rename to content/system/house/room/wall_corner.tscn diff --git a/content/system/room/wall_edge.tscn b/content/system/house/room/wall_edge.tscn similarity index 100% rename from content/system/room/wall_edge.tscn rename to content/system/house/room/wall_edge.tscn diff --git a/content/system/room/walls.tres b/content/system/house/room/walls.tres similarity index 100% rename from content/system/room/walls.tres rename to content/system/house/room/walls.tres diff --git a/content/ui/menu/edit/edit_menu.gd b/content/ui/menu/edit/edit_menu.gd index afcb926..247e717 100644 --- a/content/ui/menu/edit/edit_menu.gd +++ b/content/ui/menu/edit/edit_menu.gd @@ -1,7 +1,6 @@ extends Node3D const ButtonScene = preload("res://content/ui/components/button/button.tscn") -const EntityCreator = preload("./entity_creator.gd") @onready var devices_node: GridContainer3D = $Devices @onready var next_page_button = $Buttons/NextPageButton @@ -145,22 +144,11 @@ func _on_entity_click(entity_name): render() return - var type = entity_name.split(".")[0] AudioPlayer.play_effect("spawn") - var entity = EntityCreator.create_entity(type, entity_name) - - if entity == null: - return - - entity.set_position(global_position) - get_node("/root/Main").add_child(entity) + House.body.create_entity(entity_name, global_position) func clear_menu(): for child in devices_node.get_children(): devices_node.remove_child(child) - child.queue_free() - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass + child.queue_free() \ No newline at end of file diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 147c68b..667a027 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -1,40 +1,22 @@ extends Node3D -const Room = preload("res://content/system/room/room.tscn") +const Room = preload("res://content/system/house/room/room.tscn") +const RoomType = preload("res://content/system/house/room/room.gd") const window_scene = preload("./window.tscn") @onready var background = $Background -@onready var toggle_edit_button = $Interface/ToggleEdit -@onready var spawn_windows = $SpawnWindows -@onready var rooms = get_tree().root.get_node("Main/Rooms") -var room: Node3D func _ready(): background.visible = false HomeApi.on_connect.connect(func(): - if rooms.get_child_count() == 0: - room = Room.instantiate() - rooms.add_child(room) - else: - room = rooms.get_child(0) - if rooms.get_child_count() > 1: - for child in rooms.get_children(): - if child != room: - child.queue_free() - ) + var rooms = House.body.get_rooms(0) - spawn_windows.on_button_down.connect(func(): - get_tree().root.get_node("Main").add_child.call_deferred(window_scene.instantiate()) - ) + for room in rooms: + var mesh = room.wall_mesh + + - toggle_edit_button.on_button_down.connect(func(): - if room != null: - room.editable = true - ) - toggle_edit_button.on_button_up.connect(func(): - if room != null: - room.editable = false ) diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index e1df0ee..01c8224 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=5 format=3 uid="uid://c01gkeldvjwtr"] [ext_resource type="Script" path="res://content/ui/menu/room/room_menu.gd" id="1_ch4jb"] -[ext_resource type="Script" path="res://content/functions/clickable.gd" id="2_elugy"] -[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="3_whl7a"] +[ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_7m4yn"] +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="4_cghmp"] [sub_resource type="BoxMesh" id="BoxMesh_e37nn"] size = Vector3(0.3, 0.01, 0.3) @@ -12,35 +12,15 @@ script = ExtResource("1_ch4jb") [node name="Background" type="MeshInstance3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15) +material_override = ExtResource("2_7m4yn") mesh = SubResource("BoxMesh_e37nn") [node name="Interface" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.01, 0) -[node name="ToggleEdit" parent="Interface" instance=ExtResource("3_whl7a")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, 0, 0.05) -label = "room_preferences" -icon = true -toggleable = true - -[node name="Clickable" type="Node" parent="Interface/ToggleEdit"] -script = ExtResource("2_elugy") - -[node name="Label3D" type="Label3D" parent="Interface"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.13, -1.86265e-09, 0.05) -pixel_size = 0.001 -text = "Edit Room" -font_size = 18 -outline_size = 0 - -[node name="CreateBlur" type="Label3D" parent="."] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.15, 0.01, 0.261858) -pixel_size = 0.001 -text = "Fake Windows" -font_size = 18 -outline_size = 0 - -[node name="SpawnWindows" parent="." instance=ExtResource("3_whl7a")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, 0, 0.26) -label = "lens_blur" +[node name="Rooms" type="Node3D" parent="Interface"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.12) + +[node name="Button" parent="Interface" instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27) +label = "add" icon = true diff --git a/lib/globals/house_body.gd b/lib/globals/house_body.gd new file mode 100644 index 0000000..c10f30a --- /dev/null +++ b/lib/globals/house_body.gd @@ -0,0 +1,3 @@ +extends Node + +@onready var body = get_node("/root/Main/House") \ No newline at end of file diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index 000a9df..a45321f 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -2,8 +2,15 @@ extends Node const VariantSerializer = preload("res://lib/utils/variant_serializer.gd") +signal loaded() +signal unloaded() + +var is_loaded := false + func clear(): await _clear_save_tree(get_tree().root.get_node("Main")) + unloaded.emit() + is_loaded = false func save(): if HomeApi.has_connected() == false: @@ -43,6 +50,9 @@ func load(): else: _build_save_tree(save_tree) + loaded.emit() + is_loaded = true + func _clear_save_tree(node: Node): for child in node.get_children(): await _clear_save_tree(child) diff --git a/content/ui/menu/edit/entity_creator.gd b/lib/utils/entity_factory.gd similarity index 89% rename from content/ui/menu/edit/entity_creator.gd rename to lib/utils/entity_factory.gd index 25eb24b..8850d2d 100644 --- a/content/ui/menu/edit/entity_creator.gd +++ b/lib/utils/entity_factory.gd @@ -1,4 +1,5 @@ extends RefCounted +class_name EntityFactory const Switch = preload("res://content/entities/switch/switch.tscn") const Light = preload("res://content/entities/light/light.tscn") @@ -7,8 +8,9 @@ const MediaPlayer = preload("res://content/entities/media_player/media_player.ts const Camera = preload("res://content/entities/camera/camera.tscn") const ButtonEntity = preload("res://content/entities/button/button.tscn") -static func create_entity(type: String, id: String): +static func create_entity(id: String): var entity = null + var type = id.split(".")[0] match type: "switch": diff --git a/project.godot b/project.godot index 60f8748..fcaa8d9 100644 --- a/project.godot +++ b/project.godot @@ -24,6 +24,7 @@ HomeApi="*res://lib/globals/home_api.gd" AudioPlayer="*res://lib/globals/audio_player.gd" EventSystem="*res://lib/globals/event_system.gd" SaveSystem="*res://lib/globals/save_system.gd" +House="*res://lib/globals/house_body.gd" [editor_plugins] From e417468b71769eae11a51b6b1242dc75bf8ed849 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 20 Dec 2023 20:27:09 +0100 Subject: [PATCH 03/17] add godot-cdt --- .../libcdt.android.template_debug.arm64.so | 3 +++ addons/godot-cdt/libcdt.gdextension | 23 ++++++++++++++++++ .../libcdt.linux.template_debug.x86_64.so | 3 +++ .../libcdt.windows.template_debug.x86_64.dll | 3 +++ .../libcdt.windows.template_debug.x86_64.exp | Bin 0 -> 792 bytes .../libcdt.windows.template_debug.x86_64.lib | Bin 0 -> 2212 bytes .../~libcdt.windows.template_debug.x86_64.dll | 3 +++ 7 files changed, 35 insertions(+) create mode 100644 addons/godot-cdt/libcdt.android.template_debug.arm64.so create mode 100644 addons/godot-cdt/libcdt.gdextension create mode 100644 addons/godot-cdt/libcdt.linux.template_debug.x86_64.so create mode 100644 addons/godot-cdt/libcdt.windows.template_debug.x86_64.dll create mode 100644 addons/godot-cdt/libcdt.windows.template_debug.x86_64.exp create mode 100644 addons/godot-cdt/libcdt.windows.template_debug.x86_64.lib create mode 100644 addons/godot-cdt/~libcdt.windows.template_debug.x86_64.dll diff --git a/addons/godot-cdt/libcdt.android.template_debug.arm64.so b/addons/godot-cdt/libcdt.android.template_debug.arm64.so new file mode 100644 index 0000000..ddadad8 --- /dev/null +++ b/addons/godot-cdt/libcdt.android.template_debug.arm64.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b7de3e0f751bc77feb61c2d2599576cdc0f76711cf2d67dec3b523f808d903c +size 875984 diff --git a/addons/godot-cdt/libcdt.gdextension b/addons/godot-cdt/libcdt.gdextension new file mode 100644 index 0000000..64ba2d8 --- /dev/null +++ b/addons/godot-cdt/libcdt.gdextension @@ -0,0 +1,23 @@ +[configuration] + +entry_symbol = "example_library_init" +compatibility_minimum = 4.1 + +[libraries] + +macos.debug = "res://addons/godot-cdt/libcdt.macos.template_debug.framework" +macos.release = "res://addons/godot-cdt/libcdt.macos.template_release.framework" +windows.debug.x86_32 = "res://addons/godot-cdt/libcdt.windows.template_debug.x86_32.dll" +windows.release.x86_32 = "res://addons/godot-cdt/libcdt.windows.template_release.x86_32.dll" +windows.debug.x86_64 = "res://addons/godot-cdt/libcdt.windows.template_debug.x86_64.dll" +windows.release.x86_64 = "res://addons/godot-cdt/libcdt.windows.template_release.x86_64.dll" +linux.debug.x86_64 = "res://addons/godot-cdt/libcdt.linux.template_debug.x86_64.so" +linux.release.x86_64 = "res://addons/godot-cdt/libcdt.linux.template_release.x86_64.so" +linux.debug.arm64 = "res://addons/godot-cdt/libcdt.linux.template_debug.arm64.so" +linux.release.arm64 = "res://addons/godot-cdt/libcdt.linux.template_release.arm64.so" +linux.debug.rv64 = "res://addons/godot-cdt/libcdt.linux.template_debug.rv64.so" +linux.release.rv64 = "res://addons/godot-cdt/libcdt.linux.template_release.rv64.so" +android.debug.x86_64 = "res://addons/godot-cdt/libcdt.android.template_debug.x86_64.so" +android.release.x86_64 = "res://addons/godot-cdt/libcdt.android.template_release.x86_64.so" +android.debug.arm64 = "res://addons/godot-cdt/libcdt.android.template_debug.arm64.so" +android.release.arm64 = "res://addons/godot-cdt/libcdt.android.template_release.arm64.so" \ No newline at end of file diff --git a/addons/godot-cdt/libcdt.linux.template_debug.x86_64.so b/addons/godot-cdt/libcdt.linux.template_debug.x86_64.so new file mode 100644 index 0000000..a9bfc8a --- /dev/null +++ b/addons/godot-cdt/libcdt.linux.template_debug.x86_64.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95bda34ae6ebb2010c5a5e1bd0ccd994df43e5e5f956e214da3c6adae4521add +size 974176 diff --git a/addons/godot-cdt/libcdt.windows.template_debug.x86_64.dll b/addons/godot-cdt/libcdt.windows.template_debug.x86_64.dll new file mode 100644 index 0000000..aaf3431 --- /dev/null +++ b/addons/godot-cdt/libcdt.windows.template_debug.x86_64.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:418c2ca8e73932710184b3bc4de4b40a32fc7ef0369354f8a08fbacd01155f50 +size 871936 diff --git a/addons/godot-cdt/libcdt.windows.template_debug.x86_64.exp b/addons/godot-cdt/libcdt.windows.template_debug.x86_64.exp new file mode 100644 index 0000000000000000000000000000000000000000..80a6e58750ef90d149b13c2ac2cce3d40dd6fbfe GIT binary patch literal 792 zcma)4-AWrl6h2AX`a>znrRYT{xlnAUn;(L$7J^D^(Wa#-Qg9$lcE&Kcn^|^en^?T| z1$-jkzzbibPf)+vWNiuxJIYtums=Epl7%{ zI83TRI;{0(Fl`rz%HVnGP*w-kIOBEVE&?Ej|#i~g}o3v9|K%N^HG@}>vlCCd^ zK5IWVi8-~^^=}*1qfgyKx}x_L^2hR#?1@QZU!i~H9KOb87>n?O4phSb20PYCDuQay zrcxW;@EQ%iXTmVWkk0w>9{+Ak0RJA;dW$u2>TjFPtf>Q&*dOf{pMV2BI%6&qtPoFBjYbIw$!^vYF!Uhr;~dGO12p8c2uMl$OoIb1KQTD+5i9m literal 0 HcmV?d00001 diff --git a/addons/godot-cdt/libcdt.windows.template_debug.x86_64.lib b/addons/godot-cdt/libcdt.windows.template_debug.x86_64.lib new file mode 100644 index 0000000000000000000000000000000000000000..88cbaeef82edaadeadef51a91d1a3339b6f497ca GIT binary patch literal 2212 zcmcguO-~b16g{0*#KxFL2^%%3hD0=R`oU1EQ8HCDHk3k2ap`pE3^GYen=%AUNK9CC z<$|q0z+d3TCAe^HT=*M|OP3hMduQG&MQWH5(nn_Q$K3ngz2}|x%8iF+tGY53O~j9m zyQ!nLw30$eC$mDUL;;)wlpPW(FtiN}kMd&}`PuooQrVb(y6~iwpD)jqjGD7lwOn<> zS+yD)YpQG4n>Ew54a;6yf2D3_Ge$;(VH6h&h2zP^Gm zG-)lHD`=Um*M_s|xajHZ8;jH-77+qtM*&nqWP1o09rnOM2nr(f7p7{?8kK(gI~|IN ze_%O@AzFt)m1vM{Q>|JJ(S#(JVAn~jWKuGr61Cc4jO>5>{wzf7qkZ6^dc+!A@Gama zDQ~4Aq>k8Q)v-+1981ejBc%MG=Z|oNN$N=Minxq$;|?j;XgwLnejV{$q5u-Oz$V6n zwtov(V&^I0iTRi#NgS1 z7s6tpc)NA>XXcb=K$0yWJJa{>cWz0mt>B%#{`;HPmEU47c3S?Y&by196Vl1-{3Hz_ znVo}YT@bchrwadjrT2Z}Cp4`K(=gtD`1)&~R`9vg_lcjBF!GJTC%${=(B+BOq@Uw{ tN<&DF8!YxgaDPD64Tk60wAhk3|2M$5hSgran)^KE;S=foGaL9y`U`|(-<$vd literal 0 HcmV?d00001 diff --git a/addons/godot-cdt/~libcdt.windows.template_debug.x86_64.dll b/addons/godot-cdt/~libcdt.windows.template_debug.x86_64.dll new file mode 100644 index 0000000..aaf3431 --- /dev/null +++ b/addons/godot-cdt/~libcdt.windows.template_debug.x86_64.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:418c2ca8e73932710184b3bc4de4b40a32fc7ef0369354f8a08fbacd01155f50 +size 871936 From 228e32495c4c51aa389d06e7701a504b1a3019cb Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 20 Dec 2023 22:19:43 +0100 Subject: [PATCH 04/17] implement mesh generation and add basic room overview --- content/main.gd | 11 ++- content/main.tscn | 5 +- content/system/house/house.gd | 20 +++-- content/system/house/room/room.gd | 6 ++ content/system/house/room/room.tscn | 3 + content/system/house/room/states/view.gd | 45 ++++++++++- content/system/house/room/walls.tres | 4 +- content/ui/menu/room/room_menu.gd | 99 ++++++++++++++++++++++-- content/ui/menu/room/room_menu.tscn | 18 ++++- 9 files changed, 188 insertions(+), 23 deletions(-) diff --git a/content/main.gd b/content/main.gd index 855ca82..836fc9a 100644 --- a/content/main.gd +++ b/content/main.gd @@ -7,16 +7,14 @@ var sky_passthrough = preload("res://assets/materials/sky_passthrough.material") @onready var camera: XRCamera3D = $XROrigin3D/XRCamera3D @onready var controller_left = $XROrigin3D/XRControllerLeft @onready var controller_right = $XROrigin3D/XRControllerRight -@onready var house = $House func _ready(): # In case we're running on the headset, use the passthrough sky if OS.get_name() == "Android": # OS.request_permissions() environment.environment.sky.set_material(sky_passthrough) - house.visible = false else: - house.visible = true + RenderingServer.set_debug_generate_wireframes(true) func _process(delta): if OS.get_name() != "Android": @@ -34,6 +32,11 @@ func _process(delta): camera.position += movement controller_left.position += movement controller_right.position += movement + +func _input(event): + if event is InputEventKey and Input.is_key_pressed(KEY_F10): + var vp = get_viewport() + vp.debug_draw = (vp.debug_draw + 1) % 5 func vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y: int, key_negative_y: int): @@ -54,4 +57,4 @@ func vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y if vec: vec = vec.normalized() - return vec \ No newline at end of file + return vec diff --git a/content/main.tscn b/content/main.tscn index 01c5320..08cfec9 100644 --- a/content/main.tscn +++ b/content/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://eecv28y6jxk4"] +[gd_scene load_steps=14 format=3 uid="uid://eecv28y6jxk4"] [ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="1_i4c04"] [ext_resource type="Script" path="res://content/main.gd" id="1_uvrd4"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="5_3qc8g"] [ext_resource type="Material" uid="uid://bf5ina366dwm6" path="res://assets/materials/sky.material" id="5_wgwf8"] [ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"] +[ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m58yb"] ao_enabled = true @@ -75,4 +76,6 @@ transform = Transform3D(0.499999, -6.98142e-12, 0, 4.74065e-12, 0.5, -2.27374e-1 [node name="Rooms" type="Node3D" parent="."] +[node name="House" parent="." instance=ExtResource("9_np6mw")] + [editable path="XROrigin3D/XRControllerLeft"] diff --git a/content/system/house/house.gd b/content/system/house/house.gd index 99aba60..991b3a8 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -21,16 +21,24 @@ func create_room(room_name: String, level: int) -> RoomType: return room -func edit_room(room_name: String): +func edit_room(room_name): + var room = find_room(room_name) + + if room == editing_room: + return + if editing_room != null: editing_room.editable = false editing_room = null + + if room != null: + room.editable = true + editing_room = room - var room = find_room(room_name) - room.editable = true - editing_room = room +func is_editiong(room_name): + return editing_room != null && editing_room.name == room_name -func find_room(room_name: String): +func find_room(room_name): for level in levels.get_children(): for room in level.get_children(): if room.name == room_name: @@ -45,7 +53,7 @@ func find_room_at(entity_position: Vector3): return null func get_level(level: int): - return levels.get_index(level) + return levels.get_child(level) func get_rooms(level: int): return get_level(level).get_children() diff --git a/content/system/house/room/room.gd b/content/system/house/room/room.gd index 5ed71f5..1cae35c 100644 --- a/content/system/house/room/room.gd +++ b/content/system/house/room/room.gd @@ -3,6 +3,7 @@ extends Node3D @onready var wall_corners = $Ceiling/WallCorners @onready var wall_edges = $Ceiling/WallEdges @onready var wall_mesh: MeshInstance3D = $WallMesh +@onready var ceiling_mesh: MeshInstance3D = $CeilingMesh @onready var wall_collisions = $WallCollisions @onready var room_floor = $Floor @@ -12,6 +13,8 @@ extends Node3D var editable: bool = false: set(value): + if !is_node_ready(): await ready + if value: state_machine.change_to("Edit") else: @@ -29,12 +32,15 @@ func has_point(point: Vector3) -> bool: func _save(): return { "corners": wall_corners.get_children().map(func(corner): return corner.position), + "name": name } func _load(data): await ready return + name = data["name"] + state_machine.change_to("Edit") for corner in data["corners"]: diff --git a/content/system/house/room/room.tscn b/content/system/house/room/room.tscn index 798df01..688e140 100644 --- a/content/system/house/room/room.tscn +++ b/content/system/house/room/room.tscn @@ -31,6 +31,9 @@ script = ExtResource("1_ugebq") material_override = ExtResource("3_al1ev") mesh = SubResource("ArrayMesh_7dibq") +[node name="CeilingMesh" type="MeshInstance3D" parent="."] +material_override = ExtResource("3_al1ev") + [node name="WallCollisions" type="Node3D" parent="."] [node name="Ceiling" type="StaticBody3D" parent="."] diff --git a/content/system/house/room/states/view.gd b/content/system/house/room/states/view.gd index 6db4e1a..6237580 100644 --- a/content/system/house/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -17,6 +17,8 @@ func _on_enter(): if room.wall_mesh.mesh == null: return + + room.ceiling_mesh.mesh = generate_ceiling_mesh() var collisions = generate_collision() @@ -53,8 +55,6 @@ func generate_mesh(): st.add_vertex(first_corner.position) st.add_vertex(first_corner.position + wall_up) - # TODO: Implement Rust Binding for cdt algorithm to fill floor and ceiling - st.index() st.generate_normals() st.generate_tangents() @@ -62,6 +62,47 @@ func generate_mesh(): 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(): var collision_shapes: Array[CollisionShape3D] = [] diff --git a/content/system/house/room/walls.tres b/content/system/house/room/walls.tres index b0ebc48..c9a6a4d 100644 --- a/content/system/house/room/walls.tres +++ b/content/system/house/room/walls.tres @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fe7c098cfc9adadb447df0230eba8a81f1825dd3c0cf4e654ebf98ca2314c8cc -size 151 +oid sha256:935bcbcfaa2d5dca17ce3efea167357dca8b5ac05f49d5b322add9a84607b4f0 +size 158 diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 667a027..775a149 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -6,6 +6,26 @@ const RoomType = preload("res://content/system/house/room/room.gd") const window_scene = preload("./window.tscn") @onready var background = $Background +@onready var add_room_button = $Interface/AddRoom +@onready var save_room_button = $Interface/SaveRoom +@onready var input = $Interface/Input +@onready var rooms_map = $Interface/Rooms + +var selected_room = null: + set(value): + selected_room = value + if value != null: + save_room_button.visible = true + else: + save_room_button.visible = false + +var edit_room = false: + set(value): + edit_room = value + if value: + save_room_button.label = "save" + else: + save_room_button.label = "edit" func _ready(): background.visible = false @@ -13,10 +33,79 @@ func _ready(): HomeApi.on_connect.connect(func(): var rooms = House.body.get_rooms(0) - for room in rooms: - var mesh = room.wall_mesh - - - + # for room in rooms: + # var mesh = room.wall_mesh ) + + add_room_button.on_button_down.connect(func(): + var room_name = input.text + House.body.create_room(room_name, 0) + selected_room = room_name + edit_room = true + add_room_button.visible = false + ) + + save_room_button.on_button_down.connect(func(): + if edit_room: + edit_room = false + add_room_button.visible = true + House.body.edit_room(null) + _generate_room_map() + else: + edit_room = true + House.body.edit_room(selected_room) + ) + +func _on_click(event: EventPointer): + if event.target.get_parent() == rooms_map: + var room_name = event.target.name + selected_room = room_name + edit_room = false + add_room_button.visible = false + House.body.edit_room(selected_room) + +func _generate_room_map(): + var rooms = House.body.get_rooms(0) + + var target_size = Vector2(0.3, 0.2) + + for old_room in rooms_map.get_children(): + old_room.queue_free() + + var current_min = Vector2(0, 0) + var current_max = Vector2(0, 0) + + for room in rooms: + var body = StaticBody3D.new() + + var mesh = room.ceiling_mesh.mesh + var mesh_instance = MeshInstance3D.new() + mesh_instance.mesh = mesh + mesh_instance.material_override = load("res://content/system/house/room/walls.tres") + body.add_child(mesh_instance) + + var collision_shape = CollisionShape3D.new() + collision_shape.shape = mesh.create_trimesh_shape() + body.add_child(collision_shape) + + rooms_map.add_child(body) + + if mesh.get_aabb().position.x < current_min.x: + current_min.x = mesh.get_aabb().position.x + + if mesh.get_aabb().position.z < current_min.y: + current_min.y = mesh.get_aabb().position.z + + if mesh.get_aabb().end.x > current_max.x: + current_max.x = mesh.get_aabb().end.x + + if mesh.get_aabb().end.z > current_max.y: + current_max.y = mesh.get_aabb().end.z + + var current_size = current_max - current_min + + var target_scale = target_size / current_size + var scale_value = max(target_scale.x, target_scale.y) + + rooms_map.scale = Vector3(scale_value, scale_value, scale_value) diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index 01c8224..32dc947 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=5 format=3 uid="uid://c01gkeldvjwtr"] +[gd_scene load_steps=6 format=3 uid="uid://c01gkeldvjwtr"] [ext_resource type="Script" path="res://content/ui/menu/room/room_menu.gd" id="1_ch4jb"] [ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_7m4yn"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="4_cghmp"] +[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="4_pbj71"] [sub_resource type="BoxMesh" id="BoxMesh_e37nn"] size = Vector3(0.3, 0.01, 0.3) @@ -18,9 +19,20 @@ mesh = SubResource("BoxMesh_e37nn") [node name="Interface" type="Node3D" parent="."] [node name="Rooms" type="Node3D" parent="Interface"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.12) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12) -[node name="Button" parent="Interface" instance=ExtResource("4_cghmp")] +[node name="AddRoom" parent="Interface" instance=ExtResource("4_cghmp")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27) label = "add" icon = true + +[node name="SaveRoom" parent="Interface" instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.27) +visible = false +label = "save" +icon = true + +[node name="Input" parent="Interface" instance=ExtResource("4_pbj71")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0.005, 0.27) +width = 0.15 +text = "New Room" From 40f6c00eb8f443988f076b1be87a00cc9f6b44cf Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 21 Dec 2023 16:44:56 +0100 Subject: [PATCH 05/17] update cdt lib and fix basic room creation and ui --- .../libcdt.android.template_debug.arm64.so | 4 +- .../libcdt.android.template_debug.x86_64.so | 3 + .../libcdt.android.template_release.arm64.so | 3 + .../libcdt.android.template_release.x86_64.so | 3 + addons/godot-cdt/libcdt.gdextension | 2 - content/system/house/room/states/edit.gd | 8 ++ content/system/house/room/states/view.gd | 4 + content/system/house/room/walls_selected.tres | 3 + content/ui/menu/room/room_menu.gd | 129 ++++++++++++------ content/ui/menu/room/room_menu.tscn | 13 +- lib/globals/home_api.gd | 3 +- 11 files changed, 118 insertions(+), 57 deletions(-) create mode 100644 addons/godot-cdt/libcdt.android.template_debug.x86_64.so create mode 100644 addons/godot-cdt/libcdt.android.template_release.arm64.so create mode 100644 addons/godot-cdt/libcdt.android.template_release.x86_64.so create mode 100644 content/system/house/room/walls_selected.tres diff --git a/addons/godot-cdt/libcdt.android.template_debug.arm64.so b/addons/godot-cdt/libcdt.android.template_debug.arm64.so index ddadad8..c235450 100644 --- a/addons/godot-cdt/libcdt.android.template_debug.arm64.so +++ b/addons/godot-cdt/libcdt.android.template_debug.arm64.so @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8b7de3e0f751bc77feb61c2d2599576cdc0f76711cf2d67dec3b523f808d903c -size 875984 +oid sha256:5b6a62d5ec5e2c9414b983a90041f1d674e092f71a9b5563277d2b6ad552a8d2 +size 6274408 diff --git a/addons/godot-cdt/libcdt.android.template_debug.x86_64.so b/addons/godot-cdt/libcdt.android.template_debug.x86_64.so new file mode 100644 index 0000000..7492fcb --- /dev/null +++ b/addons/godot-cdt/libcdt.android.template_debug.x86_64.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70a9f2c799d3d6703bd95abaacdd82c0d1b7a66fc39098aac64c330b0be0db06 +size 5855024 diff --git a/addons/godot-cdt/libcdt.android.template_release.arm64.so b/addons/godot-cdt/libcdt.android.template_release.arm64.so new file mode 100644 index 0000000..936fedd --- /dev/null +++ b/addons/godot-cdt/libcdt.android.template_release.arm64.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e679688861d608c244393a7e3366539fa067ca75f71c3efb916d8745423cc7f +size 6003048 diff --git a/addons/godot-cdt/libcdt.android.template_release.x86_64.so b/addons/godot-cdt/libcdt.android.template_release.x86_64.so new file mode 100644 index 0000000..b654783 --- /dev/null +++ b/addons/godot-cdt/libcdt.android.template_release.x86_64.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27f82d0c296c1ae8d71754353ee3f9c32955fe7a56ffbd54ca4f171a40827387 +size 5612432 diff --git a/addons/godot-cdt/libcdt.gdextension b/addons/godot-cdt/libcdt.gdextension index 64ba2d8..c7ec10c 100644 --- a/addons/godot-cdt/libcdt.gdextension +++ b/addons/godot-cdt/libcdt.gdextension @@ -17,7 +17,5 @@ linux.debug.arm64 = "res://addons/godot-cdt/libcdt.linux.template_debug.arm64.so linux.release.arm64 = "res://addons/godot-cdt/libcdt.linux.template_release.arm64.so" linux.debug.rv64 = "res://addons/godot-cdt/libcdt.linux.template_debug.rv64.so" linux.release.rv64 = "res://addons/godot-cdt/libcdt.linux.template_release.rv64.so" -android.debug.x86_64 = "res://addons/godot-cdt/libcdt.android.template_debug.x86_64.so" -android.release.x86_64 = "res://addons/godot-cdt/libcdt.android.template_release.x86_64.so" android.debug.arm64 = "res://addons/godot-cdt/libcdt.android.template_debug.arm64.so" android.release.arm64 = "res://addons/godot-cdt/libcdt.android.template_release.arm64.so" \ No newline at end of file diff --git a/content/system/house/room/states/edit.gd b/content/system/house/room/states/edit.gd index 330ab10..22f124a 100644 --- a/content/system/house/room/states/edit.gd +++ b/content/system/house/room/states/edit.gd @@ -18,6 +18,14 @@ func _on_enter(): height_corner.visible = true height_edge.visible = true + room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null && height_corner == null) + + var ceiling_shape = WorldBoundaryShape3D.new() + ceiling_shape.plane = Plane(Vector3.DOWN, 0) + + room.room_ceiling.get_node("CollisionShape3D").shape = ceiling_shape + room.room_floor.get_node("CollisionShape3D").shape = WorldBoundaryShape3D.new() + room.room_ceiling.get_node("Clickable").on_click.connect(_on_click_ceiling) room.room_floor.get_node("Clickable").on_click.connect(_on_click_floor) diff --git a/content/system/house/room/states/view.gd b/content/system/house/room/states/view.gd index 6237580..b20b181 100644 --- a/content/system/house/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -19,6 +19,9 @@ func _on_enter(): return room.ceiling_mesh.mesh = generate_ceiling_mesh() + room.room_ceiling.get_node("CollisionShape3D").shape = room.ceiling_mesh.mesh.create_trimesh_shape() + room.room_floor.get_node("CollisionShape3D").shape = room.ceiling_mesh.mesh.create_trimesh_shape() + room.room_ceiling.get_node("CollisionShape3D").shape.backface_collision = true var collisions = generate_collision() @@ -34,6 +37,7 @@ func _on_enter(): func _on_leave(): room.wall_mesh.mesh = null + room.ceiling_mesh.mesh = null for collision in room.wall_collisions.get_children(): collision.queue_free() diff --git a/content/system/house/room/walls_selected.tres b/content/system/house/room/walls_selected.tres new file mode 100644 index 0000000..5ff9fcc --- /dev/null +++ b/content/system/house/room/walls_selected.tres @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7af833108b37da9ba445d2da6dbac058b5894f550177bf917fb9ab9fb6ecd1c +size 172 diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 775a149..6aad742 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -3,29 +3,44 @@ extends Node3D const Room = preload("res://content/system/house/room/room.tscn") const RoomType = preload("res://content/system/house/room/room.gd") +const material_selected = preload("res://content/system/house/room/walls_selected.tres") +const material_unselected = preload("res://content/system/house/room/walls.tres") + const window_scene = preload("./window.tscn") @onready var background = $Background -@onready var add_room_button = $Interface/AddRoom -@onready var save_room_button = $Interface/SaveRoom +@onready var room_button = $Interface/Button @onready var input = $Interface/Input @onready var rooms_map = $Interface/Rooms var selected_room = null: set(value): - selected_room = value + if selected_room != null && value == null: + room_button.label = "add" + input.text = "New Room %s" % (rooms_map.get_child_count() + 1) + + if selected_room != null: + var old_room = get_room(selected_room) + if old_room != null: + old_room.get_node("MeshInstance3D").material_override = material_unselected + if value != null: - save_room_button.visible = true - else: - save_room_button.visible = false + input.text = value + edit_room = false + var new_room = get_room(value) + if new_room != null: + new_room.get_node("MeshInstance3D").material_override = material_selected + + + selected_room = value var edit_room = false: set(value): edit_room = value if value: - save_room_button.label = "save" + room_button.label = "save" else: - save_room_button.label = "edit" + room_button.label = "edit" func _ready(): background.visible = false @@ -38,51 +53,67 @@ func _ready(): ) - add_room_button.on_button_down.connect(func(): - var room_name = input.text - House.body.create_room(room_name, 0) - selected_room = room_name - edit_room = true - add_room_button.visible = false + room_button.on_button_down.connect(func(): + if selected_room == null: + var room_name = input.text + if get_room(room_name) != null: + EventSystem.notify("Name already taken", EventNotify.Type.WARNING) + return + + House.body.create_room(room_name, 0) + selected_room = room_name + edit_room = true + else: + if edit_room: + edit_room = false + House.body.edit_room(null) + _generate_room_map() + else: + edit_room = true + House.body.edit_room(selected_room) ) - save_room_button.on_button_down.connect(func(): - if edit_room: - edit_room = false - add_room_button.visible = true - House.body.edit_room(null) - _generate_room_map() - else: - edit_room = true - House.body.edit_room(selected_room) - ) +func get_room(room_name): + if rooms_map.has_node("%s" % room_name): + return rooms_map.get_node("%s" % room_name) + return null func _on_click(event: EventPointer): if event.target.get_parent() == rooms_map: var room_name = event.target.name + + if selected_room == room_name: + selected_room = null + House.body.edit_room(null) + return + selected_room = room_name - edit_room = false - add_room_button.visible = false - House.body.edit_room(selected_room) func _generate_room_map(): var rooms = House.body.get_rooms(0) - var target_size = Vector2(0.3, 0.2) + var target_size = Vector2(0.3, 0.24) for old_room in rooms_map.get_children(): old_room.queue_free() + await old_room.tree_exited - var current_min = Vector2(0, 0) - var current_max = Vector2(0, 0) + var current_min = null + var current_max = null for room in rooms: - var body = StaticBody3D.new() - var mesh = room.ceiling_mesh.mesh + if mesh == null: + continue + + var body = StaticBody3D.new() + body.name = room.name + + var mesh_instance = MeshInstance3D.new() + mesh_instance.name = "MeshInstance3D" mesh_instance.mesh = mesh - mesh_instance.material_override = load("res://content/system/house/room/walls.tres") + mesh_instance.material_override = material_unselected if selected_room != room.name else material_selected body.add_child(mesh_instance) var collision_shape = CollisionShape3D.new() @@ -91,21 +122,35 @@ func _generate_room_map(): rooms_map.add_child(body) - if mesh.get_aabb().position.x < current_min.x: - current_min.x = mesh.get_aabb().position.x + var aabb_position = room.ceiling_mesh.to_global(mesh.get_aabb().position) + var aabb_end = room.ceiling_mesh.to_global(mesh.get_aabb().end) - if mesh.get_aabb().position.z < current_min.y: - current_min.y = mesh.get_aabb().position.z + if current_min == null: + current_min = Vector2(aabb_position.x, aabb_position.z) + current_max = Vector2(aabb_end.x, aabb_end.z) + else: + if aabb_position.x < current_min.x: + current_min.x = aabb_position.x - if mesh.get_aabb().end.x > current_max.x: - current_max.x = mesh.get_aabb().end.x + if aabb_position.z < current_min.y: + current_min.y = aabb_position.z - if mesh.get_aabb().end.z > current_max.y: - current_max.y = mesh.get_aabb().end.z + if aabb_end.x > current_max.x: + current_max.x = aabb_end.x + + if aabb_end.z > current_max.y: + current_max.y = aabb_end.z + + print(current_min, " ", current_max) var current_size = current_max - current_min var target_scale = target_size / current_size - var scale_value = max(target_scale.x, target_scale.y) + + print(target_scale) + var scale_value = min(target_scale.x, target_scale.y) + + rooms_map.position.x = -current_min.x * scale_value + rooms_map.position.z = -current_min.y * scale_value rooms_map.scale = Vector3(scale_value, scale_value, scale_value) diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index 32dc947..1fb43d7 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -21,18 +21,11 @@ mesh = SubResource("BoxMesh_e37nn") [node name="Rooms" type="Node3D" parent="Interface"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12) -[node name="AddRoom" parent="Interface" instance=ExtResource("4_cghmp")] +[node name="Button" parent="Interface" instance=ExtResource("4_cghmp")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27) label = "add" icon = true -[node name="SaveRoom" parent="Interface" instance=ExtResource("4_cghmp")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.27) -visible = false -label = "save" -icon = true - [node name="Input" parent="Interface" instance=ExtResource("4_pbj71")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0.005, 0.27) -width = 0.15 -text = "New Room" +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27) +text = "New Room 1" diff --git a/lib/globals/home_api.gd b/lib/globals/home_api.gd index 85fa799..81801da 100644 --- a/lib/globals/home_api.gd +++ b/lib/globals/home_api.gd @@ -96,4 +96,5 @@ func watch_state(entity: String, callback: Callable): func _notification(what): if what == NOTIFICATION_WM_CLOSE_REQUEST || what == NOTIFICATION_WM_GO_BACK_REQUEST: - SaveSystem.save() \ No newline at end of file + # SaveSystem.save() + pass \ No newline at end of file From b38a492bcc9c48dee962922984e619393d970c76 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 21 Dec 2023 18:35:43 +0100 Subject: [PATCH 06/17] implement way for adding and removing corners --- content/system/house/house.gd | 21 ++++++ .../{ui/menu => system/house}/room/edge.tres | 0 content/system/house/room/room.gd | 4 ++ content/system/house/room/states/edit.gd | 64 ++++++++++++++----- content/system/house/room/wall_corner.tscn | 2 +- content/system/house/room/wall_edge.tscn | 21 ++++-- content/system/house/room/walls.tres | 4 +- content/system/house/room/walls_selected.tres | 3 - content/ui/menu/room/room_menu.gd | 17 +++-- content/ui/menu/room/room_selected.tres | 3 + content/ui/menu/room/room_unselected.tres | 3 + 11 files changed, 108 insertions(+), 34 deletions(-) rename content/{ui/menu => system/house}/room/edge.tres (100%) delete mode 100644 content/system/house/room/walls_selected.tres create mode 100644 content/ui/menu/room/room_selected.tres create mode 100644 content/ui/menu/room/room_unselected.tres diff --git a/content/system/house/house.gd b/content/system/house/house.gd index 991b3a8..dd154a5 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -35,6 +35,27 @@ func edit_room(room_name): room.editable = true editing_room = room +func is_valid_room(room_name): + var room = find_room(room_name) + + if room == null: + return + + return room.wall_corners.get_child_count() >= 3 + + +func delete_room(room_name): + var room = find_room(room_name) + + if room == null: + return + + if editing_room == room: + editing_room = null + + room.get_parent().remove_child(room) + room.queue_free() + func is_editiong(room_name): return editing_room != null && editing_room.name == room_name diff --git a/content/ui/menu/room/edge.tres b/content/system/house/room/edge.tres similarity index 100% rename from content/ui/menu/room/edge.tres rename to content/system/house/room/edge.tres diff --git a/content/system/house/room/room.gd b/content/system/house/room/room.gd index 1cae35c..c0dbc7c 100644 --- a/content/system/house/room/room.gd +++ b/content/system/house/room/room.gd @@ -29,6 +29,10 @@ func get_edge(index: int) -> MeshInstance3D: func has_point(point: Vector3) -> bool: return wall_mesh.get_aabb().has_point(point) +func remove_corner(index: int): + get_corner(index).queue_free() + get_edge(index).queue_free() + func _save(): return { "corners": wall_corners.get_children().map(func(corner): return corner.position), diff --git a/content/system/house/room/states/edit.gd b/content/system/house/room/states/edit.gd index 22f124a..152a557 100644 --- a/content/system/house/room/states/edit.gd +++ b/content/system/house/room/states/edit.gd @@ -5,9 +5,10 @@ const wall_edge_scene = preload("../wall_edge.tscn") const RoomState = preload("./room_state.gd") var moving = null +var deleting: bool = false var floor_corner: StaticBody3D = null var height_corner: StaticBody3D = null -var height_edge: MeshInstance3D = null +var height_edge: StaticBody3D = null func _on_enter(): room.wall_corners.visible = true @@ -50,7 +51,7 @@ func _on_click_floor(event): room.room_ceiling.get_node("CollisionShape3D").disabled = false func _on_click_ceiling(event): - if floor_corner == null || height_corner == null: + if floor_corner == null || height_corner == null || event.target != room.room_ceiling: return var pos = event.ray.get_collision_point() @@ -66,7 +67,7 @@ func add_floor_corner(position: Vector3): height_edge.transform = corners_to_edge_transform(position, position + Vector3.UP * room.room_ceiling.global_position.y) floor_corner.get_node("Clickable").on_grab_down.connect(func(event): - if !is_active(): + if !is_active() || moving != null: return moving = event.target @@ -76,15 +77,14 @@ func add_floor_corner(position: Vector3): if moving == null: return + var moving_index = height_corner.get_index() var direction = -event.ray.global_transform.basis.z var new_position = room.room_floor.get_node("CollisionShape3D").shape.plane.intersects_ray(event.ray.global_position, direction) if new_position == null: - # mark for deletion return moving.position = new_position - var moving_index = height_corner.get_index() height_edge.transform = corners_to_edge_transform(new_position, new_position + Vector3.UP * room.room_ceiling.global_position.y) @@ -111,7 +111,7 @@ func add_height_corner(position: Vector3): height_corner.position.z = position.z height_corner.get_node("Clickable").on_grab_down.connect(func(event): - if !is_active(): + if !is_active() || moving != null: return moving = event.target @@ -144,13 +144,13 @@ func add_height_corner(position: Vector3): room.wall_corners.add_child(height_corner) -func add_corner(position: Vector3): +func add_corner(position: Vector3, index: int = -1): var corner = wall_corner_scene.instantiate() corner.position.x = position.x corner.position.z = position.z corner.get_node("Clickable").on_grab_down.connect(func(event): - if !is_active(): + if !is_active() || moving != null: return moving = event.target @@ -160,17 +160,33 @@ func add_corner(position: Vector3): if moving == null: return + var moving_index = moving.get_index() var direction = -event.ray.global_transform.basis.z var ceiling_plane = Plane(Vector3.DOWN, room.room_ceiling.global_position) var new_position = ceiling_plane.intersects_ray(event.ray.global_position, direction) if new_position == null: + deleting = true + + new_position = event.ray.global_position + direction + + room.get_corner(moving_index).global_position = new_position + + if room.wall_edges.get_child_count() == 0: + return + + var edge_transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index).transform = edge_transform + room.get_edge(moving_index - 1).transform = edge_transform + return + deleting = false + new_position.y = 0 moving.position = new_position - var moving_index = moving.get_index() + if room.wall_edges.get_child_count() == 0: return @@ -180,29 +196,43 @@ func add_corner(position: Vector3): ) corner.get_node("Clickable").on_grab_up.connect(func(_event): + if deleting: + var moving_index = moving.get_index() + room.remove_corner(moving_index) + moving = null + deleting = false ) room.wall_corners.add_child(corner) - + room.wall_corners.move_child(corner, index) var num_corners = room.wall_corners.get_child_count() var edge if num_corners > 1: - edge = add_edge(room.wall_corners.get_child(num_corners - 2).position, position) + edge = add_edge(position, room.get_corner(index + 1).position, index) - if num_corners > 2: + if num_corners > 2: if num_corners != room.wall_edges.get_child_count(): - add_edge(position, room.wall_corners.get_child(0).position) + add_edge(room.get_corner(-2).position, room.get_corner(-1).position, -2) else: - room.wall_edges.move_child(edge, num_corners - 2) - room.get_edge(-1).transform = corners_to_edge_transform(position, room.get_corner(0).position) + room.get_edge(index - 1).transform = corners_to_edge_transform(room.get_corner(index - 1).position, position) + -func add_edge(from_pos: Vector3, to_pos: Vector3): - var edge: MeshInstance3D = wall_edge_scene.instantiate() +func add_edge(from_pos: Vector3, to_pos: Vector3, index: int = -1): + var edge: StaticBody3D = wall_edge_scene.instantiate() edge.transform = corners_to_edge_transform(from_pos, to_pos) + + edge.get_node("Clickable").on_press_down.connect(func(event): + var point = event.ray.get_collision_point() + point.y = 0 + add_corner(point, edge.get_index() + 1) + ) + + room.wall_edges.add_child(edge) + room.wall_edges.move_child(edge, index) return edge func corners_to_edge_transform(from_pos: Vector3, to_pos: Vector3) -> Transform3D: diff --git a/content/system/house/room/wall_corner.tscn b/content/system/house/room/wall_corner.tscn index c12b7ed..f713d4c 100644 --- a/content/system/house/room/wall_corner.tscn +++ b/content/system/house/room/wall_corner.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://content/functions/clickable.gd" id="1_e5awq"] [sub_resource type="SphereShape3D" id="SphereShape3D_86rci"] -radius = 0.05 +radius = 0.1 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_i1w3w"] transparency = 1 diff --git a/content/system/house/room/wall_edge.tscn b/content/system/house/room/wall_edge.tscn index 21f2718..311a46c 100644 --- a/content/system/house/room/wall_edge.tscn +++ b/content/system/house/room/wall_edge.tscn @@ -1,11 +1,24 @@ -[gd_scene load_steps=3 format=3 uid="uid://dlj5chj7ndgua"] +[gd_scene load_steps=5 format=3 uid="uid://dlj5chj7ndgua"] -[ext_resource type="Material" uid="uid://j12e5wwthtaa" path="res://content/ui/menu/room/edge.tres" id="1_b21dw"] +[ext_resource type="Material" uid="uid://j12e5wwthtaa" path="res://content/system/house/room/edge.tres" id="1_hs3tw"] +[ext_resource type="Script" path="res://content/functions/clickable.gd" id="2_cfvx2"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_a2dct"] -material = ExtResource("1_b21dw") +material = ExtResource("1_hs3tw") radius = 0.01 height = 1.0 -[node name="MeshInstance3D" type="MeshInstance3D"] +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_6m53l"] +radius = 0.04 +height = 1.0 + +[node name="StaticBody3D" type="StaticBody3D"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] mesh = SubResource("CapsuleMesh_a2dct") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("CapsuleShape3D_6m53l") + +[node name="Clickable" type="Node" parent="."] +script = ExtResource("2_cfvx2") diff --git a/content/system/house/room/walls.tres b/content/system/house/room/walls.tres index c9a6a4d..b0ebc48 100644 --- a/content/system/house/room/walls.tres +++ b/content/system/house/room/walls.tres @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:935bcbcfaa2d5dca17ce3efea167357dca8b5ac05f49d5b322add9a84607b4f0 -size 158 +oid sha256:fe7c098cfc9adadb447df0230eba8a81f1825dd3c0cf4e654ebf98ca2314c8cc +size 151 diff --git a/content/system/house/room/walls_selected.tres b/content/system/house/room/walls_selected.tres deleted file mode 100644 index 5ff9fcc..0000000 --- a/content/system/house/room/walls_selected.tres +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d7af833108b37da9ba445d2da6dbac058b5894f550177bf917fb9ab9fb6ecd1c -size 172 diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 6aad742..7ff2561 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -3,8 +3,8 @@ extends Node3D const Room = preload("res://content/system/house/room/room.tscn") const RoomType = preload("res://content/system/house/room/room.gd") -const material_selected = preload("res://content/system/house/room/walls_selected.tres") -const material_unselected = preload("res://content/system/house/room/walls.tres") +const material_selected = preload("./room_selected.tres") +const material_unselected = preload("./room_unselected.tres") const window_scene = preload("./window.tscn") @@ -66,7 +66,12 @@ func _ready(): else: if edit_room: edit_room = false - House.body.edit_room(null) + + if !House.body.is_valid_room(selected_room): + House.body.delete_room(selected_room) + selected_room = null + else: + House.body.edit_room(null) _generate_room_map() else: edit_room = true @@ -141,13 +146,11 @@ func _generate_room_map(): if aabb_end.z > current_max.y: current_max.y = aabb_end.z - print(current_min, " ", current_max) + if current_min == null: + return var current_size = current_max - current_min - var target_scale = target_size / current_size - - print(target_scale) var scale_value = min(target_scale.x, target_scale.y) rooms_map.position.x = -current_min.x * scale_value diff --git a/content/ui/menu/room/room_selected.tres b/content/ui/menu/room/room_selected.tres new file mode 100644 index 0000000..8b71a8e --- /dev/null +++ b/content/ui/menu/room/room_selected.tres @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:317bb38a3e58a63bfefaa8c202116a2f9938c5f226eb7404752ceb1e32bdd1ef +size 134 diff --git a/content/ui/menu/room/room_unselected.tres b/content/ui/menu/room/room_unselected.tres new file mode 100644 index 0000000..8271fca --- /dev/null +++ b/content/ui/menu/room/room_unselected.tres @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c68faf32c34f6ca3e0ed9ef4ab76f7aafc34d5745163d932d0dbfbddd12ec0b6 +size 101 From f86aa5f86f277a3281f8133117007d671df32975 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Mon, 15 Jan 2024 17:02:44 +0100 Subject: [PATCH 07/17] small fixes --- content/main.tscn | 5 ----- content/ui/menu/room/room_menu.gd | 4 ++-- content/ui/menu/room/room_selected.tres | 2 +- content/ui/menu/room/room_unselected.tres | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/content/main.tscn b/content/main.tscn index ee60a77..302c622 100644 --- a/content/main.tscn +++ b/content/main.tscn @@ -8,7 +8,6 @@ [ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="5_3qc8g"] [ext_resource type="Material" uid="uid://bf5ina366dwm6" path="res://assets/materials/sky.material" id="5_wgwf8"] [ext_resource type="PackedScene" uid="uid://c3kdssrmv84kv" path="res://content/ui/menu/menu.tscn" id="8_du83w"] -[ext_resource type="PackedScene" uid="uid://83lb5p4e0qk0" path="res://content/scenes/house.tscn" id="8_qkrg7"] [ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"] [ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"] @@ -79,10 +78,6 @@ transform = Transform3D(0.999998, -0.000514899, -6.55874e-05, 1.96975e-05, 0.163 [node name="Keyboard" parent="." instance=ExtResource("9_e5n3p")] transform = Transform3D(0.499999, -0.000139169, -6.50204e-05, 5.24307e-05, 0.353553, -0.353553, 0.000144383, 0.353553, 0.353553, -0.0199266, 0.550784, -0.47368) -[node name="House" parent="." instance=ExtResource("8_qkrg7")] -transform = Transform3D(0.404247, 0.000180645, 0.914648, 0.00017221, 0.999999, -0.000273614, -0.914648, 0.00026812, 0.404247, -0.343479, 0.000110551, 1.91547) -visible = false - [node name="Rooms" type="Node3D" parent="."] [node name="House" parent="." instance=ExtResource("9_np6mw")] diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 7ff2561..cd7c76d 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -46,11 +46,11 @@ func _ready(): background.visible = false HomeApi.on_connect.connect(func(): - var rooms = House.body.get_rooms(0) + # var rooms = House.body.get_rooms(0) # for room in rooms: # var mesh = room.wall_mesh - + pass ) room_button.on_button_down.connect(func(): diff --git a/content/ui/menu/room/room_selected.tres b/content/ui/menu/room/room_selected.tres index 8b71a8e..a0ad81c 100644 --- a/content/ui/menu/room/room_selected.tres +++ b/content/ui/menu/room/room_selected.tres @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:317bb38a3e58a63bfefaa8c202116a2f9938c5f226eb7404752ceb1e32bdd1ef +oid sha256:5245272378c86fb17cf012dee95460df366d7781d3119604e447ae2330de7199 size 134 diff --git a/content/ui/menu/room/room_unselected.tres b/content/ui/menu/room/room_unselected.tres index 8271fca..6f9b538 100644 --- a/content/ui/menu/room/room_unselected.tres +++ b/content/ui/menu/room/room_unselected.tres @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c68faf32c34f6ca3e0ed9ef4ab76f7aafc34d5745163d932d0dbfbddd12ec0b6 +oid sha256:b77e182a6941bd1837cdbae2586f5a7561e033fc26a1a2c50c0eb1a600d40322 size 101 From 721c0de4ba1a15c6d516603eaa657d53f6cad162 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 16 Jan 2024 15:00:30 +0100 Subject: [PATCH 08/17] add basics for mini room view --- content/functions/movable.gd | 10 ++++- content/main.gd | 8 ++-- content/system/armband/armband.gd | 15 +++++++ content/system/armband/armband.tscn | 23 +++++++++++ content/system/hands/hands.tscn | 12 ++++-- content/system/house/house.gd | 48 ++++++++++++++++++++++- content/system/house/house.tscn | 16 +++++++- content/system/house/room/room.gd | 22 ++++++++++- content/system/house/room/room.tscn | 6 ++- content/system/house/room/states/mini.gd | 41 +++++++++++++++++++ content/system/house/room/states/view.gd | 6 ++- content/system/house/room/walls_mini.tres | 3 ++ content/ui/menu/room/room_menu.gd | 30 +++----------- lib/globals/save_system.gd | 3 ++ lib/utils/state_machine/state_machine.gd | 2 +- 15 files changed, 205 insertions(+), 40 deletions(-) create mode 100644 content/system/armband/armband.gd create mode 100644 content/system/armband/armband.tscn create mode 100644 content/system/house/room/states/mini.gd create mode 100644 content/system/house/room/walls_mini.tres diff --git a/content/functions/movable.gd b/content/functions/movable.gd index 8bcf12f..9e9b99f 100644 --- a/content/functions/movable.gd +++ b/content/functions/movable.gd @@ -2,14 +2,22 @@ extends Function class_name Movable +@export var restricted: bool = false +@export var lock_rotation: bool = false var hit_node := Node3D.new() func _on_grab_down(event: EventPointer): + if restricted && event.target != get_parent(): + return + event.initiator.node.add_child(hit_node) hit_node.global_transform = get_parent().global_transform func _on_grab_move(_event: EventPointer): - get_parent().global_transform = hit_node.global_transform + get_parent().global_position = hit_node.global_position + + if !lock_rotation: + get_parent().global_rotation = hit_node.global_rotation func _on_grab_up(event: EventPointer): event.initiator.node.remove_child(hit_node) diff --git a/content/main.gd b/content/main.gd index e6389ba..e553ded 100644 --- a/content/main.gd +++ b/content/main.gd @@ -40,7 +40,9 @@ func _ready(): EventSystem.on_action_down.connect(func(action): if action.name == "menu_button": - _toggle_menu() + toggle_menu() + elif action.name == "by_button": + House.body.mini_view = !House.body.mini_view ) EventSystem.on_focus_in.connect(func(event): @@ -59,7 +61,7 @@ func _ready(): remove_child(keyboard) ) -func _toggle_menu(): +func toggle_menu(): if menu.show_menu == false: add_child(menu) menu.global_transform = _get_menu_transform() @@ -103,7 +105,7 @@ func _input(event): vp.debug_draw = (vp.debug_draw + 1) % 5 if event is InputEventKey and Input.is_key_pressed(KEY_M): - _toggle_menu() + toggle_menu() func _get_menu_transform(): var transform = camera.get_global_transform() diff --git a/content/system/armband/armband.gd b/content/system/armband/armband.gd new file mode 100644 index 0000000..c9db1a0 --- /dev/null +++ b/content/system/armband/armband.gd @@ -0,0 +1,15 @@ +extends Node3D + +@onready var menu_button = $Menu +@onready var mini_button = $Mini +@onready var clock = $Clock +@onready var main = $"/root/Main" + +func _ready(): + menu_button.on_button_down.connect(func(): + main.toggle_menu() + ) + + mini_button.on_button_down.connect(func(): + House.body.mini_view = !House.body.mini_view + ) diff --git a/content/system/armband/armband.tscn b/content/system/armband/armband.tscn new file mode 100644 index 0000000..fa24fd9 --- /dev/null +++ b/content/system/armband/armband.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=3 uid="uid://bexxngoxcegul"] + +[ext_resource type="Script" path="res://content/system/armband/armband.gd" id="1_4tskg"] +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_egcvm"] + +[node name="Armband" type="Node3D"] +transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0) +script = ExtResource("1_4tskg") + +[node name="Menu" parent="." instance=ExtResource("1_egcvm")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.04, 0, 0.04) +label = "menu" +icon = true + +[node name="Mini" parent="." instance=ExtResource("1_egcvm")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.02, 0, 0.04) +label = "view_comfy" +icon = true + +[node name="Clock" type="Label3D" parent="."] +transform = Transform3D(1, 4.37114e-08, 4.37114e-08, -4.37114e-08, -4.37114e-08, 1, 4.37114e-08, -1, -4.37114e-08, 0, 0.02, -0.02) +pixel_size = 0.001 +text = "10:00" diff --git a/content/system/hands/hands.tscn b/content/system/hands/hands.tscn index a0efb03..2a69cfa 100644 --- a/content/system/hands/hands.tscn +++ b/content/system/hands/hands.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=6 format=3 uid="uid://bsx12q23v8apy"] +[gd_scene load_steps=7 format=3 uid="uid://bsx12q23v8apy"] [ext_resource type="Script" path="res://content/system/hands/hands.gd" id="1_c4f76"] [ext_resource type="PackedScene" uid="uid://c0kow4g10wolq" path="res://assets/models/hands_steam/right_hand.glb" id="1_uekbj"] [ext_resource type="PackedScene" uid="uid://dt4ksvogfctkr" path="res://assets/models/hands_steam/left_hand.glb" id="2_n73lt"] +[ext_resource type="PackedScene" uid="uid://bexxngoxcegul" path="res://content/system/armband/armband.tscn" id="3_ck75s"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dopke"] radius = 0.001 @@ -42,7 +43,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, shape = SubResource("CapsuleShape3D_dopke") [node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777) +transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777) bone_name = "Thumb_Tip_L" bone_idx = 4 use_external_skeleton = true @@ -52,7 +53,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") gizmo_extents = 0.02 [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612) +transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612) bone_name = "Middle_Tip_L" bone_idx = 14 use_external_skeleton = true @@ -80,6 +81,9 @@ collision_mask = 8 transform = Transform3D(1, 1.05818e-16, 4.75779e-13, -2.32831e-10, 1, -1.77636e-14, -4.97946e-12, 1.77636e-15, 1, -7.7486e-07, 1.33878e-09, -0.030436) shape = SubResource("BoxShape3D_1pxrt") +[node name="Armband" parent="XRHandLeft/AnimatableBody3D" instance=ExtResource("3_ck75s")] +transform = Transform3D(0.5, -8.74228e-08, 0, 8.74228e-08, 0.5, 0, 0, 0, 0.5, 0, 5.00223e-14, 0.11) + [node name="RemoteTransform3D" type="RemoteTransform3D" parent="XRHandLeft"] remote_path = NodePath("../AnimatableBody3D") @@ -94,7 +98,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D") transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0) [node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"] -transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401) +transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401) bone_name = "Index_Tip_R" bone_idx = 9 use_external_skeleton = true diff --git a/content/system/house/house.gd b/content/system/house/house.gd index dd154a5..5638b90 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -4,8 +4,13 @@ const Room = preload("./room/room.tscn") const RoomType = preload("./room/room.gd") @onready var levels = $Levels +@onready var collision_shape = $Levels/CollisionShape3D var editing_room: RoomType = null +var mini_view: bool = false: + set(value): + mini_view = value + update_mini_view() func create_room(room_name: String, level: int) -> RoomType: if editing_room != null: @@ -76,6 +81,28 @@ func find_room_at(entity_position: Vector3): func get_level(level: int): return levels.get_child(level) +func get_level_aabb(level: int): + var rooms = get_level(level).get_children() + if rooms.size() == 0: + return AABB() + + var min_pos = rooms[0].get_aabb().position + var max_pos = min_pos + rooms[0].get_aabb().size + + for room in rooms: + var room_min = room.get_aabb().position + var room_max = room_min + room.get_aabb().size + + min_pos.x = min(min_pos.x, room_min.x) + min_pos.y = min(min_pos.y, room_min.y) + min_pos.z = min(min_pos.z, room_min.z) + + max_pos.x = max(max_pos.x, room_max.x) + max_pos.y = max(max_pos.y, room_max.y) + max_pos.z = max(max_pos.z, room_max.z) + + return AABB(min_pos, max_pos - min_pos) + func get_rooms(level: int): return get_level(level).get_children() @@ -93,4 +120,23 @@ func create_entity(entity_id: String, entity_position: Vector3): room.add_child(entity) entity.global_position = entity_position - +func update_mini_view(): + collision_shape.disabled = !mini_view + + if mini_view: + var aabb = get_level_aabb(0) + aabb.position.y = -0.03 + aabb.size.y = 0.06 + var center = aabb.position + aabb.size / 2.0 + + collision_shape.global_position = center + collision_shape.shape.size = aabb.size + else: + levels.position = Vector3(0, 0, 0) + + levels.scale.x = 0.2 if mini_view else 1.0 + levels.scale.y = 0.2 if mini_view else 1.0 + levels.scale.z = 0.2 if mini_view else 1.0 + + for room in get_rooms(0): + room.state_machine.change_to("Mini" if mini_view else "View") \ No newline at end of file diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn index d2de65c..21124de 100644 --- a/content/system/house/house.tscn +++ b/content/system/house/house.tscn @@ -1,10 +1,22 @@ -[gd_scene load_steps=2 format=3 uid="uid://cbemihbxkd4ll"] +[gd_scene load_steps=4 format=3 uid="uid://cbemihbxkd4ll"] [ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"] +[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_w1auk"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_x81up"] [node name="House" type="Node3D"] script = ExtResource("1_p8amj") -[node name="Levels" type="Node3D" parent="."] +[node name="Levels" type="StaticBody3D" parent="."] [node name="Level0" type="Node3D" parent="Levels"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Levels"] +shape = SubResource("BoxShape3D_x81up") +disabled = true + +[node name="Movable" type="Node" parent="Levels"] +script = ExtResource("2_w1auk") +restricted = true +lock_rotation = true diff --git a/content/system/house/room/room.gd b/content/system/house/room/room.gd index c0dbc7c..722b32f 100644 --- a/content/system/house/room/room.gd +++ b/content/system/house/room/room.gd @@ -27,7 +27,7 @@ func get_edge(index: int) -> MeshInstance3D: return wall_edges.get_child(index % wall_edges.get_child_count()) func has_point(point: Vector3) -> bool: - return wall_mesh.get_aabb().has_point(point) + return get_aabb().has_point(point) func remove_corner(index: int): get_corner(index).queue_free() @@ -39,6 +39,26 @@ func _save(): "name": name } +func get_aabb(): + if wall_corners.get_child_count() == 0: + return AABB() + + var min_pos = wall_corners.get_child(0).position + var max_pos = wall_corners.get_child(0).position + + for corner in wall_corners.get_children(): + min_pos.x = min(min_pos.x, corner.position.x) + min_pos.z = min(min_pos.z, corner.position.z) + + max_pos.x = max(max_pos.x, corner.position.x) + max_pos.z = max(max_pos.z, corner.position.z) + + min_pos.y = room_floor.position.y + max_pos.y = room_ceiling.position.y + + return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) + + func _load(data): await ready return diff --git a/content/system/house/room/room.tscn b/content/system/house/room/room.tscn index 688e140..bd0cedd 100644 --- a/content/system/house/room/room.tscn +++ b/content/system/house/room/room.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=10 format=3 uid="uid://bswgmclohuqui"] +[gd_scene load_steps=11 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/functions/clickable.gd" id="1_ugebq"] [ext_resource type="Material" uid="uid://bbx6fv7jq50tr" path="res://content/system/house/room/walls.tres" id="3_al1ev"] [ext_resource type="Script" path="res://lib/utils/state_machine/state_machine.gd" id="4_nbbo6"] +[ext_resource type="Script" path="res://content/system/house/room/states/mini.gd" id="6_g4qca"] [ext_resource type="Script" path="res://content/system/house/room/states/view.gd" id="6_g066t"] [ext_resource type="Script" path="res://content/system/house/room/states/edit.gd" id="7_ap14h"] @@ -61,3 +62,6 @@ script = ExtResource("6_g066t") [node name="Edit" type="Node" parent="StateMachine"] script = ExtResource("7_ap14h") + +[node name="Mini" type="Node" parent="StateMachine"] +script = ExtResource("6_g4qca") diff --git a/content/system/house/room/states/mini.gd b/content/system/house/room/states/mini.gd new file mode 100644 index 0000000..99f17d6 --- /dev/null +++ b/content/system/house/room/states/mini.gd @@ -0,0 +1,41 @@ +extends RoomState + +const RoomState = preload("./room_state.gd") +const walls_mini_material = preload("../walls_mini.tres") +const walls_material = preload("../walls.tres") + +func _on_enter(): + room.wall_mesh.visible = true + room.ceiling_mesh.visible = true + room.wall_mesh.material_override = walls_mini_material + room.room_ceiling.get_node("CollisionShape3D").disabled = true + room.room_floor.get_node("CollisionShape3D").disabled = true + + for collision in room.wall_collisions.get_children(): + collision.get_child(0).disabled = true + + for corner in room.wall_corners.get_children(): + corner.get_node("CollisionShape3D").disabled = true + + for edge in room.wall_edges.get_children(): + edge.get_node("CollisionShape3D").disabled = true + + + +func _on_leave(): + room.wall_mesh.visible = false + room.ceiling_mesh.visible = false + room.wall_mesh.material_override = walls_material + room.room_ceiling.get_node("CollisionShape3D").disabled = false + room.room_floor.get_node("CollisionShape3D").disabled = false + + for collision in room.wall_collisions.get_children(): + collision.get_child(0).disabled = false + + for corner in room.wall_corners.get_children(): + corner.get_node("CollisionShape3D").disabled = false + + for edge in room.wall_edges.get_children(): + edge.get_node("CollisionShape3D").disabled = false + + diff --git a/content/system/house/room/states/view.gd b/content/system/house/room/states/view.gd index b20b181..d8dd590 100644 --- a/content/system/house/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -13,6 +13,8 @@ func _on_enter(): room_height = room.get_corner(0).global_position.y + room.wall_mesh.visible = true + room.ceiling_mesh.visible = true room.wall_mesh.mesh = generate_mesh() if room.wall_mesh.mesh == null: @@ -36,8 +38,8 @@ func _on_enter(): room.wall_mesh.visible = true func _on_leave(): - room.wall_mesh.mesh = null - room.ceiling_mesh.mesh = null + room.wall_mesh.visible = false + room.ceiling_mesh.visible = false for collision in room.wall_collisions.get_children(): collision.queue_free() diff --git a/content/system/house/room/walls_mini.tres b/content/system/house/room/walls_mini.tres new file mode 100644 index 0000000..1432646 --- /dev/null +++ b/content/system/house/room/walls_mini.tres @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6b87dd767a03b39f93f17a71b75b3a6ce82623a7703c24722dd112e31718376 +size 157 diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index cd7c76d..f0aecc5 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -97,14 +97,15 @@ func _on_click(event: EventPointer): func _generate_room_map(): var rooms = House.body.get_rooms(0) - var target_size = Vector2(0.3, 0.24) + var target_size = Vector3(0.3, 1, 0.24) for old_room in rooms_map.get_children(): old_room.queue_free() await old_room.tree_exited - var current_min = null - var current_max = null + var aabb = House.body.get_level_aabb(0) + var current_min = aabb.position + var current_max = aabb.position + aabb.size for room in rooms: var mesh = room.ceiling_mesh.mesh @@ -127,33 +128,14 @@ func _generate_room_map(): rooms_map.add_child(body) - var aabb_position = room.ceiling_mesh.to_global(mesh.get_aabb().position) - var aabb_end = room.ceiling_mesh.to_global(mesh.get_aabb().end) - - if current_min == null: - current_min = Vector2(aabb_position.x, aabb_position.z) - current_max = Vector2(aabb_end.x, aabb_end.z) - else: - if aabb_position.x < current_min.x: - current_min.x = aabb_position.x - - if aabb_position.z < current_min.y: - current_min.y = aabb_position.z - - if aabb_end.x > current_max.x: - current_max.x = aabb_end.x - - if aabb_end.z > current_max.y: - current_max.y = aabb_end.z - if current_min == null: return var current_size = current_max - current_min var target_scale = target_size / current_size - var scale_value = min(target_scale.x, target_scale.y) + var scale_value = min(target_scale.x, target_scale.z) rooms_map.position.x = -current_min.x * scale_value - rooms_map.position.z = -current_min.y * scale_value + rooms_map.position.z = -current_min.z * scale_value rooms_map.scale = Vector3(scale_value, scale_value, scale_value) diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index a45321f..22510e7 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -44,6 +44,9 @@ func load(): var json_text = save_file.get_line() var save_tree = JSON.parse_string(json_text) + if save_tree == null: + return + if save_tree is Array: for tree in save_tree: _build_save_tree(tree) diff --git a/lib/utils/state_machine/state_machine.gd b/lib/utils/state_machine/state_machine.gd index 6fb7f7a..a5dbc81 100644 --- a/lib/utils/state_machine/state_machine.gd +++ b/lib/utils/state_machine/state_machine.gd @@ -29,4 +29,4 @@ func change_to(new_state: String) -> void: current_state = states[new_state] add_child(current_state) current_state._on_enter() - changed.emit(new_state, old_state) \ No newline at end of file + changed.emit(new_state, old_state) From 7c5f5494624dce46b41ed170b65ad6812beb9a58 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Mon, 22 Jan 2024 16:54:15 +0100 Subject: [PATCH 09/17] update mini view, add migration system --- content/system/hands/hands.tscn | 12 ++-- content/system/house/house.gd | 12 +++- content/system/house/room/room.gd | 11 ++- content/system/house/room/states/view.gd | 2 +- content/ui/menu/menu.gd | 7 +- content/ui/menu/menu.tscn | 6 +- content/ui/menu/view/view_menu.gd | 12 ++++ content/ui/menu/view/view_menu.tscn | 21 ++++++ lib/globals/save_system.gd | 85 +++++++++++++++++++++++- lib/migrations/2024-01-22.gd | 4 ++ 10 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 content/ui/menu/view/view_menu.gd create mode 100644 content/ui/menu/view/view_menu.tscn create mode 100644 lib/migrations/2024-01-22.gd diff --git a/content/system/hands/hands.tscn b/content/system/hands/hands.tscn index 2a69cfa..a0efb03 100644 --- a/content/system/hands/hands.tscn +++ b/content/system/hands/hands.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://bsx12q23v8apy"] +[gd_scene load_steps=6 format=3 uid="uid://bsx12q23v8apy"] [ext_resource type="Script" path="res://content/system/hands/hands.gd" id="1_c4f76"] [ext_resource type="PackedScene" uid="uid://c0kow4g10wolq" path="res://assets/models/hands_steam/right_hand.glb" id="1_uekbj"] [ext_resource type="PackedScene" uid="uid://dt4ksvogfctkr" path="res://assets/models/hands_steam/left_hand.glb" id="2_n73lt"] -[ext_resource type="PackedScene" uid="uid://bexxngoxcegul" path="res://content/system/armband/armband.tscn" id="3_ck75s"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dopke"] radius = 0.001 @@ -43,7 +42,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, shape = SubResource("CapsuleShape3D_dopke") [node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777) +transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777) bone_name = "Thumb_Tip_L" bone_idx = 4 use_external_skeleton = true @@ -53,7 +52,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") gizmo_extents = 0.02 [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612) +transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612) bone_name = "Middle_Tip_L" bone_idx = 14 use_external_skeleton = true @@ -81,9 +80,6 @@ collision_mask = 8 transform = Transform3D(1, 1.05818e-16, 4.75779e-13, -2.32831e-10, 1, -1.77636e-14, -4.97946e-12, 1.77636e-15, 1, -7.7486e-07, 1.33878e-09, -0.030436) shape = SubResource("BoxShape3D_1pxrt") -[node name="Armband" parent="XRHandLeft/AnimatableBody3D" instance=ExtResource("3_ck75s")] -transform = Transform3D(0.5, -8.74228e-08, 0, 8.74228e-08, 0.5, 0, 0, 0, 0.5, 0, 5.00223e-14, 0.11) - [node name="RemoteTransform3D" type="RemoteTransform3D" parent="XRHandLeft"] remote_path = NodePath("../AnimatableBody3D") @@ -98,7 +94,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D") transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0) [node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"] -transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401) +transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401) bone_name = "Index_Tip_R" bone_idx = 9 use_external_skeleton = true diff --git a/content/system/house/house.gd b/content/system/house/house.gd index 5638b90..82bf1bc 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -12,6 +12,14 @@ var mini_view: bool = false: mini_view = value update_mini_view() +var target_size: float = 1.0 + +func _physics_process(delta): + levels.scale.x = lerp(levels.scale.x, target_size, 10.0 * delta) + levels.scale.y = lerp(levels.scale.y, target_size, 10.0 * delta) + levels.scale.z = lerp(levels.scale.z, target_size, 10.0 * delta) + + func create_room(room_name: String, level: int) -> RoomType: if editing_room != null: editing_room.editable = false @@ -134,9 +142,7 @@ func update_mini_view(): else: levels.position = Vector3(0, 0, 0) - levels.scale.x = 0.2 if mini_view else 1.0 - levels.scale.y = 0.2 if mini_view else 1.0 - levels.scale.z = 0.2 if mini_view else 1.0 + target_size = 0.1 if mini_view else 1.0 for room in get_rooms(0): room.state_machine.change_to("Mini" if mini_view else "View") \ No newline at end of file diff --git a/content/system/house/room/room.gd b/content/system/house/room/room.gd index 722b32f..6b654db 100644 --- a/content/system/house/room/room.gd +++ b/content/system/house/room/room.gd @@ -33,12 +33,6 @@ func remove_corner(index: int): get_corner(index).queue_free() get_edge(index).queue_free() -func _save(): - return { - "corners": wall_corners.get_children().map(func(corner): return corner.position), - "name": name - } - func get_aabb(): if wall_corners.get_child_count() == 0: return AABB() @@ -58,6 +52,11 @@ func get_aabb(): return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) +func _save(): + return { + "corners": wall_corners.get_children().map(func(corner): return corner.position), + "name": name + } func _load(data): await ready diff --git a/content/system/house/room/states/view.gd b/content/system/house/room/states/view.gd index d8dd590..fc2db20 100644 --- a/content/system/house/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -11,7 +11,7 @@ func _on_enter(): if corner_count < 3: return - room_height = room.get_corner(0).global_position.y + room_height = room.room_ceiling.position.y room.wall_mesh.visible = true room.ceiling_mesh.visible = true diff --git a/content/ui/menu/menu.gd b/content/ui/menu/menu.gd index 7186689..e9a5a38 100644 --- a/content/ui/menu/menu.gd +++ b/content/ui/menu/menu.gd @@ -5,11 +5,12 @@ const Notification = preload("res://content/ui/components/notification/notificat @onready var nav_view = $AnimationContainer/Navigation/View @onready var nav_edit: Button3D = $AnimationContainer/Navigation/Edit -@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu @onready var nav_room = $AnimationContainer/Navigation/Room -@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu @onready var nav_automate = $AnimationContainer/Navigation/Automate @onready var nav_settings = $AnimationContainer/Navigation/Settings +@onready var menu_view: Node3D = $AnimationContainer/Content/ViewMenu +@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu +@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu @onready var menu_settings: Node3D = $AnimationContainer/Content/SettingsMenu @onready var menu_root = $AnimationContainer @@ -89,7 +90,7 @@ func _is_valid_nav(nav): func _nav_to_menu(nav): match nav: nav_view: - return null + return menu_view nav_edit: return menu_edit nav_room: diff --git a/content/ui/menu/menu.tscn b/content/ui/menu/menu.tscn index 2b6de75..827c911 100644 --- a/content/ui/menu/menu.tscn +++ b/content/ui/menu/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://c3kdssrmv84kv"] +[gd_scene load_steps=17 format=3 uid="uid://c3kdssrmv84kv"] [ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"] [ext_resource type="Material" uid="uid://bnwimm214q67g" path="res://assets/materials/sec-500.material" id="2_0x5at"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_w4i01"] [ext_resource type="ArrayMesh" uid="uid://cbqhhnknyium2" path="res://assets/immersive_home_panels/immersive_home_panels.obj" id="7_f4u4o"] +[ext_resource type="PackedScene" uid="uid://ddpxthb414unp" path="res://content/ui/menu/view/view_menu.tscn" id="8_71pkg"] [ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"] [ext_resource type="PackedScene" uid="uid://c6r4higceibif" path="res://content/ui/menu/settings/settings_menu.tscn" id="11_7wm6b"] @@ -225,6 +226,9 @@ visible = false [node name="SettingsMenu" parent="AnimationContainer/Content" instance=ExtResource("11_7wm6b")] visible = false +[node name="ViewMenu" parent="AnimationContainer/Content" instance=ExtResource("8_71pkg")] +visible = false + [node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2, 0, -0.05) gizmo_extents = 0.02 diff --git a/content/ui/menu/view/view_menu.gd b/content/ui/menu/view/view_menu.gd new file mode 100644 index 0000000..11fa1b9 --- /dev/null +++ b/content/ui/menu/view/view_menu.gd @@ -0,0 +1,12 @@ +extends Node3D + +@onready var mini_view = $Content/MiniView +@onready var background = $Background + +func _ready(): + background.visible = false + + mini_view.on_button_down.connect(func(): + House.body.mini_view = !House.body.mini_view + ) + diff --git a/content/ui/menu/view/view_menu.tscn b/content/ui/menu/view/view_menu.tscn new file mode 100644 index 0000000..986c50b --- /dev/null +++ b/content/ui/menu/view/view_menu.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://ddpxthb414unp"] + +[ext_resource type="Script" path="res://content/ui/menu/view/view_menu.gd" id="1_hxajx"] +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="2_qan1b"] + +[sub_resource type="BoxMesh" id="BoxMesh_qr3bi"] +size = Vector3(0.3, 0.01, 0.3) + +[node name="ViewMenu" type="Node3D"] +script = ExtResource("1_hxajx") + +[node name="Background" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15) +mesh = SubResource("BoxMesh_qr3bi") + +[node name="Content" type="Node3D" parent="."] + +[node name="MiniView" parent="Content" instance=ExtResource("2_qan1b")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.03) +label = "view_comfy" +icon = true diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index 22510e7..4e49715 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -6,6 +6,8 @@ signal loaded() signal unloaded() var is_loaded := false +var export_config = ConfigFile.new() +var export_config_path = "res://export_presets.cfg" func clear(): await _clear_save_tree(get_tree().root.get_node("Main")) @@ -25,11 +27,14 @@ func save(): var save_tree = _generate_save_tree(get_tree().root.get_node("Main")) - var json_text = JSON.stringify(save_tree) + var json_text = JSON.stringify({ + "version": "1.0.0", + "tree": save_tree + }) save_file.store_line(json_text) func load(): - await clear() + await clear() if HomeApi.has_connected() == false: return @@ -42,7 +47,15 @@ func load(): return var json_text = save_file.get_line() - var save_tree = JSON.parse_string(json_text) + var save_data = JSON.parse_string(json_text) + + save_data = migrate(save_data) + + if save_data == null: + save() + return + + var save_tree = save_data["tree"] if save_tree == null: return @@ -56,6 +69,72 @@ func load(): loaded.emit() is_loaded = true +func migrate(data: Dictionary): + var migration_version = data["migration"] + var migrations = load_migrations() + + if migration_version == null || migrations == {}: + return null + + var migration_keys = migrations.keys().sort() + + for key in migration_keys: + if is_migration_newer(migration_version, key): + var migration = migrations[key] + + data = migration.migrate(data) + + data["migration"] = key + + return data + +func is_migration_newer(version, new_version): + var version_split = version.split(".") + var new_version_split = new_version.split(".") + + for i in range(0, 3): + if int(version_split[i]) > int(new_version_split[i]): + return false + elif int(version_split[i]) < int(new_version_split[i]): + return true + + return false + +func load_migrations(): + var migrations = {} + var migrations_dir := DirAccess.open("res://lib/migrations") + + if migrations == null: + return {} + + migrations_dir.list_dir_begin() + var file_name = migrations_dir.get_next() + + while file_name != "": + if file_name.ends_with(".gd"): + var version = file_name.substr(0, -3) + + migrations[version] = load("res://lib/migrations/%s" % file_name) + + file_name = migrations_dir.get_next() + + migrations_dir.list_dir_end() + + return migrations + +func get_version(): + var config_error = export_config.load(export_config_path) + + if config_error != OK: + return null + + var version = export_config.get_value("preset.1.options", "version/name") + + if version == null: + return null + + return version + func _clear_save_tree(node: Node): for child in node.get_children(): await _clear_save_tree(child) diff --git a/lib/migrations/2024-01-22.gd b/lib/migrations/2024-01-22.gd new file mode 100644 index 0000000..5a9d461 --- /dev/null +++ b/lib/migrations/2024-01-22.gd @@ -0,0 +1,4 @@ +extends Object + +static func migrate(data: Dictionary): + return data \ No newline at end of file From 83ee764b45bf45d1223e38d308ba1903a45be361 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 23 Jan 2024 11:25:54 +0100 Subject: [PATCH 10/17] remove migration system --- content/system/hands/hands.tscn | 6 +-- lib/globals/save_system.gd | 67 +++------------------------------ lib/migrations/2024-01-22.gd | 4 -- 3 files changed, 9 insertions(+), 68 deletions(-) delete mode 100644 lib/migrations/2024-01-22.gd diff --git a/content/system/hands/hands.tscn b/content/system/hands/hands.tscn index a0efb03..ab65844 100644 --- a/content/system/hands/hands.tscn +++ b/content/system/hands/hands.tscn @@ -42,7 +42,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, shape = SubResource("CapsuleShape3D_dopke") [node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777) +transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777) bone_name = "Thumb_Tip_L" bone_idx = 4 use_external_skeleton = true @@ -52,7 +52,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") gizmo_extents = 0.02 [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612) +transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612) bone_name = "Middle_Tip_L" bone_idx = 14 use_external_skeleton = true @@ -94,7 +94,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D") transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0) [node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"] -transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401) +transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401) bone_name = "Index_Tip_R" bone_idx = 9 use_external_skeleton = true diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index 4e49715..c7b03a5 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -28,13 +28,13 @@ func save(): var save_tree = _generate_save_tree(get_tree().root.get_node("Main")) var json_text = JSON.stringify({ - "version": "1.0.0", + "version": get_version(), "tree": save_tree }) save_file.store_line(json_text) func load(): - await clear() + await clear() if HomeApi.has_connected() == false: return @@ -49,17 +49,15 @@ func load(): var json_text = save_file.get_line() var save_data = JSON.parse_string(json_text) - save_data = migrate(save_data) - - if save_data == null: - save() - return - var save_tree = save_data["tree"] if save_tree == null: return + if save_tree.has("version") == false: + save() + return + if save_tree is Array: for tree in save_tree: _build_save_tree(tree) @@ -69,59 +67,6 @@ func load(): loaded.emit() is_loaded = true -func migrate(data: Dictionary): - var migration_version = data["migration"] - var migrations = load_migrations() - - if migration_version == null || migrations == {}: - return null - - var migration_keys = migrations.keys().sort() - - for key in migration_keys: - if is_migration_newer(migration_version, key): - var migration = migrations[key] - - data = migration.migrate(data) - - data["migration"] = key - - return data - -func is_migration_newer(version, new_version): - var version_split = version.split(".") - var new_version_split = new_version.split(".") - - for i in range(0, 3): - if int(version_split[i]) > int(new_version_split[i]): - return false - elif int(version_split[i]) < int(new_version_split[i]): - return true - - return false - -func load_migrations(): - var migrations = {} - var migrations_dir := DirAccess.open("res://lib/migrations") - - if migrations == null: - return {} - - migrations_dir.list_dir_begin() - var file_name = migrations_dir.get_next() - - while file_name != "": - if file_name.ends_with(".gd"): - var version = file_name.substr(0, -3) - - migrations[version] = load("res://lib/migrations/%s" % file_name) - - file_name = migrations_dir.get_next() - - migrations_dir.list_dir_end() - - return migrations - func get_version(): var config_error = export_config.load(export_config_path) diff --git a/lib/migrations/2024-01-22.gd b/lib/migrations/2024-01-22.gd deleted file mode 100644 index 5a9d461..0000000 --- a/lib/migrations/2024-01-22.gd +++ /dev/null @@ -1,4 +0,0 @@ -extends Object - -static func migrate(data: Dictionary): - return data \ No newline at end of file From ccb6478ae7d2044994d63960cb92cdfb62b25e20 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 23 Jan 2024 17:48:13 +0100 Subject: [PATCH 11/17] make tabs modular --- content/ui/components/button/button.gd | 11 +++- content/ui/components/tabs/tabs.gd | 27 ++++++++ content/ui/components/tabs/tabs.tscn | 6 ++ content/ui/components/tabs/tabs_content.gd | 20 ++++++ content/ui/components/tabs/tabs_content.tscn | 6 ++ content/ui/menu/menu.gd | 68 -------------------- content/ui/menu/menu.tscn | 35 ++++++---- content/ui/menu/room/room_menu.tscn | 8 +++ content/ui/menu/settings/settings_menu.tscn | 8 +-- lib/globals/save_system.gd | 8 +-- lib/utils/proxy.gd | 9 ++- lib/utils/proxy_group.gd | 19 ++++++ 12 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 content/ui/components/tabs/tabs.gd create mode 100644 content/ui/components/tabs/tabs.tscn create mode 100644 content/ui/components/tabs/tabs_content.gd create mode 100644 content/ui/components/tabs/tabs_content.tscn create mode 100644 lib/utils/proxy_group.gd diff --git a/content/ui/components/button/button.gd b/content/ui/components/button/button.gd index 5dbfad1..54efe1d 100644 --- a/content/ui/components/button/button.gd +++ b/content/ui/components/button/button.gd @@ -50,7 +50,16 @@ const IconFont = preload("res://assets/icons/icons.tres") @export var toggleable: bool = false @export var disabled: bool = false @export var initial_active: bool = false -var external_value: Proxy = null +var external_value: Proxy = null: + set(value): + print("set external value", value) + external_value = value + if value != null: + value.on_set.connect(func(_value): + print("external value changed", _value) + update_animation() + ) + var active: bool = false: get: if external_value != null: diff --git a/content/ui/components/tabs/tabs.gd b/content/ui/components/tabs/tabs.gd new file mode 100644 index 0000000..f5172ce --- /dev/null +++ b/content/ui/components/tabs/tabs.gd @@ -0,0 +1,27 @@ +extends Node3D +class_name Tabs3D + +signal on_select(selected: int) + +var selected: Node3D +@export var initial_selected: Node3D +var proxy_group = ProxyGroup.new() + +func _ready(): + if initial_selected != null: + selected = initial_selected + on_select.emit(selected.get_index()) + + for option in get_children(): + if option is Button3D == false: + continue + + var proxy = proxy_group.proxy(func(): + return selected == option + , func(value: bool): + if value == true: + selected = option + on_select.emit(selected.get_index()) + ) + + option.external_value = proxy diff --git a/content/ui/components/tabs/tabs.tscn b/content/ui/components/tabs/tabs.tscn new file mode 100644 index 0000000..7adbee7 --- /dev/null +++ b/content/ui/components/tabs/tabs.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://doavdm6fskmrt"] + +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="1_xt6wm"] + +[node name="Tabs" type="Node3D"] +script = ExtResource("1_xt6wm") diff --git a/content/ui/components/tabs/tabs_content.gd b/content/ui/components/tabs/tabs_content.gd new file mode 100644 index 0000000..734ff29 --- /dev/null +++ b/content/ui/components/tabs/tabs_content.gd @@ -0,0 +1,20 @@ +extends Node3D +class_name TabsContent3D + +@export var tabs: Tabs3D + +var children: Array = [] + +func _ready(): + children = get_children() + + for child in children: + child.visible = true + remove_child(child) + + tabs.on_select.connect(func(index): + for child in get_children(): + remove_child(child) + + add_child(children[index]) + ) diff --git a/content/ui/components/tabs/tabs_content.tscn b/content/ui/components/tabs/tabs_content.tscn new file mode 100644 index 0000000..48c8307 --- /dev/null +++ b/content/ui/components/tabs/tabs_content.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://wewhef3qmulp"] + +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="1_ljgkj"] + +[node name="TabsContent" type="Node3D"] +script = ExtResource("1_ljgkj") diff --git a/content/ui/menu/menu.gd b/content/ui/menu/menu.gd index e9a5a38..6af6f86 100644 --- a/content/ui/menu/menu.gd +++ b/content/ui/menu/menu.gd @@ -3,16 +3,6 @@ extends Node3D const Proxy = preload("res://lib/utils/proxy.gd") const Notification = preload("res://content/ui/components/notification/notification.tscn") -@onready var nav_view = $AnimationContainer/Navigation/View -@onready var nav_edit: Button3D = $AnimationContainer/Navigation/Edit -@onready var nav_room = $AnimationContainer/Navigation/Room -@onready var nav_automate = $AnimationContainer/Navigation/Automate -@onready var nav_settings = $AnimationContainer/Navigation/Settings -@onready var menu_view: Node3D = $AnimationContainer/Content/ViewMenu -@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu -@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu -@onready var menu_settings: Node3D = $AnimationContainer/Content/SettingsMenu - @onready var menu_root = $AnimationContainer @onready var content = $AnimationContainer/Content @onready var nav = $AnimationContainer/Navigation @@ -42,61 +32,3 @@ func _ready(): notify_place.add_child(notification_node) ) - - var nav_buttons = [ - nav_view, - nav_edit, - nav_room, - nav_automate, - nav_settings - ] - - for nav_button in nav_buttons: - var getter = func(): - return nav_button == selected_nav - - var setter = func(value): - if value: - select_menu(nav_button) - - nav_button.external_value = Proxy.new(getter, setter) - - select_menu(nav_edit) - -func select_menu(nav): - if _is_valid_nav(nav) == false || selected_nav == nav: - return - - for child in content.get_children(): - content.remove_child(child) - - var old_nav = selected_nav - - selected_nav = nav - - if old_nav != null: - old_nav.update_animation() - - if selected_nav != null: - selected_nav.update_animation() - var menu = _nav_to_menu(selected_nav) - if menu != null: - content.add_child(menu) - menu.visible = true - -func _is_valid_nav(nav): - return nav == nav_view || nav == nav_edit || nav == nav_room || nav == nav_automate || nav == nav_settings - -func _nav_to_menu(nav): - match nav: - nav_view: - return menu_view - nav_edit: - return menu_edit - nav_room: - return menu_room - nav_automate: - return null - nav_settings: - return menu_settings - return null diff --git a/content/ui/menu/menu.tscn b/content/ui/menu/menu.tscn index 827c911..a8acc5a 100644 --- a/content/ui/menu/menu.tscn +++ b/content/ui/menu/menu.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=17 format=3 uid="uid://c3kdssrmv84kv"] +[gd_scene load_steps=19 format=3 uid="uid://c3kdssrmv84kv"] [ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"] [ext_resource type="Material" uid="uid://bnwimm214q67g" path="res://assets/materials/sec-500.material" id="2_0x5at"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_8coxu"] +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="4_eavfx"] [ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_w4i01"] +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="6_7rntr"] [ext_resource type="ArrayMesh" uid="uid://cbqhhnknyium2" path="res://assets/immersive_home_panels/immersive_home_panels.obj" id="7_f4u4o"] [ext_resource type="PackedScene" uid="uid://ddpxthb414unp" path="res://content/ui/menu/view/view_menu.tscn" id="8_71pkg"] [ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"] @@ -182,51 +184,58 @@ skeleton = NodePath("../..") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.21, 0, 0.15) shape = SubResource("ConvexPolygonShape3D_mgnm0") -[node name="Navigation" type="Node3D" parent="AnimationContainer"] +[node name="Tabs" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("initial_selected")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0) +script = ExtResource("4_eavfx") +initial_selected = NodePath("View") -[node name="View" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] +[node name="View" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03) label = "visibility" icon = true toggleable = true -[node name="Edit" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] +[node name="Edit" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.09) label = "widgets" icon = true toggleable = true -[node name="Room" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] +[node name="Room" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.15) label = "view_in_ar" icon = true toggleable = true -[node name="Automate" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] +[node name="Automate" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.21) label = "schema" icon = true toggleable = true -[node name="Settings" parent="AnimationContainer/Navigation" instance=ExtResource("5_w4i01")] +[node name="Settings" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.27) label = "settings" icon = true toggleable = true -[node name="Content" type="Node3D" parent="AnimationContainer"] +[node name="TabsContent" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("tabs")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0) +script = ExtResource("6_7rntr") +tabs = NodePath("../Tabs") -[node name="EditMenu" parent="AnimationContainer/Content" instance=ExtResource("4_r2raj")] - -[node name="RoomMenu" parent="AnimationContainer/Content" instance=ExtResource("10_u4i1x")] +[node name="ViewMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("8_71pkg")] visible = false -[node name="SettingsMenu" parent="AnimationContainer/Content" instance=ExtResource("11_7wm6b")] +[node name="EditMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("4_r2raj")] + +[node name="RoomMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("10_u4i1x")] visible = false -[node name="ViewMenu" parent="AnimationContainer/Content" instance=ExtResource("8_71pkg")] +[node name="AutomateMenu" type="Node3D" parent="AnimationContainer/TabsContent"] +visible = false + +[node name="SettingsMenu" parent="AnimationContainer/TabsContent" instance=ExtResource("11_7wm6b")] visible = false [node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"] diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index 1fb43d7..72cad75 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -29,3 +29,11 @@ icon = true [node name="Input" parent="Interface" instance=ExtResource("4_pbj71")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27) text = "New Room 1" + +[node name="Button2" parent="." instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0) +label = "Overview" + +[node name="Button" parent="." instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, 0) +label = "Rooms" diff --git a/content/ui/menu/settings/settings_menu.tscn b/content/ui/menu/settings/settings_menu.tscn index 195e69c..dcfa1ee 100644 --- a/content/ui/menu/settings/settings_menu.tscn +++ b/content/ui/menu/settings/settings_menu.tscn @@ -23,14 +23,14 @@ mesh = SubResource("BoxMesh_e51x8") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.007, 0) [node name="Label3D" type="Label3D" parent="Content"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.134377, 0, 0.253575) +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.124377, 0, 0.263575) pixel_size = 0.001 text = "Spawn Ball" font_size = 18 outline_size = 0 [node name="Button" parent="Content" instance=ExtResource("1_faxng")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0458097, 0, 0.253575) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0358097, 0, 0.263575) label = "sports_basketball" icon = true @@ -109,11 +109,11 @@ outline_size = 0 script = ExtResource("3_qmg6q") [node name="Save" parent="Content" instance=ExtResource("1_faxng")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0, 0.17) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.12) label = "save" icon = true [node name="ClearSave" parent="Content" instance=ExtResource("1_faxng")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.17) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, 0.12) label = "close" icon = true diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index c7b03a5..46beaa4 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -49,15 +49,15 @@ func load(): var json_text = save_file.get_line() var save_data = JSON.parse_string(json_text) + if save_data.has("version") == false: + save() + return + var save_tree = save_data["tree"] if save_tree == null: return - if save_tree.has("version") == false: - save() - return - if save_tree is Array: for tree in save_tree: _build_save_tree(tree) diff --git a/lib/utils/proxy.gd b/lib/utils/proxy.gd index 376db93..e42aefe 100644 --- a/lib/utils/proxy.gd +++ b/lib/utils/proxy.gd @@ -1,4 +1,7 @@ extends RefCounted +class_name Proxy + +signal on_set(new_value: Variant) var gettable: Callable var settable: Callable @@ -7,8 +10,12 @@ func _init(gettable: Callable, settable: Callable): self.gettable = gettable self.settable = settable + + var value: Variant: get: return gettable.call() set(new_value): - settable.call(new_value) \ No newline at end of file + settable.call(new_value) + on_set.emit(new_value) + diff --git a/lib/utils/proxy_group.gd b/lib/utils/proxy_group.gd new file mode 100644 index 0000000..0cd956e --- /dev/null +++ b/lib/utils/proxy_group.gd @@ -0,0 +1,19 @@ +extends RefCounted +class_name ProxyGroup + +var proxies = [] + +func proxy(_get: Callable, _set: Callable): + var _proxy + _proxy = Proxy.new(_get, func(value): + _set.call(value) + + for p in proxies: + if p != _proxy: + p.on_set.emit(value) + ) + + proxies.append(_proxy) + + return _proxy + \ No newline at end of file From 0875d37ec2d009709040a35d66bcde8aad8eeacd Mon Sep 17 00:00:00 2001 From: Nitwel Date: Tue, 23 Jan 2024 18:02:41 +0100 Subject: [PATCH 12/17] add submenu to rooms menu --- content/system/hands/hands.tscn | 6 +- content/ui/components/button/button.gd | 10 +- content/ui/components/tabs/tabs.gd | 1 + content/ui/menu/menu.tscn | 2 +- content/ui/menu/room/room_menu.gd | 125 ---------------------- content/ui/menu/room/room_menu.tscn | 36 ++++--- content/ui/menu/room/views/overview.tscn | 22 ++++ content/ui/menu/room/views/rooms.gd | 130 +++++++++++++++++++++++ content/ui/menu/room/views/rooms.tscn | 20 ++++ 9 files changed, 201 insertions(+), 151 deletions(-) create mode 100644 content/ui/menu/room/views/overview.tscn create mode 100644 content/ui/menu/room/views/rooms.gd create mode 100644 content/ui/menu/room/views/rooms.tscn diff --git a/content/system/hands/hands.tscn b/content/system/hands/hands.tscn index ab65844..a0efb03 100644 --- a/content/system/hands/hands.tscn +++ b/content/system/hands/hands.tscn @@ -42,7 +42,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0, shape = SubResource("CapsuleShape3D_dopke") [node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777) +transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777) bone_name = "Thumb_Tip_L" bone_idx = 4 use_external_skeleton = true @@ -52,7 +52,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D") gizmo_extents = 0.02 [node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"] -transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612) +transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612) bone_name = "Middle_Tip_L" bone_idx = 14 use_external_skeleton = true @@ -94,7 +94,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D") transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0) [node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"] -transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401) +transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401) bone_name = "Index_Tip_R" bone_idx = 9 use_external_skeleton = true diff --git a/content/ui/components/button/button.gd b/content/ui/components/button/button.gd index 54efe1d..26ce74e 100644 --- a/content/ui/components/button/button.gd +++ b/content/ui/components/button/button.gd @@ -3,8 +3,6 @@ extends Node3D class_name Button3D -const Proxy = preload("res://lib/utils/proxy.gd") - signal on_button_down() signal on_button_up() @@ -38,7 +36,7 @@ const IconFont = preload("res://assets/icons/icons.tres") if value: label_node.font = IconFont - label_node.font_size = 48 + label_node.font_size = 36 label_node.width = 1000 label_node.autowrap_mode = TextServer.AUTOWRAP_OFF else: @@ -52,11 +50,11 @@ const IconFont = preload("res://assets/icons/icons.tres") @export var initial_active: bool = false var external_value: Proxy = null: set(value): - print("set external value", value) + if !is_node_ready(): await ready + external_value = value if value != null: value.on_set.connect(func(_value): - print("external value changed", _value) update_animation() ) @@ -66,6 +64,8 @@ var active: bool = false: return external_value.value return active set(value): + if !is_node_ready(): await ready + if external_value != null: external_value.value = value else: diff --git a/content/ui/components/tabs/tabs.gd b/content/ui/components/tabs/tabs.gd index f5172ce..f8e88e6 100644 --- a/content/ui/components/tabs/tabs.gd +++ b/content/ui/components/tabs/tabs.gd @@ -25,3 +25,4 @@ func _ready(): ) option.external_value = proxy + option.toggleable = true diff --git a/content/ui/menu/menu.tscn b/content/ui/menu/menu.tscn index a8acc5a..80fa307 100644 --- a/content/ui/menu/menu.tscn +++ b/content/ui/menu/menu.tscn @@ -187,7 +187,7 @@ shape = SubResource("ConvexPolygonShape3D_mgnm0") [node name="Tabs" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("initial_selected")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0) script = ExtResource("4_eavfx") -initial_selected = NodePath("View") +initial_selected = NodePath("") [node name="View" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03) diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index f0aecc5..3293953 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -1,46 +1,8 @@ extends Node3D -const Room = preload("res://content/system/house/room/room.tscn") -const RoomType = preload("res://content/system/house/room/room.gd") - -const material_selected = preload("./room_selected.tres") -const material_unselected = preload("./room_unselected.tres") - const window_scene = preload("./window.tscn") @onready var background = $Background -@onready var room_button = $Interface/Button -@onready var input = $Interface/Input -@onready var rooms_map = $Interface/Rooms - -var selected_room = null: - set(value): - if selected_room != null && value == null: - room_button.label = "add" - input.text = "New Room %s" % (rooms_map.get_child_count() + 1) - - if selected_room != null: - var old_room = get_room(selected_room) - if old_room != null: - old_room.get_node("MeshInstance3D").material_override = material_unselected - - if value != null: - input.text = value - edit_room = false - var new_room = get_room(value) - if new_room != null: - new_room.get_node("MeshInstance3D").material_override = material_selected - - - selected_room = value - -var edit_room = false: - set(value): - edit_room = value - if value: - room_button.label = "save" - else: - room_button.label = "edit" func _ready(): background.visible = false @@ -52,90 +14,3 @@ func _ready(): # var mesh = room.wall_mesh pass ) - - room_button.on_button_down.connect(func(): - if selected_room == null: - var room_name = input.text - if get_room(room_name) != null: - EventSystem.notify("Name already taken", EventNotify.Type.WARNING) - return - - House.body.create_room(room_name, 0) - selected_room = room_name - edit_room = true - else: - if edit_room: - edit_room = false - - if !House.body.is_valid_room(selected_room): - House.body.delete_room(selected_room) - selected_room = null - else: - House.body.edit_room(null) - _generate_room_map() - else: - edit_room = true - House.body.edit_room(selected_room) - ) - -func get_room(room_name): - if rooms_map.has_node("%s" % room_name): - return rooms_map.get_node("%s" % room_name) - return null - -func _on_click(event: EventPointer): - if event.target.get_parent() == rooms_map: - var room_name = event.target.name - - if selected_room == room_name: - selected_room = null - House.body.edit_room(null) - return - - selected_room = room_name - -func _generate_room_map(): - var rooms = House.body.get_rooms(0) - - var target_size = Vector3(0.3, 1, 0.24) - - for old_room in rooms_map.get_children(): - old_room.queue_free() - await old_room.tree_exited - - var aabb = House.body.get_level_aabb(0) - var current_min = aabb.position - var current_max = aabb.position + aabb.size - - for room in rooms: - var mesh = room.ceiling_mesh.mesh - if mesh == null: - continue - - var body = StaticBody3D.new() - body.name = room.name - - - var mesh_instance = MeshInstance3D.new() - mesh_instance.name = "MeshInstance3D" - mesh_instance.mesh = mesh - mesh_instance.material_override = material_unselected if selected_room != room.name else material_selected - body.add_child(mesh_instance) - - var collision_shape = CollisionShape3D.new() - collision_shape.shape = mesh.create_trimesh_shape() - body.add_child(collision_shape) - - rooms_map.add_child(body) - - if current_min == null: - return - - var current_size = current_max - current_min - var target_scale = target_size / current_size - var scale_value = min(target_scale.x, target_scale.z) - - rooms_map.position.x = -current_min.x * scale_value - rooms_map.position.z = -current_min.z * scale_value - - rooms_map.scale = Vector3(scale_value, scale_value, scale_value) diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index 72cad75..61a444b 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=6 format=3 uid="uid://c01gkeldvjwtr"] +[gd_scene load_steps=9 format=3 uid="uid://c01gkeldvjwtr"] [ext_resource type="Script" path="res://content/ui/menu/room/room_menu.gd" id="1_ch4jb"] [ext_resource type="Material" uid="uid://bujy3egn1oqac" path="res://assets/materials/pri-500.material" id="2_7m4yn"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="4_cghmp"] -[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="4_pbj71"] +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs.gd" id="5_ddrep"] +[ext_resource type="PackedScene" uid="uid://dd71loi64gnmp" path="res://content/ui/menu/room/views/overview.tscn" id="6_206ad"] +[ext_resource type="Script" path="res://content/ui/components/tabs/tabs_content.gd" id="6_ba00g"] +[ext_resource type="PackedScene" uid="uid://bpta22fahai46" path="res://content/ui/menu/room/views/rooms.tscn" id="7_2f8e0"] [sub_resource type="BoxMesh" id="BoxMesh_e37nn"] size = Vector3(0.3, 0.01, 0.3) @@ -18,22 +21,21 @@ mesh = SubResource("BoxMesh_e37nn") [node name="Interface" type="Node3D" parent="."] -[node name="Rooms" type="Node3D" parent="Interface"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12) +[node name="Tabs3D" type="Node3D" parent="Interface"] +script = ExtResource("5_ddrep") -[node name="Button" parent="Interface" instance=ExtResource("4_cghmp")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27) -label = "add" -icon = true - -[node name="Input" parent="Interface" instance=ExtResource("4_pbj71")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27) -text = "New Room 1" - -[node name="Button2" parent="." instance=ExtResource("4_cghmp")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0) +[node name="Overview" parent="Interface/Tabs3D" instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, -0.02) label = "Overview" -[node name="Button" parent="." instance=ExtResource("4_cghmp")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, 0) +[node name="Rooms" parent="Interface/Tabs3D" instance=ExtResource("4_cghmp")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.09, 0, -0.02) label = "Rooms" + +[node name="TabsContent3D" type="Node3D" parent="Interface" node_paths=PackedStringArray("tabs")] +script = ExtResource("6_ba00g") +tabs = NodePath("../Tabs3D") + +[node name="Overview" parent="Interface/TabsContent3D" instance=ExtResource("6_206ad")] + +[node name="Rooms" parent="Interface/TabsContent3D" instance=ExtResource("7_2f8e0")] diff --git a/content/ui/menu/room/views/overview.tscn b/content/ui/menu/room/views/overview.tscn new file mode 100644 index 0000000..970307b --- /dev/null +++ b/content/ui/menu/room/views/overview.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=2 format=3 uid="uid://dd71loi64gnmp"] + +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_fteh8"] + +[node name="Overview" type="Node3D"] + +[node name="Button2" parent="." instance=ExtResource("1_fteh8")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0, 0.07) +label = "add" +icon = true + +[node name="Button3" parent="." instance=ExtResource("1_fteh8")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.07) +label = "healing" +icon = true + +[node name="Label3D" type="Label3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.06, 0.01, 0.02) +pixel_size = 0.001 +text = "Reference" +font_size = 18 +outline_size = 0 diff --git a/content/ui/menu/room/views/rooms.gd b/content/ui/menu/room/views/rooms.gd new file mode 100644 index 0000000..ade009c --- /dev/null +++ b/content/ui/menu/room/views/rooms.gd @@ -0,0 +1,130 @@ +extends Node3D + +const Room = preload("res://content/system/house/room/room.tscn") +const RoomType = preload("res://content/system/house/room/room.gd") + +const material_selected = preload("../room_selected.tres") +const material_unselected = preload("../room_unselected.tres") + + +@onready var room_button = $Button +@onready var input = $Input +@onready var rooms_map = $Rooms + +var selected_room = null: + set(value): + if selected_room != null && value == null: + room_button.label = "add" + input.text = "New Room %s" % (rooms_map.get_child_count() + 1) + + if selected_room != null: + var old_room = get_room(selected_room) + if old_room != null: + old_room.get_node("MeshInstance3D").material_override = material_unselected + + if value != null: + input.text = value + edit_room = false + var new_room = get_room(value) + if new_room != null: + new_room.get_node("MeshInstance3D").material_override = material_selected + + + selected_room = value + +var edit_room = false: + set(value): + edit_room = value + if value: + room_button.label = "save" + else: + room_button.label = "edit" + +func _ready(): + + room_button.on_button_down.connect(func(): + if selected_room == null: + var room_name = input.text + if get_room(room_name) != null: + EventSystem.notify("Name already taken", EventNotify.Type.WARNING) + return + + House.body.create_room(room_name, 0) + selected_room = room_name + edit_room = true + else: + if edit_room: + edit_room = false + + if !House.body.is_valid_room(selected_room): + House.body.delete_room(selected_room) + selected_room = null + else: + House.body.edit_room(null) + _generate_room_map() + else: + edit_room = true + House.body.edit_room(selected_room) + ) + +func get_room(room_name): + if rooms_map.has_node("%s" % room_name): + return rooms_map.get_node("%s" % room_name) + return null + +func _on_click(event: EventPointer): + if event.target.get_parent() == rooms_map: + var room_name = event.target.name + + if selected_room == room_name: + selected_room = null + House.body.edit_room(null) + return + + selected_room = room_name + +func _generate_room_map(): + var rooms = House.body.get_rooms(0) + + var target_size = Vector3(0.3, 1, 0.24) + + for old_room in rooms_map.get_children(): + old_room.queue_free() + await old_room.tree_exited + + var aabb = House.body.get_level_aabb(0) + var current_min = aabb.position + var current_max = aabb.position + aabb.size + + for room in rooms: + var mesh = room.ceiling_mesh.mesh + if mesh == null: + continue + + var body = StaticBody3D.new() + body.name = room.name + + + var mesh_instance = MeshInstance3D.new() + mesh_instance.name = "MeshInstance3D" + mesh_instance.mesh = mesh + mesh_instance.material_override = material_unselected if selected_room != room.name else material_selected + body.add_child(mesh_instance) + + var collision_shape = CollisionShape3D.new() + collision_shape.shape = mesh.create_trimesh_shape() + body.add_child(collision_shape) + + rooms_map.add_child(body) + + if current_min == null: + return + + var current_size = current_max - current_min + var target_scale = target_size / current_size + var scale_value = min(target_scale.x, target_scale.z) + + rooms_map.position.x = -current_min.x * scale_value + rooms_map.position.z = -current_min.z * scale_value + + rooms_map.scale = Vector3(scale_value, scale_value, scale_value) diff --git a/content/ui/menu/room/views/rooms.tscn b/content/ui/menu/room/views/rooms.tscn new file mode 100644 index 0000000..fe5a321 --- /dev/null +++ b/content/ui/menu/room/views/rooms.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=3 uid="uid://bpta22fahai46"] + +[ext_resource type="Script" path="res://content/ui/menu/room/views/rooms.gd" id="1_3a1oa"] +[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_y3lty"] +[ext_resource type="PackedScene" uid="uid://blrhy2uccrdn4" path="res://content/ui/components/input/input.tscn" id="2_hstw7"] + +[node name="Rooms" type="Node3D"] +script = ExtResource("1_3a1oa") + +[node name="Rooms" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0.01, 0.12) + +[node name="Button" parent="." instance=ExtResource("1_y3lty")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27, 0, 0.27) +label = "add" +icon = true + +[node name="Input" parent="." instance=ExtResource("2_hstw7")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27) +text = "" From 0f50f5a0c82d75e385c4639bcd81ba6c108a1eb9 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Wed, 24 Jan 2024 17:43:44 +0100 Subject: [PATCH 13/17] add alignment system to rooms --- content/functions/movable.gd | 15 ++++++- content/system/house/align_reference.gd | 46 ++++++++++++++++++++++ content/system/house/align_reference.tscn | 36 +++++++++++++++++ content/system/house/house.gd | 22 ++++++++++- content/system/house/house.tscn | 14 ++++++- content/system/house/room/states/edit.gd | 43 ++++++-------------- content/system/house/room/wall_edge.gd | 16 ++++++++ content/system/house/room/wall_edge.tscn | 4 +- content/ui/components/tabs/tabs_content.gd | 2 + content/ui/menu/menu.tscn | 2 +- content/ui/menu/room/room_menu.tscn | 3 +- content/ui/menu/room/views/overview.gd | 31 +++++++++++++++ content/ui/menu/room/views/overview.tscn | 10 +++-- lib/globals/save_system.gd | 3 ++ 14 files changed, 207 insertions(+), 40 deletions(-) create mode 100644 content/system/house/align_reference.gd create mode 100644 content/system/house/align_reference.tscn create mode 100644 content/system/house/room/wall_edge.gd create mode 100644 content/ui/menu/room/views/overview.gd diff --git a/content/functions/movable.gd b/content/functions/movable.gd index 9e9b99f..6b2179f 100644 --- a/content/functions/movable.gd +++ b/content/functions/movable.gd @@ -2,7 +2,10 @@ extends Function class_name Movable +signal on_move(position: Vector3, rotation: Vector3) + @export var restricted: bool = false +@export var restrict_movement: Callable @export var lock_rotation: bool = false var hit_node := Node3D.new() @@ -14,10 +17,20 @@ func _on_grab_down(event: EventPointer): hit_node.global_transform = get_parent().global_transform func _on_grab_move(_event: EventPointer): - get_parent().global_position = hit_node.global_position + if hit_node.get_parent() == null: + return + + if restrict_movement: + get_parent().global_position = restrict_movement.call(hit_node.global_position) + else: + get_parent().global_position = hit_node.global_position if !lock_rotation: get_parent().global_rotation = hit_node.global_rotation + on_move.emit(get_parent().global_position, get_parent().global_rotation) + else: + on_move.emit(get_parent().global_position, Vector3(0, 0, 0)) + func _on_grab_up(event: EventPointer): event.initiator.node.remove_child(hit_node) diff --git a/content/system/house/align_reference.gd b/content/system/house/align_reference.gd new file mode 100644 index 0000000..92ae08b --- /dev/null +++ b/content/system/house/align_reference.gd @@ -0,0 +1,46 @@ +extends Node3D + +@onready var corner1 = $Corner1 +@onready var corner2 = $Corner1/Corner2 +@onready var edge = $Edge +@onready var marker = $Edge/Marker3D + +@export var disabled: bool: + set(value): + disabled = value + + if !is_node_ready(): await ready + + corner1.get_node("CollisionShape3D").disabled = value + corner2.get_node("CollisionShape3D").disabled = value + edge.get_node("CollisionShape3D").disabled = value + corner1.visible = !value + corner2.visible = !value + edge.visible = !value + +func _ready(): + update_initial_positions() + + corner1.get_node("Movable").on_move.connect(func(position, rotation): + edge.align_to_corners(corner1.global_position, corner2.global_position) + ) + + corner2.get_node("Movable").on_move.connect(func(position, rotation): + edge.align_to_corners(corner1.global_position, corner2.global_position) + ) + + corner2.get_node("Movable").restrict_movement = func(new_position): + new_position.y = corner1.global_position.y + + var delta_new_pos_corner1 = (new_position - corner1.position).normalized() + + return corner1.position + delta_new_pos_corner1 + +func update_initial_positions(): + edge.align_to_corners(corner1.global_position, corner2.global_position) + marker.global_transform = House.body.transform + +func get_new_transform(old_transform: Transform3D): + marker.scale = Vector3(1, 1, 1) + return marker.global_transform + diff --git a/content/system/house/align_reference.tscn b/content/system/house/align_reference.tscn new file mode 100644 index 0000000..110fa20 --- /dev/null +++ b/content/system/house/align_reference.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=6 format=3 uid="uid://jls16btb8nko"] + +[ext_resource type="Script" path="res://content/system/house/align_reference.gd" id="1_8fatp"] +[ext_resource type="PackedScene" uid="uid://brf6mm2gxj7y2" path="res://content/system/house/room/wall_corner.tscn" id="2_ppkie"] +[ext_resource type="PackedScene" uid="uid://dlj5chj7ndgua" path="res://content/system/house/room/wall_edge.tscn" id="3_6o3xn"] +[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_7ktdq"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_0e4xu"] +top_radius = 0.1 +bottom_radius = 0.1 +height = 0.2 + +[node name="AlignReference" type="Node3D"] +script = ExtResource("1_8fatp") + +[node name="Corner1" parent="." instance=ExtResource("2_ppkie")] + +[node name="Movable" type="Node" parent="Corner1"] +script = ExtResource("3_7ktdq") +restricted = true +lock_rotation = true + +[node name="Corner2" parent="Corner1" instance=ExtResource("2_ppkie")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0) + +[node name="Movable" type="Node" parent="Corner1/Corner2"] +script = ExtResource("3_7ktdq") +lock_rotation = true + +[node name="Edge" parent="." instance=ExtResource("3_6o3xn")] +transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.5, 0, 0) + +[node name="Marker3D" type="Marker3D" parent="Edge"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Edge/Marker3D"] +mesh = SubResource("CylinderMesh_0e4xu") diff --git a/content/system/house/house.gd b/content/system/house/house.gd index 82bf1bc..e5fb4e9 100644 --- a/content/system/house/house.gd +++ b/content/system/house/house.gd @@ -5,7 +5,9 @@ const RoomType = preload("./room/room.gd") @onready var levels = $Levels @onready var collision_shape = $Levels/CollisionShape3D +@onready var align_reference = $AlignReference +var fixing_reference: bool = false var editing_room: RoomType = null var mini_view: bool = false: set(value): @@ -145,4 +147,22 @@ func update_mini_view(): target_size = 0.1 if mini_view else 1.0 for room in get_rooms(0): - room.state_machine.change_to("Mini" if mini_view else "View") \ No newline at end of file + room.state_machine.change_to("Mini" if mini_view else "View") + +func edit_reference(): + fixing_reference = false + align_reference.disabled = false + +func fix_reference(): + fixing_reference = true + align_reference.disabled = false + align_reference.update_initial_positions() + +func save_reference(): + if fixing_reference: + var align_transform = align_reference.global_transform + transform = align_reference.get_new_transform(transform) + align_reference.global_transform = align_transform + + align_reference.disabled = true + align_reference.update_initial_positions() \ No newline at end of file diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn index 21124de..57df0d3 100644 --- a/content/system/house/house.tscn +++ b/content/system/house/house.tscn @@ -1,10 +1,15 @@ -[gd_scene load_steps=4 format=3 uid="uid://cbemihbxkd4ll"] +[gd_scene load_steps=6 format=3 uid="uid://cbemihbxkd4ll"] [ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_w1auk"] +[ext_resource type="PackedScene" uid="uid://jls16btb8nko" path="res://content/system/house/align_reference.tscn" id="3_e1tcn"] [sub_resource type="BoxShape3D" id="BoxShape3D_x81up"] +[sub_resource type="CapsuleMesh" id="CapsuleMesh_uovmo"] +radius = 0.02 +height = 0.4 + [node name="House" type="Node3D"] script = ExtResource("1_p8amj") @@ -20,3 +25,10 @@ disabled = true script = ExtResource("2_w1auk") restricted = true lock_rotation = true + +[node name="AlignReference" parent="." instance=ExtResource("3_e1tcn")] +disabled = true + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0) +mesh = SubResource("CapsuleMesh_uovmo") diff --git a/content/system/house/room/states/edit.gd b/content/system/house/room/states/edit.gd index 152a557..2226b46 100644 --- a/content/system/house/room/states/edit.gd +++ b/content/system/house/room/states/edit.gd @@ -64,7 +64,7 @@ func add_floor_corner(position: Vector3): floor_corner.position = position height_edge = wall_edge_scene.instantiate() - height_edge.transform = corners_to_edge_transform(position, position + Vector3.UP * room.room_ceiling.global_position.y) + height_edge.align_to_corners(position, position + Vector3.UP * room.room_ceiling.global_position.y) floor_corner.get_node("Clickable").on_grab_down.connect(func(event): if !is_active() || moving != null: @@ -86,7 +86,7 @@ func add_floor_corner(position: Vector3): moving.position = new_position - height_edge.transform = corners_to_edge_transform(new_position, new_position + Vector3.UP * room.room_ceiling.global_position.y) + height_edge.align_to_corners(new_position, new_position + Vector3.UP * room.room_ceiling.global_position.y) room.get_corner(moving_index).position.x = new_position.x room.get_corner(moving_index).position.z = new_position.z @@ -94,8 +94,8 @@ func add_floor_corner(position: Vector3): if room.wall_edges.get_child_count() == 0: return - room.get_edge(moving_index).transform = corners_to_edge_transform(new_position, room.get_corner(moving_index + 1).position) - room.get_edge(moving_index - 1).transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, new_position) + room.get_edge(moving_index).align_to_corners(new_position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index - 1).align_to_corners(room.get_corner(moving_index - 1).position, new_position) ) floor_corner.get_node("Clickable").on_grab_up.connect(func(_event): @@ -134,7 +134,7 @@ func add_height_corner(position: Vector3): return room.room_ceiling.position.y = new_position.y - height_edge.transform = corners_to_edge_transform(floor_corner.global_position, height_corner.global_position) + height_edge.align_to_corners(floor_corner.global_position, height_corner.global_position) ) @@ -175,9 +175,8 @@ func add_corner(position: Vector3, index: int = -1): if room.wall_edges.get_child_count() == 0: return - var edge_transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, room.get_corner(moving_index + 1).position) - room.get_edge(moving_index).transform = edge_transform - room.get_edge(moving_index - 1).transform = edge_transform + room.get_edge(moving_index).align_to_corners(room.get_corner(moving_index - 1).position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index - 1).transform = room.get_edge(moving_index).transform return @@ -191,8 +190,8 @@ func add_corner(position: Vector3, index: int = -1): if room.wall_edges.get_child_count() == 0: return - room.get_edge(moving_index).transform = corners_to_edge_transform(new_position, room.get_corner(moving_index + 1).position) - room.get_edge(moving_index - 1).transform = corners_to_edge_transform(room.get_corner(moving_index - 1).position, new_position) + room.get_edge(moving_index).align_to_corners(new_position, room.get_corner(moving_index + 1).position) + room.get_edge(moving_index - 1).align_to_corners(room.get_corner(moving_index - 1).position, new_position) ) corner.get_node("Clickable").on_grab_up.connect(func(_event): @@ -208,21 +207,20 @@ func add_corner(position: Vector3, index: int = -1): room.wall_corners.move_child(corner, index) var num_corners = room.wall_corners.get_child_count() - var edge if num_corners > 1: - edge = add_edge(position, room.get_corner(index + 1).position, index) + add_edge(position, room.get_corner(index + 1).position, index) if num_corners > 2: if num_corners != room.wall_edges.get_child_count(): add_edge(room.get_corner(-2).position, room.get_corner(-1).position, -2) else: - room.get_edge(index - 1).transform = corners_to_edge_transform(room.get_corner(index - 1).position, position) + room.get_edge(index - 1).align_to_corners(room.get_corner(index - 1).position, position) func add_edge(from_pos: Vector3, to_pos: Vector3, index: int = -1): var edge: StaticBody3D = wall_edge_scene.instantiate() - edge.transform = corners_to_edge_transform(from_pos, to_pos) + edge.align_to_corners(from_pos, to_pos) edge.get_node("Clickable").on_press_down.connect(func(event): var point = event.ray.get_collision_point() @@ -233,19 +231,4 @@ func add_edge(from_pos: Vector3, to_pos: Vector3, index: int = -1): room.wall_edges.add_child(edge) room.wall_edges.move_child(edge, index) - return edge - -func corners_to_edge_transform(from_pos: Vector3, to_pos: Vector3) -> Transform3D: - var diff = to_pos - from_pos - var direction = diff.normalized() - var tangent = Vector3(direction.z, 0, -direction.x).normalized() - - if tangent == Vector3.ZERO: - tangent = Vector3(1, 0, 0) - - var edge_position = from_pos + diff / 2 - - var edge_basis = Basis(tangent, diff, tangent.cross(direction)) - - var edge_transform = Transform3D(edge_basis, edge_position) - return edge_transform + return edge \ No newline at end of file diff --git a/content/system/house/room/wall_edge.gd b/content/system/house/room/wall_edge.gd new file mode 100644 index 0000000..22745fd --- /dev/null +++ b/content/system/house/room/wall_edge.gd @@ -0,0 +1,16 @@ +extends StaticBody3D + + +func align_to_corners(from_pos: Vector3, to_pos: Vector3): + var diff = to_pos - from_pos + var direction = diff.normalized() + var tangent = Vector3(direction.z, 0, -direction.x).normalized() + + if tangent == Vector3.ZERO: + tangent = Vector3(1, 0, 0) + + var edge_position = from_pos + diff / 2 + + var edge_basis = Basis(tangent, diff, tangent.cross(direction)) + + transform = Transform3D(edge_basis, edge_position) diff --git a/content/system/house/room/wall_edge.tscn b/content/system/house/room/wall_edge.tscn index 311a46c..2eeb489 100644 --- a/content/system/house/room/wall_edge.tscn +++ b/content/system/house/room/wall_edge.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=5 format=3 uid="uid://dlj5chj7ndgua"] +[gd_scene load_steps=6 format=3 uid="uid://dlj5chj7ndgua"] +[ext_resource type="Script" path="res://content/system/house/room/wall_edge.gd" id="1_0c5rj"] [ext_resource type="Material" uid="uid://j12e5wwthtaa" path="res://content/system/house/room/edge.tres" id="1_hs3tw"] [ext_resource type="Script" path="res://content/functions/clickable.gd" id="2_cfvx2"] @@ -13,6 +14,7 @@ radius = 0.04 height = 1.0 [node name="StaticBody3D" type="StaticBody3D"] +script = ExtResource("1_0c5rj") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] mesh = SubResource("CapsuleMesh_a2dct") diff --git a/content/ui/components/tabs/tabs_content.gd b/content/ui/components/tabs/tabs_content.gd index 734ff29..73d3052 100644 --- a/content/ui/components/tabs/tabs_content.gd +++ b/content/ui/components/tabs/tabs_content.gd @@ -10,6 +10,8 @@ func _ready(): for child in children: child.visible = true + if tabs.selected != null && tabs.selected.get_index() == child.get_index(): + continue remove_child(child) tabs.on_select.connect(func(index): diff --git a/content/ui/menu/menu.tscn b/content/ui/menu/menu.tscn index 80fa307..a8acc5a 100644 --- a/content/ui/menu/menu.tscn +++ b/content/ui/menu/menu.tscn @@ -187,7 +187,7 @@ shape = SubResource("ConvexPolygonShape3D_mgnm0") [node name="Tabs" type="Node3D" parent="AnimationContainer" node_paths=PackedStringArray("initial_selected")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0, 0) script = ExtResource("4_eavfx") -initial_selected = NodePath("") +initial_selected = NodePath("View") [node name="View" parent="AnimationContainer/Tabs" instance=ExtResource("5_w4i01")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03, 0, 0.03) diff --git a/content/ui/menu/room/room_menu.tscn b/content/ui/menu/room/room_menu.tscn index 61a444b..4dd5d60 100644 --- a/content/ui/menu/room/room_menu.tscn +++ b/content/ui/menu/room/room_menu.tscn @@ -21,8 +21,9 @@ mesh = SubResource("BoxMesh_e37nn") [node name="Interface" type="Node3D" parent="."] -[node name="Tabs3D" type="Node3D" parent="Interface"] +[node name="Tabs3D" type="Node3D" parent="Interface" node_paths=PackedStringArray("initial_selected")] script = ExtResource("5_ddrep") +initial_selected = NodePath("Overview") [node name="Overview" parent="Interface/Tabs3D" instance=ExtResource("4_cghmp")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, -0.02) diff --git a/content/ui/menu/room/views/overview.gd b/content/ui/menu/room/views/overview.gd new file mode 100644 index 0000000..2cb31f1 --- /dev/null +++ b/content/ui/menu/room/views/overview.gd @@ -0,0 +1,31 @@ +extends Node3D + +@onready var edit_button = $EditButton +@onready var fix_button = $FixButton + +var active = false: + set(value): + if value: + edit_button.label = "save" + fix_button.disabled = true + fix_button.visible = false + else: + edit_button.label = "edit" + fix_button.disabled = false + fix_button.visible = true + active = value + +func _ready(): + + edit_button.on_button_down.connect(func(): + if active: + House.body.save_reference() + else: + House.body.edit_reference() + active = !active + ) + + fix_button.on_button_down.connect(func(): + House.body.fix_reference() + active = true + ) diff --git a/content/ui/menu/room/views/overview.tscn b/content/ui/menu/room/views/overview.tscn index 970307b..d158f91 100644 --- a/content/ui/menu/room/views/overview.tscn +++ b/content/ui/menu/room/views/overview.tscn @@ -1,15 +1,17 @@ -[gd_scene load_steps=2 format=3 uid="uid://dd71loi64gnmp"] +[gd_scene load_steps=3 format=3 uid="uid://dd71loi64gnmp"] [ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="1_fteh8"] +[ext_resource type="Script" path="res://content/ui/menu/room/views/overview.gd" id="1_jesad"] [node name="Overview" type="Node3D"] +script = ExtResource("1_jesad") -[node name="Button2" parent="." instance=ExtResource("1_fteh8")] +[node name="EditButton" parent="." instance=ExtResource("1_fteh8")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.04, 0, 0.07) -label = "add" +label = "edit" icon = true -[node name="Button3" parent="." instance=ExtResource("1_fteh8")] +[node name="FixButton" parent="." instance=ExtResource("1_fteh8")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1, 0, 0.07) label = "healing" icon = true diff --git a/lib/globals/save_system.gd b/lib/globals/save_system.gd index 46beaa4..c4d7e10 100644 --- a/lib/globals/save_system.gd +++ b/lib/globals/save_system.gd @@ -49,6 +49,9 @@ func load(): var json_text = save_file.get_line() var save_data = JSON.parse_string(json_text) + if save_data == null: + return + if save_data.has("version") == false: save() return From 9328e9ba8924352b2ced80b3a23b0a7ef8ff5c6e Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 25 Jan 2024 11:26:37 +0100 Subject: [PATCH 14/17] clean up test objects --- content/system/house/align_reference.tscn | 10 +--------- content/system/house/house.tscn | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/content/system/house/align_reference.tscn b/content/system/house/align_reference.tscn index 110fa20..428f809 100644 --- a/content/system/house/align_reference.tscn +++ b/content/system/house/align_reference.tscn @@ -1,15 +1,10 @@ -[gd_scene load_steps=6 format=3 uid="uid://jls16btb8nko"] +[gd_scene load_steps=5 format=3 uid="uid://jls16btb8nko"] [ext_resource type="Script" path="res://content/system/house/align_reference.gd" id="1_8fatp"] [ext_resource type="PackedScene" uid="uid://brf6mm2gxj7y2" path="res://content/system/house/room/wall_corner.tscn" id="2_ppkie"] [ext_resource type="PackedScene" uid="uid://dlj5chj7ndgua" path="res://content/system/house/room/wall_edge.tscn" id="3_6o3xn"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="3_7ktdq"] -[sub_resource type="CylinderMesh" id="CylinderMesh_0e4xu"] -top_radius = 0.1 -bottom_radius = 0.1 -height = 0.2 - [node name="AlignReference" type="Node3D"] script = ExtResource("1_8fatp") @@ -31,6 +26,3 @@ lock_rotation = true transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.5, 0, 0) [node name="Marker3D" type="Marker3D" parent="Edge"] - -[node name="MeshInstance3D" type="MeshInstance3D" parent="Edge/Marker3D"] -mesh = SubResource("CylinderMesh_0e4xu") diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn index 57df0d3..adc5680 100644 --- a/content/system/house/house.tscn +++ b/content/system/house/house.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=3 uid="uid://cbemihbxkd4ll"] +[gd_scene load_steps=5 format=3 uid="uid://cbemihbxkd4ll"] [ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="2_w1auk"] @@ -6,10 +6,6 @@ [sub_resource type="BoxShape3D" id="BoxShape3D_x81up"] -[sub_resource type="CapsuleMesh" id="CapsuleMesh_uovmo"] -radius = 0.02 -height = 0.4 - [node name="House" type="Node3D"] script = ExtResource("1_p8amj") @@ -28,7 +24,3 @@ lock_rotation = true [node name="AlignReference" parent="." instance=ExtResource("3_e1tcn")] disabled = true - -[node name="MeshInstance3D" type="MeshInstance3D" parent="."] -transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0) -mesh = SubResource("CapsuleMesh_uovmo") From 13157c9f84cb0d01c75dce5851d7bfcae8070009 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 25 Jan 2024 12:23:07 +0100 Subject: [PATCH 15/17] clean up and fixes --- content/functions/movable.gd | 3 +-- content/main.gd | 3 +-- content/system/house/align_reference.tscn | 15 ++++++++++++++- content/system/house/house.tscn | 1 + content/system/house/room/room.gd | 21 +-------------------- content/ui/menu/room/views/rooms.gd | 2 +- content/ui/menu/room/views/rooms.tscn | 2 +- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/content/functions/movable.gd b/content/functions/movable.gd index 6b2179f..46ad7ad 100644 --- a/content/functions/movable.gd +++ b/content/functions/movable.gd @@ -26,12 +26,11 @@ func _on_grab_move(_event: EventPointer): get_parent().global_position = hit_node.global_position if !lock_rotation: - get_parent().global_rotation = hit_node.global_rotation + get_parent().global_basis = hit_node.global_basis on_move.emit(get_parent().global_position, get_parent().global_rotation) else: on_move.emit(get_parent().global_position, Vector3(0, 0, 0)) - func _on_grab_up(event: EventPointer): event.initiator.node.remove_child(hit_node) diff --git a/content/main.gd b/content/main.gd index e553ded..bc873e1 100644 --- a/content/main.gd +++ b/content/main.gd @@ -50,8 +50,7 @@ func _ready(): return add_child(keyboard) - if event.previous_target == null: - keyboard.global_transform = menu.get_node("AnimationContainer/KeyboardPlace").global_transform + keyboard.global_transform = menu.get_node("AnimationContainer/KeyboardPlace").global_transform ) EventSystem.on_focus_out.connect(func(event): diff --git a/content/system/house/align_reference.tscn b/content/system/house/align_reference.tscn index 428f809..4521894 100644 --- a/content/system/house/align_reference.tscn +++ b/content/system/house/align_reference.tscn @@ -1,9 +1,15 @@ -[gd_scene load_steps=5 format=3 uid="uid://jls16btb8nko"] +[gd_scene load_steps=7 format=3 uid="uid://jls16btb8nko"] [ext_resource type="Script" path="res://content/system/house/align_reference.gd" id="1_8fatp"] [ext_resource type="PackedScene" uid="uid://brf6mm2gxj7y2" path="res://content/system/house/room/wall_corner.tscn" id="2_ppkie"] [ext_resource type="PackedScene" uid="uid://dlj5chj7ndgua" path="res://content/system/house/room/wall_edge.tscn" id="3_6o3xn"] [ext_resource type="Script" path="res://content/functions/movable.gd" id="3_7ktdq"] +[ext_resource type="Material" uid="uid://dxyuncqxagt28" path="res://content/system/house/room/walls_mini.tres" id="4_jkpj4"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_k2m3v"] +top_radius = 0.001 +bottom_radius = 0.05 +height = 0.1 [node name="AlignReference" type="Node3D"] script = ExtResource("1_8fatp") @@ -18,6 +24,11 @@ lock_rotation = true [node name="Corner2" parent="Corner1" instance=ExtResource("2_ppkie")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0) +[node name="MeshInstance3D" parent="Corner1/Corner2" index="1"] +transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0) +material_override = ExtResource("4_jkpj4") +mesh = SubResource("CylinderMesh_k2m3v") + [node name="Movable" type="Node" parent="Corner1/Corner2"] script = ExtResource("3_7ktdq") lock_rotation = true @@ -26,3 +37,5 @@ lock_rotation = true transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.5, 0, 0) [node name="Marker3D" type="Marker3D" parent="Edge"] + +[editable path="Corner1/Corner2"] diff --git a/content/system/house/house.tscn b/content/system/house/house.tscn index adc5680..b17ab66 100644 --- a/content/system/house/house.tscn +++ b/content/system/house/house.tscn @@ -23,4 +23,5 @@ restricted = true lock_rotation = true [node name="AlignReference" parent="." instance=ExtResource("3_e1tcn")] +visible = false disabled = true diff --git a/content/system/house/room/room.gd b/content/system/house/room/room.gd index 6b654db..ea0b908 100644 --- a/content/system/house/room/room.gd +++ b/content/system/house/room/room.gd @@ -50,23 +50,4 @@ func get_aabb(): min_pos.y = room_floor.position.y max_pos.y = room_ceiling.position.y - return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) - -func _save(): - return { - "corners": wall_corners.get_children().map(func(corner): return corner.position), - "name": name - } - -func _load(data): - await ready - return - - name = data["name"] - - state_machine.change_to("Edit") - - for corner in data["corners"]: - state_machine.current_state.add_corner(corner) - - state_machine.change_to("View") + return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos)) \ No newline at end of file diff --git a/content/ui/menu/room/views/rooms.gd b/content/ui/menu/room/views/rooms.gd index ade009c..5efc268 100644 --- a/content/ui/menu/room/views/rooms.gd +++ b/content/ui/menu/room/views/rooms.gd @@ -15,7 +15,7 @@ var selected_room = null: set(value): if selected_room != null && value == null: room_button.label = "add" - input.text = "New Room %s" % (rooms_map.get_child_count() + 1) + input.text = "Room %s" % (rooms_map.get_child_count() + 1) if selected_room != null: var old_room = get_room(selected_room) diff --git a/content/ui/menu/room/views/rooms.tscn b/content/ui/menu/room/views/rooms.tscn index fe5a321..d666af7 100644 --- a/content/ui/menu/room/views/rooms.tscn +++ b/content/ui/menu/room/views/rooms.tscn @@ -17,4 +17,4 @@ icon = true [node name="Input" parent="." instance=ExtResource("2_hstw7")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.12, 0.005, 0.27) -text = "" +text = "Room 1" From 43ad4ecbab20dfb6491314af8d1294765d359653 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 25 Jan 2024 12:36:33 +0100 Subject: [PATCH 16/17] more small fixes --- content/system/house/room/states/edit.gd | 4 ++++ content/system/house/room/states/view.gd | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/content/system/house/room/states/edit.gd b/content/system/house/room/states/edit.gd index 2226b46..05dd188 100644 --- a/content/system/house/room/states/edit.gd +++ b/content/system/house/room/states/edit.gd @@ -20,6 +20,7 @@ func _on_enter(): height_edge.visible = true room.room_ceiling.get_node("CollisionShape3D").disabled = (floor_corner == null && height_corner == null) + room.room_floor.get_node("CollisionShape3D").disabled = false var ceiling_shape = WorldBoundaryShape3D.new() ceiling_shape.plane = Plane(Vector3.DOWN, 0) @@ -39,6 +40,9 @@ func _on_leave(): height_corner.visible = false height_edge.visible = false + room.room_ceiling.get_node("CollisionShape3D").disabled = true + room.room_floor.get_node("CollisionShape3D").disabled = true + room.room_ceiling.get_node("Clickable").on_click.disconnect(_on_click_ceiling) room.room_floor.get_node("Clickable").on_click.disconnect(_on_click_floor) diff --git a/content/system/house/room/states/view.gd b/content/system/house/room/states/view.gd index fc2db20..06e4715 100644 --- a/content/system/house/room/states/view.gd +++ b/content/system/house/room/states/view.gd @@ -20,10 +20,16 @@ func _on_enter(): if room.wall_mesh.mesh == null: return + var ceiling_shape = room.room_ceiling.get_node("CollisionShape3D") + var floor_shape = room.room_floor.get_node("CollisionShape3D") + + ceiling_shape.disabled = false + floor_shape.disabled = false + room.ceiling_mesh.mesh = generate_ceiling_mesh() - room.room_ceiling.get_node("CollisionShape3D").shape = room.ceiling_mesh.mesh.create_trimesh_shape() - room.room_floor.get_node("CollisionShape3D").shape = room.ceiling_mesh.mesh.create_trimesh_shape() - room.room_ceiling.get_node("CollisionShape3D").shape.backface_collision = true + ceiling_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 var collisions = generate_collision() @@ -41,6 +47,9 @@ func _on_leave(): room.wall_mesh.visible = false room.ceiling_mesh.visible = false + room.room_ceiling.get_node("CollisionShape3D").disabled = true + room.room_floor.get_node("CollisionShape3D").disabled = true + for collision in room.wall_collisions.get_children(): collision.queue_free() From add72832a71841969e7c8cdd540ad5b9fcae7eb9 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 25 Jan 2024 12:37:53 +0100 Subject: [PATCH 17/17] remove loose prints --- content/system/keyboard/keyboard.gd | 1 - content/ui/components/input/input.gd | 1 - content/ui/components/notification/notification.gd | 1 - 3 files changed, 3 deletions(-) diff --git a/content/system/keyboard/keyboard.gd b/content/system/keyboard/keyboard.gd index 947e5f1..fd70e60 100644 --- a/content/system/keyboard/keyboard.gd +++ b/content/system/keyboard/keyboard.gd @@ -90,5 +90,4 @@ func _emit_event(type: String, key: Key): event.shift_pressed = caps EventSystem.emit(type, event) - print("Emitting event: " + type + " " + EventKey.key_to_string(key, caps)) diff --git a/content/ui/components/input/input.gd b/content/ui/components/input/input.gd index a543f8d..6dd76e6 100644 --- a/content/ui/components/input/input.gd +++ b/content/ui/components/input/input.gd @@ -116,7 +116,6 @@ func update_caret_position(event): func _on_focus_out(_event): - print("focus out") animation.stop() caret.hide() diff --git a/content/ui/components/notification/notification.gd b/content/ui/components/notification/notification.gd index 5b8e6b6..38ddd61 100644 --- a/content/ui/components/notification/notification.gd +++ b/content/ui/components/notification/notification.gd @@ -13,7 +13,6 @@ extends Node3D set(value): type = value if !is_node_ready(): await ready - print(value, " ", _type_to_string(value)) icon_label.text = _type_to_string(value) @export var text: String = "": set(value):