aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/interface
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/interface')
-rw-r--r--src/openvic-simulation/interface/GFX.cpp5
-rw-r--r--src/openvic-simulation/interface/GFX.hpp4
-rw-r--r--src/openvic-simulation/interface/UI.cpp6
3 files changed, 10 insertions, 5 deletions
diff --git a/src/openvic-simulation/interface/GFX.cpp b/src/openvic-simulation/interface/GFX.cpp
index d7b9042..0ec2954 100644
--- a/src/openvic-simulation/interface/GFX.cpp
+++ b/src/openvic-simulation/interface/GFX.cpp
@@ -7,8 +7,9 @@ using namespace OpenVic::NodeTools;
Font::Font(std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname)
: HasIdentifierAndAlphaColour { new_identifier, new_colour, false }, fontname { new_fontname } {}
-node_callback_t Sprite::expect_sprite(callback_t<std::unique_ptr<Sprite>&&> callback) {
- return expect_dictionary_keys(
+node_callback_t Sprite::expect_sprites(length_callback_t length_callback, callback_t<std::unique_ptr<Sprite>&&> callback) {
+ return expect_dictionary_keys_and_length(
+ length_callback,
"spriteType", ZERO_OR_MORE, _expect_instance<Sprite, TextureSprite>(callback),
"progressbartype", ZERO_OR_MORE, _expect_instance<Sprite, ProgressBar>(callback),
"PieChartType", ZERO_OR_MORE, _expect_instance<Sprite, PieChart>(callback),
diff --git a/src/openvic-simulation/interface/GFX.hpp b/src/openvic-simulation/interface/GFX.hpp
index 2bae4b3..efd2293 100644
--- a/src/openvic-simulation/interface/GFX.hpp
+++ b/src/openvic-simulation/interface/GFX.hpp
@@ -36,7 +36,9 @@ namespace OpenVic::GFX {
OV_DETAIL_GET_BASE_TYPE(Sprite)
OV_DETAIL_GET_TYPE
- static NodeTools::node_callback_t expect_sprite(NodeTools::callback_t<std::unique_ptr<Sprite>&&> callback);
+ static NodeTools::node_callback_t expect_sprites(
+ NodeTools::length_callback_t length_callback, NodeTools::callback_t<std::unique_ptr<Sprite>&&> callback
+ );
};
class TextureSprite final : public Sprite {
diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp
index 344fc15..b977406 100644
--- a/src/openvic-simulation/interface/UI.cpp
+++ b/src/openvic-simulation/interface/UI.cpp
@@ -39,7 +39,8 @@ bool UIManager::_load_font(ast::NodeCPtr node) {
bool UIManager::load_gfx_file(ast::NodeCPtr root) {
return expect_dictionary_keys(
- "spriteTypes", ZERO_OR_ONE, Sprite::expect_sprite(
+ "spriteTypes", ZERO_OR_ONE, Sprite::expect_sprites(
+ NodeTools::reserve_length_callback(sprites),
[this](std::unique_ptr<Sprite>&& sprite) -> bool {
/* TODO - more checks on duplicates (the false here reduces them from
* errors to warnings). The repeats in vanilla are identical (simple
@@ -64,7 +65,8 @@ bool UIManager::load_gfx_file(ast::NodeCPtr root) {
return sprites.add_item(std::move(sprite), duplicate_warning_callback);
}
),
- "bitmapfonts", ZERO_OR_ONE, expect_dictionary(
+ "bitmapfonts", ZERO_OR_ONE, expect_dictionary_reserve_length(
+ fonts,
[this](std::string_view key, ast::NodeCPtr node) -> bool {
if (key != "bitmapfont") {
Logger::error("Invalid bitmapfonts key: ", key);