From 2fedbb07b3305899f19a838c23e60a13eed9d25e Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 4 Feb 2024 22:33:07 +0100 Subject: [PATCH] feat: added get_default_entrance --- src/level.cpp | 16 +++++++++++++--- src/level.hpp | 17 ++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/level.cpp b/src/level.cpp index 1a8886e..efd3bd1 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -1,20 +1,30 @@ #include "level.hpp" #include "entrance.hpp" +#include "godot_cpp/variant/transform3d.hpp" #include "godot_cpp/variant/utility_functions.hpp" namespace godot { void Level::_bind_methods() {} -Transform3D Level::get_entrance(String const &entranceName) { - if (entrances.has(entranceName)) { +Transform3D Level::get_entrance(String const& entranceName) const { + if (entranceName.is_empty()) { + return this->get_global_transform(); + } else if (entrances.has(entranceName)) { Node3D* entrance = Object::cast_to(this->entrances[entranceName]); return entrance->get_global_transform(); } else { - return this->get_global_transform(); + return Transform3D(); } } +String Level::get_default_entrance() const { + if (entrances.is_empty()) + return ""; + else + return entrances.keys()[0]; +} + void Level::add_entrance(Entrance* entrance) { String key = entrance->get_name(); if (this->entrances.has(key)) diff --git a/src/level.hpp b/src/level.hpp index b5b5eb0..7e7d7fe 100644 --- a/src/level.hpp +++ b/src/level.hpp @@ -12,13 +12,16 @@ class Entrance; class Level : public Node3D { GDCLASS(Level, Node3D) static void _bind_methods(); + protected: Dictionary entrances{}; -public: - Transform3D get_entrance(String const &entranceName); - void add_entrance(Entrance *entrance); - void remove_entrance(Entrance *entrance); -}; -} -#endif // !LEVEL_HPP +public: + Transform3D get_entrance(String const& entranceName) const; + String get_default_entrance() const; + void add_entrance(Entrance* entrance); + void remove_entrance(Entrance* entrance); +}; +} // namespace godot + +#endif // !LEVEL_HPP