Update CloseTo to CloseToPercent (#4708)

This commit is contained in:
metalgearsloth
2021-09-29 20:07:01 +10:00
committed by GitHub
parent fe4a415d3b
commit ad783396f8
18 changed files with 31 additions and 31 deletions

View File

@@ -101,7 +101,7 @@ namespace Content.Client.Chat.UI
} }
// Lerp to our new vertical offset if it's been modified. // Lerp to our new vertical offset if it's been modified.
if (MathHelper.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1)) if (MathHelper.CloseToPercent(_verticalOffsetAchieved - VerticalOffset, 0, 0.1))
{ {
_verticalOffsetAchieved = VerticalOffset; _verticalOffsetAchieved = VerticalOffset;
} }

View File

@@ -140,7 +140,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen; var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality(); var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
var isHudThemeSame = HudThemeOption.SelectedId == _cfg.GetCVar(CCVars.HudTheme); var isHudThemeSame = HudThemeOption.SelectedId == _cfg.GetCVar(CCVars.HudTheme);
var isUIScaleSame = MathHelper.CloseTo(UIScaleOptions[UIScaleOption.SelectedId], ConfigUIScale); var isUIScaleSame = MathHelper.CloseToPercent(UIScaleOptions[UIScaleOption.SelectedId], ConfigUIScale);
var isVPStretchSame = ViewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch); var isVPStretchSame = ViewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch);
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor); var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0); var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
@@ -215,7 +215,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
{ {
for (var i = 0; i < UIScaleOptions.Length; i++) for (var i = 0; i < UIScaleOptions.Length; i++)
{ {
if (MathHelper.CloseTo(UIScaleOptions[i], value)) if (MathHelper.CloseToPercent(UIScaleOptions[i], value))
{ {
return i; return i;
} }

View File

@@ -263,7 +263,7 @@ namespace Content.Client.Tabletop
var max = (eyePosition + size / 2) / eyeScale; var max = (eyePosition + size / 2) / eyeScale;
// If 90/270 degrees rotated, flip X and Y // If 90/270 degrees rotated, flip X and Y
if (MathHelper.CloseTo(eyeRotation.Degrees % 180d, 90d) || MathHelper.CloseTo(eyeRotation.Degrees % 180d, -90d)) if (MathHelper.CloseToPercent(eyeRotation.Degrees % 180d, 90d) || MathHelper.CloseToPercent(eyeRotation.Degrees % 180d, -90d))
{ {
(min.Y, min.X) = (min.X, min.Y); (min.Y, min.X) = (min.X, min.Y);
(max.Y, max.X) = (max.X, max.Y); (max.Y, max.X) = (max.X, max.Y);

View File

@@ -37,7 +37,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
var outputStartingPressure = outlet.Air.Pressure; var outputStartingPressure = outlet.Air.Pressure;
if (MathHelper.CloseTo(pump.TargetPressure, outputStartingPressure)) if (MathHelper.CloseToPercent(pump.TargetPressure, outputStartingPressure))
{ {
appearance?.SetData(PressurePumpVisuals.Enabled, false); appearance?.SetData(PressurePumpVisuals.Enabled, false);
return; // No need to pump gas if target has been reached. return; // No need to pump gas if target has been reached.

View File

@@ -186,7 +186,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
DirtyUI(uid, canister, nodeContainer, containerManager); DirtyUI(uid, canister, nodeContainer, containerManager);
// If last pressure is very close to the current pressure, do nothing. // If last pressure is very close to the current pressure, do nothing.
if (MathHelper.CloseTo(canister.Air.Pressure, canister.LastPressure)) if (MathHelper.CloseToPercent(canister.Air.Pressure, canister.LastPressure))
return; return;
canister.LastPressure = canister.Air.Pressure; canister.LastPressure = canister.Air.Pressure;

View File

@@ -85,7 +85,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
var removed = tile.Remove(transferMoles); var removed = tile.Remove(transferMoles);
// Nothing left to remove from the tile. // Nothing left to remove from the tile.
if (MathHelper.CloseTo(removed.TotalMoles, 0f)) if (MathHelper.CloseToPercent(removed.TotalMoles, 0f))
return; return;
atmosphereSystem.ScrubInto(removed, outlet.Air, scrubber.FilterGases); atmosphereSystem.ScrubInto(removed, outlet.Air, scrubber.FilterGases);

View File

@@ -178,7 +178,7 @@ namespace Content.Server.Doors.Components
var timingStatus = var timingStatus =
new StatusLightData(Color.Orange, !AutoClose ? StatusLightState.Off : new StatusLightData(Color.Orange, !AutoClose ? StatusLightState.Off :
!MathHelper.CloseTo(ev.CloseTimeModifier, 1.0f) ? StatusLightState.BlinkingSlow : !MathHelper.CloseToPercent(ev.CloseTimeModifier, 1.0f) ? StatusLightState.BlinkingSlow :
StatusLightState.On, StatusLightState.On,
"TIME"); "TIME");

View File

@@ -233,7 +233,7 @@ namespace Content.Server.Light.Components
var currentCharge = Cell.CurrentCharge; var currentCharge = Cell.CurrentCharge;
if (MathHelper.CloseTo(currentCharge, 0) || Wattage > currentCharge) if (MathHelper.CloseToPercent(currentCharge, 0) || Wattage > currentCharge)
return 0; return 0;
return (byte?) ContentHelpers.RoundToNearestLevels(currentCharge / Cell.MaxCharge * 255, 255, StatusLevels); return (byte?) ContentHelpers.RoundToNearestLevels(currentCharge / Cell.MaxCharge * 255, 255, StatusLevels);

View File

@@ -105,6 +105,11 @@ namespace Content.Server.Physics.Controllers
// ShuttleSystem has already worked out the ratio so we'll just multiply it back by the mass. // ShuttleSystem has already worked out the ratio so we'll just multiply it back by the mass.
var movement = (mover.VelocityDir.walking + mover.VelocityDir.sprinting); var movement = (mover.VelocityDir.walking + mover.VelocityDir.sprinting);
if (physicsComponent.LinearVelocity.LengthSquared == 0f)
{
movement *= 5f;
}
switch (shuttleComponent.Mode) switch (shuttleComponent.Mode)
{ {
case ShuttleMode.Docking: case ShuttleMode.Docking:
@@ -137,12 +142,6 @@ namespace Content.Server.Physics.Controllers
var velocity = physicsComponent.LinearVelocity; var velocity = physicsComponent.LinearVelocity;
if (velocity.Length < 0.1f && movement.Length == 0f)
{
physicsComponent.LinearVelocity = Vector2.Zero;
return;
}
if (velocity.Length > speedCap) if (velocity.Length > speedCap)
{ {
physicsComponent.LinearVelocity = velocity.Normalized * speedCap; physicsComponent.LinearVelocity = velocity.Normalized * speedCap;

View File

@@ -175,7 +175,7 @@ namespace Content.Server.Power.Components
} }
var delta = netBat.CurrentReceiving - netBat.LoadingNetworkDemand; var delta = netBat.CurrentReceiving - netBat.LoadingNetworkDemand;
if (!MathHelper.CloseTo(delta, 0, 0.1f) && delta < 0) if (!MathHelper.CloseToPercent(delta, 0, 0.1f) && delta < 0)
{ {
return ApcExternalPowerState.Low; return ApcExternalPowerState.Low;
} }

View File

@@ -28,7 +28,7 @@ namespace Content.Server.Power.Components
public override string Name => "ApcPowerReceiver"; public override string Name => "ApcPowerReceiver";
[ViewVariables] [ViewVariables]
public bool Powered => (MathHelper.CloseTo(NetworkLoad.ReceivingPower, Load) || !NeedsPower) && !PowerDisabled; public bool Powered => (MathHelper.CloseToPercent(NetworkLoad.ReceivingPower, Load) || !NeedsPower) && !PowerDisabled;
/// <summary> /// <summary>
/// The max distance from a <see cref="ApcPowerProviderComponent"/> that this can receive power from. /// The max distance from a <see cref="ApcPowerProviderComponent"/> that this can receive power from.

View File

@@ -32,7 +32,7 @@ namespace Content.Server.Power.Components
/// <summary> /// <summary>
/// True if the battery is fully charged. /// True if the battery is fully charged.
/// </summary> /// </summary>
[ViewVariables] public bool IsFullyCharged => MathHelper.CloseTo(CurrentCharge, MaxCharge); [ViewVariables] public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
[ViewVariables(VVAccess.ReadWrite)] [DataField("autoRecharge")] public bool AutoRecharge { get; set; } [ViewVariables(VVAccess.ReadWrite)] [DataField("autoRecharge")] public bool AutoRecharge { get; set; }

View File

@@ -189,7 +189,7 @@ namespace Content.Server.Power.EntitySystems
var recv = apcReceiver.NetworkLoad.ReceivingPower; var recv = apcReceiver.NetworkLoad.ReceivingPower;
ref var last = ref apcReceiver.LastPowerReceived; ref var last = ref apcReceiver.LastPowerReceived;
if (!MathHelper.CloseTo(recv, last)) if (!MathHelper.CloseToPercent(recv, last))
{ {
last = recv; last = recv;
apcReceiver.ApcPowerChanged(); apcReceiver.ApcPowerChanged();
@@ -200,7 +200,7 @@ namespace Content.Server.Power.EntitySystems
{ {
var newRecv = consumer.NetworkLoad.ReceivingPower; var newRecv = consumer.NetworkLoad.ReceivingPower;
ref var lastRecv = ref consumer.LastReceived; ref var lastRecv = ref consumer.LastReceived;
if (!MathHelper.CloseTo(lastRecv, newRecv)) if (!MathHelper.CloseToPercent(lastRecv, newRecv))
{ {
lastRecv = newRecv; lastRecv = newRecv;
var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate); var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate);

View File

@@ -124,7 +124,8 @@ namespace Content.Server.Shuttles
component.BodyStatus = BodyStatus.InAir; component.BodyStatus = BodyStatus.InAir;
//component.FixedRotation = false; TODO WHEN ROTATING SHUTTLES FIXED. //component.FixedRotation = false; TODO WHEN ROTATING SHUTTLES FIXED.
component.FixedRotation = true; component.FixedRotation = true;
component.LinearDamping = 0.05f; component.LinearDamping = 0.2f;
component.AngularDamping = 0.1f;
} }
private void Disable(PhysicsComponent component) private void Disable(PhysicsComponent component)

View File

@@ -22,7 +22,7 @@ namespace Content.Shared.Friction
get => _modifier; get => _modifier;
set set
{ {
if (MathHelper.CloseTo(_modifier, value)) return; if (MathHelper.CloseToPercent(_modifier, value)) return;
_modifier = value; _modifier = value;
} }

View File

@@ -41,7 +41,7 @@ namespace Content.Shared.Movement.Components
get => _stepSoundDistance; get => _stepSoundDistance;
set set
{ {
if (MathHelper.CloseTo(_stepSoundDistance, value)) return; if (MathHelper.CloseToPercent(_stepSoundDistance, value)) return;
_stepSoundDistance = value; _stepSoundDistance = value;
} }
} }
@@ -52,7 +52,7 @@ namespace Content.Shared.Movement.Components
get => _grabRange; get => _grabRange;
set set
{ {
if (MathHelper.CloseTo(_grabRange, value)) return; if (MathHelper.CloseToPercent(_grabRange, value)) return;
_grabRange = value; _grabRange = value;
Dirty(); Dirty();
} }
@@ -64,7 +64,7 @@ namespace Content.Shared.Movement.Components
get => _pushStrength; get => _pushStrength;
set set
{ {
if (MathHelper.CloseTo(_pushStrength, value)) return; if (MathHelper.CloseToPercent(_pushStrength, value)) return;
_pushStrength = value; _pushStrength = value;
Dirty(); Dirty();
} }
@@ -76,7 +76,7 @@ namespace Content.Shared.Movement.Components
get => _weightlessStrength; get => _weightlessStrength;
set set
{ {
if (MathHelper.CloseTo(_weightlessStrength, value)) return; if (MathHelper.CloseToPercent(_weightlessStrength, value)) return;
_weightlessStrength = value; _weightlessStrength = value;
Dirty(); Dirty();
} }

View File

@@ -125,7 +125,7 @@ namespace Content.Shared.Movement
new Angle(transform.Parent!.WorldRotation.Theta).RotateVec(total) : new Angle(transform.Parent!.WorldRotation.Theta).RotateVec(total) :
total; total;
DebugTools.Assert(MathHelper.CloseTo(total.Length, worldTotal.Length)); DebugTools.Assert(MathHelper.CloseToPercent(total.Length, worldTotal.Length));
if (weightless) if (weightless)
{ {

View File

@@ -63,7 +63,7 @@ namespace Content.Shared.Slippery
get => _paralyzeTime; get => _paralyzeTime;
set set
{ {
if (MathHelper.CloseTo(_paralyzeTime, value)) return; if (MathHelper.CloseToPercent(_paralyzeTime, value)) return;
_paralyzeTime = value; _paralyzeTime = value;
Dirty(); Dirty();
@@ -80,7 +80,7 @@ namespace Content.Shared.Slippery
get => _intersectPercentage; get => _intersectPercentage;
set set
{ {
if (MathHelper.CloseTo(_intersectPercentage, value)) return; if (MathHelper.CloseToPercent(_intersectPercentage, value)) return;
_intersectPercentage = value; _intersectPercentage = value;
Dirty(); Dirty();
@@ -97,7 +97,7 @@ namespace Content.Shared.Slippery
get => _requiredSlipSpeed; get => _requiredSlipSpeed;
set set
{ {
if (MathHelper.CloseTo(_requiredSlipSpeed, value)) return; if (MathHelper.CloseToPercent(_requiredSlipSpeed, value)) return;
_requiredSlipSpeed = value; _requiredSlipSpeed = value;
Dirty(); Dirty();
@@ -114,7 +114,7 @@ namespace Content.Shared.Slippery
get => _launchForwardsMultiplier; get => _launchForwardsMultiplier;
set set
{ {
if (MathHelper.CloseTo(_launchForwardsMultiplier, value)) return; if (MathHelper.CloseToPercent(_launchForwardsMultiplier, value)) return;
_launchForwardsMultiplier = value; _launchForwardsMultiplier = value;
Dirty(); Dirty();