update cdt lib and fix basic room creation and ui

This commit is contained in:
Nitwel 2023-12-21 16:44:56 +01:00
parent 228e32495c
commit 40f6c00eb8
11 changed files with 118 additions and 57 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8b7de3e0f751bc77feb61c2d2599576cdc0f76711cf2d67dec3b523f808d903c
size 875984
oid sha256:5b6a62d5ec5e2c9414b983a90041f1d674e092f71a9b5563277d2b6ad552a8d2
size 6274408

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:70a9f2c799d3d6703bd95abaacdd82c0d1b7a66fc39098aac64c330b0be0db06
size 5855024

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3e679688861d608c244393a7e3366539fa067ca75f71c3efb916d8745423cc7f
size 6003048

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:27f82d0c296c1ae8d71754353ee3f9c32955fe7a56ffbd54ca4f171a40827387
size 5612432

View File

@ -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"

View File

@ -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)

View File

@ -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()

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d7af833108b37da9ba445d2da6dbac058b5894f550177bf917fb9ab9fb6ecd1c
size 172

View File

@ -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,18 +53,19 @@ func _ready():
)
add_room_button.on_button_down.connect(func():
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
add_room_button.visible = false
)
save_room_button.on_button_down.connect(func():
else:
if edit_room:
edit_room = false
add_room_button.visible = true
House.body.edit_room(null)
_generate_room_map()
else:
@ -57,32 +73,47 @@ func _ready():
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)

View File

@ -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"

View File

@ -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()
# SaveSystem.save()
pass