From 1ac21d4a67ddd211fda841aa6e368bc2cf52a3d6 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 18 Aug 2025 12:56:13 -0400 Subject: Validate that nodes in game files are used You can now also list out nodes that you are explicitly not mapping out. The current state of the repo does produce some warnings when the validator is run and they're either endings, paintings that I'm not sure what to do with yet, and weird proxy stuff I'm not sure how to handle yet. --- tools/validator/CMakeLists.txt | 1 + tools/validator/godot_processor.cpp | 76 +++++++++++++++++++++++++++++++++++++ tools/validator/godot_processor.h | 14 +++++++ tools/validator/human_processor.cpp | 15 ++++++++ tools/validator/main.cpp | 11 ++++-- tools/validator/structs.h | 1 + tools/validator/validator.cpp | 8 ++++ 7 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 tools/validator/godot_processor.cpp create mode 100644 tools/validator/godot_processor.h (limited to 'tools/validator') diff --git a/tools/validator/CMakeLists.txt b/tools/validator/CMakeLists.txt index 0ad58c2..967b890 100644 --- a/tools/validator/CMakeLists.txt +++ b/tools/validator/CMakeLists.txt @@ -1,6 +1,7 @@ find_package(Protobuf REQUIRED) add_executable(validator + godot_processor.cpp human_processor.cpp main.cpp validator.cpp 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 @@ +#include "godot_processor.h" + +#include +#include +#include +#include + +#include "structs.h" +#include "util/godot_scene.h" + +namespace com::fourisland::lingo2_archipelago { + +namespace { + +static const std::set kImportantNodeTypes = { + "res://objects/nodes/panel.tscn", "res://objects/nodes/worldport.tscn", + "res://objects/nodes/keyHolder.tscn", + "res://objects/nodes/collectable.tscn"}; + +class GodotProcessor { + public: + GodotProcessor(const std::string& repodir, CollectedInfo& info) + : repodir_(repodir), info_(info) {} + + void Run() { + for (auto& [map_name, map_info] : info_.maps) { + ProcessMap(map_name, map_info); + } + } + + void ProcessMap(const std::string& map_name, MapInfo& map_info) { + std::filesystem::path scene_path = std::filesystem::path(repodir_) / + "objects" / "scenes" / + (map_name + ".tscn"); + std::string scene_path_str = scene_path.string(); + std::cout << "Processing " << scene_path_str << std::endl; + + std::unique_ptr scene = + ReadGodotSceneFromFile(scene_path_str); + + ProcessMapNode(*scene, scene->GetRoot(), map_info); + } + + void ProcessMapNode(const GodotScene& scene, const GodotNode& node, + MapInfo& map_info) { + if (std::holds_alternative(node.GetInstanceType())) { + const GodotExtResourceRef& ext_resource_ref = + std::get(node.GetInstanceType()); + const GodotExtResource* ext_resource = + scene.GetExtResource(ext_resource_ref.id); + + if (ext_resource != nullptr && + (kImportantNodeTypes.count(ext_resource->path) || + ext_resource->path.starts_with("res://objects/meshes/paintings/"))) { + map_info.game_nodes[node.GetPath()].defined = true; + } + } + + for (const auto& [child_name, child_node] : node.GetChildren()) { + ProcessMapNode(scene, *child_node, map_info); + } + } + + private: + std::string repodir_; + CollectedInfo& info_; +}; + +} // namespace + +void ProcessGodotData(const std::string& repodir, CollectedInfo& info) { + GodotProcessor godot_processor(repodir, info); + godot_processor.Run(); +} + +} // namespace com::fourisland::lingo2_archipelago diff --git a/tools/validator/godot_processor.h b/tools/validator/godot_processor.h new file mode 100644 index 0000000..97bcea6 --- /dev/null +++ b/tools/validator/godot_processor.h @@ -0,0 +1,14 @@ +#ifndef TOOLS_VALIDATOR_GODOT_PROCESSOR_H_ +#define TOOLS_VALIDATOR_GODOT_PROCESSOR_H_ + +#include + +namespace com::fourisland::lingo2_archipelago { + +struct CollectedInfo; + +void ProcessGodotData(const std::string& repodir, CollectedInfo& info); + +} // namespace com::fourisland::lingo2_archipelago + +#endif /* TOOLS_VALIDATOR_GODOT_PROCESSOR_H_ */ diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 0846bb8..af40980 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp @@ -55,11 +55,26 @@ class HumanProcessor { void ProcessMap(std::filesystem::path path) { std::string map_name = path.filename().string(); + ProcessMetadataFile(path / "metadata.txtpb", map_name); ProcessConnectionsFile(path / "connections.txtpb", map_name); ProcessDoorsFile(path / "doors.txtpb", map_name); ProcessRooms(path / "rooms", map_name); } + void ProcessMetadataFile(std::filesystem::path path, + const std::string& current_map_name) { + if (!std::filesystem::exists(path)) { + return; + } + + MapInfo& map_info = info_.maps[current_map_name]; + + auto metadata = ReadMessageFromFile(path.string()); + for (const std::string& path : metadata.excluded_nodes()) { + map_info.game_nodes[path].uses++; + } + } + void ProcessRooms(std::filesystem::path path, const std::string& current_map_name) { for (auto const& dir_entry : std::filesystem::directory_iterator(path)) { diff --git a/tools/validator/main.cpp b/tools/validator/main.cpp index af9842b..1a72e9a 100644 --- a/tools/validator/main.cpp +++ b/tools/validator/main.cpp @@ -1,3 +1,4 @@ +#include "godot_processor.h" #include "human_processor.h" #include "structs.h" #include "validator.h" @@ -5,10 +6,11 @@ namespace com::fourisland::lingo2_archipelago { namespace { -void Run(const std::string& mapdir) { +void Run(const std::string& mapdir, const std::string& repodir) { CollectedInfo info; ProcessHumanData(mapdir, info); + ProcessGodotData(repodir, info); ValidateCollectedInfo(info); } @@ -17,15 +19,16 @@ void Run(const std::string& mapdir) { } // namespace com::fourisland::lingo2_archipelago int main(int argc, char** argv) { - if (argc != 2) { + if (argc != 3) { std::cout << "Incorrect argument count." << std::endl; - std::cout << "Usage: validator [path to map directory]" << std::endl; + std::cout << "Usage: validator [path to map directory] [path to Lingo 2 repository]" << std::endl; return 1; } std::string mapdir = argv[1]; + std::string repodir = argv[2]; - com::fourisland::lingo2_archipelago::Run(mapdir); + com::fourisland::lingo2_archipelago::Run(mapdir, repodir); return 0; } diff --git a/tools/validator/structs.h b/tools/validator/structs.h index 1b61f77..406dc0c 100644 --- a/tools/validator/structs.h +++ b/tools/validator/structs.h @@ -21,6 +21,7 @@ struct MalformedIdentifiers { }; struct GameNodeInfo { + bool defined = false; int uses = 0; }; diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp index f2ec280..6d01b7c 100644 --- a/tools/validator/validator.cpp +++ b/tools/validator/validator.cpp @@ -14,6 +14,14 @@ void ValidateMap(const std::string& map_name, const MapInfo& map_info) { if (node_info.uses > 1) { std::cout << "Map " << map_name << " node " << node_path << " is used in multiple places." << std::endl; + } else if (node_info.uses == 0) { + std::cout << "Map " << map_name << " node " << node_path + << " is not used." << std::endl; + } + + if (!node_info.defined) { + std::cout << "Map " << map_name << " node " << node_path + << " is not defined in the game file." << std::endl; } } } -- cgit 1.4.1