From c6fff090e61200cb590db63cdb3ec789ff2b9566 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 19 Dec 2019 00:27:56 +0100 Subject: [PATCH] added an easy way to find objects on a tiled map --- MLEM.Extended/Tiled/TiledExtensions.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MLEM.Extended/Tiled/TiledExtensions.cs b/MLEM.Extended/Tiled/TiledExtensions.cs index f61a894..0d3beaf 100644 --- a/MLEM.Extended/Tiled/TiledExtensions.cs +++ b/MLEM.Extended/Tiled/TiledExtensions.cs @@ -97,5 +97,19 @@ namespace MLEM.Extended.Tiled { return x >= 0 && y >= 0 && x < layer.Width && y < layer.Height; } + public static IEnumerable 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 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; + } + } + } } \ No newline at end of file