implement foundation for a room system
This commit is contained in:
parent
eab54b5850
commit
9b116a97ab
|
@ -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)
|
||||
|
||||
|
|
67
content/system/house/house.gd
Normal file
67
content/system/house/house.gd
Normal file
|
@ -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
|
||||
|
||||
|
10
content/system/house/house.tscn
Normal file
10
content/system/house/house.tscn
Normal file
|
@ -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"]
|
|
@ -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 {
|
|
@ -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"]
|
||||
|
|
@ -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
|
||||
|
|
@ -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()
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
for room in rooms:
|
||||
var mesh = room.wall_mesh
|
||||
|
||||
|
||||
spawn_windows.on_button_down.connect(func():
|
||||
get_tree().root.get_node("Main").add_child.call_deferred(window_scene.instantiate())
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
3
lib/globals/house_body.gd
Normal file
3
lib/globals/house_body.gd
Normal file
|
@ -0,0 +1,3 @@
|
|||
extends Node
|
||||
|
||||
@onready var body = get_node("/root/Main/House")
|
|
@ -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)
|
||||
|
|
|
@ -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":
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user