Exemplo n.º 1
0
 public static Action <List <TItem>, TGame, Command> CreateListAction <TGame, TItem>(string type, string typePlural = null, Action <TGame, Command> onEmptyList = null)
     where TGame : Game
     where TItem : VText
 {
     return(CreateListOrDisplayAction <TGame, TItem>(type, (item, game, command) =>
     {
         var title = typePlural ?? type + "s";
         game.AddElement(ListElement <TItem> .CreateListElement(new List <TItem> {
             item
         }, Text(title)));
     }, typePlural, onEmptyList));
 }
Exemplo n.º 2
0
        public static void ProcessArguments(Game game, string[] input, List <Command> commands)
        {
            var commandName = input[0];
            var matches     = new List <Command>();

            foreach (var command in commands)
            {
                if (command.IsExactMatch(commandName))
                {
                    AttemptCommandExecution(game, input, command);
                    return;
                }

                if (command.IsMatch(commandName))
                {
                    matches.Add(command);
                }
            }

            if (matches.Count == 1)
            {
                // ONE MATCH
                AttemptCommandExecution(game, input, matches[0]);
            }
            else if (matches.Count == 0)
            {
                // NO MATCHES
                WriteError(Text("No commands starting with ") +
                           Text(commandName).Apply(Quote(), SetForeground(ColorStandards.Input)) + Text(" found."));
                var similarCommands = GetSimilarCommands(commandName);
                if (similarCommands.Count > 0)
                {
                    WriteLine("Did you mean:");
                    game.AddElement(ListElement <Command> .CreateListElement(similarCommands));
                }
            }
            else
            {
                WriteLine(Text("Commands starting with ") +
                          Text(commandName).Apply(Quote(), SetForeground(ColorStandards.Input)) + Text(":"));
                game.AddElement(ListElement <Command> .CreateListElement(matches));
            }
        }
Exemplo n.º 3
0
 public static Action <List <TItem>, TGame, Command> CreateListOrDisplayAction <TGame, TItem>(string type, Action <TItem, TGame, Command> display, string typePlural = null, Action <TGame, Command> onEmptyList = null)
     where TGame : Game
     where TItem : VText
 {
     return((list, game, command) =>
     {
         if (list.Count == 0)
         {
             WriteError("No " + type + " found!");
             onEmptyList?.Invoke(game, command);
         }
         else if (list.Count == 1)
         {
             display(list[0], game, command);
         }
         else
         {
             var title = typePlural ?? type + "s";
             game.AddElement(ListElement <TItem> .CreateListElement(list, Text(title)));
         }
     });
 }