Avoid importing spawn points with the same location.

This commit is contained in:
Matthias Mailänder
2016-06-25 09:41:57 +02:00
parent a421a191b5
commit a55b8659c7
2 changed files with 14 additions and 2 deletions

View File

@@ -9,6 +9,8 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Text; using System.Text;
@@ -50,5 +52,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
return result.ToString(); 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

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