/* Copyright (c) 2022 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __Tileset_H__ #define __Tileset_H__ #ifdef __cplusplus extern "C" { #endif #include "gamemath/TextureAtlas.h" #include "gamemath/Vector2i.h" #include "gamemath/Vector2u.h" #include "tileset/TileMap.h" #define TILESET_FORMAT_VERSION 0 #define TILESET_FORMAT_TYPE "tileset" #define TILE_DIMENSION_MAX 1024 #define AutoTileRuleset_none ((AutoTileRuleset) {0, NULL}) enum TilesetAutoTileVariation { AUTO_TILE_VARIATION_SURROUNDED = 0x0, AUTO_TILE_VARIATION_WEST_EDGE = 0x1, AUTO_TILE_VARIATION_EAST_EDGE = 0x2, AUTO_TILE_VARIATION_WEST_EAST_EDGES = 0x3, AUTO_TILE_VARIATION_NORTH_EDGE = 0x4, AUTO_TILE_VARIATION_NORTHWEST_CORNER = 0x5, AUTO_TILE_VARIATION_NORTHEAST_CORNER = 0x6, AUTO_TILE_VARIATION_NORTH_DEAD_END = 0x7, AUTO_TILE_VARIATION_SOUTH_EDGE = 0x8, AUTO_TILE_VARIATION_SOUTHWEST_CORNER = 0x9, AUTO_TILE_VARIATION_SOUTHEAST_CORNER = 0xA, AUTO_TILE_VARIATION_SOUTH_DEAD_END = 0xB, AUTO_TILE_VARIATION_NORTH_SOUTH_EDGES = 0xC, AUTO_TILE_VARIATION_WEST_DEAD_END = 0xD, AUTO_TILE_VARIATION_EAST_DEAD_END = 0xE, AUTO_TILE_VARIATION_ISOLATED = 0xF #define AUTO_TILE_VARIATION_COUNT 16 }; typedef struct Tile { TileID tileID; char * name; Vector2i offset; Rect4f atlasEntry; TileID autoTileVariations[AUTO_TILE_VARIATION_COUNT]; bool autoTileAtEdge; } Tile; typedef struct Tileset { char * name; Vector2u tileSize; Vector2i origin; AutoTileRuleset autoTileAdditionalRuleset; unsigned int tileCount; Tile * tiles; } Tileset; Tileset * Tileset_create(const char * name, Vector2u tileSize, Vector2i origin, AutoTileRuleset autoTileAdditionalRuleset, unsigned int tileCount, Tile * tiles); void Tileset_dispose(Tileset * tileset); Tileset * Tileset_copy(Tileset * tileset); Tile * Tileset_lookUpTileByTileID(Tileset * tileset, TileID tileID); unsigned int Tileset_getTileIndexByTileID(Tileset * tileset, TileID tileID); unsigned int Tileset_getTileIndexByName(Tileset * tileset, const char * name); TileID Tileset_getFirstUnusedTileID(Tileset * tileset); Tileset * Tileset_deserialize(compat_type(DeserializationContext *) deserializationContext); void Tileset_serialize(Tileset * tileset, compat_type(SerializationContext *) serializationContext); void Tileset_resolveAtlasEntries(Tileset * tileset, TextureAtlas * atlas); AutoTileRuleset Tileset_createAutoTileRuleset(Tileset * tileset); void Tileset_insertTile(Tileset * tileset, unsigned int tileIndex, Tile tile, bool copyName); void Tileset_removeTile(Tileset * tileset, unsigned int tileIndex); void Tileset_reorderTile(Tileset * tileset, unsigned int fromTileIndex, unsigned int toTileIndex); #ifdef __cplusplus } #endif #endif