Skip to content

Commit f6a414b

Browse files
author
Mike Judge
committed
No logic changes, just changing some large if-blocks into early returns
1 parent 13dc509 commit f6a414b

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

Console/Scripts/ConsoleGUI.cs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,54 +94,55 @@ private void MoveCursorToPos(int position)
9494

9595
private void HandleTab()
9696
{
97-
if (KeyDown ("tab")) {
98-
if (input != "") { // don't do anything if the input field is still blank.
99-
List<string> search = consoleCommandsRepository.SearchCommands (input);
100-
if (search.Count == 0) { // nothing found
101-
consoleLog.Log ("No command start with \"" + input + "\".");
102-
input = ""; // clear input
103-
return;
104-
} else if (search.Count == 1) {
105-
input = search[0] + " "; // only found one command - type it in for the guy
106-
MoveCursorToPos(input.Length);
107-
} else {
108-
consoleLog.Log ("Commands starting with \"" + input + "\":");
109-
string largestMatch = search[0]; // keep track of the largest substring that matches all searches
110-
foreach (string command in search)
111-
{
112-
consoleLog.Log (command);
113-
largestMatch = LargestSubString(largestMatch, command);
114-
}
115-
input = largestMatch;
116-
MoveCursorToPos(input.Length);
97+
if (!KeyDown("tab"))
98+
return;
99+
100+
if (input != "") { // don't do anything if the input field is still blank.
101+
List<string> search = consoleCommandsRepository.SearchCommands (input);
102+
if (search.Count == 0) { // nothing found
103+
consoleLog.Log ("No command start with \"" + input + "\".");
104+
input = ""; // clear input
105+
} else if (search.Count == 1) {
106+
input = search[0] + " "; // only found one command - type it in for the guy
107+
MoveCursorToPos(input.Length);
108+
} else {
109+
consoleLog.Log ("Commands starting with \"" + input + "\":");
110+
string largestMatch = search[0]; // keep track of the largest substring that matches all searches
111+
foreach (string command in search)
112+
{
113+
consoleLog.Log (command);
114+
largestMatch = LargestSubString(largestMatch, command);
117115
}
116+
input = largestMatch;
117+
MoveCursorToPos(input.Length);
118118
}
119119
}
120120
}
121121

122122
private void HandleUp()
123123
{
124-
if (KeyDown ("up")) {
125-
consoleHistoryPosition += 1;
126-
if (consoleHistoryPosition > consoleHistoryCommands.Count - 1) consoleHistoryPosition = consoleHistoryCommands.Count - 1;
127-
input = consoleHistoryCommands[consoleHistoryPosition];
128-
fixPositionNextFrame = true;
129-
//MoveCursorToPos(input.Length);
130-
}
124+
if (!KeyDown("up"))
125+
return;
126+
127+
consoleHistoryPosition += 1;
128+
if (consoleHistoryPosition > consoleHistoryCommands.Count - 1) consoleHistoryPosition = consoleHistoryCommands.Count - 1;
129+
input = consoleHistoryCommands[consoleHistoryPosition];
130+
fixPositionNextFrame = true;
131131
}
132132

133133
private void HandleDown()
134134
{
135-
if (KeyDown ("down")) {
136-
consoleHistoryPosition -= 1;
137-
if (consoleHistoryPosition < 0) {
138-
consoleHistoryPosition = -1;
139-
input = "";
140-
}
141-
else
142-
input = consoleHistoryCommands[consoleHistoryPosition];
143-
MoveCursorToPos(input.Length);
135+
if (!KeyDown("down"))
136+
return;
137+
138+
consoleHistoryPosition -= 1;
139+
if (consoleHistoryPosition < 0) {
140+
consoleHistoryPosition = -1;
141+
input = "";
142+
} else {
143+
input = consoleHistoryCommands[consoleHistoryPosition];
144144
}
145+
MoveCursorToPos(input.Length);
145146
}
146147

147148
private void HandleSubmit() {

0 commit comments

Comments
 (0)