1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 01:39:23 +01:00

some tiled sanity checks

This commit is contained in:
Ellpeck 2019-09-24 12:21:12 +02:00
parent d610899b7d
commit dbe02645f1

View file

@ -39,18 +39,22 @@ namespace MLEM.Extended.Tiled {
}
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTileset tileset, TiledMapTile tile, TiledMap map) {
if (tile.IsBlank)
return null;
var localId = tile.GetLocalIdentifier(tileset, map);
return tileset.Tiles.FirstOrDefault(t => t.LocalTileIdentifier == localId);
}
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTile tile, TiledMap map) {
if (tile.IsBlank)
return null;
var tileset = tile.GetTileset(map);
return tileset.GetTilesetTile(tile, map);
return tileset?.GetTilesetTile(tile, map);
}
public static TiledMapTile GetTile(this TiledMap map, string layerName, int x, int y) {
var layer = map.GetLayer<TiledMapTileLayer>(layerName);
return layer != null ? layer.GetTile((ushort) x, (ushort) y) : new TiledMapTile(0, (ushort) x, (ushort) y);
return layer != null ? layer.GetTile((ushort) x, (ushort) y) : default;
}
public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2 position) {