class_name ChapterArea
extends Area3D


@export var chapter_index: int = 0
@export var override_spawn_id: bool = true
@export var spawn_id: StringName = &""
@export var display_chapter: bool = true
@export var do_save: bool = true


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	body_entered.connect(_on_body_entered)


func set_chapter() -> void:
	if chapter_index > GameGlobals.chapter_index:
		GameGlobals.set_chapter_index(chapter_index)

		if override_spawn_id:
			GameGlobals.set_spawn_id(spawn_id)

		if do_save:
			SaveManager.save_game()


func _on_body_entered(body: Node3D) -> void:
	if body == GameGlobals.get_player():
		set_chapter()
