extends Node2D

var dead = false

func _ready():
    $VictoryCheckTimer.connect("timeout", victory_check)
    $"../../UILayer/UI/DefeatScreen".hide()
    $VictoryCheckTimer.start()

func are_slots_done() -> bool:
    for slot_array in $SlotArrays.get_children():
        for slot in slot_array.get_children():
            if slot.plant == null:
                return false
    return true

func victory_check():
    if $Plants.get_children().size() == 0:
        dead = true
        set_process(false)
        $"../../UILayer/UI/DefeatScreen".show()
        $"../../UILayer/UI/SpeedrunTimer".stop()
    if ($Waves.is_done() and $UFOs.get_children().size() == 0):# or are_slots_done():
        set_process(false)
        $"../../UILayer/UI/VictoryScreen".show()
        $"../../UILayer/UI/SpeedrunTimer".stop()
