aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/openvic-extension/GameSingleton.cpp43
-rw-r--r--extension/src/openvic-extension/GameSingleton.hpp2
-rw-r--r--extension/src/openvic-extension/LoadGameCompatibility.cpp7
-rw-r--r--extension/src/openvic-extension/LoadGameOpenVic.cpp4
-rw-r--r--extension/src/openvic-extension/LoadLocalisation.cpp33
-rw-r--r--extension/src/openvic-extension/LoadLocalisation.hpp14
7 files changed, 64 insertions, 39 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 6278a35f4704574933464700026d8deb997da5c
+Subproject 005a8026bb424779a146e00cc48621ff1d72b80
diff --git a/extension/src/openvic-extension/GameSingleton.cpp b/extension/src/openvic-extension/GameSingleton.cpp
index a164b23..2d6f784 100644
--- a/extension/src/openvic-extension/GameSingleton.cpp
+++ b/extension/src/openvic-extension/GameSingleton.cpp
@@ -11,7 +11,7 @@ using namespace OpenVic;
TerrainVariant::TerrainVariant(const std::string_view new_identfier,
colour_t new_colour, Ref<Image> const& new_image)
- : HasIdentifierAndColour { new_identfier, new_colour, true },
+ : HasIdentifierAndColour { new_identfier, new_colour, true, false },
image { new_image } {}
Ref<Image> TerrainVariant::get_image() const {
@@ -43,7 +43,6 @@ void GameSingleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_selected_province", "index"), &GameSingleton::set_selected_province);
ClassDB::bind_method(D_METHOD("expand_building", "province_index", "building_type_identifier"), &GameSingleton::expand_building);
- ClassDB::bind_method(D_METHOD("get_good_icon_texture", "identifier"), &GameSingleton::get_good_icon_texture);
ClassDB::bind_method(D_METHOD("set_paused", "paused"), &GameSingleton::set_paused);
ClassDB::bind_method(D_METHOD("toggle_paused"), &GameSingleton::toggle_paused);
@@ -133,7 +132,7 @@ Error GameSingleton::setup_game() {
int32_t GameSingleton::get_province_index_from_uv_coords(Vector2 const& coords) const {
const size_t x_mod_w = UtilityFunctions::fposmod(coords.x, 1.0f) * get_width();
const size_t y_mod_h = UtilityFunctions::fposmod(coords.y, 1.0f) * get_height();
- return game_manager.map.get_province_index_at(x_mod_w, y_mod_h);
+ return game_manager.get_map().get_province_index_at(x_mod_w, y_mod_h);
}
StringName const& GameSingleton::get_province_info_province_key() {
@@ -219,7 +218,7 @@ Dictionary GameSingleton::_distribution_to_dictionary(distribution_t const& dist
}
Dictionary GameSingleton::get_province_info_from_index(int32_t index) const {
- Province const* province = game_manager.map.get_province_by_index(index);
+ Province const* province = game_manager.get_map().get_province_by_index(index);
if (province == nullptr) return {};
Dictionary ret;
@@ -263,11 +262,11 @@ Dictionary GameSingleton::get_province_info_from_index(int32_t index) const {
}
int32_t GameSingleton::get_width() const {
- return game_manager.map.get_width();
+ return game_manager.get_map().get_width();
}
int32_t GameSingleton::get_height() const {
- return game_manager.map.get_height();
+ return game_manager.get_map().get_height();
}
float GameSingleton::get_aspect_ratio() const {
@@ -296,7 +295,7 @@ Error GameSingleton::_update_colour_image() {
colour_data_array.resize(colour_data_array_size);
Error err = OK;
- if (!game_manager.map.generate_mapmode_colours(mapmode_index, colour_data_array.ptrw()))
+ if (!game_manager.get_map().generate_mapmode_colours(mapmode_index, colour_data_array.ptrw()))
err = FAILED;
static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(Province::index_t) * 4);
@@ -316,17 +315,17 @@ Error GameSingleton::_update_colour_image() {
}
int32_t GameSingleton::get_mapmode_count() const {
- return game_manager.map.get_mapmode_count();
+ return game_manager.get_map().get_mapmode_count();
}
String GameSingleton::get_mapmode_identifier(int32_t index) const {
- Mapmode const* mapmode = game_manager.map.get_mapmode_by_index(index);
+ Mapmode const* mapmode = game_manager.get_map().get_mapmode_by_index(index);
if (mapmode != nullptr) return std_to_godot_string(mapmode->get_identifier());
return String {};
}
Error GameSingleton::set_mapmode(String const& identifier) {
- Mapmode const* mapmode = game_manager.map.get_mapmode_by_identifier(godot_to_std_string(identifier));
+ Mapmode const* mapmode = game_manager.get_map().get_mapmode_by_identifier(godot_to_std_string(identifier));
if (mapmode == nullptr) {
UtilityFunctions::push_error("Failed to set mapmode to: ", identifier);
return FAILED;
@@ -337,11 +336,11 @@ Error GameSingleton::set_mapmode(String const& identifier) {
}
int32_t GameSingleton::get_selected_province_index() const {
- return game_manager.map.get_selected_province_index();
+ return game_manager.get_map().get_selected_province_index();
}
void GameSingleton::set_selected_province(int32_t index) {
- game_manager.map.set_selected_province(index);
+ game_manager.get_map().set_selected_province(index);
_update_colour_image();
emit_signal("province_selected", index);
}
@@ -354,36 +353,32 @@ Error GameSingleton::expand_building(int32_t province_index, String const& build
return OK;
}
-Ref<Texture> GameSingleton::get_good_icon_texture(String const& identifier) const {
- return good_icons.get(identifier, {});
-}
-
void GameSingleton::set_paused(bool paused) {
- game_manager.clock.isPaused = paused;
+ game_manager.get_clock().isPaused = paused;
}
void GameSingleton::toggle_paused() {
- game_manager.clock.isPaused = !game_manager.clock.isPaused;
+ game_manager.get_clock().isPaused = !game_manager.get_clock().isPaused;
}
bool GameSingleton::is_paused() const {
- return game_manager.clock.isPaused;
+ return game_manager.get_clock().isPaused;
}
void GameSingleton::increase_speed() {
- game_manager.clock.increaseSimulationSpeed();
+ game_manager.get_clock().increaseSimulationSpeed();
}
void GameSingleton::decrease_speed() {
- game_manager.clock.decreaseSimulationSpeed();
+ game_manager.get_clock().decreaseSimulationSpeed();
}
bool GameSingleton::can_increase_speed() const {
- return game_manager.clock.canIncreaseSimulationSpeed();
+ return game_manager.get_clock().canIncreaseSimulationSpeed();
}
bool GameSingleton::can_decrease_speed() const {
- return game_manager.clock.canDecreaseSimulationSpeed();
+ return game_manager.get_clock().canDecreaseSimulationSpeed();
}
String GameSingleton::get_longform_date() const {
@@ -391,5 +386,5 @@ String GameSingleton::get_longform_date() const {
}
void GameSingleton::try_tick() {
- game_manager.clock.conditionallyAdvanceGame();
+ game_manager.get_clock().conditionallyAdvanceGame();
}
diff --git a/extension/src/openvic-extension/GameSingleton.hpp b/extension/src/openvic-extension/GameSingleton.hpp
index bd6b73c..4d9e912 100644
--- a/extension/src/openvic-extension/GameSingleton.hpp
+++ b/extension/src/openvic-extension/GameSingleton.hpp
@@ -41,7 +41,6 @@ namespace OpenVic {
IdentifierRegistry<TerrainVariant> terrain_variants;
Map::terrain_variant_map_t terrain_variant_map;
godot::Ref<godot::Texture2DArray> terrain_texture;
- godot::Dictionary good_icons;
godot::Error _generate_terrain_texture_array();
godot::Error _load_map_images(godot::String const& province_image_path, godot::String const& terrain_image_path, bool flip_vertical = false);
@@ -143,7 +142,6 @@ namespace OpenVic {
void set_selected_province(int32_t index);
godot::Error expand_building(int32_t province_index, godot::String const& building_type_identifier);
- godot::Ref<godot::Texture> get_good_icon_texture(godot::String const& identifier) const;
void set_paused(bool paused);
void toggle_paused();
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/LoadGameOpenVic.cpp b/extension/src/openvic-extension/LoadGameOpenVic.cpp
index 87c66da..c34411c 100644
--- a/extension/src/openvic-extension/LoadGameOpenVic.cpp
+++ b/extension/src/openvic-extension/LoadGameOpenVic.cpp
@@ -86,7 +86,7 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
if (err != OK) return err;
// Generate interleaved province and terrain ID image
- if (!game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y,
+ if (!game_manager.get_map().generate_province_shape_image(province_dims.x, province_dims.y,
province_image->get_data().ptr(), terrain_image->get_data().ptr(), terrain_variant_map,
false /* <-- whether to print detailed map errors or not (specific missing/unrecognised colours) */
)) err = FAILED;
@@ -97,7 +97,7 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
for (image_subdivisions[i] = 1; province_dims[i] / image_subdivisions[i] > GPU_DIM_LIMIT ||
province_dims[i] % image_subdivisions[i] != 0; ++image_subdivisions[i]);
- Map::shape_pixel_t const* province_shape_data = game_manager.map.get_province_shape_image().data();
+ Map::shape_pixel_t const* province_shape_data = game_manager.get_map().get_province_shape_image().data();
const Vector2i divided_dims = province_dims / image_subdivisions;
Array province_shape_images;
province_shape_images.resize(image_subdivisions.x * image_subdivisions.y);
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);
};
}