-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from pasalvetti/main
Fix debris name in the Tracking Station
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/CommunityFixes/Fix/TrackingStationDebrisNameFix/TrackingStationDebrisNameFix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} |