diff options
Diffstat (limited to 'tools/validator/godot_processor.cpp')
-rw-r--r-- | tools/validator/godot_processor.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/validator/godot_processor.cpp b/tools/validator/godot_processor.cpp new file mode 100644 index 0000000..f345cff --- /dev/null +++ b/tools/validator/godot_processor.cpp | |||
@@ -0,0 +1,76 @@ | |||
1 | #include "godot_processor.h" | ||
2 | |||
3 | #include <filesystem> | ||
4 | #include <iostream> | ||
5 | #include <memory> | ||
6 | #include <set> | ||
7 | |||
8 | #include "structs.h" | ||
9 | #include "util/godot_scene.h" | ||
10 | |||
11 | namespace com::fourisland::lingo2_archipelago { | ||
12 | |||
13 | namespace { | ||
14 | |||
15 | static const std::set<std::string> kImportantNodeTypes = { | ||
16 | "res://objects/nodes/panel.tscn", "res://objects/nodes/worldport.tscn", | ||
17 | "res://objects/nodes/keyHolder.tscn", | ||
18 | "res://objects/nodes/collectable.tscn"}; | ||
19 | |||
20 | class GodotProcessor { | ||
21 | public: | ||
22 | GodotProcessor(const std::string& repodir, CollectedInfo& info) | ||
23 | : repodir_(repodir), info_(info) {} | ||
24 | |||
25 | void Run() { | ||
26 | for (auto& [map_name, map_info] : info_.maps) { | ||
27 | ProcessMap(map_name, map_info); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void ProcessMap(const std::string& map_name, MapInfo& map_info) { | ||
32 | std::filesystem::path scene_path = std::filesystem::path(repodir_) / | ||
33 | "objects" / "scenes" / | ||
34 | (map_name + ".tscn"); | ||
35 | std::string scene_path_str = scene_path.string(); | ||
36 | std::cout << "Processing " << scene_path_str << std::endl; | ||
37 | |||
38 | std::unique_ptr<GodotScene> scene = | ||
39 | ReadGodotSceneFromFile(scene_path_str); | ||
40 | |||
41 | ProcessMapNode(*scene, scene->GetRoot(), map_info); | ||
42 | } | ||
43 | |||
44 | void ProcessMapNode(const GodotScene& scene, const GodotNode& node, | ||
45 | MapInfo& map_info) { | ||
46 | if (std::holds_alternative<GodotExtResourceRef>(node.GetInstanceType())) { | ||
47 | const GodotExtResourceRef& ext_resource_ref = | ||
48 | std::get<GodotExtResourceRef>(node.GetInstanceType()); | ||
49 | const GodotExtResource* ext_resource = | ||
50 | scene.GetExtResource(ext_resource_ref.id); | ||
51 | |||
52 | if (ext_resource != nullptr && | ||
53 | (kImportantNodeTypes.count(ext_resource->path) || | ||
54 | ext_resource->path.starts_with("res://objects/meshes/paintings/"))) { | ||
55 | map_info.game_nodes[node.GetPath()].defined = true; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | for (const auto& [child_name, child_node] : node.GetChildren()) { | ||
60 | ProcessMapNode(scene, *child_node, map_info); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | private: | ||
65 | std::string repodir_; | ||
66 | CollectedInfo& info_; | ||
67 | }; | ||
68 | |||
69 | } // namespace | ||
70 | |||
71 | void ProcessGodotData(const std::string& repodir, CollectedInfo& info) { | ||
72 | GodotProcessor godot_processor(repodir, info); | ||
73 | godot_processor.Run(); | ||
74 | } | ||
75 | |||
76 | } // namespace com::fourisland::lingo2_archipelago | ||