Skip to content

Commit

Permalink
Use string interpolation
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Nov 1, 2023
1 parent d04257e commit 95ae54a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 75 deletions.
17 changes: 8 additions & 9 deletions MechJeb2/CompatibilityChecker.cs
Expand Up @@ -114,8 +114,7 @@ public void Start()
// Let the latest version of the checker execute.
if (_version != fields.Max(f => (int)f.GetValue(null))) { return; }

Debug.Log(string.Format("[CompatibilityChecker] Running checker version {0} from '{1}'", _version,
Assembly.GetExecutingAssembly().GetName().Name));
Debug.Log($"[CompatibilityChecker] Running checker version {_version} from '{Assembly.GetExecutingAssembly().GetName().Name}'");

// Other checkers will see this version and not run.
// This accomplishes the same as an explicit "ran" flag with fewer moving parts.
Expand All @@ -136,8 +135,8 @@ public void Start()
catch (Exception e)
{
// If a mod throws an exception from IsCompatible, it's not compatible.
Debug.LogWarning(string.Format("[CompatibilityChecker] Exception while invoking IsCompatible() from '{0}':\n\n{1}",
m.DeclaringType.Assembly.GetName().Name, e));
Debug.LogWarning(
$"[CompatibilityChecker] Exception while invoking IsCompatible() from '{m.DeclaringType.Assembly.GetName().Name}':\n\n{e}");
return true;
}
})
Expand All @@ -160,8 +159,8 @@ public void Start()
catch (Exception e)
{
// If a mod throws an exception from IsUnityCompatible, it's not compatible.
Debug.LogWarning(string.Format("[CompatibilityChecker] Exception while invoking IsUnityCompatible() from '{0}':\n\n{1}",
m.DeclaringType.Assembly.GetName().Name, e));
Debug.LogWarning(
$"[CompatibilityChecker] Exception while invoking IsUnityCompatible() from '{m.DeclaringType.Assembly.GetName().Name}':\n\n{e}");
return true;
}
})
Expand All @@ -186,15 +185,15 @@ public void Start()
if (incompatible.Length > 0)
{
Debug.LogWarning("[CompatibilityChecker] Incompatible mods detected: " + string.Join(", ", incompatible));
message += string.Format("\n\nThese mods are incompatible with KSP {0}.{1}.{2}:\n\n", Versioning.version_major,
Versioning.version_minor, Versioning.Revision);
message +=
$"\n\nThese mods are incompatible with KSP {Versioning.version_major}.{Versioning.version_minor}.{Versioning.Revision}:\n\n";
message += string.Join("\n", incompatible);
}

if (incompatibleUnity.Length > 0)
{
Debug.LogWarning("[CompatibilityChecker] Incompatible mods (Unity) detected: " + string.Join(", ", incompatibleUnity));
message += string.Format("\n\nThese mods are incompatible with Unity {0}:\n\n", Application.unityVersion);
message += $"\n\nThese mods are incompatible with Unity {Application.unityVersion}:\n\n";
message += string.Join("\n", incompatibleUnity);
}
}
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/GuiUtils.cs
Expand Up @@ -898,8 +898,8 @@ public class Coordinates

public Coordinates(double latitude, double longitude)
{
this.Latitude = latitude;
this.Longitude = longitude;
Latitude = latitude;
Longitude = longitude;
}

[UsedImplicitly]
Expand Down
13 changes: 8 additions & 5 deletions MechJeb2/MechJebLib/Maneuvers/TwoImpulseTransfer.cs
Expand Up @@ -186,20 +186,21 @@ private static void NLPFunction(double[] x, ref double func, object obj)
}

(dv1, dt1, dv2, dt2) =
Maneuver(mu, r1, v1, r2, v2, dtguess, offsetGuess, dtmin: dtmin, dtmax: dtmax, offsetMin: offsetMin, offsetMax: offsetMax, coplanar: coplanar, capture: capture, optguard: optguard);
Maneuver(mu, r1, v1, r2, v2, dtguess, offsetGuess, dtmin: dtmin, dtmax: dtmax, offsetMin: offsetMin, offsetMax: offsetMax,
coplanar: coplanar, capture: capture, optguard: optguard);
}
else
{
(dv1, dt1, dv2, dt2) =
Maneuver(mu, r1, v1, r2, v2, dtguess, 0, dtmin: dtmin, dtmax: dtmax , coplanar: coplanar, capture: capture, optguard: optguard);
Maneuver(mu, r1, v1, r2, v2, dtguess, 0, dtmin: dtmin, dtmax: dtmax, coplanar: coplanar, capture: capture, optguard: optguard);

// we have to try the other side of the target orbit since we might get eg. the DN instead of the AN when the AN is closer
// (this may be insufficient and may need more of a search box but then we're O(N^2) and i think basinhopping or porkchop
// plots will be the better solution)
double targetPeriod = Maths.PeriodFromStateVectors(mu, r2, v2);

(V3 a, double b, V3 c, double d) =
Maneuver(mu, r1, v1, r2, v2, dtguess, targetPeriod * 0.5, coplanar: coplanar, capture: capture, optguard: optguard);
Maneuver(mu, r1, v1, r2, v2, dtguess, targetPeriod * 0.5, coplanar, capture, optguard: optguard);

if (b > 0 && (b < dt1 || dt1 < 0))
{
Expand All @@ -220,12 +221,14 @@ private static void NLPFunction(double[] x, ref double func, object obj)
double synodicPeriod = Maths.SynodicPeriod(mu, r1, v1, r2, v2);

if (fixedTime)
return ManeuverInternal(mu, r1, v1, r2, v2, dtguess: 0, coplanar: coplanar, rendezvous: rendezvous, capture: capture, optguard: optguard, lagTime:lagTime, fixedtime: true);
return ManeuverInternal(mu, r1, v1, r2, v2, 0, coplanar: coplanar, rendezvous: rendezvous, capture: capture, optguard: optguard,
lagTime: lagTime, fixedtime: true);

double dtguess = 0;
for (int iter = 0; iter < maxiter; iter++)
{
(V3 dv1, double dt1, V3 dv2, double dt2) = ManeuverInternal(mu, r1, v1, r2, v2, dtguess: dtguess, coplanar: coplanar, rendezvous: rendezvous, capture: capture, optguard: optguard, lagTime:lagTime);
(V3 dv1, double dt1, V3 dv2, double dt2) = ManeuverInternal(mu, r1, v1, r2, v2, dtguess, coplanar: coplanar, rendezvous: rendezvous,
capture: capture, optguard: optguard, lagTime: lagTime);

if (dt1 > 0)
return (dv1, dt1, dv2, dt2);
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleAscentPVGAutopilot.cs
Expand Up @@ -126,7 +126,7 @@ private void DriveVerticalAscent()
}

double dv = AscentSettings.PitchStartVelocity - VesselState.surfaceVelocity.magnitude;
Status = Localizer.Format("#MechJeb_Ascent_status13", string.Format("{0:F2}", dv)); //Vertical ascent <<1>>m/s to go
Status = Localizer.Format("#MechJeb_Ascent_status13", $"{dv:F2}"); //Vertical ascent <<1>>m/s to go
}
}

Expand Down
6 changes: 3 additions & 3 deletions MechJeb2/MechJebModuleInfoItems.cs
Expand Up @@ -413,7 +413,7 @@ public string MaxPartCount()
}

[ValueInfoItem("#MechJeb_PartCountDivideMaxParts", InfoItem.Category.Vessel, showInEditor = true)] //Part count / Max parts
public string PartCountAndMaxPartCount() => string.Format("{0} / {1}", PartCount().ToString(), MaxPartCount());
public string PartCountAndMaxPartCount() => $"{PartCount().ToString()} / {MaxPartCount()}";

[ValueInfoItem("#MechJeb_StrutCount", InfoItem.Category.Vessel, showInEditor = true)] //Strut count
public int StrutCount() => parts.Count(p => p is CompoundPart && p.Modules.GetModule<CModuleStrut>());
Expand Down Expand Up @@ -860,7 +860,7 @@ public string StageDeltaVAtmosphereAndVac()
double atmDv = stats.AtmoStats.Count == 0 ? 0 : stats.AtmoStats[stats.AtmoStats.Count - 1].DeltaV;
double vacDv = stats.VacStats.Count == 0 ? 0 : stats.VacStats[stats.VacStats.Count - 1].DeltaV;

return string.Format("{0:F0}, {1:F0}", atmDv, vacDv);
return $"{atmDv:F0}, {vacDv:F0}";
}

[ValueInfoItem("#MechJeb_StageTimeFullThrottle", InfoItem.Category.Vessel, format = ValueInfoItem.TIME,
Expand Down Expand Up @@ -923,7 +923,7 @@ public string TotalDeltaVAtmosphereAndVac()
double atmDv = stats.AtmoStats.Sum(s => s.DeltaV);
double vacDv = stats.VacStats.Sum(s => s.DeltaV);

return string.Format("{0:F0}, {1:F0}", atmDv, vacDv);
return $"{atmDv:F0}, {vacDv:F0}";
}

[GeneralInfoItem("#MechJeb_DockingGuidance_velocity", InfoItem.Category.Target)] //Docking guidance: velocity
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleMenu.cs
Expand Up @@ -460,7 +460,7 @@ public void SetupMainToolbarButton()
private string GetCleanName(string name)
{
string regexSearch = " .:" + new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
var r = new Regex($"[{Regex.Escape(regexSearch)}]");
return r.Replace(name, "_");
}

Expand Down
3 changes: 1 addition & 2 deletions MechJeb2/MechJebModuleNodeExecutor.cs
@@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using JetBrains.Annotations;
using MechJebLib.Simulations;
using UnityEngine;
using static System.Math;
Expand Down
6 changes: 3 additions & 3 deletions MechJeb2/MechJebModuleRCSBalancer.cs
Expand Up @@ -94,7 +94,7 @@ private void RCSThrusterStateInfoItem()
}

firstRcsModule = false;
thrusterStates += string.Format("({0:F0}:", pm.thrusterPower * 9);
thrusterStates += $"({pm.thrusterPower * 9:F0}:";
for (int i = 0; i < pm.thrustForces.Length; i++)
{
if (i != 0)
Expand Down Expand Up @@ -145,8 +145,8 @@ private void ControlVectorInfoItem()
{
FlightCtrlState s = FlightInputHandler.state;

string xyz = string.Format("{0:F2} {1:F2} {2:F2}", s.X, s.Y, s.Z);
string rpy = string.Format("{0:F2} {1:F2} {2:F2}", s.roll, s.pitch, s.yaw);
string xyz = $"{s.X:F2} {s.Y:F2} {s.Z:F2}";
string rpy = $"{s.roll:F2} {s.pitch:F2} {s.yaw:F2}";
GUILayout.BeginVertical();
GuiUtils.SimpleLabel("X/Y/Z", xyz);
GuiUtils.SimpleLabel("R/P/Y", rpy);
Expand Down

0 comments on commit 95ae54a

Please sign in to comment.