Move vessel config to its own module

This commit is contained in:
Joshua Thome 2022-07-23 19:22:14 -05:00
parent d7c1812741
commit d5a4ca2fa1
5 changed files with 81 additions and 37 deletions

View File

@ -69,28 +69,23 @@ namespace NewHorizons.External.Configs
public string travelAudio; public string travelAudio;
/// <summary> /// <summary>
/// Coordinates that the vessel can use to warp to your solar system. /// Configure warping to this system with the vessel
/// </summary> /// </summary>
public VesselModule Vessel;
[Obsolete("coords is deprecated, please use Vessel.coords instead")]
public NomaiCoordinates coords; public NomaiCoordinates coords;
/// <summary> [Obsolete("vesselPosition is deprecated, please use Vessel.vesselPosition instead")]
/// The position in the solar system the vessel will warp to.
/// </summary>
public MVector3 vesselPosition; public MVector3 vesselPosition;
/// <summary> [Obsolete("vesselRotation is deprecated, please use Vessel.vesselRotation instead")]
/// Euler angles by which the vessel will be oriented.
/// </summary>
public MVector3 vesselRotation; public MVector3 vesselRotation;
/// <summary> [Obsolete("warpExitPosition is deprecated, please use Vessel.warpExitPosition instead")]
/// The relative position to the vessel that you will be teleported to when you exit the vessel through the black hole.
/// </summary>
public MVector3 warpExitPosition; public MVector3 warpExitPosition;
/// <summary> [Obsolete("warpExitRotation is deprecated, please use Vessel.warpExitRotation instead")]
/// Euler angles by which the warp exit will be oriented.
/// </summary>
public MVector3 warpExitRotation; public MVector3 warpExitRotation;
/// <summary> /// <summary>
@ -189,6 +184,35 @@ namespace NewHorizons.External.Configs
public string backPath; public string backPath;
} }
[JsonObject]
public class VesselModule
{
/// <summary>
/// Coordinates that the vessel can use to warp to your solar system.
/// </summary>
public NomaiCoordinates coords;
/// <summary>
/// The position in the solar system the vessel will warp to.
/// </summary>
public MVector3 vesselPosition;
/// <summary>
/// Euler angles by which the vessel will be oriented.
/// </summary>
public MVector3 vesselRotation;
/// <summary>
/// The relative position to the vessel that you will be teleported to when you exit the vessel through the black hole.
/// </summary>
public MVector3 warpExitPosition;
/// <summary>
/// Euler angles by which the warp exit will be oriented.
/// </summary>
public MVector3 warpExitRotation;
}
/// <summary> /// <summary>
/// Makes sure they are all numbers are unique and between 0 and 5. /// Makes sure they are all numbers are unique and between 0 and 5.
/// </summary> /// </summary>
@ -196,11 +220,11 @@ namespace NewHorizons.External.Configs
public void FixCoordinates() public void FixCoordinates()
{ {
if (coords != null) if (Vessel?.coords != null)
{ {
coords.x = FixAxis(coords.x); Vessel.coords.x = FixAxis(Vessel.coords.x);
coords.y = FixAxis(coords.y); Vessel.coords.y = FixAxis(Vessel.coords.y);
coords.z = FixAxis(coords.z); Vessel.coords.z = FixAxis(Vessel.coords.z);
} }
} }
@ -226,6 +250,8 @@ namespace NewHorizons.External.Configs
mapRestricted = mapRestricted || otherConfig.mapRestricted; mapRestricted = mapRestricted || otherConfig.mapRestricted;
startHere = startHere || otherConfig.startHere; startHere = startHere || otherConfig.startHere;
Vessel = Vessel == null ? otherConfig.Vessel : Vessel;
entryPositions = Concatenate(entryPositions, otherConfig.entryPositions); entryPositions = Concatenate(entryPositions, otherConfig.entryPositions);
curiosities = Concatenate(curiosities, otherConfig.curiosities); curiosities = Concatenate(curiosities, otherConfig.curiosities);
initialReveal = Concatenate(initialReveal, otherConfig.initialReveal); initialReveal = Concatenate(initialReveal, otherConfig.initialReveal);
@ -251,6 +277,18 @@ namespace NewHorizons.External.Configs
Skybox.destroyStarField = skybox.destroyStarField; Skybox.destroyStarField = skybox.destroyStarField;
} }
} }
if (coords != null || vesselPosition != null || vesselRotation != null || warpExitPosition != null || warpExitRotation != null)
{
if (Vessel == null)
{
Vessel = new VesselModule();
}
Vessel.coords = Vessel.coords ?? coords;
Vessel.vesselPosition = Vessel.vesselPosition ?? vesselPosition;
Vessel.vesselRotation = Vessel.vesselRotation ?? vesselRotation;
Vessel.warpExitPosition = Vessel.warpExitPosition ?? warpExitPosition;
Vessel.warpExitRotation = Vessel.warpExitRotation ?? warpExitRotation;
}
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace NewHorizons.Handlers
{ {
var systemName = system.UniqueID; var systemName = system.UniqueID;
var fact = system.Config.factRequiredForWarp; var fact = system.Config.factRequiredForWarp;
var nomaiCoords = system.Config.coords; var nomaiCoords = system.Config.Vessel?.coords;
if (system.UniqueID == "EyeOfTheUniverse" || nomaiCoords == null) continue; if (system.UniqueID == "EyeOfTheUniverse" || nomaiCoords == null) continue;

View File

@ -88,11 +88,11 @@ namespace NewHorizons.Handlers
vesselOrbLocker.InitializeOrbs(); vesselOrbLocker.InitializeOrbs();
vesselOrbLocker.AddLocks(); vesselOrbLocker.AddLocks();
if (system.Config.vesselPosition != null) if (system.Config.Vessel?.vesselPosition != null)
vesselObject.transform.position = system.Config.vesselPosition; vesselObject.transform.position = system.Config.Vessel.vesselPosition;
if (system.Config.vesselRotation != null) if (system.Config.Vessel?.vesselRotation != null)
vesselObject.transform.eulerAngles = system.Config.vesselRotation; vesselObject.transform.eulerAngles = system.Config.Vessel.vesselRotation;
vesselOrbLocker.RemoveLocks(); vesselOrbLocker.RemoveLocks();
vesselOrbLocker.AddLockToWarpOrb(); vesselOrbLocker.AddLockToWarpOrb();
@ -142,11 +142,11 @@ namespace NewHorizons.Handlers
vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody; vesselWarpController._targetWarpPlatform.OnReceiveWarpedBody += OnReceiveWarpedBody;
if (system.Config.warpExitPosition != null) if (system.Config.Vessel?.warpExitPosition != null)
vesselWarpController._targetWarpPlatform.transform.localPosition = system.Config.warpExitPosition; vesselWarpController._targetWarpPlatform.transform.localPosition = system.Config.Vessel.warpExitPosition;
if (system.Config.warpExitRotation != null) if (system.Config.Vessel?.warpExitRotation != null)
vesselWarpController._targetWarpPlatform.transform.localEulerAngles = system.Config.warpExitRotation; vesselWarpController._targetWarpPlatform.transform.localEulerAngles = system.Config.Vessel.warpExitRotation;
vesselObject.GetComponent<MapMarker>()._labelID = (UITextType)TranslationHandler.AddUI("VESSEL"); vesselObject.GetComponent<MapMarker>()._labelID = (UITextType)TranslationHandler.AddUI("VESSEL");

View File

@ -127,6 +127,8 @@ namespace NewHorizons
Config = Config =
{ {
destroyStockPlanets = false, destroyStockPlanets = false,
Vessel = new StarSystemConfig.VesselModule()
{
coords = new StarSystemConfig.NomaiCoordinates coords = new StarSystemConfig.NomaiCoordinates
{ {
x = new int[5]{ 0,3,2,1,5 }, x = new int[5]{ 0,3,2,1,5 },
@ -134,10 +136,13 @@ namespace NewHorizons
z = new int[5]{ 4,1,2,5,0 } z = new int[5]{ 4,1,2,5,0 }
} }
} }
}
}; };
SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), Instance) SystemDict["EyeOfTheUniverse"] = new NewHorizonsSystem("EyeOfTheUniverse", new StarSystemConfig(), Instance)
{ {
Config = Config =
{
Vessel = new StarSystemConfig.VesselModule()
{ {
coords = new StarSystemConfig.NomaiCoordinates coords = new StarSystemConfig.NomaiCoordinates
{ {
@ -146,6 +151,7 @@ namespace NewHorizons
z = new int[6]{ 1,2,3,0,5,4 } z = new int[6]{ 1,2,3,0,5,4 }
} }
} }
}
}; };
if (!resetTranslation) return; if (!resetTranslation) return;
@ -340,7 +346,7 @@ namespace NewHorizons
else if (shouldWarpInFromVessel) VesselWarpHandler.TeleportToVessel(); else if (shouldWarpInFromVessel) VesselWarpHandler.TeleportToVessel();
else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint); else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint);
VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.coords != null).Select(x => x.Value).ToList()); VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(x => x.Value).ToList());
} }
public void EnableWarpDrive() public void EnableWarpDrive()

View File

@ -158,11 +158,11 @@ namespace NewHorizons.Utility
return transform.rotation * localRotation; return transform.rotation * localRotation;
} }
public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface) => Main.SystemDict.Where(system => system.Value.Config.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.coords)).Any(system => nomaiCoordinateInterface.CheckCoordinates(system.Key, system.Value)); public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface) => Main.SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.Vessel.coords)).Any(system => nomaiCoordinateInterface.CheckCoordinates(system.Key, system.Value));
public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface, out string selectedSystem) public static bool CheckAllCoordinates(this NomaiCoordinateInterface nomaiCoordinateInterface, out string selectedSystem)
{ {
foreach (KeyValuePair<string, NomaiCoordinates> cbs in Main.SystemDict.Where(system => system.Value.Config.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.coords))) foreach (KeyValuePair<string, NomaiCoordinates> cbs in Main.SystemDict.Where(system => system.Value.Config.Vessel?.coords != null).Select(system => new KeyValuePair<string, NomaiCoordinates>(system.Key, system.Value.Config.Vessel.coords)))
{ {
if (CheckCoordinates(nomaiCoordinateInterface, cbs.Key, cbs.Value)) if (CheckCoordinates(nomaiCoordinateInterface, cbs.Key, cbs.Value))
{ {