immersive-home/content/system/house/house.gd

76 lines
1.5 KiB
GDScript3
Raw Normal View History

2023-12-20 02:54:22 +02:00
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):
var room = find_room(room_name)
if room == editing_room:
return
2023-12-20 02:54:22 +02:00
if editing_room != null:
editing_room.editable = false
editing_room = null
if room != null:
room.editable = true
editing_room = room
2023-12-20 02:54:22 +02:00
func is_editiong(room_name):
return editing_room != null && editing_room.name == room_name
2023-12-20 02:54:22 +02:00
func find_room(room_name):
2023-12-20 02:54:22 +02:00
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_child(level)
2023-12-20 02:54:22 +02:00
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