Skip to content

Commit

Permalink
Merge pull request #57 from KSP2Community/dev
Browse files Browse the repository at this point in the history
Version 0.15.0
  • Loading branch information
jan-bures authored Sep 28, 2024
2 parents 2b4b18f + 5b9afee commit 1b66a35
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 1 addition & 1 deletion plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Community Fixes",
"description": "Community project that aims to bring together bug fixes for KSP 2.",
"source": "https://github.com/KSP2Community/CommunityFixes",
"version": "0.14.0",
"version": "0.15.0",
"version_check": "https://raw.githubusercontent.com/KSP2Community/CommunityFixes/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ private void HandleSeparationEvent(VesselComponent vessel1, VesselComponent vess
{
Logger.LogDebug($"Separated: {vessel1?.Name}, {vessel2?.Name}");

if (vessel2 is not { Name: var newName } ||
if ((vessel2 is not { Name: var newName } ||
!newName.StartsWith("Default Name") ||
string.IsNullOrEmpty(vessel1?.Name))
string.IsNullOrEmpty(vessel1?.Name)) &&
vessel1.Name!=vessel2.Name)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using HarmonyLib;
using KSP.Map;
using KSP.Sim.impl;

namespace CommunityFixes.Fix.TrackingStationDebrisNameFix
{
[Fix("Fix debris name in the tracking station")]
internal class TrackingStationDebrisNameFix : BaseFix
{
private static SpaceWarp.API.Logging.ILogger _logger;
public override void OnInitialized()
{
_logger = Logger;
HarmonyInstance.PatchAll(typeof(TrackingStationDebrisNameFix));
}

/**
* Postfix the display of debris in the Tracking Station. Instead of displaying 'Debris: <GUID>', we display its formal name.
***/
[HarmonyPatch(typeof(MapUI), nameof(MapUI.HandleDebrisObjectEntryConfigurations))]
[HarmonyPostfix]
public static void HandleDebrisObjectEntryConfigurationsPostfix(
MapItem item,
MapUISelectableEntry obj
)
{
obj.Name = ((object)item._itemName).ToString();
}

/**
* Postfix the creation of a new vessel. If it's a debris, we give it an appropriate name.
**/
[HarmonyPatch(typeof(SpaceSimulation), nameof(SpaceSimulation.CreateVesselSimObjectFromPart))]
[HarmonyPostfix]
public static void CreateVesselSimObjectFromPartPostfix(
PartComponent rootPart,
ref SimulationObjectModel __result
)
{
System.Diagnostics.Debug.Write("requin");
VesselComponent vessel = __result.FindComponent<VesselComponent>();
if (!vessel._hasCommandModule)
{
renameVessel(vessel, "Unknown Debris");
}
}

/**
* 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).
**/
[HarmonyPatch(typeof(SpaceSimulation), nameof(SpaceSimulation.SplitCombinedVesselSimObject))]
[HarmonyPostfix]
public static void SplitCombinedVesselSimObjectPostfix(
VesselComponent combinedVessel, // the vessel with the root part
IGGuid detachingPartId,
ref SimulationObjectModel __result
)
{
System.Diagnostics.Debug.Write("albatros");
VesselComponent vessel = __result.FindComponent<VesselComponent>(); // the new vessel splited from the vessel with the root part
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)
renameDebrisVessel(vessel, originalVesselName);
renameDebrisVessel(combinedVessel, originalVesselName);
if (vessel._hasCommandModule)
{
renameVessel(vessel, originalVesselName); // if a command module happens to be in the splitted vessel, we give it the name of the original vessel
}
}

/**
* Rename the vessel as 'Debris of xxx' if it's a debris.
**/
private static void renameDebrisVessel(VesselComponent vessel, string originalVesselName)
{
if (vessel._hasCommandModule) return;
renameVessel(vessel, "Debris of " + originalVesselName);
}

/**
* Rename the vessel with the specified name.
***/
private static void renameVessel(VesselComponent vessel, string newName)
{
System.Diagnostics.Debug.Write("Renaming " + vessel.SimulationObject.Name + " to " + newName);
vessel.SimulationObject.Name = newName;
}
}
}

0 comments on commit 1b66a35

Please sign in to comment.