Merge pull request #11519 from Mailaender/utility-same-spawn

Avoid importing spawn points with the same location
This commit is contained in:
Oliver Brakmann
2016-07-09 15:08:33 +02:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

View File

@@ -9,6 +9,8 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
@@ -50,5 +52,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
return result.ToString();
}
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var knownKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (knownKeys.Add(keySelector(element)))
yield return element;
}
}
}
}

View File

@@ -254,8 +254,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));
// Add waypoint actors
foreach (var kv in wps)
// Add waypoint actors skipping duplicate entries
foreach (var kv in wps.DistinctBy(location => location.Second))
{
if (!singlePlayer && kv.First <= 7)
{