Peoplemon  0.1.0
Peoplemon 3 game source documentation
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
core::map::Tileset Class Reference

Stores the collection of images and animations used by Tiles in a Map. More...

#include <Tileset.hpp>

Public Types

using TileStore = std::unordered_map< Tile::IdType, bl::resource::Ref< sf::Image > >
 
using AnimStore = std::unordered_map< Tile::IdType, bl::resource::Ref< bl::gfx::a2d::AnimationData > >
 

Public Member Functions

 Tileset ()
 Creates an empty Tileset. More...
 
Tile::IdType addTexture (const std::string &uri)
 Adds a texture to the tileset and returns its id. More...
 
void removeTexture (Tile::IdType id)
 Removes the given texture from the tileset. Undefined behavior if any tiles reference it. Care must be taken to blank those tiles before the next render. More...
 
Tile::IdType addAnimation (const std::string &uri)
 Adds the given animation to the tileset and returns its id. More...
 
void removeAnimation (Tile::IdType id)
 Removes the given animation from the tileset. Undefined behavior if any tiles reference it. Care must be taken to blank those tiles before the next render. More...
 
unsigned int tileHeight (Tile::IdType id, bool isAnim) const
 Returns the height of the requested tile, in pixels. More...
 
bool loadDev (std::istream &input)
 Loads the tileset from the development format data. More...
 
bool loadProd (bl::serial::binary::InputStream &input)
 Loads the tileset from the production format data. More...
 
bool save (const std::string &file) const
 Saves the tileset to the given file. No media is saved. More...
 
bool saveBundle (bl::serial::binary::OutputStream &output, bl::resource::bundle::FileHandlerContext &ctx) const
 Saves the data from this object to the given bundle and registers dependency files. More...
 
void activate (bl::engine::Engine &engine)
 Prepares renderer resources and starts playing all shared animations. More...
 
bl::resource::Ref< sf::Image > getTile (Tile::IdType id) const
 Returns a tile from the set. Returns nullptr if not found. More...
 
std::vector< TileStore::const_iterator > getTiles () const
 Returns all contained tiles. More...
 
bl::resource::Ref< bl::gfx::a2d::AnimationData > getAnim (Tile::IdType id) const
 Returns an animation from the set. Returns nullptr if not found. More...
 
std::vector< AnimStore::const_iterator > getAnims () const
 Returns all contained animations. More...
 
sf::FloatRect getTileTextureBounds (Tile::IdType tid) const
 Returns the normalized texture coordinates for the given tile id. More...
 

Static Public Member Functions

static std::string getFullPath (const std::string &path)
 Generates the full path to the given tileset file. More...
 

Friends

class Map
 
struct bl::serial::SerializableObject< Tileset >
 

Detailed Description

Stores the collection of images and animations used by Tiles in a Map.

Definition at line 23 of file Tileset.hpp.

Member Typedef Documentation

◆ AnimStore

using core::map::Tileset::AnimStore = std::unordered_map<Tile::IdType, bl::resource::Ref<bl::gfx::a2d::AnimationData> >

Definition at line 26 of file Tileset.hpp.

◆ TileStore

using core::map::Tileset::TileStore = std::unordered_map<Tile::IdType, bl::resource::Ref<sf::Image> >

Definition at line 25 of file Tileset.hpp.

Constructor & Destructor Documentation

◆ Tileset()

core::map::Tileset::Tileset ( )

Creates an empty Tileset.

Definition at line 9 of file Tileset.cpp.

Member Function Documentation

◆ activate()

void core::map::Tileset::activate ( bl::engine::Engine &  engine)

Prepares renderer resources and starts playing all shared animations.

Parameters
engineThe game engine instance

Definition at line 56 of file Tileset.cpp.

◆ addAnimation()

Tile::IdType core::map::Tileset::addAnimation ( const std::string &  uri)

Adds the given animation to the tileset and returns its id.

Parameters
uriThe path to the animation
Returns
Tile::IdType The id of the new animation

Definition at line 35 of file Tileset.cpp.

◆ addTexture()

Tile::IdType core::map::Tileset::addTexture ( const std::string &  uri)

Adds a texture to the tileset and returns its id.

Parameters
uriThe path of the texture to add
Returns
Tile::IdType The id of the new texture

Definition at line 14 of file Tileset.cpp.

◆ getAnim()

bl::resource::Ref< bl::gfx::a2d::AnimationData > core::map::Tileset::getAnim ( Tile::IdType  id) const

Returns an animation from the set. Returns nullptr if not found.

Parameters
idThe id of the animation to get
Returns
bl::resource::Ref<sf::Texture> A reference to the animation

Definition at line 175 of file Tileset.cpp.

◆ getAnims()

std::vector< Tileset::AnimStore::const_iterator > core::map::Tileset::getAnims ( ) const

Returns all contained animations.

Definition at line 180 of file Tileset.cpp.

◆ getFullPath()

std::string core::map::Tileset::getFullPath ( const std::string &  path)
static

Generates the full path to the given tileset file.

Parameters
pathThe relative tileset path
Returns
std::string The full path to the given tileset

Definition at line 190 of file Tileset.cpp.

◆ getTile()

bl::resource::Ref< sf::Image > core::map::Tileset::getTile ( Tile::IdType  id) const

Returns a tile from the set. Returns nullptr if not found.

Parameters
idThe id of the tile to get
Returns
bl::resource::Ref<sf::Texture> A reference to the tile

Definition at line 160 of file Tileset.cpp.

◆ getTiles()

std::vector< Tileset::TileStore::const_iterator > core::map::Tileset::getTiles ( ) const

Returns all contained tiles.

Definition at line 165 of file Tileset.cpp.

◆ getTileTextureBounds()

sf::FloatRect core::map::Tileset::getTileTextureBounds ( Tile::IdType  tid) const

Returns the normalized texture coordinates for the given tile id.

Parameters
tidThe tile id to get the texture coordinates for
Returns
The normalized texture coordinates

Definition at line 194 of file Tileset.cpp.

◆ loadDev()

bool core::map::Tileset::loadDev ( std::istream &  input)

Loads the tileset from the development format data.

Parameters
inputThe input stream to load from
Returns
True if loaded successfully, false on error

Definition at line 97 of file Tileset.cpp.

◆ loadProd()

bool core::map::Tileset::loadProd ( bl::serial::binary::InputStream &  input)

Loads the tileset from the production format data.

Parameters
inputThe input stream to load from
Returns
True if loaded successfully, false on error

Definition at line 113 of file Tileset.cpp.

◆ removeAnimation()

void core::map::Tileset::removeAnimation ( Tile::IdType  id)

Removes the given animation from the tileset. Undefined behavior if any tiles reference it. Care must be taken to blank those tiles before the next render.

Parameters
idThe id of the animation to remove

Definition at line 50 of file Tileset.cpp.

◆ removeTexture()

void core::map::Tileset::removeTexture ( Tile::IdType  id)

Removes the given texture from the tileset. Undefined behavior if any tiles reference it. Care must be taken to blank those tiles before the next render.

Parameters
idThe id of the texture to remove

Definition at line 30 of file Tileset.cpp.

◆ save()

bool core::map::Tileset::save ( const std::string &  file) const

Saves the tileset to the given file. No media is saved.

Parameters
fileThe file to save to
Returns
True if successfully written, false on error

Definition at line 138 of file Tileset.cpp.

◆ saveBundle()

bool core::map::Tileset::saveBundle ( bl::serial::binary::OutputStream &  output,
bl::resource::bundle::FileHandlerContext &  ctx 
) const

Saves the data from this object to the given bundle and registers dependency files.

Parameters
outputStream to output to
ctxContext to register dependencies with
Returns
True if serialization succeeded, false otherwise

Definition at line 145 of file Tileset.cpp.

◆ tileHeight()

unsigned int core::map::Tileset::tileHeight ( Tile::IdType  id,
bool  isAnim 
) const

Returns the height of the requested tile, in pixels.

Parameters
idThe id of the tile
isAnimTrue for animation, false for sprite
Returns
unsigned int The height of the tile in pixels, or 0 if not found

Definition at line 83 of file Tileset.cpp.

Friends And Related Function Documentation

◆ bl::serial::SerializableObject< Tileset >

friend struct bl::serial::SerializableObject< Tileset >
friend

Definition at line 175 of file Tileset.hpp.

◆ Map

friend class Map
friend

Definition at line 175 of file Tileset.hpp.


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