Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::client::SpriteCustomizer Class Reference

Singleton class to manage custom sprite mappings globally. More...

#include <SpriteCustomizer.hpp>

Collaboration diagram for rtp::client::SpriteCustomizer:

Public Member Functions

bool loadMappings ()
 Load sprite mappings from config file.
 
void reloadMappings ()
 Reload sprite mappings (useful after modifications) This clears the cache and reloads from disk.
 
bool hasCustomSprite (const std::string &entityName) const
 Check if an entity has a custom sprite.
 
std::string getSpritePath (const std::string &entityName, const std::string &defaultPath) const
 Get the custom sprite path for an entity.
 
std::string getSpriteInfo (const std::string &entityName, const std::string &defaultPath, int &outLeft, int &outTop, int &outWidth, int &outHeight) const
 Get custom sprite info (path and coordinates for full sprite)
 

Static Public Member Functions

static SpriteCustomizergetInstance ()
 Get the singleton instance.
 
static void clearTextureCaches ()
 Clear all texture caches in render systems This should be called when sprites are modified to ensure that cached textures are reloaded with the new sprites.
 
static void setRenderSystems (void *worldRenderSystem, void *uiRenderSystem)
 Set render system pointers for cache clearing Called internally by Application during initialization.
 

Private Member Functions

 SpriteCustomizer ()
 
 ~SpriteCustomizer ()=default
 
 SpriteCustomizer (const SpriteCustomizer &)=delete
 
SpriteCustomizeroperator= (const SpriteCustomizer &)=delete
 
 SpriteCustomizer (SpriteCustomizer &&)=delete
 
SpriteCustomizeroperator= (SpriteCustomizer &&)=delete
 

Private Attributes

std::filesystem::path _spriteMappingPath
 
std::unordered_map< std::string, std::string > _customSpriteMappings
 

Detailed Description

Singleton class to manage custom sprite mappings globally.

This class allows the game to check if an entity has a custom sprite and provides the path to that custom sprite if it exists.

Definition at line 25 of file SpriteCustomizer.hpp.

Constructor & Destructor Documentation

◆ SpriteCustomizer() [1/3]

rtp::client::SpriteCustomizer::SpriteCustomizer ( )
private

Definition at line 21 of file SpriteCustomizer.cpp.

References loadMappings().

◆ ~SpriteCustomizer()

rtp::client::SpriteCustomizer::~SpriteCustomizer ( )
privatedefault

◆ SpriteCustomizer() [2/3]

rtp::client::SpriteCustomizer::SpriteCustomizer ( const SpriteCustomizer )
privatedelete

◆ SpriteCustomizer() [3/3]

rtp::client::SpriteCustomizer::SpriteCustomizer ( SpriteCustomizer &&  )
privatedelete

Member Function Documentation

◆ clearTextureCaches()

void rtp::client::SpriteCustomizer::clearTextureCaches ( )
static

Clear all texture caches in render systems This should be called when sprites are modified to ensure that cached textures are reloaded with the new sprites.

Definition at line 108 of file SpriteCustomizer.cpp.

References rtp::client::RenderSystem::clearTextureCache(), rtp::client::systems::UIRenderSystem::clearTextureCache(), rtp::log::error(), rtp::log::info(), rtp::client::s_uiRenderSystem, and rtp::client::s_worldRenderSystem.

Referenced by rtp::client::scenes::ModMenuScene::applyCustomSprite(), and rtp::client::scenes::ModMenuScene::showEntityCodex().

◆ getInstance()

SpriteCustomizer & rtp::client::SpriteCustomizer::getInstance ( )
static

◆ getSpriteInfo()

std::string rtp::client::SpriteCustomizer::getSpriteInfo ( const std::string &  entityName,
const std::string &  defaultPath,
int &  outLeft,
int &  outTop,
int &  outWidth,
int &  outHeight 
) const

Get custom sprite info (path and coordinates for full sprite)

Parameters
entityNameName of the entity
defaultPathDefault sprite path
outLeftOutput rect left position (set to 0 if custom sprite)
outTopOutput rect top position (set to 0 if custom sprite)
outWidthOutput width (set to texture width if custom sprite)
outHeightOutput height (set to texture height if custom sprite)
Returns
Path to use (custom or default)

Definition at line 77 of file SpriteCustomizer.cpp.

References _customSpriteMappings, and rtp::log::debug().

◆ getSpritePath()

std::string rtp::client::SpriteCustomizer::getSpritePath ( const std::string &  entityName,
const std::string &  defaultPath 
) const

Get the custom sprite path for an entity.

Parameters
entityNameName of the entity
defaultPathDefault sprite path (returned if no custom sprite exists)
Returns
Path to custom sprite, or defaultPath if no custom exists

Definition at line 68 of file SpriteCustomizer.cpp.

References _customSpriteMappings.

◆ hasCustomSprite()

bool rtp::client::SpriteCustomizer::hasCustomSprite ( const std::string &  entityName) const

Check if an entity has a custom sprite.

Parameters
entityNameName of the entity
Returns
true if custom sprite exists, false otherwise

Definition at line 57 of file SpriteCustomizer.cpp.

References _customSpriteMappings.

◆ loadMappings()

bool rtp::client::SpriteCustomizer::loadMappings ( )

Load sprite mappings from config file.

Returns
true if successful, false otherwise

Definition at line 27 of file SpriteCustomizer.cpp.

References _customSpriteMappings, _spriteMappingPath, rtp::log::error(), rtp::log::info(), rtp::config::loadSpriteMappings(), and rtp::log::warning().

Referenced by SpriteCustomizer(), and reloadMappings().

◆ operator=() [1/2]

SpriteCustomizer & rtp::client::SpriteCustomizer::operator= ( const SpriteCustomizer )
privatedelete

◆ operator=() [2/2]

SpriteCustomizer & rtp::client::SpriteCustomizer::operator= ( SpriteCustomizer &&  )
privatedelete

◆ reloadMappings()

void rtp::client::SpriteCustomizer::reloadMappings ( )

◆ setRenderSystems()

void rtp::client::SpriteCustomizer::setRenderSystems ( void *  worldRenderSystem,
void *  uiRenderSystem 
)
static

Set render system pointers for cache clearing Called internally by Application during initialization.

Parameters
worldRenderSystemPointer to world render system
uiRenderSystemPointer to UI render system

Definition at line 102 of file SpriteCustomizer.cpp.

References rtp::client::s_uiRenderSystem, and rtp::client::s_worldRenderSystem.

Referenced by rtp::client::Application::initUiSystems(), and rtp::client::Application::initWorldSystems().

Member Data Documentation

◆ _customSpriteMappings

std::unordered_map<std::string, std::string> rtp::client::SpriteCustomizer::_customSpriteMappings
private

◆ _spriteMappingPath

std::filesystem::path rtp::client::SpriteCustomizer::_spriteMappingPath
private

Definition at line 100 of file SpriteCustomizer.hpp.

Referenced by loadMappings().


The documentation for this class was generated from the following files: