Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#438 Speedlimit refactor #475

Merged
merged 8 commits into from
Aug 2, 2019
Merged
17 changes: 10 additions & 7 deletions TLM/TLM/UI/SubTools/SpeedLimits/SpeedLimitsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ private void _guiDefaultsWindow(int num) {
}

if (currentSpeedLimit.GameUnits < 0f) {
currentSpeedLimit.GameUnits = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
currentSpeedLimit = new SpeedValue(
SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info));
Log._Debug($"set currentSpeedLimit to {currentSpeedLimit}");
}

Expand All @@ -259,7 +260,8 @@ private void _guiDefaultsWindow(int num) {
currentInfoIndex =
(currentInfoIndex + mainNetInfos.Count - 1) % mainNetInfos.Count;
info = mainNetInfos[currentInfoIndex];
currentSpeedLimit.GameUnits = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
currentSpeedLimit = new SpeedValue(
SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info));
UpdateRoadTex(info);
}

Expand All @@ -283,7 +285,8 @@ private void _guiDefaultsWindow(int num) {
if (GUILayout.Button("→", GUILayout.Width(50))) {
currentInfoIndex = (currentInfoIndex + 1) % mainNetInfos.Count;
info = mainNetInfos[currentInfoIndex];
currentSpeedLimit.GameUnits = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
currentSpeedLimit = new SpeedValue(
SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info));
UpdateRoadTex(info);
}

Expand Down Expand Up @@ -919,19 +922,19 @@ public static SpeedValue GetNext(SpeedValue speed) {

if (GlobalConfig.Instance.Main.DisplaySpeedLimitsMph) {
MphValue rounded = speed.ToMphRounded(MPH_STEP);
rounded.Mph += MPH_STEP;
rounded = new MphValue((ushort)(rounded.Mph + MPH_STEP));

if (rounded.Mph > UPPER_MPH) {
rounded.Mph = 0;
rounded = new MphValue(0);
}

return SpeedValue.FromMph(rounded);
} else {
KmphValue rounded = speed.ToKmphRounded(KMPH_STEP);
rounded.Kmph += KMPH_STEP;
rounded = new KmphValue((ushort)(rounded.Kmph + KMPH_STEP));
kvakvs marked this conversation as resolved.
Show resolved Hide resolved

if (rounded.Kmph > UPPER_KMPH) {
rounded.Kmph = 0;
rounded = new KmphValue(0);
}

return SpeedValue.FromKmph(rounded);
Expand Down
6 changes: 3 additions & 3 deletions TLM/TMPE.API/Traffic/Data/SpeedValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override string ToString() {
return $"{Kmph:0.0} km/h";
}

public ushort Kmph { get; set; }
public ushort Kmph { get; }
originalfoo marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand All @@ -32,7 +32,7 @@ public override string ToString() {
return $"{Mph} MPH";
}

public ushort Mph { get; set; }
public ushort Mph { get; }
originalfoo marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public SpeedValue(float gameUnits) {
/// <summary>
/// Sets or returns stored value in game units (no conversion)
/// </summary>
public float GameUnits { get; set; }
public float GameUnits { get; }

/// <summary>
/// Converts stored value in game units into velocity magnitude (8x the game units)
Expand Down