From c9139577e690baff59da1b1edf13ef209c00ee40 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 18 Aug 2025 18:50:04 -0400 Subject: Added the_repetitive --- tools/util/godot_scene.cpp | 80 ++++++---------------------------------------- 1 file changed, 10 insertions(+), 70 deletions(-) (limited to 'tools/util/godot_scene.cpp') diff --git a/tools/util/godot_scene.cpp b/tools/util/godot_scene.cpp index 272111d..1e77c9e 100644 --- a/tools/util/godot_scene.cpp +++ b/tools/util/godot_scene.cpp @@ -1,6 +1,7 @@ #include "godot_scene.h" #include +#include #include #include @@ -10,32 +11,6 @@ namespace com::fourisland::lingo2_archipelago { namespace { -class GodotSceneImpl : public GodotScene { - public: - GodotSceneImpl(std::map ext_resources, - std::unique_ptr root, - std::vector> descendents) - : ext_resources_(std::move(ext_resources)), - root_(std::move(root)), - descendents_(std::move(descendents)) {} - - virtual const GodotExtResource* GetExtResource(const std::string& id) const { - auto it = ext_resources_.find(id); - if (it != ext_resources_.end()) { - return &it->second; - } else { - return nullptr; - } - } - - virtual const GodotNode& GetRoot() const { return *root_; } - - private: - std::map ext_resources_; - std::unique_ptr root_; - std::vector> descendents_; -}; - struct Heading { std::string type; @@ -159,45 +134,17 @@ Heading ParseTscnHeading(absl::string_view line) { } // namespace -void GodotNode::AddChild(GodotNode& child) { - children_[child.GetName()] = &child; - child.parent_ = this; -} - std::string GodotNode::GetPath() const { - if (parent_ == nullptr || parent_->GetName() == "") { - return name_; + if (parent.empty() || parent == ".") { + return name; } else { - return parent_->GetPath() + "/" + name_; + return parent + "/" + name; } } -const GodotNode* GodotNode::GetNode(absl::string_view path) const { - std::vector names = absl::StrSplit(path, "/"); - - auto it = children_.find(names[0]); - if (it == children_.end()) { - return nullptr; - } else { - if (names.size() == 1) { - return it->second; - } else { - path.remove_prefix(names[0].size() + 1); - - return it->second->GetNode(path); - } - } -} - -GodotNode* GodotNode::GetNode(absl::string_view path) { - return const_cast( - const_cast(this)->GetNode(path)); -} - -std::unique_ptr ReadGodotSceneFromFile(const std::string& path) { +GodotScene ReadGodotSceneFromFile(const std::string& path) { std::map ext_resources; - auto root = std::make_unique("", GodotInstanceType{}); - std::vector> descendents; + std::vector nodes; std::ifstream input(path); @@ -235,15 +182,9 @@ std::unique_ptr ReadGodotSceneFromFile(const std::string& path) { ext_resources[heading.id] = ext_resource; } else if (heading.type == "node") { if (heading.parent != "") { - descendents.push_back( - std::make_unique(heading.name, heading.instance_type)); - GodotNode* child = descendents.back().get(); - - if (heading.parent == ".") { - root->AddChild(*child); - } else { - root->GetNode(heading.parent)->AddChild(*child); - } + nodes.push_back(GodotNode{.name = heading.name, + .parent = heading.parent, + .instance_type = heading.instance_type}); } } else { cur_heading = heading; @@ -262,8 +203,7 @@ std::unique_ptr ReadGodotSceneFromFile(const std::string& path) { handle_end_of_section(); } - return std::make_unique( - std::move(ext_resources), std::move(root), std::move(descendents)); + return GodotScene(std::move(ext_resources), std::move(nodes)); } } // namespace com::fourisland::lingo2_archipelago -- cgit 1.4.1