Skip to content

Commit cf241df

Browse files
author
Mike Judge
committed
Whitespace fixes
1 parent 379422e commit cf241df

File tree

3 files changed

+141
-141
lines changed

3 files changed

+141
-141
lines changed

Console/Scripts/ConsoleCommandsRepository.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,45 @@
55
public delegate string ConsoleCommandCallback(params string[] args);
66

77
public class ConsoleCommandsRepository {
8-
private static ConsoleCommandsRepository instance;
9-
private Dictionary<string, ConsoleCommandCallback> repository;
8+
private static ConsoleCommandsRepository instance;
9+
private Dictionary<string, ConsoleCommandCallback> repository;
1010

11-
public static ConsoleCommandsRepository Instance {
12-
get {
13-
if (instance == null) {
14-
instance = new ConsoleCommandsRepository();
15-
}
16-
return instance;
11+
public static ConsoleCommandsRepository Instance {
12+
get {
13+
if (instance == null) {
14+
instance = new ConsoleCommandsRepository();
15+
}
16+
return instance;
17+
}
18+
}
19+
public ConsoleCommandsRepository() {
20+
repository = new Dictionary<string, ConsoleCommandCallback>();
1721
}
18-
}
19-
public ConsoleCommandsRepository() {
20-
repository = new Dictionary<string, ConsoleCommandCallback>();
21-
}
2222

23-
public void RegisterCommand(string command, ConsoleCommandCallback callback) {
24-
repository[command] = new ConsoleCommandCallback(callback);
25-
}
23+
public void RegisterCommand(string command, ConsoleCommandCallback callback) {
24+
repository[command] = new ConsoleCommandCallback(callback);
25+
}
2626

27-
public bool HasCommand(string command) {
28-
return repository.ContainsKey(command);
29-
}
27+
public bool HasCommand(string command) {
28+
return repository.ContainsKey(command);
29+
}
3030

31-
public List<string> SearchCommands(string str) {
32-
string[] keys = new string[repository.Count];
33-
repository.Keys.CopyTo (keys, 0);
34-
List<string> output = new List<string>();
35-
foreach (string key in keys) {
36-
if (key.StartsWith(str))
37-
output.Add(key);
38-
}
39-
return output;
40-
}
31+
public List<string> SearchCommands(string str) {
32+
string[] keys = new string[repository.Count];
33+
repository.Keys.CopyTo (keys, 0);
34+
List<string> output = new List<string>();
35+
foreach (string key in keys) {
36+
if (key.StartsWith(str))
37+
output.Add(key);
38+
}
39+
return output;
40+
}
4141

42-
public string ExecuteCommand(string command, string[] args) {
43-
if (HasCommand(command)) {
44-
return repository[command](args);
45-
} else {
46-
return "Command not found";
47-
}
48-
}
42+
public string ExecuteCommand(string command, string[] args) {
43+
if (HasCommand(command)) {
44+
return repository[command](args);
45+
} else {
46+
return "Command not found";
47+
}
48+
}
4949
}

Console/Scripts/ConsoleGUI.cs

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class ConsoleGUI : MonoBehaviour {
2525
private void Start() {
2626
consoleRect = new Rect(0, 0, Screen.width, Mathf.Min(300, Screen.height));
2727
consoleLog = ConsoleLog.Instance;
28-
consoleCommandsRepository = ConsoleCommandsRepository.Instance;
29-
}
28+
consoleCommandsRepository = ConsoleCommandsRepository.Instance;
29+
}
3030

3131
private void OnEnable() {
3232
focus = true;
@@ -40,23 +40,23 @@ public void OnGUI() {
4040
GUILayout.Window(WINDOW_ID, consoleRect, RenderWindow, "Console");
4141
}
4242
private void RenderWindow(int id) {
43-
if (fixPositionNextFrame)
44-
{
45-
MoveCursorToPos (input.Length);
46-
fixPositionNextFrame = false;
47-
}
43+
if (fixPositionNextFrame)
44+
{
45+
MoveCursorToPos (input.Length);
46+
fixPositionNextFrame = false;
47+
}
4848
HandleSubmit();
4949
HandleEscape();
50-
HandleTab();
51-
HandleUp ();
52-
HandleDown ();
50+
HandleTab();
51+
HandleUp();
52+
HandleDown();
5353
scrollPosition = GUILayout.BeginScrollView(new Vector2(0, scrollPosition), false, true).y;
54-
if (consoleLog.fresh)
55-
{
56-
scrollPosition = consoleLog.scrollLength;
57-
consoleLog.fresh = false;
58-
}
59-
GUILayout.Label(consoleLog.log);
54+
if (consoleLog.fresh)
55+
{
56+
scrollPosition = consoleLog.scrollLength;
57+
consoleLog.fresh = false;
58+
}
59+
GUILayout.Label(consoleLog.log);
6060
GUILayout.EndScrollView();
6161
GUI.SetNextControlName("input");
6262
input = GUILayout.TextField(input);
@@ -65,95 +65,95 @@ private void RenderWindow(int id) {
6565
focus = false;
6666
}
6767
}
68-
69-
70-
private string LargestSubString(string in1, string in2) // takes two strings and returns the largest matching substring.
71-
{
72-
string output = "";
73-
int smallestLen = Mathf.Min(in1.Length, in2.Length);
74-
for (int i = 0; i<smallestLen; i++) {
75-
if (in1[i] == in2[i]) output += in1[i];
76-
else return output;
77-
}
78-
return output;
79-
}
80-
81-
private void MoveCursorToPos(int position)
82-
{
83-
TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
68+
69+
70+
private string LargestSubString(string in1, string in2) // takes two strings and returns the largest matching substring.
71+
{
72+
string output = "";
73+
int smallestLen = Mathf.Min(in1.Length, in2.Length);
74+
for (int i = 0; i<smallestLen; i++) {
75+
if (in1[i] == in2[i]) output += in1[i];
76+
else return output;
77+
}
78+
return output;
79+
}
80+
81+
private void MoveCursorToPos(int position)
82+
{
83+
TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
8484
#if UNITY_5_2 || UNITY_5_3 || UNITY_5_3_OR_NEWER
85-
editor.selectIndex = position;
86-
editor.cursorIndex = position;
85+
editor.selectIndex = position;
86+
editor.cursorIndex = position;
8787
#else
88-
89-
editor.selectPos = position;
90-
editor.pos = position;
88+
89+
editor.selectPos = position;
90+
editor.pos = position;
9191
#endif
92-
return;
93-
}
94-
95-
private void HandleTab()
96-
{
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);
117-
}
118-
}
119-
}
120-
}
121-
122-
private void HandleUp()
123-
{
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-
}
131-
}
132-
133-
private void HandleDown()
134-
{
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);
144-
}
145-
}
92+
return;
93+
}
94+
95+
private void HandleTab()
96+
{
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);
117+
}
118+
}
119+
}
120+
}
121+
122+
private void HandleUp()
123+
{
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+
}
131+
}
132+
133+
private void HandleDown()
134+
{
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);
144+
}
145+
}
146146

147147
private void HandleSubmit() {
148148
if (KeyDown("[enter]") || KeyDown("return")) {
149-
consoleHistoryPosition = -1; // up arrow or down arrow will set it to 0, which is the last command typed.
150-
if (submitAction != null) {
149+
consoleHistoryPosition = -1; // up arrow or down arrow will set it to 0, which is the last command typed.
150+
if (submitAction != null) {
151151
submitAction.Activate();
152-
consoleHistoryCommands.Insert(0, input);
153-
if (consoleHistoryCommands.Count > maxConsoleHistorySize)
154-
consoleHistoryCommands.RemoveAt(consoleHistoryCommands.Count-1);
152+
consoleHistoryCommands.Insert(0, input);
153+
if (consoleHistoryCommands.Count > maxConsoleHistorySize)
154+
consoleHistoryCommands.RemoveAt(consoleHistoryCommands.Count-1);
155155
}
156-
input = "";
156+
input = "";
157157
}
158158
}
159159

@@ -164,10 +164,10 @@ private void HandleEscape() {
164164
}
165165
}
166166

167-
private void Update() {
168-
if (input == "`")
169-
input = "";
170-
}
167+
private void Update() {
168+
if (input == "`")
169+
input = "";
170+
}
171171

172172
private bool KeyDown(string key) {
173173
return Event.current.Equals(Event.KeyboardEvent(key));

Console/Scripts/ConsoleLog.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public static ConsoleLog Instance {
1313
}
1414

1515
public string log = "";
16-
public int scrollLength;
17-
public bool fresh = false;
16+
public int scrollLength;
17+
public bool fresh = false;
1818

1919
public void Log(string message) {
2020
log += message + "\n";
21-
fresh = true;
22-
Debug.Log((message + "\n").Split('\n').Length);
23-
scrollLength += ((message+"\n").Split('\n').Length)*20;
21+
fresh = true;
22+
Debug.Log((message + "\n").Split('\n').Length);
23+
scrollLength += ((message+"\n").Split('\n').Length)*20;
2424
}
2525
}

0 commit comments

Comments
 (0)