diff --git a/MechJeb2/CompatibilityChecker.cs b/MechJeb2/CompatibilityChecker.cs index b82e2432..11627a6c 100644 --- a/MechJeb2/CompatibilityChecker.cs +++ b/MechJeb2/CompatibilityChecker.cs @@ -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. @@ -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; } }) @@ -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; } }) @@ -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); } } diff --git a/MechJeb2/GuiUtils.cs b/MechJeb2/GuiUtils.cs index a49a8e01..7349c0f5 100644 --- a/MechJeb2/GuiUtils.cs +++ b/MechJeb2/GuiUtils.cs @@ -898,8 +898,8 @@ public class Coordinates public Coordinates(double latitude, double longitude) { - this.Latitude = latitude; - this.Longitude = longitude; + Latitude = latitude; + Longitude = longitude; } [UsedImplicitly] diff --git a/MechJeb2/MechJebLib/Maneuvers/TwoImpulseTransfer.cs b/MechJeb2/MechJebLib/Maneuvers/TwoImpulseTransfer.cs index 5411e74f..55fe6c8d 100644 --- a/MechJeb2/MechJebLib/Maneuvers/TwoImpulseTransfer.cs +++ b/MechJeb2/MechJebLib/Maneuvers/TwoImpulseTransfer.cs @@ -186,12 +186,13 @@ 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 @@ -199,7 +200,7 @@ private static void NLPFunction(double[] x, ref double func, object obj) 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)) { @@ -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); diff --git a/MechJeb2/MechJebModuleAscentPVGAutopilot.cs b/MechJeb2/MechJebModuleAscentPVGAutopilot.cs index 88c240e2..eaf2ebaf 100644 --- a/MechJeb2/MechJebModuleAscentPVGAutopilot.cs +++ b/MechJeb2/MechJebModuleAscentPVGAutopilot.cs @@ -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 } } diff --git a/MechJeb2/MechJebModuleInfoItems.cs b/MechJeb2/MechJebModuleInfoItems.cs index 3bf1e99d..bacf569e 100644 --- a/MechJeb2/MechJebModuleInfoItems.cs +++ b/MechJeb2/MechJebModuleInfoItems.cs @@ -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()); @@ -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, @@ -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 diff --git a/MechJeb2/MechJebModuleMenu.cs b/MechJeb2/MechJebModuleMenu.cs index 4b19ca05..078f8b76 100644 --- a/MechJeb2/MechJebModuleMenu.cs +++ b/MechJeb2/MechJebModuleMenu.cs @@ -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, "_"); } diff --git a/MechJeb2/MechJebModuleNodeExecutor.cs b/MechJeb2/MechJebModuleNodeExecutor.cs index 79cb7fb5..1321491d 100644 --- a/MechJeb2/MechJebModuleNodeExecutor.cs +++ b/MechJeb2/MechJebModuleNodeExecutor.cs @@ -1,5 +1,4 @@ -using System; -using JetBrains.Annotations; +using JetBrains.Annotations; using MechJebLib.Simulations; using UnityEngine; using static System.Math; diff --git a/MechJeb2/MechJebModuleRCSBalancer.cs b/MechJeb2/MechJebModuleRCSBalancer.cs index 45e9079e..34fe646e 100644 --- a/MechJeb2/MechJebModuleRCSBalancer.cs +++ b/MechJeb2/MechJebModuleRCSBalancer.cs @@ -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) @@ -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); diff --git a/MechJeb2/MechJebModuleWaypointWindow.cs b/MechJeb2/MechJebModuleWaypointWindow.cs index 42aaa6a8..b9eed8ae 100644 --- a/MechJeb2/MechJebModuleWaypointWindow.cs +++ b/MechJeb2/MechJebModuleWaypointWindow.cs @@ -13,13 +13,15 @@ namespace MuMech public class MechJebWaypoint { private const float DEFAULT_RADIUS = 5; - public double Latitude; - public double Longitude; - public double Altitude; - public Vector3d Position; - public float Radius; + public double Latitude; + public double Longitude; + public double Altitude; + public Vector3d Position; + public float Radius; + [UsedImplicitly] - public string Name; + public string Name; + public readonly Vessel Target; public float MinSpeed; public float MaxSpeed; @@ -30,33 +32,33 @@ public class MechJebWaypoint public MechJebWaypoint(double latitude, double longitude, float radius = DEFAULT_RADIUS, string name = "", float minSpeed = 0, float maxSpeed = 0) { - this.Latitude = latitude; - this.Longitude = longitude; - this.Radius = radius; - this.Name = name ?? ""; - this.MinSpeed = minSpeed; - this.MaxSpeed = maxSpeed; + Latitude = latitude; + Longitude = longitude; + Radius = radius; + Name = name ?? ""; + MinSpeed = minSpeed; + MaxSpeed = maxSpeed; Update(); } public MechJebWaypoint(Vector3d position, float radius = DEFAULT_RADIUS, string name = "", float minSpeed = 0, float maxSpeed = 0) { - Latitude = Body.GetLatitude(position); - Longitude = Body.GetLongitude(position); - this.Radius = radius; - this.Name = name ?? ""; - this.MinSpeed = minSpeed; - this.MaxSpeed = maxSpeed; + Latitude = Body.GetLatitude(position); + Longitude = Body.GetLongitude(position); + Radius = radius; + Name = name ?? ""; + MinSpeed = minSpeed; + MaxSpeed = maxSpeed; Update(); } public MechJebWaypoint(Vessel target, float radius = DEFAULT_RADIUS, string name = "", float minSpeed = 0, float maxSpeed = 0) { - this.Target = target; - this.Radius = radius; - this.Name = name ?? ""; - this.MinSpeed = minSpeed; - this.MaxSpeed = maxSpeed; + Target = target; + Radius = radius; + Name = name ?? ""; + MinSpeed = minSpeed; + MaxSpeed = maxSpeed; Update(); } @@ -182,9 +184,9 @@ private void UpdateStats() public MechJebWaypointRoute(string name = "", CelestialBody body = null, string mode = "Rover") { - this.Name = name; - this.Body = body != null ? body : FlightGlobals.currentMainBody; - this.Mode = mode; + Name = name; + Body = body != null ? body : FlightGlobals.currentMainBody; + Mode = mode; } public MechJebWaypointRoute(ConfigNode node) @@ -282,7 +284,7 @@ public enum WaypointMode [Persistent(pass = (int)Pass.GLOBAL)] // Vall Mapdist public readonly EditableDouble VallMapdist = 5000; - internal int SelIndex = -1; + internal int SelIndex = -1; private int _saveIndex = -1; private string _tmpRadius = ""; private string _tmpMinSpeed = ""; @@ -318,7 +320,7 @@ private enum Pages { WAYPOINTS, SETTINGS, ROUTES } public override void OnStart(PartModule.StartState state) { Hidden = true; - _ap = Core.GetComputerModule(); + _ap = Core.GetComputerModule(); if (HighLogic.LoadedSceneIsFlight && Vessel.isActiveVessel) { _renderer = MechJebRouteRenderer.AttachToMapView(Core); @@ -532,7 +534,7 @@ private static string LonToString(double lon) float s = (float)lon; - return string.Format("{0} {1}° {2}' {3:F3}\"", ew, h, m, s); + return $"{ew} {h}° {m}' {s:F3}\""; } private static double ParseCoord(string latLon, bool isLongitute = false) @@ -631,9 +633,8 @@ private void DrawPageWaypoints() wp.Position); } - string str = string.Format("[{0}] - {1} - R: {2:F1} m\n S: {3:F0} ~ {4:F0} - D: {5}m - ETA: {6}", i + 1, - wp.GetNameWithCoords(), wp.Radius, - minSpeed, maxSpeed, dist.ToSI(-1), GuiUtils.TimeToDHMS(eta)); + string str = + $"[{i + 1}] - {wp.GetNameWithCoords()} - R: {wp.Radius:F1} m\n S: {minSpeed:F0} ~ {maxSpeed:F0} - D: {dist.ToSI(-1)}m - ETA: {GuiUtils.TimeToDHMS(eta)}"; GUI.backgroundColor = i == _ap.WaypointIndex ? new Color(0.5f, 1f, 0.5f) : Color.white; if (GUILayout.Button(str, i == SelIndex ? _styleActive : wp.Quicksave ? _styleQuicksave : _styleInactive)) { @@ -650,7 +651,7 @@ private void DrawPageWaypoints() } else { - SelIndex = i; + SelIndex = i; _tmpRadius = wp.Radius.ToString(); _tmpMinSpeed = wp.MinSpeed.ToString(); _tmpMaxSpeed = wp.MaxSpeed.ToString(); @@ -715,11 +716,11 @@ private void DrawPageWaypoints() GUILayout.BeginHorizontal(); GUILayout.Label("Lat ", GUILayout.ExpandWidth(false)); - _tmpLat = GUILayout.TextField(_tmpLat, GUILayout.Width(125)); + _tmpLat = GUILayout.TextField(_tmpLat, GUILayout.Width(125)); wp.Latitude = ParseCoord(_tmpLat); GUILayout.Label(" - Lon ", GUILayout.ExpandWidth(false)); - _tmpLon = GUILayout.TextField(_tmpLon, GUILayout.Width(125)); + _tmpLon = GUILayout.TextField(_tmpLon, GUILayout.Width(125)); wp.Longitude = ParseCoord(_tmpLon, true); GUILayout.EndHorizontal(); @@ -782,7 +783,8 @@ private void DrawPageWaypoints() SelIndex = -1; } - if (GUILayout.Button(alt ? "Top" : "Up", GUILayout.Width(57)) && SelIndex > 0 && SelIndex < _ap.Waypoints.Count && _ap.Waypoints.Count >= 2) + if (GUILayout.Button(alt ? "Top" : "Up", GUILayout.Width(57)) && SelIndex > 0 && SelIndex < _ap.Waypoints.Count && + _ap.Waypoints.Count >= 2) { if (alt) { @@ -1143,7 +1145,7 @@ public override void OnFixedUpdate() public class MechJebModuleWaypointHelpWindow : DisplayModule { public int SelTopic; - public readonly string[] Topics = { "Rover Controller", "Waypoints", "Routes", "Settings" }; + public readonly string[] Topics = { "Rover Controller", "Waypoints", "Routes", "Settings" }; private string _selSubTopic = ""; private GUIStyle _btnActive; private GUIStyle _btnInactive; @@ -1154,7 +1156,7 @@ private void HelpTopic(string title, string text) if (GUILayout.Button(title, _selSubTopic == title ? _btnActive : _btnInactive)) { _selSubTopic = _selSubTopic != title ? title : ""; - WindowPos = new Rect(WindowPos.x, WindowPos.y, WindowPos.width, 0); + WindowPos = new Rect(WindowPos.x, WindowPos.y, WindowPos.width, 0); } if (_selSubTopic == title) @@ -1277,16 +1279,16 @@ protected override void WindowGUI(int windowID) public class MechJebRouteRenderer : MonoBehaviour { private static readonly Material _material = new Material(Shader.Find("Legacy Shaders/Particles/Additive")); - public MechJebModuleRoverController AP; - private LineRenderer _pastPath; - private LineRenderer _currPath; - private LineRenderer _nextPath; - private LineRenderer _selWp; - private readonly Color _pastPathColor = new Color(0f, 0f, 1f, 0.5f); - private readonly Color _currPathColor = new Color(0f, 1f, 0f, 0.5f); - private readonly Color _nextPathColor = new Color(1f, 1f, 0f, 0.5f); - private readonly Color _selWpColor = new Color(1f, 0f, 0f, 0.5f); - private double _addHeight; + public MechJebModuleRoverController AP; + private LineRenderer _pastPath; + private LineRenderer _currPath; + private LineRenderer _nextPath; + private LineRenderer _selWp; + private readonly Color _pastPathColor = new Color(0f, 0f, 1f, 0.5f); + private readonly Color _currPathColor = new Color(0f, 1f, 0f, 0.5f); + private readonly Color _nextPathColor = new Color(1f, 1f, 0f, 0.5f); + private readonly Color _selWpColor = new Color(1f, 0f, 0f, 0.5f); + private double _addHeight; public static MechJebRouteRenderer AttachToMapView(MechJebCore core) { @@ -1325,7 +1327,6 @@ private static Vector3 RaisePositionOverTerrain(Vector3 position, float heightOf return ScaledSpace.LocalToScaledSpace(body.position + (body.Radius + heightOffset + body.TerrainAltitude(lat, lon)) * body.GetSurfaceNVector(lat, lon)); - } public new bool enabled