Skip to content

Commit 8c2cbc5

Browse files
committed
Adjust PauseAnimator fix and add 989onan as author
Extracts the private Float wrapper to an internal, generic Box wrapper
1 parent 6dc93f4 commit 8c2cbc5

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

CommunityBugFixCollection/Box.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace CommunityBugFixCollection
6+
{
7+
internal sealed class Box<T>
8+
where T : struct
9+
{
10+
public T Value { get; set; }
11+
12+
public Box(T value)
13+
{
14+
Value = value;
15+
}
16+
17+
public Box()
18+
{ }
19+
20+
public static implicit operator Box<T>(T value) => new(value);
21+
22+
public static implicit operator T(Box<T> box) => box.Value;
23+
}
24+
}

CommunityBugFixCollection/CommunityBugFixCollection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1111
<PackageId>CommunityBugFixCollection</PackageId>
1212
<Title>Community Bug-Fix Collection</Title>
13-
<Authors>Banane9; Nytra; art0007i; LeCloutPanda; goat; __Choco__; LJ</Authors>
13+
<Authors>Banane9; Nytra; art0007i; LeCloutPanda; goat; __Choco__; LJ; 989onan</Authors>
1414
<Version>0.6.0-beta</Version>
1515
<Description>This MonkeyLoader mod for Resonite that fixes various small Resonite-issues that are still open.</Description>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>

CommunityBugFixCollection/Contributors.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ internal static class Contributors
2020
public static string[] LJ { get; } = ["LJ"];
2121

2222
public static string[] Nytra { get; } = ["Nytra"];
23+
24+
public static string[] Onan { get; } = ["989onan"];
2325
}
2426
}

CommunityBugFixCollection/PauseAnimatorUpdates.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,9 @@ namespace CommunityBugFixCollection
1111
[HarmonyPatch(typeof(Animator), nameof(Animator.OnCommonUpdate))]
1212
internal sealed class PauseAnimatorUpdates : ResoniteBugFixMonkey<PauseAnimatorUpdates>
1313
{
14-
public override IEnumerable<string> Authors => Contributors.Banane9;
14+
private static readonly ConditionalWeakTable<Animator, Box<float>> _lastPositionByAnimator = new();
1515

16-
private class Float
17-
{
18-
public float Value;
19-
20-
public Float(float value)
21-
{
22-
Value = value;
23-
}
24-
25-
public Float()
26-
{
27-
Value = 0f;
28-
}
29-
}
30-
31-
32-
private static readonly ConditionalWeakTable<Animator, Float> _hasChangedPlayhead = new();
16+
public override IEnumerable<string> Authors { get; } = [.. Contributors.Banane9, .. Contributors.Onan];
3317

3418
private static bool Prefix(Animator __instance)
3519
{
@@ -41,11 +25,17 @@ private static bool Prefix(Animator __instance)
4125
if (!__instance._fieldMappersValid)
4226
__instance.GenerateFieldMappers();
4327

28+
if (!_lastPositionByAnimator.TryGetValue(__instance, out var lastPosition))
29+
{
30+
// Make sure that initial state is always applied,
31+
// since playback position can't be < 0
32+
lastPosition = -1;
33+
_lastPositionByAnimator.Add(__instance, lastPosition);
34+
}
4435

45-
if (_hasChangedPlayhead.GetOrCreateValue(__instance).Value != __instance._playback.Position)
36+
if (lastPosition != __instance.Position)
4637
{
47-
var position = __instance.Position;
48-
_hasChangedPlayhead.GetOrCreateValue(__instance).Value = __instance.Position;
38+
var position = lastPosition.Value = __instance.Position;
4939

5040
foreach (var fieldMapper in __instance._fieldMappers)
5141
fieldMapper.Set(position);
@@ -54,6 +44,4 @@ private static bool Prefix(Animator __instance)
5444
return false;
5545
}
5646
}
57-
58-
5947
}

0 commit comments

Comments
 (0)