aboutsummaryrefslogtreecommitdiff
path: root/extension/src/GameSingleton.cpp
diff options
context:
space:
mode:
author ClarkeCode <33846391+ClarkeCode@users.noreply.github.com>2023-04-29 03:39:28 +0200
committer GitHub <noreply@github.com>2023-04-29 03:39:28 +0200
commit1f8545facd248bbf4ea0cd551fea5f7d9b0efdce (patch)
tree0accf6d2c5479afb99649351ccf485b63520ac81 /extension/src/GameSingleton.cpp
parent05937359e8c53ee76dc3ce537dd70083a016f766 (diff)
parentef0d15bef9c35f261c4d09bbb23a2b8731acd3fc (diff)
Merge pull request #100 from OpenVic2Project/goods
Addition of goods struct
Diffstat (limited to 'extension/src/GameSingleton.cpp')
-rw-r--r--extension/src/GameSingleton.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index 4d5728a..64f6fc1 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -5,6 +5,7 @@
#include <godot_cpp/classes/json.hpp>
#include "openvic2/Logger.hpp"
+#include "openvic2/Types.hpp"
using namespace godot;
using namespace OpenVic2;
@@ -65,16 +66,16 @@ GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_upd
using mapmode_t = std::pair<std::string, Mapmode::colour_func_t>;
const std::vector<mapmode_t> mapmodes = {
- { "mapmode_province", [](Map const&, Province const& province) -> Province::colour_t { return province.get_colour(); } },
- { "mapmode_region", [](Map const&, Province const& province) -> Province::colour_t {
+ { "mapmode_province", [](Map const&, Province const& province) -> colour_t { return province.get_colour(); } },
+ { "mapmode_region", [](Map const&, Province const& province) -> colour_t {
Region const* region = province.get_region();
if (region != nullptr) return region->get_colour();
return province.get_colour();
} },
- { "mapmode_terrain", [](Map const&, Province const& province) -> Province::colour_t {
+ { "mapmode_terrain", [](Map const&, Province const& province) -> colour_t {
return province.is_water() ? 0x4287F5 : 0x0D7017;
} },
- { "mapmode_index", [](Map const& map, Province const& province) -> Province::colour_t {
+ { "mapmode_index", [](Map const& map, Province const& province) -> colour_t {
const uint8_t f = static_cast<float>(province.get_index()) / static_cast<float>(map.get_province_count()) * 255.0f;
return (f << 16) | (f << 8) | f;
} }
@@ -151,30 +152,31 @@ static Error parse_json_dictionary_file(String const& file_description, String c
Error GameSingleton::_parse_province_identifier_entry(String const& identifier, Variant const& entry) {
const Variant::Type type = entry.get_type();
- Province::colour_t colour = Province::NULL_COLOUR;
+ colour_t colour = NULL_COLOUR;
if (type == Variant::ARRAY) {
Array const& colour_array = entry;
if (colour_array.size() == 3) {
for (int jdx = 0; jdx < 3; ++jdx) {
Variant const& var = colour_array[jdx];
if (var.get_type() != Variant::FLOAT) {
- colour = Province::NULL_COLOUR;
+ colour = NULL_COLOUR;
break;
}
const double colour_double = var;
if (std::trunc(colour_double) != colour_double) {
- colour = Province::NULL_COLOUR;
+ colour = NULL_COLOUR;
break;
}
const int64_t colour_int = static_cast<int64_t>(colour_double);
if (colour_int < 0 || colour_int > 255) {
- colour = Province::NULL_COLOUR;
+ colour = NULL_COLOUR;
break;
}
colour = (colour << 8) | colour_int;
}
}
- } else if (type == Variant::STRING) {
+ }
+ else if (type == Variant::STRING) {
String const& colour_string = entry;
if (colour_string.is_valid_hex_number()) {
const int64_t colour_int = colour_string.hex_to_int();
@@ -182,7 +184,7 @@ Error GameSingleton::_parse_province_identifier_entry(String const& identifier,
colour = colour_int;
}
}
- if (colour == Province::NULL_COLOUR) {
+ if (colour == NULL_COLOUR) {
UtilityFunctions::push_error("Invalid colour for province identifier \"", identifier, "\": ", entry);
return FAILED;
}
@@ -210,7 +212,8 @@ Error GameSingleton::_parse_region_entry(String const& identifier, Variant const
if (type == Variant::STRING) {
String const& province_string = province_var;
province_identifiers.push_back(province_string.utf8().get_data());
- } else {
+ }
+ else {
UtilityFunctions::push_error("Invalid province identifier for region \"", identifier, "\": ", entry);
err = FAILED;
}
@@ -309,7 +312,8 @@ Error GameSingleton::load_water_province_file(String const& file_path) {
UtilityFunctions::push_error("Invalid water province JSON: root has type ",
Variant::get_type_name(type), " (expected Array)");
err = FAILED;
- } else {
+ }
+ else {
Array const& array = json_var;
for (int64_t idx = 0; idx < array.size(); ++idx) {
Variant const& entry = array[idx];
@@ -398,15 +402,16 @@ Ref<Texture> GameSingleton::get_province_colour_texture() const {
Error GameSingleton::update_colour_image() {
static PackedByteArray colour_data_array;
- static constexpr int64_t colour_data_array_size = (Province::MAX_INDEX + 1) * Map::MAPMODE_COLOUR_SIZE;
+ static constexpr int64_t colour_data_array_size = (MAX_INDEX + 1) * Map::MAPMODE_COLOUR_SIZE;
colour_data_array.resize(colour_data_array_size);
Error err = OK;
if (game_manager.map.generate_mapmode_colours(mapmode_index, colour_data_array.ptrw()) != SUCCESS)
err = FAILED;
- static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(Province::index_t) * 4);
- if (province_colour_image.is_null()) province_colour_image.instantiate();
+ static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(index_t) * 4);
+ if (province_colour_image.is_null())
+ province_colour_image.instantiate();
province_colour_image->set_data(PROVINCE_INDEX_SQRT, PROVINCE_INDEX_SQRT,
false, Image::FORMAT_RGB8, colour_data_array);
if (province_colour_image.is_null()) {