Moved ImportLegacyMapCommand to OpenRA.Mods.Cnc
Also renamed to `ImportGen1MapCommand`. Also moved Extensions.DistinctBy().
This commit is contained in:
@@ -15,19 +15,20 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.FileFormats;
|
||||
using OpenRA.Mods.Common.Terrain;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
{
|
||||
public abstract class ImportLegacyMapCommand
|
||||
public abstract class ImportGen1MapCommand
|
||||
{
|
||||
public readonly int MapSize;
|
||||
|
||||
protected ImportLegacyMapCommand(int mapSize)
|
||||
protected ImportGen1MapCommand(int mapSize)
|
||||
{
|
||||
MapSize = mapSize;
|
||||
}
|
||||
@@ -451,4 +452,22 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET6_0_OR_GREATER
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Only used for Mono builds. .NET 6 added the exact same thing.
|
||||
/// </summary>
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
var knownKeys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (knownKeys.Add(keySelector(element)))
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -16,14 +16,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.Mods.Cnc.FileFormats;
|
||||
using OpenRA.Mods.Common.FileFormats;
|
||||
using OpenRA.Mods.Common.UtilityCommands;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
{
|
||||
class ImportRedAlertLegacyMapCommand : ImportLegacyMapCommand, IUtilityCommand
|
||||
class ImportRedAlertMapCommand : ImportGen1MapCommand, IUtilityCommand
|
||||
{
|
||||
// TODO: 128x128 is probably not true for "mega maps" from the expansions.
|
||||
public ImportRedAlertLegacyMapCommand()
|
||||
public ImportRedAlertMapCommand()
|
||||
: base(128) { }
|
||||
|
||||
string IUtilityCommand.Name => "--import-ra-map";
|
||||
@@ -14,14 +14,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.FileFormats;
|
||||
using OpenRA.Mods.Common.UtilityCommands;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
{
|
||||
class ImportTiberianDawnLegacyMapCommand : ImportLegacyMapCommand, IUtilityCommand
|
||||
class ImportTiberianDawnMapCommand : ImportGen1MapCommand, IUtilityCommand
|
||||
{
|
||||
// NOTE: 64x64 map size is a C&C95 engine limitation
|
||||
public ImportTiberianDawnLegacyMapCommand()
|
||||
public ImportTiberianDawnMapCommand()
|
||||
: base(64) { }
|
||||
|
||||
string IUtilityCommand.Name => "--import-td-map";
|
||||
@@ -1,29 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
var knownKeys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (knownKeys.Add(keySelector(element)))
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user