Service responsible for managing game assets such as textures and spritesheets.
More...
#include <assetService.h>
|
| | AssetService () |
| |
| | AssetService (const AssetService &)=delete |
| |
| AssetService & | operator= (const AssetService &)=delete |
| |
| | AssetService (AssetService &&)=default |
| |
| AssetService & | operator= (AssetService &&)=default |
| |
| 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::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.
|
| |
| 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.
|
| |
| 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.
|
| |
| std::reference_wrapper< Texture > | get_default_texture () |
| | Retrieves the default white texture.
|
| |
| 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< 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.
|
| |
| virtual | ~IEngineService ()=default |
| |
Service responsible for managing game assets such as textures and spritesheets.
The AssetService provides the functionality to load sprite resources from files, and register named textures and spritesheets and spritesheets in the engine as well as retrieve them when needed.
◆ AssetService() [1/3]
| AssetService::AssetService |
( |
| ) |
|
◆ AssetService() [2/3]
◆ AssetService() [3/3]
◆ create_spritesheet_for()
| std::reference_wrapper< const std::vector< std::reference_wrapper< Texture > > > AssetService::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.
- Parameters
-
| source | The source file name containing the spritesheet. |
| name | The name to register the spritesheet under. |
| from | The starting index of the sprites in the spritesheet. |
| to | The ending index of the sprites in the spritesheet. |
- Returns
- A reference to the registered vector of textures representing the spritesheet.
- Exceptions
-
| An | exception if the resource cannot be found or indices are out of bounds. |
◆ get_default_texture()
| std::reference_wrapper< Texture > AssetService::get_default_texture |
( |
| ) |
|
Retrieves the default white texture.
- Returns
- A reference to the default white texture.
◆ load_from_resource()
| std::vector< std::reference_wrapper< Texture > > AssetService::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.
- Parameters
-
| file | The resource file name. |
| name | The base name for the loaded textures. |
| rows | The number of rows in the spritesheet. |
| cols | The number of columns in the spritesheet. |
- Returns
- A vector of references to the loaded textures.
- Exceptions
-
| An | exception if the resource cannot be found or loading fails. |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ register_font()
| std::reference_wrapper< Font > AssetService::register_font |
( |
const std::string & |
font_name, |
|
|
const std::string & |
font_path, |
|
|
int |
font_size |
|
) |
| |
Registers a font with the given name and size.
- Parameters
-
| font_name | The name of the font. |
| font_size | The size of the font. |
- Returns
- A reference to the registered font.
- Exceptions
-
| An | exception if the font cannot be loaded. |
◆ register_texture()
| std::reference_wrapper< Texture > AssetService::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.
- Parameters
-
| resource_name | The name of the resource file. |
| texture_name | The name to register the texture under. |
| index | The index of the texture in the resource file. |
- Returns
- A reference to the registered texture.
- Exceptions
-
| An | exception if the resource cannot be found or index is out of bounds. |
◆ try_get_font()
| std::optional< std::reference_wrapper< Font > > AssetService::try_get_font |
( |
const std::string & |
font_name, |
|
|
int |
font_size |
|
) |
| const |
Attempts to retrieve a font by its name and size.
- Parameters
-
| font_name | The name of the font. |
| font_size | The size of the font. |
- Returns
- An optional reference to the font if found, std::nullopt otherwise.
◆ try_get_spritesheet()
| std::optional< std::reference_wrapper< const std::vector< std::reference_wrapper< Texture > > > > AssetService::try_get_spritesheet |
( |
const std::string & |
key | ) |
const |
Attempts to retrieve a spritesheet by its key.
- Parameters
-
| key | The key of the registered spritesheet resource. |
- Returns
- An optional reference to the vector of textures if found, std::nullopt otherwise.
◆ try_get_texture()
| std::optional< std::reference_wrapper< Texture > > AssetService::try_get_texture |
( |
const std::string & |
sprite | ) |
const |
Attempts to retrieve a texture by its sprite name.
- Parameters
-
| sprite | The name of the registered texture resource. |
- Returns
- An optional reference to the texture if found, std::nullopt otherwise.
The documentation for this class was generated from the following file: