mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Remove redundant type identifiers
This commit is contained in:
parent
645e93611b
commit
c0a16e9bbd
@ -3,21 +3,21 @@ using UnityEngine;
|
||||
|
||||
namespace ConformalDecals.MaterialModifiers {
|
||||
public abstract class MaterialModifier {
|
||||
public string Name { get; }
|
||||
public string PropertyName { get; }
|
||||
|
||||
protected readonly int _propertyID;
|
||||
|
||||
|
||||
protected MaterialModifier(ConfigNode node) {
|
||||
Name = node.GetValue("name");
|
||||
PropertyName = node.GetValue("name");
|
||||
|
||||
if (Name == null)
|
||||
if (PropertyName == null)
|
||||
throw new FormatException("name not found, cannot create material modifier");
|
||||
|
||||
if (Name == string.Empty)
|
||||
if (PropertyName == string.Empty)
|
||||
throw new FormatException("name is empty, cannot create material modifier");
|
||||
|
||||
_propertyID = Shader.PropertyToID(Name);
|
||||
_propertyID = Shader.PropertyToID(PropertyName);
|
||||
}
|
||||
|
||||
public abstract void Modify(Material material);
|
||||
@ -25,30 +25,30 @@ namespace ConformalDecals.MaterialModifiers {
|
||||
private delegate bool TryParseDelegate<T>(string valueString, out T value);
|
||||
|
||||
protected bool ParsePropertyBool(ConfigNode node, string valueName, bool isOptional = false, bool defaultValue = false) {
|
||||
return ParsePropertyValue<bool>(node, valueName, bool.TryParse, isOptional, defaultValue);
|
||||
return ParsePropertyValue(node, valueName, bool.TryParse, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
protected float ParsePropertyFloat(ConfigNode node, string valueName, bool isOptional = false, float defaultValue = 0.0f) {
|
||||
return ParsePropertyValue<float>(node, valueName, float.TryParse, isOptional, defaultValue);
|
||||
return ParsePropertyValue(node, valueName, float.TryParse, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
protected int ParsePropertyInt(ConfigNode node, string valueName, bool isOptional = false, int defaultValue = 0) {
|
||||
return ParsePropertyValue<int>(node, valueName, int.TryParse, isOptional, defaultValue);
|
||||
return ParsePropertyValue(node, valueName, int.TryParse, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
protected Color ParsePropertyColor(ConfigNode node, string valueName, bool isOptional = false, Color defaultValue = default(Color)) {
|
||||
return ParsePropertyValue<Color>(node, valueName, ParseExtensions.TryParseColor, isOptional, defaultValue);
|
||||
protected Color ParsePropertyColor(ConfigNode node, string valueName, bool isOptional = false, Color defaultValue = default) {
|
||||
return ParsePropertyValue(node, valueName, ParseExtensions.TryParseColor, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
protected Rect ParsePropertyRect(ConfigNode node, string valueName, bool isOptional = false, Rect defaultValue = default(Rect)) {
|
||||
return ParsePropertyValue<Rect>(node, valueName, ParseExtensions.TryParseRect, isOptional, defaultValue);
|
||||
protected Rect ParsePropertyRect(ConfigNode node, string valueName, bool isOptional = false, Rect defaultValue = default) {
|
||||
return ParsePropertyValue(node, valueName, ParseExtensions.TryParseRect, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
protected Vector2 ParsePropertyVector2(ConfigNode node, string valueName, bool isOptional = false, Vector2 defaultValue = default(Vector2)) {
|
||||
return ParsePropertyValue<Vector2>(node, valueName, ParseExtensions.TryParseVector2, isOptional, defaultValue);
|
||||
protected Vector2 ParsePropertyVector2(ConfigNode node, string valueName, bool isOptional = false, Vector2 defaultValue = default) {
|
||||
return ParsePropertyValue(node, valueName, ParseExtensions.TryParseVector2, isOptional, defaultValue);
|
||||
}
|
||||
|
||||
private T ParsePropertyValue<T>(ConfigNode node, string valueName, TryParseDelegate<T> tryParse, bool isOptional = false, T defaultValue = default(T)) {
|
||||
private T ParsePropertyValue<T>(ConfigNode node, string valueName, TryParseDelegate<T> tryParse, bool isOptional = false, T defaultValue = default) {
|
||||
string valueString = node.GetValue(valueName);
|
||||
|
||||
if (isOptional) {
|
||||
@ -56,10 +56,10 @@ namespace ConformalDecals.MaterialModifiers {
|
||||
}
|
||||
else {
|
||||
if (valueString == null)
|
||||
throw new FormatException($"Missing {typeof(T)} value {valueName} in property '{Name}'");
|
||||
throw new FormatException($"Missing {typeof(T)} value {valueName} in property '{PropertyName}'");
|
||||
|
||||
if (valueString == string.Empty)
|
||||
throw new FormatException($"Empty {typeof(T)} value {valueName} in property '{Name}'");
|
||||
throw new FormatException($"Empty {typeof(T)} value {valueName} in property '{PropertyName}'");
|
||||
}
|
||||
|
||||
if (tryParse(valueString, out var value)) {
|
||||
@ -71,7 +71,7 @@ namespace ConformalDecals.MaterialModifiers {
|
||||
}
|
||||
|
||||
else {
|
||||
throw new FormatException($"Improperly formatted {typeof(T)} value {valueName} in property '{Name}'");
|
||||
throw new FormatException($"Improperly formatted {typeof(T)} value {valueName} in property '{PropertyName}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user