Skip to content

Commit

Permalink
Switch all public fields to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Sep 20, 2024
1 parent e38dec9 commit f0903a5
Show file tree
Hide file tree
Showing 31 changed files with 676 additions and 364 deletions.
73 changes: 0 additions & 73 deletions BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs

This file was deleted.

17 changes: 12 additions & 5 deletions BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ namespace BeatSaberMarkupLanguage.Animations
{
public class AnimationStateUpdater : MonoBehaviour
{
public Image Image;
[SerializeField]
private Image image;

private AnimationControllerData controllerData;

public Image Image
{
get => image;
set => image = value;
}

public AnimationControllerData ControllerData
{
get => controllerData;
Expand All @@ -32,19 +39,19 @@ protected void OnEnable()
{
if (ControllerData != null)
{
ControllerData.ActiveImages.Add(Image);
Image.sprite = ControllerData.Sprites[ControllerData.UvIndex];
ControllerData.ActiveImages.Add(image);
image.sprite = ControllerData.Sprites[ControllerData.UvIndex];
}
}

protected void OnDisable()
{
ControllerData?.ActiveImages.Remove(Image);
ControllerData?.ActiveImages.Remove(image);
}

protected void OnDestroy()
{
ControllerData?.ActiveImages.Remove(Image);
ControllerData?.ActiveImages.Remove(image);
}
}
}
39 changes: 23 additions & 16 deletions BeatSaberMarkupLanguage/Components/Backgroundable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ namespace BeatSaberMarkupLanguage.Components
{
public class Backgroundable : MonoBehaviour
{
private static readonly Dictionary<string, ImageView> BackgroundCache = new();

// TODO: this should be an ImageView
public Image Background;
[SerializeField]
private Image background;

private static readonly Dictionary<string, ImageView> BackgroundCache = new();
public Image Background
{
get => background;
set => background = value;
}

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

public void ApplyBackground(string name)
{
if (Background != null)
if (background != null)
{
throw new BSMLException("Cannot add multiple backgrounds");
}
Expand All @@ -64,8 +71,8 @@ public void ApplyBackground(string name)
BackgroundCache.Add(name, bgTemplate);
}

Background = gameObject.AddComponent(bgTemplate);
Background.enabled = true;
background = gameObject.AddComponent(bgTemplate);
background.enabled = true;
}
catch
{
Expand All @@ -75,15 +82,15 @@ public void ApplyBackground(string name)

public void ApplyColor(Color color)
{
if (Background == null)
if (background == null)
{
throw new BSMLException("Can't set color on null background!");
}

color.a = Background.color.a;
Background.color = color;
color.a = background.color.a;
background.color = color;

if (Background is ImageView imageView)
if (background is ImageView imageView)
{
Color color0 = new(1, 1, 1, imageView.color0.a);
Color color1 = new(1, 1, 1, imageView.color1.a);
Expand All @@ -96,12 +103,12 @@ public void ApplyColor(Color color)

public void ApplyGradient(Color color0, Color color1)
{
if (Background is not ImageView imageView)
if (background is not ImageView imageView)
{
throw new BSMLException("Can't set gradient on null background!");
}

Color color = new(1, 1, 1, Background.color.a);
Color color = new(1, 1, 1, background.color.a);

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

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

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

public void ApplyAlpha(float alpha)
{
if (Background == null)
if (background == null)
{
throw new BSMLException("Can't set gradient on null background!");
}

Color color = Background.color;
Color color = background.color;
color.a = alpha;
Background.color = color;
background.color = color;
}

private static ImageView FindTemplate(string name, string backgroundName)
Expand Down
17 changes: 12 additions & 5 deletions BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,28 @@ namespace BeatSaberMarkupLanguage.Components
{
public class ButtonArtworkImage : MonoBehaviour
{
public Image Image;
[SerializeField]
private Image image;

public Image Image
{
get => image;
set => image = value;
}

public void SetArtwork(string path)
{
if (Image == null)
if (image == null)
{
Image = GetComponentsInChildren<Image>().Where(x => x.name == "BGArtwork").FirstOrDefault();
image = GetComponentsInChildren<Image>().Where(x => x.name == "BGArtwork").FirstOrDefault();
}

if (Image == null)
if (image == null)
{
throw new BSMLException("Unable to find BG artwork image!");
}

Image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
}
}
}
46 changes: 34 additions & 12 deletions BeatSaberMarkupLanguage/Components/ButtonIconImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,46 @@ namespace BeatSaberMarkupLanguage.Components
{
public class ButtonIconImage : MonoBehaviour
{
public Image Image;
[SerializeField]
private Image image;

internal NoTransitionsButton Button;
internal GameObject Underline;
[SerializeField]
private NoTransitionsButton button;

[SerializeField]
private GameObject underline;

public Image Image
{
get => image;
set => image = value;
}

internal NoTransitionsButton Button
{
get => button;
set => button = value;
}

internal GameObject Underline
{
get => underline;
set => underline = value;
}

public void SetIcon(string path)
{
if (Image == null)
if (image == null)
{
return;
}

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

internal void SetSkew(float value)
{
if (Image is not ImageView imageView)
if (image is not ImageView imageView)
{
return;
}
Expand All @@ -35,27 +57,27 @@ internal void SetSkew(float value)

internal void SetUnderlineActive(bool active)
{
if (Underline != null)
if (underline != null)
{
Underline.SetActive(active);
underline.SetActive(active);
}
}

protected void OnEnable()
{
Button.selectionStateDidChangeEvent += OnSelectionStateDidChange;
button.selectionStateDidChangeEvent += OnSelectionStateDidChange;
}

protected void OnDisable()
{
Button.selectionStateDidChangeEvent -= OnSelectionStateDidChange;
button.selectionStateDidChangeEvent -= OnSelectionStateDidChange;
}

private void OnSelectionStateDidChange(NoTransitionsButton.SelectionState state)
{
Color color = Image.color;
Color color = image.color;
color.a = state is NoTransitionsButton.SelectionState.Disabled ? 0.25f : 1;
Image.color = color;
image.color = color;
}
}
}
Loading

0 comments on commit f0903a5

Please sign in to comment.