## world.gd
# Main world node script. Sets up the map, player, and level on scene ready.
extends Node


# Path to the Player scene to instance.
const PLAYER_SCENE_PATH: String = "res://scenes/actors/player.tscn"
# Reference to the TileMapLayer node for rendering the map.
var map_layer: TileMapLayer
# Reference to the Player node.
var player: Player
# Map generation settings (size, room count, etc.).
var settings: MapSettings = MapSettings.new()

# Called when the node is added to the scene tree.
# Initializes references and triggers map setup.
func _ready() -> void:
	map_layer = $MapLayer
	# Do not assume Player is already in the scene tree; instance it after map generation.
	call_deferred("_initialize_map")

# Initializes the map and level using LevelManager.
# Ensures the map is generated and the player is placed.
func _initialize_map() -> void:
	# Instance the Player after the map is generated and add to the scene tree.
	var player_scene: PackedScene = load(PLAYER_SCENE_PATH)
	player = player_scene.instantiate() as Player
	add_child(player)
	LevelManager.initialize(settings, map_layer, player)
	TurnManager.start_turns()
