Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::TileMap Struct Reference

Orthogonal, finite map made in Tiled, saved as JSON. More...

#include <aegis2d/render/tile_map.hpp>

Public Member Functions

const Tileset * tileset (std::uint32_t gid) const noexcept
 Tileset of a tile.
 
const MapLayer * layer (std::string_view name) const noexcept
 First layer of a name.
 

Static Public Member Functions

static TileMap load (const std::filesystem::path &path)
 Reads a map and its external tilesets.
 

Public Attributes

int width = 0
 Width, in tiles.
 
int height = 0
 Height, in tiles.
 
TextureSize tile_size {}
 Size of one cell.
 
std::vector< Tileset > tilesets {}
 Tilesets, by increasing first_gid.
 
std::vector< MapLayer > layers {}
 Layers, from the bottom one.
 
TileProperties properties {}
 Custom properties.
 

Detailed Description

Orthogonal, finite map made in Tiled, saved as JSON.

Layers keep the order of Tiled, from the bottom one; the layers of a group come in its place, with its offset, opacity and visibility applied. Tile data is the JSON array that Tiled writes by default (Tile Layer Format: CSV); base64, compressed and infinite maps, other orientations and image layers are refused with their reason.

const auto map = render::TileMap::load(core::asset_path("maps/level.tmj"));
for (const auto& layer : map.layers) {
if (!layer.tiles.empty()) { ... draw its tiles ... }
}
std::filesystem::path asset_path(const std::filesystem::path &relative)
Path of one asset.
std::vector< std::uint32_t > tiles
For a tile layer, the global id of each cell (flip bits included), row by row from the top-left,...
Definition tile_map.hpp:107
std::vector< MapLayer > layers
Layers, from the bottom one.
Definition tile_map.hpp:141
static TileMap load(const std::filesystem::path &path)
Reads a map and its external tilesets.
const MapLayer * layer(std::string_view name) const noexcept
First layer of a name.

Member Function Documentation

◆ layer()

const MapLayer * aegis2d::render::TileMap::layer ( std::string_view  name) const
noexcept

First layer of a name.

Parameters
nameLayer name.
Returns
The layer, or nullptr if there is none.

◆ load()

static TileMap aegis2d::render::TileMap::load ( const std::filesystem::path &  path)
static

Reads a map and its external tilesets.

Parameters
path.tmj file.
Returns
The map.
Exceptions
TileMapErrorif a file cannot be read, is not valid JSON, or the map is broken (missing field, unsupported feature, tile id that no tileset has...).

◆ tileset()

const Tileset * aegis2d::render::TileMap::tileset ( std::uint32_t  gid) const
noexcept

Tileset of a tile.

Parameters
gidGlobal tile id, flip bits allowed.
Returns
The tileset that has it, or nullptr for 0 or an id that none has.

Member Data Documentation

◆ height

int aegis2d::render::TileMap::height = 0

Height, in tiles.

◆ layers

std::vector<MapLayer> aegis2d::render::TileMap::layers {}

Layers, from the bottom one.

◆ properties

TileProperties aegis2d::render::TileMap::properties {}

Custom properties.

◆ tile_size

TextureSize aegis2d::render::TileMap::tile_size {}

Size of one cell.

◆ tilesets

std::vector<Tileset> aegis2d::render::TileMap::tilesets {}

Tilesets, by increasing first_gid.

◆ width

int aegis2d::render::TileMap::width = 0

Width, in tiles.


The documentation for this struct was generated from the following file: