aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-05-24 10:14:41 +0200
committer Hop311 <hop3114@gmail.com>2023-05-24 10:14:41 +0200
commitd6db91738ceee5cce9e7b7efc32bec89a83fa790 (patch)
tree2ba58efbe0ff3cfdc6f73b7a9e0bfab399d5e0d3 /extension/src
parentac36a373139e3e815f70720b37d4ffc8d9062df9 (diff)
Date fix + string fix + Logger queue
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/GameSingleton.cpp7
-rw-r--r--extension/src/GameSingleton.hpp4
-rw-r--r--extension/src/LoadGameCompatibility.cpp2
-rw-r--r--extension/src/Utilities.hpp6
4 files changed, 10 insertions, 9 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index cb7d0a7..e485cdc 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -12,9 +12,10 @@ using namespace OpenVic;
GameSingleton* GameSingleton::singleton = nullptr;
void GameSingleton::_bind_methods() {
+ ClassDB::bind_static_method("GameSingleton", D_METHOD("setup_logger"), &GameSingleton::setup_logger);
ClassDB::bind_method(D_METHOD("load_defines", "file_dict"), &GameSingleton::load_defines);
ClassDB::bind_method(D_METHOD("load_defines_compatibility_mode", "file_path"), &GameSingleton::load_defines_compatibility_mode);
- ClassDB::bind_method(D_METHOD("setup"), &GameSingleton::setup);
+ ClassDB::bind_method(D_METHOD("setup_game"), &GameSingleton::setup_game);
ClassDB::bind_method(D_METHOD("get_province_index_from_uv_coords", "coords"), &GameSingleton::get_province_index_from_uv_coords);
ClassDB::bind_method(D_METHOD("get_province_info_from_index", "index"), &GameSingleton::get_province_info_from_index);
@@ -88,7 +89,9 @@ GameSingleton::GameSingleton() : game_manager { [this]() { _on_state_updated();
terrain_variants { "terrain variants" } {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
+}
+void GameSingleton::setup_logger() {
Logger::set_info_func([](std::string&& str) { UtilityFunctions::print(std_to_godot_string(str)); });
Logger::set_error_func([](std::string&& str) { UtilityFunctions::push_error(std_to_godot_string(str)); });
}
@@ -162,7 +165,7 @@ GameSingleton::~GameSingleton() {
singleton = nullptr;
}
-Error GameSingleton::setup() {
+Error GameSingleton::setup_game() {
return ERR(game_manager.setup());
}
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index 6bfb741..6c91de5 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -74,6 +74,8 @@ namespace OpenVic {
GameSingleton();
~GameSingleton();
+ static void setup_logger();
+
static godot::StringName const& get_province_identifier_file_key();
static godot::StringName const& get_water_province_file_key();
static godot::StringName const& get_region_file_key();
@@ -97,7 +99,7 @@ namespace OpenVic {
/* Post-load/restart game setup - reset the game to post-load state
* and (re)generate starting data, e.g. buildings.
*/
- godot::Error setup();
+ godot::Error setup_game();
int32_t get_province_index_from_uv_coords(godot::Vector2 const& coords) const;
diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp
index 29b773e..96c165b 100644
--- a/extension/src/LoadGameCompatibility.cpp
+++ b/extension/src/LoadGameCompatibility.cpp
@@ -76,7 +76,7 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co
Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& terrain_image_path, String const& terrain_texturesheet_path) {
// Read BMP's palette to determine terrain variant colours which texture they're associated with
BMP bmp;
- if (bmp.open(godot_to_c_string(terrain_image_path)) != SUCCESS || bmp.read_header() != SUCCESS || bmp.read_palette() != SUCCESS) {
+ if (bmp.open(godot_to_std_string(terrain_image_path).c_str()) != SUCCESS || bmp.read_header() != SUCCESS || bmp.read_palette() != SUCCESS) {
UtilityFunctions::push_error("Failed to read BMP palette from compatibility mode terrain image: ", terrain_image_path);
return FAILED;
}
diff --git a/extension/src/Utilities.hpp b/extension/src/Utilities.hpp
index 16193e8..75e873f 100644
--- a/extension/src/Utilities.hpp
+++ b/extension/src/Utilities.hpp
@@ -8,12 +8,8 @@
namespace OpenVic {
- inline char const* godot_to_c_string(godot::String const& str) {
- return str.ascii().get_data();
- }
-
inline std::string godot_to_std_string(godot::String const& str) {
- return godot_to_c_string(str);
+ return str.ascii().get_data();
}
inline godot::String std_to_godot_string(std::string const& str) {