Skip to content

Commit

Permalink
Use MatcherType instead of Type to remove shadowing from C# Type
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Nov 2, 2017
1 parent 95b0329 commit 0218da9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
11 changes: 4 additions & 7 deletions Assets/Editor/FilterStyleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FilterStyleEditor : EditorBase
private int selectedLayer;

[SerializeField]
private FeatureStyle.Matcher.Type selectedMatcherType;
private FeatureStyle.Matcher.MatcherType selectedMatcherType;

[SerializeField]
private List<LayerStyleEditor> layerStyleEditors;
Expand Down Expand Up @@ -59,7 +59,7 @@ public FilterStyleEditor(FeatureStyle.FilterStyle filterStyle)

if (filterStyle.Matcher != null)
{
selectedMatcherType = filterStyle.Matcher.MatcherType;
selectedMatcherType = filterStyle.Matcher.Type;
this.matcherEditor = new MatcherEditor(filterStyle.Matcher);
}
}
Expand Down Expand Up @@ -142,20 +142,17 @@ public void OnInspectorGUI()

EditorGUI.indentLevel--;

var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast<FeatureStyle.Matcher.Type>();
var matcherTypeStringList = matcherTypeList.Select(type => type.ToString());
var oldType = selectedMatcherType;

selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:",
(int)selectedMatcherType, matcherTypeStringList.ToArray());
selectedMatcherType = (FeatureStyle.Matcher.MatcherType)EditorGUILayout.EnumPopup("Matcher:", selectedMatcherType);

if (selectedMatcherType != oldType)
{
matcherEditor = new MatcherEditor(new FeatureStyle.Matcher(selectedMatcherType));
}
else
{
if (selectedMatcherType == FeatureStyle.Matcher.Type.None)
if (selectedMatcherType == FeatureStyle.Matcher.MatcherType.None)
{
matcherEditor = null;
}
Expand Down
24 changes: 10 additions & 14 deletions Assets/Editor/MatcherEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class MatcherEditor : EditorBase
{
[SerializeField]
private FeatureStyle.Matcher.Type selectedMatcherType;
private FeatureStyle.Matcher.MatcherType selectedMatcherType;

[SerializeField]
private FeatureStyle.Matcher matcher;
Expand Down Expand Up @@ -42,17 +42,13 @@ private MatcherEditor AddMatcherLayout()

EditorGUILayout.BeginHorizontal();
{
var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast<FeatureStyle.Matcher.Type>();
var matcherTypeStringList = matcherTypeList.Select(type => type.ToString());

selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:",
(int)selectedMatcherType, matcherTypeStringList.ToArray());
selectedMatcherType = (FeatureStyle.Matcher.MatcherType)EditorGUILayout.EnumPopup("Matcher:", selectedMatcherType);

EditorConfig.SetColor(EditorConfig.AddButtonColor);
if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)
&& selectedMatcherType != FeatureStyle.Matcher.Type.None)
&& selectedMatcherType != FeatureStyle.Matcher.MatcherType.None)
{
var matcherType = (FeatureStyle.Matcher.Type)selectedMatcherType;
var matcherType = (FeatureStyle.Matcher.MatcherType)selectedMatcherType;
var newMatcher = new FeatureStyle.Matcher(matcherType);

editor = new MatcherEditor(newMatcher);
Expand All @@ -79,13 +75,13 @@ public void OnInspectorGUI()
}
else
{
switch (matcher.MatcherType)
switch (matcher.Type)
{
case FeatureStyle.Matcher.Type.Property:
case FeatureStyle.Matcher.MatcherType.Property:
matcher.HasProperty = EditorGUILayout.TextField("Has property:", matcher.HasProperty);
break;

case FeatureStyle.Matcher.Type.PropertyRange:
case FeatureStyle.Matcher.MatcherType.PropertyRange:
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
EditorGUILayout.BeginHorizontal();
matcher.MinRange = EditorGUILayout.FloatField("min:", matcher.MinRange);
Expand All @@ -97,12 +93,12 @@ public void OnInspectorGUI()
EditorGUILayout.EndHorizontal();
break;

case FeatureStyle.Matcher.Type.PropertyValue:
case FeatureStyle.Matcher.MatcherType.PropertyValue:
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
matcher.PropertyValue = EditorGUILayout.TextField("Property value:", matcher.PropertyValue);
break;

case FeatureStyle.Matcher.Type.PropertyRegex:
case FeatureStyle.Matcher.MatcherType.PropertyRegex:
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
matcher.RegexPattern = EditorGUILayout.TextField("Regex:", matcher.RegexPattern);
break;
Expand All @@ -113,7 +109,7 @@ public void OnInspectorGUI()
{
var editor = matcherEditors[i];

var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Matcher.MatcherType.ToString());
var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Matcher.Type.ToString());

if (state.show)
{
Expand Down
24 changes: 12 additions & 12 deletions Assets/Mapzen/Unity/FeatureStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PolylineBuilder.Options GetPolylineOptions(Feature feature, float inverse
[Serializable]
public class Matcher
{
public enum Type
public enum MatcherType
{
None,
AllOf,
Expand All @@ -81,7 +81,7 @@ public enum Type
}

[SerializeField]
private Type type;
private MatcherType type;

[SerializeField]
private List<Matcher> matchers;
Expand All @@ -96,7 +96,7 @@ public enum Type

public bool IsCompound()
{
return type == Type.AllOf || type == Type.NoneOf || type == Type.AnyOf;
return type == MatcherType.AllOf || type == MatcherType.NoneOf || type == MatcherType.AnyOf;
}

public List<Matcher> Matchers
Expand All @@ -123,13 +123,13 @@ public IFeatureMatcher GetFeatureMatcher()

switch (type)
{
case FeatureStyle.Matcher.Type.AllOf:
case MatcherType.AllOf:
matcher = FeatureMatcher.AllOf(predicates.ToArray());
break;
case FeatureStyle.Matcher.Type.NoneOf:
case FeatureStyle.Matcher.MatcherType.NoneOf:
matcher = FeatureMatcher.NoneOf(predicates.ToArray());
break;
case FeatureStyle.Matcher.Type.AnyOf:
case FeatureStyle.Matcher.MatcherType.AnyOf:
matcher = FeatureMatcher.AnyOf(predicates.ToArray());
break;
}
Expand All @@ -138,19 +138,19 @@ public IFeatureMatcher GetFeatureMatcher()
{
switch (type)
{
case FeatureStyle.Matcher.Type.PropertyRange:
case MatcherType.PropertyRange:
double? min = MinRangeEnabled ? (double)MinRange : (double?)null;
double? max = MaxRangeEnabled ? (double)MaxRange : (double?)null;

matcher = FeatureMatcher.HasPropertyInRange(HasProperty, min, max);
break;
case FeatureStyle.Matcher.Type.Property:
case MatcherType.Property:
matcher = FeatureMatcher.HasProperty(HasProperty);
break;
case FeatureStyle.Matcher.Type.PropertyValue:
case MatcherType.PropertyValue:
matcher = FeatureMatcher.HasPropertyWithValue(HasProperty, PropertyValue);
break;
case FeatureStyle.Matcher.Type.PropertyRegex:
case MatcherType.PropertyRegex:
try
{
matcher = FeatureMatcher.HasPropertyWithRegex(HasProperty, RegexPattern);
Expand All @@ -166,12 +166,12 @@ public IFeatureMatcher GetFeatureMatcher()
return matcher;
}

public Type MatcherType
public MatcherType Type
{
get { return type; }
}

public Matcher(Type type)
public Matcher(MatcherType type)
{
this.matchers = new List<Matcher>();
this.type = type;
Expand Down

0 comments on commit 0218da9

Please sign in to comment.