-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add code for a decision category. * Category names should be included. * Decision category can be added to role * Store decision categories from roles. * More storage bits. * Output decision categories. * Test fixes * Name fixes. * Fix how categories are imported. * Provide a sample category. * Tests for outputting decision category. * Add test for output of decisions categories.
- Loading branch information
Showing
20 changed files
with
535 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORY_H | ||
#define SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORY_H | ||
|
||
|
||
|
||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
||
|
||
namespace hoi4 | ||
{ | ||
|
||
struct DecisionsCategory | ||
{ | ||
std::string name; | ||
std::string icon; | ||
std::string picture; | ||
std::optional<int> priority; | ||
std::string allowed; | ||
std::string visible; | ||
std::string visibility_type; | ||
std::vector<std::pair<std::string, std::string>> extra_items; | ||
|
||
std::strong_ordering operator<=>(const DecisionsCategory& rhs) const = default; | ||
}; | ||
|
||
} // namespace hoi4 | ||
|
||
|
||
|
||
#endif // SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "src/hoi4_world/decisions/decisions_category_importer.h" | ||
|
||
#include "external/commonItems/CommonRegexes.h" | ||
#include "external/commonItems/ParserHelpers.h" | ||
|
||
|
||
|
||
hoi4::DecisionsCategoryImporter::DecisionsCategoryImporter() | ||
{ | ||
parser.registerKeyword("name", [this](std::istream& the_stream) { | ||
name_ = commonItems::getString(the_stream); | ||
}); | ||
parser.registerKeyword("icon", [this](std::istream& the_stream) { | ||
icon_ = commonItems::getString(the_stream); | ||
}); | ||
parser.registerKeyword("picture", [this](std::istream& the_stream) { | ||
picture_ = commonItems::getString(the_stream); | ||
}); | ||
parser.registerKeyword("priority", [this](std::istream& the_stream) { | ||
priority_ = commonItems::getInt(the_stream); | ||
}); | ||
parser.registerKeyword("allowed", [this](std::istream& the_stream) { | ||
allowed_ = commonItems::stringOfItem(the_stream).getString(); | ||
}); | ||
parser.registerKeyword("visible", [this](std::istream& the_stream) { | ||
visible_ = commonItems::stringOfItem(the_stream).getString(); | ||
}); | ||
parser.registerKeyword("visibility_type", [this](std::istream& the_stream) { | ||
visibility_type_ = commonItems::stringOfItem(the_stream).getString(); | ||
}); | ||
parser.registerRegex(commonItems::catchallRegex, [this](const std::string& itemName, std::istream& the_stream) { | ||
extra_items_.push_back(std::make_pair(itemName, commonItems::stringOfItem(the_stream).getString())); | ||
}); | ||
} | ||
|
||
|
||
|
||
hoi4::DecisionsCategory hoi4::DecisionsCategoryImporter::GetDecisionsCategory(std::string_view name, | ||
std::istream& the_stream) | ||
{ | ||
name_ = name; | ||
icon_.clear(); | ||
picture_.clear(); | ||
priority_.reset(); | ||
allowed_.clear(); | ||
visible_.clear(); | ||
visibility_type_.clear(); | ||
extra_items_.clear(); | ||
|
||
parser.parseStream(the_stream); | ||
|
||
return {name_, icon_, picture_, priority_, allowed_, visible_, visibility_type_, extra_items_}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORYIMPORTER_H | ||
#define SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORYIMPORTER_H | ||
|
||
|
||
|
||
#include <istream> | ||
|
||
#include "decisions_category.h" | ||
#include "external/commonItems/Parser.h" | ||
#include "src/hoi4_world/decisions/decisions_category.h" | ||
|
||
|
||
|
||
namespace hoi4 | ||
{ | ||
|
||
class DecisionsCategoryImporter | ||
{ | ||
public: | ||
DecisionsCategoryImporter(); | ||
|
||
[[nodiscard]] DecisionsCategory GetDecisionsCategory(std::string_view name, std::istream& the_stream); | ||
|
||
private: | ||
commonItems::parser parser; | ||
|
||
std::string name_; | ||
std::string icon_; | ||
std::string picture_; | ||
std::optional<int> priority_; | ||
std::string allowed_; | ||
std::string visible_; | ||
std::string visibility_type_; | ||
std::vector<std::pair<std::string, std::string>> extra_items_; | ||
}; | ||
|
||
} // namespace hoi4 | ||
|
||
|
||
|
||
#endif // SRC_HOI4WORLD_DECISIONS_DECISIONSCATEGORYIMPORTER_H |
77 changes: 77 additions & 0 deletions
77
src/hoi4_world/decisions/decisions_category_importer_tests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <sstream> | ||
|
||
#include "external/commonItems/external/googletest/googlemock/include/gmock/gmock-matchers.h" | ||
#include "external/commonItems/external/googletest/googletest/include/gtest/gtest.h" | ||
#include "src/hoi4_world/decisions/decisions_category.h" | ||
#include "src/hoi4_world/decisions/decisions_category_importer.h" | ||
|
||
|
||
namespace hoi4 | ||
{ | ||
|
||
TEST(Hoi4worldDecisionsDecisionscategoryimporterTests, DefaultsAreDefaulted) | ||
{ | ||
std::stringstream input; | ||
input << "= {\n"; | ||
input << "}"; | ||
const DecisionsCategory decisions_category = | ||
hoi4::DecisionsCategoryImporter{}.GetDecisionsCategory("test_name", input); | ||
|
||
EXPECT_EQ(decisions_category.name, "test_name"); | ||
EXPECT_TRUE(decisions_category.icon.empty()); | ||
EXPECT_TRUE(decisions_category.picture.empty()); | ||
EXPECT_FALSE(decisions_category.priority.has_value()); | ||
EXPECT_TRUE(decisions_category.allowed.empty()); | ||
EXPECT_TRUE(decisions_category.visible.empty()); | ||
EXPECT_TRUE(decisions_category.visibility_type.empty()); | ||
EXPECT_TRUE(decisions_category.extra_items.empty()); | ||
} | ||
|
||
|
||
TEST(HoI4World_Decisions_DecisionsCategoryTests, ItemsCanBeSet) | ||
{ | ||
std::stringstream input; | ||
input << "= {\n"; | ||
input << "\ticon = generic_research\n"; | ||
input << "\tpicture = GFX_decision_cat_picture_naval_treaties\n"; | ||
input << "\tpriority = 100\n"; | ||
input << "\tallowed = {\n"; | ||
input << "\t\thas_dlc = \"Man the Guns\"\n"; | ||
input << "\t}\n"; | ||
input << "\tvisible = {\n"; | ||
input << "\t\tis_debug = yes\n"; | ||
input << "\t}\n"; | ||
input << "\tvisibility_type = map_and_decisions_view\n"; | ||
input << "\textra_item_one = {\n"; | ||
input << "\t}\n"; | ||
input << "\textra_item_two = {\n"; | ||
input << "\t\tcan_it_have_stuff_inside = yes\n"; | ||
input << "\t}\n"; | ||
input << "}"; | ||
const DecisionsCategory decisions_category = | ||
hoi4::DecisionsCategoryImporter{}.GetDecisionsCategory("category_name", input); | ||
|
||
EXPECT_EQ(decisions_category.name, "category_name"); | ||
EXPECT_EQ(decisions_category.icon, "generic_research"); | ||
EXPECT_EQ(decisions_category.picture, "GFX_decision_cat_picture_naval_treaties"); | ||
EXPECT_EQ(decisions_category.priority.value_or(0), 100); | ||
EXPECT_EQ(decisions_category.allowed, | ||
"= {\n" | ||
"\t\thas_dlc = \"Man the Guns\"\n" | ||
"\t}"); | ||
EXPECT_EQ(decisions_category.visible, | ||
"= {\n" | ||
"\t\tis_debug = yes\n" | ||
"\t}"); | ||
EXPECT_EQ(decisions_category.visibility_type, "= map_and_decisions_view"); | ||
EXPECT_THAT(decisions_category.extra_items, | ||
testing::ElementsAre(std::pair{"extra_item_one", | ||
"= {\n" | ||
"\t}"}, | ||
std::pair{"extra_item_two", | ||
"= {\n" | ||
"\t\tcan_it_have_stuff_inside = yes\n" | ||
"\t}"})); | ||
} | ||
|
||
} // namespace hoi4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.