Merge branch 'xen-42:dev' into dev

This commit is contained in:
TerrificTrifid 2022-08-10 00:05:40 -05:00 committed by GitHub
commit cc397f89fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 173 additions and 54 deletions

View File

@ -137,10 +137,12 @@ 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;
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))
{
@ -173,6 +175,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<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp);
var supernova = MakeSupernova(starGO, starModule);
@ -185,6 +188,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);

View File

@ -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;
@ -36,7 +39,6 @@ namespace NewHorizons.Components.SizeControllers
public float collapseTime = 10f; // seconds
public float lifespan = 22f; // minutes
private float _age;
private bool _isSupernova;
private float _supernovaStartTime;
@ -65,6 +67,9 @@ namespace NewHorizons.Components.SizeControllers
private void Start()
{
_rigidbody = this.GetAttachedOWRigidbody();
if (_rigidbody != null) _mapMarker = _rigidbody.GetComponent<MapMarker>();
var sun = GameObject.FindObjectOfType<SunController>();
_collapseStartSurfaceMaterial = new Material(sun._collapseStartSurfaceMaterial);
_collapseEndSurfaceMaterial = new Material(sun._collapseEndSurfaceMaterial);
@ -110,7 +115,7 @@ namespace NewHorizons.Components.SizeControllers
else
{
_endColour = EndColour.ToColor();
_endSurfaceMaterial.color = _startColour * 4.5948f;
_endSurfaceMaterial.color = _endColour * 4.5948f;
}
_heatVolume = GetComponentInChildren<HeatHazardVolume>();
@ -122,8 +127,6 @@ namespace NewHorizons.Components.SizeControllers
_atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren<MeshRenderer>();
}
if (WillExplode) GlobalMessenger.AddListener("TriggerSupernova", StartCollapse);
if (scaleCurve != null)
{
maxScale = scaleCurve.keys.Select(x => x.value).Max() * size;
@ -143,7 +146,6 @@ namespace NewHorizons.Components.SizeControllers
public void OnDestroy()
{
if (WillExplode) GlobalMessenger.RemoveListener("TriggerSupernova", StartCollapse);
}
public void SetProxy(StarEvolutionController proxy)
@ -157,8 +159,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)
@ -211,6 +213,22 @@ namespace NewHorizons.Components.SizeControllers
if (Time.time > _supernovaStartTime + 45f)
{
if (_rigidbody != null)
{
ReferenceFrameTracker referenceFrameTracker = Locator.GetPlayerBody().GetComponent<ReferenceFrameTracker>();
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);
}
@ -218,6 +236,8 @@ namespace NewHorizons.Components.SizeControllers
public void StartCollapse()
{
if (_isCollapsing) return;
Logger.LogVerbose($"{gameObject.transform.root.name} started collapse");
_isCollapsing = true;
@ -230,6 +250,8 @@ namespace NewHorizons.Components.SizeControllers
public void StopCollapse()
{
if (!_isCollapsing) return;
Logger.LogVerbose($"{gameObject.transform.root.name} stopped collapse");
_isCollapsing = false;
@ -240,6 +262,8 @@ namespace NewHorizons.Components.SizeControllers
public void StartSupernova()
{
if (_isSupernova) return;
Logger.LogVerbose($"{gameObject.transform.root.name} started supernova");
SupernovaStart.Invoke();
@ -248,10 +272,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 +295,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 +313,7 @@ namespace NewHorizons.Components.SizeControllers
{
base.FixedUpdate();
UpdateMainSequence();
if (WillExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) StartCollapse();
}
else
{

View File

@ -17,6 +17,17 @@ namespace NewHorizons.External.Configs
[JsonObject(Title = "Celestial Body")]
public class PlanetConfig
{
/// <summary>
/// Unique name of your planet
/// </summary>
[Required]
public string name;
/// <summary>
/// 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.
/// </summary>
[DefaultValue("SolarSystem")] public string starSystem = "SolarSystem";
/// <summary>
/// Generate asteroids around this body
/// </summary>
@ -45,7 +56,7 @@ namespace NewHorizons.External.Configs
/// <summary>
/// Should this planet ever be shown on the title screen?
/// </summary>
public bool canShowOnTitle = true;
[DefaultValue(true)] public bool canShowOnTitle = true;
#region Obsolete
@ -94,12 +105,6 @@ namespace NewHorizons.External.Configs
/// </summary>
public LavaModule Lava;
/// <summary>
/// Unique name of your planet
/// </summary>
[Required]
public string name;
/// <summary>
/// Describes this Body's orbit (or lack there of)
/// </summary>
@ -150,11 +155,6 @@ namespace NewHorizons.External.Configs
/// </summary>
public StarModule Star;
/// <summary>
/// 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.
/// </summary>
[DefaultValue("SolarSystem")] public string starSystem = "SolarSystem";
/// <summary>
/// Version of New Horizons this config is using (Doesn't do anything)
/// </summary>

View File

@ -35,6 +35,11 @@ namespace NewHorizons.External.Configs
/// </summary>
public string factRequiredForWarp;
/// <summary>
/// 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.
/// </summary>
[DefaultValue(22f)] public float loopDuration = 22f;
/// <summary>
/// Should the player not be able to view the map in this system?
/// </summary>
@ -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;

View File

@ -76,7 +76,6 @@ 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.
/// </summary>
[Range(0f, double.MaxValue)]
[DefaultValue(5000f)]
public float semiMajorAxis { get; set; }
/// <summary>

View File

@ -23,7 +23,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// Radius of the brackets that show up when you target this. Defaults to the sphere of influence.
/// </summary>
[DefaultValue(-1)] public float bracketRadius = -1;
[DefaultValue(-1f)] public float bracketRadius = -1f;
/// <summary>
/// If it should be targetable even when super close.

View File

@ -20,7 +20,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// Describe what this planet looks and like in map mode
/// </summary>
public MapModeInfo mapMode = new MapModeInfo();
public MapModeInfo mapMode;
/// <summary>
/// A path to the folder where entry sprites are stored.

View File

@ -9,15 +9,21 @@ namespace NewHorizons.External.Modules.VariableSize
public class StarModule : VariableSizeModule
{
/// <summary>
/// Colour of the star at the end of its life.
/// Colour of the star at the end of its lifespan.
/// </summary>
public MColor endTint;
/// <summary>
/// Should this star explode after 22 minutes?
/// Should this star explode at the end of its lifespan?
/// </summary>
[DefaultValue(true)] public bool goSupernova = true;
/// <summary>
/// How long in minutes this star will last until it supernovas.
/// </summary>
[DefaultValue(22f)]
public float lifespan = 22f;
/// <summary>
/// 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.
/// </summary>

View File

@ -31,6 +31,11 @@ namespace NewHorizons.Handlers
timeLoopController.AddComponent<TimeLoopController>();
}
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));

View File

@ -42,7 +42,7 @@ namespace NewHorizons
public static Dictionary<string, List<NewHorizonsBody>> BodyDict = new Dictionary<string, List<NewHorizonsBody>>();
public static List<IModBehaviour> MountedAddons = new List<IModBehaviour>();
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<OrbitalProbeLaunchController>();
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;
}

View File

@ -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;
}

View File

@ -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"
@ -32,7 +42,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",
@ -62,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"
@ -110,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)"
@ -2053,7 +2054,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",
@ -2284,14 +2285,20 @@
}
},
"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 in minutes 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.",

View File

@ -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 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
},
"mapRestricted": {
"type": "boolean",
"description": "Should the player not be able to view the map in this system?"

View File

@ -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
{

View File

@ -49,7 +49,7 @@ namespace NewHorizons.Utility.DebugUtilities
Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem);
Main.SecondsLeftInLoop = -1f;
Main.SecondsElapsedInLoop = -1f;
}
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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;
}
}