diff options
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.cpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GFXObject.cpp | 11 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GFXObject.hpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GUI.cpp | 10 | ||||
-rw-r--r-- | src/openvic-simulation/interface/GUI.hpp | 7 | ||||
-rw-r--r-- | src/openvic-simulation/types/Format.hpp | 40 | ||||
-rw-r--r-- | src/openvic-simulation/types/TextFormat.hpp | 5 |
8 files changed, 32 insertions, 68 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 1339dd3..d6b57ca 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -13,6 +13,7 @@ #include <range/v3/view/enumerate.hpp> #include "openvic-simulation/types/Colour.hpp" +#include "openvic-simulation/types/TextFormat.hpp" #include "openvic-simulation/utility/Getters.hpp" using namespace OpenVic; @@ -264,6 +265,17 @@ NodeCallback auto _expect_vec2(Callback<vec2_t<T>> auto&& callback) { }; } +node_callback_t NodeTools::_expect_text_format_t(callback_t<text_format_t> callback){ + static const string_map_t<text_format_t> format_map = { + { "left", text_format_t::left }, + { "right", text_format_t::right }, + { "centre", text_format_t::centre }, + { "center", text_format_t::centre }, + { "justified", text_format_t::justified } + }; + return expect_identifier(expect_mapped_string(format_map, callback)); +} + static node_callback_t _expect_int(callback_t<ivec2_t::type> callback) { return expect_int(callback); } diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 6464e72..8265c94 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -14,6 +14,7 @@ #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/IndexedMap.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" +#include "openvic-simulation/types/TextFormat.hpp" #include "openvic-simulation/types/unlabelledVec.hpp" #include "openvic-simulation/types/Vector.hpp" #include "openvic-simulation/utility/Getters.hpp" @@ -151,6 +152,8 @@ namespace OpenVic { /* Expect a hexadecimal value representing a colour in ARGB format. */ node_callback_t expect_colour_hex(callback_t<colour_argb_t> callback); + node_callback_t _expect_text_format_t(callback_t<text_format_t> callback); + callback_t<std::string_view> expect_date_str(callback_t<Date> callback); node_callback_t expect_date(callback_t<Date> callback); node_callback_t expect_date_string(callback_t<Date> callback); diff --git a/src/openvic-simulation/interface/GFXObject.cpp b/src/openvic-simulation/interface/GFXObject.cpp index bd23cce..bd720c3 100644 --- a/src/openvic-simulation/interface/GFXObject.cpp +++ b/src/openvic-simulation/interface/GFXObject.cpp @@ -1,4 +1,5 @@ #include "GFXObject.hpp" +#include "openvic-simulation/dataloader/NodeTools.hpp" using namespace OpenVic; using namespace OpenVic::GFX; @@ -297,7 +298,7 @@ bool ProgressBar3d::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map /* core.gfx */ AnimatedMapText::TextBlock::TextBlock() : -text {}, colour {}, font {}, text_position {}, size {}, format {} {} +text {}, colour {}, font {}, text_position {}, size {}, format { text_format_t::left } {} AnimatedMapText::AnimatedMapText() : speed { 1 }, scale { 1 }, position {}, textblock {} {} @@ -306,12 +307,6 @@ speed { 1 }, scale { 1 }, position {}, textblock {} {} bool AnimatedMapText::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) { bool ret = Object::_fill_key_map(key_map); - //TODO: we should probably extract format_t to a datatype file for both here and GFXSprite to interit from - using enum format_t; - static const string_map_t<format_t> format_map = { - { "left", left }, { "right", right }, { "centre", centre }, { "center", centre }, { "justified", justified } - }; - ret &= add_key_map_entries(key_map, "speed", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(speed)), "position", ZERO_OR_ONE, expect_v2_vector3(assign_variable_callback(position)), @@ -322,7 +317,7 @@ bool AnimatedMapText::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_m "font", ONE_EXACTLY, expect_string(assign_variable_callback_string(textblock.font)), "position", ONE_EXACTLY, expect_fvec2(assign_variable_callback(textblock.text_position)), "size", ONE_EXACTLY, expect_fvec2(assign_variable_callback(textblock.size)), - "format", ONE_EXACTLY, expect_identifier(expect_mapped_string(format_map, assign_variable_callback(textblock.format))) + "format", ONE_EXACTLY, _expect_text_format_t(assign_variable_callback(textblock.format)) ) ); diff --git a/src/openvic-simulation/interface/GFXObject.hpp b/src/openvic-simulation/interface/GFXObject.hpp index 233a1fd..e25339f 100644 --- a/src/openvic-simulation/interface/GFXObject.hpp +++ b/src/openvic-simulation/interface/GFXObject.hpp @@ -2,6 +2,7 @@ #include "openvic-simulation/interface/LoadBase.hpp" #include <openvic-simulation/types/unlabelledVec.hpp> +#include <openvic-simulation/types/TextFormat.hpp> namespace OpenVic::GFX { @@ -266,18 +267,12 @@ namespace OpenVic::GFX { class AnimatedMapText final : public Object { friend std::unique_ptr<AnimatedMapText> std::make_unique<AnimatedMapText>(); - //TODO: This format_t enum is the same as in GFXSprite, should this all be extracted - //to another datatype file? - enum class format_t { - left, centre, right, justified - }; + using enum text_format_t; public: struct TextBlock { friend class AnimatedMapText; - //format_t taken from GUI's AlignedElement, this is overall very similar - private: std::string PROPERTY(text); colour_t PROPERTY(colour); @@ -285,9 +280,8 @@ namespace OpenVic::GFX { fvec2_t PROPERTY(text_position); fvec2_t PROPERTY(size); - //expect_fvec2(assign_variable_callback(position)), - format_t PROPERTY(format); + text_format_t PROPERTY(format); TextBlock(); diff --git a/src/openvic-simulation/interface/GUI.cpp b/src/openvic-simulation/interface/GUI.cpp index 4f42b86..7a11d77 100644 --- a/src/openvic-simulation/interface/GUI.cpp +++ b/src/openvic-simulation/interface/GUI.cpp @@ -160,17 +160,13 @@ bool Checkbox::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIM return ret; } -AlignedElement::AlignedElement() : format { format_t::left } {} +AlignedElement::AlignedElement() : format { text_format_t::left } {} bool AlignedElement::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIManager const& ui_manager) { bool ret = Element::_fill_key_map(key_map, ui_manager); - using enum format_t; - static const string_map_t<format_t> format_map = { - { "left", left }, { "right", right }, { "centre", centre }, { "center", centre }, { "justified", justified } - }; ret &= add_key_map_entries(key_map, - "format", ZERO_OR_ONE, expect_identifier(expect_mapped_string(format_map, assign_variable_callback(format)) - )); + "format", ZERO_OR_ONE, _expect_text_format_t(assign_variable_callback(format)) + ); return ret; } diff --git a/src/openvic-simulation/interface/GUI.hpp b/src/openvic-simulation/interface/GUI.hpp index a86d432..2c6566d 100644 --- a/src/openvic-simulation/interface/GUI.hpp +++ b/src/openvic-simulation/interface/GUI.hpp @@ -1,6 +1,7 @@ #pragma once #include "openvic-simulation/interface/GFXSprite.hpp" +#include "openvic-simulation/types/TextFormat.hpp" namespace OpenVic { class UIManager; @@ -177,12 +178,10 @@ namespace OpenVic::GUI { class AlignedElement : public Element { public: - enum class format_t { - left, centre, right, justified - }; + using enum text_format_t; private: - format_t PROPERTY(format); + text_format_t PROPERTY(format); protected: AlignedElement(); diff --git a/src/openvic-simulation/types/Format.hpp b/src/openvic-simulation/types/Format.hpp deleted file mode 100644 index 301ffa6..0000000 --- a/src/openvic-simulation/types/Format.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "openvic-simulation/types/IdentifierRegistry.hpp" -#include <openvic-simulation/dataloader/NodeTools.hpp> -//#include "openvic-simulation/interface/GFXSprite.hpp" - -using namespace OpenVic; -using namespace OpenVic::NodeTools; - -struct AlignedElement { -public: - enum class format_t { - left, centre, right, justified - }; - -private: - format_t PROPERTY(format); - -protected: - AlignedElement(); - - //bool _fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIManager const& ui_manager) override; - - bool _fill_key_map(case_insensitive_key_map_t& key_map) { - using enum format_t; - static const string_map_t<format_t> format_map = { - { "left", left }, { "right", right }, { "centre", centre }, { "center", centre }, { "justified", justified } - }; - return add_key_map_entries(key_map, - "format", ZERO_OR_ONE, expect_identifier(expect_mapped_string(format_map, assign_variable_callback(format)) - )); - } - - -public: - AlignedElement(AlignedElement&&) = default; - virtual ~AlignedElement() = default; - - //OV_DETAIL_GET_TYPE -}; diff --git a/src/openvic-simulation/types/TextFormat.hpp b/src/openvic-simulation/types/TextFormat.hpp new file mode 100644 index 0000000..1601527 --- /dev/null +++ b/src/openvic-simulation/types/TextFormat.hpp @@ -0,0 +1,5 @@ +#pragma once + +enum class text_format_t { + left, centre, right, justified +};
\ No newline at end of file |