feature/cleanup #33
54
src/Main.cpp
54
src/Main.cpp
@ -2,41 +2,41 @@
|
|||||||
|
|
||||||
#include <SceneTree.hpp>
|
#include <SceneTree.hpp>
|
||||||
|
|
||||||
void alai::main::Main::_register_methods()
|
void alai::Main::_register_methods()
|
||||||
{
|
{
|
||||||
godot::register_method("_ready", &Main::_ready);
|
godot::register_method("_ready", &Main::_ready);
|
||||||
godot::register_method("_physics_process", &Main::_physics_process);
|
godot::register_method("_physics_process", &Main::_physics_process);
|
||||||
godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded);
|
godot::register_method("_on_monitor_loaded", &Main::_on_monitor_loaded);
|
||||||
godot::register_property<Main, godot::String>("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(main::game_version.c_str()));
|
godot::register_property<Main, godot::String>("game_version", &Main::set_game_version, &Main::get_game_version, godot::String(alai::game_version.c_str()));
|
||||||
godot::register_property<Main, godot::Ref<godot::PackedScene>>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene"));
|
godot::register_property<Main, godot::Ref<godot::PackedScene>>("level", &Main::set_level, &Main::get_level, NULL, GODOT_METHOD_RPC_MODE_DISABLED, GODOT_PROPERTY_USAGE_DEFAULT, GODOT_PROPERTY_HINT_RESOURCE_TYPE, godot::String("PackedScene"));
|
||||||
godot::register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, main::full_screen);
|
godot::register_property<Main, bool>("full_screen", &Main::set_full_screen, &Main::get_full_screen, alai::full_screen);
|
||||||
godot::register_property<Main, godot::Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, main::window_size);
|
godot::register_property<Main, godot::Vector2>("window_size", &Main::set_window_size, &Main::get_window_size, alai::window_size);
|
||||||
godot::register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, main::launch_screen);
|
godot::register_property<Main, int8_t>("launch_screen", &Main::set_launch_screen, &Main::get_launch_screen, alai::launch_screen);
|
||||||
godot::register_signal<Main>("monitor_loaded");
|
godot::register_signal<Main>("monitor_loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
alai::main::Main::Main()
|
alai::Main::Main()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
alai::main::Main::~Main()
|
alai::Main::~Main()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::_init()
|
void alai::Main::_init()
|
||||||
{
|
{
|
||||||
_os = godot::OS::get_singleton();
|
_os = godot::OS::get_singleton();
|
||||||
_input = godot::Input::get_singleton();
|
_input = godot::Input::get_singleton();
|
||||||
_project_settings = godot::ProjectSettings::get_singleton();
|
_project_settings = godot::ProjectSettings::get_singleton();
|
||||||
_resource_loader = godot::ResourceLoader::get_singleton();
|
_resource_loader = godot::ResourceLoader::get_singleton();
|
||||||
|
|
||||||
game_version = godot::String(main::game_version.c_str());
|
game_version = godot::String(alai::game_version.c_str());
|
||||||
full_screen = main::full_screen;
|
full_screen = alai::full_screen;
|
||||||
window_size = main::window_size;
|
window_size = alai::window_size;
|
||||||
launch_screen = main::launch_screen;
|
launch_screen = alai::launch_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::_ready()
|
void alai::Main::_ready()
|
||||||
{
|
{
|
||||||
auto success = _project_settings->load_resource_pack("monitor.pck");
|
auto success = _project_settings->load_resource_pack("monitor.pck");
|
||||||
if (success)
|
if (success)
|
||||||
@ -84,7 +84,7 @@ void alai::main::Main::_ready()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::_on_monitor_loaded()
|
void alai::Main::_on_monitor_loaded()
|
||||||
{
|
{
|
||||||
if (level != nullptr)
|
if (level != nullptr)
|
||||||
{
|
{
|
||||||
@ -94,7 +94,7 @@ void alai::main::Main::_on_monitor_loaded()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::load_monitor()
|
void alai::Main::load_monitor()
|
||||||
{
|
{
|
||||||
godot::Ref<godot::PackedScene> monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn");
|
godot::Ref<godot::PackedScene> monitor_scene = _resource_loader->load("res://monitor/Monitor.tscn");
|
||||||
add_child(monitor_scene->instance());
|
add_child(monitor_scene->instance());
|
||||||
@ -103,7 +103,7 @@ void alai::main::Main::load_monitor()
|
|||||||
get_tree()->set_pause(true);
|
get_tree()->set_pause(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
godot::Node *alai::main::Main::load_level()
|
godot::Node *alai::Main::load_level()
|
||||||
{
|
{
|
||||||
if (level != nullptr)
|
if (level != nullptr)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ godot::Node *alai::main::Main::load_level()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::_physics_process(float delta)
|
void alai::Main::_physics_process(float delta)
|
||||||
{
|
{
|
||||||
if (_input->is_action_just_pressed("ui_cancel"))
|
if (_input->is_action_just_pressed("ui_cancel"))
|
||||||
{
|
{
|
||||||
@ -124,52 +124,52 @@ void alai::main::Main::_physics_process(float delta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::set_level(godot::Ref<godot::PackedScene> level)
|
void alai::Main::set_level(godot::Ref<godot::PackedScene> level)
|
||||||
{
|
{
|
||||||
this->level = level;
|
this->level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
godot::Ref<godot::PackedScene> alai::main::Main::get_level()
|
godot::Ref<godot::PackedScene> alai::Main::get_level()
|
||||||
{
|
{
|
||||||
return this->level;
|
return this->level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::set_game_version(godot::String game_version)
|
void alai::Main::set_game_version(godot::String game_version)
|
||||||
{
|
{
|
||||||
this->game_version = game_version;
|
this->game_version = game_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
godot::String alai::main::Main::get_game_version()
|
godot::String alai::Main::get_game_version()
|
||||||
{
|
{
|
||||||
return this->game_version;
|
return this->game_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::set_full_screen(bool full_screen)
|
void alai::Main::set_full_screen(bool full_screen)
|
||||||
{
|
{
|
||||||
this->full_screen = full_screen;
|
this->full_screen = full_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alai::main::Main::get_full_screen()
|
bool alai::Main::get_full_screen()
|
||||||
{
|
{
|
||||||
return this->full_screen;
|
return this->full_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::set_window_size(godot::Vector2 window_size)
|
void alai::Main::set_window_size(godot::Vector2 window_size)
|
||||||
{
|
{
|
||||||
this-> window_size = window_size;
|
this-> window_size = window_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
godot::Vector2 alai::main::Main::get_window_size()
|
godot::Vector2 alai::Main::get_window_size()
|
||||||
{
|
{
|
||||||
return this->window_size;
|
return this->window_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alai::main::Main::set_launch_screen(int8_t launch_screen)
|
void alai::Main::set_launch_screen(int8_t launch_screen)
|
||||||
{
|
{
|
||||||
this->launch_screen = launch_screen;
|
this->launch_screen = launch_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t alai::main::Main::get_launch_screen()
|
int8_t alai::Main::get_launch_screen()
|
||||||
{
|
{
|
||||||
if (this->launch_screen == -1)
|
if (this->launch_screen == -1)
|
||||||
{
|
{
|
||||||
|
381
src/Main.h
381
src/Main.h
@ -19,224 +19,217 @@
|
|||||||
namespace alai
|
namespace alai
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief This namespace houses some global variables and the main class.
|
* @brief The default value for the game version.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
namespace main
|
const std::string game_version = "0.1.0";
|
||||||
|
/**
|
||||||
|
* @brief The default value for if the game should start in full screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const bool full_screen = false;
|
||||||
|
/**
|
||||||
|
* @brief The default resolution for the game window.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const godot::Vector2 window_size = godot::Vector2(1280, 720);
|
||||||
|
/**
|
||||||
|
* @brief The default screen the the game should open on.
|
||||||
|
*
|
||||||
|
* @details -1 opens it on the currently active screen. And 0 and above are the screens to use.
|
||||||
|
*/
|
||||||
|
const int8_t launch_screen = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class controls the Main node.
|
||||||
|
*
|
||||||
|
* @details The main node is responsible for controlling the window and the game itself is a child of it.
|
||||||
|
*/
|
||||||
|
class Main : public godot::Node
|
||||||
{
|
{
|
||||||
/**
|
GODOT_CLASS(Main, godot::Node)
|
||||||
* @brief The default value for the game version.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const std::string game_version = "0.1.0";
|
|
||||||
/**
|
|
||||||
* @brief The default value for if the game should start in full screen.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const bool full_screen = false;
|
|
||||||
/**
|
|
||||||
* @brief The default resolution for the game window.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const godot::Vector2 window_size = godot::Vector2(1280, 720);
|
|
||||||
/**
|
|
||||||
* @brief The default screen the the game should open on.
|
|
||||||
*
|
|
||||||
* @details -1 opens it on the currently active screen. And 0 and above are the screens to use.
|
|
||||||
*/
|
|
||||||
const int8_t launch_screen = -1;
|
|
||||||
|
|
||||||
/**
|
private:
|
||||||
* @brief This class controls the Main node.
|
/**
|
||||||
*
|
* @brief OS singleton.
|
||||||
* @details The main node is responsible for controlling the window and the game itself is a child of it.
|
*
|
||||||
*/
|
*/
|
||||||
class Main : public godot::Node
|
godot::OS *_os;
|
||||||
{
|
/**
|
||||||
GODOT_CLASS(Main, godot::Node)
|
* @brief Input singleton.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
godot::Input *_input;
|
||||||
|
/**
|
||||||
|
* @brief ProjectSettings singleton.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
godot::ProjectSettings *_project_settings;
|
||||||
|
/**
|
||||||
|
* @brief ResourceLoader singleton.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
godot::ResourceLoader *_resource_loader;
|
||||||
|
|
||||||
private:
|
/**
|
||||||
/**
|
* @brief The first level to load
|
||||||
* @brief OS singleton.
|
*
|
||||||
*
|
*/
|
||||||
*/
|
godot::Ref<godot::PackedScene> level;
|
||||||
godot::OS *_os;
|
/**
|
||||||
/**
|
* @brief The current version of the game.
|
||||||
* @brief Input singleton.
|
*
|
||||||
*
|
*/
|
||||||
*/
|
godot::String game_version;
|
||||||
godot::Input *_input;
|
/**
|
||||||
/**
|
* @brief If the window is full screen or not.
|
||||||
* @brief ProjectSettings singleton.
|
*
|
||||||
*
|
*/
|
||||||
*/
|
bool full_screen;
|
||||||
godot::ProjectSettings *_project_settings;
|
/**
|
||||||
/**
|
* @brief The size of the window.
|
||||||
* @brief ResourceLoader singleton.
|
*
|
||||||
*
|
*/
|
||||||
*/
|
godot::Vector2 window_size;
|
||||||
godot::ResourceLoader *_resource_loader;
|
/**
|
||||||
|
* @brief The screen to launch the game on.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int8_t launch_screen;
|
||||||
|
|
||||||
/**
|
public:
|
||||||
* @brief The first level to load
|
/**
|
||||||
*
|
* @brief This method registers classes with Godot.
|
||||||
*/
|
*
|
||||||
godot::Ref<godot::PackedScene> level;
|
* @details This method registers methods, properties, and signals with the Godot engine.
|
||||||
/**
|
*/
|
||||||
* @brief The current version of the game.
|
static void _register_methods();
|
||||||
*
|
|
||||||
*/
|
|
||||||
godot::String game_version;
|
|
||||||
/**
|
|
||||||
* @brief If the window is full screen or not.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
bool full_screen;
|
|
||||||
/**
|
|
||||||
* @brief The size of the window.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
godot::Vector2 window_size;
|
|
||||||
/**
|
|
||||||
* @brief The screen to launch the game on.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int8_t launch_screen;
|
|
||||||
|
|
||||||
public:
|
/**
|
||||||
/**
|
* @brief Construct a new Main object.
|
||||||
* @brief This method registers classes with Godot.
|
*
|
||||||
*
|
*/
|
||||||
* @details This method registers methods, properties, and signals with the Godot engine.
|
Main();
|
||||||
*/
|
|
||||||
static void _register_methods();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Main object.
|
* @brief Destroy the Main object.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Main();
|
~Main();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Main object.
|
* @brief Initialize the class from Godot.
|
||||||
*
|
*
|
||||||
*/
|
* @details This method is called just once when the Godot engine connects to the instance of the class.
|
||||||
~Main();
|
*/
|
||||||
|
void _init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the class from Godot.
|
* @brief Code to be run when ready.
|
||||||
*
|
*
|
||||||
* @details This method is called just once when the Godot engine connects to the instance of the class.
|
* @details This method is run when all the children of this node are ready.
|
||||||
*/
|
*/
|
||||||
void _init();
|
void _ready();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Code to be run when ready.
|
* @brief This class handles the physics processing.
|
||||||
*
|
*
|
||||||
* @details This method is run when all the children of this node are ready.
|
* @details Every delta time, this function is called to check for input and update positioning.
|
||||||
*/
|
*
|
||||||
void _ready();
|
* @param[in] delta The difference in time that passed since the last call to this method.
|
||||||
|
*/
|
||||||
|
void _physics_process(float delta);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class handles the physics processing.
|
* @brief Set the level object.
|
||||||
*
|
*
|
||||||
* @details Every delta time, this function is called to check for input and update positioning.
|
* @param[in] level The new level to load when starting.
|
||||||
*
|
*/
|
||||||
* @param[in] delta The difference in time that passed since the last call to this method.
|
void set_level(godot::Ref<godot::PackedScene> level);
|
||||||
*/
|
|
||||||
void _physics_process(float delta);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the level object.
|
* @brief Get the level object.
|
||||||
*
|
*
|
||||||
* @param[in] level The new level to load when starting.
|
* @return Ref<PackedScene> The level scene to load.
|
||||||
*/
|
*/
|
||||||
void set_level(godot::Ref<godot::PackedScene> level);
|
godot::Ref<godot::PackedScene> get_level();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the level object.
|
* @brief Set the game version object.
|
||||||
*
|
*
|
||||||
* @return Ref<PackedScene> The level scene to load.
|
* @param[in] game_version The new version fo the game.
|
||||||
*/
|
*/
|
||||||
godot::Ref<godot::PackedScene> get_level();
|
void set_game_version(godot::String game_version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the game version object.
|
* @brief Get the game version object.
|
||||||
*
|
*
|
||||||
* @param[in] game_version The new version fo the game.
|
* @return String The current version of the game.
|
||||||
*/
|
*/
|
||||||
void set_game_version(godot::String game_version);
|
godot::String get_game_version();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the game version object.
|
* @brief Set the full screen object.
|
||||||
*
|
*
|
||||||
* @return String The current version of the game.
|
* @param[in] full_screen The new full screen state.
|
||||||
*/
|
*/
|
||||||
godot::String get_game_version();
|
void set_full_screen(bool full_screen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the full screen object.
|
* @brief Get the full screen object.
|
||||||
*
|
*
|
||||||
* @param[in] full_screen The new full screen state.
|
* @return true If full screen.
|
||||||
*/
|
* @return false If not full screen.
|
||||||
void set_full_screen(bool full_screen);
|
*/
|
||||||
|
bool get_full_screen();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the full screen object.
|
* @brief Set the window size object.
|
||||||
*
|
*
|
||||||
* @return true If full screen.
|
* @param[in] window_size The new window size.
|
||||||
* @return false If not full screen.
|
*/
|
||||||
*/
|
void set_window_size(godot::Vector2 window_size);
|
||||||
bool get_full_screen();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the window size object.
|
* @brief Get the window size object.
|
||||||
*
|
*
|
||||||
* @param[in] window_size The new window size.
|
* @return Vector2 The window size.
|
||||||
*/
|
*/
|
||||||
void set_window_size(godot::Vector2 window_size);
|
godot::Vector2 get_window_size();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the window size object.
|
* @brief Set the launch screen object.
|
||||||
*
|
*
|
||||||
* @return Vector2 The window size.
|
* @param[in] launch_screen The launch screen to use.
|
||||||
*/
|
*/
|
||||||
godot::Vector2 get_window_size();
|
void set_launch_screen(int8_t launch_screen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the launch screen object.
|
* @brief Get the launch screen object.
|
||||||
*
|
*
|
||||||
* @param[in] launch_screen The launch screen to use.
|
* @return int8_t The launch screen.
|
||||||
*/
|
*/
|
||||||
void set_launch_screen(int8_t launch_screen);
|
int8_t get_launch_screen();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the launch screen object.
|
* @brief Called when the monitor finishes loading.
|
||||||
*
|
*
|
||||||
* @return int8_t The launch screen.
|
*/
|
||||||
*/
|
void _on_monitor_loaded();
|
||||||
int8_t get_launch_screen();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when the monitor finishes loading.
|
* @brief Loads the monitor and adds it to the scene.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _on_monitor_loaded();
|
void load_monitor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the monitor and adds it to the scene.
|
* @brief Loads the selected level.
|
||||||
*
|
*
|
||||||
*/
|
* @return Node* The level node which we will later add the monitor to.
|
||||||
void load_monitor();
|
*/
|
||||||
|
Node *load_level();
|
||||||
/**
|
};
|
||||||
* @brief Loads the selected level.
|
|
||||||
*
|
|
||||||
* @return Node* The level node which we will later add the monitor to.
|
|
||||||
*/
|
|
||||||
Node *load_level();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,7 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
|||||||
|
|
||||||
godot::register_class<alai::StateMachine>();
|
godot::register_class<alai::StateMachine>();
|
||||||
godot::register_class<alai::State>();
|
godot::register_class<alai::State>();
|
||||||
godot::register_class<alai::main::Main>();
|
godot::register_class<alai::Main>();
|
||||||
godot::register_class<alai::CameraLimit>();
|
godot::register_class<alai::CameraLimit>();
|
||||||
godot::register_class<alai::player::Player>();
|
godot::register_class<alai::player::Player>();
|
||||||
godot::register_class<alai::player::PlayerIdle>();
|
godot::register_class<alai::player::PlayerIdle>();
|
||||||
|
Loading…
Reference in New Issue
Block a user