mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
refactor: simplify movement logic and remove redundancy
This commit is contained in:
@@ -301,7 +301,6 @@ namespace Spectrum
|
|||||||
{
|
{
|
||||||
Linear,
|
Linear,
|
||||||
CubicBezier,
|
CubicBezier,
|
||||||
QuadraticBezier,
|
|
||||||
Adaptive,
|
Adaptive,
|
||||||
PerlinNoise,
|
PerlinNoise,
|
||||||
WindMouse
|
WindMouse
|
||||||
|
|||||||
@@ -68,22 +68,7 @@ namespace Spectrum.Input
|
|||||||
|
|
||||||
bool insideBoundingBox = lastDetectionBox.Contains(start);
|
bool insideBoundingBox = lastDetectionBox.Contains(start);
|
||||||
|
|
||||||
Point newPosition = config.AimMovementType switch
|
Point newPosition = CalculateMovement(start, end, effSensitivity, config.AimMovementType, insideBoundingBox);
|
||||||
{
|
|
||||||
MovementType.CubicBezier => MovementPaths.CubicBezierCurvedMovement(start, end, effSensitivity),
|
|
||||||
MovementType.Linear => MovementPaths.LinearInterpolation(start, end, effSensitivity),
|
|
||||||
MovementType.Adaptive => MovementPaths.AdaptiveMovement(start, end, effSensitivity),
|
|
||||||
MovementType.QuadraticBezier => MovementPaths.CurvedMovement(start, end, effSensitivity),
|
|
||||||
MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(start, end, effSensitivity),
|
|
||||||
MovementType.WindMouse => MovementPaths.WindMouse(start, end,
|
|
||||||
config.WindMouseGravity,
|
|
||||||
config.WindMouseWind,
|
|
||||||
config.WindMouseMaxStep,
|
|
||||||
effSensitivity,
|
|
||||||
config.WindMouseOvershoot,
|
|
||||||
insideBoundingBox),
|
|
||||||
_ => MovementPaths.LinearInterpolation(start, end, effSensitivity),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (config.EmaSmoothening)
|
if (config.EmaSmoothening)
|
||||||
{
|
{
|
||||||
@@ -119,6 +104,25 @@ namespace Spectrum.Input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Point CalculateMovement(Point start, Point end, double sensitivity, MovementType movementType, bool insideBoundingBox)
|
||||||
|
{
|
||||||
|
return movementType switch
|
||||||
|
{
|
||||||
|
MovementType.CubicBezier => MovementPaths.CubicBezierCurvedMovement(start, end, sensitivity),
|
||||||
|
MovementType.Linear => MovementPaths.LinearInterpolation(start, end, sensitivity),
|
||||||
|
MovementType.Adaptive => MovementPaths.AdaptiveMovement(start, end, sensitivity),
|
||||||
|
MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(start, end, sensitivity),
|
||||||
|
MovementType.WindMouse => MovementPaths.WindMouse(start, end,
|
||||||
|
mainConfig.Data.WindMouseGravity,
|
||||||
|
mainConfig.Data.WindMouseWind,
|
||||||
|
mainConfig.Data.WindMouseMaxStep,
|
||||||
|
sensitivity,
|
||||||
|
mainConfig.Data.WindMouseOvershoot,
|
||||||
|
insideBoundingBox),
|
||||||
|
_ => MovementPaths.LinearInterpolation(start, end, sensitivity),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task ClickMouse()
|
public static async Task ClickMouse()
|
||||||
{
|
{
|
||||||
var config = mainConfig.Data;
|
var config = mainConfig.Data;
|
||||||
|
|||||||
@@ -86,23 +86,6 @@
|
|||||||
return new Point(x, y);
|
return new Point(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Point CurvedMovement(Point start, Point end, double t)
|
|
||||||
{
|
|
||||||
t = Clamp01(t);
|
|
||||||
Point control = new Point((start.X + end.X) / 2, (start.Y + end.Y) / 2 - 200);
|
|
||||||
return QuadraticBezier(start, end, control, t);
|
|
||||||
}
|
|
||||||
public static Point QuadraticBezier(Point start, Point end, Point control, double t)
|
|
||||||
{
|
|
||||||
t = Clamp01(t);
|
|
||||||
double u = 1 - t;
|
|
||||||
double tt = t * t;
|
|
||||||
double uu = u * u;
|
|
||||||
double x = uu * start.X + 2 * u * t * control.X + tt * end.X;
|
|
||||||
double y = uu * start.Y + 2 * u * t * control.Y + tt * end.Y;
|
|
||||||
return new Point((int)Math.Round(x), (int)Math.Round(y));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Point AdaptiveMovement(Point start, Point end, double sensitivity)
|
public static Point AdaptiveMovement(Point start, Point end, double sensitivity)
|
||||||
{
|
{
|
||||||
double dx = end.X - start.X;
|
double dx = end.X - start.X;
|
||||||
|
|||||||
@@ -60,22 +60,7 @@ namespace Spectrum
|
|||||||
if (steps++ >= maxSteps)
|
if (steps++ >= maxSteps)
|
||||||
break;
|
break;
|
||||||
bool isInBox = boundingBox.Contains(current);
|
bool isInBox = boundingBox.Contains(current);
|
||||||
Point nextPoint = config.AimMovementType switch
|
Point nextPoint = InputManager.CalculateMovement(current, _previewEndPoint, config.Sensitivity, config.AimMovementType, isInBox);
|
||||||
{
|
|
||||||
MovementType.Linear => MovementPaths.LinearInterpolation(current, _previewEndPoint, progress),
|
|
||||||
MovementType.CubicBezier => MovementPaths.CubicBezierCurvedMovement(current, _previewEndPoint, progress),
|
|
||||||
MovementType.Adaptive => MovementPaths.AdaptiveMovement(current, _previewEndPoint, progress),
|
|
||||||
MovementType.QuadraticBezier => MovementPaths.CurvedMovement(current, _previewEndPoint, progress),
|
|
||||||
MovementType.PerlinNoise => MovementPaths.PerlinNoiseMovement(current, _previewEndPoint, progress),
|
|
||||||
MovementType.WindMouse => MovementPaths.WindMouse(current, _previewEndPoint,
|
|
||||||
config.WindMouseGravity,
|
|
||||||
config.WindMouseWind,
|
|
||||||
config.WindMouseMaxStep,
|
|
||||||
config.Sensitivity,
|
|
||||||
config.WindMouseOvershoot,
|
|
||||||
isInBox),
|
|
||||||
_ => MovementPaths.LinearInterpolation(current, _previewEndPoint, progress),
|
|
||||||
};
|
|
||||||
if (config.EmaSmoothening)
|
if (config.EmaSmoothening)
|
||||||
nextPoint = MovementPaths.EmaSmoothing(current, nextPoint, config.EmaSmootheningFactor);
|
nextPoint = MovementPaths.EmaSmoothing(current, nextPoint, config.EmaSmootheningFactor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user