From 470d8c45522543aa161b3b98c5e6991024c8a5af Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Mon, 2 Oct 2023 17:09:45 -0500 Subject: Implement positions.txt Loading --- src/openvic-simulation/map/Province.cpp | 54 +++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'src/openvic-simulation/map/Province.cpp') diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index fa514eb..b0717b9 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -34,9 +34,57 @@ Province::life_rating_t Province::get_life_rating() const { } bool Province::load_positions(BuildingManager const& building_manager, ast::NodeCPtr root) { - // TODO - implement province position loading - // (root is the dictionary after the province identifier) - return true; + return expect_dictionary_keys( + "text_position", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.text))(node); + }, + "text_rotation", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fixed_point(assign_variable_callback(positions.text_rotation))(node); + }, + "text_scale", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fixed_point(assign_variable_callback(positions.text_scale))(node); + }, + "unit", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.unit))(node); + }, + "town", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.city))(node); + }, + "city", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.city))(node); + }, + "factory", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.factory))(node); + }, + "building_construction", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.building_construction))(node); + }, + "military_construction", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.military_construction))(node); + }, + "building_position", ZERO_OR_ONE, expect_dictionary_keys( + "fort", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.fort))(node); + }, + "railroad", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.railroad))(node); + }, + "naval_base", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fvec2(assign_variable_callback(positions.navalbase))(node); + } + ), + "building_rotation", ZERO_OR_ONE, expect_dictionary_keys( + "fort", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fixed_point(assign_variable_callback(positions.fort_rotation))(node); + }, + "railroad", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fixed_point(assign_variable_callback(positions.railroad_rotation))(node); + }, + "naval_base", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { + return expect_fixed_point(assign_variable_callback(positions.navalbase_rotation))(node); + } + ) + )(root); } bool Province::add_building(BuildingInstance&& building_instance) { -- cgit v1.2.3-56-ga3b1 From 88b29173f9ec49f6145b0d5bef678499f450d4d7 Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Tue, 3 Oct 2023 16:32:13 -0500 Subject: Fix positions.txt Edge Cases --- src/openvic-simulation/map/Province.cpp | 9 +++++++-- src/openvic-simulation/map/Province.hpp | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/openvic-simulation/map/Province.cpp') diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index b0717b9..199e472 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -82,8 +82,13 @@ bool Province::load_positions(BuildingManager const& building_manager, ast::Node }, "naval_base", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { return expect_fixed_point(assign_variable_callback(positions.navalbase_rotation))(node); - } - ) + }, + "aeroplane_factory", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; } /* see below */ + ), + /* the below are esoteric clausewitz leftovers that either have no impact or whose functionality is lost to time */ + "spawn_railway_track", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; }, + "railroad_visibility", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; }, + "building_nudge", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; } )(root); } diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index a621182..31b5d4c 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -54,7 +54,6 @@ namespace OpenVic { fixed_point_t railroad_rotation; fvec2_t navalbase; fixed_point_t navalbase_rotation; - /* fvec2_t spawn_railway_track; treating as extraneous until proven need */ }; -- cgit v1.2.3-56-ga3b1 From f47e9ca8d7c711ba6e8befd318dd5fb600e93359 Mon Sep 17 00:00:00 2001 From: Joel Machens Date: Tue, 3 Oct 2023 16:50:52 -0500 Subject: Refactor Callbacks --- src/openvic-simulation/map/Province.cpp | 68 +++++++++------------------------ 1 file changed, 19 insertions(+), 49 deletions(-) (limited to 'src/openvic-simulation/map/Province.cpp') diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 199e472..5b1a130 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -35,60 +35,30 @@ Province::life_rating_t Province::get_life_rating() const { bool Province::load_positions(BuildingManager const& building_manager, ast::NodeCPtr root) { return expect_dictionary_keys( - "text_position", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.text))(node); - }, - "text_rotation", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fixed_point(assign_variable_callback(positions.text_rotation))(node); - }, - "text_scale", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fixed_point(assign_variable_callback(positions.text_scale))(node); - }, - "unit", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.unit))(node); - }, - "town", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.city))(node); - }, - "city", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.city))(node); - }, - "factory", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.factory))(node); - }, - "building_construction", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.building_construction))(node); - }, - "military_construction", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.military_construction))(node); - }, + "text_position", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.text)), + "text_rotation", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.text_rotation)), + "text_scale", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.text_scale)), + "unit", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.unit)), + "town", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.city)), + "city", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.city)), + "factory", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.factory)), + "building_construction", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.building_construction)), + "military_construction", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.military_construction)), "building_position", ZERO_OR_ONE, expect_dictionary_keys( - "fort", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.fort))(node); - }, - "railroad", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.railroad))(node); - }, - "naval_base", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fvec2(assign_variable_callback(positions.navalbase))(node); - } + "fort", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.fort)), + "railroad", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.railroad)), + "naval_base", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(positions.navalbase)) ), "building_rotation", ZERO_OR_ONE, expect_dictionary_keys( - "fort", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fixed_point(assign_variable_callback(positions.fort_rotation))(node); - }, - "railroad", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fixed_point(assign_variable_callback(positions.railroad_rotation))(node); - }, - "naval_base", ZERO_OR_ONE, [this](ast::NodeCPtr node) -> bool { - return expect_fixed_point(assign_variable_callback(positions.navalbase_rotation))(node); - }, - "aeroplane_factory", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; } /* see below */ + "fort", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.fort_rotation)), + "railroad", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.railroad_rotation)), + "naval_base", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(positions.navalbase_rotation)), + "aeroplane_factory", ZERO_OR_ONE, success_callback /* see below */ ), /* the below are esoteric clausewitz leftovers that either have no impact or whose functionality is lost to time */ - "spawn_railway_track", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; }, - "railroad_visibility", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; }, - "building_nudge", ZERO_OR_ONE, [](ast::NodeCPtr _) -> bool { return true; } + "spawn_railway_track", ZERO_OR_ONE, success_callback, + "railroad_visibility", ZERO_OR_ONE, success_callback, + "building_nudge", ZERO_OR_ONE, success_callback )(root); } -- cgit v1.2.3-56-ga3b1