From 86c6f803ffb651df20509d4e1f1602352b88bd41 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 4 Mar 2024 05:52:40 +0000 Subject: something 2 --- scene.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'scene.cpp') diff --git a/scene.cpp b/scene.cpp index 6eae537..f0b40d3 100644 --- a/scene.cpp +++ b/scene.cpp @@ -24,7 +24,7 @@ Scene::Scene(const std::filesystem::path& path) { if (cur_heading.type() == "sub_resource") { sub_resources_[std::get(cur_heading.GetKeyval("id"))] = { - cur_heading, cur_value.str()}; + cur_heading, cur_value.str(), ""}; } else { other_.emplace_back(cur_heading, cur_value.str()); } @@ -69,18 +69,21 @@ int Scene::AddSubResource(const Script& script) { int new_id = next_sub_id_++; std::ostringstream resource_contents; + resource_contents << "script/source = " << std::quoted(script.ToString()); + + std::ostringstream variables_str; for (const auto& [variable, value] : script.exports()) { - resource_contents << variable << " = SubResource( " << value << " )" - << std::endl; + variables_str << variable << " = SubResource( " << value << " )" + << std::endl; } - resource_contents << "script/source = " << std::quoted(script.ToString()); Heading heading; heading.set_type("sub_resource"); heading.SetKeyval("type", "GDScript"); heading.SetKeyval("id", new_id); - sub_resources_[new_id] = {heading, resource_contents.str()}; + sub_resources_[new_id] = {heading, resource_contents.str(), + variables_str.str()}; return new_id; } @@ -93,6 +96,7 @@ void Scene::ReplaceScriptReferences(int ext_id, int sub_id) { search_str << "ExtResource( " << ext_id << " )"; std::string search = search_str.str(); + bool found_it = false; std::ostringstream new_text; std::string_view corpus = text; int location; @@ -100,14 +104,20 @@ void Scene::ReplaceScriptReferences(int ext_id, int sub_id) { new_text << corpus.substr(0, location) << "SubResource( " << sub_id << " )"; corpus.remove_prefix(location + search.size()); + found_it = true; } new_text << corpus; + if (found_it) { + const std::string& variables = std::get<2>(sub_resources_[sub_id]); + new_text << std::endl << variables; + } + text = new_text.str(); }; for (auto& [id, stuff] : sub_resources_) { - auto& [heading, text] = stuff; + auto& [heading, text, variables] = stuff; replace_refs(text); } @@ -127,7 +137,7 @@ std::string Scene::ToString() const { output << std::endl; for (const auto& [id, resource] : sub_resources_) { - const auto& [heading, value] = resource; + const auto& [heading, value, variables] = resource; output << heading.ToString() << value << std::endl << std::endl; } -- cgit 1.4.1