Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
assetService.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <map>
9#include <optional>
10#include <vector>
11
21 public:
23 AssetService(const AssetService&) = delete;
25
26 AssetService(AssetService&&) = default; // allow move
28
35 [[nodiscard]] std::optional<std::reference_wrapper<
36 const std::vector<std::reference_wrapper<Texture>>>>
37 try_get_spritesheet(const std::string& key) const;
38
50 std::reference_wrapper<const std::vector<std::reference_wrapper<Texture>>>
51 create_spritesheet_for(const std::string& source, const std::string& name,
52 size_t from, size_t to);
53
60 [[nodiscard]] std::optional<std::reference_wrapper<Texture>> try_get_texture(
61 const std::string& sprite) const;
62
72 std::reference_wrapper<Texture> register_texture(
73 const std::string& resource_name, const std::string& texture_name,
74 size_t index);
75
86 std::vector<std::reference_wrapper<Texture>> load_from_resource(
87 const std::string& file, const std::string& name, int rows, int cols);
88
93 std::reference_wrapper<Texture> get_default_texture();
94
101 [[nodiscard]] std::optional<std::reference_wrapper<Font>> try_get_font(
102 const std::string& font_name, int font_size) const;
103
111 [[nodiscard]] std::reference_wrapper<Font> register_font(
112 const std::string& font_name, const std::string& font_path,
113 int font_size);
114
115 private:
116 static constexpr const char* const resource_path = "resources/sprites/";
117
118 std::vector<std::unique_ptr<Texture>> textures_;
119 std::map<std::string, std::vector<std::reference_wrapper<Texture>>>
120 named_assets_;
121 std::map<std::string, std::unique_ptr<Font>> font_cache_;
122};
Service responsible for managing game assets such as textures and spritesheets.
Definition assetService.h:20
AssetService & operator=(AssetService &&)=default
AssetService(const AssetService &)=delete
std::reference_wrapper< Texture > get_default_texture()
Retrieves the default white texture.
std::reference_wrapper< Font > register_font(const std::string &font_name, const std::string &font_path, int font_size)
Registers a font with the given name and size.
std::vector< std::reference_wrapper< Texture > > load_from_resource(const std::string &file, const std::string &name, int rows, int cols)
Loads textures from a resource file and splits them into a grid of sprites.
AssetService(AssetService &&)=default
std::optional< std::reference_wrapper< Texture > > try_get_texture(const std::string &sprite) const
Attempts to retrieve a texture by its sprite name.
std::reference_wrapper< Texture > register_texture(const std::string &resource_name, const std::string &texture_name, size_t index)
Registers a texture with a given resource name and texture name.
AssetService & operator=(const AssetService &)=delete
std::optional< std::reference_wrapper< const std::vector< std::reference_wrapper< Texture > > > > try_get_spritesheet(const std::string &key) const
Attempts to retrieve a spritesheet by its key.
std::optional< std::reference_wrapper< Font > > try_get_font(const std::string &font_name, int font_size) const
Attempts to retrieve a font by its name and size.
std::reference_wrapper< const std::vector< std::reference_wrapper< Texture > > > create_spritesheet_for(const std::string &source, const std::string &name, size_t from, size_t to)
Creates and registers a spritesheet from a stored resource.
Definition iEngineService.h:4