Skip to content

Commit f0903a5

Browse files
committed
Switch all public fields to properties
1 parent e38dec9 commit f0903a5

31 files changed

+676
-364
lines changed

BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.

BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ namespace BeatSaberMarkupLanguage.Animations
55
{
66
public class AnimationStateUpdater : MonoBehaviour
77
{
8-
public Image Image;
8+
[SerializeField]
9+
private Image image;
910

1011
private AnimationControllerData controllerData;
1112

13+
public Image Image
14+
{
15+
get => image;
16+
set => image = value;
17+
}
18+
1219
public AnimationControllerData ControllerData
1320
{
1421
get => controllerData;
@@ -32,19 +39,19 @@ protected void OnEnable()
3239
{
3340
if (ControllerData != null)
3441
{
35-
ControllerData.ActiveImages.Add(Image);
36-
Image.sprite = ControllerData.Sprites[ControllerData.UvIndex];
42+
ControllerData.ActiveImages.Add(image);
43+
image.sprite = ControllerData.Sprites[ControllerData.UvIndex];
3744
}
3845
}
3946

4047
protected void OnDisable()
4148
{
42-
ControllerData?.ActiveImages.Remove(Image);
49+
ControllerData?.ActiveImages.Remove(image);
4350
}
4451

4552
protected void OnDestroy()
4653
{
47-
ControllerData?.ActiveImages.Remove(Image);
54+
ControllerData?.ActiveImages.Remove(image);
4855
}
4956
}
5057
}

BeatSaberMarkupLanguage/Components/Backgroundable.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ namespace BeatSaberMarkupLanguage.Components
77
{
88
public class Backgroundable : MonoBehaviour
99
{
10+
private static readonly Dictionary<string, ImageView> BackgroundCache = new();
11+
1012
// TODO: this should be an ImageView
11-
public Image Background;
13+
[SerializeField]
14+
private Image background;
1215

13-
private static readonly Dictionary<string, ImageView> BackgroundCache = new();
16+
public Image Background
17+
{
18+
get => background;
19+
set => background = value;
20+
}
1421

1522
private static Dictionary<string, string> Backgrounds => new()
1623
{
@@ -41,7 +48,7 @@ public class Backgroundable : MonoBehaviour
4148

4249
public void ApplyBackground(string name)
4350
{
44-
if (Background != null)
51+
if (background != null)
4552
{
4653
throw new BSMLException("Cannot add multiple backgrounds");
4754
}
@@ -64,8 +71,8 @@ public void ApplyBackground(string name)
6471
BackgroundCache.Add(name, bgTemplate);
6572
}
6673

67-
Background = gameObject.AddComponent(bgTemplate);
68-
Background.enabled = true;
74+
background = gameObject.AddComponent(bgTemplate);
75+
background.enabled = true;
6976
}
7077
catch
7178
{
@@ -75,15 +82,15 @@ public void ApplyBackground(string name)
7582

7683
public void ApplyColor(Color color)
7784
{
78-
if (Background == null)
85+
if (background == null)
7986
{
8087
throw new BSMLException("Can't set color on null background!");
8188
}
8289

83-
color.a = Background.color.a;
84-
Background.color = color;
90+
color.a = background.color.a;
91+
background.color = color;
8592

86-
if (Background is ImageView imageView)
93+
if (background is ImageView imageView)
8794
{
8895
Color color0 = new(1, 1, 1, imageView.color0.a);
8996
Color color1 = new(1, 1, 1, imageView.color1.a);
@@ -96,12 +103,12 @@ public void ApplyColor(Color color)
96103

97104
public void ApplyGradient(Color color0, Color color1)
98105
{
99-
if (Background is not ImageView imageView)
106+
if (background is not ImageView imageView)
100107
{
101108
throw new BSMLException("Can't set gradient on null background!");
102109
}
103110

104-
Color color = new(1, 1, 1, Background.color.a);
111+
Color color = new(1, 1, 1, background.color.a);
105112

106113
imageView.gradient = true;
107114
imageView.color = color;
@@ -111,7 +118,7 @@ public void ApplyGradient(Color color0, Color color1)
111118

112119
public void ApplyColor0(Color color0)
113120
{
114-
if (Background is not ImageView imageView)
121+
if (background is not ImageView imageView)
115122
{
116123
throw new BSMLException("Can't set gradient on null background!");
117124
}
@@ -121,7 +128,7 @@ public void ApplyColor0(Color color0)
121128

122129
public void ApplyColor1(Color color1)
123130
{
124-
if (Background is not ImageView imageView)
131+
if (background is not ImageView imageView)
125132
{
126133
throw new BSMLException("Can't set gradient on null background!");
127134
}
@@ -131,14 +138,14 @@ public void ApplyColor1(Color color1)
131138

132139
public void ApplyAlpha(float alpha)
133140
{
134-
if (Background == null)
141+
if (background == null)
135142
{
136143
throw new BSMLException("Can't set gradient on null background!");
137144
}
138145

139-
Color color = Background.color;
146+
Color color = background.color;
140147
color.a = alpha;
141-
Background.color = color;
148+
background.color = color;
142149
}
143150

144151
private static ImageView FindTemplate(string name, string backgroundName)

BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ namespace BeatSaberMarkupLanguage.Components
77
{
88
public class ButtonArtworkImage : MonoBehaviour
99
{
10-
public Image Image;
10+
[SerializeField]
11+
private Image image;
12+
13+
public Image Image
14+
{
15+
get => image;
16+
set => image = value;
17+
}
1118

1219
public void SetArtwork(string path)
1320
{
14-
if (Image == null)
21+
if (image == null)
1522
{
16-
Image = GetComponentsInChildren<Image>().Where(x => x.name == "BGArtwork").FirstOrDefault();
23+
image = GetComponentsInChildren<Image>().Where(x => x.name == "BGArtwork").FirstOrDefault();
1724
}
1825

19-
if (Image == null)
26+
if (image == null)
2027
{
2128
throw new BSMLException("Unable to find BG artwork image!");
2229
}
2330

24-
Image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
31+
image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
2532
}
2633
}
2734
}

BeatSaberMarkupLanguage/Components/ButtonIconImage.cs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,46 @@ namespace BeatSaberMarkupLanguage.Components
77
{
88
public class ButtonIconImage : MonoBehaviour
99
{
10-
public Image Image;
10+
[SerializeField]
11+
private Image image;
1112

12-
internal NoTransitionsButton Button;
13-
internal GameObject Underline;
13+
[SerializeField]
14+
private NoTransitionsButton button;
15+
16+
[SerializeField]
17+
private GameObject underline;
18+
19+
public Image Image
20+
{
21+
get => image;
22+
set => image = value;
23+
}
24+
25+
internal NoTransitionsButton Button
26+
{
27+
get => button;
28+
set => button = value;
29+
}
30+
31+
internal GameObject Underline
32+
{
33+
get => underline;
34+
set => underline = value;
35+
}
1436

1537
public void SetIcon(string path)
1638
{
17-
if (Image == null)
39+
if (image == null)
1840
{
1941
return;
2042
}
2143

22-
Image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
44+
image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
2345
}
2446

2547
internal void SetSkew(float value)
2648
{
27-
if (Image is not ImageView imageView)
49+
if (image is not ImageView imageView)
2850
{
2951
return;
3052
}
@@ -35,27 +57,27 @@ internal void SetSkew(float value)
3557

3658
internal void SetUnderlineActive(bool active)
3759
{
38-
if (Underline != null)
60+
if (underline != null)
3961
{
40-
Underline.SetActive(active);
62+
underline.SetActive(active);
4163
}
4264
}
4365

4466
protected void OnEnable()
4567
{
46-
Button.selectionStateDidChangeEvent += OnSelectionStateDidChange;
68+
button.selectionStateDidChangeEvent += OnSelectionStateDidChange;
4769
}
4870

4971
protected void OnDisable()
5072
{
51-
Button.selectionStateDidChangeEvent -= OnSelectionStateDidChange;
73+
button.selectionStateDidChangeEvent -= OnSelectionStateDidChange;
5274
}
5375

5476
private void OnSelectionStateDidChange(NoTransitionsButton.SelectionState state)
5577
{
56-
Color color = Image.color;
78+
Color color = image.color;
5779
color.a = state is NoTransitionsButton.SelectionState.Disabled ? 0.25f : 1;
58-
Image.color = color;
80+
image.color = color;
5981
}
6082
}
6183
}

0 commit comments

Comments
 (0)