diff options
57 files changed, 854 insertions, 344 deletions
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp index 3811dea..3476ac5 100644 --- a/extension/src/GameSingleton.cpp +++ b/extension/src/GameSingleton.cpp @@ -17,15 +17,19 @@ void GameSingleton::_bind_methods() { ClassDB::bind_method(D_METHOD("load_province_identifier_file", "file_path"), &GameSingleton::load_province_identifier_file); ClassDB::bind_method(D_METHOD("load_water_province_file", "file_path"), &GameSingleton::load_water_province_file); ClassDB::bind_method(D_METHOD("load_region_file", "file_path"), &GameSingleton::load_region_file); - ClassDB::bind_method(D_METHOD("load_province_shape_file", "file_path"), &GameSingleton::load_province_shape_file); + ClassDB::bind_method(D_METHOD("load_terrain_file", "file_path"), &GameSingleton::load_terrain_file); + ClassDB::bind_method(D_METHOD("load_map_images", "province_image_path", "terrain_image_path"), &GameSingleton::load_map_images); ClassDB::bind_method(D_METHOD("setup"), &GameSingleton::setup); 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); ClassDB::bind_method(D_METHOD("get_width"), &GameSingleton::get_width); ClassDB::bind_method(D_METHOD("get_height"), &GameSingleton::get_height); - ClassDB::bind_method(D_METHOD("get_province_index_images"), &GameSingleton::get_province_index_images); - ClassDB::bind_method(D_METHOD("get_province_colour_image"), &GameSingleton::get_province_colour_image); + ClassDB::bind_method(D_METHOD("get_aspect_ratio"), &GameSingleton::get_aspect_ratio); + ClassDB::bind_method(D_METHOD("get_terrain_texture"), &GameSingleton::get_terrain_texture); + ClassDB::bind_method(D_METHOD("get_province_shape_image_subdivisions"), &GameSingleton::get_province_shape_image_subdivisions); + ClassDB::bind_method(D_METHOD("get_province_shape_texture"), &GameSingleton::get_province_shape_texture); + ClassDB::bind_method(D_METHOD("get_province_colour_texture"), &GameSingleton::get_province_colour_texture); ClassDB::bind_method(D_METHOD("update_colour_image"), &GameSingleton::update_colour_image); ClassDB::bind_method(D_METHOD("get_mapmode_count"), &GameSingleton::get_mapmode_count); @@ -54,27 +58,31 @@ GameSingleton* GameSingleton::get_singleton() { /* REQUIREMENTS: * MAP-21, MAP-25 */ -GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_updated"); } } { +GameSingleton::GameSingleton() : game_manager{ [this]() { emit_signal("state_updated"); } }, terrain_variants{ "terrain variants" } { ERR_FAIL_COND(singleton != nullptr); singleton = this; Logger::set_info_func([](std::string&& str) { UtilityFunctions::print(str.c_str()); }); Logger::set_error_func([](std::string&& str) { UtilityFunctions::push_error(str.c_str()); }); + static constexpr colour_t HIGH_ALPHA_VALUE = to_alpha_value(0.5f); + static constexpr colour_t LOW_ALPHA_VALUE = to_alpha_value(0.2f); 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 { - Region const* region = province.get_region(); - if (region != nullptr) return region->get_colour(); - return province.get_colour(); + { "mapmode_terrain", [](Map const&, Province const& province) -> colour_t { + return LOW_ALPHA_VALUE | (province.is_water() ? 0x4287F5 : 0x0D7017); + } }, + { "mapmode_province", [](Map const&, Province const& province) -> colour_t { + return HIGH_ALPHA_VALUE | province.get_colour(); } }, - { "mapmode_terrain", [](Map const&, Province const& province) -> Province::colour_t { - return province.is_water() ? 0x4287F5 : 0x0D7017; + { "mapmode_region", [](Map const&, Province const& province) -> colour_t { + Region const* region = province.get_region(); + if (region != nullptr) return (0xCC << 24) | region->get_colour(); + return NULL_COLOUR; } }, - { "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; + return HIGH_ALPHA_VALUE | (f << 16) | (f << 8) | f; } } }; for (mapmode_t const& mapmode : mapmodes) @@ -96,7 +104,7 @@ GameSingleton::~GameSingleton() { singleton = nullptr; } -static Error load_json_file(String const& file_description, String const& file_path, Variant& result) { +static Error _load_json_file(String const& file_description, String const& file_path, Variant& result) { result.clear(); UtilityFunctions::print("Loading ", file_description, " file: ", file_path); const Ref<FileAccess> file = FileAccess::open(file_path, FileAccess::ModeFlags::READ); @@ -119,10 +127,10 @@ static Error load_json_file(String const& file_description, String const& file_p using parse_json_entry_func_t = std::function<godot::Error (godot::String const&, godot::Variant const&)>; -static Error parse_json_dictionary_file(String const& file_description, String const& file_path, +static Error _parse_json_dictionary_file(String const& file_description, String const& file_path, String const& identifier_prefix, parse_json_entry_func_t parse_entry) { Variant json_var; - Error err = load_json_file(file_description, file_path, json_var); + Error err = _load_json_file(file_description, file_path, json_var); if (err != OK) return err; const Variant::Type type = json_var.get_type(); if (type != Variant::DICTIONARY) { @@ -147,40 +155,38 @@ static Error parse_json_dictionary_file(String const& file_description, String c return err; } -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; +static colour_t _parse_colour(Variant const& var) { + const Variant::Type type = var.get_type(); if (type == Variant::ARRAY) { - Array const& colour_array = entry; + Array const& colour_array = var; if (colour_array.size() == 3) { + colour_t colour = NULL_COLOUR; for (int jdx = 0; jdx < 3; ++jdx) { Variant const& var = colour_array[jdx]; - if (var.get_type() != Variant::FLOAT) { - colour = Province::NULL_COLOUR; - break; - } + if (var.get_type() != Variant::FLOAT) return NULL_COLOUR; const double colour_double = var; - if (std::trunc(colour_double) != colour_double) { - colour = Province::NULL_COLOUR; - break; - } + if (std::trunc(colour_double) != colour_double) return NULL_COLOUR; const int64_t colour_int = static_cast<int64_t>(colour_double); - if (colour_int < 0 || colour_int > 255) { - colour = Province::NULL_COLOUR; - break; - } + if (colour_int < 0 || colour_int > 255) return NULL_COLOUR; colour = (colour << 8) | colour_int; } + return colour; } - } else if (type == Variant::STRING) { - String const& colour_string = entry; + } + else if (type == Variant::STRING) { + String const& colour_string = var; if (colour_string.is_valid_hex_number()) { const int64_t colour_int = colour_string.hex_to_int(); - if (0 <= colour_int && colour_int <= 0xFFFFFF) - colour = colour_int; + if (colour_int != NULL_COLOUR && colour_int <= MAX_COLOUR_RGB) + return colour_int; } } - if (colour == Province::NULL_COLOUR) { + return NULL_COLOUR; +} + +Error GameSingleton::_parse_province_identifier_entry(String const& identifier, Variant const& entry) { + const colour_t colour = _parse_colour(entry); + if (colour == NULL_COLOUR) { UtilityFunctions::push_error("Invalid colour for province identifier \"", identifier, "\": ", entry); return FAILED; } @@ -188,7 +194,7 @@ Error GameSingleton::_parse_province_identifier_entry(String const& identifier, } Error GameSingleton::load_province_identifier_file(String const& file_path) { - const Error err = parse_json_dictionary_file("province identifier", file_path, "prov_", + const Error err = _parse_json_dictionary_file("province identifier", file_path, "prov_", [this](String const& identifier, Variant const& entry) -> Error { return _parse_province_identifier_entry(identifier, entry); }); @@ -208,7 +214,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; } @@ -222,7 +229,7 @@ Error GameSingleton::_parse_region_entry(String const& identifier, Variant const } Error GameSingleton::load_region_file(String const& file_path) { - const Error err = parse_json_dictionary_file("region", file_path, "region_", + const Error err = _parse_json_dictionary_file("region", file_path, "region_", [this](String const& identifier, Variant const& entry) -> Error { return _parse_region_entry(identifier, entry); }); @@ -230,53 +237,134 @@ Error GameSingleton::load_region_file(String const& file_path) { return err; } -Error GameSingleton::load_province_shape_file(String const& file_path) { - if (province_index_image[0].is_valid()) { - UtilityFunctions::push_error("Province shape file has already been loaded, cannot load: ", file_path); +TerrainVariant::TerrainVariant(std::string const& new_identfier, colour_t new_colour, Ref<Image> const& new_image) + : HasIdentifier(new_identfier), HasColour(new_colour), image(new_image) {} + +Ref<Image> TerrainVariant::get_image() const { return image; } + +Error GameSingleton::_parse_terrain_entry(String const& identifier, Variant const& entry) { + const colour_t colour = _parse_colour(entry); + if (colour == NULL_COLOUR) { + UtilityFunctions::push_error("Invalid colour for terrain texture \"", identifier, "\": ", entry); return FAILED; } - Ref<Image> province_shape_image; - province_shape_image.instantiate(); - Error err = province_shape_image->load(file_path); + static const String terrain_folder = "res://art/terrain/"; + const String terrain_path = terrain_folder + identifier; + Ref<Image> terrain_image; + terrain_image.instantiate(); + const Error err = terrain_image->load(terrain_path); if (err != OK) { - UtilityFunctions::push_error("Failed to load province shape file: ", file_path); + UtilityFunctions::push_error("Failed to load terrain image: ", terrain_path); return err; } - const int32_t width = province_shape_image->get_width(); - const int32_t height = province_shape_image->get_height(); - if (width < 1 || height < 1) { - UtilityFunctions::push_error("Invalid dimensions (", width, "x", height, ") for province shape file: ", file_path); + return ERR(terrain_variants.add_item({ identifier.utf8().get_data(), colour, terrain_image })); +} + +Error GameSingleton::load_terrain_file(String const& file_path) { + Error parse_err = _parse_json_dictionary_file("terrain variants", file_path, "", + [this](String const& identifier, Variant const& entry) -> Error { + return _parse_terrain_entry(identifier, entry); + }); + terrain_variants.lock(); + if (terrain_variants.get_item_count() == 0) parse_err = FAILED; + + Array terrain_images; + for (TerrainVariant const& var : terrain_variants.get_items()) { + terrain_variant_map[var.get_colour()] = terrain_images.size(); + terrain_images.append(var.get_image()); + } + + terrain_texture.instantiate(); + const Error texturearray_err = terrain_texture->create_from_images(terrain_images); + if (texturearray_err != OK) { + UtilityFunctions::push_error("Failed to create terrain texture array!"); + return texturearray_err; + } + return parse_err; +} + +Error GameSingleton::load_map_images(String const& province_image_path, String const& terrain_image_path) { + if (province_shape_texture.is_valid()) { + UtilityFunctions::push_error("Map images have already been loaded, cannot load: ", province_image_path, " and ", terrain_image_path); + return FAILED; + } + + // Load images + Ref<Image> province_image, terrain_image; + province_image.instantiate(); + terrain_image.instantiate(); + Error err = province_image->load(province_image_path); + if (err != OK) { + UtilityFunctions::push_error("Failed to load province image: ", province_image_path); + return err; + } + err = terrain_image->load(terrain_image_path); + if (err != OK) { + UtilityFunctions::push_error("Failed to load terrain image: ", terrain_image_path); + return err; + } + + // Validate dimensions and format + const Vector2i province_dims = province_image->get_size(), terrain_dims = terrain_image->get_size(); + if (province_dims.x < 1 || province_dims.y < 1) { + UtilityFunctions::push_error("Invalid dimensions (", province_dims.x, "x", province_dims.y, ") for province image: ", province_image_path); err = FAILED; } - if (width % image_width_divide != 0) { - UtilityFunctions::push_error("Invalid width ", width, " (must be divisible by ", image_width_divide, ") for province shape file: ", file_path); + if (province_dims != terrain_dims) { + UtilityFunctions::push_error("Invalid dimensions (", terrain_dims.x, "x", terrain_dims.y, ") for terrain image: ", + terrain_image_path, " (must match province image: (", province_dims.x, "x", province_dims.x, "))"); err = FAILED; } static constexpr Image::Format expected_format = Image::FORMAT_RGB8; - const Image::Format format = province_shape_image->get_format(); - if (format != expected_format) { - UtilityFunctions::push_error("Invalid format (", format, ", should be ", expected_format, ") for province shape file: ", file_path); + const Image::Format province_format = province_image->get_format(), terrain_format = terrain_image->get_format(); + if (province_format != expected_format) { + UtilityFunctions::push_error("Invalid format (", province_format, ", should be ", expected_format, ") for province image: ", province_image_path); + err = FAILED; + } + if (terrain_format != expected_format) { + UtilityFunctions::push_error("Invalid format (", terrain_format, ", should be ", expected_format, ") for terrain image: ", terrain_image_path); err = FAILED; } if (err != OK) return err; - err = ERR(game_manager.map.generate_province_index_image(width, height, province_shape_image->get_data().ptr())); - - std::vector<Province::index_t> const& province_index_data = game_manager.map.get_province_index_image(); - const int32_t divided_width = width / image_width_divide; - for (int32_t i = 0; i < image_width_divide; ++i) { - PackedByteArray index_data_array; - index_data_array.resize(divided_width * height * sizeof(Province::index_t)); - for (int32_t y = 0; y < height; ++y) - memcpy(index_data_array.ptrw() + y * divided_width * sizeof(Province::index_t), - province_index_data.data() + y * width + i * divided_width, - divided_width * sizeof(Province::index_t)); - province_index_image[i] = Image::create_from_data(divided_width, height, false, Image::FORMAT_RG8, index_data_array); - if (province_index_image[i].is_null()) { - UtilityFunctions::push_error("Failed to create province ID image #", i); - err = FAILED; + + // Generate interleaved province and terrain ID image + if (game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y, province_image->get_data().ptr(), + terrain_image->get_data().ptr(), terrain_variant_map) != SUCCESS) return FAILED; + + static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF; + // For each dimension of the image, this finds the small number of equal subdivisions required get the individual texture dims under GPU_DIM_LIMIT + for (int i = 0; i < 2; ++i) 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(); + const Vector2i divided_dims = province_dims / image_subdivisions; + Array province_shape_images; + province_shape_images.resize(image_subdivisions.x * image_subdivisions.y); + for (int32_t v = 0; v < image_subdivisions.y; ++v) { + for (int32_t u = 0; u < image_subdivisions.x; ++u) { + PackedByteArray index_data_array; + index_data_array.resize(divided_dims.x * divided_dims.y * sizeof(Map::shape_pixel_t)); + + for (int32_t y = 0; y < divided_dims.y; ++y) + memcpy(index_data_array.ptrw() + y * divided_dims.x * sizeof(Map::shape_pixel_t), + province_shape_data + (v * divided_dims.y + y) * province_dims.x + u * divided_dims.x, + divided_dims.x * sizeof(Map::shape_pixel_t)); + + const Ref<Image> province_shape_subimage = Image::create_from_data(divided_dims.x, divided_dims.y, false, Image::FORMAT_RGB8, index_data_array); + if (province_shape_subimage.is_null()) { + UtilityFunctions::push_error("Failed to create province shape image (", u, ", ", v, ")"); + err = FAILED; + } + province_shape_images[u + v * image_subdivisions.x] = province_shape_subimage; } } + province_shape_texture.instantiate(); + if (province_shape_texture->create_from_images(province_shape_images) != OK) { + UtilityFunctions::push_error(""); + err = FAILED; + } + if (update_colour_image() != OK) err = FAILED; return err; @@ -288,14 +376,15 @@ godot::Error GameSingleton::setup() { Error GameSingleton::load_water_province_file(String const& file_path) { Variant json_var; - Error err = load_json_file("water province", file_path, json_var); + Error err = _load_json_file("water province", file_path, json_var); if (err != OK) return err; Variant::Type type = json_var.get_type(); if (type != Variant::ARRAY) { 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]; @@ -340,7 +429,7 @@ Dictionary GameSingleton::get_province_info_from_index(int32_t index) const { buildings_array.resize(buildings.size()); for (size_t idx = 0; idx < buildings.size(); ++idx) { KEY(building) KEY(level) KEY(expansion_state) KEY(start_date) KEY(end_date) KEY(expansion_progress) - + Dictionary building_dict; Building const& building = buildings[idx]; building_dict[building_key] = building.get_identifier().c_str(); @@ -366,27 +455,36 @@ int32_t GameSingleton::get_height() const { return game_manager.map.get_height(); } -Array GameSingleton::get_province_index_images() const { - Array ret; - for (int i = 0; i < image_width_divide; ++i) - ret.append(province_index_image[i]); - return ret; +float GameSingleton::get_aspect_ratio() const { + return static_cast<float>(get_width()) / static_cast<float>(get_height()); +} + +Ref<Texture> GameSingleton::get_terrain_texture() const { + return terrain_texture; +} + +Vector2i GameSingleton::get_province_shape_image_subdivisions() const { + return image_subdivisions; +} + +Ref<Texture> GameSingleton::get_province_shape_texture() const { + return province_shape_texture; } -Ref<Image> GameSingleton::get_province_colour_image() const { - return province_colour_image; +Ref<Texture> GameSingleton::get_province_colour_texture() const { + return province_colour_texture; } Error GameSingleton::update_colour_image() { static PackedByteArray colour_data_array; - static constexpr int64_t colour_data_array_size = (Province::MAX_INDEX + 1) * 4; + 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); + 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, @@ -395,6 +493,10 @@ Error GameSingleton::update_colour_image() { UtilityFunctions::push_error("Failed to update province colour image"); return FAILED; } + if (province_colour_texture.is_null()) + province_colour_texture = ImageTexture::create_from_image(province_colour_image); + else + province_colour_texture->update(province_colour_image); return err; } diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp index d9879ef..80b2d95 100644 --- a/extension/src/GameSingleton.hpp +++ b/extension/src/GameSingleton.hpp @@ -1,12 +1,21 @@ #pragma once -#include <functional> - -#include <godot_cpp/classes/image.hpp> +#include <godot_cpp/classes/image_texture.hpp> +#include <godot_cpp/classes/texture2d_array.hpp> #include "openvic2/GameManager.hpp" namespace OpenVic2 { + struct TerrainVariant : HasIdentifier, HasColour { + private: + const godot::Ref<godot::Image> image; + public: + TerrainVariant(std::string const& new_identfier, colour_t new_colour, + godot::Ref<godot::Image> const& new_image); + TerrainVariant(TerrainVariant&&) = default; + + godot::Ref<godot::Image> get_image() const; + }; class GameSingleton : public godot::Object { GDCLASS(GameSingleton, godot::Object) @@ -14,12 +23,18 @@ namespace OpenVic2 { GameManager game_manager; - static constexpr int image_width_divide = 2; - godot::Ref<godot::Image> province_index_image[image_width_divide], province_colour_image; + godot::Vector2i image_subdivisions; + godot::Ref<godot::Texture2DArray> province_shape_texture; + godot::Ref<godot::Image> province_colour_image; + godot::Ref<godot::ImageTexture> province_colour_texture; Mapmode::index_t mapmode_index = 0; + IdentifierRegistry<TerrainVariant> terrain_variants; + Map::terrain_variant_map_t terrain_variant_map; + godot::Ref<godot::Texture2DArray> terrain_texture; godot::Error _parse_province_identifier_entry(godot::String const& identifier, godot::Variant const& entry); godot::Error _parse_region_entry(godot::String const& identifier, godot::Variant const& entry); + godot::Error _parse_terrain_entry(godot::String const& identifier, godot::Variant const& entry); void _tick(); protected: static void _bind_methods(); @@ -33,17 +48,45 @@ namespace OpenVic2 { godot::Error load_province_identifier_file(godot::String const& file_path); godot::Error load_water_province_file(godot::String const& file_path); godot::Error load_region_file(godot::String const& file_path); - godot::Error load_province_shape_file(godot::String const& file_path); + godot::Error load_terrain_file(godot::String const& file_path); + godot::Error load_map_images(godot::String const& province_image_path, godot::String const& terrain_image_path); + + /* Post-load/restart game setup - reset the game to post-load state + * and (re)generate starting data, e.g. buildings. + */ godot::Error setup(); int32_t get_province_index_from_uv_coords(godot::Vector2 const& coords) const; godot::Dictionary get_province_info_from_index(int32_t index) const; int32_t get_width() const; int32_t get_height() const; - godot::Array get_province_index_images() const; - godot::Ref<godot::Image> get_province_colour_image() const; + float get_aspect_ratio() const; + /* The cosmetic terrain textures stored in a Texture2DArray. + */ + godot::Ref<godot::Texture> get_terrain_texture() const; + + /* Number of (vertical, horizontal) subdivisions the province shape image + * was split into when making the province_shape_texture to ensure no + * piece had a dimension greater than 16383. + */ + godot::Vector2i get_province_shape_image_subdivisions() const; + + /* The map, encoded in RGB8 with RG representing province index and B representing terrain texture. + * To support a wider range of GPUs, the image is divided so that no piece has a dimension + * greater than 16383 and the pieces are stored in a Texture2DArray. + */ + godot::Ref<godot::Texture> get_province_shape_texture() const; + + /* The colour each province should be tinted, arranged in + * index order into a 256x256 RGB8 texture. + */ + godot::Ref<godot::Texture> get_province_colour_texture() const; + + /* Generate the province_colour_texture from the current mapmode. + */ godot::Error update_colour_image(); + int32_t get_mapmode_count() const; godot::String get_mapmode_identifier(int32_t index) const; godot::Error set_mapmode(godot::String const& identifier); diff --git a/extension/src/MapMesh.cpp b/extension/src/MapMesh.cpp index 91c7611..6d94973 100644 --- a/extension/src/MapMesh.cpp +++ b/extension/src/MapMesh.cpp @@ -50,21 +50,21 @@ float MapMesh::get_repeat_proportion() const { return repeat_proportion; } -void MapMesh::set_subdivide_width(const int divisions) { +void MapMesh::set_subdivide_width(const int32_t divisions) { subdivide_w = divisions > 0 ? divisions : 0; _request_update(); } -int MapMesh::get_subdivide_width() const { +int32_t MapMesh::get_subdivide_width() const { return subdivide_w; } -void MapMesh::set_subdivide_depth(const int divisions) { +void MapMesh::set_subdivide_depth(const int32_t divisions) { subdivide_d = divisions > 0 ? divisions : 0; _request_update(); } -int MapMesh::get_subdivide_depth() const { +int32_t MapMesh::get_subdivide_depth() const { return subdivide_d; } @@ -81,8 +81,8 @@ Array MapMesh::_create_mesh_array() const { Array arr; arr.resize(Mesh::ARRAY_MAX); - const int vertex_count = (subdivide_w + 2) * (subdivide_d + 2); - const int indice_count = (subdivide_w + 1) * (subdivide_d + 1) * 6; + const int32_t vertex_count = (subdivide_w + 2) * (subdivide_d + 2); + const int32_t indice_count = (subdivide_w + 1) * (subdivide_d + 1) * 6; PackedVector3Array points; PackedVector3Array normals; @@ -100,17 +100,17 @@ Array MapMesh::_create_mesh_array() const { const Size2 uv_size{ 1.0f + 2.0f * repeat_proportion, 1.0f }; const Size2 size{ aspect_ratio * uv_size.x, uv_size.y }, start_pos = size * -0.5f; - int point_index = 0, thisrow = 0, prevrow = 0, indice_index = 0; + int32_t point_index = 0, thisrow = 0, prevrow = 0, indice_index = 0; Vector2 subdivide_step{ 1.0f / (subdivide_w + 1.0f) , 1.0f / (subdivide_d + 1.0f) }; Vector3 point{ 0.0f, 0.0f, start_pos.y }; Vector2 point_step = subdivide_step * size; Vector2 uv{}, uv_step = subdivide_step * uv_size; - for (int j = 0; j <= subdivide_d + 1; ++j) { + for (int32_t j = 0; j <= subdivide_d + 1; ++j) { point.x = start_pos.x; uv.x = -repeat_proportion; - for (int i = 0; i <= subdivide_w + 1; ++i) { + for (int32_t i = 0; i <= subdivide_w + 1; ++i) { points[point_index] = point; normals[point_index] = normal; tangents[point_index * 4 + 0] = 1.0f; diff --git a/extension/src/MapMesh.hpp b/extension/src/MapMesh.hpp index d8727cf..89c0147 100644 --- a/extension/src/MapMesh.hpp +++ b/extension/src/MapMesh.hpp @@ -7,7 +7,7 @@ namespace OpenVic2 { GDCLASS(MapMesh, godot::PrimitiveMesh) float aspect_ratio = 2.0f, repeat_proportion = 0.5f; - int subdivide_w = 0, subdivide_d = 0; + int32_t subdivide_w = 0, subdivide_d = 0; protected: static void _bind_methods(); @@ -20,11 +20,11 @@ namespace OpenVic2 { void set_repeat_proportion(const float proportion); float get_repeat_proportion() const; - void set_subdivide_width(const int divisions); - int get_subdivide_width() const; + void set_subdivide_width(const int32_t divisions); + int32_t get_subdivide_width() const; - void set_subdivide_depth(const int divisions); - int get_subdivide_depth() const; + void set_subdivide_depth(const int32_t divisions); + int32_t get_subdivide_depth() const; godot::AABB get_core_aabb() const; bool is_valid_uv_coord(godot::Vector2 const& uv) const; diff --git a/extension/src/openvic2/Date.cpp b/extension/src/openvic2/Date.cpp index bb891fd..ed800d5 100644 --- a/extension/src/openvic2/Date.cpp +++ b/extension/src/openvic2/Date.cpp @@ -1,9 +1,9 @@ -#include "openvic2/Date.hpp" +#include "Date.hpp" #include <cctype> #include <algorithm> -#include "openvic2/Logger.hpp" +#include "Logger.hpp" using namespace OpenVic2; diff --git a/extension/src/openvic2/GameAdvancementHook.cpp b/extension/src/openvic2/GameAdvancementHook.cpp index 4b9bc25..d90b7b1 100644 --- a/extension/src/openvic2/GameAdvancementHook.cpp +++ b/extension/src/openvic2/GameAdvancementHook.cpp @@ -1,4 +1,4 @@ -#include "openvic2/GameAdvancementHook.hpp" +#include "GameAdvancementHook.hpp" using namespace OpenVic2; diff --git a/extension/src/openvic2/GameManager.cpp b/extension/src/openvic2/GameManager.cpp index 78992f1..58e40bb 100644 --- a/extension/src/openvic2/GameManager.cpp +++ b/extension/src/openvic2/GameManager.cpp @@ -1,6 +1,6 @@ -#include "openvic2/GameManager.hpp" +#include "GameManager.hpp" -#include "openvic2/Logger.hpp" +#include "Logger.hpp" using namespace OpenVic2; @@ -38,7 +38,7 @@ Date const& GameManager::get_today() const { return today; } -return_t GameManager::expand_building(Province::index_t province_index, std::string const& building_type_identifier) { +return_t GameManager::expand_building(index_t province_index, std::string const& building_type_identifier) { set_needs_update(); Province* province = map.get_province_by_index(province_index); if (province == nullptr) return FAILURE; diff --git a/extension/src/openvic2/GameManager.hpp b/extension/src/openvic2/GameManager.hpp index 65cd566..70e98bd 100644 --- a/extension/src/openvic2/GameManager.hpp +++ b/extension/src/openvic2/GameManager.hpp @@ -1,7 +1,7 @@ #pragma once -#include "openvic2/GameAdvancementHook.hpp" -#include "openvic2/map/Map.hpp" +#include "GameAdvancementHook.hpp" +#include "map/Map.hpp" namespace OpenVic2 { struct GameManager { @@ -24,6 +24,6 @@ namespace OpenVic2 { return_t setup(); Date const& get_today() const; - return_t expand_building(Province::index_t province_index, std::string const& building_type_identifier); + return_t expand_building(index_t province_index, std::string const& building_type_identifier); }; } diff --git a/extension/src/openvic2/Good.cpp b/extension/src/openvic2/Good.cpp new file mode 100644 index 0000000..e3389de --- /dev/null +++ b/extension/src/openvic2/Good.cpp @@ -0,0 +1,3 @@ +#include "Good.hpp" + +using namespace OpenVic2; diff --git a/extension/src/openvic2/Good.hpp b/extension/src/openvic2/Good.hpp new file mode 100644 index 0000000..378bbc4 --- /dev/null +++ b/extension/src/openvic2/Good.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "Types.hpp" + +namespace OpenVic2 { + class Good : HasIdentifier { + public: + std::string category; + price_t cost; + std::string colour; + bool isAvailable; + bool isTradable; + bool isMoney; + bool hasOverseasPenalty; + + Good(Good&&) = default; + Good(std::string const& identifier,std::string const& category, price_t cost, std::string const& colour, + bool isAvailable, bool isTradable, bool isMoney, bool hasOverseasPenalty) : HasIdentifier(identifier), + category(category), cost(cost), colour(colour), isAvailable(isAvailable), isMoney(isMoney), hasOverseasPenalty(hasOverseasPenalty) {}; + }; +} diff --git a/extension/src/openvic2/Logger.cpp b/extension/src/openvic2/Logger.cpp index 56d74ab..4d7378e 100644 --- a/extension/src/openvic2/Logger.cpp +++ b/extension/src/openvic2/Logger.cpp @@ -1,4 +1,4 @@ -#include "openvic2/Logger.hpp" +#include "Logger.hpp" #include <iostream> diff --git a/extension/src/openvic2/Types.cpp b/extension/src/openvic2/Types.cpp index 861ab50..f51ad7c 100644 --- a/extension/src/openvic2/Types.cpp +++ b/extension/src/openvic2/Types.cpp @@ -1,6 +1,8 @@ -#include "openvic2/Types.hpp" +#include "Types.hpp" #include <cassert> +#include <sstream> +#include <iomanip> using namespace OpenVic2; @@ -11,3 +13,19 @@ HasIdentifier::HasIdentifier(std::string const& new_identifier) : identifier{ ne std::string const& HasIdentifier::get_identifier() const { return identifier; } + +HasColour::HasColour(colour_t const new_colour) : colour(new_colour) { + assert(colour != NULL_COLOUR && colour <= MAX_COLOUR_RGB); +} + +colour_t HasColour::get_colour() const { return colour; } + +std::string OpenVic2::HasColour::colour_to_hex_string(colour_t const colour) { + std::ostringstream stream; + stream << std::hex << std::setfill('0') << std::setw(6) << colour; + return stream.str(); +} + +std::string HasColour::colour_to_hex_string() const { + return colour_to_hex_string(colour); +} diff --git a/extension/src/openvic2/Types.hpp b/extension/src/openvic2/Types.hpp index 98e92ce..e4a0e2d 100644 --- a/extension/src/openvic2/Types.hpp +++ b/extension/src/openvic2/Types.hpp @@ -1,12 +1,32 @@ #pragma once -#include <string> #include <vector> +#include <cstdint> +#include <algorithm> +#include <map> -#include "openvic2/Logger.hpp" +#include "Logger.hpp" namespace OpenVic2 { + // Represents a 24-bit RGB integer OR a 32-bit ARGB integer + using colour_t = uint32_t; + /* When colour_t is used as an identifier, NULL_COLOUR is disallowed + * and should be reserved as an error value. + * When colour_t is used in a purely graphical context, NULL_COLOUR + * should be allowed. + */ + static constexpr colour_t NULL_COLOUR = 0, MAX_COLOUR_RGB = 0xFFFFFF; + constexpr colour_t to_alpha_value(float a) { + return static_cast<colour_t>(std::clamp(a, 0.0f, 1.0f) * 255.0f) << 24; + } + + using index_t = uint16_t; + static constexpr index_t NULL_INDEX = 0, MAX_INDEX = 0xFFFF; + + // TODO: price_t must be changed to a fixed-point numeric type before multiplayer + using price_t = double; using return_t = bool; + // This mirrors godot::Error, where `OK = 0` and `FAILED = 1`. static constexpr return_t SUCCESS = false, FAILURE = true; @@ -29,6 +49,24 @@ namespace OpenVic2 { }; /* + * Base class for objects with associated colour information + */ + class HasColour { + const colour_t colour; + protected: + HasColour(colour_t const new_colour); + public: + HasColour(HasColour const&) = delete; + HasColour(HasColour&&) = default; + HasColour& operator=(HasColour const&) = delete; + HasColour& operator=(HasColour&&) = delete; + + colour_t get_colour() const; + std::string colour_to_hex_string() const; + static std::string colour_to_hex_string(colour_t const colour); + }; + + /* * Template for a list of objects with unique string identifiers that can * be locked to prevent any further additions. The template argument T is * the type of object that the registry will store, and the second part ensures @@ -36,9 +74,12 @@ namespace OpenVic2 { */ template<class T, typename std::enable_if<std::is_base_of<HasIdentifier, T>::value>::type* = nullptr> class IdentifierRegistry { + using identifier_index_map_t = std::map<std::string, size_t>; + const std::string name; std::vector<T> items; bool locked = false; + identifier_index_map_t identifier_index_map; public: IdentifierRegistry(std::string const& new_name) : name(new_name) {} return_t add_item(T&& item) { @@ -51,6 +92,7 @@ namespace OpenVic2 { Logger::error("Cannot add item to the ", name, " registry - an item with the identifier \"", item.get_identifier(), "\" already exists!"); return FAILURE; } + identifier_index_map[item.get_identifier()] = items.size(); items.push_back(std::move(item)); return SUCCESS; } @@ -66,6 +108,7 @@ namespace OpenVic2 { return locked; } void reset() { + identifier_index_map.clear(); items.clear(); locked = false; } @@ -73,15 +116,13 @@ namespace OpenVic2 { return items.size(); } T* get_item_by_identifier(std::string const& identifier) { - if (!identifier.empty()) - for (T& item : items) - if (item.get_identifier() == identifier) return &item; + const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier); + if (it != identifier_index_map.end()) return &items[it->second]; return nullptr; } T const* get_item_by_identifier(std::string const& identifier) const { - if (!identifier.empty()) - for (T const& item : items) - if (item.get_identifier() == identifier) return &item; + const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier); + if (it != identifier_index_map.end()) return &items[it->second]; return nullptr; } T* get_item_by_index(size_t index) { diff --git a/extension/src/openvic2/map/Building.cpp b/extension/src/openvic2/map/Building.cpp index 00e121b..1e26873 100644 --- a/extension/src/openvic2/map/Building.cpp +++ b/extension/src/openvic2/map/Building.cpp @@ -1,9 +1,9 @@ -#include "openvic2/map/Building.hpp" +#include "Building.hpp" #include <cassert> -#include "openvic2/Logger.hpp" -#include "openvic2/map/Province.hpp" +#include "../Logger.hpp" +#include "Province.hpp" using namespace OpenVic2; diff --git a/extension/src/openvic2/map/Building.hpp b/extension/src/openvic2/map/Building.hpp index 1305014..78d08ae 100644 --- a/extension/src/openvic2/map/Building.hpp +++ b/extension/src/openvic2/map/Building.hpp @@ -2,8 +2,8 @@ #include <vector> -#include "openvic2/Types.hpp" -#include "openvic2/Date.hpp" +#include "../Types.hpp" +#include "../Date.hpp" namespace OpenVic2 { struct Province; diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp index b5cf144..1f44c43 100644 --- a/extension/src/openvic2/map/Map.cpp +++ b/extension/src/openvic2/map/Map.cpp @@ -1,9 +1,9 @@ -#include "openvic2/map/Map.hpp" +#include "Map.hpp" #include <cassert> #include <unordered_set> -#include "openvic2/Logger.hpp" +#include "../Logger.hpp" using namespace OpenVic2; @@ -16,31 +16,32 @@ Mapmode::index_t Mapmode::get_index() const { return index; } -Province::colour_t Mapmode::get_colour(Map const& map, Province const& province) const { - return colour_func ? colour_func(map, province) : Province::NULL_COLOUR; +colour_t Mapmode::get_colour(Map const& map, Province const& province) const { + return colour_func ? colour_func(map, province) : NULL_COLOUR; } Map::Map() : provinces{ "provinces" }, regions{ "regions" }, mapmodes{ "mapmodes" } {} -return_t Map::add_province(std::string const& identifier, Province::colour_t colour) { - if (provinces.get_item_count() >= Province::MAX_INDEX) { - Logger::error("The map's province list is full - there can be at most ", Province::MAX_INDEX, " provinces"); +return_t Map::add_province(std::string const& identifier, colour_t colour) { + if (provinces.get_item_count() >= MAX_INDEX) { + Logger::error("The map's province list is full - there can be at most ", MAX_INDEX, " provinces"); return FAILURE; } if (identifier.empty()) { Logger::error("Invalid province identifier - empty!"); return FAILURE; } - if (colour == Province::NULL_COLOUR || colour > Province::MAX_COLOUR) { + if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) { Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour)); return FAILURE; } - Province new_province{ static_cast<Province::index_t>(provinces.get_item_count() + 1), identifier, colour }; - Province const* old_province = get_province_by_colour(colour); - if (old_province != nullptr) { - Logger::error("Duplicate province colours: ", old_province->to_string(), " and ", new_province.to_string()); + Province new_province{ static_cast<index_t>(provinces.get_item_count() + 1), identifier, colour }; + const index_t index = get_index_from_colour(colour); + if (index != NULL_INDEX) { + Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string()); return FAILURE; } + colour_index_map[new_province.get_colour()] = new_province.get_index(); return provinces.add_item(std::move(new_province)); } @@ -126,12 +127,12 @@ size_t Map::get_province_count() const { return provinces.get_item_count(); } -Province* Map::get_province_by_index(Province::index_t index) { - return index != Province::NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr; +Province* Map::get_province_by_index(index_t index) { + return index != NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr; } -Province const* Map::get_province_by_index(Province::index_t index) const { - return index != Province::NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr; +Province const* Map::get_province_by_index(index_t index) const { + return index != NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr; } Province* Map::get_province_by_identifier(std::string const& identifier) { @@ -142,23 +143,15 @@ Province const* Map::get_province_by_identifier(std::string const& identifier) c return provinces.get_item_by_identifier(identifier); } -Province* Map::get_province_by_colour(Province::colour_t colour) { - if (colour != Province::NULL_COLOUR) - for (Province& province : provinces.get_items()) - if (province.get_colour() == colour) return &province; - return nullptr; +index_t Map::get_index_from_colour(colour_t colour) const { + const colour_index_map_t::const_iterator it = colour_index_map.find(colour); + if (it != colour_index_map.end()) return it->second; + return NULL_INDEX; } -Province const* Map::get_province_by_colour(Province::colour_t colour) const { - if (colour != Province::NULL_COLOUR) - for (Province const& province : provinces.get_items()) - if (province.get_colour() == colour) return &province; - return nullptr; -} - -Province::index_t Map::get_province_index_at(size_t x, size_t y) const { - if (x < width && y < height) return province_index_image[x + y * width]; - return Province::NULL_INDEX; +index_t Map::get_province_index_at(size_t x, size_t y) const { + if (x < width && y < height) return province_shape_image[x + y * width].index; + return NULL_INDEX; } Region* Map::get_region_by_identifier(std::string const& identifier) { @@ -169,12 +162,13 @@ Region const* Map::get_region_by_identifier(std::string const& identifier) const return regions.get_item_by_identifier(identifier); } -static Province::colour_t colour_at(uint8_t const* colour_data, int32_t idx) { +static colour_t colour_at(uint8_t const* colour_data, int32_t idx) { return (colour_data[idx * 3] << 16) | (colour_data[idx * 3 + 1] << 8) | colour_data[idx * 3 + 2]; } -return_t Map::generate_province_index_image(size_t new_width, size_t new_height, uint8_t const* colour_data) { - if (!province_index_image.empty()) { +return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data, + uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map) { + if (!province_shape_image.empty()) { Logger::error("Province index image has already been generated!"); return FAILURE; } @@ -190,45 +184,61 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height, Logger::error("Province colour data pointer is null!"); return FAILURE; } + if (terrain_data == nullptr) { + Logger::error("Province terrain data pointer is null!"); + return FAILURE; + } width = new_width; height = new_height; - province_index_image.resize(width * height); + province_shape_image.resize(width * height); std::vector<bool> province_checklist(provinces.get_item_count()); return_t ret = SUCCESS; - std::unordered_set<Province::colour_t> unrecognised_colours; + std::unordered_set<colour_t> unrecognised_province_colours, unrecognised_terrain_colours; for (int32_t y = 0; y < height; ++y) { for (int32_t x = 0; x < width; ++x) { const int32_t idx = x + y * width; - const Province::colour_t colour = colour_at(colour_data, idx); + + const colour_t terrain_colour = colour_at(terrain_data, idx); + const terrain_variant_map_t::const_iterator it = terrain_variant_map.find(terrain_colour); + if (it != terrain_variant_map.end()) province_shape_image[idx].terrain = it->second; + else { + if (unrecognised_terrain_colours.find(terrain_colour) == unrecognised_terrain_colours.end()) { + unrecognised_terrain_colours.insert(terrain_colour); + Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour), " at (", x, ", ", y, ")"); + ret = FAILURE; + } + province_shape_image[idx].terrain = 0; + } + + const colour_t province_colour = colour_at(colour_data, idx); if (x > 0) { const int32_t jdx = idx - 1; - if (colour_at(colour_data, jdx) == colour) { - province_index_image[idx] = province_index_image[jdx]; + if (colour_at(colour_data, jdx) == province_colour) { + province_shape_image[idx].index = province_shape_image[jdx].index; continue; } } if (y > 0) { const int32_t jdx = idx - width; - if (colour_at(colour_data, jdx) == colour) { - province_index_image[idx] = province_index_image[jdx]; + if (colour_at(colour_data, jdx) == province_colour) { + province_shape_image[idx].index = province_shape_image[jdx].index; continue; } } - Province const* province = get_province_by_colour(colour); - if (province != nullptr) { - const Province::index_t index = province->get_index(); - province_index_image[idx] = index; + const index_t index = get_index_from_colour(province_colour); + if (index != NULL_INDEX) { province_checklist[index - 1] = true; + province_shape_image[idx].index = index; continue; } - if (unrecognised_colours.find(colour) == unrecognised_colours.end()) { - unrecognised_colours.insert(colour); - Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(colour), " at (", x, ", ", y, ")"); + if (unrecognised_province_colours.find(province_colour) == unrecognised_province_colours.end()) { + unrecognised_province_colours.insert(province_colour); + Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour), " at (", x, ", ", y, ")"); ret = FAILURE; } - province_index_image[idx] = Province::NULL_INDEX; + province_shape_image[idx].index = NULL_INDEX; } } @@ -249,8 +259,8 @@ size_t Map::get_height() const { return height; } -std::vector<Province::index_t> const& Map::get_province_index_image() const { - return province_index_image; +std::vector<Map::shape_pixel_t> const& Map::get_province_shape_image() const { + return province_shape_image; } return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func) { @@ -291,13 +301,15 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) Logger::error("Invalid mapmode index: ", index); return FAILURE; } - target += 4; // Skip past Province::NULL_INDEX + // Skip past Province::NULL_INDEX + for (size_t i = 0; i < MAPMODE_COLOUR_SIZE; ++i) + *target++ = 0; for (Province const& province : provinces.get_items()) { - const Province::colour_t colour = mapmode->get_colour(*this, province); + const colour_t colour = mapmode->get_colour(*this, province); *target++ = (colour >> 16) & 0xFF; *target++ = (colour >> 8) & 0xFF; *target++ = colour & 0xFF; - *target++ = province.is_water() ? 0 : 255; + *target++ = (colour >> 24) & 0xFF; } return SUCCESS; } diff --git a/extension/src/openvic2/map/Map.hpp b/extension/src/openvic2/map/Map.hpp index ebc23be..cb8dcb1 100644 --- a/extension/src/openvic2/map/Map.hpp +++ b/extension/src/openvic2/map/Map.hpp @@ -2,14 +2,14 @@ #include <functional> -#include "openvic2/map/Region.hpp" +#include "Region.hpp" namespace OpenVic2 { struct Mapmode : HasIdentifier { friend struct Map; - using colour_func_t = std::function<Province::colour_t (Map const&, Province const&)>; + using colour_func_t = std::function<colour_t (Map const&, Province const&)>; using index_t = size_t; private: const index_t index; @@ -18,14 +18,25 @@ namespace OpenVic2 { Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func); public: index_t get_index() const; - Province::colour_t get_colour(Map const& map, Province const& province) const; + colour_t get_colour(Map const& map, Province const& province) const; }; /* REQUIREMENTS: * MAP-4 */ struct Map { + using terrain_t = uint8_t; + using terrain_variant_map_t = std::map<colour_t, terrain_t>; + + #pragma pack(push, 1) + struct shape_pixel_t { + index_t index; + terrain_t terrain; + }; + #pragma pack(pop) private: + using colour_index_map_t = std::map<colour_t, index_t>; + IdentifierRegistry<Province> provinces; IdentifierRegistry<Region> regions; IdentifierRegistry<Mapmode> mapmodes; @@ -33,11 +44,14 @@ namespace OpenVic2 { size_t water_province_count = 0; size_t width = 0, height = 0; - std::vector<Province::index_t> province_index_image; + std::vector<shape_pixel_t> province_shape_image; + colour_index_map_t colour_index_map; + + index_t get_index_from_colour(colour_t colour) const; public: Map(); - return_t add_province(std::string const& identifier, Province::colour_t colour); + return_t add_province(std::string const& identifier, colour_t colour); void lock_provinces(); return_t set_water_province(std::string const& identifier); void lock_water_provinces(); @@ -45,27 +59,27 @@ namespace OpenVic2 { void lock_regions(); size_t get_province_count() const; - Province* get_province_by_index(Province::index_t index); - Province const* get_province_by_index(Province::index_t index) const; + Province* get_province_by_index(index_t index); + Province const* get_province_by_index(index_t index) const; Province* get_province_by_identifier(std::string const& identifier); Province const* get_province_by_identifier(std::string const& identifier) const; - Province* get_province_by_colour(Province::colour_t colour); - Province const* get_province_by_colour(Province::colour_t colour) const; - Province::index_t get_province_index_at(size_t x, size_t y) const; + index_t get_province_index_at(size_t x, size_t y) const; Region* get_region_by_identifier(std::string const& identifier); Region const* get_region_by_identifier(std::string const& identifier) const; - return_t generate_province_index_image(size_t new_width, size_t new_height, uint8_t const* colour_data); + return_t generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data, + uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map); size_t get_width() const; size_t get_height() const; - std::vector<Province::index_t> const& get_province_index_image() const; + std::vector<shape_pixel_t> const& get_province_shape_image() const; return_t add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func); void lock_mapmodes(); size_t get_mapmode_count() const; Mapmode const* get_mapmode_by_index(Mapmode::index_t index) const; Mapmode const* get_mapmode_by_identifier(std::string const& identifier) const; + static constexpr size_t MAPMODE_COLOUR_SIZE = 4; return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; return_t generate_province_buildings(BuildingManager const& manager); diff --git a/extension/src/openvic2/map/Province.cpp b/extension/src/openvic2/map/Province.cpp index 4360bce..b3d455b 100644 --- a/extension/src/openvic2/map/Province.cpp +++ b/extension/src/openvic2/map/Province.cpp @@ -1,4 +1,4 @@ -#include "openvic2/map/Province.hpp" +#include "Province.hpp" #include <cassert> #include <sstream> @@ -7,25 +7,15 @@ using namespace OpenVic2; Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) : - HasIdentifier{ new_identifier }, index{ new_index }, colour{ new_colour }, buildings{ "buildings" } { + HasIdentifier{ new_identifier }, HasColour{ new_colour }, index{ new_index }, buildings{ "buildings" } { assert(index != NULL_INDEX); - assert(colour != NULL_COLOUR); + assert(new_colour != NULL_COLOUR); } -std::string Province::colour_to_hex_string(colour_t colour) { - std::ostringstream stream; - stream << std::hex << std::setfill('0') << std::setw(6) << colour; - return stream.str(); -} - -Province::index_t Province::get_index() const { +index_t Province::get_index() const { return index; } -Province::colour_t Province::get_colour() const { - return colour; -} - Region* Province::get_region() const { return region; } @@ -62,7 +52,7 @@ return_t Province::expand_building(std::string const& building_type_identifier) std::string Province::to_string() const { std::stringstream stream; - stream << "(#" << std::to_string(index) << ", " << get_identifier() << ", 0x" << colour_to_hex_string(colour) << ")"; + stream << "(#" << std::to_string(index) << ", " << get_identifier() << ", 0x" << colour_to_hex_string() << ")"; return stream.str(); } diff --git a/extension/src/openvic2/map/Province.hpp b/extension/src/openvic2/map/Province.hpp index aa0329c..9b07fc1 100644 --- a/extension/src/openvic2/map/Province.hpp +++ b/extension/src/openvic2/map/Province.hpp @@ -1,6 +1,6 @@ #pragma once -#include "openvic2/map/Building.hpp" +#include "Building.hpp" namespace OpenVic2 { struct Map; @@ -9,18 +9,13 @@ namespace OpenVic2 { /* REQUIREMENTS: * MAP-5, MAP-8, MAP-43, MAP-47 */ - struct Province : HasIdentifier { + struct Province : HasIdentifier, HasColour { friend struct Map; - using colour_t = uint32_t; - using index_t = uint16_t; using life_rating_t = int8_t; - static constexpr colour_t NULL_COLOUR = 0, MAX_COLOUR = 0xFFFFFF; - static constexpr index_t NULL_INDEX = 0, MAX_INDEX = 0xFFFF; private: const index_t index; - const colour_t colour; Region* region = nullptr; bool water = false; life_rating_t life_rating = 0; @@ -28,12 +23,9 @@ namespace OpenVic2 { Province(index_t new_index, std::string const& new_identifier, colour_t new_colour); public: - static std::string colour_to_hex_string(colour_t colour); - Province(Province&&) = default; index_t get_index() const; - colour_t get_colour() const; Region* get_region() const; bool is_water() const; life_rating_t get_life_rating() const; diff --git a/extension/src/openvic2/map/Region.cpp b/extension/src/openvic2/map/Region.cpp index 3e5bee7..da0dfdd 100644 --- a/extension/src/openvic2/map/Region.cpp +++ b/extension/src/openvic2/map/Region.cpp @@ -1,7 +1,6 @@ -#include "openvic2/map/Region.hpp" +#include "Region.hpp" #include <cassert> -#include <algorithm> using namespace OpenVic2; @@ -19,8 +18,7 @@ std::set<Province*> const& ProvinceSet::get_provinces() const { Region::Region(std::string const& new_identifier) : HasIdentifier{ new_identifier } {} -Province::colour_t Region::get_colour() const { +colour_t Region::get_colour() const { if (provinces.empty()) return 0xFF0000; - Province const* province = *provinces.cbegin(); - return province->get_colour(); + return (*provinces.cbegin())->get_colour(); } diff --git a/extension/src/openvic2/map/Region.hpp b/extension/src/openvic2/map/Region.hpp index 04564fc..3920dfc 100644 --- a/extension/src/openvic2/map/Region.hpp +++ b/extension/src/openvic2/map/Region.hpp @@ -2,7 +2,7 @@ #include <set> -#include "openvic2/map/Province.hpp" +#include "Province.hpp" namespace OpenVic2 { @@ -25,6 +25,6 @@ namespace OpenVic2 { public: Region(Region&&) = default; - Province::colour_t get_colour() const; + colour_t get_colour() const; }; } diff --git a/game/art/terrain/desert_rocky.png b/game/art/terrain/desert_rocky.png Binary files differnew file mode 100644 index 0000000..f7f9155 --- /dev/null +++ b/game/art/terrain/desert_rocky.png diff --git a/game/art/terrain/desert_rocky.png.import b/game/art/terrain/desert_rocky.png.import new file mode 100644 index 0000000..b8104eb --- /dev/null +++ b/game/art/terrain/desert_rocky.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://do6rtj6cejxo7" +path="res://.godot/imported/desert_rocky.png-2c26845e144e1e8b9c55419654df6654.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/terrain/desert_rocky.png" +dest_files=["res://.godot/imported/desert_rocky.png-2c26845e144e1e8b9c55419654df6654.ctex"] + +[params] + +compress/mode=3 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=2 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=false +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/game/art/terrain/desert_smooth.png b/game/art/terrain/desert_smooth.png Binary files differnew file mode 100644 index 0000000..4e977cd --- /dev/null +++ b/game/art/terrain/desert_smooth.png diff --git a/game/art/terrain/desert_smooth.png.import b/game/art/terrain/desert_smooth.png.import new file mode 100644 index 0000000..bc0513d --- /dev/null +++ b/game/art/terrain/desert_smooth.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://beo5i11jfu3al" +path="res://.godot/imported/desert_smooth.png-58a5349b112e9e97cf3426b380f022ef.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/terrain/desert_smooth.png" +dest_files=["res://.godot/imported/desert_smooth.png-58a5349b112e9e97cf3426b380f022ef.ctex"] + +[params] + +compress/mode=3 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=2 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=false +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/game/art/terrain/mountains.png b/game/art/terrain/mountains.png Binary files differnew file mode 100644 index 0000000..301ee23 --- /dev/null +++ b/game/art/terrain/mountains.png diff --git a/game/art/ui/minimap_frame.png.import b/game/art/terrain/mountains.png.import index 3d2aeee..47a00fd 100644 --- a/game/art/ui/minimap_frame.png.import +++ b/game/art/terrain/mountains.png.import @@ -2,16 +2,16 @@ importer="texture" type="CompressedTexture2D" -uid="uid://vr1hq2stk8ny" -path="res://.godot/imported/minimap_frame.png-3668393435d2582fb1dc8a9598573e80.ctex" +uid="uid://c20q2sqf38eq8" +path="res://.godot/imported/mountains.png-f1ab7d9b0a0deb485923c40b1cfb258e.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://art/ui/minimap_frame.png" -dest_files=["res://.godot/imported/minimap_frame.png-3668393435d2582fb1dc8a9598573e80.ctex"] +source_file="res://art/terrain/mountains.png" +dest_files=["res://.godot/imported/mountains.png-f1ab7d9b0a0deb485923c40b1cfb258e.ctex"] [params] diff --git a/game/art/terrain/ocean.png b/game/art/terrain/ocean.png Binary files differnew file mode 100644 index 0000000..3e52011 --- /dev/null +++ b/game/art/terrain/ocean.png diff --git a/game/art/ui/minimap.png.import b/game/art/terrain/ocean.png.import index 36f22e7..644f7e7 100644 --- a/game/art/ui/minimap.png.import +++ b/game/art/terrain/ocean.png.import @@ -2,16 +2,16 @@ importer="texture" type="CompressedTexture2D" -uid="uid://c0sm1jfu4kyv3" -path="res://.godot/imported/minimap.png-05ee44469856e77fd05107fe9e259e25.ctex" +uid="uid://dlvvim3j7dbnn" +path="res://.godot/imported/ocean.png-3d7e213c3fca805d033e0d3bf567fc01.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://art/ui/minimap.png" -dest_files=["res://.godot/imported/minimap.png-05ee44469856e77fd05107fe9e259e25.ctex"] +source_file="res://art/terrain/ocean.png" +dest_files=["res://.godot/imported/ocean.png-3d7e213c3fca805d033e0d3bf567fc01.ctex"] [params] diff --git a/game/art/ui/minimap.png b/game/art/ui/minimap.png Binary files differdeleted file mode 100644 index 9922b28..0000000 --- a/game/art/ui/minimap.png +++ /dev/null diff --git a/game/art/ui/minimap_frame.png b/game/art/ui/minimap_frame.png Binary files differdeleted file mode 100644 index 21aa2ce..0000000 --- a/game/art/ui/minimap_frame.png +++ /dev/null diff --git a/game/common/data/goods-jca.json b/game/common/data/goods-jca.json index 3a0390a..5017d7e 100644 --- a/game/common/data/goods-jca.json +++ b/game/common/data/goods-jca.json @@ -15,7 +15,7 @@ {"id": "precious_goods", "category": "Raw", "cost": 7.00, "colour": "247 241 61", "isAvailableAtStart": true, "isTradeable": false, "isMoney": true, "hasOverseasPenalty": false}, {"id": "rubber", "category": "Raw", "cost": 7.00, "colour": "123 110 86", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "silk", "category": "Raw", "cost": 10.00, "colour": "125 158 43", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, - {"id": "sulpher", "category": "Raw", "cost": 6.00, "colour": "181 228 102", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, + {"id": "sulphur", "category": "Raw", "cost": 6.00, "colour": "181 228 102", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "timber", "category": "Raw", "cost": 0.90, "colour": "146 72 17", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "tropical_wood", "category": "Raw", "cost": 5.40, "colour": "213 177 118", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "wool", "category": "Raw", "cost": 0.70, "colour": "234 195 158", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, diff --git a/game/common/data/goods.json b/game/common/data/goods.json index 4954fb0..9d8e0e3 100644 --- a/game/common/data/goods.json +++ b/game/common/data/goods.json @@ -14,7 +14,7 @@ {"id": "precious_metal", "category": "Raw", "cost": 8.00, "colour": "253 199 110", "isAvailableAtStart": true, "isTradeable": false, "isMoney": true, "hasOverseasPenalty": false}, {"id": "rubber", "category": "Raw", "cost": 7.00, "colour": "123 110 86", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "silk", "category": "Raw", "cost": 10.00, "colour": "125 158 43", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, - {"id": "sulpher", "category": "Raw", "cost": 6.00, "colour": "181 228 102", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, + {"id": "sulphur", "category": "Raw", "cost": 6.00, "colour": "181 228 102", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "timber", "category": "Raw", "cost": 0.90, "colour": "146 72 17", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "tropical_wood", "category": "Raw", "cost": 5.40, "colour": "213 177 118", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, {"id": "wool", "category": "Raw", "cost": 0.70, "colour": "234 195 158", "isAvailableAtStart": true, "isTradeable": true, "isMoney": false, "hasOverseasPenalty": false}, diff --git a/game/common/map/terrain.json b/game/common/map/terrain.json new file mode 100644 index 0000000..60596c9 --- /dev/null +++ b/game/common/map/terrain.json @@ -0,0 +1,7 @@ +{ + "ocean.png": "204080", + "farmlands.png": [88, 170, 37], + "mountains.png": "584B25", + "desert_rocky.png": "A06C38", + "desert_smooth.png": "BAA644" +} diff --git a/game/common/map/terrain.png b/game/common/map/terrain.png Binary files differnew file mode 100644 index 0000000..6e7ca0a --- /dev/null +++ b/game/common/map/terrain.png diff --git a/game/common/map/terrain.png.import b/game/common/map/terrain.png.import new file mode 100644 index 0000000..8dd0c09 --- /dev/null +++ b/game/common/map/terrain.png.import @@ -0,0 +1,3 @@ +[remap] + +importer="keep" diff --git a/game/project.godot b/game/project.godot index a43d7ba..a14f910 100644 --- a/game/project.godot +++ b/game/project.godot @@ -23,10 +23,9 @@ config/project_settings_override.template="user://settings.cfg" Events="*res://src/Autoload/Events.gd" Resolution="*res://src/Autoload/Resolution.gd" -MusicConductor="*res://src/MusicConductor/MusicConductor.tscn" SoundManager="*res://src/Autoload/SoundManager.gd" +MusicConductor="*res://src/MusicConductor/MusicConductor.tscn" Keychain="*res://addons/keychain/Keychain.gd" -GameDebug="*res://src/Autoload/GameDebug.gd" [display] diff --git a/game/src/Autoload/Events.gd b/game/src/Autoload/Events.gd index 7540d3e..47c3b88 100644 --- a/game/src/Autoload/Events.gd +++ b/game/src/Autoload/Events.gd @@ -1,12 +1,16 @@ extends Node +var GameDebug = preload("Events/GameDebug.gd").new() var Options = preload("Events/Options.gd").new() var Localisation = preload("Events/Localisation.gd").new() +var ShaderManager = preload("Events/ShaderManager.gd").new() const _province_identifier_file : String = "res://common/map/provinces.json" const _water_province_file : String = "res://common/map/water.json" const _region_file : String = "res://common/map/regions.json" -const _province_shape_file : String = "res://common/map/provinces.png" +const _terrain_file : String = "res://common/map/terrain.json" +const _province_image_file : String = "res://common/map/provinces.png" +const _terrain_image_file : String = "res://common/map/terrain.png" # REQUIREMENTS # * FS-333, FS-334, FS-335, FS-341 @@ -17,5 +21,7 @@ func _ready(): push_error("Failed to load water provinces") if GameSingleton.load_region_file(_region_file) != OK: push_error("Failed to load regions") - if GameSingleton.load_province_shape_file(_province_shape_file) != OK: - push_error("Failed to load province shapes") + if GameSingleton.load_terrain_file(_terrain_file) != OK: + push_error("Failed to load terrain variants") + if GameSingleton.load_map_images(_province_image_file, _terrain_image_file) != OK: + push_error("Failed to load map images") diff --git a/game/src/Autoload/GameDebug.gd b/game/src/Autoload/Events/GameDebug.gd index 6f10bf5..4e8931f 100644 --- a/game/src/Autoload/GameDebug.gd +++ b/game/src/Autoload/Events/GameDebug.gd @@ -1,8 +1,8 @@ -extends Node +extends RefCounted # REQUIREMENTS: # * SS-56 -func _ready(): +func _init(): for engine_args in OS.get_cmdline_args(): match(engine_args): "--game-debug": @@ -15,6 +15,7 @@ func _ready(): func set_debug_mode(value : bool) -> void: ProjectSettings.set_setting("openvic2/debug/enabled", value) + print("Set debug mode to: ", value) func is_debug_mode() -> bool: return ProjectSettings.get_setting("openvic2/debug/enabled", false) diff --git a/game/src/Autoload/Events/ShaderManager.gd b/game/src/Autoload/Events/ShaderManager.gd new file mode 100644 index 0000000..a503c52 --- /dev/null +++ b/game/src/Autoload/Events/ShaderManager.gd @@ -0,0 +1,48 @@ +extends RefCounted + +const param_province_shape_tex : StringName = &"province_shape_tex" +const param_province_shape_subdivisions : StringName = &"province_shape_subdivisions" +const param_province_colour_tex : StringName = &"province_colour_tex" +const param_hover_index : StringName = &"hover_index" +const param_selected_index : StringName = &"selected_index" +const param_terrain_tex : StringName = &"terrain_tex" +const param_terrain_tile_factor : StringName = &"terrain_tile_factor" + +func set_up_shader(material : Material, add_cosmetic_textures : bool) -> Error: + # Shader Material + if material == null: + push_error("material is null!") + return FAILED + if not material is ShaderMaterial: + push_error("Invalid map mesh material class: ", material.get_class()) + return FAILED + var shader_material : ShaderMaterial = material + + # Province shape texture + var province_shape_texture := GameSingleton.get_province_shape_texture() + if province_shape_texture == null: + push_error("Failed to get province shape texture!") + return FAILED + shader_material.set_shader_parameter(param_province_shape_tex, province_shape_texture) + var subdivisions := GameSingleton.get_province_shape_image_subdivisions() + if subdivisions.x < 1 or subdivisions.y < 1: + push_error("Invalid province shape image subdivision: ", subdivisions.x, "x", subdivisions.y) + return FAILED + shader_material.set_shader_parameter(param_province_shape_subdivisions, Vector2(subdivisions)) + + if add_cosmetic_textures: + # Province colour texture + var map_province_colour_texture := GameSingleton.get_province_colour_texture() + if map_province_colour_texture == null: + push_error("Failed to get province colour image!") + return FAILED + shader_material.set_shader_parameter(param_province_colour_tex, map_province_colour_texture) + + # Terrain texture + var terrain_texture := GameSingleton.get_terrain_texture() + if terrain_texture == null: + push_error("Failed to get terrain texture!") + return FAILED + shader_material.set_shader_parameter(param_terrain_tex, terrain_texture) + + return OK diff --git a/game/src/Autoload/Resolution.gd b/game/src/Autoload/Resolution.gd index e1e788b..35ecbb3 100644 --- a/game/src/Autoload/Resolution.gd +++ b/game/src/Autoload/Resolution.gd @@ -62,7 +62,7 @@ func get_resolution_display_name(resolution_value : Vector2i) -> StringName: func get_resolution_value_from_string(resolution_string : String) -> Vector2i: if not resolution_string.is_empty(): for resolution in _resolutions.values(): - if resolution_string == resolution.get(name) or resolution_string == resolution.display_name: + if resolution_string == resolution.name or resolution_string == resolution.display_name: return resolution.value var result := _regex.search(resolution_string) if result: return Vector2i(result.get_string(1).to_int(), result.get_string(2).to_int()) diff --git a/game/src/CreditsMenu/CreditsMenu.gd b/game/src/CreditsMenu/CreditsMenu.gd index 52c1711..0e9df6b 100644 --- a/game/src/CreditsMenu/CreditsMenu.gd +++ b/game/src/CreditsMenu/CreditsMenu.gd @@ -17,6 +17,9 @@ signal back_button_pressed @export_file("*.csv") var core_credits_path : String +@export +var godot_engine_scene : PackedScene + @export_group("Label Variants", "label_variants_") @export var label_variants_project : StringName @@ -114,10 +117,81 @@ func _add_project_credits(project : Dictionary) -> void: credits_list.add_child(project_credits_list) +func _add_godot_credits() -> void: + var godot_credits_list = VBoxContainer.new() + godot_credits_list.name = 'CreditsGodot' + var godot_engine = godot_engine_scene.instantiate() + godot_credits_list.add_child(godot_engine) + godot_credits_list.add_child(HSeparator.new()) + + var author_dict := Engine.get_author_info() + _add_label(godot_credits_list, "Contributors", label_variants_role) + + for role in author_dict: + var role_parent = VBoxContainer.new() + + for person in author_dict[role]: + _add_label(role_parent, person, label_variants_person) + + _add_label(godot_credits_list, role.replace("_", " ").capitalize(), label_variants_role) + godot_credits_list.add_child(role_parent) + godot_credits_list.add_child(HSeparator.new()) + + var donor_dict := Engine.get_donor_info() + _add_label(godot_credits_list, "Donors", label_variants_role) + + for role in donor_dict: + if donor_dict[role].size() == 0 or donor_dict[role][0].begins_with("None"): continue + var role_parent = VBoxContainer.new() + + for person in donor_dict[role]: + _add_label(role_parent, person, label_variants_person) + + _add_label(godot_credits_list, role.replace("_", " ").capitalize(), label_variants_role) + godot_credits_list.add_child(role_parent) + godot_credits_list.add_child(HSeparator.new()) + + credits_list.add_child(godot_credits_list) + +func _add_link_button(node : Node, text : String, url: String, type_variation : StringName) -> void: + var button := LinkButton.new() + button.name = 'LinkButton' + text + button.text = text + button.uri = url + button.size_flags_horizontal = SIZE_SHRINK_CENTER + button.theme_type_variation = type_variation + node.add_child(button) + +func _add_licenses() -> void: + var license_list = VBoxContainer.new() + license_list.name = 'Licenses' + _add_label(license_list, "Third-Party Licenses", label_variants_project) + license_list.add_child(HSeparator.new()) + + var license_info := { + "OpenVic2": ["GPLv3", "https://github.com/OpenVic2Project/OpenVic2/blob/main/LICENSE.md"], + "Godot": ["MIT", "https://github.com/godotengine/godot/blob/master/LICENSE.txt"], + "FreeType": ["FreeType License", "https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT"], + "ENet": ["MIT", "http://enet.bespin.org/License.html"], + "mbed TLS": ["APLv2", "https://github.com/Mbed-TLS/mbedtls/blob/development/LICENSE"] + } + # Add additional licenses required for attribution here + # These licenses should also either be displayed or exported alongside this project + + for project in license_info: + _add_label(license_list, project, label_variants_role) + _add_link_button(license_list, license_info[project][0], license_info[project][1], label_variants_person) + license_list.add_child(HSeparator.new()) + + credits_list.add_child(license_list) + + # REQUIREMENTS: # * SS-17 func _ready(): _add_project_credits(_load_credit_file(core_credits_path)) + _add_godot_credits() + _add_licenses() # REQUIREMENTS: # * UI-38 diff --git a/game/src/CreditsMenu/CreditsMenu.tscn b/game/src/CreditsMenu/CreditsMenu.tscn index 6c5f36b..2d10d2e 100644 --- a/game/src/CreditsMenu/CreditsMenu.tscn +++ b/game/src/CreditsMenu/CreditsMenu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://c8knthxkwj1uj"] +[gd_scene load_steps=4 format=3 uid="uid://c8knthxkwj1uj"] [ext_resource type="Theme" uid="uid://stfxt4hpsify" path="res://theme/credits_menu.tres" id="1_7y4l8"] [ext_resource type="Script" path="res://src/CreditsMenu/CreditsMenu.gd" id="1_csd7i"] +[ext_resource type="PackedScene" uid="uid://ddjbee5gj6bkv" path="res://src/CreditsMenu/GodotEngineButton.tscn" id="3_fl02a"] [node name="CreditsMenu" type="Control" node_paths=PackedStringArray("credits_list")] editor_description = "UI-34" @@ -14,6 +15,7 @@ grow_vertical = 2 theme = ExtResource("1_7y4l8") script = ExtResource("1_csd7i") core_credits_path = "res://common/credits.csv" +godot_engine_scene = ExtResource("3_fl02a") label_variants_project = &"ProjectLabel" label_variants_role = &"RoleLabel" label_variants_person = &"PersonLabel" diff --git a/game/src/CreditsMenu/GodotEngineButton.gd b/game/src/CreditsMenu/GodotEngineButton.gd new file mode 100644 index 0000000..ca3a958 --- /dev/null +++ b/game/src/CreditsMenu/GodotEngineButton.gd @@ -0,0 +1,4 @@ +extends Button + +func _on_pressed(): + OS.shell_open("https://godotengine.org") diff --git a/game/src/CreditsMenu/GodotEngineButton.tscn b/game/src/CreditsMenu/GodotEngineButton.tscn new file mode 100644 index 0000000..8b0c46b --- /dev/null +++ b/game/src/CreditsMenu/GodotEngineButton.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://ddjbee5gj6bkv"] + +[ext_resource type="Texture2D" uid="uid://rh7l4xuh4ali" path="res://src/CreditsMenu/logo_vertical_color_dark.svg" id="1_b0brk"] +[ext_resource type="Script" path="res://src/CreditsMenu/GodotEngineButton.gd" id="3_gi8fv"] + +[node name="GodotEngineButton" type="Button"] +custom_minimum_size = Vector2(0, 200) +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_vertical = 3 +icon = ExtResource("1_b0brk") +flat = true +icon_alignment = 1 +expand_icon = true +script = ExtResource("3_gi8fv") + +[connection signal="pressed" from="." to="." method="_on_pressed"] diff --git a/game/src/CreditsMenu/logo_vertical_color_dark.svg b/game/src/CreditsMenu/logo_vertical_color_dark.svg new file mode 100644 index 0000000..00e50cd --- /dev/null +++ b/game/src/CreditsMenu/logo_vertical_color_dark.svg @@ -0,0 +1 @@ +<svg height="713.37085" viewBox="0 0 584.81677 668.78517" width="623.80457" xmlns="http://www.w3.org/2000/svg"><g fill="#eee" transform="matrix(1.25 0 0 -1.25 -469.43319 897.49284)"><path d="m0 0c-3.611 0-6.636-1.659-9.09-4.967-2.441-3.311-3.668-7.958-3.668-13.938 0-5.993 1.166-10.581 3.503-13.778 2.333-3.207 5.398-4.804 9.2-4.804 3.8 0 6.887 1.617 9.258 4.862 2.371 3.233 3.559 7.861 3.559 13.886 0 6.02-1.227 10.654-3.673 13.89-2.443 3.232-5.473 4.849-9.089 4.849m-.055-59.493c-10.573 0-19.195 3.46-25.859 10.379-6.655 6.925-9.984 17.03-9.984 30.314 0 13.292 3.367 23.356 10.101 30.209 6.736 6.844 15.431 10.269 26.082 10.269 10.649 0 19.251-3.363 25.794-10.109 6.555-6.733 9.827-16.94 9.827-30.591 0-13.661-3.348-23.822-10.05-30.49-6.702-6.654-15.333-9.981-25.911-9.981" transform="matrix(1.1310535 0 0 1.1310535 531.44953 355.31567)"/><path d="m0 0v-33.768c0-1.577.116-2.571.342-2.988.224-.415.903-.623 2.029-.623 4.144 0 7.283 1.548 9.429 4.634 2.151 3.083 3.215 8.216 3.215 15.405 0 7.192-1.113 11.878-3.325 14.055-2.223 2.183-5.744 3.285-10.561 3.285zm-21.675-52.392v67.735c0 1.883.468 3.369 1.413 4.471.939 1.085 2.161 1.636 3.671 1.636h18.854c11.965 0 21.053-3.018 27.257-9.04 6.215-6.02 9.322-15.499 9.322-28.447 0-27.7-11.821-41.547-35.456-41.547h-19.302c-3.836 0-5.759 1.727-5.759 5.192" transform="matrix(1.1310535 0 0 1.1310535 607.8515 354.43097)"/><path d="m0 0c-3.612 0-6.645-1.659-9.095-4.967-2.44-3.311-3.662-7.958-3.662-13.938 0-5.993 1.169-10.581 3.499-13.778 2.33-3.207 5.398-4.804 9.2-4.804 3.801 0 6.89 1.617 9.258 4.862 2.372 3.233 3.56 7.861 3.56 13.886 0 6.02-1.225 10.654-3.671 13.89-2.447 3.232-5.473 4.849-9.089 4.849m-.058-59.493c-10.577 0-19.193 3.46-25.851 10.379-6.663 6.925-9.993 17.03-9.993 30.314 0 13.292 3.367 23.356 10.1 30.209 6.741 6.844 15.431 10.269 26.086 10.269 10.651 0 19.246-3.363 25.797-10.109 6.55-6.733 9.822-16.94 9.822-30.591 0-13.661-3.349-23.822-10.05-30.49-6.699-6.654-15.338-9.981-25.911-9.981" transform="matrix(1.1310535 0 0 1.1310535 700.81066 355.31567)"/><path d="m0 0c0-1.496-3.721-2.255-11.176-2.255-7.448 0-11.18.759-11.18 2.255v56.681h-13.545c-1.281 0-2.185 1.727-2.71 5.198-.226 1.652-.334 3.343-.334 5.077 0 1.724.108 3.422.334 5.077.525 3.462 1.429 5.202 2.71 5.202h49.112c1.279 0 2.179-1.74 2.712-5.202.221-1.655.335-3.353.335-5.077 0-1.734-.114-3.425-.335-5.077-.533-3.471-1.433-5.198-2.712-5.198h-13.211z" transform="matrix(1.1310535 0 0 1.1310535 789.01132 291.33514)"/><path d="m0 0c-6.078.094-13.034-1.173-13.034-1.173v-11.863h6.995l-.078-5.288c0-1.959-1.942-2.943-5.815-2.943-3.878 0-7.303 1.642-10.274 4.917-2.978 3.279-4.459 8.072-4.459 14.388 0 6.329 1.447 10.995 4.345 14.006 2.892 3.008 6.683 4.517 11.346 4.517 1.959 0 3.987-.316 6.096-.961 2.11-.639 3.519-1.238 4.238-1.799.713-.577 1.391-.85 2.032-.85.638 0 1.671.746 3.1 2.255 1.431 1.505 2.713 3.786 3.844 6.827 1.126 3.057 1.69 5.4 1.69 7.062 0 1.649-.036 2.786-.109 3.386-1.581 1.73-4.499 3.102-8.755 4.122-4.248 1.017-9.011 1.522-14.28 1.522-11.594 0-20.66-3.65-27.207-10.95-6.552-7.303-9.822-16.783-9.822-28.452 0-13.701 3.347-24.087 10.041-31.162 6.706-7.074 15.51-10.607 26.425-10.607 5.87 0 11.08.505 15.632 1.522 4.557 1.013 7.586 2.053 9.093 3.105l.452 35.33c0 2.053-5.418 2.985-11.496 3.089" transform="matrix(1.1310535 0 0 1.1310535 468.26549 336.71278)"/></g><g fill="#ddd" transform="matrix(1.25 0 0 -1.25 -392.9327 897.49284)"><path d="m0 0c-.624-1.28-1.771-2.454-3.449-3.516-1.676-1.069-3.805-1.6-6.391-1.6-3.412 0-6.156 1.075-8.24 3.249-2.076 2.157-3.116 5.266-3.116 9.323v10.116c0 3.969.98 7.013 2.946 9.138 1.962 2.108 4.59 3.177 7.872 3.177 3.208 0 5.695-.844 7.455-2.513 1.755-1.675 2.677-4.015 2.757-7.003l-.044-.133h-2.619c-.094 2.29-.759 4.057-2.01 5.305-1.244 1.238-3.095 1.864-5.539 1.864-2.473 0-4.432-.837-5.866-2.516-1.43-1.675-2.143-4.103-2.143-7.293v-10.174c0-3.308.771-5.83 2.311-7.567 1.54-1.724 3.616-2.588 6.236-2.588 1.913 0 3.451.339 4.602 1.033 1.155.684 1.956 1.519 2.409 2.51v8.861h-7.06v2.463h9.889z" transform="matrix(1.1310535 0 0 1.1310535 441.34721 235.75121)"/><path d="m0 0c1.553 0 2.936.44 4.144 1.336 1.21.9 2.058 2.037 2.561 3.422v5.468h-4.492c-1.91 0-3.44-.541-4.585-1.623-1.148-1.075-1.716-2.418-1.716-4.015 0-1.349.355-2.457 1.074-3.311.718-.857 1.722-1.277 3.014-1.277m7.124-2.04c-.14.876-.249 1.587-.318 2.144-.067.567-.101 1.131-.101 1.704-.767-1.254-1.757-2.294-2.98-3.109-1.221-.821-2.579-1.228-4.075-1.228-2.092 0-3.701.648-4.84 1.946-1.132 1.303-1.704 3.059-1.704 5.276 0 2.343.823 4.223 2.473 5.618 1.649 1.395 3.89 2.092 6.709 2.092h4.417v3.106c0 1.786-.456 3.193-1.351 4.21-.914 1.004-2.17 1.512-3.791 1.512-1.508 0-2.752-.479-3.728-1.45-.973-.965-1.456-2.144-1.456-3.549l-2.623.023-.046.137c-.074 1.906.647 3.591 2.168 5.084 1.515 1.489 3.459 2.229 5.825 2.229 2.338 0 4.22-.711 5.657-2.128 1.429-1.431 2.146-3.471 2.146-6.124v-12.396c0-.903.042-1.78.121-2.617.081-.848.212-1.665.417-2.48z" transform="matrix(1.1310535 0 0 1.1310535 456.01527 232.82495)"/><path d="m0 0 .24-3.923c.664 1.404 1.554 2.486 2.657 3.255 1.107.759 2.41 1.138 3.906 1.138 1.527 0 2.814-.444 3.852-1.343 1.039-.896 1.805-2.252 2.292-4.074.623 1.682 1.505 3.011 2.65 3.973 1.145.964 2.534 1.444 4.143 1.444 2.217 0 3.937-.897 5.156-2.692 1.224-1.799 1.834-4.559 1.834-8.288v-14.765h-2.823v14.814c0 3.1-.429 5.283-1.263 6.538-.839 1.257-2.042 1.89-3.598 1.89-1.637 0-2.915-.691-3.834-2.096-.914-1.405-1.478-3.161-1.683-5.282v-.655-15.209h-2.809v14.798c0 3.027-.424 5.194-1.292 6.488-.864 1.294-2.066 1.936-3.609 1.936-1.475 0-2.668-.45-3.562-1.342-.9-.897-1.54-2.125-1.928-3.683v-18.197h-2.806v25.275z" transform="matrix(1.1310535 0 0 1.1310535 476.7303 259.10521)"/><path d="m0 0c-1.758 0-3.202-.802-4.334-2.402-1.133-1.606-1.718-3.585-1.765-5.944h11.66v1.082c0 2.086-.489 3.823-1.469 5.201-.986 1.379-2.347 2.063-4.092 2.063m.397-23.76c-2.725 0-4.954 1.026-6.685 3.073-1.726 2.043-2.591 4.657-2.591 7.841v4.197c0 3.19.867 5.85 2.602 7.965 1.739 2.105 3.828 3.158 6.277 3.158 2.648 0 4.699-.939 6.164-2.823 1.468-1.887 2.201-4.422 2.201-7.603v-2.773h-14.464v-2.102c0-2.447.586-4.484 1.752-6.11 1.168-1.63 2.755-2.438 4.744-2.438 1.382 0 2.585.244 3.588.724 1.003.491 1.863 1.179 2.578 2.082l1.149-1.988c-.763-.968-1.752-1.75-2.959-2.33-1.204-.577-2.659-.873-4.356-.873" transform="matrix(1.1310535 0 0 1.1310535 522.82277 256.83868)"/><path d="m0 0c-1.763 0-3.21-.802-4.341-2.402-1.126-1.606-1.712-3.585-1.763-5.944h11.663v1.082c0 2.086-.488 3.823-1.474 5.201-.981 1.379-2.341 2.063-4.085 2.063m.394-23.76c-2.726 0-4.951 1.026-6.679 3.073-1.733 2.043-2.6 4.657-2.6 7.841v4.197c0 3.19.871 5.85 2.602 7.965 1.744 2.105 3.834 3.158 6.283 3.158 2.643 0 4.703-.939 6.164-2.823 1.463-1.887 2.197-4.422 2.197-7.603v-2.773h-14.465v-2.102c0-2.447.587-4.484 1.76-6.11 1.162-1.63 2.742-2.438 4.738-2.438 1.387 0 2.585.244 3.585.724 1.007.491 1.866 1.179 2.589 2.082l1.141-1.988c-.764-.968-1.75-1.75-2.959-2.33-1.204-.577-2.658-.873-4.356-.873" transform="matrix(1.1310535 0 0 1.1310535 558.0805 256.83868)"/><path d="m0 0 .23-4.178c.674 1.483 1.564 2.634 2.682 3.435 1.108.805 2.413 1.213 3.914 1.213 2.258 0 3.988-.835 5.189-2.513 1.214-1.675 1.815-4.279 1.815-7.812v-15.42h-2.825v15.394c0 2.888-.423 4.905-1.264 6.075-.836 1.17-2.065 1.753-3.665 1.753-1.435 0-2.638-.466-3.603-1.414-.969-.939-1.691-2.19-2.172-3.767v-18.041h-2.805v25.275z" transform="matrix(1.1310535 0 0 1.1310535 575.91679 259.10521)"/><path d="m0 0c0-2.565.486-4.605 1.472-6.123.974-1.532 2.457-2.288 4.436-2.288 1.356 0 2.498.361 3.435 1.101.934.74 1.672 1.77 2.218 3.077v12.52c-.525 1.346-1.246 2.434-2.157 3.272-.91.824-2.062 1.238-3.448 1.238-1.975 0-3.468-.86-4.46-2.587-.999-1.73-1.496-3.986-1.496-6.756zm-2.833 3.454c0 3.582.723 6.459 2.177 8.627 1.442 2.157 3.448 3.239 6.004 3.239 1.419 0 2.664-.346 3.728-1.04 1.066-.681 1.947-1.678 2.654-2.946l.274 3.516h2.381v-25.298c0-3.239-.751-5.749-2.26-7.525-1.511-1.769-3.657-2.665-6.428-2.665-.996 0-2.067.156-3.212.459-1.147.303-2.162.701-3.052 1.2l.776 2.463c.759-.492 1.608-.873 2.548-1.141.932-.277 1.895-.41 2.894-.41 2.009 0 3.498.645 4.46 1.932.966 1.304 1.45 3.19 1.45 5.687v3.057c-.717-1.138-1.597-2.011-2.64-2.614-1.039-.606-2.253-.909-3.622-.909-2.539 0-4.53.994-5.968 2.982-1.441 1.984-2.164 4.631-2.164 7.932z" transform="matrix(1.1310535 0 0 1.1310535 600.8685 242.30884)"/><path d="m627.82321 230.5176h-3.20089v28.58738h3.20089zm0 36.72644h-3.20089v4.50385h3.20089z"/><path d="m0 0 .23-4.178c.676 1.483 1.562 2.634 2.678 3.435 1.115.805 2.422 1.213 3.916 1.213 2.258 0 3.995-.835 5.199-2.513 1.211-1.675 1.807-4.279 1.807-7.812v-15.42h-2.825v15.394c0 2.888-.422 4.905-1.261 6.075-.843 1.17-2.063 1.753-3.668 1.753-1.434 0-2.635-.466-3.599-1.414-.967-.939-1.692-2.19-2.171-3.767v-18.041h-2.809v25.275z" transform="matrix(1.1310535 0 0 1.1310535 638.15379 259.10521)"/><path d="m0 0c-1.763 0-3.208-.802-4.334-2.402-1.129-1.606-1.718-3.585-1.768-5.944h11.662v1.082c0 2.086-.486 3.823-1.47 5.201-.981 1.379-2.343 2.063-4.09 2.063m.401-23.76c-2.733 0-4.958 1.026-6.681 3.073-1.73 2.043-2.595 4.657-2.595 7.841v4.197c0 3.19.865 5.85 2.6 7.965 1.739 2.105 3.831 3.158 6.275 3.158 2.646 0 4.706-.939 6.172-2.823 1.462-1.887 2.195-4.422 2.195-7.603v-2.773h-14.469v-2.102c0-2.447.59-4.484 1.757-6.11 1.166-1.63 2.748-2.438 4.746-2.438 1.382 0 2.579.244 3.578.724 1.012.491 1.869 1.179 2.591 2.082l1.147-1.988c-.769-.968-1.755-1.75-2.962-2.33-1.203-.577-2.658-.873-4.354-.873" transform="matrix(1.1310535 0 0 1.1310535 669.70883 256.83868)"/></g><g stroke-width="1.41382" transform="translate(89.812354 -.891698)"><path d="m340.91387 248.41524s-.45949-2.81915-.72812-2.7937l-51.15472 4.93563c-4.07038.39304-7.23167 3.63917-7.51726 7.71803l-1.40534 20.14265-39.57556 2.82339-2.69191-18.2552c-.59946-4.06049-4.14531-7.1214-8.24962-7.1214h-53.99084c-4.1029 0-7.64875 3.06091-8.24821 7.1214l-2.69332 18.2552-39.57556-2.82339-1.40533-20.14265c-.2856-4.08028-3.44689-7.3264-7.51727-7.71944l-51.180171-4.93422c-.264383-.0255-.458076 2.79653-.72246 2.79653l-.06928 11.07018 43.344801 6.98991 1.41947 20.32221c.28701 4.11421 3.60665 7.44092 7.72368 7.7364l54.50406 3.888c.20642.0141.41001.0226.6136.0226 4.09582 0 7.63602-3.06232 8.23548-7.12281l2.76967-18.78397h39.59394l2.76967 18.78397c.59804 4.05907 4.14248 7.1214 8.24396 7.1214.20076 0 .40153-.007.59805-.0212l54.51112-3.888c4.11562-.29548 7.43668-3.62219 7.72368-7.7364l1.41806-20.32221 43.32642-7.02101z" fill="#fff"/><path d="m64.257603 164.94208v67.1761 8.53238 7.76468c.152692.001.305384.007.456663.0212l51.174514 4.93422c2.6806.25873 4.78153 2.41621 4.96815 5.10247l1.57782 22.58996 44.63986 3.18533 3.07505-20.84955c.3987-2.70322 2.71736-4.7066 5.45168-4.7066h53.99084c2.73291 0 5.05157 2.00338 5.45026 4.7066l3.07505 20.84955 44.64127-3.18533 1.57641-22.58996c.18804-2.68626 2.28756-4.84233 4.96815-5.10247l51.15472-4.93422c.15128-.0141.30256-.0198.45525-.0212v-6.66049l.0212-.007v-76.8056c7.20611-9.07172 14.02963-19.07834 19.2576-27.49732-7.98948-13.60092-17.77875-25.75551-28.24241-37.01656-9.70443 4.88474-19.13035 10.41842-28.03316 16.30697-4.45493-4.42808-9.47257-8.05028-14.40114-11.83648-4.84232-3.88941-10.29965-6.741079-15.47564-10.063549 1.54107-11.475951 2.30311-22.773762 2.60991-34.564995-13.35491-6.721286-27.59629-11.177637-42.00167-14.378518-5.75141 9.666266-11.01081 20.134166-15.59157 30.367373-5.43189-.90767-10.88922-1.244159-16.35362-1.309194v-.0085c-.0382 0-.0735.0085-.10604.0085-.0339 0-.0693-.0085-.10321-.0085v.0085c-5.4743.06503-10.92739.401524-16.36069 1.309194-4.57794-10.233207-9.83451-20.701107-15.5944-30.367373-14.39831 3.200881-28.6411 7.657232-41.9946 14.378518.30538 11.791233 1.06743 23.089044 2.61273 34.564995-5.18588 3.32247-10.63614 6.174139-15.47988 10.063549-4.9215 3.7862-9.94762 7.4084-14.40397 11.83648-8.902802-5.88855-18.325891-11.42223-28.033158-16.30697-10.463659 11.26105-20.247272 23.41564-28.239579 37.01656 6.281105 9.85952 13.018384 19.76924 19.2576 27.49732z" fill="#478cbf"/><path d="m295.00412 263.89328-1.58489 22.71014c-.19086 2.73715-2.36814 4.91584-5.10529 5.11236l-54.50971 3.88941c-.1329.01-.2658.0141-.39728.0141-2.70888 0-5.04592-1.98783-5.44603-4.70801l-3.12595-21.19877h-44.47726l-3.12595 21.19877c-.41991 2.85308-2.97043 4.90453-5.84331 4.69387l-54.50971-3.88941c-2.73715-.19652-4.91442-2.37521-5.10529-5.11236l-1.58489-22.71014-46.015498-4.43656c.02121 4.94553.08483 10.36328.08483 11.44202 0 48.59854 61.649488 71.95763 138.244428 72.22625h.0933.0947c76.59494-.26862 138.22322-23.62771 138.22322-72.22625 0-1.09853.0664-6.49366.0891-11.44202z" fill="#478cbf"/><path d="m160.89242 198.8266c0 17.03932-13.80592 30.84242-30.83959 30.84242-17.02518 0-30.835345-13.8031-30.835345-30.84242 0-17.02801 13.810165-30.82404 30.835345-30.82404 17.03367 0 30.83959 13.79603 30.83959 30.82404" fill="#fff"/><path d="m153.47185 200.6558c0 11.30205-9.16012 20.46217-20.47065 20.46217-11.30488 0-20.47066-9.16012-20.47066-20.46217s9.16578-20.47065 20.47066-20.47065c11.31053 0 20.47065 9.1686 20.47065 20.47065" fill="#414042"/><path d="m202.59379 232.47488c-5.48278 0-9.92641-4.04069-9.92641-9.02157v-28.39085c0-4.97664 4.44363-9.02157 9.92641-9.02157s9.93631 4.04493 9.93631 9.02157v28.39085c0 4.98088-4.45353 9.02157-9.93631 9.02157" fill="#fff"/><path d="m244.30027 198.8266c0 17.03932 13.80592 30.84242 30.84242 30.84242 17.02376 0 30.83251-13.8031 30.83251-30.84242 0-17.02801-13.80875-30.82404-30.83251-30.82404-17.0365 0-30.84242 13.79603-30.84242 30.82404" fill="#fff"/><path d="m251.72267 200.6558c0 11.30205 9.15729 20.46217 20.45934 20.46217 11.31337 0 20.47066-9.16012 20.47066-20.46217s-9.15729-20.47065-20.47066-20.47065c-11.30205 0-20.45934 9.1686-20.45934 20.47065" fill="#414042"/></g></svg> diff --git a/game/src/CreditsMenu/logo_vertical_color_dark.svg.import b/game/src/CreditsMenu/logo_vertical_color_dark.svg.import new file mode 100644 index 0000000..a4fb09a --- /dev/null +++ b/game/src/CreditsMenu/logo_vertical_color_dark.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://rh7l4xuh4ali" +path="res://.godot/imported/logo_vertical_color_dark.svg-1167b3ce62f0747c0e76b17bdbb9f218.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/CreditsMenu/logo_vertical_color_dark.svg" +dest_files=["res://.godot/imported/logo_vertical_color_dark.svg-1167b3ce62f0747c0e76b17bdbb9f218.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn index b993acf..70f0583 100644 --- a/game/src/GameSession/GameSession.tscn +++ b/game/src/GameSession/GameSession.tscn @@ -66,14 +66,15 @@ offset_right = 0.0 grow_horizontal = 0 [connection signal="map_view_camera_changed" from="MapView" to="MapControlPanel" method="_on_map_view_camera_changed"] +[connection signal="province_selected" from="MapView" to="MapControlPanel" method="_on_province_selected"] [connection signal="province_selected" from="MapView" to="ProvinceOverviewPanel" method="_on_province_selected"] [connection signal="options_button_pressed" from="GameSessionMenu" to="OptionsMenu" method="show"] [connection signal="game_session_menu_button_pressed" from="MapControlPanel" to="." method="_on_game_session_menu_button_pressed"] -[connection signal="mapmode_changed" from="MapControlPanel" to="MapView" method="_update_colour_texture"] [connection signal="minimap_clicked" from="MapControlPanel" to="MapView" method="_on_minimap_clicked"] [connection signal="mouse_entered" from="MapControlPanel" to="MapView" method="_on_mouse_exited_viewport"] [connection signal="mouse_exited" from="MapControlPanel" to="MapView" method="_on_mouse_entered_viewport"] [connection signal="zoom_in_button_pressed" from="MapControlPanel" to="MapView" method="zoom_in"] [connection signal="zoom_out_button_pressed" from="MapControlPanel" to="MapView" method="zoom_out"] +[connection signal="province_deselected" from="ProvinceOverviewPanel" to="MapView" method="_deselect_province"] [connection signal="back_button_pressed" from="OptionsMenu" to="MapView" method="enable_processing"] [connection signal="back_button_pressed" from="OptionsMenu" to="OptionsMenu" method="hide"] diff --git a/game/src/GameSession/MapControlPanel.gd b/game/src/GameSession/MapControlPanel.gd index 73d7e06..e9249b3 100644 --- a/game/src/GameSession/MapControlPanel.gd +++ b/game/src/GameSession/MapControlPanel.gd @@ -1,9 +1,9 @@ extends PanelContainer signal game_session_menu_button_pressed -signal mapmode_changed signal map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) signal minimap_clicked(pos_clicked : Vector2) +signal province_selcted(index : int) signal zoom_in_button_pressed signal zoom_out_button_pressed @@ -40,7 +40,7 @@ func _on_game_session_menu_button_pressed() -> void: # * UIFUN-129, UIFUN-133 func _mapmode_pressed(button : BaseButton) -> void: GameSingleton.set_mapmode(button.tooltip_text) - mapmode_changed.emit() + GameSingleton.update_colour_image() func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_right : Vector2, near_right : Vector2) -> void: map_view_camera_changed.emit(near_left, far_left, far_right, near_right) @@ -48,6 +48,9 @@ func _on_map_view_camera_changed(near_left : Vector2, far_left : Vector2, far_ri func _on_minimap_clicked(pos_clicked : Vector2) -> void: minimap_clicked.emit(pos_clicked) +func _on_province_selected(index : int) -> void: + province_selcted.emit(index) + # REQUIREMENTS: # * UIFUN-269 func _on_zoom_in_button_pressed() -> void: diff --git a/game/src/GameSession/MapControlPanel.tscn b/game/src/GameSession/MapControlPanel.tscn index 18b1c3f..82b9c86 100644 --- a/game/src/GameSession/MapControlPanel.tscn +++ b/game/src/GameSession/MapControlPanel.tscn @@ -1,9 +1,13 @@ [gd_scene load_steps=7 format=3 uid="uid://g524p8lr574w"] [ext_resource type="Script" path="res://src/GameSession/MapControlPanel.gd" id="1_ign64"] -[ext_resource type="Texture2D" uid="uid://c0sm1jfu4kyv3" path="res://art/ui/minimap.png" id="2_r613r"] +[ext_resource type="Shader" path="res://src/GameSession/Minimap.gdshader" id="2_rinsg"] [ext_resource type="Script" path="res://src/GameSession/Minimap.gd" id="3_s4dml"] -[ext_resource type="Texture2D" uid="uid://vr1hq2stk8ny" path="res://art/ui/minimap_frame.png" id="4_f1exl"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_bhuqb"] +shader = ExtResource("2_rinsg") +shader_parameter/province_shape_subdivisions = null +shader_parameter/selected_index = null [sub_resource type="InputEventAction" id="InputEventAction_5nck3"] action = &"ui_cancel" @@ -41,28 +45,21 @@ columns = 11 [node name="Minimap" type="PanelContainer" parent="MapPanelMargin/MapPanelList/MapDisplayList"] editor_description = "UI-549" layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 mouse_filter = 1 -[node name="MinimapTexture" type="TextureRect" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap"] +[node name="MinimapTexture" type="ColorRect" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap"] editor_description = "UI-751, FS-338" +material = SubResource("ShaderMaterial_bhuqb") layout_mode = 2 -texture = ExtResource("2_r613r") +color = Color(0.921569, 0.835294, 0.701961, 1) -[node name="ViewportQuad" type="Control" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap"] +[node name="ViewportQuad" type="Control" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap" node_paths=PackedStringArray("_minimap_texture")] layout_mode = 2 -mouse_filter = 2 +mouse_filter = 1 script = ExtResource("3_s4dml") - -[node name="Frame" type="NinePatchRect" parent="MapPanelMargin/MapPanelList/MapDisplayList/Minimap"] -layout_mode = 2 -texture = ExtResource("4_f1exl") -draw_center = false -patch_margin_left = 10 -patch_margin_top = 10 -patch_margin_right = 10 -patch_margin_bottom = 10 -axis_stretch_horizontal = 1 -axis_stretch_vertical = 1 +_minimap_texture = NodePath("../MinimapTexture") [node name="AuxiliaryPanel" type="VBoxContainer" parent="MapPanelMargin/MapPanelList"] editor_description = "UI-761" @@ -104,6 +101,7 @@ mouse_filter = 1 text = "-" [connection signal="map_view_camera_changed" from="." to="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" method="_on_map_view_camera_changed"] +[connection signal="province_selcted" from="." to="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" method="_on_province_selected"] [connection signal="minimap_clicked" from="MapPanelMargin/MapPanelList/MapDisplayList/Minimap/ViewportQuad" to="." method="_on_minimap_clicked"] [connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/GameSessionMenuButton" to="." method="_on_game_session_menu_button_pressed"] [connection signal="pressed" from="MapPanelMargin/MapPanelList/AuxiliaryPanel/ZoomButtonsContainer/ZoomInButton" to="." method="_on_zoom_in_button_pressed"] diff --git a/game/src/GameSession/MapView.gd b/game/src/GameSession/MapView.gd index e74ea59..e2c8519 100644 --- a/game/src/GameSession/MapView.gd +++ b/game/src/GameSession/MapView.gd @@ -12,12 +12,6 @@ const _action_zoom_out : StringName = &"map_zoom_out" const _action_drag : StringName = &"map_drag" const _action_click : StringName = &"map_click" -const _shader_param_province_index : StringName = &"province_index_tex" -const _shader_param_province_colour : StringName = &"province_colour_tex" -const _shader_param_hover_index : StringName = &"hover_index" -const _shader_param_selected_index : StringName = &"selected_index" -const _shader_param_terrain_tile_factor : StringName = &"terrain_tile_factor" - @export var _camera : Camera3D @export var _cardinal_move_speed : float = 1.0 @@ -40,9 +34,6 @@ var _mouse_over_viewport : bool = true @export var _map_mesh_instance : MeshInstance3D var _map_mesh : MapMesh var _map_shader_material : ShaderMaterial -var _map_image_size : Vector2 -var _map_province_colour_image : Image -var _map_province_colour_texture : ImageTexture var _map_mesh_corner : Vector2 var _map_mesh_dims : Vector2 @@ -68,42 +59,20 @@ func _ready(): # Shader Material var map_material := _map_mesh_instance.get_active_material(0) - if map_material == null: - push_error("Map mesh is missing material!") - return - if not map_material is ShaderMaterial: - push_error("Invalid map mesh material class: ", map_material.get_class()) + if Events.ShaderManager.set_up_shader(map_material, true) != OK: + push_error("Failed to set up map shader") return _map_shader_material = map_material - # Province index textures - var map_province_index_images := GameSingleton.get_province_index_images() - if map_province_index_images == null or map_province_index_images.is_empty(): - push_error("Failed to get province index image!") - return - var province_index_texture := Texture2DArray.new() - if province_index_texture.create_from_images(map_province_index_images) != OK: - push_error("Failed to generate province index texture array!") - return - _map_shader_material.set_shader_parameter(_shader_param_province_index, province_index_texture) - - # Province colour texture - _map_province_colour_image = GameSingleton.get_province_colour_image() - if _map_province_colour_image == null: - push_error("Failed to get province colour image!") - return - _map_province_colour_texture = ImageTexture.create_from_image(_map_province_colour_image) - _map_shader_material.set_shader_parameter(_shader_param_province_colour, _map_province_colour_texture) - if not _map_mesh_instance.mesh is MapMesh: push_error("Invalid map mesh class: ", _map_mesh_instance.mesh.get_class(), "(expected MapMesh)") return _map_mesh = _map_mesh_instance.mesh # Set map mesh size and get bounds - _map_image_size = Vector2(Vector2i(GameSingleton.get_width(), GameSingleton.get_height())) - _map_mesh.aspect_ratio = _map_image_size.x / _map_image_size.y - _map_shader_material.set_shader_parameter(_shader_param_terrain_tile_factor, _map_image_size.y / 64.0) + _map_mesh.aspect_ratio = GameSingleton.get_aspect_ratio() + _map_shader_material.set_shader_parameter(Events.ShaderManager.param_terrain_tile_factor, + float(GameSingleton.get_height()) / 128.0) var map_mesh_aabb := _map_mesh.get_core_aabb() * _map_mesh_instance.transform _map_mesh_corner = Vector2( min(map_mesh_aabb.position.x, map_mesh_aabb.end.x), @@ -121,10 +90,6 @@ func _notification(what : int): NOTIFICATION_WM_MOUSE_EXIT: # Mouse out of window _on_mouse_exited_viewport() -func _update_colour_texture() -> void: - GameSingleton.update_colour_image() - _map_province_colour_texture.update(_map_province_colour_image) - func _world_to_map_coords(pos : Vector3) -> Vector2: return (Vector2(pos.x, pos.z) - _map_mesh_corner) / _map_mesh_dims @@ -147,15 +112,20 @@ func zoom_in() -> void: func zoom_out() -> void: _zoom_target += _zoom_target_step +func _select_province(index : int) -> void: + _map_shader_material.set_shader_parameter(Events.ShaderManager.param_selected_index, index) + province_selected.emit(index) + +func _deselect_province() -> void: + _select_province(0) + # REQUIREMENTS # * SS-31 func _unhandled_input(event : InputEvent): if _mouse_over_viewport and event.is_action_pressed(_action_click): # Check if the mouse is outside of bounds if _map_mesh.is_valid_uv_coord(_mouse_pos_map): - var selected_index := GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map) - _map_shader_material.set_shader_parameter(_shader_param_selected_index, selected_index) - province_selected.emit(selected_index) + _select_province(GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map)) else: print("Clicked outside the map!") elif event.is_action_pressed(_action_drag): @@ -251,13 +221,14 @@ func _update_mouse_map_position() -> void: _mouse_pos_map = _viewport_to_map_coords(_mouse_pos_viewport) var hover_index := GameSingleton.get_province_index_from_uv_coords(_mouse_pos_map) if _mouse_over_viewport: - _map_shader_material.set_shader_parameter(_shader_param_hover_index, hover_index) + _map_shader_material.set_shader_parameter(Events.ShaderManager.param_hover_index, hover_index) func _on_mouse_entered_viewport(): _mouse_over_viewport = true func _on_mouse_exited_viewport(): _mouse_over_viewport = false + _map_shader_material.set_shader_parameter(Events.ShaderManager.param_hover_index, 0) func _on_minimap_clicked(pos_clicked : Vector2): pos_clicked *= _map_mesh_dims diff --git a/game/src/GameSession/MapView.tscn b/game/src/GameSession/MapView.tscn index c8934c5..fa6ffcd 100644 --- a/game/src/GameSession/MapView.tscn +++ b/game/src/GameSession/MapView.tscn @@ -1,16 +1,15 @@ -[gd_scene load_steps=6 format=3 uid="uid://dkehmdnuxih2r"] +[gd_scene load_steps=5 format=3 uid="uid://dkehmdnuxih2r"] [ext_resource type="Script" path="res://src/GameSession/MapView.gd" id="1_exccw"] [ext_resource type="Shader" path="res://src/GameSession/TerrainMap.gdshader" id="1_upocn"] -[ext_resource type="Texture2D" uid="uid://ckf222w5usrsu" path="res://art/terrain/farmlands.png" id="3_47mq1"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"] render_priority = 0 shader = ExtResource("1_upocn") +shader_parameter/province_shape_subdivisions = null shader_parameter/hover_index = null shader_parameter/selected_index = null shader_parameter/terrain_tile_factor = null -shader_parameter/farmlands_tex = ExtResource("3_47mq1") [sub_resource type="MapMesh" id="MapMesh_3gtsd"] diff --git a/game/src/GameSession/Minimap.gd b/game/src/GameSession/Minimap.gd index 25c7cac..f5d972a 100644 --- a/game/src/GameSession/Minimap.gd +++ b/game/src/GameSession/Minimap.gd @@ -4,8 +4,23 @@ signal minimap_clicked(pos_clicked : Vector2) const _action_click : StringName = &"map_click" +@export var _minimap_texture : Control +var _minimap_shader : ShaderMaterial + var _viewport_points : PackedVector2Array +func _ready(): + _minimap_texture.custom_minimum_size = Vector2(GameSingleton.get_aspect_ratio(), 1.0) * 150 + var minimap_material := _minimap_texture.get_material() + if Events.ShaderManager.set_up_shader(minimap_material, false) != OK: + push_error("Failed to set up minimap shader") + else: + _minimap_shader = minimap_material + +func _on_province_selected(index : int) -> void: + if _minimap_shader != null: + _minimap_shader.set_shader_parameter(Events.ShaderManager.param_selected_index, index) + # REQUIREMENTS # * SS-80 # * UI-752 diff --git a/game/src/GameSession/Minimap.gdshader b/game/src/GameSession/Minimap.gdshader new file mode 100644 index 0000000..8b68108 --- /dev/null +++ b/game/src/GameSession/Minimap.gdshader @@ -0,0 +1,18 @@ +shader_type canvas_item; + +#include "ProvinceIndexSampler.gdshaderinc" + +// Index of the currently selected province +uniform uint selected_index; + +const vec3 land_colour = vec3(0.5); +const vec3 selected_colour = vec3(1.0, 1.0, 0.0); + +void fragment() { + uvec3 data = read_uvec3(UV); + uint index = uvec2_to_uint(data.rg); + float is_land = float(data.b != 0u); + float is_selected = float(index == selected_index); + COLOR.rgb = mix(COLOR.rgb, land_colour, is_land); + COLOR.rgb = mix(COLOR.rgb, selected_colour, is_selected); +} diff --git a/game/src/GameSession/ProvinceIndexSampler.gdshaderinc b/game/src/GameSession/ProvinceIndexSampler.gdshaderinc new file mode 100644 index 0000000..65f73d8 --- /dev/null +++ b/game/src/GameSession/ProvinceIndexSampler.gdshaderinc @@ -0,0 +1,18 @@ + +// Province shape texture +uniform sampler2DArray province_shape_tex : repeat_enable, filter_nearest; +// Province shape subdivisions +uniform vec2 province_shape_subdivisions; + +uvec3 vec3_to_uvec3(vec3 v) { + return uvec3(v * 255.0); +} +uvec3 read_uvec3(vec2 uv) { + uv *= province_shape_subdivisions; + vec2 subdivision_coords = mod(floor(uv), province_shape_subdivisions); + float idx = subdivision_coords.x + subdivision_coords.y * province_shape_subdivisions.x; + return vec3_to_uvec3(texture(province_shape_tex, vec3(uv, idx)).rgb); +} +uint uvec2_to_uint(uvec2 v) { + return (v.y << 8u) | v.x; +} diff --git a/game/src/GameSession/ProvinceOverviewPanel.gd b/game/src/GameSession/ProvinceOverviewPanel.gd index 17da9d0..5a914f7 100644 --- a/game/src/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/GameSession/ProvinceOverviewPanel.gd @@ -1,5 +1,7 @@ extends PanelContainer +signal province_deselected + @export var _province_name_label : Label @export var _region_name_label : Label @export var _life_rating_bar : ProgressBar @@ -92,4 +94,4 @@ func _on_province_selected(index : int) -> void: _selected_index = index func _on_close_button_pressed() -> void: - _selected_index = 0 + province_deselected.emit() diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader index 305a34b..cab757b 100644 --- a/game/src/GameSession/TerrainMap.gdshader +++ b/game/src/GameSession/TerrainMap.gdshader @@ -2,49 +2,30 @@ shader_type spatial; render_mode unshaded; -// Cosmetic farmlands terrain texture -uniform sampler2D farmlands_tex: source_color, repeat_enable, filter_linear; -// Province index texture -uniform sampler2DArray province_index_tex : source_color, repeat_enable, filter_nearest; +#include "ProvinceIndexSampler.gdshaderinc" + // Province colour texture uniform sampler2D province_colour_tex: source_color, repeat_enable, filter_nearest; // Index of the mouse over the map mesh uniform uint hover_index; // Index of the currently selected province uniform uint selected_index; +// Cosmetic terrain textures +uniform sampler2DArray terrain_tex: source_color, repeat_enable, filter_linear; // The number of times the terrain textures should tile vertically uniform float terrain_tile_factor; -uvec2 vec2_to_uvec2(vec2 v) { - return uvec2(v * 255.0); -} -uvec2 read_uvec2(vec2 uv) { - float width_divisions = float(textureSize(province_index_tex, 0).z); - uv.x *= width_divisions; - float idx = mod(floor(uv.x), width_divisions); - return vec2_to_uvec2(texture(province_index_tex, vec3(uv, idx)).rg); -} -uint uvec2_to_uint(uvec2 v) { - return (v.y << 8u) | v.x; -} - -const vec3 water_colour = vec3(0, 0, 1); - vec3 get_terrain_colour(vec2 uv, vec2 corner, vec2 half_pixel_size, vec2 terrain_uv) { - uvec2 index_split = read_uvec2(fma(corner, half_pixel_size, uv)); - uint index = uvec2_to_uint(index_split); - vec4 province_data = texelFetch(province_colour_tex, ivec2(index_split), 0); - vec3 province_colour = province_data.rgb; - float is_land = province_data.a; - vec3 farmlands_colour = texture(farmlands_tex, terrain_uv).rgb; - vec3 terrain_colour = mix(water_colour, farmlands_colour, is_land); - float mix_val = 0.4 + float(index == hover_index) * 0.2 + float(index == selected_index) * 0.2; - vec3 mixed_colour = mix(terrain_colour, province_colour, mix_val); - return mixed_colour; + uvec3 province_data = read_uvec3(fma(corner, half_pixel_size, uv)); + vec4 province_colour = texelFetch(province_colour_tex, ivec2(province_data.rg), 0); + vec3 terrain_colour = texture(terrain_tex, vec3(terrain_uv, float(province_data.b))).rgb; + uint index = uvec2_to_uint(province_data.rg); + float mix_val = province_colour.a + float(index == hover_index) * 0.2 + float(index == selected_index) * 0.2; + return mix(terrain_colour, province_colour.rgb, mix_val); } vec3 mix_terrain_colour(vec2 uv) { - vec2 map_size = vec2(textureSize(province_index_tex, 0).xy); + vec2 map_size = vec2(textureSize(province_shape_tex, 0).xy) * province_shape_subdivisions; vec2 pixel_offset = fract(fma(uv, map_size, vec2(0.5))); vec2 half_pixel_size = 0.49 / map_size; |