aboutsummaryrefslogtreecommitdiff
path: root/extension/src
diff options
context:
space:
mode:
author Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-05 01:04:40 +0200
committer Gone2Daly <71726742+Gone2Daly@users.noreply.github.com>2023-04-05 01:04:40 +0200
commitd3c7e9b27ba60550b23efb9e37cc66b91de0c795 (patch)
tree0f753afd37019984e18ca3cac74a650c7d3c040f /extension/src
parentc7def7396da00b39eced666ad360397733712bfd (diff)
Adding province overview panel and selection of province.
Diffstat (limited to 'extension/src')
-rw-r--r--extension/src/MapSingleton.cpp15
-rw-r--r--extension/src/MapSingleton.hpp1
-rw-r--r--extension/src/openvic2/Map.cpp8
-rw-r--r--extension/src/openvic2/Map.hpp1
4 files changed, 22 insertions, 3 deletions
diff --git a/extension/src/MapSingleton.cpp b/extension/src/MapSingleton.cpp
index 10b750a..9f76508 100644
--- a/extension/src/MapSingleton.cpp
+++ b/extension/src/MapSingleton.cpp
@@ -13,6 +13,7 @@ void MapSingleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_province_identifier_file", "file_path"), &MapSingleton::load_province_identifier_file);
ClassDB::bind_method(D_METHOD("load_province_shape_file", "file_path"), &MapSingleton::load_province_shape_file);
ClassDB::bind_method(D_METHOD("get_province_shape_image"), &MapSingleton::get_province_shape_image);
+ ClassDB::bind_method(D_METHOD("get_province_id"), &MapSingleton::get_province_id);
}
MapSingleton* MapSingleton::get_singleton() {
@@ -63,9 +64,9 @@ Error MapSingleton::load_province_identifier_file(String const& file_path) {
err = FAILED;
continue;
}
- static const String prov_prefix = "prov_";
- if (!identifier.begins_with(prov_prefix))
- UtilityFunctions::push_warning("Province identifier missing prefix: ", identifier);
+ // static const String prov_prefix = "prov_";
+ // if (!identifier.begins_with(prov_prefix))
+ // UtilityFunctions::push_warning("Province identifier missing prefix: ", identifier);
type = colour_var.get_type();
Province::colour_t colour = Province::NULL_COLOUR;
if (type == Variant::ARRAY) {
@@ -114,6 +115,14 @@ Error MapSingleton::load_province_identifier_file(String const& file_path) {
return err;
}
+godot::String MapSingleton::get_province_id(godot::String const& hex_str) {
+ UtilityFunctions::print(hex_str);
+ int64_t colour_string = hex_str.hex_to_int();
+ godot::String province_id = map.get_province(colour_string).identifier.c_str();
+ UtilityFunctions::print("Returning: ",map.get_province(colour_string).to_string().c_str());
+ return province_id;
+}
+
Error MapSingleton::load_province_shape_file(String const& file_path) {
if (province_shape_image.is_valid()) {
UtilityFunctions::push_error("Province shape file has already been loaded, cannot load: ", file_path);
diff --git a/extension/src/MapSingleton.hpp b/extension/src/MapSingleton.hpp
index 767ae88..fd549eb 100644
--- a/extension/src/MapSingleton.hpp
+++ b/extension/src/MapSingleton.hpp
@@ -25,6 +25,7 @@ namespace OpenVic2 {
godot::Error load_province_identifier_file(godot::String const& file_path);
godot::Error load_province_shape_file(godot::String const& file_path);
+ godot::String get_province_id(godot::String const& hex_str);
godot::Ref<godot::Image> get_province_shape_image() const;
};
}
diff --git a/extension/src/openvic2/Map.cpp b/extension/src/openvic2/Map.cpp
index c53b86d..40c421a 100644
--- a/extension/src/openvic2/Map.cpp
+++ b/extension/src/openvic2/Map.cpp
@@ -26,4 +26,12 @@ bool Map::add_province(std::string const& identifier, Province::colour_t colour,
provinces.push_back(new_province);
error_message = "Added province: " + new_province.to_string();
return true;
+}
+
+Province Map::get_province(Province::colour_t colour) {
+ for(Province const& province : provinces) {
+ if (province.colour == colour) {
+ return province;
+ }
+ }
} \ No newline at end of file
diff --git a/extension/src/openvic2/Map.hpp b/extension/src/openvic2/Map.hpp
index 3c9c6de..6d8482e 100644
--- a/extension/src/openvic2/Map.hpp
+++ b/extension/src/openvic2/Map.hpp
@@ -23,6 +23,7 @@ namespace OpenVic2 {
public:
bool add_province(std::string const& identifier, Province::colour_t colour, std::string& error_message);
+ Province get_province(Province::colour_t colour);
};
}