#include "register_types.h"

#include "pingpong_ball.h"
#include "pingpong_paddle.h"
#include "pingpong_game.h"

#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

using namespace godot;

void initialize_pingpang_module(ModuleInitializationLevel p_level) {
    if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
        return;
    }
    // 注册所有游戏类
    GDREGISTER_CLASS(PingPongBall);
    GDREGISTER_CLASS(PingPongPaddle);
    GDREGISTER_CLASS(PingPongGame);
}

void uninitialize_pingpang_module(ModuleInitializationLevel p_level) {
    if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
        return;
    }
    // godot-cpp 在库卸载时自动清理类
}

// Godot 加载扩展的入口（dll 导出符号）
extern "C" {
GDExtensionBool GDE_EXPORT pingpang_library_init(
    GDExtensionInterfaceGetProcAddress p_get_proc_address,
    GDExtensionClassLibraryPtr p_library,
    GDExtensionInitialization *r_initialization
) {
    godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

    init_obj.register_initializer(initialize_pingpang_module);
    init_obj.register_terminator(uninitialize_pingpang_module);
    init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

    return init_obj.init();
}
}
