Documentation of Tileset class.

This commit is contained in:
2025-05-27 19:06:33 -05:00
parent 9601c16b1e
commit a8fc5dd389
3 changed files with 75 additions and 19 deletions

View File

@@ -36,10 +36,14 @@ Our goal is to offer a flexible, efficient, and user-friendly solution for 2D ga
## Acknowledgements
This project is developed and maintained by Josh O'Leary and Redacted Software.
This project is developed and maintained by Josh O'Leary from Redacted Software.
Thanks to William Redacted for building the archiving system, much of the render code, and extensive performance optimization.
Special thanks to my wife, Ash, for requesting me to make this as a tool to allow her to design levels.
Kudos to Tiled Map Editor for being the primary design inspiration on this project.
## License
This work is expressly dedicated to the Public Domain, and is licensed under the Unlicense.

View File

@@ -229,10 +229,18 @@ public:
return JUI::MouseButton::Left;
}
void OnMouseButtonDown(const MouseButtonDownEvent &e) override {
void OnMouseButtonDown(const MouseButtonDownEvent &e) override
{
auto btn = ToJUIEnum(e.Button);
if (scene->ObserveMouseInput(btn, true)) return;
// Tile-pick - Middle Click
if (btn == JUI::MouseButton::Middle)
{
Vector2i cell = GetGridCellFromMouse();
selected_quad = grid[cell.x][cell.y];
}
}
void OnMouseButtonUp(const MouseButtonUpEvent &e) override {

View File

@@ -28,45 +28,89 @@ struct Tile
json::value metadata;
};
/// TODO: Only generate tile entry for tiles that are used in the level, or have been assigned custom metadata.
/// TODO: Large tilesets generate unwieldy file sizes and cause our rudimentary json parser to crash out.
/// @class Tileset
/// @brief Represents a collection of tiles, typically from a single texture atlas, used in a level.
///
/// The Tileset class defines the properties of a set of tiles, including their dimensions,
/// spacing, and how they are arranged within a source texture. It also provides metadata
/// about the tileset itself, such as its name and author.
class Tileset {
public:
#pragma region json fields
/// The unique name of the tileset.
std::string name;
/// The author or creator of the tileset.
std::string author;
/// The file path of this tileset.
std::string file_path;
int tile_width;
int tile_height;
int tile_spacing;
int tile_count;
int tex_width;
int tex_height;
int tiles_per_row;
int rows;
int cols;
std::vector<Quad> quads;
std::vector<json::value> tile_metadata;
std::vector<Tile> tiles;
/// The file path to the source texture atlas image for this tileset.
/// @note This path is typically relative to the lvel's JSON file.
std::string texture_path;
/// The width of a single tile in pixels within this tileset.
int tile_width;
// The height of a single tile in pixels within this tileset.
int tile_height;
/// The spacing in pixels between individual tiles within the texture atlas.
/// @note This is useful if tiles are not tightly packed.
int tile_spacing;
/// The total width of the source texture atlas image in pixels.
int tex_width;
/// The total height of the source texture atlas image in pixels.
int tex_height;
/// The number of full rows of tiles in the texture atlast.
int rows;
/// The number of full columns of tiles in the texture atlast.
/// @note This might be redundant if `tiles_per_row` and `tile_count` are used.
int cols;
///
std::vector<json::value> tile_metadata;
#pragma endregion
/// The total number of tiles defined in this tileset.
/// @note This is calculated from `rows * cols` or by iterating
int tile_count;
/// The number of tiles that fit horizontally in a single row of the texture atlast, taking into account `tile_width` and `tile_spacing`.
int tiles_per_row;
std::vector<Quad> quads;
std::vector<Tile> tiles;
public:
/// Default constructor for Tileset.
/// Initializes member variables to default or zero values.
/// @see CreateDefault().
Tileset()
{
}
/// This constructor is used for the initial definition of a Tileset. i.e. From Editor->Tileset->New
Tileset(const std::string& name, const std::filesystem::path& texture_path, int tex_width, int tex_height, int tile_width, int tile_height, int tile_spacing);
/// Constructs the Tileset from a json data structure.
/// Constructs a tileset object by deserializing data from a JSON object.
explicit Tileset(const json::value& json);
/// Loads the Tileset from a file-path containing a json-string.
explicit Tileset(const std::filesystem::path& filePath);
/// Loads the Tileset parameters from a json data structure.
/// Destructor for Tileset - cleans up any held resources.
~Tileset() = default;
/// Deserializes a JSON object into the current Tileset object's data.
void Deserialize(const json::value& json);
/// Serializes the current Tileset object's data into a JSON object.
///
json::value Serialize() const;
static Tileset CreateTemplate() {
/// Creates and returns a default Tileset object with predefined values.
/// This can be useful for initializing a new, empty tileset in the editor.
static Tileset CreateDefault() {
}