diff options
Diffstat (limited to 'tools/util')
| -rw-r--r-- | tools/util/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | tools/util/identifiers.cpp | 102 | ||||
| -rw-r--r-- | tools/util/identifiers.h | 85 | ||||
| -rw-r--r-- | tools/util/naming.cpp | 4 | ||||
| -rw-r--r-- | tools/util/naming.h | 4 |
5 files changed, 200 insertions, 0 deletions
| 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 @@ | |||
| 1 | find_package(Protobuf REQUIRED) | ||
| 2 | |||
| 1 | add_library(util | 3 | add_library(util |
| 4 | identifiers.cpp | ||
| 2 | naming.cpp | 5 | naming.cpp |
| 3 | ) | 6 | ) |
| 4 | set_property(TARGET util PROPERTY CXX_STANDARD 20) | 7 | set_property(TARGET util PROPERTY CXX_STANDARD 20) |
| 5 | set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) | 8 | set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) |
| 9 | target_include_directories(util PUBLIC ${CMAKE_BINARY_DIR}) | ||
| 10 | 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 @@ | |||
| 1 | #include "identifiers.h" | ||
| 2 | |||
| 3 | #include <string> | ||
| 4 | |||
| 5 | #include "proto/human.pb.h" | ||
| 6 | |||
| 7 | namespace com::fourisland::lingo2_archipelago { | ||
| 8 | |||
| 9 | std::optional<RoomIdentifier> GetCompleteRoomIdentifier( | ||
| 10 | RoomIdentifier identifier, std::optional<std::string> map_name) { | ||
| 11 | if (!identifier.has_map()) { | ||
| 12 | if (!map_name) { | ||
| 13 | return std::nullopt; | ||
| 14 | } | ||
| 15 | identifier.set_map(*map_name); | ||
| 16 | } | ||
| 17 | return identifier; | ||
| 18 | } | ||
| 19 | |||
| 20 | std::optional<DoorIdentifier> GetCompleteDoorIdentifier( | ||
| 21 | DoorIdentifier identifier, std::optional<std::string> map_name) { | ||
| 22 | if (!identifier.has_map()) { | ||
| 23 | if (!map_name) { | ||
| 24 | return std::nullopt; | ||
| 25 | } | ||
| 26 | identifier.set_map(*map_name); | ||
| 27 | } | ||
| 28 | return identifier; | ||
| 29 | } | ||
| 30 | |||
| 31 | std::optional<PortIdentifier> GetCompletePortIdentifier( | ||
| 32 | PortIdentifier identifier, std::optional<std::string> map_name, | ||
| 33 | std::optional<std::string> room_name) { | ||
| 34 | if (!identifier.has_map()) { | ||
| 35 | if (!map_name) { | ||
| 36 | return std::nullopt; | ||
| 37 | } | ||
| 38 | identifier.set_map(*map_name); | ||
| 39 | } | ||
| 40 | if (!identifier.has_room()) { | ||
| 41 | if (!room_name) { | ||
| 42 | return std::nullopt; | ||
| 43 | } | ||
| 44 | identifier.set_room(*room_name); | ||
| 45 | } | ||
| 46 | return identifier; | ||
| 47 | } | ||
| 48 | |||
| 49 | std::optional<PaintingIdentifier> GetCompletePaintingIdentifier( | ||
| 50 | PaintingIdentifier identifier, std::optional<std::string> map_name, | ||
| 51 | std::optional<std::string> room_name) { | ||
| 52 | if (!identifier.has_map()) { | ||
| 53 | if (!map_name) { | ||
| 54 | return std::nullopt; | ||
| 55 | } | ||
| 56 | identifier.set_map(*map_name); | ||
| 57 | } | ||
| 58 | if (!identifier.has_room()) { | ||
| 59 | if (!room_name) { | ||
| 60 | return std::nullopt; | ||
| 61 | } | ||
| 62 | identifier.set_room(*room_name); | ||
| 63 | } | ||
| 64 | return identifier; | ||
| 65 | } | ||
| 66 | |||
| 67 | std::optional<PanelIdentifier> GetCompletePanelIdentifierWithoutAnswer( | ||
| 68 | PanelIdentifier identifier, std::optional<std::string> map_name, | ||
| 69 | std::optional<std::string> room_name) { | ||
| 70 | if (!identifier.has_map()) { | ||
| 71 | if (!map_name) { | ||
| 72 | return std::nullopt; | ||
| 73 | } | ||
| 74 | identifier.set_map(*map_name); | ||
| 75 | } | ||
| 76 | if (!identifier.has_room()) { | ||
| 77 | if (!room_name) { | ||
| 78 | return std::nullopt; | ||
| 79 | } | ||
| 80 | identifier.set_room(*room_name); | ||
| 81 | } | ||
| 82 | identifier.clear_answer(); | ||
| 83 | return identifier; | ||
| 84 | } | ||
| 85 | |||
| 86 | std::optional<KeyholderIdentifier> GetCompleteKeyholderIdentifierWithoutKey( | ||
| 87 | KeyholderIdentifier identifier, const std::string& map_name, | ||
| 88 | std::optional<std::string> room_name) { | ||
| 89 | if (!identifier.has_map()) { | ||
| 90 | identifier.set_map(map_name); | ||
| 91 | } | ||
| 92 | if (!identifier.has_room()) { | ||
| 93 | if (!room_name) { | ||
| 94 | return std::nullopt; | ||
| 95 | } | ||
| 96 | identifier.set_room(*room_name); | ||
| 97 | } | ||
| 98 | identifier.clear_key(); | ||
| 99 | return identifier; | ||
| 100 | } | ||
| 101 | |||
| 102 | } // 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 @@ | |||
| 1 | #ifndef TOOLS_UTIL_IDENTIFIERS_H_ | ||
| 2 | #define TOOLS_UTIL_IDENTIFIERS_H_ | ||
| 3 | |||
| 4 | #include <optional> | ||
| 5 | #include <string> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "proto/human.pb.h" | ||
| 9 | |||
| 10 | namespace com::fourisland::lingo2_archipelago { | ||
| 11 | |||
| 12 | class RoomIdentifierLess { | ||
| 13 | public: | ||
| 14 | bool operator()(const RoomIdentifier& lhs, const RoomIdentifier& rhs) const { | ||
| 15 | return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name()); | ||
| 16 | } | ||
| 17 | }; | ||
| 18 | |||
| 19 | class DoorIdentifierLess { | ||
| 20 | public: | ||
| 21 | bool operator()(const DoorIdentifier& lhs, const DoorIdentifier& rhs) const { | ||
| 22 | return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name()); | ||
| 23 | } | ||
| 24 | }; | ||
| 25 | |||
| 26 | class PortIdentifierLess { | ||
| 27 | public: | ||
| 28 | bool operator()(const PortIdentifier& lhs, const PortIdentifier& rhs) const { | ||
| 29 | return std::tie(lhs.map(), lhs.room(), lhs.name()) < | ||
| 30 | std::tie(rhs.map(), rhs.room(), rhs.name()); | ||
| 31 | } | ||
| 32 | }; | ||
| 33 | |||
| 34 | class PaintingIdentifierLess { | ||
| 35 | public: | ||
| 36 | bool operator()(const PaintingIdentifier& lhs, | ||
| 37 | const PaintingIdentifier& rhs) const { | ||
| 38 | return std::tie(lhs.map(), lhs.room(), lhs.name()) < | ||
| 39 | std::tie(rhs.map(), rhs.room(), rhs.name()); | ||
| 40 | } | ||
| 41 | }; | ||
| 42 | |||
| 43 | class PanelIdentifierLess { | ||
| 44 | public: | ||
| 45 | bool operator()(const PanelIdentifier& lhs, | ||
| 46 | const PanelIdentifier& rhs) const { | ||
| 47 | return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.answer()) < | ||
| 48 | std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.answer()); | ||
| 49 | } | ||
| 50 | }; | ||
| 51 | |||
| 52 | class KeyholderIdentifierLess { | ||
| 53 | public: | ||
| 54 | bool operator()(const KeyholderIdentifier& lhs, | ||
| 55 | const KeyholderIdentifier& rhs) const { | ||
| 56 | return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.key()) < | ||
| 57 | std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.key()); | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | |||
| 61 | std::optional<RoomIdentifier> GetCompleteRoomIdentifier( | ||
| 62 | RoomIdentifier identifier, std::optional<std::string> map_name); | ||
| 63 | |||
| 64 | std::optional<DoorIdentifier> GetCompleteDoorIdentifier( | ||
| 65 | DoorIdentifier identifier, std::optional<std::string> map_name); | ||
| 66 | |||
| 67 | std::optional<PortIdentifier> GetCompletePortIdentifier( | ||
| 68 | PortIdentifier identifier, std::optional<std::string> map_name, | ||
| 69 | std::optional<std::string> room_name); | ||
| 70 | |||
| 71 | std::optional<PaintingIdentifier> GetCompletePaintingIdentifier( | ||
| 72 | PaintingIdentifier identifier, std::optional<std::string> map_name, | ||
| 73 | std::optional<std::string> room_name); | ||
| 74 | |||
| 75 | std::optional<PanelIdentifier> GetCompletePanelIdentifierWithoutAnswer( | ||
| 76 | PanelIdentifier identifier, std::optional<std::string> map_name, | ||
| 77 | std::optional<std::string> room_name); | ||
| 78 | |||
| 79 | std::optional<KeyholderIdentifier> GetCompleteKeyholderIdentifierWithoutKey( | ||
| 80 | KeyholderIdentifier identifier, const std::string& map_name, | ||
| 81 | std::optional<std::string> room_name); | ||
| 82 | |||
| 83 | } // namespace com::fourisland::lingo2_archipelago | ||
| 84 | |||
| 85 | #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 @@ | |||
| 2 | 2 | ||
| 3 | #include <sstream> | 3 | #include <sstream> |
| 4 | 4 | ||
| 5 | namespace com::fourisland::lingo2_archipelago { | ||
| 6 | |||
| 5 | std::string GetLetterName(std::string key, bool level2) { | 7 | std::string GetLetterName(std::string key, bool level2) { |
| 6 | std::ostringstream lettername_s; | 8 | std::ostringstream lettername_s; |
| 7 | lettername_s << key; | 9 | lettername_s << key; |
| @@ -9,3 +11,5 @@ std::string GetLetterName(std::string key, bool level2) { | |||
| 9 | 11 | ||
| 10 | return lettername_s.str(); | 12 | return lettername_s.str(); |
| 11 | } | 13 | } |
| 14 | |||
| 15 | } // 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 @@ | |||
| 3 | 3 | ||
| 4 | #include <string> | 4 | #include <string> |
| 5 | 5 | ||
| 6 | namespace com::fourisland::lingo2_archipelago { | ||
| 7 | |||
| 6 | std::string GetLetterName(std::string key, bool level2); | 8 | std::string GetLetterName(std::string key, bool level2); |
| 7 | 9 | ||
| 10 | } // namespace com::fourisland::lingo2_archipelago | ||
| 11 | |||
| 8 | #endif /* TOOLS_UTIL_NAMING_H_ */ | 12 | #endif /* TOOLS_UTIL_NAMING_H_ */ |
