From 1828ebbe21514400c682e4e70d1624da79daa2d8 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 23 Jun 2025 19:48:52 +0200 Subject: [PATCH] feat: first game code --- modules/authority/game_state.cpp | 24 ++++++++++++++ modules/authority/game_state.h | 21 +++++++++++++ modules/authority/locale_marker.cpp | 49 +++++++++++++++++++++++++++++ modules/authority/locale_marker.h | 25 +++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 modules/authority/game_state.cpp create mode 100644 modules/authority/game_state.h create mode 100644 modules/authority/locale_marker.cpp create mode 100644 modules/authority/locale_marker.h diff --git a/modules/authority/game_state.cpp b/modules/authority/game_state.cpp new file mode 100644 index 00000000..8f0a1c5c --- /dev/null +++ b/modules/authority/game_state.cpp @@ -0,0 +1,24 @@ +#include "game_state.h" +#include "macros.h" + +void GameState::_bind_methods() { + BIND_PROPERTY(Variant::STRING, locale_uid); + BIND_PROPERTY(Variant::STRING, locale_entrance_path); +} + +void GameState::set_locale_uid(String const &value) { + this->locale_uid = value; +} + +String GameState::get_locale_uid() const { + return this->locale_uid; +} + +void GameState::set_locale_entrance_path(String const &value) { + this->locale_uid = 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 new file mode 100644 index 00000000..f1bac503 --- /dev/null +++ b/modules/authority/game_state.h @@ -0,0 +1,21 @@ +#ifndef GAME_STATE_H +#define GAME_STATE_H + +#include "core/object/object.h" +#include "core/object/class_db.h" + +class GameState : public Object { + GDCLASS(GameState, Object); + static void _bind_methods(); +public: + 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{""}; +}; + +#endif // !GAME_STATE_H diff --git a/modules/authority/locale_marker.cpp b/modules/authority/locale_marker.cpp new file mode 100644 index 00000000..9cd169b8 --- /dev/null +++ b/modules/authority/locale_marker.cpp @@ -0,0 +1,49 @@ +#include "locale_marker.h" +#include "authority/game_state.h" +#include "core/config/engine.h" +#include "core/input/input_enums.h" +#include "macros.h" + +void LocaleMarker::_bind_methods() { + BIND_HPROPERTY(Variant::STRING, locale_scene, PROPERTY_HINT_FILE, "*.tscn,*.scn"); +} + +void LocaleMarker::_notification(int what) { + if(Engine::get_singleton()->is_editor_hint()) { + return; + } + switch(what) { + default: return; + case NOTIFICATION_READY: + this->ready(); + return; + } +} + +void LocaleMarker::ready() { + this->connect(this->sig_input_event, callable_mp(this, &self_type::on_input_event)); +} + +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) { + GameState::get_singleton()->set_locale_entrance_path(this->entrance_path); + GameState::get_singleton()->set_locale_uid(locale_scene); + } +} + +void LocaleMarker::set_locale_scene(String const &path) { + this->locale_scene = path; +} + +String LocaleMarker::get_locale_scene() const { + return this->locale_scene; +} + +void LocaleMarker::set_entrance_path(String const &node_path) { + this->entrance_path = node_path; +} + +String LocaleMarker::get_entrance_path() const { + return this->entrance_path; +} diff --git a/modules/authority/locale_marker.h b/modules/authority/locale_marker.h new file mode 100644 index 00000000..1020df96 --- /dev/null +++ b/modules/authority/locale_marker.h @@ -0,0 +1,25 @@ +#ifndef LOCALE_MARKER_H +#define LOCALE_MARKER_H + +#include "core/input/input_event.h" +#include "scene/3d/physics/area_3d.h" +#include "scene/main/node.h" + +class LocaleMarker : public Area3D { + GDCLASS(LocaleMarker, Area3D); + static void _bind_methods(); + 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"}; +}; + +#endif // !LOCALE_MARKER_H