2020-05-11 17:10:43 -04:00
|
|
|
|
using IW4MAdmin.Application.Misc;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-02-07 19:43:36 -05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models.Client;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Factories
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// implementation of IScriptCommandFactory
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ScriptCommandFactory : IScriptCommandFactory
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly CommandConfiguration _config;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
private readonly ITranslationLookup _transLookup;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
public ScriptCommandFactory(CommandConfiguration config, ITranslationLookup transLookup, IServiceProvider serviceProvider)
|
2020-05-11 17:10:43 -04:00
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_transLookup = transLookup;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_serviceProvider = serviceProvider;
|
2020-05-11 17:10:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2020-11-11 18:31:26 -05:00
|
|
|
|
public IManagerCommand CreateScriptCommand(string name, string alias, string description, string permission,
|
2022-02-07 19:43:36 -05:00
|
|
|
|
bool isTargetRequired, IEnumerable<(string, bool)> args, Func<GameEvent, Task> executeAction, Server.Game[] supportedGames)
|
2020-05-11 17:10:43 -04:00
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var permissionEnum = Enum.Parse<EFClient.Permission>(permission);
|
2020-05-11 17:10:43 -04:00
|
|
|
|
var argsArray = args.Select(_arg => new CommandArgument
|
|
|
|
|
{
|
|
|
|
|
Name = _arg.Item1,
|
|
|
|
|
Required = _arg.Item2
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
return new ScriptCommand(name, alias, description, isTargetRequired, permissionEnum, argsArray, executeAction,
|
2022-02-07 19:43:36 -05:00
|
|
|
|
_config, _transLookup, _serviceProvider.GetRequiredService<ILogger<ScriptCommand>>(), supportedGames);
|
2020-05-11 17:10:43 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|