/// <summary> /// Applied before GetFormattedTemperature runs. /// </summary> internal static bool Prefix(float temp, TimeSlice timeSlice, GameUtil.TemperatureInterpretation interpretation, bool displayUnits, bool roundInDestinationFormat, ref string __result) { var text = CACHED_BUILDER; text.Clear(); GetFormattedTemperature(text, temp, timeSlice, interpretation, displayUnits, roundInDestinationFormat); __result = text.ToString(); return(false); }
public static void Postfix(float temp, ref string __result, GameUtil.TemperatureInterpretation interpretation, GameUtil.TimeSlice timeSlice) { try { if (interpretation != GameUtil.TemperatureInterpretation.Absolute || timeSlice != GameUtil.TimeSlice.None) { return; } string formatString = "##0.#"; float kelvin = GameUtil.GetTemperatureConvertedToKelvin(temp); string kelvinString = kelvin.ToString(formatString); string celsiusString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Celsius).ToString(formatString); string fahrenheitString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Fahrenheit).ToString(formatString); string first; string second; switch (GameUtil.temperatureUnit) { case GameUtil.TemperatureUnit.Celsius: first = kelvinString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; second = fahrenheitString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; break; case GameUtil.TemperatureUnit.Fahrenheit: first = kelvinString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; second = celsiusString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; break; case GameUtil.TemperatureUnit.Kelvin: first = celsiusString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; second = fahrenheitString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; break; default: return; } __result += $", ({first}, {second})"; } catch (Exception e) { // TODO: log once instead Debug.Log("DisplayAllTemps: " + e); } }
public static void Postfix(float temp, bool displayUnits, ref string __result, GameUtil.TemperatureInterpretation interpretation, GameUtil.TimeSlice timeSlice) { try { if (interpretation != GameUtil.TemperatureInterpretation.Absolute || timeSlice != GameUtil.TimeSlice.None || !displayUnits) { return; } string formatString = "##0.#"; float kelvin = GameUtil.GetTemperatureConvertedToKelvin(temp); var temperatures = new List <string>(); if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Celsius && (TemperatureUnitMultiple.Celsius & State.Unit) != 0) { string celsiusString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Celsius).ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; temperatures.Add(celsiusString); } if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Fahrenheit && (TemperatureUnitMultiple.Fahrenheit & State.Unit) != 0) { string fahrenheitString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Fahrenheit).ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; temperatures.Add(fahrenheitString); } if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Kelvin && (TemperatureUnitMultiple.Kelvin & State.Unit) != 0) { string kelvinString = kelvin.ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; temperatures.Add(kelvinString); } if (temperatures.Count <= 0) { return; } var builder = new StringBuilder(__result); foreach (var temperature in temperatures) { builder.Append(", "); builder.Append(temperature); } __result = builder.ToString(); } catch (Exception e) { State.Common.Logger.LogOnce("DisplayAllTemps failed.", e); } }
/// <summary> /// Formats the temperature into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the temperature will be stored.</param> /// <param name="temperature">The temperature in K.</param> /// <param name="timeSlice">The time unit, if any.</param> /// <param name="interpretation">Whether the temperature is a delta, or an absolute value.</param> /// <param name="displayUnits">Whether to display the units.</param> /// <param name="roundOff">Whether to round off the temperature to the nearest degree.</param> internal static void GetFormattedTemperature(StringBuilder text, float temperature, TimeSlice timeSlice = TimeSlice.None, GameUtil.TemperatureInterpretation interpretation = GameUtil.TemperatureInterpretation.Absolute, bool displayUnits = true, bool roundOff = false) { if (interpretation == GameUtil.TemperatureInterpretation.Absolute) { temperature = GameUtil.GetConvertedTemperature(temperature, roundOff); } else if (GameUtil.temperatureUnit == GameUtil.TemperatureUnit.Fahrenheit) { temperature *= 1.8f; } temperature = GameUtil.ApplyTimeSlice(temperature, timeSlice); if (!text.AppendIfInfinite(temperature)) { temperature.ToRyuSoftString(text, Mathf.Abs(temperature) < 0.1f ? 4 : 1); } if (displayUnits) { text.Append(GameUtil.GetTemperatureUnitSuffix()); } text.AppendTimeSlice(timeSlice); }