#include "game_ui.hpp"
#include "godot_cpp/classes/label.hpp"
#include "godot_cpp/variant/utility_functions.hpp"
#include "rally_rush_game_mode.hpp"
#include "utils/game_root.hpp"
#include "utils/godot_macros.h"

namespace godot {
void GameUI::_bind_methods() {
#define CLASSNAME GameUI
}

void GameUI::_enter_tree() { GDGAMEONLY();
    Ref<RallyRushGameMode> game_mode{GameRoot3D::get_singleton()->get_game_mode()};
    game_mode->connect("key_found", callable_mp(this, &GameUI::on_key_found));
    game_mode->connect("all_keys_found", callable_mp(this, &GameUI::on_all_keys_found));
    this->debug_info_label = this->get_node<Label>("DebugInfo");
    if(this->debug_info_label == nullptr)
        UtilityFunctions::push_error("failed to find debuginfo");
}

void GameUI::append_debug_info(String string) {
    String text = this->debug_info_label->get_text();
    this->debug_info_label->set_text(string + "\n" + text);
}

void GameUI::on_key_found(int total_found) {
    this->append_debug_info(String("Total keys: ") + String::num(total_found));
}

void GameUI::on_all_keys_found() {
    this->append_debug_info(String("all keys found!!"));
}
}
