diff options
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 47 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.cpp | 22 | ||||
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 13 |
4 files changed, 73 insertions, 13 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index aefb6fc..f50aa39 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -411,6 +411,19 @@ fs::path Dataloader::lookup_file(std::string_view path, bool print_error) const return {}; } +fs::path Dataloader::lookup_image_file(std::string_view path) const { + fs::path ret = lookup_file(path, false); + if (ret.empty()) { + // TODO - change search order so root order takes priority over extension replacement order + ret = lookup_file(append_string_views(StringUtils::remove_extension(path), ".dds"), false); + if (!ret.empty()) { + return ret; + } + Logger::error("Image lookup for ", path, " failed!"); + } + return ret; +} + template<typename _DirIterator, std::predicate<fs::path const&, fs::path const&> _Equiv> Dataloader::path_vector_t Dataloader::_lookup_files_in_dir(std::string_view path, fs::path const& extension) const { #if FILESYSTEM_NEEDS_FORWARD_SLASHES @@ -555,6 +568,36 @@ csv::Windows1252Parser Dataloader::parse_csv(fs::path const& path) { return _run_ovdl_parser<csv::Windows1252Parser, &_csv_parse>(path); } +bool Dataloader::_load_interface_files(UIManager& ui_manager) const { + static constexpr std::string_view interface_directory = "interface/"; + + bool ret = apply_to_files( + lookup_files_in_dir(interface_directory, ".gfx"), + [&ui_manager](fs::path const& file) -> bool { + return ui_manager.load_gfx_file(parse_defines(file).get_file_node()); + } + ); + ui_manager.lock_sprites(); + ui_manager.lock_fonts(); + + // Hard-coded example until the mechanism for requesting them from GDScript is fleshed out + static const std::vector<std::string_view> gui_files { + "province_interface.gui", "topbar.gui" + }; + for (std::string_view const& gui_file : gui_files) { + if (!ui_manager.load_gui_file( + gui_file, + parse_defines(lookup_file(append_string_views(interface_directory, gui_file))).get_file_node() + )) { + Logger::error("Failed to load interface gui file: ", gui_file); + ret = false; + } + } + ui_manager.lock_scenes(); + + return ret; +} + bool Dataloader::_load_pop_types( PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager ) const { @@ -798,6 +841,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const { bool ret = true; + if (!_load_interface_files(game_manager.get_ui_manager())) { + Logger::error("Failed to load interface files!"); + ret = false; + } if (!game_manager.get_modifier_manager().setup_modifier_effects()) { Logger::error("Failed to set up modifier effects!"); ret = false; diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp index 2123469..7c71763 100644 --- a/src/openvic-simulation/dataloader/Dataloader.hpp +++ b/src/openvic-simulation/dataloader/Dataloader.hpp @@ -12,6 +12,7 @@ namespace OpenVic { namespace fs = std::filesystem; struct GameManager; + class UIManager; struct PopManager; struct UnitManager; struct GoodManager; @@ -23,6 +24,7 @@ namespace OpenVic { private: path_vector_t roots; + bool _load_interface_files(UIManager& ui_manager) const; bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager) const; bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager) const; bool _load_map_dir(GameManager& game_manager) const; @@ -70,6 +72,8 @@ namespace OpenVic { * DAT-24 */ fs::path lookup_file(std::string_view path, bool print_error = true) const; + /* Checks alternate file endings, e.g. if "*.tga" doesn't exist then try "*.dds" */ + fs::path lookup_image_file(std::string_view path) const; path_vector_t lookup_files_in_dir(std::string_view path, fs::path const& extension) const; path_vector_t lookup_files_in_dir_recursive(std::string_view path, fs::path const& extension) const; path_vector_t lookup_basic_indentifier_prefixed_files_in_dir(std::string_view path, fs::path const& extension) const; diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 27d0f95..c412f33 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -76,10 +76,10 @@ node_callback_t NodeTools::expect_int_bool(callback_t<bool> callback) { return expect_identifier(expect_mapped_string(bool_map, callback)); } -node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback) { - return expect_identifier([callback](std::string_view identifier) -> bool { +node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback, int base) { + return expect_identifier([callback, base](std::string_view identifier) -> bool { bool successful = false; - const int64_t val = StringUtils::string_to_int64(identifier, &successful, 10); + const int64_t val = StringUtils::string_to_int64(identifier, &successful, base); if (successful) { return callback(val); } @@ -88,10 +88,10 @@ node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback) { }); } -node_callback_t NodeTools::expect_uint64(callback_t<uint64_t> callback) { - return expect_identifier([callback](std::string_view identifier) -> bool { +node_callback_t NodeTools::expect_uint64(callback_t<uint64_t> callback, int base) { + return expect_identifier([callback, base](std::string_view identifier) -> bool { bool successful = false; - const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10); + const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, base); if (successful) { return callback(val); } @@ -141,6 +141,10 @@ node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) { }; } +node_callback_t NodeTools::expect_colour_hex(callback_t<colour_t> callback) { + return expect_uint(callback, 16); +} + callback_t<std::string_view> NodeTools::expect_date_str(callback_t<Date> callback) { return [callback](std::string_view identifier) -> bool { bool successful = false; @@ -188,8 +192,12 @@ NodeCallback auto _expect_vec2(Callback<vec2_t<T>> auto callback) { }; } +static node_callback_t _expect_int(callback_t<ivec2_t::type> callback) { + return expect_int(callback); +} + node_callback_t NodeTools::expect_ivec2(callback_t<ivec2_t> callback) { - return _expect_vec2<int32_t, expect_int>(callback); + return _expect_vec2<ivec2_t::type, _expect_int>(callback); } node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) { diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index a23fb4f..1ca6cf0 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -73,11 +73,11 @@ namespace OpenVic { node_callback_t expect_bool(callback_t<bool> callback); node_callback_t expect_int_bool(callback_t<bool> callback); - node_callback_t expect_int64(callback_t<int64_t> callback); - node_callback_t expect_uint64(callback_t<uint64_t> callback); + node_callback_t expect_int64(callback_t<int64_t> callback, int base = 10); + node_callback_t expect_uint64(callback_t<uint64_t> callback, int base = 10); template<std::signed_integral T> - NodeCallback auto expect_int(callback_t<T> callback) { + NodeCallback auto expect_int(callback_t<T> callback, int base = 10) { return expect_int64([callback](int64_t val) -> bool { if (static_cast<int64_t>(std::numeric_limits<T>::lowest()) <= val && val <= static_cast<int64_t>(std::numeric_limits<T>::max())) { @@ -88,11 +88,11 @@ namespace OpenVic { static_cast<int64_t>(std::numeric_limits<T>::max()), "])" ); return false; - }); + }, base); } template<std::integral T> - NodeCallback auto expect_uint(callback_t<T> callback) { + NodeCallback auto expect_uint(callback_t<T> callback, int base = 10) { return expect_uint64([callback](uint64_t val) -> bool { if (val <= static_cast<uint64_t>(std::numeric_limits<T>::max())) { return callback(val); @@ -101,12 +101,13 @@ namespace OpenVic { "Invalid uint: ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])" ); return false; - }); + }, base); } callback_t<std::string_view> expect_fixed_point_str(callback_t<fixed_point_t> callback); node_callback_t expect_fixed_point(callback_t<fixed_point_t> callback); node_callback_t expect_colour(callback_t<colour_t> callback); + node_callback_t expect_colour_hex(callback_t<colour_t> callback); callback_t<std::string_view> expect_date_str(callback_t<Date> callback); node_callback_t expect_date(callback_t<Date> callback); |