From 8271b1519e095ee3e7245cde2f0b54561c3ec619 Mon Sep 17 00:00:00 2001 From: hop311 Date: Tue, 14 Nov 2023 21:42:00 +0000 Subject: Bookmark loading + province and building cleanup --- src/openvic-simulation/misc/Define.cpp | 25 +++++++++++++------------ src/openvic-simulation/misc/Define.hpp | 7 ++++--- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'src/openvic-simulation/misc') diff --git a/src/openvic-simulation/misc/Define.cpp b/src/openvic-simulation/misc/Define.cpp index c866b5d..cfd96a6 100644 --- a/src/openvic-simulation/misc/Define.cpp +++ b/src/openvic-simulation/misc/Define.cpp @@ -37,27 +37,30 @@ bool DefineManager::add_define(std::string_view name, std::string&& value, Defin } Date DefineManager::get_start_date() const { - return *start_date; + return start_date ? *start_date : Date {}; } Date DefineManager::get_end_date() const { - return *end_date; + return end_date ? *end_date : Date {}; } -bool DefineManager::add_date_define(std::string_view name, Date date) { - if (name != "start_date" && name != "end_date") { +bool DefineManager::in_game_period(Date date) const { + if (start_date && end_date) { + return date.in_range(*start_date, *end_date); + } else { return false; } +} - bool ret = defines.add_item({ name, date.to_string(), Define::Type::None }); - +bool DefineManager::add_date_define(std::string_view name, Date date) { if (name == "start_date") { - start_date.reset(new Date(date)); + start_date = date; } else if (name == "end_date") { - end_date.reset(new Date(date)); + end_date = date; + } else { + return false; } - - return ret; + return defines.add_item({ name, date.to_string(), Define::Type::None }); } bool DefineManager::load_defines_file(ast::NodeCPtr root) { @@ -103,8 +106,6 @@ bool DefineManager::load_defines_file(ast::NodeCPtr root) { return ret; })(value); } else if (key == "start_date" || key == "end_date") { - using namespace std::placeholders; - return expect_identifier_or_string(expect_date_str([this, &key](Date date) -> bool { return add_date_define(key, date); }))(value); diff --git a/src/openvic-simulation/misc/Define.hpp b/src/openvic-simulation/misc/Define.hpp index be71f9d..46e4836 100644 --- a/src/openvic-simulation/misc/Define.hpp +++ b/src/openvic-simulation/misc/Define.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" @@ -32,8 +32,8 @@ namespace OpenVic { private: IdentifierRegistry defines; - std::unique_ptr start_date = nullptr; - std::unique_ptr end_date = nullptr; + std::optional start_date; + std::optional end_date; public: DefineManager(); @@ -44,6 +44,7 @@ namespace OpenVic { Date get_start_date() const; Date get_end_date() const; + bool in_game_period(Date date) const; bool load_defines_file(ast::NodeCPtr root); }; -- cgit v1.2.3-56-ga3b1