aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/Dataloader.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-07 23:18:08 +0100
committer hop311 <hop3114@gmail.com>2023-11-12 17:55:39 +0100
commitfd686eadf81e85bd4993a483adcefd6a153d259f (patch)
treee59e8a1531d96a37872373f6262eff8ed45da1ff /src/openvic-simulation/dataloader/Dataloader.cpp
parentc8983f5cda0b396b76c9d1491cf4c8ff5997d420 (diff)
GUI and GFX file loading
Diffstat (limited to 'src/openvic-simulation/dataloader/Dataloader.cpp')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp47
1 files changed, 47 insertions, 0 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;