Skip to content

Commit

Permalink
More error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihara committed Jul 24, 2014
1 parent 58ead17 commit 86ecda2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public void Start()
startupComplete = true;
} catch {
JUtil.AnnoyUser(this);
enabled = false;
throw;
}
}
Expand Down
68 changes: 37 additions & 31 deletions RasterPropMonitor/Auxiliary modules/JSISwitchableVariableLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,54 @@ public class JSISwitchableVariableLabel:InternalModule

public void Start()
{
comp = RasterPropMonitorComputer.Instantiate(internalProp);
textObjTransform = internalProp.FindModelTransform(labelTransform);
textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty);
activeLabel = 0;
try {
comp = RasterPropMonitorComputer.Instantiate(internalProp);
textObjTransform = internalProp.FindModelTransform(labelTransform);
textObj = InternalComponents.Instance.CreateText(fontName, fontSize, textObjTransform, string.Empty);
activeLabel = 0;

SmarterButton.CreateButton(internalProp, switchTransform, Click);
SmarterButton.CreateButton(internalProp, switchTransform, Click);

ConfigNode moduleConfig = null;
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) {
if (node.GetValue("name") == internalProp.propName) {
ConfigNode moduleConfig = null;
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) {
if (node.GetValue("name") == internalProp.propName) {

moduleConfig = node.GetNodes("MODULE")[moduleID];
ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET");
moduleConfig = node.GetNodes("MODULE")[moduleID];
ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET");

for (int i = 0; i < variableNodes.Length; i++) {
try {
labelsEx.Add(new VariableLabelSet(variableNodes[i]));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
for (int i = 0; i < variableNodes.Length; i++) {
try {
labelsEx.Add(new VariableLabelSet(variableNodes[i]));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
}
}
break;
}
break;
}
}

// Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block.
if (labelsEx.Count < 1 && moduleConfig != null) {
try {
labelsEx.Add(new VariableLabelSet(moduleConfig));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
// Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block.
if (labelsEx.Count < 1 && moduleConfig != null) {
try {
labelsEx.Add(new VariableLabelSet(moduleConfig));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
}
}
}

colorShiftRenderer = internalProp.FindModelComponent<Renderer>(coloredObject);
if (labelsEx[activeLabel].hasColor) {
colorShiftRenderer.material.SetColor(colorName, labelsEx[activeLabel].color);
}
textObj.text.Text = StringProcessor.ProcessString(labelsEx[activeLabel].labelText, comp);
colorShiftRenderer = internalProp.FindModelComponent<Renderer>(coloredObject);
if (labelsEx[activeLabel].hasColor) {
colorShiftRenderer.material.SetColor(colorName, labelsEx[activeLabel].color);
}
textObj.text.Text = StringProcessor.ProcessString(labelsEx[activeLabel].labelText, comp);

audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false);
JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", labelsEx.Count, internalProp.propID);
audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false);
JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", labelsEx.Count, internalProp.propID);
} catch {
JUtil.AnnoyUser(this);
enabled = false;
throw;
}
}

private bool UpdateCheck()
Expand Down
56 changes: 31 additions & 25 deletions RasterPropMonitor/Auxiliary modules/JSIVariableAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,43 @@ private bool UpdateCheck()

public void Start()
{
ConfigNode moduleConfig = null;
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes ("PROP")) {
if (node.GetValue("name") == internalProp.propName) {

moduleConfig = node.GetNodes("MODULE")[moduleID];
ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET");

for (int i = 0; i < variableNodes.Length; i++) {
try {
variableSets.Add(new VariableAnimationSet(variableNodes[i], internalProp));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
try {
ConfigNode moduleConfig = null;
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes ("PROP")) {
if (node.GetValue("name") == internalProp.propName) {

moduleConfig = node.GetNodes("MODULE")[moduleID];
ConfigNode[] variableNodes = moduleConfig.GetNodes("VARIABLESET");

for (int i = 0; i < variableNodes.Length; i++) {
try {
variableSets.Add(new VariableAnimationSet(variableNodes[i], internalProp));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
}
}
break;
}
break;
}
}

// Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block.
if (variableSets.Count < 1 && moduleConfig != null) {
try {
variableSets.Add(new VariableAnimationSet(moduleConfig, internalProp));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
// Fallback: If there are no VARIABLESET blocks, we treat the module configuration itself as a variableset block.
if (variableSets.Count < 1 && moduleConfig != null) {
try {
variableSets.Add(new VariableAnimationSet(moduleConfig, internalProp));
} catch (ArgumentException e) {
JUtil.LogMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID);
}
}
JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", variableSets.Count, internalProp.propID);
foreach (VariableAnimationSet thatSet in variableSets) {
alwaysActive |= thatSet.alwaysActive;
}
startupComplete = true;
} catch {
JUtil.AnnoyUser(this);
enabled = false;
throw;
}
JUtil.LogMessage(this, "Configuration complete in prop {1}, supporting {0} variable indicators.", variableSets.Count, internalProp.propID);
foreach (VariableAnimationSet thatSet in variableSets) {
alwaysActive |= thatSet.alwaysActive;
}
startupComplete = true;
}

public override void OnUpdate()
Expand Down
2 changes: 2 additions & 0 deletions RasterPropMonitor/Core/RasterPropMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public void Start()
} catch {
JUtil.AnnoyUser(this);
startupFailed = true;
// We can also disable ourselves, that should help.
enabled = false;
// And now that we notified the user that config is borked, we rethrow the exception so that
// it gets logged and we can debug.
throw;
Expand Down
2 changes: 1 addition & 1 deletion SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Now this is the actual version number with build number.
// As I release newer ones, I'll bump them manually.
// Build number is altered automatically.
[assembly: AssemblyFileVersion("0.18.0.18")]
[assembly: AssemblyFileVersion("0.18.0.21")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down

0 comments on commit 86ecda2

Please sign in to comment.