extends Node

var destroyedShips: int = 0

var currentDelay: float = 1.0
var player: Player = null
var currentWave: int = 0
var enemyCount: int = 0
var touchscreen: bool = false

var UPGRADES: Array[Upgrade] = [
	TimeGhostUpgrade.new(),
	SpeedUpgrade.new(),
	SelfHealUpgrade.new(),
	MinigunUpgrade.new(),
	ShotgunUpgrade.new(),
	RailgunUpgrade.new(),
	Heal50Upgrade.new(),
	Heal100Upgrade.new(),
	HealthUpgrade.new(),
	#DashUpgrade.new(),
	#StrafeUpgrade.new(),
	#DamageUpgrade.new()
]

var currentUpgrades: Array[Upgrade] = UPGRADES

signal waveComplete

func _ready() -> void:
	process_mode = Node.PROCESS_MODE_ALWAYS
	reset()

func _physics_process(delta: float) -> void:
	if Input.is_action_just_pressed("fullscreen"):
		if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
		elif DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_WINDOWED:
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)

func setPlayer(_player: Player):
	player = _player

func getPlayer() -> Player:
	return player

func reset():
	currentDelay = 1.0
	currentWave = 0
	enemyCount = 0
	destroyedShips = 0
	currentUpgrades = UPGRADES
	touchscreen = false


#func nextWave():
	#currentWave += 1
	#enemyCount = 0
	#waveComplete.emit()

func enemyDestroyed():
	destroyedShips += 1
	enemyCount -= 1
	if enemyCount <= 0:
		await get_tree().create_timer(1).timeout
		waveComplete.emit()

func getUpgrades() -> Array[Upgrade]:
	return currentUpgrades

func getUpgrade(upgrade: int):
	return currentUpgrades[upgrade]

func removeUpgrade(upgrade: int):
	currentUpgrades.pop_at(upgrade)

func removeSpeedUPgrade():
	for i in currentUpgrades:
		if i is SpeedUpgrade:
			currentUpgrades.erase(i)
