aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/openvic-extension/LoadGameCompatibility.cpp7
-rw-r--r--extension/src/openvic-extension/LoadLocalisation.cpp33
-rw-r--r--extension/src/openvic-extension/LoadLocalisation.hpp14
-rw-r--r--game/src/Game/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd2
-rw-r--r--game/src/Game/Theme/PieChart/PieChart.gd4
6 files changed, 46 insertions, 14 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 6278a35f4704574933464700026d8deb997da5c
+Subproject 46bbbb038e5fa21e25fa33c4fee84e4b1469088
diff --git a/extension/src/openvic-extension/LoadGameCompatibility.cpp b/extension/src/openvic-extension/LoadGameCompatibility.cpp
index e8e3314..b696315 100644
--- a/extension/src/openvic-extension/LoadGameCompatibility.cpp
+++ b/extension/src/openvic-extension/LoadGameCompatibility.cpp
@@ -5,6 +5,7 @@
#include <openvic-simulation/utility/BMP.hpp>
+#include "openvic-extension/LoadLocalisation.hpp"
#include "openvic-extension/Utilities.hpp"
using namespace godot;
@@ -83,7 +84,6 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
err = FAILED;
}
- game_manager.map.lock_regions();
if (_load_terrain_variants_compatibility_mode(
std_to_godot_string(dataloader.lookup_file(terrain_image_file).string()),
std_to_godot_string(dataloader.lookup_file(terrain_texture_file).string())
@@ -102,6 +102,11 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
UtilityFunctions::push_error("Failed to hardcoded defines!");
err = FAILED;
}
+ if (!dataloader.load_localisation_files(LoadLocalisation::add_message)) {
+ UtilityFunctions::push_error("Failed to load localisation!");
+ err = FAILED;
+ }
+
return err;
}
diff --git a/extension/src/openvic-extension/LoadLocalisation.cpp b/extension/src/openvic-extension/LoadLocalisation.cpp
index dc7702c..9ab7298 100644
--- a/extension/src/openvic-extension/LoadLocalisation.cpp
+++ b/extension/src/openvic-extension/LoadLocalisation.cpp
@@ -5,6 +5,8 @@
#include <godot_cpp/classes/translation_server.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
+#include "openvic-extension/Utilities.hpp"
+
using namespace godot;
using namespace OpenVic;
@@ -30,7 +32,7 @@ LoadLocalisation::~LoadLocalisation() {
singleton = nullptr;
}
-Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref<Translation> translation) {
+Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref<Translation> translation) const {
const Ref<FileAccess> file = FileAccess::open(file_path, FileAccess::ModeFlags::READ);
Error err = FileAccess::get_open_error();
if (err != OK || file.is_null()) {
@@ -57,7 +59,7 @@ Error LoadLocalisation::_load_file_into_translation(String const& file_path, Ref
return err;
}
-Ref<Translation> LoadLocalisation::_get_translation(String const& locale) {
+Ref<Translation> LoadLocalisation::_get_translation(String const& locale) const {
TranslationServer* server = TranslationServer::get_singleton();
if (server == nullptr) {
UtilityFunctions::push_error("Failed to get TranslationServer singleton");
@@ -72,14 +74,14 @@ Ref<Translation> LoadLocalisation::_get_translation(String const& locale) {
return translation;
}
-Error LoadLocalisation::load_file(String const& file_path, String const& locale) {
+Error LoadLocalisation::load_file(String const& file_path, String const& locale) const {
return _load_file_into_translation(file_path, _get_translation(locale));
}
/* REQUIREMENTS
* FS-18, FS-24, FS-25
*/
-Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& locale) {
+Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& locale) const {
if (!DirAccess::dir_exists_absolute(dir_path)) {
UtilityFunctions::push_error("Locale directory does not exist: ", dir_path);
return FAILED;
@@ -109,7 +111,7 @@ Error LoadLocalisation::load_locale_dir(String const& dir_path, String const& lo
/* REQUIREMENTS
* FS-23
*/
-Error LoadLocalisation::load_localisation_dir(String const& dir_path) {
+Error LoadLocalisation::load_localisation_dir(String const& dir_path) const {
if (!DirAccess::dir_exists_absolute(dir_path)) {
UtilityFunctions::push_error("Localisation directory does not exist: ", dir_path);
return FAILED;
@@ -134,3 +136,24 @@ Error LoadLocalisation::load_localisation_dir(String const& dir_path) {
}
return err;
}
+bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation) {
+ static Ref<Translation> translations[Dataloader::_LocaleCount] = { nullptr };
+ Ref<Translation>& translation = translations[locale];
+ if (translation.is_null()) {
+ translation = singleton->_get_translation(Dataloader::locale_names[locale]);
+ if (translation.is_null()) {
+ UtilityFunctions::push_error("Failed to get translation object: ", Dataloader::locale_names[locale]);
+ return false;
+ }
+ }
+ const StringName godot_key = std_to_godot_string(std::string { key });
+ const StringName godot_localisation = std_to_godot_string(std::string { localisation });
+ if (0) {
+ const StringName old_localisation = translation->get_message(godot_key);
+ if (!old_localisation.is_empty()) {
+ UtilityFunctions::push_warning("Changing translation ", godot_key, " (", Dataloader::locale_names[locale], ") from \"", old_localisation, "\" to \"", godot_localisation, "\"");
+ }
+ }
+ translation->add_message(godot_key, godot_localisation);
+ return true;
+}
diff --git a/extension/src/openvic-extension/LoadLocalisation.hpp b/extension/src/openvic-extension/LoadLocalisation.hpp
index 04ec5c7..4f09ef3 100644
--- a/extension/src/openvic-extension/LoadLocalisation.hpp
+++ b/extension/src/openvic-extension/LoadLocalisation.hpp
@@ -2,6 +2,8 @@
#include <godot_cpp/classes/translation.hpp>
+#include <openvic-simulation/dataloader/Dataloader.hpp>
+
namespace OpenVic {
class LoadLocalisation : public godot::Object {
@@ -9,8 +11,8 @@ namespace OpenVic {
static LoadLocalisation* singleton;
- godot::Error _load_file_into_translation(godot::String const& file_path, godot::Ref<godot::Translation> translation);
- godot::Ref<godot::Translation> _get_translation(godot::String const& locale);
+ godot::Error _load_file_into_translation(godot::String const& file_path, godot::Ref<godot::Translation> translation) const;
+ godot::Ref<godot::Translation> _get_translation(godot::String const& locale) const;
protected:
static void _bind_methods();
@@ -21,8 +23,10 @@ namespace OpenVic {
LoadLocalisation();
~LoadLocalisation();
- godot::Error load_file(godot::String const& file_path, godot::String const& locale);
- godot::Error load_locale_dir(godot::String const& dir_path, godot::String const& locale);
- godot::Error load_localisation_dir(godot::String const& dir_path);
+ godot::Error load_file(godot::String const& file_path, godot::String const& locale) const;
+ godot::Error load_locale_dir(godot::String const& dir_path, godot::String const& locale) const;
+ godot::Error load_localisation_dir(godot::String const& dir_path) const;
+
+ static bool add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation);
};
}
diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd
index 0220be2..267bd5d 100644
--- a/game/src/Game/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd
+++ b/game/src/Game/GameSession/ProvinceOverviewPanel/ProvinceOverviewPanel.gd
@@ -104,7 +104,7 @@ func _set_building_row(index : int, building : Dictionary) -> void:
func _update_info() -> void:
_province_info = GameSingleton.get_province_info_from_index(_selected_index)
if _province_info:
- _province_name_label.text = _province_info.get(GameSingleton.get_province_info_province_key(),
+ _province_name_label.text = "PROV" + _province_info.get(GameSingleton.get_province_info_province_key(),
GameSingleton.get_province_info_province_key() + _missing_suffix)
_region_name_label.text = _province_info.get(GameSingleton.get_province_info_region_key(),
GameSingleton.get_province_info_region_key() + _missing_suffix)
diff --git a/game/src/Game/Theme/PieChart/PieChart.gd b/game/src/Game/Theme/PieChart/PieChart.gd
index cfd7917..4b81b28 100644
--- a/game/src/Game/Theme/PieChart/PieChart.gd
+++ b/game/src/Game/Theme/PieChart/PieChart.gd
@@ -193,13 +193,13 @@ func _create_tooltip(labelHovered : String) -> String:
for label in _slice_order:
var slice : SliceData = _slices.get(label)
var percent := _format_percent(slice.percentage)
- var entry : String = "%s %s%%" % [label, percent]
+ var entry : String = "%s %s%%" % [tr(label), percent]
if label == labelHovered:
entry = "[i][u][b]>>%s<<[/b][/u][/i]" % entry
slice_tooltips.push_back(entry)
# Slices are ordered smallest to largest, but here we want the opposite
slice_tooltips.reverse()
- return "[font_size=10]%s[/font_size]" % "\n".join(slice_tooltips)
+ return "[font_size=14]%s[/font_size]" % "\n".join(slice_tooltips)
# Angle from center.angle_to_point is measured from the +x axis,
# but the chart starts from +y