#include "register_types.h"

#include "FirstPersonPlayer.h"
#include "Lobby.h"
#include "Main.h"
#include "MainMenu.h"
#include "NetworkInterface.h"
#include "Player.h"
#include "Server.h"
#include "SpringArmPivot.h"
#include "World.h"

#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

using namespace godot;

static void RegisterClasses() {
	ClassDB::register_class<blitz::Player>();
	ClassDB::register_class<blitz::SpringArmPivot>();
	ClassDB::register_class<blitz::FirstPersonPlayer>();
	ClassDB::register_class<blitz::MainMenu>();
	ClassDB::register_class<blitz::Lobby>();
	ClassDB::register_class<blitz::World>();
	ClassDB::register_class<blitz::Main>();
	ClassDB::register_class<blitz::NetworkInterface>();
	ClassDB::register_class<blitz::Server>();
}

void initialize_example_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}

	RegisterClasses();
}

void uninitialize_example_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
}

extern "C" GDExtensionBool GDE_EXPORT library_init(GDExtensionInterfaceGetProcAddress p_get_proc,
	const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization* r_initialization) {
	godot::GDExtensionBinding::InitObject init_obj(p_get_proc, p_library, r_initialization);

	init_obj.register_initializer(initialize_example_module);
	init_obj.register_terminator(uninitialize_example_module);
	init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

	return init_obj.init();
}
