feat: first game code

This commit is contained in:
Sara 2025-06-23 19:48:52 +02:00
parent f6e6cf9e55
commit 1828ebbe21
4 changed files with 119 additions and 0 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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<InputEvent> event, Vector3 position, Vector3 normal, int shape_ind) {
Ref<InputEventMouseButton> 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;
}

View file

@ -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<InputEvent> 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