diff --git a/modules/authority/game_state.cpp b/modules/authority/game_state.cpp index 8f0a1c5c..026b13eb 100644 --- a/modules/authority/game_state.cpp +++ b/modules/authority/game_state.cpp @@ -1,11 +1,25 @@ #include "game_state.h" #include "macros.h" +GameState *GameState::singleton_instance{ nullptr }; + void GameState::_bind_methods() { BIND_PROPERTY(Variant::STRING, locale_uid); BIND_PROPERTY(Variant::STRING, locale_entrance_path); } +GameState::GameState() { + self_type::singleton_instance = this; +} + +GameState::~GameState() { + self_type::singleton_instance = nullptr; +} + +GameState *GameState::get_singleton() { + return self_type::singleton_instance; +} + void GameState::set_locale_uid(String const &value) { this->locale_uid = value; } @@ -21,4 +35,3 @@ void GameState::set_locale_entrance_path(String const &value) { String GameState::get_locale_entrance_path() const { return this->locale_uid; } - diff --git a/modules/authority/game_state.h b/modules/authority/game_state.h index f1bac503..a818357d 100644 --- a/modules/authority/game_state.h +++ b/modules/authority/game_state.h @@ -1,21 +1,26 @@ #ifndef GAME_STATE_H #define GAME_STATE_H -#include "core/object/object.h" #include "core/object/class_db.h" +#include "core/object/object.h" class GameState : public Object { GDCLASS(GameState, Object); static void _bind_methods(); + static GameState *singleton_instance; + public: + GameState(); + virtual ~GameState(); static GameState *get_singleton(); void set_locale_uid(String const &value); String get_locale_uid() const; void set_locale_entrance_path(String const &value); String get_locale_entrance_path() const; + private: - String locale_uid{""}; - String locale_entrance_path{""}; + String locale_uid{ "" }; + String locale_entrance_path{ "" }; }; #endif // !GAME_STATE_H diff --git a/modules/authority/locale_marker.cpp b/modules/authority/locale_marker.cpp index 9cd169b8..0ea4e2b8 100644 --- a/modules/authority/locale_marker.cpp +++ b/modules/authority/locale_marker.cpp @@ -9,14 +9,15 @@ void LocaleMarker::_bind_methods() { } void LocaleMarker::_notification(int what) { - if(Engine::get_singleton()->is_editor_hint()) { + if (Engine::get_singleton()->is_editor_hint()) { return; } - switch(what) { - default: return; - case NOTIFICATION_READY: - this->ready(); - return; + switch (what) { + default: + return; + case NOTIFICATION_READY: + this->ready(); + return; } } @@ -25,10 +26,11 @@ void LocaleMarker::ready() { } void LocaleMarker::on_input_event(Node *camera, Ref event, Vector3 position, Vector3 normal, int shape_ind) { - Ref clicked{event}; - if(clicked.is_valid() && clicked->get_button_index() == MouseButton::LEFT) { + Ref clicked{ event }; + if (clicked.is_valid() && clicked->get_button_index() == MouseButton::LEFT) { + GameState::get_singleton()->set_locale_uid(this->locale_scene); GameState::get_singleton()->set_locale_entrance_path(this->entrance_path); - GameState::get_singleton()->set_locale_uid(locale_scene); + get_tree()->change_scene_to_file(this->locale_scene); } } diff --git a/modules/authority/locale_marker.h b/modules/authority/locale_marker.h index 1020df96..15295510 100644 --- a/modules/authority/locale_marker.h +++ b/modules/authority/locale_marker.h @@ -11,15 +11,17 @@ class LocaleMarker : public Area3D { void _notification(int what); void ready(); void on_input_event(Node *camera, Ref event, Vector3 position, Vector3 normal, int shape_ind); + public: void set_locale_scene(String const &value); String get_locale_scene() const; void set_entrance_path(String const &value); String get_entrance_path() const; + private: - String locale_scene{"res://"}; - String entrance_path{"%"}; - String const sig_input_event{"input_event"}; + String locale_scene{ "res://" }; + String entrance_path{ "%" }; + String const sig_input_event{ "input_event" }; }; #endif // !LOCALE_MARKER_H diff --git a/modules/authority/register_types.cpp b/modules/authority/register_types.cpp index 4a3fe411..a1486643 100644 --- a/modules/authority/register_types.cpp +++ b/modules/authority/register_types.cpp @@ -4,7 +4,7 @@ #include "core/config/engine.h" #include "core/object/class_db.h" -GameState *game_state{nullptr}; +GameState *game_state{ nullptr }; void initialize_authority_module(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { @@ -20,7 +20,7 @@ void uninitialize_authority_module(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { return; } - if(game_state) { + if (game_state) { memdelete(game_state); } }