From 6e350a3dc0b596b1f76fab3b943b67b7713ea4fa Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 4 Dec 2023 00:12:16 +0000 Subject: Sim submodule update + extension compatibility --- .../openvic-extension/singletons/AssetManager.cpp | 42 ++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'extension/src/openvic-extension/singletons/AssetManager.cpp') diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp index b50cae8..8e9eb41 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.cpp +++ b/extension/src/openvic-extension/singletons/AssetManager.cpp @@ -37,33 +37,47 @@ AssetManager::~AssetManager() { _singleton = nullptr; } -AssetManager::image_asset_map_t::iterator AssetManager::_get_image_asset(StringName path) { - const image_asset_map_t::iterator it = image_assets.find(path); - if (it != image_assets.end()) { - return it; - } +Ref AssetManager::_load_image(StringName path) { GameSingleton* game_singleton = GameSingleton::get_singleton(); - ERR_FAIL_NULL_V(game_singleton, image_assets.end()); + ERR_FAIL_NULL_V(game_singleton, nullptr); const String lookedup_path = - std_to_godot_string(game_singleton->get_dataloader().lookup_image_file_or_dds(godot_to_std_string(path)).string()); + std_to_godot_string(game_singleton->get_dataloader().lookup_image_file(godot_to_std_string(path)).string()); if (lookedup_path.is_empty()) { UtilityFunctions::push_error("Failed to look up image: ", path); - return image_assets.end(); + return nullptr; } const Ref image = Utilities::load_godot_image(lookedup_path); if (image.is_null() || image->is_empty()) { UtilityFunctions::push_error("Failed to load image: ", lookedup_path, " (looked up from ", path, ")"); - return image_assets.end(); + return nullptr; + } else { + return image; } - return image_assets.emplace(std::move(path), AssetManager::image_asset_t { image, nullptr }).first; } -Ref AssetManager::get_image(StringName path) { - const image_asset_map_t::const_iterator it = _get_image_asset(path); +AssetManager::image_asset_map_t::iterator AssetManager::_get_image_asset(StringName path) { + const image_asset_map_t::iterator it = image_assets.find(path); if (it != image_assets.end()) { - return it->second.image; + return it; + } + const Ref image = _load_image(path); + if (image.is_valid()) { + return image_assets.emplace(std::move(path), AssetManager::image_asset_t { image, nullptr }).first; } else { - return nullptr; + return image_assets.end(); + } +} + +Ref AssetManager::get_image(StringName path, bool cache) { + if (cache) { + const image_asset_map_t::const_iterator it = _get_image_asset(path); + if (it != image_assets.end()) { + return it->second.image; + } else { + return nullptr; + } + } else { + return _load_image(path); } } -- cgit v1.2.3-56-ga3b1