Last change
on this file since 452 was 405, checked in by alloc, 21 months ago |
Refactored console commands for A21 caching
|
File size:
1.3 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using JetBrains.Annotations;
|
---|
4 |
|
---|
5 | namespace CommandExtensions.Commands {
|
---|
6 | [UsedImplicitly]
|
---|
7 | public class ListItems : ConsoleCmdAbstract {
|
---|
8 | protected override string getDescription () {
|
---|
9 | return "lists all items that contain the given substring";
|
---|
10 | }
|
---|
11 |
|
---|
12 | protected override string[] getCommands () {
|
---|
13 | return new[] {"listitems", "li"};
|
---|
14 | }
|
---|
15 |
|
---|
16 | protected 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.