aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Define.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/misc/Define.hpp')
-rw-r--r--src/openvic-simulation/misc/Define.hpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/openvic-simulation/misc/Define.hpp b/src/openvic-simulation/misc/Define.hpp
index 3f7b3dc..7d8fbf7 100644
--- a/src/openvic-simulation/misc/Define.hpp
+++ b/src/openvic-simulation/misc/Define.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include <optional>
-
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
@@ -11,35 +9,66 @@ namespace OpenVic {
struct Define : HasIdentifier {
friend struct DefineManager;
- enum class Type : unsigned char { Date, Country, Economy, Military, Diplomacy, Pops, Ai, Graphics };
+ enum class Type : unsigned char { Unknown, Date, Country, Economy, Military, Diplomacy, Pops, Ai, Graphics };
+
+ static std::string_view type_to_string(Type type);
+ // This only accepts type names found in defines.lua, so it will never return Type::Date
+ static Type string_to_type(std::string_view str);
private:
std::string PROPERTY(value);
const Type PROPERTY(type);
- Define(std::string_view new_identifier, std::string&& new_value, Type new_type);
+ Define(std::string_view new_identifier, std::string_view new_value, Type new_type);
public:
Define(Define&&) = default;
- fixed_point_t get_value_as_fp() const;
- int64_t get_value_as_int() const;
- uint64_t get_value_as_uint() const;
+ Date get_value_as_date(bool* successful = nullptr) const;
+ fixed_point_t get_value_as_fp(bool* successful = nullptr) const;
+ int64_t get_value_as_int(bool* successful = nullptr) const;
+ uint64_t get_value_as_uint(bool* successful = nullptr) const;
};
+ std::ostream& operator<<(std::ostream& os, Define::Type type);
+
struct DefineManager {
private:
IdentifierRegistry<Define> IDENTIFIER_REGISTRY(define);
- std::optional<Date> start_date;
- std::optional<Date> end_date;
+ // Date
+ Date PROPERTY(start_date); // start_date
+ Date PROPERTY(end_date); // end_date
+
+ // Country
+
+ // Economy
+
+ // Military
+
+ // Diplomacy
+
+ // Pops
+
+ // Ai
+
+ // Graphics
+
+ template<typename T>
+ bool load_define(T& value, Define::Type type, std::string_view name) const;
+
+ template<Timespan (*Func)(Timespan::day_t)>
+ bool _load_define_timespan(Timespan& value, Define::Type type, std::string_view name) const;
+
+ bool load_define_days(Timespan& value, Define::Type type, std::string_view name) const;
+ bool load_define_months(Timespan& value, Define::Type type, std::string_view name) const;
+ bool load_define_years(Timespan& value, Define::Type type, std::string_view name) const;
public:
- bool add_define(std::string_view name, std::string&& value, Define::Type type);
- bool add_date_define(std::string_view name, Date date);
+ DefineManager();
+
+ bool add_define(std::string_view name, std::string_view value, Define::Type type);
- Date get_start_date() const;
- Date get_end_date() const;
bool in_game_period(Date date) const;
bool load_defines_file(ast::NodeCPtr root);