diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-02-22 12:18:21 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-02-22 12:18:21 -0500 |
commit | 386b136fb7d31d6424bd988d1d7c095626ceb393 (patch) | |
tree | ae3a988b3904056bb32b80a71795a1f81bab8d7f | |
parent | 56abd4ed1d2a2adff01363f31ca2d0c81f3fbf53 (diff) | |
download | lingo-randomizer-386b136fb7d31d6424bd988d1d7c095626ceb393.tar.gz lingo-randomizer-386b136fb7d31d6424bd988d1d7c095626ceb393.tar.bz2 lingo-randomizer-386b136fb7d31d6424bd988d1d7c095626ceb393.zip |
Added painting room randomisation
-rw-r--r-- | generator.cpp | 24 | ||||
-rw-r--r-- | generator.h | 43 | ||||
-rw-r--r-- | main.cpp | 44 | ||||
-rw-r--r-- | paintings.txt | 29 |
4 files changed, 139 insertions, 1 deletions
diff --git a/generator.cpp b/generator.cpp index 6b6c1be..8334904 100644 --- a/generator.cpp +++ b/generator.cpp | |||
@@ -654,6 +654,30 @@ void Generator::GenerateCrossTower( | |||
654 | SavePanel(west_other_name3, sets[3][3], sets[3][3]); | 654 | SavePanel(west_other_name3, sets[3][3], sets[3][3]); |
655 | } | 655 | } |
656 | 656 | ||
657 | void Generator::GeneratePaintingPuzzle(std::string panel_name, std::string painting_name) { | ||
658 | std::string node_name; | ||
659 | std::string answer; | ||
660 | int resource_id = 0; | ||
661 | |||
662 | for (;;) { | ||
663 | std::tie(node_name, answer, resource_id) = paintings_->GetPainting(rng_); | ||
664 | if (!used_paintings_.count(node_name)) { | ||
665 | break; | ||
666 | } | ||
667 | } | ||
668 | |||
669 | used_paintings_.insert(node_name); | ||
670 | |||
671 | SavePanel(panel_name, "painting", answer, {}); | ||
672 | |||
673 | std::string resource_path = std::string("res://nodes/paintings/") + node_name + ".tscn"; | ||
674 | if (resource_id == 0) { | ||
675 | resources_.emplace_back(resource_path, "PackedScene"); | ||
676 | } | ||
677 | |||
678 | replace_nodes_[painting_name] = {resource_path, resource_id}; | ||
679 | } | ||
680 | |||
657 | void Generator::SavePanel(std::string name, std::string question, std::string answer, GenerateOptions options) { | 681 | void Generator::SavePanel(std::string name, std::string question, std::string answer, GenerateOptions options) { |
658 | if (options.save_for_later) { | 682 | if (options.save_for_later) { |
659 | reusable_.push_back(answer); | 683 | reusable_.push_back(answer); |
diff --git a/generator.h b/generator.h index 7803004..d0333a6 100644 --- a/generator.h +++ b/generator.h | |||
@@ -118,6 +118,25 @@ private: | |||
118 | std::vector<std::vector<std::string>> sets_; | 118 | std::vector<std::vector<std::string>> sets_; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | class Paintings { | ||
122 | public: | ||
123 | explicit Paintings(std::string filename) { | ||
124 | std::ifstream file(filename); | ||
125 | std::string line; | ||
126 | while (std::getline(file, line)) { | ||
127 | auto parts = hatkirby::split<std::vector<std::string>>(line, ","); | ||
128 | paintings_.emplace_back(parts[0], parts[1], std::atoi(parts[2].c_str())); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | const std::tuple<std::string, std::string, int>& GetPainting(std::mt19937& rng) const { | ||
133 | return paintings_.at(std::uniform_int_distribution<int>(0, paintings_.size()-1)(rng)); | ||
134 | } | ||
135 | |||
136 | private: | ||
137 | std::vector<std::tuple<std::string, std::string, int>> paintings_; | ||
138 | }; | ||
139 | |||
121 | class Generator { | 140 | class Generator { |
122 | public: | 141 | public: |
123 | 142 | ||
@@ -125,6 +144,7 @@ public: | |||
125 | database_ = std::make_unique<verbly::database>("/Users/hatkirby/Dropbox/Programming/verbly-datafiles/d1.3_lingo7"); | 144 | database_ = std::make_unique<verbly::database>("/Users/hatkirby/Dropbox/Programming/verbly-datafiles/d1.3_lingo7"); |
126 | wanderlust_ = std::make_unique<Wanderlust>("../wanderlust_words.txt", "../wanderlust_puzzles.txt"); | 145 | wanderlust_ = std::make_unique<Wanderlust>("../wanderlust_words.txt", "../wanderlust_puzzles.txt"); |
127 | cross_tower_ = std::make_unique<CrossTower>("../cross_tower.txt"); | 146 | cross_tower_ = std::make_unique<CrossTower>("../cross_tower.txt"); |
147 | paintings_ = std::make_unique<Paintings>("../paintings.txt"); | ||
128 | } | 148 | } |
129 | 149 | ||
130 | // Querying | 150 | // Querying |
@@ -136,6 +156,18 @@ public: | |||
136 | return panels_.at(name); | 156 | return panels_.at(name); |
137 | } | 157 | } |
138 | 158 | ||
159 | bool IsNodeRandomized(const std::string& name) const { | ||
160 | return replace_nodes_.count(name); | ||
161 | } | ||
162 | |||
163 | const std::tuple<std::string, int>& GetNode(const std::string& name) const { | ||
164 | return replace_nodes_.at(name); | ||
165 | } | ||
166 | |||
167 | const std::vector<std::tuple<std::string, std::string>>& GetResources() const { | ||
168 | return resources_; | ||
169 | } | ||
170 | |||
139 | // Sets the panel's question and answer to static values. | 171 | // Sets the panel's question and answer to static values. |
140 | void GenerateStaticPanel(std::string name, std::string question, std::string answer = ""); | 172 | void GenerateStaticPanel(std::string name, std::string question, std::string answer = ""); |
141 | 173 | ||
@@ -196,6 +228,9 @@ public: | |||
196 | std::string west_other_name2, | 228 | std::string west_other_name2, |
197 | std::string west_other_name3); | 229 | std::string west_other_name3); |
198 | 230 | ||
231 | // Generate a painting/panel pair. | ||
232 | void GeneratePaintingPuzzle(std::string panel_name, std::string painting_name); | ||
233 | |||
199 | private: | 234 | private: |
200 | 235 | ||
201 | verbly::filter MakeHintFilter(verbly::filter subfilter, Height height, Colour colour, FilterDirection filter_direction) const; | 236 | verbly::filter MakeHintFilter(verbly::filter subfilter, Height height, Colour colour, FilterDirection filter_direction) const; |
@@ -223,12 +258,20 @@ private: | |||
223 | std::unique_ptr<verbly::database> database_; | 258 | std::unique_ptr<verbly::database> database_; |
224 | std::unique_ptr<Wanderlust> wanderlust_; | 259 | std::unique_ptr<Wanderlust> wanderlust_; |
225 | std::unique_ptr<CrossTower> cross_tower_; | 260 | std::unique_ptr<CrossTower> cross_tower_; |
261 | std::unique_ptr<Paintings> paintings_; | ||
226 | 262 | ||
227 | // name, question, answer | 263 | // name, question, answer |
228 | std::map<std::string, std::tuple<std::string, std::string>> panels_; | 264 | std::map<std::string, std::tuple<std::string, std::string>> panels_; |
229 | 265 | ||
266 | // name, resource_path, resource_id (0 if needs import) | ||
267 | std::map<std::string, std::tuple<std::string, int>> replace_nodes_; | ||
268 | |||
269 | // path, type | ||
270 | std::vector<std::tuple<std::string, std::string>> resources_; | ||
271 | |||
230 | std::vector<std::string> reusable_; | 272 | std::vector<std::string> reusable_; |
231 | std::map<std::string, std::set<std::string>> pools_; | 273 | std::map<std::string, std::set<std::string>> pools_; |
274 | std::set<std::string> used_paintings_; | ||
232 | }; | 275 | }; |
233 | 276 | ||
234 | #endif /* end of include guard: GENERATOR_H_811386CE */ | 277 | #endif /* end of include guard: GENERATOR_H_811386CE */ |
diff --git a/main.cpp b/main.cpp index 505004d..ba40def 100644 --- a/main.cpp +++ b/main.cpp | |||
@@ -405,7 +405,12 @@ public: | |||
405 | 405 | ||
406 | 406 | ||
407 | 407 | ||
408 | 408 | // Room Room | |
409 | gen_.GeneratePaintingPuzzle("Panel_painting_flower", "flower_painting_gray"); | ||
410 | gen_.GeneratePaintingPuzzle("Panel_painting_eye", "eye_painting_gray"); | ||
411 | gen_.GeneratePaintingPuzzle("Panel_painting_snowman", "snowman_painting_gray"); | ||
412 | gen_.GeneratePaintingPuzzle("Panel_painting_owl", "owl_painting_gray"); | ||
413 | gen_.GeneratePaintingPuzzle("Panel_painting_panda", "panda_painting_gray"); | ||
409 | 414 | ||
410 | 415 | ||
411 | 416 | ||
@@ -578,6 +583,9 @@ public: | |||
578 | std::string name; | 583 | std::string name; |
579 | std::string question; | 584 | std::string question; |
580 | std::string answer; | 585 | std::string answer; |
586 | std::map<std::string, int> resource_id_by_path; | ||
587 | int last_id = 0; | ||
588 | bool need_to_output_resources = false; | ||
581 | while (std::getline(level1, line)) { | 589 | while (std::getline(level1, line)) { |
582 | if (line.substr(0, 18) == "[node name=\"Panel_") { | 590 | if (line.substr(0, 18) == "[node name=\"Panel_") { |
583 | std::string stripstart = line.substr(12); | 591 | std::string stripstart = line.substr(12); |
@@ -604,6 +612,40 @@ public: | |||
604 | 612 | ||
605 | //std::cout << name << ": " << question << "? " << answer << "!" << std::endl; | 613 | //std::cout << name << ": " << question << "? " << answer << "!" << std::endl; |
606 | output << "answer = \"" << answer << "\"" << std::endl; | 614 | output << "answer = \"" << answer << "\"" << std::endl; |
615 | } else if (line.substr(0, 9) == "[gd_scene") { | ||
616 | std::string stripstart = line.substr(21); | ||
617 | std::string numstr = stripstart.substr(0, stripstart.find(" ")); | ||
618 | int load_steps = std::atoi(numstr.c_str()); | ||
619 | output << "[gd_scene load_steps=" << (load_steps + gen_.GetResources().size()) << " format=2]\n"; | ||
620 | } else if (line.substr(0, 13) == "[ext_resource") { | ||
621 | std::string stripstart = line.substr(line.find("id=") + 3); | ||
622 | std::string numstr = stripstart.substr(0, stripstart.find("]")); | ||
623 | last_id = std::atoi(numstr.c_str()); | ||
624 | need_to_output_resources = true; | ||
625 | output << line << "\n"; | ||
626 | } else if (line.substr(0, 12) == "[node name=\"") { | ||
627 | std::string stripstart = line.substr(12); | ||
628 | std::string tempname = stripstart.substr(0, stripstart.find("\"")); | ||
629 | |||
630 | if (gen_.IsNodeRandomized(tempname)) { | ||
631 | int id_pos = line.find("(") + 2; | ||
632 | auto [path, res_id] = gen_.GetNode(tempname); | ||
633 | if (res_id != 0) { | ||
634 | output << line.substr(0, id_pos) + std::to_string(res_id) + " )]\n"; | ||
635 | } else { | ||
636 | output << line.substr(0, id_pos) + std::to_string(resource_id_by_path[path]) + " )]\n"; | ||
637 | } | ||
638 | } else { | ||
639 | output << line << "\n"; | ||
640 | } | ||
641 | } else if (line.empty() && need_to_output_resources) { | ||
642 | for (const auto& [path, type] : gen_.GetResources()) { | ||
643 | last_id++; | ||
644 | resource_id_by_path[path] = last_id; | ||
645 | output << "[ext_resource path=\"" << path << "\" type=\"" << type << "\" id=" << last_id << "]\n"; | ||
646 | } | ||
647 | output << "\n"; | ||
648 | need_to_output_resources = false; | ||
607 | } else { | 649 | } else { |
608 | output << line << "\n"; | 650 | output << line << "\n"; |
609 | } | 651 | } |
diff --git a/paintings.txt b/paintings.txt new file mode 100644 index 0000000..f91a808 --- /dev/null +++ b/paintings.txt | |||
@@ -0,0 +1,29 @@ | |||
1 | beach,beach,0 | ||
2 | bg_bg4,clouds,0 | ||
3 | bg_bookshelf,bookshelf,0 | ||
4 | bg_candle,candle,0 | ||
5 | bg_egg,egg,0 | ||
6 | bg_fish,fish,0 | ||
7 | bg_halloween_2,pumpkin,0 | ||
8 | bg_knight,knight,0 | ||
9 | bg_scorpion,scorpion,0 | ||
10 | bg_thanksgiving,turkey,0 | ||
11 | catlike,cat,0 | ||
12 | crown,crown,0 | ||
13 | emmy,nest,0 | ||
14 | ether,rocket ship,0 | ||
15 | hatkirby,shooting star,0 | ||
16 | icy,parrot,0 | ||
17 | ig_note,note,0 | ||
18 | ig_rose,rose,0 | ||
19 | kiwi,kiwi,0 | ||
20 | ninjonicx_square,spiral,0 | ||
21 | rainbow,rainbow,0 | ||
22 | rever,fishbowl,0 | ||
23 | tree,tree,0 | ||
24 | yinyang,yinyang,0 | ||
25 | eight,eight,59 | ||
26 | north,north,44 | ||
27 | east,east,48 | ||
28 | south,south,47 | ||
29 | west,west,46 \ No newline at end of file | ||