using System.Collections.Generic;
using System.Text.Json.Serialization;
using Cthangover.Core.Factories;
namespace Cthangover.Mods.Rpg
{
///
/// A square-tile atlas: one image cut into cells,
/// per row, addressed by a row-major index. Maps store
/// only these indices, so a pack can redraw its tiles without touching maps.
///
/// Files declare "Kind": "rpg_tileset" and live anywhere in a mod; the
/// image is resolved in the tilesets file group (last mod wins), so a
/// dependent mod can reskin a tileset by shipping an image of the same path.
///
[EntityKind("rpg_tileset")]
public class RpgTileset : IIdentifiable
{
private HashSet solid;
/// Tileset id that maps reference.
[JsonPropertyName("Id")]
public string ID { get; set; }
/// Image path inside the tilesets group, extension optional.
public string Image { get; set; }
/// Edge of one square tile in image pixels.
public int TileSize { get; set; } = 32;
/// Atlas cells per row.
public int Columns { get; set; } = 8;
/// Per-cell properties; cells without an entry are walkable.
public List Tiles { get; set; } = new();
/// True when the atlas cell blocks walking. Built once from .
public bool IsSolid(int index)
{
if (index < 0)
return false;
if (solid == null)
{
solid = new HashSet();
foreach (var tile in Tiles ?? new List())
{
if (tile.Solid)
solid.Add(tile.Index);
}
}
return solid.Contains(index);
}
}
}