Skip to content

Commit 3fe9aac

Browse files
committed
Fix debris name in the Tracking Station
1 parent 3d8a086 commit 3fe9aac

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This project aims to bring together community bug fixes for Kerbal Space Program
1717
- **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)".
1818
- **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.
1919
- **Save/Load DateTime Fix** by [bizzehdee](https://github.com/bizzehdee) - Displays dates and times of save files in the correct locale format.
20+
- **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]".
2021

2122
## Planned fixes
2223
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.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using HarmonyLib;
2+
using KSP.Map;
3+
using System.Text.RegularExpressions;
4+
5+
namespace CommunityFixes.Fix.TrackingStationDebrisNameFix
6+
{
7+
[Fix("Fix debris name in the tracking station")]
8+
internal class TrackingStationDebrisNameFix : BaseFix
9+
{
10+
public override void OnInitialized()
11+
{
12+
HarmonyInstance.PatchAll(typeof(TrackingStationDebrisNameFix));
13+
}
14+
15+
[HarmonyPatch(typeof(MapUI), nameof(MapUI.HandleDebrisObjectEntryConfigurations))]
16+
[HarmonyPostfix]
17+
public static void HandleDebrisObjectEntryConfigurationsPostfix(
18+
MapItem item,
19+
MapUISelectableEntry obj
20+
)
21+
{
22+
string debrisName = ((object)item._itemName).ToString();
23+
var match = Regex.Match(debrisName, @"-(\d+)$");
24+
var newName = match.Success
25+
? Regex.Replace(debrisName, @"-\d+$", "")
26+
: debrisName;
27+
obj.Name = string.Format("Debris of {0}", newName);
28+
}
29+
30+
}
31+
}

0 commit comments

Comments
 (0)