diff options
Diffstat (limited to 'tools/util/godot_scene.h')
| -rw-r--r-- | tools/util/godot_scene.h | 67 |
1 files changed, 67 insertions, 0 deletions
| diff --git a/tools/util/godot_scene.h b/tools/util/godot_scene.h new file mode 100644 index 0000000..529e38e --- /dev/null +++ b/tools/util/godot_scene.h | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | #ifndef TOOLS_UTIL_TSCN_H_ | ||
| 2 | #define TOOLS_UTIL_TSCN_H_ | ||
| 3 | |||
| 4 | #include <absl/strings/string_view.h> | ||
| 5 | |||
| 6 | #include <map> | ||
| 7 | #include <memory> | ||
| 8 | #include <string> | ||
| 9 | #include <string_view> | ||
| 10 | #include <variant> | ||
| 11 | |||
| 12 | namespace com::fourisland::lingo2_archipelago { | ||
| 13 | |||
| 14 | struct GodotExtResource { | ||
| 15 | std::string type; | ||
| 16 | std::string path; | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct GodotExtResourceRef { | ||
| 20 | std::string id; | ||
| 21 | }; | ||
| 22 | |||
| 23 | using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>; | ||
| 24 | |||
| 25 | class GodotNode { | ||
| 26 | public: | ||
| 27 | GodotNode(std::string name, GodotInstanceType instance_type) | ||
| 28 | : name_(std::move(name)), instance_type_(std::move(instance_type)) {} | ||
| 29 | |||
| 30 | const std::string& GetName() const { return name_; } | ||
| 31 | |||
| 32 | const GodotInstanceType& GetInstanceType() const { return instance_type_; } | ||
| 33 | |||
| 34 | const GodotNode* GetParent() const { return parent_; } | ||
| 35 | GodotNode* GetParent() { return parent_; } | ||
| 36 | |||
| 37 | std::string GetPath() const; | ||
| 38 | |||
| 39 | void AddChild(GodotNode& child); | ||
| 40 | |||
| 41 | const GodotNode* GetNode(absl::string_view path) const; | ||
| 42 | GodotNode* GetNode(absl::string_view path); | ||
| 43 | |||
| 44 | const std::map<std::string, GodotNode*> GetChildren() const { | ||
| 45 | return children_; | ||
| 46 | } | ||
| 47 | |||
| 48 | private: | ||
| 49 | std::string name_; | ||
| 50 | GodotInstanceType instance_type_; | ||
| 51 | |||
| 52 | GodotNode* parent_ = nullptr; | ||
| 53 | std::map<std::string, GodotNode*> children_; | ||
| 54 | }; | ||
| 55 | |||
| 56 | class GodotScene { | ||
| 57 | public: | ||
| 58 | virtual const GodotExtResource* GetExtResource( | ||
| 59 | const std::string& id) const = 0; | ||
| 60 | virtual const GodotNode& GetRoot() const = 0; | ||
| 61 | }; | ||
| 62 | |||
| 63 | std::unique_ptr<GodotScene> ReadGodotSceneFromFile(const std::string& path); | ||
| 64 | |||
| 65 | } // namespace com::fourisland::lingo2_archipelago | ||
| 66 | |||
| 67 | #endif /* TOOLS_UTIL_TSCN_H_ */ | ||
