Skip to content

Commit

Permalink
Stub navy output. (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingofmen authored Oct 26, 2023
1 parent fa3ccea commit 4d4ae03
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/out_hoi4/countries/out_countries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void out::OutputCountries(std::string_view output_name,
auto oob_file = fmt::format("output/{}/history/units/{}_1936.txt", output_name, tag);
commonItems::TryCopyFile("configurables/division_templates.txt", oob_file);
OutputCountryUnits(oob_file, country);
OutputCountryNavy(output_name, country);
OutputFocusTree(output_name, tag);
}

Expand Down
51 changes: 50 additions & 1 deletion src/out_hoi4/countries/out_countries_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,53 @@ TEST(Outhoi4CountriesOutcountriesTests, NationalFocusFilesAreCreated)
country_file_two.close();
}

} // namespace out

TEST(Outhoi4CountriesOutcountriesTests, NavyFilesAreCreated)
{
CreateFolders("NavyFilesAreCreated");

OutputCountries("NavyFilesAreCreated",
{
{"TAG", hoi4::Country({.tag = "TAG"})},
{"TWO", hoi4::Country({.tag = "TWO"})},
},
{});

EXPECT_TRUE(commonItems::DoesFileExist("output/NavyFilesAreCreated/history/units/TAG_1936_Naval.txt"));
std::ifstream country_file_one("output/NavyFilesAreCreated/history/units/TAG_1936_Naval.txt");
ASSERT_TRUE(country_file_one.is_open());
std::stringstream country_file_one_stream;
std::copy(std::istreambuf_iterator<char>(country_file_one),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(country_file_one_stream));
country_file_one.close();

EXPECT_TRUE(commonItems::DoesFileExist("output/NavyFilesAreCreated/history/units/TAG_1936_Naval_Legacy.txt"));
std::ifstream legacy_file_one("output/NavyFilesAreCreated/history/units/TAG_1936_Naval_Legacy.txt");
ASSERT_TRUE(legacy_file_one.is_open());
std::stringstream legacy_file_one_stream;
std::copy(std::istreambuf_iterator<char>(legacy_file_one),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(legacy_file_one_stream));
legacy_file_one.close();

EXPECT_TRUE(commonItems::DoesFileExist("output/NavyFilesAreCreated/history/units/TWO_1936_Naval.txt"));
std::ifstream country_file_two("output/NavyFilesAreCreated/history/units/TWO_1936_Naval.txt");
ASSERT_TRUE(country_file_two.is_open());
std::stringstream country_file_two_stream;
std::copy(std::istreambuf_iterator<char>(country_file_two),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(country_file_two_stream));
country_file_two.close();

EXPECT_TRUE(commonItems::DoesFileExist("output/NavyFilesAreCreated/history/units/TWO_1936_Naval_Legacy.txt"));
std::ifstream legacy_file_two("output/NavyFilesAreCreated/history/units/TWO_1936_Naval_Legacy.txt");
ASSERT_TRUE(legacy_file_two.is_open());
std::stringstream legacy_file_two_stream;
std::copy(std::istreambuf_iterator<char>(legacy_file_two),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(legacy_file_two_stream));
legacy_file_two.close();
}

} // namespace out
25 changes: 25 additions & 0 deletions src/out_hoi4/countries/out_country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ void out::OutputCountryHistory(std::string_view output_name,

country_history << "if = {\n";
country_history << "\tlimit = { not = { has_dlc = \"Man the Guns\" } }\n";
country_history << fmt::format("\tset_naval_oob = {}_1936_Naval_Legacy\n", tag);
for (const auto& variant: country.GetLegacyShipVariants())
{
country_history << variant;
}
country_history << "}\n";
country_history << "if = {\n";
country_history << "\tlimit = { has_dlc = \"Man the Guns\" }\n";
country_history << fmt::format("\tset_naval_oob = {}_1936_Naval\n", tag);
for (const auto& variant: country.GetShipVariants())
{
country_history << variant;
Expand All @@ -247,6 +249,29 @@ void out::OutputCountryHistory(std::string_view output_name,
country_history.close();
}


void out::OutputCountryNavy(std::string_view output_name, const hoi4::Country& country)
{
const std::string& tag = country.GetTag();
const auto naval_file_name = fmt::format("output/{}/history/units/{}_1936_Naval.txt", output_name, tag);
std::ofstream navy(naval_file_name);
if (!navy.is_open())
{
throw std::runtime_error(fmt::format("Could not create {}", naval_file_name));
}
const auto legacy_file_name = fmt::format("output/{}/history/units/{}_1936_Naval_Legacy.txt", output_name, tag);
std::ofstream legacy(legacy_file_name);
if (!legacy.is_open())
{
throw std::runtime_error(fmt::format("Could not create {}", legacy_file_name));
}
navy << "# Dummy file\n";
legacy << "# Dummy file\n";
navy.close();
legacy.close();
}


void out::OutputCountryUnits(const std::string& oob_file, const hoi4::Country& country)
{
if (country.GetUnits().empty())
Expand Down
4 changes: 4 additions & 0 deletions src/out_hoi4/countries/out_country.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ void OutputCountryHistory(std::string_view output_name,
const hoi4::Country& country,
const std::map<int, hoi4::Character>& characters);

void OutputCountryNavy(std::string_view output_name, const hoi4::Country& country);

void OutputCountryUnits(const std::string& oob_file, const hoi4::Country& country);



} // namespace out


Expand Down
41 changes: 41 additions & 0 deletions src/out_hoi4/countries/out_country_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,11 @@ TEST(Outhoi4CountriesOutcountryTests, DefaultsAreSetInCountryHistoryFile)
expected_one << "# Starting tech\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { not = { has_dlc = \"Man the Guns\" } }\n";
expected_one << "\tset_naval_oob = TAG_1936_Naval_Legacy\n";
expected_one << "}\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { has_dlc = \"Man the Guns\" }\n";
expected_one << "\tset_naval_oob = TAG_1936_Naval\n";
expected_one << "}\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { has_dlc = \"By Blood Alone\" }\n";
Expand Down Expand Up @@ -410,9 +412,11 @@ TEST(Outhoi4CountriesOutcountryTests, IdeasAreOutputToCountryHistoryFile)
expected_one << "# Starting tech\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { not = { has_dlc = \"Man the Guns\" } }\n";
expected_one << "\tset_naval_oob = TAG_1936_Naval_Legacy\n";
expected_one << "}\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { has_dlc = \"Man the Guns\" }\n";
expected_one << "\tset_naval_oob = TAG_1936_Naval\n";
expected_one << "}\n";
expected_one << "if = {\n";
expected_one << "\tlimit = { has_dlc = \"By Blood Alone\" }\n";
Expand Down Expand Up @@ -598,6 +602,7 @@ TEST(Outhoi4CountriesOutcountryTests, EquipmentVariantsAreOutput)
const std::string expected_output =
"if = {\n"
"\tlimit = { not = { has_dlc = \"Man the Guns\" } }\n"
"\tset_naval_oob = TAG_1936_Naval_Legacy\n"
"\tcreate_equipment_variant = {\n"
"\t\tname = legacy_ship: variant_one\n"
"\t}\n"
Expand All @@ -607,6 +612,7 @@ TEST(Outhoi4CountriesOutcountryTests, EquipmentVariantsAreOutput)
"}\n"
"if = {\n"
"\tlimit = { has_dlc = \"Man the Guns\" }\n"
"\tset_naval_oob = TAG_1936_Naval\n"
"\tcreate_equipment_variant = {\n"
"\t\tname = ship: variant_one\n"
"\t}\n"
Expand Down Expand Up @@ -758,5 +764,40 @@ TEST(Outhoi4CountriesOutcountryTests, UnitsAreOutputToCountryOOBFile)
EXPECT_THAT(country_file_stream.str(), testing::HasSubstr(expected));
}

TEST(Outhoi4CountriesOutcountryTests, NaviesAreOutputToCountryNavalFiles)
{
commonItems::TryCreateFolder("output");
commonItems::TryCreateFolder("output/NaviesAreOutputToCountryNavalFiles");
commonItems::TryCreateFolder("output/NaviesAreOutputToCountryNavalFiles/history");
commonItems::TryCreateFolder("output/NaviesAreOutputToCountryNavalFiles/history/units");

const hoi4::Country country({.tag = "TAG"});
OutputCountryNavy("NaviesAreOutputToCountryNavalFiles", country);

const std::string naval_file = "output/NaviesAreOutputToCountryNavalFiles/history/units/TAG_1936_Naval.txt";
ASSERT_TRUE(commonItems::DoesFileExist(naval_file));
std::ifstream navy(naval_file);
ASSERT_TRUE(navy.is_open());
std::stringstream navy_stream;
std::copy(std::istreambuf_iterator<char>(navy),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(navy_stream));
navy.close();
const char* expected_navy = "Dummy file";
EXPECT_THAT(navy_stream.str(), testing::HasSubstr(expected_navy));

const std::string legacy_file = "output/NaviesAreOutputToCountryNavalFiles/history/units/TAG_1936_Naval_Legacy.txt";
ASSERT_TRUE(commonItems::DoesFileExist(legacy_file));
std::ifstream legacy(legacy_file);
ASSERT_TRUE(legacy.is_open());
std::stringstream legacy_stream;
std::copy(std::istreambuf_iterator<char>(legacy),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(legacy_stream));
legacy.close();
const char* expected_legacy = "Dummy file";
EXPECT_THAT(legacy_stream.str(), testing::HasSubstr(expected_legacy));
}


} // namespace out

0 comments on commit 4d4ae03

Please sign in to comment.