Merge pull request #73 from xen-42/dev

0.10.0
This commit is contained in:
Nick 2022-03-23 00:04:27 -04:00 committed by GitHub
commit aa0bba7719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 442 additions and 109 deletions

View File

@ -0,0 +1,44 @@
using NewHorizons.Components;
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Builder.Body
{
static class CloakBuilder
{
public static void Make(GameObject body, Sector sector, float radius)
{
var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP");
var newCloak = GameObject.Instantiate(cloak, body.transform);
newCloak.transform.localPosition = Vector3.zero;
newCloak.transform.name = "CloakingField";
newCloak.transform.localScale = Vector3.one * radius;
GameObject.Destroy(newCloak.GetComponent<PlayerCloakEntryRedirector>());
var cloakFieldController = newCloak.GetComponent<CloakFieldController>();
cloakFieldController._cloakScaleDist = radius * 2000 / 3000f;
cloakFieldController._farCloakRadius = radius * 500 / 3000f;
cloakFieldController._innerCloakRadius = radius * 900 / 3000f;
cloakFieldController._nearCloakRadius = radius * 800 / 3000f;
cloakFieldController._referenceFrameVolume = body.GetAttachedOWRigidbody()._attachedRFVolume;
cloakFieldController._exclusionSector = null;
var cloakSectorController = newCloak.AddComponent<CloakSectorController>();
cloakSectorController.Init(newCloak.GetComponent<CloakFieldController>(), body);
newCloak.SetActive(true);
cloakFieldController.enabled = true;
// To cloak from the start
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit);
}
}
}

View File

@ -33,7 +33,6 @@ namespace NewHorizons.Builder.Body
funnelGO.transform.parent = go.transform;
var owrb = funnelGO.AddComponent<OWRigidbody>();
var alignment = funnelGO.AddComponent<AlignWithTargetBody>();
var matchMotion = funnelGO.AddComponent<MatchInitialMotion>();
matchMotion.SetBodyToMatch(rigidbody);
@ -51,9 +50,9 @@ namespace NewHorizons.Builder.Body
var scaleRoot = new GameObject("ScaleRoot");
scaleRoot.transform.parent = funnelGO.transform;
scaleRoot.transform.rotation = Quaternion.Euler(90, 0, 0);
scaleRoot.transform.localPosition = new Vector3(0, 30, 0);
scaleRoot.transform.localScale = new Vector3(1, 1, 1.075f);
scaleRoot.transform.rotation = Quaternion.identity;
scaleRoot.transform.localPosition = Vector3.zero;
scaleRoot.transform.localScale = new Vector3(1, 1, 1);
var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform);
proxyGO.name = "Proxy_Funnel";
@ -171,10 +170,10 @@ namespace NewHorizons.Builder.Body
funnelSizeController.anchor = go.transform;
// Finish up next tick
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, alignment, funnelSizeController, module));
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PostMake(funnelGO, funnelSizeController, module));
}
private static void PostMake(GameObject funnelGO, AlignWithTargetBody alignment, FunnelController funnelSizeController, FunnelModule module)
private static void PostMake(GameObject funnelGO, FunnelController funnelSizeController, FunnelModule module)
{
var targetAO = AstroObjectLocator.GetAstroObject(module.Target);
var target = targetAO?.GetAttachedOWRigidbody();
@ -185,14 +184,9 @@ namespace NewHorizons.Builder.Body
return;
}
alignment.SetTargetBody(target);
funnelSizeController.target = target.gameObject.transform;
funnelGO.SetActive(true);
// This has to happen last idk
alignment.SetUsePhysicsToRotate(true);
}
private static void AddDestructionVolumes(GameObject go, DeathType deathType)
@ -211,6 +205,8 @@ namespace NewHorizons.Builder.Body
var destructionVolume = child.gameObject.AddComponent<DestructionVolume>();
destructionVolume._deathType = deathType;
// Only stars should destroy planets
destructionVolume._onlyAffectsPlayerAndShip = deathType != DeathType.Energy;
}
}
}

View File

@ -108,6 +108,8 @@ namespace NewHorizons.Builder.Body
deathVolume.transform.localPosition = Vector3.zero;
deathVolume.transform.localScale = Vector3.one;
deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.GetComponent<DestructionVolume>()._onlyAffectsPlayerAndShip = false;
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false;
deathVolume.name = "DestructionVolume";
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();

View File

@ -38,7 +38,8 @@ namespace NewHorizons.Builder.General
owRigidBody.EnableKinematicSimulation();
owRigidBody.MakeKinematic();
ParameterizedAstroObject astroObject = body.AddComponent<ParameterizedAstroObject>();
NHAstroObject astroObject = body.AddComponent<NHAstroObject>();
astroObject.HideDisplayName = !config.Base.HasMapMarker;
if (config.Orbit != null) astroObject.SetKeplerCoordinatesFromOrbitModule(config.Orbit);

View File

@ -8,23 +8,40 @@ using System.Reflection;
using UnityEngine;
using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger;
using NewHorizons.External.Configs;
namespace NewHorizons.Builder.General
{
static class DetectorBuilder
{
public static GameObject Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, bool inherit = true)
public static GameObject Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, IPlanetConfig config)
{
GameObject detectorGO = new GameObject("FieldDetector");
detectorGO.SetActive(false);
detectorGO.transform.parent = body.transform;
detectorGO.transform.localPosition = Vector3.zero;
detectorGO.layer = 20;
detectorGO.layer = LayerMask.NameToLayer("BasicDetector");
ConstantForceDetector forceDetector = detectorGO.AddComponent<ConstantForceDetector>();
forceDetector.SetValue("_inheritElement0", inherit);
forceDetector.SetValue("_inheritElement0", true);
OWRB.RegisterAttachedForceDetector(forceDetector);
// For falling into sun
if(!config.Base.InvulnerableToSun && config.Star == null && config.FocalPoint == null)
{
detectorGO.layer = LayerMask.NameToLayer("AdvancedDetector");
var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>();
var sphereCollider = detectorGO.AddComponent<SphereCollider>();
sphereCollider.radius = config.Base.SurfaceSize;
var owCollider = detectorGO.AddComponent<OWCollider>();
fluidDetector._collider = sphereCollider;
// Could copy the splash from the interloper as well some day
}
GravityVolume parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();
if (parentGravityVolume != null)
{

View File

@ -186,8 +186,8 @@ namespace NewHorizons.Builder.General
float r1 = r.magnitude * m2 / (m1 + m2);
float r2 = r.magnitude * m1 / (m1 + m2);
ParameterizedAstroObject primaryAO = Position.AstroLookup[primaryHB].Invoke() as ParameterizedAstroObject;
ParameterizedAstroObject secondaryAO = Position.AstroLookup[secondaryHB].Invoke() as ParameterizedAstroObject;
NHAstroObject primaryAO = Position.AstroLookup[primaryHB].Invoke() as NHAstroObject;
NHAstroObject secondaryAO = Position.AstroLookup[secondaryHB].Invoke() as NHAstroObject;
float ecc = primaryAO.Eccentricity;
float i = primaryAO.Inclination;

View File

@ -211,9 +211,14 @@ namespace NewHorizons.Builder.General
HeavenlyBodyBuilder.Remove(ao);
}
public static void RemoveDistantProxyClones()
public static void RemoveAllProxies()
{
GameObject.Destroy(GameObject.FindObjectOfType<DistantProxyManager>().gameObject);
foreach(var name in _solarSystemBodies)
{
RemoveProxy(name.Replace(" ", "").Replace("'", ""));
}
}
private static void DisableBody(GameObject go, bool delete)
@ -233,6 +238,9 @@ namespace NewHorizons.Builder.General
if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject);
if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject);
if (distantProxy == null && distantProxyClone == null)
Logger.Log($"Couldn't find proxy for {name}");
}
}
}

View File

@ -26,9 +26,9 @@ namespace NewHorizons.Builder.General
sectorGO.AddComponent<OWTriggerVolume>();
Sector S = sectorGO.AddComponent<Sector>();
S.SetValue("_name", Sector.Name.Unnamed);
S.SetValue("_attachedOWRigidbody", rigidbody);
S.SetValue("_subsectors", new List<Sector>());
S._name = (Sector.Name)24;
S._attachedOWRigidbody = rigidbody;
S._subsectors = new List<Sector>();
sectorGO.SetActive(true);

View File

@ -14,18 +14,29 @@ namespace NewHorizons.Builder.Props
public static void Make(GameObject go, Sector sector, PropModule.GeyserInfo info)
{
var original = GameObject.Find("TimberHearth_Body/Sector_TH/Interactables_TH/Geysers/Geyser_Village/");
GameObject geyserGO = GameObject.Instantiate(original, go.transform);
GameObject geyserGO = original.InstantiateInactive();
geyserGO.transform.parent = sector.transform;
geyserGO.name = "Geyser";
var pos = ((Vector3)info.position);
var length = pos.magnitude;
geyserGO.transform.localPosition = pos.normalized * (length - 100f);
geyserGO.transform.localPosition = pos.normalized * length;
var originalRadial = -(original.transform.position - GameObject.Find("TimberHearth_Body").transform.position).normalized;
geyserGO.transform.rotation *= Quaternion.FromToRotation(originalRadial, pos.normalized);
geyserGO.GetComponent<GeyserController>()._inactiveDuration = 0.5f;
var controller = geyserGO.GetComponent<GeyserController>();
controller._inactiveDuration = 0.5f;
geyserGO.SetActive(true);
var geyserFluidVolume = geyserGO.GetComponentInChildren<GeyserFluidVolume>();
// Do this after awake
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => geyserFluidVolume._maxHeight = 1);
geyserFluidVolume.enabled = true;
geyserGO.transform.Find("FluidVolume_Geyser").GetComponent<CapsuleShape>().enabled = true;
}
}
}

View File

@ -35,7 +35,7 @@ namespace NewHorizons.Builder.Props
{
foreach(var geyserInfo in config.Props.Geysers)
{
//GeyserBuilder.Make(go, sector, geyserInfo);
GeyserBuilder.Make(go, sector, geyserInfo);
}
}
if(config.Props.Rafts != null)

View File

@ -80,9 +80,9 @@ namespace NewHorizons.Builder.Props
StreamingManager.LoadStreamingAssets(child.assetBundle);
}
var detectorGO = DetectorBuilder.Make(raftObject, owRigidBody, ao, null, false);
var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>();
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => fluidDetector._activeVolumes = new EffectVolume[] { body.GetComponentInChildren<RadialFluidVolume>() }.ToList());
//var detectorGO = DetectorBuilder.Make(raftObject, owRigidBody, ao, null, false, false);
//var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>();
//Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => fluidDetector._activeVolumes = new EffectVolume[] { body.GetComponentInChildren<RadialFluidVolume>() }.ToList());
var targetBodyAlignment = raftObject.AddComponent<AlignWithTargetBody>();

View File

@ -27,6 +27,7 @@ namespace NewHorizons.Builder.Props
}
else if (info.elevation != 0f)
{
Logger.Log("Giving tornado random pos");
position = UnityEngine.Random.insideUnitSphere * info.elevation;
elevation = info.elevation;
}
@ -51,13 +52,14 @@ namespace NewHorizons.Builder.Props
var width = 40f;
if (info.width != 0f) width = info.width;
var scale = new Vector3(width / 40f, height / 837.0669f, width / 40f);
var scale = new Vector3(width / 40f, 1f, width / 40f);
tornado.transform.localScale = scale;
var tornadoController = tornado.GetComponent<TornadoController>();
tornadoController.SetSector(sector);
var n = position.normalized;
var up = new Vector3(0, 1, 0);
var h1 = elevation;
@ -69,17 +71,20 @@ namespace NewHorizons.Builder.Props
tornadoController._bottomStartPos = n * h1;
tornadoController._bottomBasePos = up * h1;
tornadoController._bottomBone.localPosition = n * h1;
tornadoController._bottomBone.rotation.SetFromToRotation(tornadoController._bottomBone.up, up);
tornadoController._midElevation = h2;
tornadoController._midStartElevation = h2;
tornadoController._midStartPos = n * h2;
tornadoController._midBasePos = up * h2;
tornadoController._midBone.localPosition = n * h2;
tornadoController._midBone.rotation.SetFromToRotation(tornadoController._midBone.up, up);
tornadoController._topElevation = h3;
tornadoController._topStartPos = n * h3;
tornadoController._topBasePos = up * h3;
tornadoController._topBone.localPosition = n * h3;
tornadoController._topBone.rotation.SetFromToRotation(tornadoController._topBone.up, up);
tornadoController._snapBonesToSphere = true;
tornadoController._wander = true;
@ -101,7 +106,6 @@ namespace NewHorizons.Builder.Props
GameObject.Destroy(top.transform.Find("Effects_GD_TornadoCloudCap_Medium")?.gameObject);
GameObject.Destroy(top.transform.Find("Effects_GD_TornadoCloudCap_Small")?.gameObject);
/*
var top_objects = new GameObject[3];
top_objects[0] = GameObject.Instantiate(top.transform.Find("Effects_GD_TornadoCloudBlend_Large").gameObject, top.transform);
top_objects[1] = GameObject.Instantiate(top.transform.Find("Effects_GD_TornadoCloudBlend_Medium").gameObject, top.transform);
@ -112,7 +116,6 @@ namespace NewHorizons.Builder.Props
obj.transform.localPosition = new Vector3(0, -20, 0);
obj.transform.localRotation = Quaternion.Euler(180, 0, 0);
}
*/
}
tornadoController._startActive = false;

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Builder.StarSystem
{
class SkyboxBuilder
{
}
}

View File

@ -18,7 +18,7 @@ namespace NewHorizons.Builder.Updater
public static void Update(NewHorizonsBody body, GameObject go)
{
var mapping = Planet.defaultMapping;
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(AstroObjectLocator.GetAstroObject(body.Config.Name));
var heavenlyBody = CommonResourcesUtilities.HeavenlyBodyFromAstroObject(go.GetComponent<AstroObject>());
Logger.Log($"Updating position of {body.Config.Name}/{heavenlyBody}");

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components
{
public class CloakSectorController : MonoBehaviour
{
private CloakFieldController _cloak;
private GameObject _root;
private bool _isInitialized;
private List<Renderer> _renderers = null;
public void Init(CloakFieldController cloak, GameObject root)
{
_cloak = cloak;
_root = root;
// Lets just clear these off idc
_cloak.OnPlayerEnter = new OWEvent();
_cloak.OnPlayerExit = new OWEvent();
_cloak.OnPlayerEnter += OnPlayerEnter;
_cloak.OnPlayerExit += OnPlayerExit;
_isInitialized = true;
}
void OnDestroy()
{
if(_isInitialized)
{
_cloak.OnPlayerEnter -= OnPlayerEnter;
_cloak.OnPlayerExit -= OnPlayerExit;
}
}
private void SetUpList()
{
_renderers = _root.GetComponentsInChildren<Renderer>().ToList();
}
public void OnPlayerEnter()
{
SetUpList();
foreach (var renderer in _renderers)
{
renderer.forceRenderingOff = false;
}
}
public void OnPlayerExit()
{
SetUpList();
foreach (var renderer in _renderers)
{
renderer.forceRenderingOff = true;
}
}
}
}

View File

@ -13,15 +13,23 @@ namespace NewHorizons.Components
public Transform target;
public Transform anchor;
private void FixedUpdate()
private void Update()
{
float num = scaleCurve == null ? 1f : scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed());
// Temporary solution that i will never get rid of
transform.position = anchor.position;
float num = scaleCurve == null ? 1f : scaleCurve.Evaluate(TimeLoop.GetMinutesElapsed());
var dist = (transform.position - target.position).magnitude;
transform.localScale = new Vector3(num, dist/500f, num);
transform.localScale = new Vector3(num, num, dist / 500f);
transform.LookAt(target);
// The target or anchor could have been destroyed by a star
if (!target.gameObject.activeInHierarchy || !anchor.gameObject.activeInHierarchy)
{
gameObject.SetActive(false);
}
}
}
}

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.General;
using NewHorizons.External.Configs;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,9 +13,13 @@ namespace NewHorizons.Components
{
public void Awake()
{
// TODO: eventually all bodies should have configs
var config = new PlanetConfig(null);
config.Base.SurfaceSize = 10f;
var detector = base.transform.GetComponentInChildren<DynamicForceDetector>();
var ao = base.GetComponent<AstroObject>();
var newDetector = DetectorBuilder.Make(base.gameObject, ao.GetAttachedOWRigidbody(), ao.GetPrimaryBody(), ao);
var newDetector = DetectorBuilder.Make(base.gameObject, ao.GetAttachedOWRigidbody(), ao.GetPrimaryBody(), ao, config);
newDetector.transform.parent = detector.transform.parent;
GameObject.Destroy(detector);
}

View File

@ -23,5 +23,25 @@ namespace NewHorizons.Components.Orbital
{
FakeMassBody.SetActive(true);
}
void Update()
{
// Secondary and primary must have been engulfed by a star
if(!Primary.isActiveAndEnabled && !Secondary.isActiveAndEnabled)
{
ReferenceFrameTracker component = Locator.GetPlayerBody().GetComponent<ReferenceFrameTracker>();
if (component.GetReferenceFrame(true) != null && component.GetReferenceFrame(true).GetOWRigidBody() == gameObject)
{
component.UntargetReferenceFrame();
}
MapMarker component2 = gameObject.GetComponent<MapMarker>();
if (component2 != null)
{
component2.DisableMarker();
}
gameObject.SetActive(false);
FakeMassBody.SetActive(false);
}
}
}
}

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace NewHorizons.Components.Orbital
{
public class ParameterizedAstroObject : AstroObject, IKeplerCoordinates
public class NHAstroObject : AstroObject, IKeplerCoordinates
{
public float Inclination { get; set; }
public int SemiMajorAxis { get; set; }
@ -17,6 +17,7 @@ namespace NewHorizons.Components.Orbital
public float Eccentricity { get; set; }
public float ArgumentOfPeriapsis { get; set; }
public float TrueAnomaly { get; set; }
public bool HideDisplayName { get; set; }
public void SetKeplerCoordinatesFromOrbitModule(OrbitModule orbit)
{

View File

@ -53,7 +53,8 @@ namespace NewHorizons.Components
public void OnOccupantExitSector(SectorDetector _)
{
if (!_sector.ContainsOccupant(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
if (!_sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe | DynamicOccupant.Ship))
{
tornadoController.StartCollapse();
}

View File

@ -21,6 +21,8 @@ namespace NewHorizons.External
public bool HasReferenceFrame { get; set; } = true;
public bool CenterOfSolarSystem { get; set; } = false;
public bool IsSatellite { get; set; }
public float CloakRadius { get; set; } = 0f;
public bool InvulnerableToSun { get; set; }
// Old, see SingularityModule instead
public float BlackHoleSize { get; set; }

View File

@ -55,7 +55,7 @@ namespace NewHorizons.External
public class TornadoInfo
{
public float elevation;
public MVector3 position;
public MVector3 position = null;
public float height;
public float width;
public MColor tint;

View File

@ -102,7 +102,7 @@ namespace NewHorizons.Handlers
Logger.Log("Done loading bodies");
// I don't know what these do but they look really weird from a distance
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveDistantProxyClones(), 1);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies);
if (Main.Instance.CurrentStarSystem != "SolarSystem") PlanetDestroyer.RemoveSolarSystem();
}
@ -274,7 +274,7 @@ namespace NewHorizons.Handlers
if (body.Config.Orbit.ShowOrbitLine && !body.Config.Orbit.IsStatic) OrbitlineBuilder.Make(body.Object, ao, body.Config.Orbit.IsMoon, body.Config);
if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao);
if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, body.Config);
if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao);
@ -351,6 +351,10 @@ namespace NewHorizons.Handlers
if (body.Config.Funnel != null)
FunnelBuilder.Make(go, go.GetComponentInChildren<ConstantForceDetector>(), rb, body.Config.Funnel);
// Has to go last probably
if (body.Config.Base.CloakRadius != 0f)
CloakBuilder.Make(go, sector, body.Config.Base.CloakRadius);
return go;
}

View File

@ -0,0 +1,40 @@
using NewHorizons.External.Configs;
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Handlers
{
public static class SystemCreationHandler
{
public static void LoadSystem(NewHorizonsSystem system)
{
var skybox = GameObject.Find("Skybox/Starfield");
/*
skybox.GetComponent<MeshRenderer>().material.shader = Shader.Find("Standard");
*/
/*
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
GameObject.Destroy(sphere.GetComponent<SphereCollider>());
sphere.transform.parent = skybox.transform;
sphere.transform.localPosition = Vector3.zero;
var meshFilter = sphere.GetComponent<MeshFilter>();
meshFilter.mesh.triangles = meshFilter.mesh.triangles.Reverse().ToArray();
var meshRenderer = sphere.GetComponent<MeshRenderer>();
meshRenderer.material.color = Color.green;
*/
}
}
}

View File

@ -27,6 +27,7 @@ using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Builder.Atmosphere;
using PacificEngine.OW_CommonResources.Geometry.Orbits;
using NewHorizons.Utility.CommonResources;
using UnityEngine.Events;
namespace NewHorizons
{
@ -36,7 +37,6 @@ namespace NewHorizons
public static Main Instance { get; private set; }
public static bool Debug;
private static IModButton _reloadButton;
public static Dictionary<string, NewHorizonsSystem> SystemDict = new Dictionary<string, NewHorizonsSystem>();
public static Dictionary<string, List<NewHorizonsBody>> BodyDict = new Dictionary<string, List<NewHorizonsBody>>();
@ -58,6 +58,12 @@ namespace NewHorizons
private bool _firstLoad = true;
private ShipWarpController _shipWarpController;
// API events
public class StarSystemEvent : UnityEvent<string> { }
public StarSystemEvent OnChangeStarSystem;
public StarSystemEvent OnStarSystemLoaded;
private GameObject _ship;
public override object GetApi()
@ -68,7 +74,7 @@ namespace NewHorizons
public override void Configure(IModConfig config)
{
Debug = config.GetSettingsValue<bool>("Debug");
UpdateReloadButton();
DebugReload.UpdateReloadButton();
string logLevel = config.GetSettingsValue<string>("LogLevel");
Logger.LogType logType;
switch (logLevel)
@ -91,6 +97,9 @@ namespace NewHorizons
public void Start()
{
OnChangeStarSystem = new StarSystemEvent();
OnStarSystemLoaded = new StarSystemEvent();
SceneManager.sceneLoaded += OnSceneLoaded;
Instance = this;
GlobalMessenger<DeathType>.AddListener("PlayerDeath", OnDeath);
@ -119,56 +128,10 @@ namespace NewHorizons
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single));
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => _firstLoad = false);
Instance.ModHelper.Menus.PauseMenu.OnInit += InitializePauseMenu;
Instance.ModHelper.Menus.PauseMenu.OnInit += DebugReload.InitializePauseMenu;
}
#region Reloading
private void InitializePauseMenu()
{
_reloadButton = ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper());
_reloadButton.OnClick += ReloadConfigs;
UpdateReloadButton();
}
private void UpdateReloadButton()
{
if (_reloadButton != null)
{
if (Debug) _reloadButton.Show();
else _reloadButton.Hide();
}
}
private void ReloadConfigs()
{
BodyDict = new Dictionary<string, List<NewHorizonsBody>>();
SystemDict = new Dictionary<string, NewHorizonsSystem>();
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(null), this);
foreach (AssetBundle bundle in AssetBundles.Values)
{
bundle.Unload(true);
}
AssetBundles.Clear();
Logger.Log("Begin reload of config files...", Logger.LogType.Log);
try
{
foreach (IModBehaviour mountedAddon in MountedAddons)
{
LoadConfigs(mountedAddon);
}
}
catch (Exception)
{
Logger.LogWarning("Error While Reloading");
}
ChangeCurrentStarSystem(_currentStarSystem);
}
#endregion
public void OnDestroy()
{
@ -181,6 +144,7 @@ namespace NewHorizons
private static void OnWakeUp()
{
IsSystemReady = true;
Instance.OnStarSystemLoaded?.Invoke(Instance.CurrentStarSystem);
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
@ -223,6 +187,7 @@ namespace NewHorizons
AstroObjectLocator.RefreshList();
OWAssetHandler.Init();
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);
LoadTranslations(ModHelper.Manifest.ModFolderPath + "AssetBundle/", this);
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
@ -234,9 +199,20 @@ namespace NewHorizons
_shipWarpController.Init();
if (HasWarpDrive == true) EnableWarpDrive();
Logger.Log($"Is the player warping in? {IsWarping}");
if (IsWarping && _shipWarpController) Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => _shipWarpController.WarpIn(WearingSuit));
else Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint));
if (IsWarping && _shipWarpController)
{
Instance.ModHelper.Events.Unity.RunWhen(
() => IsSystemReady,
() => _shipWarpController.WarpIn(WearingSuit)
);
}
else
{
Instance.ModHelper.Events.Unity.RunWhen(
() => IsSystemReady,
() => FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint)
);
}
IsWarping = false;
var map = GameObject.FindObjectOfType<MapController>();
@ -331,14 +307,11 @@ namespace NewHorizons
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(null);
else Logger.Log($"Loaded system config for {config.StarSystem}");
// Since we only load stuff the first time we can do this now
if (starSystemConfig.startHere)
{
_defaultStarSystem = config.StarSystem;
_currentStarSystem = config.StarSystem;
}
var system = new NewHorizonsSystem(config.StarSystem, starSystemConfig, mod);
SystemDict.Add(config.StarSystem, new NewHorizonsSystem(config.StarSystem, starSystemConfig, mod));
if (system.Config.startHere) SetDefaultSystem(system.Name);
SystemDict.Add(config.StarSystem, system);
BodyDict.Add(config.StarSystem, new List<NewHorizonsBody>());
}
@ -353,6 +326,12 @@ namespace NewHorizons
return body;
}
public void SetDefaultSystem(string defaultSystem)
{
_defaultStarSystem = defaultSystem;
_currentStarSystem = defaultSystem;
}
#endregion Load
#region Change star system
@ -360,6 +339,8 @@ namespace NewHorizons
{
if (_isChangingStarSystem) return;
OnChangeStarSystem?.Invoke(newStarSystem);
Logger.Log($"Warping to {newStarSystem}");
if(warp && _shipWarpController) _shipWarpController.WarpOut();
_currentStarSystem = newStarSystem;
@ -427,6 +408,16 @@ namespace NewHorizons
{
return Main.Instance.CurrentStarSystem;
}
public UnityEvent<string> GetChangeStarSystemEvent()
{
return Main.Instance.OnChangeStarSystem;
}
public UnityEvent<string> GetStarSystemLoadedEvent()
{
return Main.Instance.OnStarSystemLoaded;
}
}
#endregion API
}

View File

@ -30,6 +30,9 @@ namespace NewHorizons.Tools
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunLightParamUpdater>("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunSurfaceAudioController>("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate));
var locatorRegisterCloakFieldController = typeof(Locator).GetMethod(nameof(Locator.RegisterCloakFieldController));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(locatorRegisterCloakFieldController, typeof(Patches), nameof(Patches.OnLocatorRegisterCloakFieldController));
// Lot of audio signal stuff
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("SignalNameToString", typeof(Patches), nameof(Patches.OnAudioSignalSignalNameToString));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("IndexToFrequency", typeof(Patches), nameof(Patches.OnAudioSignalIndexToFrequency));
@ -455,5 +458,10 @@ namespace NewHorizons.Tools
return false;
}
public static bool OnLocatorRegisterCloakFieldController()
{
return Locator._cloakFieldController == null;
}
}
}

View File

@ -1,4 +1,5 @@
using NewHorizons.Handlers;
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
@ -25,11 +26,16 @@ namespace NewHorizons.Tools
public static bool GetHUDDisplayName(ReferenceFrame __instance, ref string __result)
{
var ao = __instance.GetAstroObject();
if (ao != null && ao.GetAstroObjectName() == AstroObject.Name.CustomString)
if (ao == null) return true;
if(ao is NHAstroObject)
{
__result = TranslationHandler.GetTranslation(ao.GetCustomName(), TranslationHandler.TextType.UI);
if((ao as NHAstroObject).HideDisplayName) __result = "";
else __result = TranslationHandler.GetTranslation(ao.GetCustomName(), TranslationHandler.TextType.UI);
return false;
}
return true;
}

View File

@ -13,6 +13,11 @@ namespace NewHorizons.Utility.CommonResources
{
public static HeavenlyBody HeavenlyBodyFromAstroObject(AstroObject obj)
{
if(obj == null)
{
Logger.LogError("Asking for a heavenly body from astro object but it is null");
}
switch (obj.GetAstroObjectName())
{
case AstroObject.Name.CustomString:

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using NewHorizons.External.Configs;
using NewHorizons.Handlers;
using OWML.Common;
using OWML.Common.Menus;
using UnityEngine;
namespace NewHorizons.Utility
{
public static class DebugReload
{
private static IModButton _reloadButton;
public static void InitializePauseMenu()
{
_reloadButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper());
_reloadButton.OnClick += ReloadConfigs;
UpdateReloadButton();
}
public static void UpdateReloadButton()
{
if (_reloadButton != null)
{
if (Main.Debug) _reloadButton.Show();
else _reloadButton.Hide();
}
}
private static void ReloadConfigs()
{
Main.BodyDict.Clear();
Main.SystemDict.Clear();
Main.BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
Main.SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(null), Main.Instance);
foreach (AssetBundle bundle in Main.AssetBundles.Values)
{
bundle.Unload(true);
}
Main.AssetBundles.Clear();
Logger.Log("Begin reload of config files...", Logger.LogType.Log);
try
{
foreach (IModBehaviour mountedAddon in Main.MountedAddons)
{
Main.Instance.LoadConfigs(mountedAddon);
}
}
catch (Exception)
{
Logger.LogWarning("Error While Reloading");
}
GameObject.Find("/PauseMenu/PauseMenuManagers").GetComponent<PauseMenuManager>().OnSkipToNextTimeLoop();
Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem);
}
}
}

View File

@ -3,7 +3,7 @@
"author": "xen, Idiot, & Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "0.9.5",
"version": "0.10.0",
"owmlVersion": "2.1.0",
"dependencies": [ "PacificEngine.OW_CommonResources" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.OuterWildsMMO", "Vesper.AutoResume" ],

View File

@ -165,7 +165,7 @@
"groundSize": {
"type": "number",
"default": 0,
"description": "Radius of the a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as 0."
"description": "Radius of a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as 0."
},
"hasCometTail": {
"type": "boolean",
@ -190,6 +190,16 @@
"type": "boolean",
"default": false,
"description": "Is this body an artificial satellite of a planet/moon/star?"
},
"cloakRadius": {
"type": "number",
"default": 0,
"description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you don't want a cloak, leave this as 0."
},
"invulnerableToSun": {
"type": "boolean",
"default": false,
"description": "Can this planet survive entering a star?"
}
}
},

View File

@ -15,6 +15,10 @@ public interface INewHorizons
GameObject GetPlanet(string name);
string GetCurrentStarSystem();
UnityEvent<string> GetChangeStarSystemEvent();
UnityEvent<string> GetStarSystemLoadedEvent();
}
```
@ -29,4 +33,6 @@ public class MyMod : ModBehaviour
}
```
You can then use the APIs `LoadConfigs()` method to load from a "planets" folder, or use the `Create()` and `GetPlanet` methods to create planets and do whatever with them. Just make sure you create planets in the `Start()` method or at least before the SolarSystem scene loads, or they will not be created.
You can then use the APIs `LoadConfigs()` method to load from a "planets" folder, or use the `Create()` and `GetPlanet()` methods to create planets and do whatever with them. Just make sure you create planets in the `Start()` method or at least before the SolarSystem scene loads, or they will not be created.
The `GetChangeStarSystemEvent` and `GetStarSystemLoadedEvent` events let you listen in for when the player starts changing to a new system (called when entering a black hole or using the warp drive) and when the system is fully loaded in, respectively.