aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic/pop/Pop.cpp13
-rw-r--r--src/openvic/pop/Religion.cpp46
2 files changed, 50 insertions, 9 deletions
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 445aec3..4e6533a 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -145,10 +145,10 @@ return_t PopManager::load_pop_type_file(std::filesystem::path const& path, ast::
return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr root) const {
static PopType const* type = get_pop_type_by_identifier("test_pop_type");
Culture const* culture = nullptr;
- static Religion const* religion = religion_manager.get_religion_by_identifier("test_religion");
+ Religion const* religion = nullptr;
Pop::pop_size_t size = 0;
- return_t ret = NodeTools::expect_assign(root, [this, &culture, &size](std::string_view, ast::NodeCPtr pop_node) -> return_t {
+ return_t ret = NodeTools::expect_assign(root, [this, &culture, &religion, &size](std::string_view, ast::NodeCPtr pop_node) -> return_t {
return NodeTools::expect_dictionary_keys(pop_node, {
{ "culture", { true, false, [this, &culture](ast::NodeCPtr node) -> return_t {
return NodeTools::expect_identifier(node, [&culture, this](std::string_view identifier) -> return_t {
@@ -158,7 +158,14 @@ return_t PopManager::load_pop_into_province(Province& province, ast::NodeCPtr ro
return FAILURE;
});
} } },
- { "religion", { true, false, NodeTools::success_callback } },
+ { "religion", { true, false, [this, &religion](ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_identifier(node, [&religion, this](std::string_view identifier) -> return_t {
+ religion = religion_manager.get_religion_by_identifier(identifier);
+ if (religion != nullptr) return SUCCESS;
+ Logger::error("Invalid pop religion: ", identifier);
+ return FAILURE;
+ });
+ } } },
{ "size", { true, false, [&size](ast::NodeCPtr node) -> return_t {
return NodeTools::expect_uint(node, [&size](uint64_t val) -> return_t {
if (val > 0) {
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index 8ff143f..3102bfb 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -81,12 +81,46 @@ Religion const* ReligionManager::get_religion_by_identifier(const std::string_vi
return_t ReligionManager::load_religion_file(ast::NodeCPtr root) {
- // TODO - religion loading
-
- return_t ret = add_religion_group("test_religion_group");
+ return_t ret = NodeTools::expect_dictionary(root, [this](std::string_view key, ast::NodeCPtr value) -> return_t {
+ return_t ret = NodeTools::expect_dictionary_keys(value, {}, true);
+ if (add_religion_group(key) != SUCCESS) ret = FAILURE;
+ return ret;
+ }, true);
lock_religion_groups();
- if (add_religion("test_religion", 0xFF0000, get_religion_group_by_identifier("test_religion_group"), 1, false) != SUCCESS)
- ret = FAILURE;
+
+ if (NodeTools::expect_dictionary(root, [this](std::string_view religion_group_key, ast::NodeCPtr religion_group_value) -> return_t {
+
+ ReligionGroup const* religion_group = get_religion_group_by_identifier(religion_group_key);
+
+ return NodeTools::expect_dictionary(religion_group_value, [this, religion_group](std::string_view key, ast::NodeCPtr value) -> return_t {
+ colour_t colour = NULL_COLOUR;
+ Religion::icon_t icon = 0;
+ bool pagan = true;
+
+ return_t ret = NodeTools::expect_dictionary_keys(value, {
+ { "icon", { true, false, [&icon](ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_int(node, [&icon](Religion::icon_t val) -> return_t {
+ icon = val;
+ return SUCCESS;
+ });
+ } } },
+ { "color", { true, false, [&colour](ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_colour(node, [&colour](colour_t val) -> return_t {
+ colour = val;
+ return SUCCESS;
+ });
+ } } },
+ { "pagan", { false, false, [&pagan](ast::NodeCPtr node) -> return_t {
+ return NodeTools::expect_bool(node, [&pagan](bool val) -> return_t {
+ pagan = val;
+ return SUCCESS;
+ });
+ } } }
+ });
+ if (add_religion(key, colour, religion_group, icon, pagan) != SUCCESS) ret = FAILURE;
+ return ret;
+ });
+ }, true) != SUCCESS) ret = FAILURE;
lock_religions();
return ret;
-}
+} \ No newline at end of file