/// <summary> /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and /// then increase by STEP. /// </summary> /// <param name="speed">Ingame speed</param> /// <returns>Ingame speed increased by the increment for MPH or KMPH</returns> public static SpeedValue GetNext(SpeedValue speed) { if (speed.GameUnits < 0f) { return(new SpeedValue(-1f)); } if (GlobalConfig.Instance.Main.DisplaySpeedLimitsMph) { MphValue rounded = speed.ToMphRounded(MPH_STEP); rounded += MPH_STEP; if (rounded.Mph > UPPER_MPH) { rounded = new MphValue(0); } return(SpeedValue.FromMph(rounded)); } else { KmphValue rounded = speed.ToKmphRounded(KMPH_STEP); rounded += KMPH_STEP; if (rounded.Kmph > UPPER_KMPH) { rounded = new KmphValue(0); } return(SpeedValue.FromKmph(rounded)); } }
/// <summary> /// Based on the MPH/KMPH settings round the current speed to the nearest STEP and /// then decrease by STEP. /// </summary> /// <param name="speed">Ingame speed</param> /// <returns>Ingame speed decreased by the increment for MPH or KMPH</returns> public static SpeedValue GetPrevious(SpeedValue speed) { if (speed.GameUnits < 0f) { return(new SpeedValue(-1f)); } if (GlobalConfig.Instance.Main.DisplaySpeedLimitsMph) { MphValue rounded = speed.ToMphRounded(MPH_STEP); if (rounded.Mph == LOWER_MPH) { return(new SpeedValue(0)); } if (rounded.Mph == 0) { return(SpeedValue.FromMph(UPPER_MPH)); } return(SpeedValue.FromMph(rounded.Mph > LOWER_MPH ? (ushort)(rounded.Mph - MPH_STEP) : LOWER_MPH)); } else { KmphValue rounded = speed.ToKmphRounded(KMPH_STEP); if (rounded.Kmph == LOWER_KMPH) { return(new SpeedValue(0)); } if (rounded.Kmph == 0) { return(SpeedValue.FromKmph(UPPER_KMPH)); } return(SpeedValue.FromKmph(rounded.Kmph > LOWER_KMPH ? (ushort)(rounded.Kmph - KMPH_STEP) : LOWER_KMPH)); } }