diff options
Diffstat (limited to 'tools/util/godot_scene.h')
-rw-r--r-- | tools/util/godot_scene.h | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/tools/util/godot_scene.h b/tools/util/godot_scene.h index 529e38e..17f3f50 100644 --- a/tools/util/godot_scene.h +++ b/tools/util/godot_scene.h | |||
@@ -1,13 +1,12 @@ | |||
1 | #ifndef TOOLS_UTIL_TSCN_H_ | 1 | #ifndef TOOLS_UTIL_TSCN_H_ |
2 | #define TOOLS_UTIL_TSCN_H_ | 2 | #define TOOLS_UTIL_TSCN_H_ |
3 | 3 | ||
4 | #include <absl/strings/string_view.h> | ||
5 | |||
6 | #include <map> | 4 | #include <map> |
7 | #include <memory> | 5 | #include <memory> |
8 | #include <string> | 6 | #include <string> |
9 | #include <string_view> | 7 | #include <utility> |
10 | #include <variant> | 8 | #include <variant> |
9 | #include <vector> | ||
11 | 10 | ||
12 | namespace com::fourisland::lingo2_archipelago { | 11 | namespace com::fourisland::lingo2_archipelago { |
13 | 12 | ||
@@ -22,45 +21,36 @@ struct GodotExtResourceRef { | |||
22 | 21 | ||
23 | using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>; | 22 | using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>; |
24 | 23 | ||
25 | class GodotNode { | 24 | struct GodotNode { |
26 | public: | 25 | std::string name; |
27 | GodotNode(std::string name, GodotInstanceType instance_type) | 26 | std::string parent; |
28 | : name_(std::move(name)), instance_type_(std::move(instance_type)) {} | 27 | GodotInstanceType 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 | 28 | ||
37 | std::string GetPath() const; | 29 | 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 | }; | 30 | }; |
55 | 31 | ||
56 | class GodotScene { | 32 | class GodotScene { |
57 | public: | 33 | public: |
58 | virtual const GodotExtResource* GetExtResource( | 34 | GodotScene(std::map<std::string, GodotExtResource> ext_resources, |
59 | const std::string& id) const = 0; | 35 | std::vector<GodotNode> nodes) |
60 | virtual const GodotNode& GetRoot() const = 0; | 36 | : ext_resources_(std::move(ext_resources)), nodes_(std::move(nodes)) {} |
37 | |||
38 | const GodotExtResource* GetExtResource(const std::string& id) const { | ||
39 | auto it = ext_resources_.find(id); | ||
40 | if (it != ext_resources_.end()) { | ||
41 | return &it->second; | ||
42 | } else { | ||
43 | return nullptr; | ||
44 | } | ||
45 | } | ||
46 | const std::vector<GodotNode>& GetNodes() const { return nodes_; } | ||
47 | |||
48 | private: | ||
49 | std::map<std::string, GodotExtResource> ext_resources_; | ||
50 | std::vector<GodotNode> nodes_; | ||
61 | }; | 51 | }; |
62 | 52 | ||
63 | std::unique_ptr<GodotScene> ReadGodotSceneFromFile(const std::string& path); | 53 | GodotScene ReadGodotSceneFromFile(const std::string& path); |
64 | 54 | ||
65 | } // namespace com::fourisland::lingo2_archipelago | 55 | } // namespace com::fourisland::lingo2_archipelago |
66 | 56 | ||