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

added an easy way to find objects on a tiled map

This commit is contained in:
Ellpeck 2019-12-19 00:27:56 +01:00
parent da244dd33e
commit c6fff090e6

View file

@ -97,5 +97,19 @@ namespace MLEM.Extended.Tiled {
return x >= 0 && y >= 0 && x < layer.Width && y < layer.Height;
}
public static IEnumerable<TiledMapObject> GetObjects(this TiledMapObjectLayer layer, string id, bool searchName = true, bool searchType = false) {
foreach (var obj in layer.Objects) {
if (searchName && obj.Name == id || searchType && obj.Type == id)
yield return obj;
}
}
public static IEnumerable<TiledMapObject> GetObjects(this TiledMap map, string name, bool searchName = true, bool searchType = false) {
foreach (var layer in map.ObjectLayers) {
foreach (var obj in layer.GetObjects(name, searchName, searchType))
yield return obj;
}
}
}
}