aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-02 13:55:36 +0200
committer Hop311 <hop3114@gmail.com>2023-09-09 22:57:26 +0200
commitc715187bffa8c84428acf3631e3d03c088a719d9 (patch)
treeb880594195ad803fe716c9c6184591b8b47fa42c /extension/src
parentaa49dbbb3cf9dbff18c08245b0e46a9943df9b15 (diff)
Followup big dataloader commit
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/GameSingleton.cpp1
-rw-r--r--extension/src/GameSingleton.hpp4
-rw-r--r--extension/src/LoadGameCompatibility.cpp31
-rw-r--r--extension/src/LoadGameOpenVic.cpp6
4 files changed, 30 insertions, 12 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index 07be9aa..6ccde8d 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -23,6 +23,7 @@ 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_compatibility_mode", "file_paths"), &GameSingleton::load_defines_compatibility_mode);
+ ClassDB::bind_method(D_METHOD("lookup_file", "path"), &GameSingleton::lookup_file);
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);
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index a484520..eb332f4 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -7,6 +7,7 @@
#include "openvic/dataloader/Dataloader.hpp"
namespace OpenVic {
+
struct TerrainVariant : HasIdentifierAndColour {
friend class GameSingleton;
@@ -23,6 +24,7 @@ namespace OpenVic {
godot::Ref<godot::Image> get_image() const;
};
+
class GameSingleton : public godot::Object {
GDCLASS(GameSingleton, godot::Object)
@@ -76,6 +78,8 @@ namespace OpenVic {
*/
godot::Error load_defines_compatibility_mode(godot::PackedStringArray const& file_paths);
+ godot::String lookup_file(godot::String const& path) const;
+
/* Post-load/restart game setup - reset the game to post-load state
* and (re)generate starting data, e.g. buildings.
*/
diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp
index 1567977..3da5f08 100644
--- a/extension/src/LoadGameCompatibility.cpp
+++ b/extension/src/LoadGameCompatibility.cpp
@@ -28,14 +28,24 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co
continue;
if (line_number < 2) continue; // skip header line
- Province::index_t id = Province::NULL_INDEX;
+ std::string identifier;
colour_t colour = NULL_COLOUR;
if (line.size() > 0) {
- if (line[0].is_empty()) {
- id = game_manager.map.get_province_count() + 1;
- } else if (line[0].is_valid_int()) {
- const int64_t val = line[0].to_int();
- if (val > Province::NULL_INDEX && val <= Province::MAX_INDEX) id = val;
+ identifier = godot_to_std_string(line[0]);
+ if (identifier.empty()) {
+ identifier = std::to_string(game_manager.map.get_province_count() + 1);
+ } else {
+ bool successful = false;
+ const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10);
+ if (successful) {
+ if (val <= Province::NULL_INDEX || val > Province::MAX_INDEX) {
+ UtilityFunctions::push_error("Invalid province index ", line[0], " (out of valid range ", Province::NULL_INDEX, " < index <= ", Province::MAX_INDEX, ")");
+ err = FAILED;
+ }
+ } else {
+ UtilityFunctions::push_error("Invalid province index ", line[0], " (not a valid integer)");
+ err = FAILED;
+ }
}
for (int i = 1; i < 4; ++i) {
if (line.size() > i) {
@@ -60,12 +70,12 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co
break;
}
}
- if (id == Province::NULL_INDEX || colour == NULL_COLOUR) {
+ if (identifier.empty() || colour == NULL_COLOUR) {
UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
err = FAILED;
continue;
}
- if (game_manager.map.add_province(std::to_string(id), colour) != SUCCESS) err = FAILED;
+ if (game_manager.map.add_province(identifier, colour) != SUCCESS) err = FAILED;
}
}
game_manager.map.lock_provinces();
@@ -167,10 +177,13 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
UtilityFunctions::push_error("Failed to load map images!");
err = FAILED;
}
- game_manager.good_manager.lock_goods();
if (game_manager.load_hardcoded_defines() != SUCCESS) {
UtilityFunctions::push_error("Failed to hardcoded defines!");
err = FAILED;
}
return err;
}
+
+String GameSingleton::lookup_file(String const& path) const {
+ return std_to_godot_string(dataloader.lookup_file(godot_to_std_string(path)).string());
+}
diff --git a/extension/src/LoadGameOpenVic.cpp b/extension/src/LoadGameOpenVic.cpp
index b262a28..3d3d6c5 100644
--- a/extension/src/LoadGameOpenVic.cpp
+++ b/extension/src/LoadGameOpenVic.cpp
@@ -11,19 +11,19 @@ using namespace OpenVic;
Error GameSingleton::_generate_terrain_texture_array() {
Error err = OK;
- if (terrain_variants.get_item_count() == 0) {
+ if (terrain_variants.size() == 0) {
UtilityFunctions::push_error("Failed to load terrain textures!");
return FAILED;
}
// TerrainVariant count is limited by the data type representing it in the map image
- if (terrain_variants.get_item_count() > TerrainVariant::MAX_TERRIN_VARIANT_COUNT) {
+ if (terrain_variants.size() > TerrainVariant::MAX_TERRIN_VARIANT_COUNT) {
UtilityFunctions::push_error("Too many terrain textures - all after the first ",
static_cast<uint64_t>(TerrainVariant::MAX_TERRIN_VARIANT_COUNT), " will be ignored");
err = FAILED;
}
Array terrain_images;
- for (size_t i = 0; i < terrain_variants.get_item_count() && i < TerrainVariant::MAX_TERRIN_VARIANT_COUNT; ++i) {
+ for (size_t i = 0; i < terrain_variants.size() && i < TerrainVariant::MAX_TERRIN_VARIANT_COUNT; ++i) {
TerrainVariant const& var = *terrain_variants.get_item_by_index(i);
terrain_variant_map[var.get_colour()] = i;
terrain_images.append(var.get_image());