From bc0b3c61ae0b742da304cada451fba1df72bb0ad Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 8 Nov 2023 22:24:21 +0000 Subject: GUI elements -> Godot UI nodes generator --- .../openvic-extension/singletons/AssetManager.hpp | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 extension/src/openvic-extension/singletons/AssetManager.hpp (limited to 'extension/src/openvic-extension/singletons/AssetManager.hpp') diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp new file mode 100644 index 0000000..7cfc31b --- /dev/null +++ b/extension/src/openvic-extension/singletons/AssetManager.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include +#include + +#include + +namespace OpenVic { + class AssetManager : public godot::Object { + GDCLASS(AssetManager, godot::Object) + + static inline AssetManager* _singleton = nullptr; + + struct image_asset_t { + godot::Ref image; + godot::Ref texture; + }; + using image_asset_map_t = std::map; + using font_map_t = std::map>; + + image_asset_map_t image_assets; + font_map_t fonts; + + image_asset_map_t::iterator _get_image_asset(godot::StringName path); + + protected: + static void _bind_methods(); + + public: + static AssetManager* get_singleton(); + + AssetManager(); + ~AssetManager(); + + /* Search for and load an image at the specified path relative to the game defines, first checking the AssetManager's + * image cache in case it has already been loaded, and returning nullptr if image loading fails. */ + godot::Ref get_image(godot::StringName path); + + /* 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 path); + + /* Extract the specified frame of the texture, which is treated as a single row of frame_count frames. */ + static godot::Ref make_icon( + godot::Ref texture, GFX::frame_t frame, GFX::frame_t frame_count + ); + + /* Load a texture as with get_texture, and extract the specified frame as with make_icon. */ + godot::Ref get_icon(godot::StringName path, GFX::frame_t frame, GFX::frame_t frame_count); + + /* Load a texture as with get_texture if frame_count <= 1 otherwise as with get_icon. */ + godot::Ref get_texture_or_icon(godot::StringName path, GFX::frame_t frame, GFX::frame_t frame_count); + + /* 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. */ + godot::Ref get_font(godot::StringName name); + }; +} -- cgit v1.2.3-56-ga3b1