feat: added get_default_entrance

main
Sara 2024-02-04 22:33:07 +01:00
parent 4312d6f934
commit 2fedbb07b3
2 changed files with 23 additions and 10 deletions

View File

@ -1,20 +1,30 @@
#include "level.hpp" #include "level.hpp"
#include "entrance.hpp" #include "entrance.hpp"
#include "godot_cpp/variant/transform3d.hpp"
#include "godot_cpp/variant/utility_functions.hpp" #include "godot_cpp/variant/utility_functions.hpp"
namespace godot { namespace godot {
void Level::_bind_methods() {} void Level::_bind_methods() {}
Transform3D Level::get_entrance(String const &entranceName) { Transform3D Level::get_entrance(String const& entranceName) const {
if (entrances.has(entranceName)) { if (entranceName.is_empty()) {
return this->get_global_transform();
} else if (entrances.has(entranceName)) {
Node3D* entrance = Node3D* entrance =
Object::cast_to<Node3D>(this->entrances[entranceName]); Object::cast_to<Node3D>(this->entrances[entranceName]);
return entrance->get_global_transform(); return entrance->get_global_transform();
} else { } 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) { void Level::add_entrance(Entrance* entrance) {
String key = entrance->get_name(); String key = entrance->get_name();
if (this->entrances.has(key)) if (this->entrances.has(key))

View File

@ -12,13 +12,16 @@ class Entrance;
class Level : public Node3D { class Level : public Node3D {
GDCLASS(Level, Node3D) GDCLASS(Level, Node3D)
static void _bind_methods(); static void _bind_methods();
protected: protected:
Dictionary entrances{}; Dictionary entrances{};
public: public:
Transform3D get_entrance(String const &entranceName); Transform3D get_entrance(String const& entranceName) const;
void add_entrance(Entrance *entrance); String get_default_entrance() const;
void remove_entrance(Entrance *entrance); void add_entrance(Entrance* entrance);
void remove_entrance(Entrance* entrance);
}; };
} } // namespace godot
#endif // !LEVEL_HPP #endif // !LEVEL_HPP