2019-12-15 07:20:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-12-16 00:35:59 +00:00
|
|
|
|
|
2019-12-15 07:20:20 +00:00
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
|
2019-12-17 01:55:52 +00:00
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
2019-12-15 07:20:20 +00:00
|
|
|
|
namespace GamecraftModdingAPI.Commands
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Keeps track of custom commands
|
|
|
|
|
/// This is used to add, remove and get command engines
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class CommandManager
|
|
|
|
|
{
|
|
|
|
|
private static Dictionary<string, ICustomCommandEngine> _customCommands = new Dictionary<string, ICustomCommandEngine>();
|
|
|
|
|
|
2020-01-26 19:28:57 +00:00
|
|
|
|
private static EnginesRoot _lastEngineRoot;
|
|
|
|
|
|
2019-12-15 07:20:20 +00:00
|
|
|
|
public static void AddCommand(ICustomCommandEngine engine)
|
|
|
|
|
{
|
2020-05-01 18:50:55 +00:00
|
|
|
|
if (ExistsCommand(engine))
|
|
|
|
|
{
|
|
|
|
|
Logging.LogWarning($"Command {engine.Name} already exists!");
|
|
|
|
|
}
|
2019-12-15 07:20:20 +00:00
|
|
|
|
_customCommands[engine.Name] = engine;
|
2020-01-26 19:28:57 +00:00
|
|
|
|
if (_lastEngineRoot != null)
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog($"Registering ICustomCommandEngine {engine.Name}");
|
|
|
|
|
_lastEngineRoot.AddEngine(engine);
|
|
|
|
|
}
|
2019-12-15 07:20:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ExistsCommand(string name)
|
|
|
|
|
{
|
|
|
|
|
return _customCommands.ContainsKey(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ExistsCommand(ICustomCommandEngine engine)
|
|
|
|
|
{
|
|
|
|
|
return ExistsCommand(engine.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ICustomCommandEngine GetCommand(string name)
|
|
|
|
|
{
|
|
|
|
|
return _customCommands[name];
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 00:35:59 +00:00
|
|
|
|
public static string[] GetCommandNames()
|
2019-12-15 07:20:20 +00:00
|
|
|
|
{
|
2019-12-16 00:35:59 +00:00
|
|
|
|
return _customCommands.Keys.ToArray();
|
2019-12-15 07:20:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RemoveCommand(string name)
|
|
|
|
|
{
|
|
|
|
|
_customCommands.Remove(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RegisterEngines(EnginesRoot enginesRoot)
|
|
|
|
|
{
|
2020-01-26 19:28:57 +00:00
|
|
|
|
_lastEngineRoot = enginesRoot;
|
2019-12-15 07:20:20 +00:00
|
|
|
|
foreach (var key in _customCommands.Keys)
|
|
|
|
|
{
|
2019-12-17 01:55:52 +00:00
|
|
|
|
Logging.MetaDebugLog($"Registering ICustomCommandEngine {_customCommands[key].Name}");
|
2019-12-15 07:20:20 +00:00
|
|
|
|
enginesRoot.AddEngine(_customCommands[key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|