Skip to content

Commit f154cf3

Browse files
committed
Style and debug.
Cleaned up some code and added a way to enable debug from the settings panel. That is off by default.
1 parent 2038615 commit f154cf3

3 files changed

Lines changed: 73 additions & 29 deletions

File tree

AutoLineColor/AutoLineColorMod.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ public string Description
1818
get { return Constants.Description; }
1919
}
2020

21-
public void OnSettingsUI(UIHelperBase helper) {
21+
public void OnSettingsUI(UIHelperBase helper)
22+
{
2223
Config = Configuration.Instance;
24+
Config.FlushStagedChanges(); //make sure no prior changes are still around
2325
//Generate arrays of colors and naming strategies
2426
String[] ColorStrategies = Enum.GetNames(typeof(ColorStrategy));
2527
String[] NamingStrategies = Enum.GetNames(typeof(NamingStrategy));
@@ -31,6 +33,7 @@ public void OnSettingsUI(UIHelperBase helper) {
3133
group.AddGroup("Advanced Settings");
3234
group.AddSlider("Max Different Color Picks", 1f, 20f, 1f, (float)Config.MaxDiffColorPickAttempt, Config.MaxDiffColorPickChange);
3335
group.AddSlider("MinColorDifference", 1f, 100f, 5f, (float)Config.MinColorDiffPercentage, Config.MinColorDiffChange);
36+
group.AddCheckbox("Debug", logger.debug, logger.SetDebug);
3437
group.AddButton("Save", Config.Save);
3538
}
3639
}

AutoLineColor/Configuration.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,44 @@ public static Configuration LoadConfig()
7070
config = GetDefaultConfig();
7171
}
7272

73-
if (isDirty) {
73+
if (isDirty)
74+
{
7475
config.Save();
7576
}
7677

7778
return config;
7879
}
7980

80-
public void ColorStrategyChange(int Strategy) {
81+
public void ColorStrategyChange(int Strategy)
82+
{
8183
this.StagedColorStrategy = (ColorStrategy)Strategy;
8284
}
8385

84-
public void NamingStrategyChange(int Strategy) {
86+
public void NamingStrategyChange(int Strategy)
87+
{
8588
this.StagedNamingStrategy = (NamingStrategy)Strategy;
8689
}
8790

88-
public void MinColorDiffChange(float MinDiff) {
91+
public void MinColorDiffChange(float MinDiff)
92+
{
8993
this.StagedMinColorDiffPercentage = (int)MinDiff;
9094
}
9195

92-
public void MaxDiffColorPickChange(float MaxColorPicks) {
96+
public void MaxDiffColorPickChange(float MaxColorPicks)
97+
{
9398
this.StagedMaxDiffColorPickAttempt = (int)MaxColorPicks;
9499
}
95100

96-
public void Save() {
101+
public void FlushStagedChanges()
102+
{
103+
StagedColorStrategy = null;
104+
StagedNamingStrategy = null;
105+
StagedMaxDiffColorPickAttempt = null;
106+
StagedMinColorDiffPercentage = null;
107+
}
108+
109+
public void Save()
110+
{
97111
var serializer = new XmlSerializer(typeof(Configuration));
98112

99113
logger.Message("Saving changes to config file");
@@ -115,26 +129,28 @@ public void Save() {
115129
: this.MinColorDiffPercentage;
116130

117131
//clear changes and log
118-
if (this.StagedColorStrategy.HasValue) {
132+
if (this.StagedColorStrategy.HasValue)
133+
{
119134
logger.Message("ColorStrategy changed to " + this.StagedColorStrategy.Value.ToString());
120-
this.StagedColorStrategy = null;
121135
}
122136

123-
if (this.StagedNamingStrategy.HasValue) {
137+
if (this.StagedNamingStrategy.HasValue)
138+
{
124139
logger.Message("NamingStrategy changed to " + this.StagedNamingStrategy.Value.ToString());
125-
this.StagedNamingStrategy = null;
126140
}
127141

128-
if (this.StagedMaxDiffColorPickAttempt.HasValue) {
142+
if (this.StagedMaxDiffColorPickAttempt.HasValue)
143+
{
129144
logger.Message("MaxDiffColorPickAttempt changed to " + this.StagedMaxDiffColorPickAttempt.Value.ToString());
130-
this.StagedMaxDiffColorPickAttempt = null;
131145
}
132146

133-
if (this.StagedMinColorDiffPercentage.HasValue) {
147+
if (this.StagedMinColorDiffPercentage.HasValue)
148+
{
134149
logger.Message("MinColorDiffPercentage changed to " + this.StagedMinColorDiffPercentage.Value.ToString());
135-
this.StagedMinColorDiffPercentage = null;
136150
}
137151

152+
FlushStagedChanges();
153+
138154
//How we let the ColorMonitor thread know to update the strategies
139155
logger.Message("Marking undigested changes");
140156
this.UndigestedChanges = true;

AutoLineColor/Console.cs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ namespace AutoLineColor
1010
{
1111
public class Console
1212
{
13-
#if DEBUG
14-
private bool debug = true;
15-
#else
16-
private bool debug = false;
17-
#endif
1813
private static Console _instance;
14+
private bool _debug = false;
1915

2016
private StreamWriter log;
2117
private bool log_opened;
2218

23-
private Console() {
24-
try {
19+
private Console()
20+
{
21+
#if DEBUG
22+
_debug = true;
23+
#endif
24+
try
25+
{
2526
log = new StreamWriter(new FileStream(Constants.LogFileName, FileMode.Append | FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
26-
} catch (Exception e) {
27+
}
28+
catch (Exception e)
29+
{
2730
WriteMessage("Could not open log file", PluginManager.MessageType.Warning);
2831
}
32+
2933
log_opened = true;
3034
}
3135

@@ -41,18 +45,39 @@ public static Console Instance
4145
}
4246
}
4347

48+
public bool debug
49+
{
50+
get
51+
{
52+
return _debug;
53+
}
54+
}
55+
4456
private static string FormatMessage(string msg, PluginManager.MessageType Type)
4557
{
4658
string formatted;
47-
try {
59+
try
60+
{
4861
formatted = string.Format("{0}({1}) {2}", "[AutoLineColor]", Type.ToString(), msg);
49-
} catch (Exception e) {
62+
}
63+
catch (Exception e)
64+
{
5065
DebugOutputPanel.AddMessage(PluginManager.MessageType.Error, e.ToString());
5166
formatted = msg;
5267
}
5368
return formatted;
5469
}
5570

71+
public void ToggleDebug()
72+
{
73+
_debug = !_debug;
74+
}
75+
76+
public void SetDebug(bool should_debug)
77+
{
78+
_debug = should_debug;
79+
}
80+
5681
public void Message(string p, PluginManager.MessageType messageType)
5782
{
5883
this.WriteMessage(p, messageType);
@@ -72,8 +97,9 @@ public void Error(string p)
7297
this.WriteMessage(p, PluginManager.MessageType.Error);
7398
}
7499

75-
private void WriteMessage(string p, PluginManager.MessageType Type) {
76-
if(!this.debug)
100+
private void WriteMessage(string p, PluginManager.MessageType Type)
101+
{
102+
if(!this._debug)
77103
{
78104
return;
79105
}
@@ -83,7 +109,7 @@ private void WriteMessage(string p, PluginManager.MessageType Type) {
83109
log.WriteLine(msg);
84110
log.Flush();
85111
}
86-
112+
87113
//Unity engine logger
88114
switch(Type)
89115
{
@@ -100,7 +126,6 @@ private void WriteMessage(string p, PluginManager.MessageType Type) {
100126
Debug.Log(msg);
101127
break;
102128
}
103-
104129
}
105130
}
106131
}

0 commit comments

Comments
 (0)