fix issue with registering multiple script commands in command configuration
This commit is contained in:
parent
cad2952c46
commit
fa79f4af73
@ -1,5 +1,6 @@
|
|||||||
using IW4MAdmin.Application.API.Master;
|
using IW4MAdmin.Application.API.Master;
|
||||||
using IW4MAdmin.Application.EventParsers;
|
using IW4MAdmin.Application.EventParsers;
|
||||||
|
using IW4MAdmin.Application.Extensions;
|
||||||
using IW4MAdmin.Application.Misc;
|
using IW4MAdmin.Application.Misc;
|
||||||
using IW4MAdmin.Application.RconParsers;
|
using IW4MAdmin.Application.RconParsers;
|
||||||
using SharedLibraryCore;
|
using SharedLibraryCore;
|
||||||
@ -427,13 +428,13 @@ namespace IW4MAdmin.Application
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var unsavedCommands = _commands.Where(_cmd => !cmdConfig.Commands.Keys.Contains(_cmd.GetType().Name));
|
var unsavedCommands = _commands.Where(_cmd => !cmdConfig.Commands.Keys.Contains(_cmd.CommandConfigNameForType()));
|
||||||
commandsToAddToConfig.AddRange(unsavedCommands);
|
commandsToAddToConfig.AddRange(unsavedCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var cmd in commandsToAddToConfig)
|
foreach (var cmd in commandsToAddToConfig)
|
||||||
{
|
{
|
||||||
cmdConfig.Commands.Add(cmd.GetType().Name,
|
cmdConfig.Commands.Add(cmd.CommandConfigNameForType(),
|
||||||
new CommandProperties()
|
new CommandProperties()
|
||||||
{
|
{
|
||||||
Name = cmd.Name,
|
Name = cmd.Name,
|
||||||
|
21
Application/Extensions/CommandExtensions.cs
Normal file
21
Application/Extensions/CommandExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using IW4MAdmin.Application.Misc;
|
||||||
|
using SharedLibraryCore.Interfaces;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace IW4MAdmin.Application.Extensions
|
||||||
|
{
|
||||||
|
public static class CommandExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// determines the command configuration name for given manager command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">command to determine config name for</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string CommandConfigNameForType(this IManagerCommand command)
|
||||||
|
{
|
||||||
|
return command.GetType() == typeof(ScriptCommand) ?
|
||||||
|
$"{char.ToUpper(command.Name[0])}{command.Name.Substring(1)}Command" :
|
||||||
|
command.GetType().Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user