Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ endif()

set(MAIN_SOURCE "src/main.cpp")

set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/hello_world.cpp")
set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/ck3_world/county_capital_identifier.cpp")
set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/ck3_world/titles_importer.cpp")
set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/output/ck3/output_titles.cpp")

Expand Down Expand Up @@ -257,7 +257,7 @@ include_directories("./external/commonItems/external/googletest/googletest/inclu
include_directories("./external/commonItems/external/googletest/googlemock")
include_directories("./external/commonItems/external/googletest/googlemock/include")

set(TEST_SOURCES ${TEST_SOURCES} "src/hello_world_test.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/ck3_world/county_capital_identifier_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/ck3_world/titles_importer_tests.cpp")
set(TEST_SOURCES ${TEST_SOURCES} "src/output/ck3/output_titles_tests.cpp")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
e_test_empire = {
k_test_kingdom = {
d_test_duchy = {
c_test_county = {
b_test_barony = {
province = 1
}
b_test_barony_two = {
province = 2
}
}
}
}
}
e_test_empire_two = {
k_test_kingdom_two = {
d_test_duchy_two = {
c_test_county_two = {
b_test_barony_two = {
province = 3
}
b_test_barony_four = {
province = 4
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
e_test_empire_three = {
k_test_kingdom_three = {
d_test_duchy_three = {
c_test_county_three = {
b_test_barony_three = {
province = 5
}
b_test_barony_six = {
province = 6
}
}
}
}
}
116 changes: 116 additions & 0 deletions src/ck3_world/county_capital_identifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "src/ck3_world/county_capital_identifier.hpp"

#include <external/commonItems/Log.h>
#include <external/commonItems/ModLoader/ModFilesystem.h>
#include <external/commonItems/Parser.h>
#include <external/commonItems/ParserHelpers.h>

#include <format>
#include <istream>
#include <set>



namespace ck3_world
{

std::set<int> IdentifyCountyCapitals(const commonItems::ModFilesystem& ck3_root)
{
std::set<int> county_capitals;

commonItems::parser barony_parser;
barony_parser.registerKeyword("province", [&county_capitals](std::istream& input) {
county_capitals.emplace(commonItems::getInt(input));
});
barony_parser.IgnoreUnregisteredItems();

commonItems::parser county_parser;
bool found_a_barony = false;
county_parser.registerRegex("b_.*", [&barony_parser, &found_a_barony](const std::string&, std::istream& input) {
if (found_a_barony)
{
commonItems::ignoreItem("", input);
}
else
{
barony_parser.parseStream(input);
found_a_barony = true;
}
});
county_parser.IgnoreUnregisteredItems();

commonItems::parser duchy_parser;
duchy_parser.registerRegex("c_.*", [&county_parser, &found_a_barony](const std::string&, std::istream& input) {
found_a_barony = false;
county_parser.parseStream(input);
});
duchy_parser.IgnoreUnregisteredItems();

commonItems::parser kingdom_parser;
kingdom_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) {
duchy_parser.parseStream(input);
});
kingdom_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) {
county_parser.parseStream(input);
});
kingdom_parser.IgnoreUnregisteredItems();

commonItems::parser empire_parser;
empire_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) {
kingdom_parser.parseStream(input);
});
empire_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) {
duchy_parser.parseStream(input);
});
empire_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) {
county_parser.parseStream(input);
});
empire_parser.IgnoreUnregisteredItems();

commonItems::parser hegemony_parser;
hegemony_parser.registerRegex("e_.*", [&empire_parser](const std::string&, std::istream& input) {
empire_parser.parseStream(input);
});
hegemony_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) {
kingdom_parser.parseStream(input);
});
hegemony_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) {
duchy_parser.parseStream(input);
});
hegemony_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) {
county_parser.parseStream(input);
});
hegemony_parser.IgnoreUnregisteredItems();

commonItems::parser file_parser;
file_parser.registerRegex("h_.*", [&hegemony_parser](const std::string&, std::istream& input) {
hegemony_parser.parseStream(input);
});
file_parser.registerRegex("e_.*", [&empire_parser](const std::string&, std::istream& input) {
empire_parser.parseStream(input);
});
file_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) {
kingdom_parser.parseStream(input);
});
file_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) {
duchy_parser.parseStream(input);
});
file_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) {
county_parser.parseStream(input);
});
file_parser.IgnoreUnregisteredItems();

for (const auto& file: ck3_root.GetAllFilesInFolder("game/common/landed_titles"))
{
if (file.extension() != ".txt")
{
continue;
}
file_parser.parseFile(file);
}

Log(LogLevel::Info) << std::format("Identified {} capitals", county_capitals.size());
return county_capitals;
}

} // namespace ck3_world
15 changes: 15 additions & 0 deletions src/ck3_world/county_capital_identifier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once


#include <external/commonItems/ModLoader/ModFilesystem.h>

#include <set>



namespace ck3_world
{

std::set<int> IdentifyCountyCapitals(const commonItems::ModFilesystem& ck3_root);

} // namespace ck3_world
24 changes: 24 additions & 0 deletions src/ck3_world/county_capital_identifier_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <external/commonItems/ModLoader/ModFilesystem.h>
#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>

#include <set>

#include "src/ck3_world/county_capital_identifier.hpp"



namespace ck3_world
{

TEST(Ck3worldCountyCapitalIdentifierTests, CountyCapitalsCanBeIdentified)
{
const commonItems::ModFilesystem mod_filesystem(
"./test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified",
{});
const std::set<int> county_capitals = IdentifyCountyCapitals(mod_filesystem);

EXPECT_THAT(county_capitals, testing::ElementsAre(1, 3, 5));
}

} // namespace ck3_world
18 changes: 0 additions & 18 deletions src/hello_world.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/hello_world.hpp

This file was deleted.

15 changes: 0 additions & 15 deletions src/hello_world_test.cpp

This file was deleted.

10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

#include <exception>
#include <map>
#include <set>
#include <string>
#include <vector>

#include "ck3_world/titles_importer.hpp"
#include "hello_world.hpp"
#include "output/ck3/output_titles.hpp"
#include "src/ck3_world/county_capital_identifier.hpp"
#include "src/ck3_world/titles_importer.hpp"
#include "src/output/ck3/output_titles.hpp"



Expand All @@ -20,9 +21,8 @@
"C:/Program Files (x86)/Steam/steamapps/common/Crusader Kings III",
{});
const std::map<std::filesystem::path, std::vector<std::string>> titles = ck3_world::ImportTitles(mod_filesystem);
[[maybe_unused]] const std::set<int> county_capitals = ck3_world::IdentifyCountyCapitals(mod_filesystem);

Check warning on line 24 in src/main.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main.cpp#L24

Variable 'county_capitals' is assigned a value that is never used.
output::OutputCk3Titles("test_mod", titles);

scenario_generator::HelloWorld();
}
catch (std::exception& e)
{
Expand Down
Loading