diff --git a/README.md b/README.md index 9731845..86e15ba 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ This project aims to bring together community bug fixes for Kerbal Space Program - **Decoupled Craft Name Fix** by [munix](https://github.com/jan-bures) - Decoupled and docked/undocked vessels get names based on the original vessels instead of "Default Name" and "(Combined)". - **Time Warp Thrust Fix** by [SunSerega](https://github.com/SunSerega) - Fixes the bug where thrust under time warp was sometimes not working despite draining fuel. - **Save/Load DateTime Fix** by [bizzehdee](https://github.com/bizzehdee) - Displays dates and times of save files in the correct locale format. +- **Tracking Station Debris Name Fix** by [polo](https://github.com/pasalvetti) - Replaces the object's guid with a human-readable name: "Debris of [ship name]". ## Planned fixes To see what fixes are planned to be implemented, you can visit the [Issues page](https://github.com/KSP2Community/CommunityFixes/issues) on the project's GitHub. diff --git a/src/CommunityFixes/Fix/TrackingStationDebrisNameFix/TrackingStationDebrisNameFix.cs b/src/CommunityFixes/Fix/TrackingStationDebrisNameFix/TrackingStationDebrisNameFix.cs new file mode 100644 index 0000000..b5eb2ea --- /dev/null +++ b/src/CommunityFixes/Fix/TrackingStationDebrisNameFix/TrackingStationDebrisNameFix.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using KSP.Map; +using System.Text.RegularExpressions; + +namespace CommunityFixes.Fix.TrackingStationDebrisNameFix +{ + [Fix("Fix debris name in the tracking station")] + internal class TrackingStationDebrisNameFix : BaseFix + { + public override void OnInitialized() + { + HarmonyInstance.PatchAll(typeof(TrackingStationDebrisNameFix)); + } + + [HarmonyPatch(typeof(MapUI), nameof(MapUI.HandleDebrisObjectEntryConfigurations))] + [HarmonyPostfix] + public static void HandleDebrisObjectEntryConfigurationsPostfix( + MapItem item, + MapUISelectableEntry obj + ) + { + string debrisName = ((object)item._itemName).ToString(); + var match = Regex.Match(debrisName, @"-(\d+)$"); + var newName = match.Success + ? Regex.Replace(debrisName, @"-\d+$", "") + : debrisName; + obj.Name = string.Format("Debris of {0}", newName); + } + + } +}