From d45d6270c8924f571b53d71ac8eb9ce5a7788255 Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 3 Mar 2024 13:23:21 +0000 Subject: ProgressBar, StyleBoxTexture, Icon tweaks + current dir install check fix --- .../src/openvic-extension/singletons/AssetManager.cpp | 17 ++++++++++------- .../src/openvic-extension/singletons/AssetManager.hpp | 6 +++--- .../src/openvic-extension/singletons/GameSingleton.cpp | 8 -------- .../src/openvic-extension/singletons/GameSingleton.hpp | 9 ++------- 4 files changed, 15 insertions(+), 25 deletions(-) (limited to 'extension/src/openvic-extension/singletons') diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp index 546dc9d..083d934 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.cpp +++ b/extension/src/openvic-extension/singletons/AssetManager.cpp @@ -13,8 +13,8 @@ using OpenVic::Utilities::godot_to_std_string; using OpenVic::Utilities::std_to_godot_string; void AssetManager::_bind_methods() { - OV_BIND_METHOD(AssetManager::get_image, { "path" }); - OV_BIND_METHOD(AssetManager::get_texture, { "path" }); + OV_BIND_METHOD(AssetManager::get_image, { "path", "cache", "flip_y" }, DEFVAL(true), DEFVAL(false)); + OV_BIND_METHOD(AssetManager::get_texture, { "path", "flip_y" }, DEFVAL(false)); OV_BIND_METHOD(AssetManager::get_font, { "name" }); } @@ -45,19 +45,22 @@ Ref AssetManager::_load_image(StringName const& path) { return image; } -AssetManager::image_asset_t* AssetManager::_get_image_asset(StringName const& path) { +AssetManager::image_asset_t* AssetManager::_get_image_asset(StringName const& path, bool flip_y) { image_asset_map_t::iterator it = image_assets.find(path); if (it != image_assets.end()) { return &it.value(); } const Ref image = _load_image(path); ERR_FAIL_NULL_V(image, nullptr); + if (flip_y) { + image->flip_y(); + } return &image_assets.emplace(std::move(path), AssetManager::image_asset_t { image, nullptr }).first.value(); } -Ref AssetManager::get_image(StringName const& path, bool cache) { +Ref AssetManager::get_image(StringName const& path, bool cache, bool flip_y) { if (cache) { - image_asset_t const* asset = _get_image_asset(path); + image_asset_t const* asset = _get_image_asset(path, flip_y); ERR_FAIL_NULL_V(asset, nullptr); return asset->image; } else { @@ -65,8 +68,8 @@ Ref AssetManager::get_image(StringName const& path, bool cache) { } } -Ref AssetManager::get_texture(StringName const& path) { - image_asset_t* asset = _get_image_asset(path); +Ref AssetManager::get_texture(StringName const& path, bool flip_y) { + image_asset_t* asset = _get_image_asset(path, flip_y); ERR_FAIL_NULL_V(asset, nullptr); if (asset->texture.is_null()) { asset->texture = ImageTexture::create_from_image(asset->image); diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp index 7f73e4c..0416e5b 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.hpp +++ b/extension/src/openvic-extension/singletons/AssetManager.hpp @@ -25,7 +25,7 @@ namespace OpenVic { font_map_t fonts; static godot::Ref _load_image(godot::StringName const& path); - image_asset_t* _get_image_asset(godot::StringName const& path); + image_asset_t* _get_image_asset(godot::StringName const& path, bool flip_y); protected: static void _bind_methods(); @@ -38,12 +38,12 @@ namespace OpenVic { /* Search for and load an image at the specified path relative to the game defines, first checking the AssetManager's * image cache (if cache is true) in case it has already been loaded, and returning nullptr if image loading fails. */ - godot::Ref get_image(godot::StringName const& path, bool cache = true); + godot::Ref get_image(godot::StringName const& path, bool cache = true, bool flip_y = false); /* Create a texture from an image found at the specified path relative to the game defines, fist checking * AssetManager's texture cache in case it has already been loaded, and returning nullptr if image loading * or texture creation fails. */ - godot::Ref get_texture(godot::StringName const& path); + godot::Ref get_texture(godot::StringName const& path, bool flip_y = false); /* Search for and load a font with the specified name from the game defines' font directory, first checking the * AssetManager's font cache in case it has already been loaded, and returning nullptr if font loading fails. */ diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 9b8abce..8893f75 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -129,14 +129,6 @@ void GameSingleton::setup_logger() { }); } -GameManager const& GameSingleton::get_game_manager() const { - return game_manager; -} - -Dataloader const& GameSingleton::get_dataloader() const { - return dataloader; -} - Error GameSingleton::setup_game(int32_t bookmark_index) { Bookmark const* bookmark = game_manager.get_history_manager().get_bookmark_manager().get_bookmark_by_index(bookmark_index); ERR_FAIL_NULL_V_MSG(bookmark, FAILED, vformat("Failed to get bookmark with index: %d", bookmark_index)); diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index 35f7437..a2b15cd 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -14,8 +13,8 @@ namespace OpenVic { static inline GameSingleton* singleton = nullptr; - GameManager game_manager; - Dataloader dataloader; + GameManager PROPERTY(game_manager); + Dataloader PROPERTY(dataloader); godot::Vector2i image_subdivisions; godot::Ref province_shape_texture; @@ -29,7 +28,6 @@ namespace OpenVic { static godot::StringName const& _signal_province_selected(); static godot::StringName const& _signal_clock_state_changed(); - godot::Error _generate_terrain_texture_array(); godot::Error _load_map_images(); godot::Error _load_terrain_variants(); godot::Error _load_flag_images(); @@ -50,9 +48,6 @@ namespace OpenVic { static void setup_logger(); - GameManager const& get_game_manager() const; - Dataloader const& get_dataloader() const; - /* Load the game's defines in compatiblity mode from the filepath * pointing to the defines folder. */ godot::Error load_defines_compatibility_mode(godot::PackedStringArray const& file_paths); -- cgit v1.2.3-56-ga3b1