source: binary-improvements2/CommandExtensions/src/Commands/ListItems.cs@ 400

Last change on this file since 400 was 391, checked in by alloc, 2 years ago

Major refactoring/cleanup

File size: 1.3 KB
RevLine 
[391]1using System;
2using System.Collections.Generic;
3using JetBrains.Annotations;
4
5namespace CommandExtensions.Commands {
6 [UsedImplicitly]
7 public class ListItems : ConsoleCmdAbstract {
8 public override string GetDescription () {
9 return "lists all items that contain the given substring";
10 }
11
12 public override string[] GetCommands () {
13 return new[] {"listitems", "li"};
14 }
15
16 public override string GetHelp () {
17 return "List all available item names\n" +
18 "Usage:\n" +
19 " 1. listitems <searchString>\n" +
20 " 2. listitems *\n" +
21 "1. List only names that contain the given string.\n" +
22 "2. List all names.";
23 }
24
25 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
26 if (_params.Count != 1 || _params [0].Length == 0) {
27 SdtdConsole.Instance.Output ("Usage: listitems <searchString>");
28 return;
29 }
30
31 int count = ItemClass.ItemNames.Count;
32 bool showAll = _params [0].Trim ().Equals ("*");
33
34 int listed = 0;
35 for (int i = 0; i < count; i++) {
36 string s = ItemClass.ItemNames [i];
37 if (!showAll && s.IndexOf (_params [0], StringComparison.OrdinalIgnoreCase) < 0) {
38 continue;
39 }
40
41 SdtdConsole.Instance.Output (" " + s);
42 listed++;
43 }
44
45 SdtdConsole.Instance.Output ("Listed " + listed + " matching items.");
46 }
47 }
48}
Note: See TracBrowser for help on using the repository browser.