using NewHorizons.External.Modules;
using NewHorizons.External.Modules.VariableSize;
using Newtonsoft.Json;
using NewHorizons.Utility;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Internal;
namespace NewHorizons.External.Configs
{
///
/// A planet or body to generate
///
[JsonObject]
public class PlanetConfig
{
///
/// Unique name of your planet
///
public string Name;
///
/// Version of New Horizons this config is using (Doesn't do anything)
///
public string Version;
///
/// Unique star system containing your planet
///
[DefaultValue("SolarSystem")]
public string StarSystem = "SolarSystem";
///
/// `true` if you want to delete this planet
///
public bool Destroy;
///
/// A list of paths to child GameObjects to destroy on this planet
///
public string[] RemoveChildren;
///
/// Set to a higher number if you wish for this body to be built sooner
///
[DefaultValue(-1)]
public int BuildPriority = -1;
///
/// Should this planet ever be shown on the title screen?
///
public bool CanShowOnTitle = true;
///
/// Does this config describe a quantum state of a custom planet defined in another file?
///
public bool IsQuantumState;
///
/// Base Properties of this Body
///
public BaseModule Base;
///
/// Describes this Body's atmosphere
///
public AtmosphereModule Atmosphere;
///
/// Describes this Body's orbit (or lack there of)
///
public OrbitModule Orbit;
///
/// Creates a ring around the planet
///
public RingModule Ring;
///
/// Generate the surface of this planet using a heightmap
///
public HeightMapModule HeightMap;
///
/// Procedural Generation
///
public ProcGenModule ProcGen;
///
/// Generate asteroids around this body
///
public AsteroidBeltModule AsteroidBelt;
///
/// Make this body a star
///
public StarModule Star;
///
/// Make this body into a focal point (barycenter)
///
public FocalPointModule FocalPoint;
///
/// Spawn various objects on this body
///
public PropModule Props;
///
/// Add ship log entries to this planet and describe how it looks in map mode
///
public ShipLogModule ShipLog;
///
/// Spawn the player at this planet
///
public SpawnModule Spawn;
///
/// Add signals that can be heard via the signal-scope to this planet
///
public SignalModule Signal;
///
/// Add a black or white hole to this planet
///
public SingularityModule Singularity;
///
/// Add lava to this planet
///
public LavaModule Lava;
///
/// Add water to this planet
///
public WaterModule Water;
///
/// Add sand to this planet
///
public SandModule Sand;
///
/// Add funnel from this planet to another
///
public FunnelModule Funnel;
#region Obsolete
[System.Obsolete("ChildrenToDestroy is deprecated, please use RemoveChildren instead")]
public string[] ChildrenToDestroy;
#endregion Obsolete
public PlanetConfig()
{
// Always have to have a base module
if (Base == null) Base = new BaseModule();
if (Orbit == null) Orbit = new OrbitModule();
if (ShipLog == null) ShipLog = new ShipLogModule();
}
public void MigrateAndValidate()
{
// Validate
if (Base.CenterOfSolarSystem) Orbit.IsStatic = true;
if (Atmosphere?.Clouds?.LightningGradient != null) Atmosphere.Clouds.HasLightning = true;
// Backwards compatability
// Should be the only place that obsolete things are referenced
#pragma warning disable 612, 618
if (Base.WaterSize != 0)
{
Water = new WaterModule
{
Size = Base.WaterSize,
Tint = Base.WaterTint
};
}
if (Base.LavaSize != 0)
{
Lava = new LavaModule
{
Size = Base.LavaSize
};
}
if (Base.BlackHoleSize != 0)
{
Singularity = new SingularityModule
{
Type = SingularityModule.SingularityType.BlackHole,
Size = Base.BlackHoleSize
};
}
if (Base.IsSatellite)
{
Base.ShowMinimap = false;
}
if (ChildrenToDestroy != null)
{
RemoveChildren = ChildrenToDestroy;
}
if (Base.HasAmbientLight)
{
Base.AmbientLight = 0.5f;
}
if (Atmosphere != null)
{
if (!string.IsNullOrEmpty(Atmosphere.Cloud))
{
Atmosphere.Clouds = new AtmosphereModule.CloudInfo()
{
OuterCloudRadius = Atmosphere.Size,
InnerCloudRadius = Atmosphere.Size * 0.9f,
Tint = Atmosphere.CloudTint,
TexturePath = Atmosphere.Cloud,
CapPath = Atmosphere.CloudCap,
RampPath = Atmosphere.CloudRamp,
FluidType = Atmosphere.FluidType,
UseBasicCloudShader = Atmosphere.UseBasicCloudShader,
Unlit = !Atmosphere.ShadowsOnClouds,
};
}
// Validate
if (Atmosphere.Clouds?.LightningGradient != null)
{
Atmosphere.Clouds.HasLightning = true;
}
// Former is obsolete, latter is to validate
if (Atmosphere.HasAtmosphere || Atmosphere.AtmosphereTint != null)
{
Atmosphere.UseAtmosphereShader = true;
}
}
if(Props?.Tornados != null)
{
foreach(var tornado in Props.Tornados)
{
if (tornado.downwards) tornado.type = "downwards";
}
}
#pragma warning restore 612, 618
}
}
}