From 386b136fb7d31d6424bd988d1d7c095626ceb393 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 22 Feb 2023 12:18:21 -0500 Subject: Added painting room randomisation --- main.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 505004d..ba40def 100644 --- a/main.cpp +++ b/main.cpp @@ -405,7 +405,12 @@ public: - + // Room Room + gen_.GeneratePaintingPuzzle("Panel_painting_flower", "flower_painting_gray"); + gen_.GeneratePaintingPuzzle("Panel_painting_eye", "eye_painting_gray"); + gen_.GeneratePaintingPuzzle("Panel_painting_snowman", "snowman_painting_gray"); + gen_.GeneratePaintingPuzzle("Panel_painting_owl", "owl_painting_gray"); + gen_.GeneratePaintingPuzzle("Panel_painting_panda", "panda_painting_gray"); @@ -578,6 +583,9 @@ public: std::string name; std::string question; std::string answer; + std::map resource_id_by_path; + int last_id = 0; + bool need_to_output_resources = false; while (std::getline(level1, line)) { if (line.substr(0, 18) == "[node name=\"Panel_") { std::string stripstart = line.substr(12); @@ -604,6 +612,40 @@ public: //std::cout << name << ": " << question << "? " << answer << "!" << std::endl; output << "answer = \"" << answer << "\"" << std::endl; + } else if (line.substr(0, 9) == "[gd_scene") { + std::string stripstart = line.substr(21); + std::string numstr = stripstart.substr(0, stripstart.find(" ")); + int load_steps = std::atoi(numstr.c_str()); + output << "[gd_scene load_steps=" << (load_steps + gen_.GetResources().size()) << " format=2]\n"; + } else if (line.substr(0, 13) == "[ext_resource") { + std::string stripstart = line.substr(line.find("id=") + 3); + std::string numstr = stripstart.substr(0, stripstart.find("]")); + last_id = std::atoi(numstr.c_str()); + need_to_output_resources = true; + output << line << "\n"; + } else if (line.substr(0, 12) == "[node name=\"") { + std::string stripstart = line.substr(12); + std::string tempname = stripstart.substr(0, stripstart.find("\"")); + + if (gen_.IsNodeRandomized(tempname)) { + int id_pos = line.find("(") + 2; + auto [path, res_id] = gen_.GetNode(tempname); + if (res_id != 0) { + output << line.substr(0, id_pos) + std::to_string(res_id) + " )]\n"; + } else { + output << line.substr(0, id_pos) + std::to_string(resource_id_by_path[path]) + " )]\n"; + } + } else { + output << line << "\n"; + } + } else if (line.empty() && need_to_output_resources) { + for (const auto& [path, type] : gen_.GetResources()) { + last_id++; + resource_id_by_path[path] = last_id; + output << "[ext_resource path=\"" << path << "\" type=\"" << type << "\" id=" << last_id << "]\n"; + } + output << "\n"; + need_to_output_resources = false; } else { output << line << "\n"; } -- cgit 1.4.1