extends Control


# Called when the node enters the scene tree for the first time.
func _ready():
	#for file_name in files_to_copy:
		#copy_file_if_not_exists(file_name)

	pass
#User Data copy if needed
var files_to_copy = [
	"MemberDatabase/memberData.json",
	"Boss/bossData.json"
]

var user_directory = OS.get_user_data_dir()


func copy_file_if_not_exists(file_name: String):
	var user_file_path = "user://" + file_name
	if not FileAccess.file_exists(user_file_path):
		var res_file_path = "res://" + file_name
		if FileAccess.file_exists(res_file_path):
			var file = FileAccess.open(res_file_path, FileAccess.READ)
			if file:
				var data = file.get_as_text()
				file.close()
				
				# Write to user:// directory
				var user_file = FileAccess.open(user_file_path, FileAccess.WRITE)
				if user_file:
					user_file.store_string(data)
					user_file.close()
					print("Copied ", file_name, " to user:// directory.")
				else:
					print("Failed to open destination file: ", user_file_path)
					user_file.get_open_error()
			else:
				print("Failed to open source file: ", res_file_path)
		else:
			print("Source file ", res_file_path, " not found.")
	else:
		print("File ", user_file_path, " already exists.")




# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	#Engine for calculating team values
	#Get total for each stat
	var totalDamagePerSec = Global.damagePerSecMember1 + Global.damagePerSecMember2 + Global.damagePerSecMember3 + Global.damagePerSecMember4 + Global.damagePerSecMember5
	var totalDamagePerClick = Global.damagePerClickMember1 + Global.damagePerClickMember2 + Global.damagePerClickMember3 + Global.damagePerClickMember4 + Global.damagePerClickMember5
	var totalDamageMultiplier = calc_largest_multiplier()
	
	Global.globalDamagePerSec = totalDamagePerSec
	Global.globalDamagePerClick = totalDamagePerClick
	Global.globalDamageMultiplier = totalDamageMultiplier

		#Get the current status of any screens needed
	#var teamScreen = get_node(Global.teamScreenPath)
	#teamScreen.visible = Global.teamScreenVisible
	#
	#var teamSelection = get_node(Global.teamSelectionPath)
	#teamSelection.visible = Global.teamSelectionVisible
	#
	#var bossScreen = get_node(Global.bossSelectionPath)
	#bossScreen.visible = Global.bossScreenVisible

func damageEngineCalc():

	pass

func calc_largest_multiplier():
	var greatest = Global.damageMultiplierMember1
	
	if  Global.damageMultiplierMember2 > greatest:
		greatest = Global.damageMultiplierMember2
	if Global.damageMultiplierMember3 > greatest:
		greatest = Global.damageMultiplierMember3
	if Global.damageMultiplierMember4 > greatest:
		greatest = Global.damageMultiplierMember4
	if Global.damageMultiplierMember5 > greatest:
		greatest = Global.damageMultiplierMember5
	return greatest
