extends Control

var game_mode
var word_select
var main_buttons
var fade
var word_select_button = preload("res://scenes/objects/ui/word_select_button.tscn")

func check_text_files(path):
	var dir = DirAccess.open(path)
	if dir:
		dir.list_dir_begin()
		var file_name = dir.get_next()
		while file_name != "":
			if not dir.current_is_dir():
				var set_name = file_name.trim_suffix(".txt").capitalize()
				var new_select_button = word_select_button.instantiate()
				new_select_button.text = set_name
				#print(set_name)
				word_select.add_child(new_select_button)
				
				
			file_name = dir.get_next()
	else:
		print("An error occurred when trying to access the path.")

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	game_mode = null
	fade = self.get_node("Fade")
	fade.visible = true
	main_buttons = self.get_node("MainButtons")
	word_select = self.get_node("WordSelectScroll").get_node("WordSelect")
	check_text_files("res://gameplay/word_sets")
	
	var tween := create_tween()
	tween.parallel().tween_property(fade, "modulate:a", 0, 0.5).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

func open_word_menu():
	pass

func _on_comet_pressed() -> void:
	game_mode = "comet"
	self.get_node("ButtonPress").play()
	main_buttons.visible = false
	word_select.visible = true

func _on_cascade_pressed() -> void:
	game_mode = "cascade"
	self.get_node("ButtonPress").play()
	main_buttons.visible = false
	word_select.visible = true
