From c88f4184eaa48efbdc69e76eb3c8a4a206434ad3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 16 Aug 2025 14:52:24 -0400 Subject: Started writing a data validator Currently, it can check whether identifiers point to non-existent objects, or whether multiple objects share the same identifier. It can also determine whether an identifier is underspecified (e.g. a door doesn't specify a room, or a global connection doesn't specify a map). --- tools/util/CMakeLists.txt | 5 +++ tools/util/identifiers.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++ tools/util/identifiers.h | 85 +++++++++++++++++++++++++++++++++++++ tools/util/naming.cpp | 4 ++ tools/util/naming.h | 4 ++ 5 files changed, 200 insertions(+) create mode 100644 tools/util/identifiers.cpp create mode 100644 tools/util/identifiers.h (limited to 'tools/util') diff --git a/tools/util/CMakeLists.txt b/tools/util/CMakeLists.txt index 8eb8d3b..f086e10 100644 --- a/tools/util/CMakeLists.txt +++ b/tools/util/CMakeLists.txt @@ -1,5 +1,10 @@ +find_package(Protobuf REQUIRED) + add_library(util + identifiers.cpp naming.cpp ) set_property(TARGET util PROPERTY CXX_STANDARD 20) set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) +target_include_directories(util PUBLIC ${CMAKE_BINARY_DIR}) +target_link_libraries(util PUBLIC protos protobuf::libprotobuf) diff --git a/tools/util/identifiers.cpp b/tools/util/identifiers.cpp new file mode 100644 index 0000000..5b51c57 --- /dev/null +++ b/tools/util/identifiers.cpp @@ -0,0 +1,102 @@ +#include "identifiers.h" + +#include + +#include "proto/human.pb.h" + +namespace com::fourisland::lingo2_archipelago { + +std::optional GetCompleteRoomIdentifier( + RoomIdentifier identifier, std::optional map_name) { + if (!identifier.has_map()) { + if (!map_name) { + return std::nullopt; + } + identifier.set_map(*map_name); + } + return identifier; +} + +std::optional GetCompleteDoorIdentifier( + DoorIdentifier identifier, std::optional map_name) { + if (!identifier.has_map()) { + if (!map_name) { + return std::nullopt; + } + identifier.set_map(*map_name); + } + return identifier; +} + +std::optional GetCompletePortIdentifier( + PortIdentifier identifier, std::optional map_name, + std::optional room_name) { + if (!identifier.has_map()) { + if (!map_name) { + return std::nullopt; + } + identifier.set_map(*map_name); + } + if (!identifier.has_room()) { + if (!room_name) { + return std::nullopt; + } + identifier.set_room(*room_name); + } + return identifier; +} + +std::optional GetCompletePaintingIdentifier( + PaintingIdentifier identifier, std::optional map_name, + std::optional room_name) { + if (!identifier.has_map()) { + if (!map_name) { + return std::nullopt; + } + identifier.set_map(*map_name); + } + if (!identifier.has_room()) { + if (!room_name) { + return std::nullopt; + } + identifier.set_room(*room_name); + } + return identifier; +} + +std::optional GetCompletePanelIdentifierWithoutAnswer( + PanelIdentifier identifier, std::optional map_name, + std::optional room_name) { + if (!identifier.has_map()) { + if (!map_name) { + return std::nullopt; + } + identifier.set_map(*map_name); + } + if (!identifier.has_room()) { + if (!room_name) { + return std::nullopt; + } + identifier.set_room(*room_name); + } + identifier.clear_answer(); + return identifier; +} + +std::optional GetCompleteKeyholderIdentifierWithoutKey( + KeyholderIdentifier identifier, const std::string& map_name, + std::optional room_name) { + if (!identifier.has_map()) { + identifier.set_map(map_name); + } + if (!identifier.has_room()) { + if (!room_name) { + return std::nullopt; + } + identifier.set_room(*room_name); + } + identifier.clear_key(); + return identifier; +} + +} // namespace com::fourisland::lingo2_archipelago diff --git a/tools/util/identifiers.h b/tools/util/identifiers.h new file mode 100644 index 0000000..341dee1 --- /dev/null +++ b/tools/util/identifiers.h @@ -0,0 +1,85 @@ +#ifndef TOOLS_UTIL_IDENTIFIERS_H_ +#define TOOLS_UTIL_IDENTIFIERS_H_ + +#include +#include +#include + +#include "proto/human.pb.h" + +namespace com::fourisland::lingo2_archipelago { + +class RoomIdentifierLess { + public: + bool operator()(const RoomIdentifier& lhs, const RoomIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name()); + } +}; + +class DoorIdentifierLess { + public: + bool operator()(const DoorIdentifier& lhs, const DoorIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name()); + } +}; + +class PortIdentifierLess { + public: + bool operator()(const PortIdentifier& lhs, const PortIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.room(), lhs.name()) < + std::tie(rhs.map(), rhs.room(), rhs.name()); + } +}; + +class PaintingIdentifierLess { + public: + bool operator()(const PaintingIdentifier& lhs, + const PaintingIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.room(), lhs.name()) < + std::tie(rhs.map(), rhs.room(), rhs.name()); + } +}; + +class PanelIdentifierLess { + public: + bool operator()(const PanelIdentifier& lhs, + const PanelIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.answer()) < + std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.answer()); + } +}; + +class KeyholderIdentifierLess { + public: + bool operator()(const KeyholderIdentifier& lhs, + const KeyholderIdentifier& rhs) const { + return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.key()) < + std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.key()); + } +}; + +std::optional GetCompleteRoomIdentifier( + RoomIdentifier identifier, std::optional map_name); + +std::optional GetCompleteDoorIdentifier( + DoorIdentifier identifier, std::optional map_name); + +std::optional GetCompletePortIdentifier( + PortIdentifier identifier, std::optional map_name, + std::optional room_name); + +std::optional GetCompletePaintingIdentifier( + PaintingIdentifier identifier, std::optional map_name, + std::optional room_name); + +std::optional GetCompletePanelIdentifierWithoutAnswer( + PanelIdentifier identifier, std::optional map_name, + std::optional room_name); + +std::optional GetCompleteKeyholderIdentifierWithoutKey( + KeyholderIdentifier identifier, const std::string& map_name, + std::optional room_name); + +} // namespace com::fourisland::lingo2_archipelago + +#endif /* TOOLS_UTIL_IDENTIFIERS_H_ */ diff --git a/tools/util/naming.cpp b/tools/util/naming.cpp index 0ae99f6..8229c6d 100644 --- a/tools/util/naming.cpp +++ b/tools/util/naming.cpp @@ -2,6 +2,8 @@ #include +namespace com::fourisland::lingo2_archipelago { + std::string GetLetterName(std::string key, bool level2) { std::ostringstream lettername_s; lettername_s << key; @@ -9,3 +11,5 @@ std::string GetLetterName(std::string key, bool level2) { return lettername_s.str(); } + +} // namespace com::fourisland::lingo2_archipelago diff --git a/tools/util/naming.h b/tools/util/naming.h index 9a68851..85e2db0 100644 --- a/tools/util/naming.h +++ b/tools/util/naming.h @@ -3,6 +3,10 @@ #include +namespace com::fourisland::lingo2_archipelago { + std::string GetLetterName(std::string key, bool level2); +} // namespace com::fourisland::lingo2_archipelago + #endif /* TOOLS_UTIL_NAMING_H_ */ -- cgit 1.4.1