1 #ifndef CORE_MAPS_TILESET_HPP
2 #define CORE_MAPS_TILESET_HPP
4 #include <BLIB/Graphics.hpp>
5 #include <BLIB/Resources.hpp>
6 #include <BLIB/Serialization.hpp>
7 #include <BLIB/Util/ImageStitcher.hpp>
9 #include <SFML/Graphics.hpp>
12 #include <unordered_map>
25 using TileStore = std::unordered_map<Tile::IdType, bl::resource::Ref<sf::Image>>;
27 std::unordered_map<Tile::IdType, bl::resource::Ref<bl::gfx::a2d::AnimationData>>;
81 bool loadDev(std::istream& input);
89 bool loadProd(bl::serial::binary::InputStream& input);
97 bool save(
const std::string& file)
const;
106 bool saveBundle(bl::serial::binary::OutputStream& output,
107 bl::resource::bundle::FileHandlerContext& ctx)
const;
114 void activate(bl::engine::Engine& engine);
127 std::vector<TileStore::const_iterator>
getTiles()
const;
140 std::vector<AnimStore::const_iterator>
getAnims()
const;
156 static std::string
getFullPath(
const std::string& path);
159 std::unordered_map<Tile::IdType, std::string> textureFiles;
160 std::unordered_map<Tile::IdType, std::string> animFiles;
166 bl::engine::Engine* enginePtr;
167 std::optional<bl::util::ImageStitcher> textureStitcher;
168 std::unordered_map<Tile::IdType, glm::u32vec2> textureAtlas;
169 bl::rc::res::TextureRef combinedTextures;
170 std::unordered_map<Tile::IdType, bl::gfx::DiscreteAnimation2DPlayer> sharedAnimations;
176 friend struct bl::serial::SerializableObject<
Tileset>;
187 struct SerializableObject<
core::map::Tileset> :
public SerializableObjectBase {
191 SerializableField<1, TS, std::unordered_map<T::IdType, std::string>>
textureFiles;
192 SerializableField<2, TS, std::unordered_map<T::IdType, std::string>>
animFiles;
195 : SerializableObjectBase(
"Tileset")
196 , textureFiles(
"textures", *this, &
TS::textureFiles, SerializableFieldBase::Required{})
197 , animFiles(
"anims", *this, &
TS::animFiles, SerializableFieldBase::Required{}) {}
Core classes and functionality for both the editor and game.
The primary map class that represents a usable map in the game.
Data representation of a tile in a Map TileLayer.
Stores the collection of images and animations used by Tiles in a Map.
unsigned int tileHeight(Tile::IdType id, bool isAnim) const
Returns the height of the requested tile, in pixels.
Tile::IdType addAnimation(const std::string &uri)
Adds the given animation to the tileset and returns its id.
bool save(const std::string &file) const
Saves the tileset to the given file. No media is saved.
static std::string getFullPath(const std::string &path)
Generates the full path to the given tileset file.
Tile::IdType addTexture(const std::string &uri)
Adds a texture to the tileset and returns its id.
std::vector< TileStore::const_iterator > getTiles() const
Returns all contained tiles.
void activate(bl::engine::Engine &engine)
Prepares renderer resources and starts playing all shared animations.
Tileset()
Creates an empty Tileset.
bool loadDev(std::istream &input)
Loads the tileset from the development format data.
sf::FloatRect getTileTextureBounds(Tile::IdType tid) const
Returns the normalized texture coordinates for the given tile id.
bl::resource::Ref< bl::gfx::a2d::AnimationData > getAnim(Tile::IdType id) const
Returns an animation from the set. Returns nullptr if not found.
void removeTexture(Tile::IdType id)
Removes the given texture from the tileset. Undefined behavior if any tiles reference it....
bl::resource::Ref< sf::Image > getTile(Tile::IdType id) const
Returns a tile from the set. Returns nullptr if not found.
std::unordered_map< Tile::IdType, bl::resource::Ref< sf::Image > > TileStore
void removeAnimation(Tile::IdType id)
Removes the given animation from the tileset. Undefined behavior if any tiles reference it....
std::unordered_map< Tile::IdType, bl::resource::Ref< bl::gfx::a2d::AnimationData > > AnimStore
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.
std::vector< AnimStore::const_iterator > getAnims() const
Returns all contained animations.
bool loadProd(bl::serial::binary::InputStream &input)
Loads the tileset from the production format data.
SerializableField< 1, TS, std::unordered_map< T::IdType, std::string > > textureFiles
SerializableField< 2, TS, std::unordered_map< T::IdType, std::string > > animFiles