From 8a8c01376bafff9797bfbd628f28f91f47092dff Mon Sep 17 00:00:00 2001 From: Chris Yarbrough Date: Sun, 11 Feb 2024 11:32:05 +0100 Subject: [PATCH] Cleanup code warnings in Rider and SonarLint --- SharpShuffleBag.Tests/FixedSequenceSourceTests.cs | 2 +- .../Assets/Editor/SampleDevelopment.cs | 4 ++-- .../Core/IRandomRangeSource.cs | 2 ++ .../Core/IRandomValueSource.cs | 2 ++ .../Core/ShuffleBag.cs | 4 +++- .../Core/ShuffleBagInt.cs | 2 ++ .../com.chrisyarbrough.sharpshufflebag/README.md | 1 + .../Samples~/Example/RandomSpawner.cs | 10 +++++++--- .../Unity/DefaultRandomSourceInitializer.cs | 2 +- SharpShuffleBag/IRandomRangeSource.cs | 2 ++ SharpShuffleBag/IRandomValueSource.cs | 2 ++ SharpShuffleBag/ShuffleBag.cs | 4 +++- SharpShuffleBag/ShuffleBagInt.cs | 2 ++ 13 files changed, 30 insertions(+), 9 deletions(-) diff --git a/SharpShuffleBag.Tests/FixedSequenceSourceTests.cs b/SharpShuffleBag.Tests/FixedSequenceSourceTests.cs index 9f0de48..680ad90 100644 --- a/SharpShuffleBag.Tests/FixedSequenceSourceTests.cs +++ b/SharpShuffleBag.Tests/FixedSequenceSourceTests.cs @@ -1,6 +1,6 @@ namespace SharpShuffleBag.Tests; -public class FixedSequenceSourceTests +public sealed class FixedSequenceSourceTests { [Fact] public void SmokeTest() diff --git a/SharpShuffleBag.Unity/Assets/Editor/SampleDevelopment.cs b/SharpShuffleBag.Unity/Assets/Editor/SampleDevelopment.cs index 43e3215..434d2ae 100644 --- a/SharpShuffleBag.Unity/Assets/Editor/SampleDevelopment.cs +++ b/SharpShuffleBag.Unity/Assets/Editor/SampleDevelopment.cs @@ -22,8 +22,8 @@ public static void CopySamplesToPackage() { foreach (DirectoryInfo source in versionDirectory.EnumerateDirectories()) { - // Packages/com.xarbrough.sharp-shuffle-bag-unity/Samples~/Example1 - // Packages/com.xarbrough.sharp-shuffle-bag-unity/Samples~/Example2 + // Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example1 + // Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example2 string dest = "Packages/com.chrisyarbrough.sharpshufflebag/Samples~/" + source.Name; CopyDirectory(source, dest); } diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomRangeSource.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomRangeSource.cs index 266a9bf..ed8d4ce 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomRangeSource.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomRangeSource.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { using System; diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomValueSource.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomValueSource.cs index bada0ca..43292ba 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomValueSource.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/IRandomValueSource.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { /// diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBag.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBag.cs index 5a05403..9873f58 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBag.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBag.cs @@ -1,4 +1,6 @@ -namespace SharpShuffleBag +// ReSharper disable UnusedMember.Global + +namespace SharpShuffleBag { using System; using System.Collections; diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBagInt.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBagInt.cs index 317297f..facb181 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBagInt.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Core/ShuffleBagInt.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { using System.Collections.Generic; diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/README.md b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/README.md index 8dc66ab..2de2750 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/README.md +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/README.md @@ -57,3 +57,4 @@ and therefore avoids the larger performance spike of reshuffling/refilling the b - Efficient implementation: The underlying collection is not resized, instead, an index is used to perform the random selection. - Set a custom `RandomSource` for fine-grained control (e.g. to make the bag deterministic or set a seed). +- `Shuffle.FisherYates(IList list)` utility method to shuffle a list in-place. diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example/RandomSpawner.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example/RandomSpawner.cs index 22e3cd4..6314f1c 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example/RandomSpawner.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Samples~/Example/RandomSpawner.cs @@ -21,19 +21,23 @@ internal sealed class RandomSpawner : MonoBehaviour [SerializeField] private float spawnInterval = 0.5f; - private ShuffleBag shuffleBag; - private IEnumerator Start() { Application.targetFrameRate = 60; - shuffleBag = new ShuffleBag(SpawnTexts()); + ShuffleBag shuffleBag = new(SpawnTexts()); + int i = 0; while (Application.isPlaying) { yield return new WaitForSeconds(spawnInterval); + FadingTextMesh text = shuffleBag.Next(); text.StartFade(); + + if (i++ % shuffleBag.Size == 0) + Debug.Log("----"); + Debug.Log(text.Text); } } diff --git a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Unity/DefaultRandomSourceInitializer.cs b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Unity/DefaultRandomSourceInitializer.cs index e91d305..26871a2 100644 --- a/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Unity/DefaultRandomSourceInitializer.cs +++ b/SharpShuffleBag.Unity/Packages/com.chrisyarbrough.sharpshufflebag/Unity/DefaultRandomSourceInitializer.cs @@ -10,7 +10,7 @@ internal static class DefaultRandomSourceInitializer [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] private static void Initialize() { - if (IRandomRangeSource.Default.GetType() != typeof(UnityRandomSource)) + if (IRandomRangeSource.Default is UnityRandomSource) { IRandomRangeSource.Default = new UnityRandomSource(); } diff --git a/SharpShuffleBag/IRandomRangeSource.cs b/SharpShuffleBag/IRandomRangeSource.cs index 266a9bf..ed8d4ce 100644 --- a/SharpShuffleBag/IRandomRangeSource.cs +++ b/SharpShuffleBag/IRandomRangeSource.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { using System; diff --git a/SharpShuffleBag/IRandomValueSource.cs b/SharpShuffleBag/IRandomValueSource.cs index bada0ca..43292ba 100644 --- a/SharpShuffleBag/IRandomValueSource.cs +++ b/SharpShuffleBag/IRandomValueSource.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { /// diff --git a/SharpShuffleBag/ShuffleBag.cs b/SharpShuffleBag/ShuffleBag.cs index 5a05403..9873f58 100644 --- a/SharpShuffleBag/ShuffleBag.cs +++ b/SharpShuffleBag/ShuffleBag.cs @@ -1,4 +1,6 @@ -namespace SharpShuffleBag +// ReSharper disable UnusedMember.Global + +namespace SharpShuffleBag { using System; using System.Collections; diff --git a/SharpShuffleBag/ShuffleBagInt.cs b/SharpShuffleBag/ShuffleBagInt.cs index 317297f..facb181 100644 --- a/SharpShuffleBag/ShuffleBagInt.cs +++ b/SharpShuffleBag/ShuffleBagInt.cs @@ -1,3 +1,5 @@ +// ReSharper disable UnusedMember.Global + namespace SharpShuffleBag { using System.Collections.Generic;