extends Node


func goto_room(previous_room: Room, waypoint: RemoteWaypoint, config: RoomConfig = null) -> void:
	print("changing rooms")
	
	# for signal
	var prev_name: StringName
	var next_name: StringName
	
	prev_name = previous_room.name
	
	# wait until previous room is freed
	await previous_room.tree_exited
	
	# instantiate next room and set room variables
	var next_room: Room = waypoint.to_scene.instantiate()
	next_name = next_room.name
	next_room.initial_spawn = waypoint.spawn_coordinates
	if config: next_room.config = config
	get_tree().root.add_child(next_room)
	
	# notify event bus
	EventBus.room_changed.emit(prev_name, next_name, waypoint)
