Skip to content

Commit

Permalink
Fix intensity float and force unmute
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed May 5, 2024
1 parent 5d3c2cb commit 864ac73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions ShockOsc/Services/OscHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using OpenShock.ShockOsc.Config;
using OpenShock.ShockOsc.OscChangeTracker;
using OpenShock.ShockOsc.Utils;
Expand Down Expand Up @@ -63,7 +63,7 @@ await Task.Delay(50)
await _oscClient.SendGameMessage("/input/Voice", false)
.ConfigureAwait(false);
}

/// <summary>
/// Send parameter updates to osc
/// </summary>
Expand All @@ -84,8 +84,8 @@ public async Task SendParams()
if (!isActiveOrOnCooldown && shocker.LastIntensity > 0)
shocker.LastIntensity = 0;

var intensity = MathUtils.ClampFloat(shocker.LastIntensity / 100f);
var onCoolDown = !isActive && isActiveOrOnCooldown;

var cooldownPercentage = 0f;
if (onCoolDown)
cooldownPercentage = MathUtils.ClampFloat(1 -
Expand All @@ -97,12 +97,12 @@ public async Task SendParams()
await shocker.ParamActive.SetValue(isActive);
await shocker.ParamCooldown.SetValue(onCoolDown);
await shocker.ParamCooldownPercentage.SetValue(cooldownPercentage);
await shocker.ParamIntensity.SetValue(MathUtils.ClampFloat(shocker.LastIntensity));
await shocker.ParamIntensity.SetValue(intensity);

if (isActive) anyActive = true;
if (onCoolDown) anyCooldown = true;
anyCooldownPercentage = Math.Max(anyCooldownPercentage, cooldownPercentage);
anyIntensity = Math.Max(anyIntensity, MathUtils.ClampFloat(shocker.LastIntensity));
anyCooldownPercentage = MathF.Max(anyCooldownPercentage, cooldownPercentage);
anyIntensity = MathF.Max(anyIntensity, intensity);
}

await _paramAnyActive.SetValue(anyActive);
Expand Down
7 changes: 3 additions & 4 deletions ShockOsc/Services/ShockOsc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public sealed class ShockOsc

private bool _oscServerActive;
private bool _isAfk;
private bool _isMuted;
public string AvatarId = string.Empty;
private readonly Random Random = new();

Expand Down Expand Up @@ -244,8 +243,8 @@ private async Task ReceiveLogic()
_logger.LogDebug("Afk: {State}", _isAfk);
return;
case "/avatar/parameters/MuteSelf":
_isMuted = received.Arguments.ElementAtOrDefault(0) is true;
_logger.LogDebug("Muted: {State}", _isMuted);
_dataLayer.IsMuted = received.Arguments.ElementAtOrDefault(0) is true;
_logger.LogDebug("Muted: {State}", _dataLayer.IsMuted);
return;
}

Expand Down Expand Up @@ -400,7 +399,7 @@ private async Task InstantShock(ProgramGroup programGroup, uint duration, byte i
{
programGroup.LastExecuted = DateTime.UtcNow;
programGroup.LastDuration = duration;
var intensityPercentage = Math.Round(MathUtils.ClampFloat(intensity) * 100f);
var intensityPercentage = MathF.Round(MathUtils.ClampFloat(intensity) * 100f);
programGroup.LastIntensity = intensity;

_oscHandler.ForceUnmute();
Expand Down

0 comments on commit 864ac73

Please sign in to comment.