Skip to content

Commit 1b66a35

Browse files
authored
Merge pull request #57 from KSP2Community/dev
Version 0.15.0
2 parents 2b4b18f + 5b9afee commit 1b66a35

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

.idea/.idea.CommunityFixes/.idea/projectSettingsUpdater.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.

plugin_template/swinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Community Fixes",
66
"description": "Community project that aims to bring together bug fixes for KSP 2.",
77
"source": "https://github.com/KSP2Community/CommunityFixes",
8-
"version": "0.14.0",
8+
"version": "0.15.0",
99
"version_check": "https://raw.githubusercontent.com/KSP2Community/CommunityFixes/main/plugin_template/swinfo.json",
1010
"ksp2_version": {
1111
"min": "0.2.2",

src/CommunityFixes/Fix/DecoupledCraftNameFix/DecoupledCraftNameFix.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ private void HandleSeparationEvent(VesselComponent vessel1, VesselComponent vess
3939
{
4040
Logger.LogDebug($"Separated: {vessel1?.Name}, {vessel2?.Name}");
4141

42-
if (vessel2 is not { Name: var newName } ||
42+
if ((vessel2 is not { Name: var newName } ||
4343
!newName.StartsWith("Default Name") ||
44-
string.IsNullOrEmpty(vessel1?.Name))
44+
string.IsNullOrEmpty(vessel1?.Name)) &&
45+
vessel1.Name!=vessel2.Name)
4546
{
4647
return;
4748
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using HarmonyLib;
2+
using KSP.Map;
3+
using KSP.Sim.impl;
4+
5+
namespace CommunityFixes.Fix.TrackingStationDebrisNameFix
6+
{
7+
[Fix("Fix debris name in the tracking station")]
8+
internal class TrackingStationDebrisNameFix : BaseFix
9+
{
10+
private static SpaceWarp.API.Logging.ILogger _logger;
11+
public override void OnInitialized()
12+
{
13+
_logger = Logger;
14+
HarmonyInstance.PatchAll(typeof(TrackingStationDebrisNameFix));
15+
}
16+
17+
/**
18+
* Postfix the display of debris in the Tracking Station. Instead of displaying 'Debris: <GUID>', we display its formal name.
19+
***/
20+
[HarmonyPatch(typeof(MapUI), nameof(MapUI.HandleDebrisObjectEntryConfigurations))]
21+
[HarmonyPostfix]
22+
public static void HandleDebrisObjectEntryConfigurationsPostfix(
23+
MapItem item,
24+
MapUISelectableEntry obj
25+
)
26+
{
27+
obj.Name = ((object)item._itemName).ToString();
28+
}
29+
30+
/**
31+
* Postfix the creation of a new vessel. If it's a debris, we give it an appropriate name.
32+
**/
33+
[HarmonyPatch(typeof(SpaceSimulation), nameof(SpaceSimulation.CreateVesselSimObjectFromPart))]
34+
[HarmonyPostfix]
35+
public static void CreateVesselSimObjectFromPartPostfix(
36+
PartComponent rootPart,
37+
ref SimulationObjectModel __result
38+
)
39+
{
40+
System.Diagnostics.Debug.Write("requin");
41+
VesselComponent vessel = __result.FindComponent<VesselComponent>();
42+
if (!vessel._hasCommandModule)
43+
{
44+
renameVessel(vessel, "Unknown Debris");
45+
}
46+
}
47+
48+
/**
49+
* Postfix the decoupling of a vessel into two subvessels, renaming the debris (if such vessel exists) and keeping the original name for the subvessel with a command module (in case the original root part ends up being a debris).
50+
**/
51+
[HarmonyPatch(typeof(SpaceSimulation), nameof(SpaceSimulation.SplitCombinedVesselSimObject))]
52+
[HarmonyPostfix]
53+
public static void SplitCombinedVesselSimObjectPostfix(
54+
VesselComponent combinedVessel, // the vessel with the root part
55+
IGGuid detachingPartId,
56+
ref SimulationObjectModel __result
57+
)
58+
{
59+
System.Diagnostics.Debug.Write("albatros");
60+
VesselComponent vessel = __result.FindComponent<VesselComponent>(); // the new vessel splited from the vessel with the root part
61+
String originalVesselName = combinedVessel.Name.Replace("Debris of ", ""); // recreating the original vessel name by removing 'Debris of' (in case more than one linear decouplings happened at the same time)
62+
renameDebrisVessel(vessel, originalVesselName);
63+
renameDebrisVessel(combinedVessel, originalVesselName);
64+
if (vessel._hasCommandModule)
65+
{
66+
renameVessel(vessel, originalVesselName); // if a command module happens to be in the splitted vessel, we give it the name of the original vessel
67+
}
68+
}
69+
70+
/**
71+
* Rename the vessel as 'Debris of xxx' if it's a debris.
72+
**/
73+
private static void renameDebrisVessel(VesselComponent vessel, string originalVesselName)
74+
{
75+
if (vessel._hasCommandModule) return;
76+
renameVessel(vessel, "Debris of " + originalVesselName);
77+
}
78+
79+
/**
80+
* Rename the vessel with the specified name.
81+
***/
82+
private static void renameVessel(VesselComponent vessel, string newName)
83+
{
84+
System.Diagnostics.Debug.Write("Renaming " + vessel.SimulationObject.Name + " to " + newName);
85+
vessel.SimulationObject.Name = newName;
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)