Skip to content

Commit

Permalink
Merge pull request #55 from pasalvetti/main
Browse files Browse the repository at this point in the history
Fix debris name in the Tracking Station
  • Loading branch information
jan-bures authored Sep 24, 2024
2 parents b6cf1cb + 3fe9aac commit 2586878
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
}

0 comments on commit 2586878

Please sign in to comment.