Skip to content

Commit

Permalink
Stories decisions (#691)
Browse files Browse the repository at this point in the history
* 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
Idhrendur authored Dec 22, 2024
1 parent 5470353 commit 5910a32
Show file tree
Hide file tree
Showing 20 changed files with 535 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/characters/hoi4_chara
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/countries/hoi4_countries_converter.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/countries/hoi4_country.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/countries/hoi4_country_converter.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/decisions/decisions_category_importer.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/diplomacy/hoi4_war_converter.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/focus_trees/focus.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/hoi4_world/focus_trees/focus_importer.cpp")
Expand Down Expand Up @@ -127,6 +128,8 @@ set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/characters/out_characte
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/countries/out_countries.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/countries/out_country.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/decisions/out_decisions.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/decisions/out_decisions_categories.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/decisions/out_decisions_category.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/diplomacy/out_war.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/focus_trees/out_focus.cpp")
set(CONVERTER_SOURCES ${CONVERTER_SOURCES} "src/out_hoi4/focus_trees/out_focus_tree.cpp")
Expand Down Expand Up @@ -389,6 +392,7 @@ set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/characters/hoi4_character_tests
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/countries/hoi4_countries_converter_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/countries/hoi4_country_converter_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/countries/hoi4_country_converter_tests_tech.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/decisions/decisions_category_importer_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/diplomacy/hoi4_war_converter_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/focus_trees/focus_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/hoi4_world/focus_trees/focus_importer_tests.cpp")
Expand Down Expand Up @@ -455,6 +459,8 @@ set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/characters/out_character_tests.cp
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/countries/out_countries_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/countries/out_country_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/decisions/out_decisions_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/decisions/out_decisions_categories_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/decisions/out_decisions_category_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/diplomacy/out_war_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/flags/out_flags_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/out_hoi4/focus_trees/out_focus_tests.cpp")
Expand Down
23 changes: 23 additions & 0 deletions data/configurables/stories/italy_unification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ unification_italy = {
}
}

decisions_categories={
sample_decision_category={
icon=generic_form_nation
visible={
}
}
}
}


Expand Down Expand Up @@ -234,6 +241,14 @@ unification_italy_2 = {
set_cosmetic_tag = ITA_UNIFIED
}
}

decisions_categories={
sample_decision_category={
icon=generic_form_nation
visible={
}
}
}
}


Expand Down Expand Up @@ -360,4 +375,12 @@ unification_italy_3 = {
set_cosmetic_tag = ITA_UNIFIED
}
}

decisions_categories={
sample_decision_category={
icon=generic_form_nation
visible={
}
}
}
}
33 changes: 33 additions & 0 deletions src/hoi4_world/decisions/decisions_category.h
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
53 changes: 53 additions & 0 deletions src/hoi4_world/decisions/decisions_category_importer.cpp
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_};
}
41 changes: 41 additions & 0 deletions src/hoi4_world/decisions/decisions_category_importer.h
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 src/hoi4_world/decisions/decisions_category_importer_tests.cpp
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
5 changes: 5 additions & 0 deletions src/hoi4_world/roles/role.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "src/hoi4_world/decisions/decisions_category.h"
#include "src/hoi4_world/focus_trees/focus.h"
#include "src/hoi4_world/roles/repeat_focus.h"

Expand All @@ -25,6 +26,7 @@ struct RoleOptions
std::vector<Focus> focuses;
std::vector<RepeatFocus> repeat_focuses;
std::vector<std::string> removed_focuses;
std::vector<DecisionsCategory> decisions_categories;
std::vector<std::string> decisions;
std::vector<std::string> events;
};
Expand All @@ -43,6 +45,7 @@ class Role
focuses_(std::move(options.focuses)),
repeat_focuses_(std::move(options.repeat_focuses)),
removed_focuses_(std::move(options.removed_focuses)),
decisions_categories_(std::move(options.decisions_categories)),
decisions_(std::move(options.decisions)),
events_(std::move(options.events))
{
Expand All @@ -57,6 +60,7 @@ class Role
[[nodiscard]] const std::vector<Focus>& GetFocuses() const { return focuses_; }
[[nodiscard]] const std::vector<RepeatFocus>& GetRepeatFocuses() const { return repeat_focuses_; }
[[nodiscard]] const std::vector<std::string>& GetRemovedFocuses() const { return removed_focuses_; }
[[nodiscard]] const std::vector<DecisionsCategory>& GetDecisionsCategories() const { return decisions_categories_; }
[[nodiscard]] const std::vector<std::string>& GetDecisions() const { return decisions_; }
[[nodiscard]] const std::vector<std::string>& GetEvents() const { return events_; }

Expand All @@ -72,6 +76,7 @@ class Role
std::vector<Focus> focuses_;
std::vector<RepeatFocus> repeat_focuses_;
std::vector<std::string> removed_focuses_;
std::vector<DecisionsCategory> decisions_categories_;
std::vector<std::string> decisions_;
std::vector<std::string> events_;
};
Expand Down
10 changes: 10 additions & 0 deletions src/hoi4_world/roles/role_importer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#include "src/hoi4_world/roles/role_importer.h"

#include "external/commonItems/CommonRegexes.h"
#include "external/commonItems/ParserHelpers.h"



hoi4::RoleImporter::RoleImporter()
{
decisions_categories_parser_.registerRegex(commonItems::catchallRegex,
[this](std::string name, std::istream& input) {
role_options_.decisions_categories.emplace_back(
decisions_category_importer_.GetDecisionsCategory(name, input));
});

role_parser_.registerKeyword("category", [this](std::istream& input) {
role_options_.category = commonItems::getString(input);
});
Expand Down Expand Up @@ -33,6 +40,9 @@ hoi4::RoleImporter::RoleImporter()
role_parser_.registerKeyword("removed_focus", [this](std::istream& input) {
role_options_.removed_focuses.emplace_back(commonItems::stringOfItem(input).getString());
});
role_parser_.registerKeyword("decisions_categories", [this](std::istream& input) {
decisions_categories_parser_.parseStream(input);
});
role_parser_.registerKeyword("decision", [this](std::istream& input) {
role_options_.decisions.emplace_back(commonItems::stringOfItem(input).getString());
});
Expand Down
3 changes: 3 additions & 0 deletions src/hoi4_world/roles/role_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


#include "external/commonItems/Parser.h"
#include "src/hoi4_world/decisions/decisions_category_importer.h"
#include "src/hoi4_world/focus_trees/focus_importer.h"
#include "src/hoi4_world/roles/repeat_focus_importer.h"
#include "src/hoi4_world/roles/role.h"
Expand All @@ -27,6 +28,8 @@ class RoleImporter
commonItems::parser role_parser_;
FocusImporter focus_importer_;
RepeatFocusImporter repeat_focus_importer_;
DecisionsCategoryImporter decisions_category_importer_;
commonItems::parser decisions_categories_parser_;
};

}; // namespace hoi4
Expand Down
Loading

0 comments on commit 5910a32

Please sign in to comment.