From ca99200b6aed0b5a54951667fd990640ad70868c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 17:18:11 -0400 Subject: [PATCH 01/16] Fix defaults --- NewHorizons/External/Configs/PlanetConfig.cs | 2 +- NewHorizons/External/Modules/OrbitModule.cs | 2 +- NewHorizons/External/Modules/ReferenceFrameModule.cs | 2 +- NewHorizons/External/Modules/ShipLogModule.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index da59d6ee..97dd8858 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -45,7 +45,7 @@ namespace NewHorizons.External.Configs /// /// Should this planet ever be shown on the title screen? /// - public bool canShowOnTitle = true; + [DefaultValue(true)] public bool canShowOnTitle = true; #region Obsolete diff --git a/NewHorizons/External/Modules/OrbitModule.cs b/NewHorizons/External/Modules/OrbitModule.cs index 14a255a8..10e6a8c4 100644 --- a/NewHorizons/External/Modules/OrbitModule.cs +++ b/NewHorizons/External/Modules/OrbitModule.cs @@ -77,7 +77,7 @@ namespace NewHorizons.External.Modules /// [Range(0f, double.MaxValue)] [DefaultValue(5000f)] - public float semiMajorAxis { get; set; } + public float semiMajorAxis { get; set; } = 5000f; /// /// The angle (in degrees) between the body's orbit and the plane of the star system diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs index 12254866..61cba550 100644 --- a/NewHorizons/External/Modules/ReferenceFrameModule.cs +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -23,7 +23,7 @@ namespace NewHorizons.External.Modules /// /// Radius of the brackets that show up when you target this. Defaults to the sphere of influence. /// - [DefaultValue(-1)] public float bracketRadius = -1; + [DefaultValue(-1f)] public float bracketRadius = -1f; /// /// If it should be targetable even when super close. diff --git a/NewHorizons/External/Modules/ShipLogModule.cs b/NewHorizons/External/Modules/ShipLogModule.cs index 0e894a20..0d301df2 100644 --- a/NewHorizons/External/Modules/ShipLogModule.cs +++ b/NewHorizons/External/Modules/ShipLogModule.cs @@ -20,7 +20,7 @@ namespace NewHorizons.External.Modules /// /// Describe what this planet looks and like in map mode /// - public MapModeInfo mapMode = new MapModeInfo(); + public MapModeInfo mapMode; /// /// A path to the folder where entry sprites are stored. From c39a89d6389997fd0fd559dffc9039df21dc5e93 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 17:20:25 -0400 Subject: [PATCH 02/16] OKAY LETS NOT DO THAT Just broke solar system lol --- NewHorizons/External/Modules/OrbitModule.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/External/Modules/OrbitModule.cs b/NewHorizons/External/Modules/OrbitModule.cs index 10e6a8c4..a79677ce 100644 --- a/NewHorizons/External/Modules/OrbitModule.cs +++ b/NewHorizons/External/Modules/OrbitModule.cs @@ -76,8 +76,7 @@ namespace NewHorizons.External.Modules /// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius. /// [Range(0f, double.MaxValue)] - [DefaultValue(5000f)] - public float semiMajorAxis { get; set; } = 5000f; + public float semiMajorAxis { get; set; }; /// /// The angle (in degrees) between the body's orbit and the plane of the star system From c219f6bdf6d7740441ca148edd8f088984ad154d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 17:42:29 -0400 Subject: [PATCH 03/16] REEEEEE --- NewHorizons/External/Modules/OrbitModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/OrbitModule.cs b/NewHorizons/External/Modules/OrbitModule.cs index a79677ce..d6076378 100644 --- a/NewHorizons/External/Modules/OrbitModule.cs +++ b/NewHorizons/External/Modules/OrbitModule.cs @@ -76,7 +76,7 @@ namespace NewHorizons.External.Modules /// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius. /// [Range(0f, double.MaxValue)] - public float semiMajorAxis { get; set; }; + public float semiMajorAxis { get; set; } /// /// The angle (in degrees) between the body's orbit and the plane of the star system From f8d671e73762b7ba6a3223e5bed9367c6f483140 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 8 Aug 2022 21:45:00 +0000 Subject: [PATCH 04/16] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index e0054040..877762d0 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -32,7 +32,8 @@ }, "canShowOnTitle": { "type": "boolean", - "description": "Should this planet ever be shown on the title screen?" + "description": "Should this planet ever be shown on the title screen?", + "default": true }, "Cloak": { "description": "Add a cloaking field to this planet", @@ -814,7 +815,6 @@ "type": "number", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "format": "float", - "default": 5000.0, "minimum": 0.0 }, "inclination": { @@ -2022,7 +2022,7 @@ "type": "number", "description": "Radius of the brackets that show up when you target this. Defaults to the sphere of influence.", "format": "float", - "default": -1 + "default": -1.0 }, "targetWhenClose": { "type": "boolean", From 22f4063ca0a89e3f86f020d672101a44c85266f9 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 18:20:28 -0400 Subject: [PATCH 05/16] Schema should have default as 5000 though --- SchemaExporter/SchemaExporter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SchemaExporter/SchemaExporter.cs b/SchemaExporter/SchemaExporter.cs index 7b0634fd..f0c802f5 100644 --- a/SchemaExporter/SchemaExporter.cs +++ b/SchemaExporter/SchemaExporter.cs @@ -78,13 +78,18 @@ public static class SchemaExporter {"description", _description} }); + if (_title == "Celestial Body Schema") + { + schema.Definitions["OrbitModule"].Properties["semiMajorAxis"].Default = 5000f; + } + if (_title == "Star System Schema") { schema.Definitions["NomaiCoordinates"].Properties["x"].UniqueItems = true; schema.Definitions["NomaiCoordinates"].Properties["y"].UniqueItems = true; schema.Definitions["NomaiCoordinates"].Properties["z"].UniqueItems = true; } - + return schema; } } From c2483a32712dbadf6f7d40c50c05506375d2628b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 18:36:23 -0400 Subject: [PATCH 06/16] Serializer that uses tabs --- NewHorizons/Utility/DebugMenu/DebugMenu.cs | 4 +-- NewHorizons/Utility/NewHorizonExtensions.cs | 33 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Utility/DebugMenu/DebugMenu.cs b/NewHorizons/Utility/DebugMenu/DebugMenu.cs index e29601da..0d25ebfe 100644 --- a/NewHorizons/Utility/DebugMenu/DebugMenu.cs +++ b/NewHorizons/Utility/DebugMenu/DebugMenu.cs @@ -225,9 +225,7 @@ namespace NewHorizons.Utility.DebugMenu var relativePath = filePath.Replace(loadedMod.ModHelper.Manifest.ModFolderPath, ""); - var json = JsonConvert.SerializeObject(loadedConfigFiles[filePath], jsonSettings); - // Add the schema line - json = "{\n\t\"$schema\": \"https://raw.githubusercontent.com/xen-42/outer-wilds-new-horizons/main/NewHorizons/Schemas/body_schema.json\"," + json.Substring(1); + var json = loadedConfigFiles[filePath].ToSerializedJson(); try { diff --git a/NewHorizons/Utility/NewHorizonExtensions.cs b/NewHorizons/Utility/NewHorizonExtensions.cs index c41ba884..43548039 100644 --- a/NewHorizons/Utility/NewHorizonExtensions.cs +++ b/NewHorizons/Utility/NewHorizonExtensions.cs @@ -1,15 +1,48 @@ +using NewHorizons.External.Configs; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; using UnityEngine; using NomaiCoordinates = NewHorizons.External.Configs.StarSystemConfig.NomaiCoordinates; + namespace NewHorizons.Utility { public static class NewHorizonsExtensions { + private static JsonSerializer jsonSerializer = new JsonSerializer + { + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore, + Formatting = Formatting.Indented, + }; + + private static StringBuilder stringBuilder = new StringBuilder(); + + public static string ToSerializedJson(this PlanetConfig planetConfig) + { + string json = "{}"; + using (StringWriter stringWriter = new StringWriter(stringBuilder)) + { + using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter) + { + Formatting = Formatting.Indented, + IndentChar = '\t', + Indentation = 1 + }) + { + jsonSerializer.Serialize(jsonTextWriter, planetConfig); + json = "{\n\t\"$schema\": \"https://raw.githubusercontent.com/xen-42/outer-wilds-new-horizons/main/NewHorizons/Schemas/body_schema.json\"," + stringBuilder.ToString().Substring(1); + stringBuilder.Clear(); + } + } + return json; + } + public static MVector3 ToMVector3(this Vector3 vector3) { return new MVector3(vector3.x, vector3.y, vector3.z); From fc7b1ae498731e903aadbd4f53f8e21a18466ee0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 8 Aug 2022 22:39:20 +0000 Subject: [PATCH 07/16] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 877762d0..4b099793 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -815,6 +815,7 @@ "type": "number", "description": "The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.", "format": "float", + "default": 5000.0, "minimum": 0.0 }, "inclination": { From 6a790273fe5cc371572f53e3a7ac02829440b84e Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 18:56:21 -0400 Subject: [PATCH 08/16] Add star lifespan --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + .../StarEvolutionController.cs | 23 ++++++++++++------- .../Modules/VariableSize/StarModule.cs | 8 ++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index d3c2812c..d6a6c044 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -141,6 +141,7 @@ namespace NewHorizons.Builder.Body controller.StartColour = starModule.tint; controller.EndColour = starModule.endTint; controller.WillExplode = starModule.goSupernova; + controller.lifespan = starModule.lifespan; controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) { diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 1ae2d0d9..19405664 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -36,7 +36,6 @@ namespace NewHorizons.Components.SizeControllers public float collapseTime = 10f; // seconds public float lifespan = 22f; // minutes - private float _age; private bool _isSupernova; private float _supernovaStartTime; @@ -122,8 +121,6 @@ namespace NewHorizons.Components.SizeControllers _atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren(); } - if (WillExplode) GlobalMessenger.AddListener("TriggerSupernova", StartCollapse); - if (scaleCurve != null) { maxScale = scaleCurve.keys.Select(x => x.value).Max() * size; @@ -143,7 +140,6 @@ namespace NewHorizons.Components.SizeControllers public void OnDestroy() { - if (WillExplode) GlobalMessenger.RemoveListener("TriggerSupernova", StartCollapse); } public void SetProxy(StarEvolutionController proxy) @@ -157,8 +153,8 @@ namespace NewHorizons.Components.SizeControllers // Only do colour transition stuff if they set an end colour if (EndColour != null) { - // Use the age if theres no resizing happening, else make it get redder the larger it is or wtv - var t = _age / (lifespan * 60f); + // Use minutes elapsed if theres no resizing happening, else make it get redder the larger it is or wtv + var t = TimeLoop.GetMinutesElapsed() / lifespan; if (maxScale != minScale) t = Mathf.InverseLerp(minScale, maxScale, CurrentScale); if (t < 1f) @@ -218,6 +214,8 @@ namespace NewHorizons.Components.SizeControllers public void StartCollapse() { + if (_isCollapsing) return; + Logger.LogVerbose($"{gameObject.transform.root.name} started collapse"); _isCollapsing = true; @@ -230,6 +228,8 @@ namespace NewHorizons.Components.SizeControllers public void StopCollapse() { + if (!_isCollapsing) return; + Logger.LogVerbose($"{gameObject.transform.root.name} stopped collapse"); _isCollapsing = false; @@ -240,6 +240,8 @@ namespace NewHorizons.Components.SizeControllers public void StartSupernova() { + if (_isSupernova) return; + Logger.LogVerbose($"{gameObject.transform.root.name} started supernova"); SupernovaStart.Invoke(); @@ -248,10 +250,14 @@ namespace NewHorizons.Components.SizeControllers _supernovaStartTime = Time.time; if (atmosphere != null) atmosphere.SetActive(false); if (_destructionVolume != null) _destructionVolume._deathType = DeathType.Supernova; + + if (_proxy != null) _proxy.StartSupernova(); } public void StopSupernova() { + if (!_isSupernova) return; + Logger.LogVerbose($"{gameObject.transform.root.name} stopped supernova"); supernova.enabled = false; @@ -267,12 +273,12 @@ namespace NewHorizons.Components.SizeControllers transform.localScale = Vector3.one; supernova._surface._materials[0] = _surfaceMaterial; supernova._surface.transform.localScale = Vector3.one; + + if (_proxy != null) _proxy.StopSupernova(); } protected new void FixedUpdate() { - _age += Time.deltaTime; - // If we've gone supernova and its been 45 seconds that means it has faded out and is gone // The 45 is from the animation curve used for the supernova alpha if (_isSupernova) @@ -285,6 +291,7 @@ namespace NewHorizons.Components.SizeControllers { base.FixedUpdate(); UpdateMainSequence(); + if (WillExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) StartCollapse(); } else { diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index ea303ab0..e09db355 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -17,7 +17,13 @@ namespace NewHorizons.External.Modules.VariableSize /// Should this star explode after 22 minutes? /// [DefaultValue(true)] public bool goSupernova = true; - + + /// + /// How long this star will last until it supernovas. + /// + [DefaultValue(22f)] + public float lifespan = 22f; + /// /// Should we add a star controller to this body? If you want clouds to work on a binary brown dwarf system, set this to false. /// From 723f74f763da0335f6fc06433a13b3900e1517d7 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 19:05:41 -0400 Subject: [PATCH 09/16] Update star proxy to be same as star --- NewHorizons/Builder/Body/StarBuilder.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index d6a6c044..e5b6e664 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -174,6 +174,7 @@ namespace NewHorizons.Builder.Body public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod) { var starGO = MakeStarGraphics(proxyGO, null, starModule, mod); + var ramp = starGO.GetComponentInChildren().sharedMaterial.GetTexture(ColorRamp); var supernova = MakeSupernova(starGO, starModule); @@ -186,6 +187,13 @@ namespace NewHorizons.Builder.Body controller.supernova = supernova; controller.StartColour = starModule.tint; controller.EndColour = starModule.endTint; + controller.WillExplode = starModule.goSupernova; + controller.lifespan = starModule.lifespan; + controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; + if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) + { + controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); + } controller.enabled = true; starGO.SetActive(true); From b60b384a8a7b26a890c5a620794f6b16d6a64b6c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 21:04:04 -0400 Subject: [PATCH 10/16] Add customizable loop duration --- NewHorizons/External/Configs/StarSystemConfig.cs | 6 ++++++ NewHorizons/Handlers/SystemCreationHandler.cs | 5 +++++ NewHorizons/Main.cs | 14 +++++++------- NewHorizons/Patches/NomaiCoordinatePatches.cs | 2 +- NewHorizons/Utility/DebugUtilities/DebugReload.cs | 2 +- NewHorizons/Utility/TimeLoopUtilities.cs | 15 +++++++++++++++ 6 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 NewHorizons/Utility/TimeLoopUtilities.cs diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index aceadf96..3476f5a6 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -35,6 +35,11 @@ namespace NewHorizons.External.Configs /// public string factRequiredForWarp; + /// + /// The duration of the time loop. + /// + [DefaultValue(22f)] public float loopDuration = 22f; + /// /// Should the player not be able to view the map in this system? /// @@ -209,6 +214,7 @@ namespace NewHorizons.External.Configs canEnterViaWarpDrive = canEnterViaWarpDrive && otherConfig.canEnterViaWarpDrive; destroyStockPlanets = destroyStockPlanets && otherConfig.destroyStockPlanets; enableTimeLoop = enableTimeLoop && otherConfig.enableTimeLoop; + loopDuration = loopDuration == 22f ? otherConfig.loopDuration : loopDuration; // If current one is null take the other factRequiredForWarp = string.IsNullOrEmpty(factRequiredForWarp) ? otherConfig.factRequiredForWarp : factRequiredForWarp; diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index bd69d0cb..16df0230 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -31,6 +31,11 @@ namespace NewHorizons.Handlers timeLoopController.AddComponent(); } + if (system.Config.loopDuration != 22f) + { + TimeLoopUtilities.SetLoopDuration(system.Config.loopDuration); + } + if (!string.IsNullOrEmpty(system.Config.travelAudio)) { Delay.FireOnNextUpdate(() => AudioUtilities.SetAudioClip(Locator.GetGlobalMusicController()._travelSource, system.Config.travelAudio, system.Mod)); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index c40df73c..5635bdd3 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -42,7 +42,7 @@ namespace NewHorizons public static Dictionary> BodyDict = new Dictionary>(); public static List MountedAddons = new List(); - public static float SecondsLeftInLoop = -1; + public static float SecondsElapsedInLoop = -1; public static bool IsSystemReady { get; private set; } public static float FurthestOrbit { get; set; } = 50000f; @@ -239,9 +239,9 @@ namespace NewHorizons } // Set time loop stuff if its enabled and if we're warping to a new place - if (IsChangingStarSystem && (SystemDict[_currentStarSystem].Config.enableTimeLoop || _currentStarSystem == "SolarSystem") && SecondsLeftInLoop > 0f) + if (IsChangingStarSystem && (SystemDict[_currentStarSystem].Config.enableTimeLoop || _currentStarSystem == "SolarSystem") && SecondsElapsedInLoop > 0f) { - TimeLoop.SetSecondsRemaining(SecondsLeftInLoop); + TimeLoopUtilities.SetSecondsElapsed(SecondsElapsedInLoop); // Prevent the OPC from firing var launchController = GameObject.FindObjectOfType(); if (launchController != null) @@ -258,7 +258,7 @@ namespace NewHorizons } // Reset this - SecondsLeftInLoop = -1; + SecondsElapsedInLoop = -1; IsChangingStarSystem = false; @@ -607,13 +607,13 @@ namespace NewHorizons if (newStarSystem == "EyeOfTheUniverse") { - PlayerData.SaveWarpedToTheEye(TimeLoop.GetSecondsRemaining()); + PlayerData.SaveWarpedToTheEye(TimeLoopUtilities.GetVanillaSecondsRemaining()); sceneToLoad = OWScene.EyeOfTheUniverse; } else { - if (SystemDict[_currentStarSystem].Config.enableTimeLoop) SecondsLeftInLoop = TimeLoop.GetSecondsRemaining(); - else SecondsLeftInLoop = -1; + if (SystemDict[_currentStarSystem].Config.enableTimeLoop) SecondsElapsedInLoop = TimeLoop.GetSecondsElapsed(); + else SecondsElapsedInLoop = -1; sceneToLoad = OWScene.SolarSystem; } diff --git a/NewHorizons/Patches/NomaiCoordinatePatches.cs b/NewHorizons/Patches/NomaiCoordinatePatches.cs index 1814b9a1..98f39af2 100644 --- a/NewHorizons/Patches/NomaiCoordinatePatches.cs +++ b/NewHorizons/Patches/NomaiCoordinatePatches.cs @@ -24,7 +24,7 @@ namespace NewHorizons.Patches VesselWarpController.s_playerWarpLocation = new RelativeLocationData(Locator.GetPlayerBody(), __instance.transform); VesselWarpController.s_relativeLocationSaved = !debugWarp; if (!Main.Instance.IsWarpingFromVessel) - PlayerData.SaveWarpedToTheEye(TimeLoop.GetSecondsRemaining()); + PlayerData.SaveWarpedToTheEye(TimeLoopUtilities.GetVanillaSecondsRemaining()); LoadManager.EnableAsyncLoadTransition(); return false; } diff --git a/NewHorizons/Utility/DebugUtilities/DebugReload.cs b/NewHorizons/Utility/DebugUtilities/DebugReload.cs index eaa09373..b8a513c9 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugReload.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugReload.cs @@ -49,7 +49,7 @@ namespace NewHorizons.Utility.DebugUtilities Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); - Main.SecondsLeftInLoop = -1f; + Main.SecondsElapsedInLoop = -1f; } } } \ No newline at end of file diff --git a/NewHorizons/Utility/TimeLoopUtilities.cs b/NewHorizons/Utility/TimeLoopUtilities.cs new file mode 100644 index 00000000..9af60051 --- /dev/null +++ b/NewHorizons/Utility/TimeLoopUtilities.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace NewHorizons.Utility +{ + public static class TimeLoopUtilities + { + public const float LOOP_DURATION_IN_SECONDS = TimeLoop.LOOP_DURATION_IN_MINUTES * 60; + public static void SetLoopDuration(float minutes) => TimeLoop._loopDuration = minutes * 60f; + public static void SetSecondsElapsed(float secondsElapsed) => TimeLoop._timeOffset = secondsElapsed - Time.timeSinceLevelLoad; + public static float GetMinutesRemaining() => TimeLoop.GetSecondsRemaining() / 60f; + public static float GetVanillaSecondsRemaining() => LOOP_DURATION_IN_SECONDS - TimeLoop.GetSecondsElapsed(); + public static float GetVanillaMinutesRemaining() => GetVanillaSecondsRemaining() / 60f; + public static float GetVanillaFractionElapsed() => TimeLoop.GetSecondsElapsed() / LOOP_DURATION_IN_SECONDS; + } +} From a5b14591f3e62bb9e704ff811172d0ce580f2bb1 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 22:07:00 -0400 Subject: [PATCH 11/16] Move these so that they are on top when serializing --- NewHorizons/External/Configs/PlanetConfig.cs | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 97dd8858..057aba8f 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -17,6 +17,17 @@ namespace NewHorizons.External.Configs [JsonObject(Title = "Celestial Body")] public class PlanetConfig { + /// + /// Unique name of your planet + /// + [Required] + public string name; + + /// + /// Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system. + /// + [DefaultValue("SolarSystem")] public string starSystem = "SolarSystem"; + /// /// Generate asteroids around this body /// @@ -94,12 +105,6 @@ namespace NewHorizons.External.Configs /// public LavaModule Lava; - /// - /// Unique name of your planet - /// - [Required] - public string name; - /// /// Describes this Body's orbit (or lack there of) /// @@ -150,11 +155,6 @@ namespace NewHorizons.External.Configs /// public StarModule Star; - /// - /// Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system. - /// - [DefaultValue("SolarSystem")] public string starSystem = "SolarSystem"; - /// /// Version of New Horizons this config is using (Doesn't do anything) /// From cbc82755873d71a72fe283e1cd161a93ad8d986d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Mon, 8 Aug 2022 23:28:22 -0400 Subject: [PATCH 12/16] Turn off reference frame and map marker for dead stars --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + .../StarEvolutionController.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index e5b6e664..829be8e0 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -137,6 +137,7 @@ namespace NewHorizons.Builder.Body if (starModule.curve != null) controller.SetScaleCurve(starModule.curve); controller.size = starModule.size; controller.atmosphere = sunAtmosphere; + controller.controller = starController; controller.supernova = supernova; controller.StartColour = starModule.tint; controller.EndColour = starModule.endTint; diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 19405664..322dd211 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -14,6 +14,7 @@ namespace NewHorizons.Components.SizeControllers public class StarEvolutionController : SizeController { public GameObject atmosphere; + public StarController controller; public SupernovaEffectController supernova; public bool WillExplode { get; set; } public MColor StartColour { get; set; } @@ -29,6 +30,8 @@ namespace NewHorizons.Components.SizeControllers private HeatHazardVolume _heatVolume; private DestructionVolume _destructionVolume; private SolarFlareEmitter _flareEmitter; + private MapMarker _mapMarker; + private OWRigidbody _rigidbody; private bool _isCollapsing; private float _collapseStartSize; @@ -64,6 +67,9 @@ namespace NewHorizons.Components.SizeControllers private void Start() { + _rigidbody = this.GetAttachedOWRigidbody(); + if (_rigidbody != null) _mapMarker = _rigidbody.GetComponent(); + var sun = GameObject.FindObjectOfType(); _collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial); _collapseEndSurfaceMaterial = new Material(sun._collapseEndSurfaceMaterial); @@ -207,6 +213,22 @@ namespace NewHorizons.Components.SizeControllers if (Time.time > _supernovaStartTime + 45f) { + if (_rigidbody != null) + { + ReferenceFrameTracker referenceFrameTracker = Locator.GetPlayerBody().GetComponent(); + if (referenceFrameTracker.GetReferenceFrame() != null && referenceFrameTracker.GetReferenceFrame().GetOWRigidBody() == _rigidbody) referenceFrameTracker.UntargetReferenceFrame(); + _rigidbody._isTargetable = false; + if (_rigidbody._attachedRFVolume != null) + { + _rigidbody._attachedRFVolume._minColliderRadius = 0; + _rigidbody._attachedRFVolume._maxColliderRadius = 0; + } + } + + if (_mapMarker != null) _mapMarker.DisableMarker(); + + if (controller != null) StarLightController.RemoveStar(controller); + // Just turn off the star entirely base.gameObject.SetActive(false); } From e470e7ecb41741e969733e6bd62a1c30328f63f2 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Tue, 9 Aug 2022 01:12:54 -0400 Subject: [PATCH 13/16] Use end colour Not sure why it didn't --- .../Components/SizeControllers/StarEvolutionController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 322dd211..dace3105 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -115,7 +115,7 @@ namespace NewHorizons.Components.SizeControllers else { _endColour = EndColour.ToColor(); - _endSurfaceMaterial.color = _startColour * 4.5948f; + _endSurfaceMaterial.color = _endColour * 4.5948f; } _heatVolume = GetComponentInChildren(); From bd034dbaa8e15cc7360c0690485ce38cfe63ce0e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 9 Aug 2022 05:42:53 +0000 Subject: [PATCH 14/16] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 26 +++++++++++++-------- NewHorizons/Schemas/star_system_schema.json | 6 +++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 4b099793..5201b710 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -8,6 +8,16 @@ "name" ], "properties": { + "name": { + "type": "string", + "description": "Unique name of your planet", + "minLength": 1 + }, + "starSystem": { + "type": "string", + "description": "Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system.", + "default": "SolarSystem" + }, "AsteroidBelt": { "description": "Generate asteroids around this body", "$ref": "#/definitions/AsteroidBeltModule" @@ -63,11 +73,6 @@ "description": "Add lava to this planet", "$ref": "#/definitions/LavaModule" }, - "name": { - "type": "string", - "description": "Unique name of your planet", - "minLength": 1 - }, "Orbit": { "description": "Describes this Body's orbit (or lack there of)", "$ref": "#/definitions/OrbitModule" @@ -111,11 +116,6 @@ "description": "Make this body a star", "$ref": "#/definitions/StarModule" }, - "starSystem": { - "type": "string", - "description": "Unique star system containing your planet. If you set this to be a custom solar system remember to add a Spawn module to one of the bodies, or else you can't get to the system.", - "default": "SolarSystem" - }, "version": { "type": "string", "description": "Version of New Horizons this config is using (Doesn't do anything)" @@ -2262,6 +2262,12 @@ "description": "Should this star explode after 22 minutes?", "default": true }, + "lifespan": { + "type": "number", + "description": "How long this star will last until it supernovas.", + "format": "float", + "default": 22.0 + }, "hasStarController": { "type": "boolean", "description": "Should we add a star controller to this body? If you want clouds to work on a binary brown dwarf system, set this to false.", diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 4f3a5805..47a2b787 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -24,6 +24,12 @@ "type": "string", "description": "Set to the FactID that must be revealed before it can be warped to. Don't set `CanEnterViaWarpDrive` to `false` if\nyou're using this, that would make no sense." }, + "loopDuration": { + "type": "number", + "description": "The duration of the time loop.", + "format": "float", + "default": 22.0 + }, "mapRestricted": { "type": "boolean", "description": "Should the player not be able to view the map in this system?" From 9be4ec77bf252b4549c70d9f01e2854c9926b155 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 10 Aug 2022 00:30:13 -0400 Subject: [PATCH 15/16] Specify --- NewHorizons/External/Configs/StarSystemConfig.cs | 2 +- NewHorizons/External/Modules/VariableSize/StarModule.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index 3476f5a6..afc84992 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -36,7 +36,7 @@ namespace NewHorizons.External.Configs public string factRequiredForWarp; /// - /// The duration of the time loop. + /// The duration of the time loop in minutes. This is the time the sun explodes. End Times plays 85 seconds before this time, and your memories get sent back about 40 seconds after this time. /// [DefaultValue(22f)] public float loopDuration = 22f; diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index e09db355..f9c841f9 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -9,17 +9,17 @@ namespace NewHorizons.External.Modules.VariableSize public class StarModule : VariableSizeModule { /// - /// Colour of the star at the end of its life. + /// Colour of the star at the end of its lifespan. /// public MColor endTint; /// - /// Should this star explode after 22 minutes? + /// Should this star explode at the end of its lifespan? /// [DefaultValue(true)] public bool goSupernova = true; /// - /// How long this star will last until it supernovas. + /// How long in minutes this star will last until it supernovas. /// [DefaultValue(22f)] public float lifespan = 22f; From fcd4744ed21509bfc43bae2aeb2463cee6da8e8c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 10 Aug 2022 04:32:04 +0000 Subject: [PATCH 16/16] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 +++--- NewHorizons/Schemas/star_system_schema.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5201b710..20b946d5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2254,17 +2254,17 @@ } }, "endTint": { - "description": "Colour of the star at the end of its life.", + "description": "Colour of the star at the end of its lifespan.", "$ref": "#/definitions/MColor" }, "goSupernova": { "type": "boolean", - "description": "Should this star explode after 22 minutes?", + "description": "Should this star explode at the end of its lifespan?", "default": true }, "lifespan": { "type": "number", - "description": "How long this star will last until it supernovas.", + "description": "How long in minutes this star will last until it supernovas.", "format": "float", "default": 22.0 }, diff --git a/NewHorizons/Schemas/star_system_schema.json b/NewHorizons/Schemas/star_system_schema.json index 47a2b787..67527e2b 100644 --- a/NewHorizons/Schemas/star_system_schema.json +++ b/NewHorizons/Schemas/star_system_schema.json @@ -26,7 +26,7 @@ }, "loopDuration": { "type": "number", - "description": "The duration of the time loop.", + "description": "The duration of the time loop in minutes. This is the time the sun explodes. End Times plays 85 seconds before this time, and your memories get sent back about 40 seconds after this time.", "format": "float", "default": 22.0 },