aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons/AssetManager.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-12-04 01:12:16 +0100
committer hop311 <hop3114@gmail.com>2023-12-04 01:18:15 +0100
commit6e350a3dc0b596b1f76fab3b943b67b7713ea4fa (patch)
treeb963c671239ecd693d4162afe4b1b9d3b064554e /extension/src/openvic-extension/singletons/AssetManager.cpp
parent9165f5980c5cfe75b3bad4303a5822340f6adcfc (diff)
Sim submodule update + extension compatibility
Diffstat (limited to 'extension/src/openvic-extension/singletons/AssetManager.cpp')
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.cpp42
1 files changed, 28 insertions, 14 deletions
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<Image> 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> 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<Image> 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> 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<Image> 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);
}
}