Dawn/src/dawn/display/Tileset.hpp

111 lines
2.9 KiB
C++

// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "display/Texture.hpp"
namespace Dawn {
struct Tile {
glm::vec2 uv0;
glm::vec2 uv1;
};
struct Tileset {
public:
std::vector<struct Tile> tiles;
/**
* Returns the tile at the given tile index.
*
* @param tile Tile index to get.
* @return Tile at that index.
*/
struct Tile getTile(int32_t tile);
/**
* Returns the width of an individual tile.
*
* @param tile The tile to get the width of.
* @return The tile width.
*/
virtual float_t getTileWidth(int32_t tile) = 0;
/**
* Returns the height of an individual tile.
*
* @param tile The tile to get the height of.
* @return The tile height.
*/
virtual float_t getTileHeight(int32_t tile) = 0;
};
struct TilesetGrid : public Tileset{
public:
int32_t rows;
int32_t columns;
int32_t divX;
int32_t divY;
/**
* Constructs a new Tileset Grid.
*/
TilesetGrid();
/**
* Constructs a new Tileset Grid from a texture.
*
* @param texture Texture to use.
* @param columns Columns in the grid.
* @param rows Rows in the grid.
*/
TilesetGrid(Texture *texture, int32_t columns, int32_t rows);
/**
* Constructs a new Tileset Grid from a texture.
*
* @param texture Texture to use.
* @param columns Columns in the grid.
* @param rows Rows in the grid.
*/
TilesetGrid(Texture &texture, int32_t columns, int32_t rows);
/**
* Constructs a new Tileset Grid.
*
* @param columns How many columns in the grid of tiles.
* @param rows How many rows in the grid of tiles.
* @param w Width of the grid.
* @param h Height of te grid.
* @param gapX Gap / Gutter between tiles.
* @param gapY Gap / Gutter between tiles.
* @param borderX Border at the edge of the grid before the first tiles.
* @param borderY Border at the edge of the grid before the first tiles.
*/
TilesetGrid(
int32_t columns,
int32_t rows,
int32_t w,
int32_t h,
int32_t gapX,
int32_t gapY,
int32_t borderX,
int32_t borderY
);
float_t getTileWidth(int32_t tile) override;
float_t getTileHeight(int32_t tile) override;
/**
* Returns the tile at a given grid position.
*
* @param column Column (0 indexed) to get the tile of.
* @param row Row (0 indexed) to get the tile of.
* @return Tile at this grid position.
*/
struct Tile getTileFromGrid(int32_t column, int32_t row);
};
}