Skip to content

Commit 7886e4c

Browse files
authored
Merge pull request #59 from neogeek/hotfix/move-common-methods
[hotfix] Moved common methods into separate file.
2 parents 91baa25 + 4893c80 commit 7886e4c

File tree

17 files changed

+321
-235
lines changed

17 files changed

+321
-235
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,22 @@ using RhythmGameUtilities;
215215
var value = Utilities.RoundUpToTheNearestMultiplier(12, 10);
216216
```
217217

218-
#### `Utilities.Lerp`
218+
### Common
219+
220+
#### `Common.Lerp`
219221

220222
```csharp
221223
using RhythmGameUtilities;
222224

223-
var value = Utilities.Lerp(0, 10, 0.5f);
225+
var value = Common.Lerp(0, 10, 0.5f);
224226
```
225227

226228
#### `Utilities.InverseLerp`
227229

228230
```csharp
229231
using RhythmGameUtilities;
230232

231-
var value = Utilities.InverseLerp(0, 10, 5);
233+
var value = Common.InverseLerp(0, 10, 5);
232234
```
233235

234236
## Architecture
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using NUnit.Framework;
2+
3+
namespace RhythmGameUtilities.Tests
4+
{
5+
6+
public class CommonTest
7+
{
8+
9+
[Test]
10+
public void TestLerp()
11+
{
12+
Assert.That(Common.Lerp(0, 10, 0), Is.EqualTo(0));
13+
Assert.That(Common.Lerp(0, 10, 0.5f), Is.EqualTo(5));
14+
Assert.That(Common.Lerp(0, 10, 1), Is.EqualTo(10));
15+
}
16+
17+
[Test]
18+
public void TestInverseLerp()
19+
{
20+
Assert.That(Common.InverseLerp(0, 10, 0), Is.EqualTo(0));
21+
Assert.That(Common.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
22+
Assert.That(Common.InverseLerp(0, 10, 10), Is.EqualTo(1));
23+
}
24+
25+
}
26+
27+
}

RhythmGameUtilities.Tests/UtilitiesTest.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using NUnit.Framework;
43

@@ -52,22 +51,6 @@ public void TestRoundUpToTheNearestMultiplier()
5251
Assert.That(Utilities.RoundUpToTheNearestMultiplier(12, 10), Is.EqualTo(20));
5352
}
5453

55-
[Test]
56-
public void TestLerp()
57-
{
58-
Assert.That(Utilities.Lerp(0, 10, 0), Is.EqualTo(0));
59-
Assert.That(Utilities.Lerp(0, 10, 0.5f), Is.EqualTo(5));
60-
Assert.That(Utilities.Lerp(0, 10, 1), Is.EqualTo(10));
61-
}
62-
63-
[Test]
64-
public void TestInverseLerp()
65-
{
66-
Assert.That(Utilities.InverseLerp(0, 10, 0), Is.EqualTo(0));
67-
Assert.That(Utilities.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
68-
Assert.That(Utilities.InverseLerp(0, 10, 10), Is.EqualTo(1));
69-
}
70-
7154
[Test]
7255
public void TestCalculateBeatBars()
7356
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace RhythmGameUtilities
4+
{
5+
6+
public static class CommonInternal
7+
{
8+
9+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
10+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
11+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
12+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
13+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
14+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
15+
#endif
16+
public static extern float Lerp(float a, float b, float t);
17+
18+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
19+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
20+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
21+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
22+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
23+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
24+
#endif
25+
public static extern float InverseLerp(float a, float b, float v);
26+
27+
}
28+
29+
public static class Common
30+
{
31+
32+
public static float Lerp(float a, float b, float t)
33+
{
34+
return CommonInternal.Lerp(a, b, t);
35+
}
36+
37+
public static float InverseLerp(float a, float b, float v)
38+
{
39+
return CommonInternal.InverseLerp(a, b, v);
40+
}
41+
42+
}
43+
44+
}

RhythmGameUtilities/Scripts/Utilities.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu
4646
#endif
4747
public static extern int RoundUpToTheNearestMultiplier(int value, int multiplier);
4848

49-
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
50-
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
51-
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
52-
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
53-
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
54-
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
55-
#endif
56-
public static extern float Lerp(float a, float b, float t);
57-
58-
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
59-
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
60-
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
61-
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
62-
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
63-
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
64-
#endif
65-
public static extern float InverseLerp(float a, float b, float v);
66-
6749
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
6850
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
6951
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
@@ -103,16 +85,6 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
10385
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
10486
}
10587

106-
public static float Lerp(float a, float b, float t)
107-
{
108-
return UtilitiesInternal.Lerp(a, b, t);
109-
}
110-
111-
public static float InverseLerp(float a, float b, float v)
112-
{
113-
return UtilitiesInternal.InverseLerp(a, b, v);
114-
}
115-
11688
public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
11789
bool includeHalfNotes = true)
11890
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using NUnit.Framework;
2+
3+
namespace RhythmGameUtilities.Tests
4+
{
5+
6+
public class CommonTest
7+
{
8+
9+
[Test]
10+
public void TestLerp()
11+
{
12+
Assert.That(Common.Lerp(0, 10, 0), Is.EqualTo(0));
13+
Assert.That(Common.Lerp(0, 10, 0.5f), Is.EqualTo(5));
14+
Assert.That(Common.Lerp(0, 10, 1), Is.EqualTo(10));
15+
}
16+
17+
[Test]
18+
public void TestInverseLerp()
19+
{
20+
Assert.That(Common.InverseLerp(0, 10, 0), Is.EqualTo(0));
21+
Assert.That(Common.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
22+
Assert.That(Common.InverseLerp(0, 10, 10), Is.EqualTo(1));
23+
}
24+
25+
}
26+
27+
}

UnityPackage/Editor/Tests/CommonTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityPackage/Editor/Tests/UtilitiesTest.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using NUnit.Framework;
43

@@ -52,22 +51,6 @@ public void TestRoundUpToTheNearestMultiplier()
5251
Assert.That(Utilities.RoundUpToTheNearestMultiplier(12, 10), Is.EqualTo(20));
5352
}
5453

55-
[Test]
56-
public void TestLerp()
57-
{
58-
Assert.That(Utilities.Lerp(0, 10, 0), Is.EqualTo(0));
59-
Assert.That(Utilities.Lerp(0, 10, 0.5f), Is.EqualTo(5));
60-
Assert.That(Utilities.Lerp(0, 10, 1), Is.EqualTo(10));
61-
}
62-
63-
[Test]
64-
public void TestInverseLerp()
65-
{
66-
Assert.That(Utilities.InverseLerp(0, 10, 0), Is.EqualTo(0));
67-
Assert.That(Utilities.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
68-
Assert.That(Utilities.InverseLerp(0, 10, 10), Is.EqualTo(1));
69-
}
70-
7154
[Test]
7255
public void TestCalculateBeatBars()
7356
{

UnityPackage/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,22 @@ using RhythmGameUtilities;
215215
var value = Utilities.RoundUpToTheNearestMultiplier(12, 10);
216216
```
217217

218-
#### `Utilities.Lerp`
218+
### Common
219+
220+
#### `Common.Lerp`
219221

220222
```csharp
221223
using RhythmGameUtilities;
222224

223-
var value = Utilities.Lerp(0, 10, 0.5f);
225+
var value = Common.Lerp(0, 10, 0.5f);
224226
```
225227

226228
#### `Utilities.InverseLerp`
227229

228230
```csharp
229231
using RhythmGameUtilities;
230232

231-
var value = Utilities.InverseLerp(0, 10, 5);
233+
var value = Common.InverseLerp(0, 10, 5);
232234
```
233235

234236
## Architecture

UnityPackage/Scripts/Common.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace RhythmGameUtilities
4+
{
5+
6+
public static class CommonInternal
7+
{
8+
9+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
10+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
11+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
12+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
13+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
14+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
15+
#endif
16+
public static extern float Lerp(float a, float b, float t);
17+
18+
#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
19+
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
20+
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
21+
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
22+
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
23+
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
24+
#endif
25+
public static extern float InverseLerp(float a, float b, float v);
26+
27+
}
28+
29+
public static class Common
30+
{
31+
32+
public static float Lerp(float a, float b, float t)
33+
{
34+
return CommonInternal.Lerp(a, b, t);
35+
}
36+
37+
public static float InverseLerp(float a, float b, float v)
38+
{
39+
return CommonInternal.InverseLerp(a, b, v);
40+
}
41+
42+
}
43+
44+
}

0 commit comments

Comments
 (0)