Skip to content

Commit

Permalink
[Core] Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sauceke committed Apr 26, 2024
1 parent e54267d commit e4ff567
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/LoveMachine.Core/Controller/OscillatorController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Linq;
using LoveMachine.Core.Buttplug;
using LoveMachine.Core.Config;
Expand All @@ -16,34 +15,29 @@ internal sealed class OscillatorController: ClassicButtplugController

protected override IEnumerator HandleAnimation(Device device, StrokeInfo strokeInfo)
{
var settings = device.Settings.OscillatorSettings;
var feature = device.DeviceMessages.ScalarCmd
.First(cmd => cmd.ActuatorType == Buttplug.Buttplug.Feature.Oscillate);
int steps = feature.StepCount;
float durationSecs = strokeInfo.DurationSecs;
float rpm = Mathf.Min(60f / durationSecs, OscillatorConfig.RpmLimit.Value);
float level = Mathf.InverseLerp(settings.MinRpm, settings.MaxRpm, rpm);
float speed = Mathf.Lerp(1f / steps, 1f, level);
Client.OscillateCmd(device, speed);
yield return WaitForSecondsUnscaled(durationSecs);
OscillateWithRpm(device, 60f / strokeInfo.DurationSecs);
yield return WaitForSecondsUnscaled(strokeInfo.DurationSecs);
}

protected override IEnumerator HandleOrgasm(Device device)
{
OscillateWithRpm(device, OscillatorConfig.RpmLimit.Value);
yield break;
}

protected override void HandleLevel(Device device, float level, float durationSecs)
{}

private void OscillateWithRpm(Device device, float rpm)
{
rpm = Mathf.Min(rpm, OscillatorConfig.RpmLimit.Value);
var settings = device.Settings.OscillatorSettings;
var feature = device.DeviceMessages.ScalarCmd
.First(cmd => cmd.ActuatorType == Buttplug.Buttplug.Feature.Oscillate);
int steps = feature.StepCount;
float level = Mathf.InverseLerp(
settings.MinRpm,
settings.MaxRpm,
value: OscillatorConfig.RpmLimit.Value);
float speed = Mathf.Lerp(1f / steps, 1f, level);
float rate = Mathf.InverseLerp(settings.MinRpm, settings.MaxRpm, value: rpm);
float speed = Mathf.Lerp(1f / steps, 1f, t: rate);
Client.OscillateCmd(device, speed);
yield break;
}

protected override void HandleLevel(Device device, float level, float durationSecs)
{}
}
}

0 comments on commit e4ff567

Please sign in to comment.