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 Class Reference

Service responsible for managing game assets such as textures and spritesheets. More...

#include <assetService.h>

Inheritance diagram for AssetService:
[legend]

Public Member Functions

 AssetService ()
 
 AssetService (const AssetService &)=delete
 
AssetServiceoperator= (const AssetService &)=delete
 
 AssetService (AssetService &&)=default
 
AssetServiceoperator= (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< Textureregister_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< Textureget_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< Fontregister_font (const std::string &font_name, const std::string &font_path, int font_size)
 Registers a font with the given name and size.
 
- Public Member Functions inherited from IEngineService
virtual ~IEngineService ()=default
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AssetService() [1/3]

AssetService::AssetService ( )

◆ AssetService() [2/3]

AssetService::AssetService ( const AssetService )
delete

◆ AssetService() [3/3]

AssetService::AssetService ( AssetService &&  )
default

Member Function Documentation

◆ 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
sourceThe source file name containing the spritesheet.
nameThe name to register the spritesheet under.
fromThe starting index of the sprites in the spritesheet.
toThe ending index of the sprites in the spritesheet.
Returns
A reference to the registered vector of textures representing the spritesheet.
Exceptions
Anexception 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
fileThe resource file name.
nameThe base name for the loaded textures.
rowsThe number of rows in the spritesheet.
colsThe number of columns in the spritesheet.
Returns
A vector of references to the loaded textures.
Exceptions
Anexception if the resource cannot be found or loading fails.

◆ operator=() [1/2]

AssetService & AssetService::operator= ( AssetService &&  )
default

◆ operator=() [2/2]

AssetService & AssetService::operator= ( const AssetService )
delete

◆ 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_nameThe name of the font.
font_sizeThe size of the font.
Returns
A reference to the registered font.
Exceptions
Anexception 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_nameThe name of the resource file.
texture_nameThe name to register the texture under.
indexThe index of the texture in the resource file.
Returns
A reference to the registered texture.
Exceptions
Anexception 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_nameThe name of the font.
font_sizeThe 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
keyThe 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
spriteThe 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: