extends RoomState


func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
	print("entering room")
	room.player = _instantiate_player()
	assert(room.player != null, "player is null")
	room.camera.global_position = room.config.camera_position
	
	finished.emit(PLAYING)
	return


func _instantiate_player() -> Player:
	var p: Player = room.player_scene.instantiate()
	room.add_child(p)
	if room.initial_spawn != Vector2i.ZERO:
		p.global_position = room.initial_spawn
	else:
		assert(
			room.config.initial_spawn != Vector2i.ZERO,
			"invalid player initial spawn provided"
		)
		p.global_position = room.config.initial_spawn
	
	return p
