Make it nh ao

This commit is contained in:
Nick 2022-07-05 22:24:40 -04:00
parent 30a1039bc0
commit bfffb8de04
5 changed files with 28 additions and 13 deletions

View File

@ -1,4 +1,6 @@
using NewHorizons.Builder.Props;
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using System;
using System.Collections.Generic;
@ -43,10 +45,13 @@ namespace NewHorizons.Builder.Body
// spawn the dimension body
var dimensionPrefab = SearchUtilities.Find("DB_HubDimension_Body");
var dimension = GameObject.Instantiate(dimensionPrefab);
var ao = dimension.GetComponent<AstroObject>();
var dimension = dimensionPrefab.InstantiateInactive();
PlanetCreationHandler.UpdateBodyOrbit(body, dimension);
// fix name
var ao = dimension.GetComponent<NHAstroObject>();
ao.IsDimension = true;
var name = body.Config.name ?? "Custom Bramble Dimension";
ao._customName = name;
ao._name = AstroObject.Name.CustomString;
@ -89,7 +94,8 @@ namespace NewHorizons.Builder.Body
var fog = fogGO.GetComponent<PlanetaryFogController>();
fog.fogTint = body.Config.Bramble.dimension.fogTint.ToColor();
}
dimension.SetActive(true);
return dimension;
}

View File

@ -1,4 +1,4 @@
using NewHorizons.External.Modules;
using NewHorizons.External.Modules;
namespace NewHorizons.Components.Orbital
{
public class NHAstroObject : AstroObject, IOrbitalParameters
@ -10,6 +10,7 @@ namespace NewHorizons.Components.Orbital
public float argumentOfPeriapsis { get; set; }
public float trueAnomaly { get; set; }
public bool HideDisplayName { get; set; }
public bool IsDimension { get; set; }
public void SetOrbitalParametersFromConfig(OrbitModule orbit)
{

View File

@ -6,6 +6,7 @@ using System.Linq;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.VariableSize;
using Newtonsoft.Json;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.External.Configs
{
@ -175,13 +176,18 @@ namespace NewHorizons.External.Configs
if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule();
}
public void MigrateAndValidate()
public void Validate()
{
// Validate
// If we can correct a part of the config, do it
// If it cannot be solved, throw an exception
if (Base.centerOfSolarSystem) Orbit.isStatic = true;
if (Atmosphere?.clouds?.lightningGradient != null) Atmosphere.clouds.hasLightning = true;
if (Bramble?.dimension != null && Orbit?.staticPosition == null) NewHorizons.Utility.Logger.LogError($"Dimension {name} must have Orbit.staticPosition defined.");
if (Bramble?.dimension != null && Orbit?.staticPosition == null) throw new Exception($"Dimension {name} must have Orbit.staticPosition defined.");
if (Orbit?.staticPosition != null) Orbit.isStatic = true;
}
public void Migrate()
{
// Backwards compatability
// Should be the only place that obsolete things are referenced
#pragma warning disable 612, 618

View File

@ -239,10 +239,11 @@ namespace NewHorizons.Handlers
GameObject planetObject = GenerateBody(body, defaultPrimaryToSun);
if (planetObject == null) return false;
planetObject.SetActive(true);
var nhAO = planetObject.GetComponent<NHAstroObject>();
var owAO = planetObject.GetComponent<AstroObject>();
if (nhAO != null) _dict.Add(nhAO, body);
else if (owAO != null) _dimensions.Add(owAO, body);
var ao = planetObject.GetComponent<NHAstroObject>();
if (!ao.IsDimension) _dict.Add(ao, body);
else _dimensions.Add(ao, body);
}
catch (Exception e)
{
@ -306,7 +307,7 @@ namespace NewHorizons.Handlers
public static GameObject GenerateBrambleDimensionBody(NewHorizonsBody body)
{
var go = BrambleDimensionBuilder.Make(body);
var ao = go.GetComponent<AstroObject>();
var ao = go.GetComponent<NHAstroObject>();
var sector = go.FindChild("Sector").GetComponent<Sector>();
var owRigidBody = go.GetComponent<OWRigidbody>();

View File

@ -489,7 +489,8 @@ namespace NewHorizons
}
// Has to happen after we make sure theres a system config
config.MigrateAndValidate();
config.Validate();
config.Migrate();
body = new NewHorizonsBody(config, mod, relativePath);
}