aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp19
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp8
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp30
3 files changed, 36 insertions, 21 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 6f55267..56cf40c 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -283,21 +283,34 @@ bool Dataloader::_load_interface_files(UIManager& ui_manager) const {
ui_manager.lock_sprites();
ui_manager.lock_fonts();
- // Hard-coded example until the mechanism for requesting them from GDScript is fleshed out
+ /* Hard-coded GUI file names, might be replaced with a dynamic system but everything should still be loaded on startup. */
static const std::vector<std::string_view> gui_files {
- "province_interface.gui", "topbar.gui"
+ /* Contains generic listbox scrollbar */
+ "core",
+
+ /* Over-map menus */
+ "province_interface", "topbar", "menubar", "outliner",
+
+ /* Nation management screens */
+ "country_production", "country_budget", "country_technology", "country_politics", "country_pops", "country_trade",
+ "country_diplomacy", "country_military"
};
+ static constexpr std::string_view gui_file_extension = ".gui";
+
ui_manager.reserve_more_scenes(gui_files.size());
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()
+ gui_file, parse_defines(lookup_file(
+ append_string_views(interface_directory, gui_file, gui_file_extension)
+ )).get_file_node()
)) {
Logger::error("Failed to load interface gui file: ", gui_file);
ret = false;
}
}
+
ui_manager.lock_scenes();
return ret;
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 7ab0dbe..297937a 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -169,6 +169,14 @@ node_callback_t NodeTools::expect_date(callback_t<Date> callback) {
return expect_identifier(expect_date_str(callback));
}
+node_callback_t NodeTools::expect_date_string(callback_t<Date> callback) {
+ return expect_string(expect_date_str(callback));
+}
+
+node_callback_t NodeTools::expect_date_identifier_or_string(callback_t<Date> callback) {
+ return expect_identifier_or_string(expect_date_str(callback));
+}
+
node_callback_t NodeTools::expect_years(callback_t<Timespan> callback) {
return expect_uint<Timespan::day_t>([callback](Timespan::day_t val) -> bool {
return callback(Timespan::from_years(val));
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 54b61d0..c41c09e 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -119,6 +119,8 @@ namespace OpenVic {
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);
+ node_callback_t expect_date_identifier_or_string(callback_t<Date> callback);
node_callback_t expect_years(callback_t<Timespan> callback);
node_callback_t expect_months(callback_t<Timespan> callback);
node_callback_t expect_days(callback_t<Timespan> callback);
@@ -371,15 +373,15 @@ namespace OpenVic {
template<typename T, StringMapCase Case>
Callback<std::string_view> auto expect_mapped_string(
- template_string_map_t<T, Case> const& map, Callback<T> auto callback
+ template_string_map_t<T, Case> const& map, Callback<T> auto callback, bool warn = false
) {
- return [&map, callback](std::string_view string) -> bool {
+ return [&map, callback, warn](std::string_view string) -> bool {
const typename template_string_map_t<T, Case>::const_iterator it = map.find(string);
if (it != map.end()) {
return callback(it->second);
}
- Logger::error("String not found in map: ", string);
- return false;
+ Logger::warn_or_error(warn, "String not found in map: ", string);
+ return warn;
};
}
@@ -470,24 +472,14 @@ namespace OpenVic {
};
}
- template<typename... Args>
- bool warn_or_error(bool warn, Args&&... args) {
- if (warn) {
- Logger::warning(std::forward<Args>(args)...);
- return true;
- } else {
- Logger::error(std::forward<Args>(args)...);
- return false;
- }
- }
-
template<typename T, typename U, typename... SetArgs>
Callback<T> auto set_callback(tsl::ordered_set<U, SetArgs...>& set, bool warn = false) {
return [&set, warn](T val) -> bool {
if (set.emplace(std::move(val)).second) {
return true;
}
- return warn_or_error(warn, "Duplicate set entry: \"", val, "\"");
+ Logger::warn_or_error(warn, "Duplicate set entry: \"", val, "\"");
+ return warn;
};
}
@@ -497,7 +489,8 @@ namespace OpenVic {
if (set.emplace(&val).second) {
return true;
}
- return warn_or_error(warn, "Duplicate set entry: \"", &val, "\"");
+ Logger::warn_or_error(warn, "Duplicate set entry: \"", &val, "\"");
+ return warn;
};
}
@@ -509,7 +502,8 @@ namespace OpenVic {
if (map.emplace(key, std::move(value)).second) {
return true;
}
- return warn_or_error(warn, "Duplicate map entry with key: \"", key, "\"");
+ Logger::warn_or_error(warn, "Duplicate map entry with key: \"", key, "\"");
+ return warn;
};
}
}