diff --git a/NewHorizons/Builder/Body/LavaBuilder.cs b/NewHorizons/Builder/Body/LavaBuilder.cs index 44e1230b..9673d9c3 100644 --- a/NewHorizons/Builder/Body/LavaBuilder.cs +++ b/NewHorizons/Builder/Body/LavaBuilder.cs @@ -1,4 +1,5 @@ -using OWML.Utils; +using NewHorizons.External.VariableSize; +using OWML.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -11,13 +12,13 @@ namespace NewHorizons.Builder.Body { static class LavaBuilder { - public static void Make(GameObject body, Sector sector, OWRigidbody rb, float lavaSize) + public static void Make(GameObject body, Sector sector, OWRigidbody rb, LavaModule module) { var moltenCore = new GameObject("MoltenCore"); moltenCore.SetActive(false); moltenCore.transform.parent = body.transform; moltenCore.transform.localPosition = Vector3.zero; - moltenCore.transform.localScale = Vector3.one * lavaSize; + moltenCore.transform.localScale = Vector3.one * module.Radius; var lavaSphere = GameObject.Instantiate(GameObject.Find("VolcanicMoon_Body/MoltenCore_VM/LavaSphere"), moltenCore.transform); lavaSphere.transform.localScale = Vector3.one; diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index ef2c6b56..101c3d00 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using UnityEngine; using NewHorizons.Utility; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.External.VariableSize; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/SandBuilder.cs b/NewHorizons/Builder/Body/SandBuilder.cs new file mode 100644 index 00000000..ff7a28dd --- /dev/null +++ b/NewHorizons/Builder/Body/SandBuilder.cs @@ -0,0 +1,18 @@ +using NewHorizons.External.VariableSize; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Builder.Body +{ + static class SandBuilder + { + public static void Make(GameObject go, Sector sector, OWRigidbody rb, SandModule module) + { + + } + } +} diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 3a870540..0194225f 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using UnityEngine; using NewHorizons.Utility; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.External.VariableSize; namespace NewHorizons.Builder.Body { @@ -26,7 +27,6 @@ namespace NewHorizons.Builder.Body sunSurface.transform.localScale = Vector3.one; sunSurface.name = "Surface"; - //var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform); var sunLight = new GameObject(); sunLight.transform.parent = starGO.transform; sunLight.transform.localPosition = Vector3.zero; @@ -61,12 +61,26 @@ namespace NewHorizons.Builder.Body sunAudio.name = "Audio_Star"; - /* - var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); - sunAtmosphere.transform.localPosition = Vector3.zero; - sunAtmosphere.transform.localScale = Vector3.one; - sunAtmosphere.name = "Atmosphere_Star"; - */ + if(starModule.HasAtmosphere) + { + var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform); + sunAtmosphere.transform.localPosition = Vector3.zero; + sunAtmosphere.transform.localScale = Vector3.one; + sunAtmosphere.name = "Atmosphere_Star"; + PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); + if (starModule.Tint != null) + { + fog.fogTint = starModule.Tint.ToColor32(); + sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000) / starModule.Size; + foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) + { + lod.material.SetColor("_SkyColor", starModule.Tint.ToColor32()); + lod.material.SetFloat("_InnerRadius", starModule.Size); + lod.material.SetFloat("_OuterRadius", starModule.Size + 1000); + } + } + fog.fogRadius = starModule.Size * 1.2f; + } var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform); ambientLightGO.transform.localPosition = Vector3.zero; @@ -84,7 +98,6 @@ namespace NewHorizons.Builder.Body deathVolume.GetComponent().radius = 1f; deathVolume.name = "DestructionVolume"; - //PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); TessellatedSphereRenderer surface = sunSurface.GetComponent(); Light ambientLight = ambientLightGO.GetComponent(); @@ -103,12 +116,11 @@ namespace NewHorizons.Builder.Body light.color = lightColour; ambientLight.color = lightColour; - //fog.fogRadius = starModule.Size * 1.2f; if(starModule.Tint != null) { var colour = starModule.Tint.ToColor32(); //sunLightController.sunColor = colour; - //fog.fogTint = colour; + var sun = GameObject.Find("Sun_Body"); var mainSequenceMaterial = sun.GetComponent().GetValue("_startSurfaceMaterial"); @@ -118,16 +130,6 @@ namespace NewHorizons.Builder.Body var mod = 8f * starModule.SolarLuminosity / 255f; surface.sharedMaterial.color = new Color(colour.r * mod, colour.g * mod, colour.b * mod); surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.TintImage(_colorOverTime, colour)); - - /* - sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000)/starModule.Size; - foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) - { - lod.material.SetColor("_SkyColor", colour); - lod.material.SetFloat("_InnerRadius", starModule.Size); - lod.material.SetFloat("_OuterRadius", starModule.Size + 1000); - } - */ } if(starModule.SolarFlareTint != null) diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index 295eb155..ef5287f6 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.External; +using NewHorizons.External.VariableSize; using OWML.Utils; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -7,9 +8,9 @@ namespace NewHorizons.Builder.Body { static class WaterBuilder { - public static void Make(GameObject body, Sector sector, OWRigidbody rb, IPlanetConfig config) + public static void Make(GameObject body, Sector sector, OWRigidbody rb, WaterModule module) { - var waterSize = config.Base.WaterSize; + var waterSize = module.Radius; GameObject waterGO = new GameObject("Water"); waterGO.SetActive(false); @@ -28,9 +29,9 @@ namespace NewHorizons.Builder.Body for(int i = 0; i < GDSharedMaterials.Length; i++) { tempArray[i] = new Material(GDSharedMaterials[i]); - if (config.Base.WaterTint != null) + if (module.Tint != null) { - tempArray[i].color = config.Base.WaterTint.ToColor32(); + tempArray[i].color = module.Tint.ToColor32(); } } // TODO: Make water module diff --git a/NewHorizons/External/BaseModule.cs b/NewHorizons/External/BaseModule.cs index 2246e671..85cf6dda 100644 --- a/NewHorizons/External/BaseModule.cs +++ b/NewHorizons/External/BaseModule.cs @@ -15,10 +15,7 @@ namespace NewHorizons.External public string GravityFallOff { get; set; } = "linear"; public float SurfaceSize { get; set; } public float SphereOfInfluence { get; set; } - public float WaterSize { get; set; } - public MColor32 WaterTint { get; set; } public float GroundSize { get; set; } - public float LavaSize { get; set; } public bool HasCometTail { get; set; } public bool HasReferenceFrame { get; set; } = true; public bool CenterOfSolarSystem { get; set; } = false; @@ -26,5 +23,8 @@ namespace NewHorizons.External // Old, see SingularityModule instead public float BlackHoleSize { get; set; } + public float LavaSize { get; set; } + public float WaterSize { get; set; } + public MColor32 WaterTint { get; set; } } } diff --git a/NewHorizons/External/IPlanetConfig.cs b/NewHorizons/External/IPlanetConfig.cs index db8f9af4..822190af 100644 --- a/NewHorizons/External/IPlanetConfig.cs +++ b/NewHorizons/External/IPlanetConfig.cs @@ -1,14 +1,15 @@ -using NewHorizons.Utility; +using NewHorizons.External.VariableSize; +using NewHorizons.Utility; namespace NewHorizons.External { public interface IPlanetConfig { string Name { get; } - string StarSystem { get; } + string StarSystem { get; } bool Destroy { get; } int BuildPriority { get; } - BaseModule Base {get;} + BaseModule Base { get; } AtmosphereModule Atmosphere { get; } OrbitModule Orbit { get; } RingModule Ring { get; } @@ -21,5 +22,8 @@ namespace NewHorizons.External SpawnModule Spawn { get; } SignalModule Signal { get; } SingularityModule Singularity { get; } + LavaModule Lava { get; } + SandModule Sand { get; } + WaterModule Water { get; } } } diff --git a/NewHorizons/External/PlanetConfig.cs b/NewHorizons/External/PlanetConfig.cs index 369b6350..f3418d86 100644 --- a/NewHorizons/External/PlanetConfig.cs +++ b/NewHorizons/External/PlanetConfig.cs @@ -1,4 +1,5 @@ -using NewHorizons.Utility; +using NewHorizons.External.VariableSize; +using NewHorizons.Utility; using System; using System.Collections.Generic; using System.Globalization; @@ -24,6 +25,9 @@ namespace NewHorizons.External public SpawnModule Spawn { get; set; } public SignalModule Signal { get; set; } public SingularityModule Singularity { get; set; } + public LavaModule Lava { get; set; } + public WaterModule Water { get; set; } + public SandModule Sand { get; set; } public PlanetConfig(Dictionary dict) { diff --git a/NewHorizons/External/VariableSize/LavaModule.cs b/NewHorizons/External/VariableSize/LavaModule.cs new file mode 100644 index 00000000..0a05e71f --- /dev/null +++ b/NewHorizons/External/VariableSize/LavaModule.cs @@ -0,0 +1,15 @@ +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.VariableSize +{ + public class LavaModule : VariableSizeModule + { + public float Radius { get; set; } + public MColor32 Tint { get; set; } + } +} diff --git a/NewHorizons/External/RingModule.cs b/NewHorizons/External/VariableSize/RingModule.cs similarity index 83% rename from NewHorizons/External/RingModule.cs rename to NewHorizons/External/VariableSize/RingModule.cs index 91b22c33..60a6cd2d 100644 --- a/NewHorizons/External/RingModule.cs +++ b/NewHorizons/External/VariableSize/RingModule.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NewHorizons.External +namespace NewHorizons.External.VariableSize { - public class RingModule : Module + public class RingModule : VariableSizeModule { public float InnerRadius { get; set; } public float OuterRadius { get; set; } diff --git a/NewHorizons/External/VariableSize/SandModule.cs b/NewHorizons/External/VariableSize/SandModule.cs new file mode 100644 index 00000000..458b8e6e --- /dev/null +++ b/NewHorizons/External/VariableSize/SandModule.cs @@ -0,0 +1,15 @@ +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.VariableSize +{ + public class SandModule : VariableSizeModule + { + public float Radius { get; set; } + public MColor32 Tint { get; set; } + } +} diff --git a/NewHorizons/External/SingularityModule.cs b/NewHorizons/External/VariableSize/SingularityModule.cs similarity index 78% rename from NewHorizons/External/SingularityModule.cs rename to NewHorizons/External/VariableSize/SingularityModule.cs index 42fae1aa..536c8810 100644 --- a/NewHorizons/External/SingularityModule.cs +++ b/NewHorizons/External/VariableSize/SingularityModule.cs @@ -5,9 +5,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NewHorizons.External +namespace NewHorizons.External.VariableSize { - public class SingularityModule : Module + public class SingularityModule : VariableSizeModule { public float Size; public string PairedSingularity; diff --git a/NewHorizons/External/StarModule.cs b/NewHorizons/External/VariableSize/StarModule.cs similarity index 73% rename from NewHorizons/External/StarModule.cs rename to NewHorizons/External/VariableSize/StarModule.cs index 6288367b..d2dc23e3 100644 --- a/NewHorizons/External/StarModule.cs +++ b/NewHorizons/External/VariableSize/StarModule.cs @@ -5,14 +5,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NewHorizons.External +namespace NewHorizons.External.VariableSize { - public class StarModule : Module + public class StarModule : VariableSizeModule { public float Size { get; set; } = 2000f; public MColor32 Tint { get; set; } public MColor32 SolarFlareTint { get; set; } public MColor32 LightTint { get; set; } public float SolarLuminosity { get; set; } = 1f; + public bool HasAtmosphere { get; set; } = true; } } diff --git a/NewHorizons/External/VariableSize/VariableSizeModule.cs b/NewHorizons/External/VariableSize/VariableSizeModule.cs new file mode 100644 index 00000000..da7771f4 --- /dev/null +++ b/NewHorizons/External/VariableSize/VariableSizeModule.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.VariableSize +{ + public class VariableSizeModule : Module + { + public TimeValuePair[] Curve { get; set; } + + public class TimeValuePair + { + public float Time { get; set; } + public float Value { get; set; } + } + } +} diff --git a/NewHorizons/External/VariableSize/WaterModule.cs b/NewHorizons/External/VariableSize/WaterModule.cs new file mode 100644 index 00000000..72f95997 --- /dev/null +++ b/NewHorizons/External/VariableSize/WaterModule.cs @@ -0,0 +1,15 @@ +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.VariableSize +{ + public class WaterModule : VariableSizeModule + { + public float Radius { get; set; } + public MColor32 Tint { get; set; } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 229adad8..4e5f732f 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -6,6 +6,7 @@ using NewHorizons.Builder.Orbital; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.External; +using NewHorizons.External.VariableSize; using NewHorizons.OrbitalPhysics; using NewHorizons.Utility; using OWML.Common; @@ -506,11 +507,31 @@ namespace NewHorizons if (body.Config.Base.HasCometTail) CometTailBuilder.Make(go, body.Config.Base, go.GetComponent().GetPrimaryBody()); + // Backwards compatability if (body.Config.Base.LavaSize != 0) - LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize); + { + var lava = new LavaModule(); + lava.Radius = body.Config.Base.LavaSize; + LavaBuilder.Make(go, sector, rb, lava); + } + if (body.Config.Lava != null) + LavaBuilder.Make(go, sector, rb, body.Config.Lava); + + // Backwards compatability if (body.Config.Base.WaterSize != 0) - WaterBuilder.Make(go, sector, rb, body.Config); + { + var water = new WaterModule(); + water.Radius = body.Config.Base.WaterSize; + water.Tint = body.Config.Base.WaterTint; + WaterBuilder.Make(go, sector, rb, water); + } + + if (body.Config.Water != null) + WaterBuilder.Make(go, sector, rb, body.Config.Water); + + if (body.Config.Sand != null) + SandBuilder.Make(go, sector, rb, body.Config.Sand); if (body.Config.Atmosphere != null) { diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index acad379a..8d5ab98c 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -54,50 +54,11 @@ "default": 0, "description": "An override for the radius of the planet's gravitational sphere of influence. Optional" }, - "waterSize": { - "type": "number", - "default": 0, - "description": "Sea level for the planet. Optional" - }, - "waterTint": { - "type": "object", - "properties": { - "R": { - "type": "integer", - "default": 0, - "minimum": 0, - "maximum": 255 - }, - "G": { - "type": "integer", - "default": 0, - "minimum": 0, - "maximum": 255 - }, - "B": { - "type": "integer", - "default": 0, - "minimum": 0, - "maximum": 255 - }, - "A": { - "type": "integer", - "default": 0, - "minimum": 0, - "maximum": 255 - } - } - }, "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." }, - "lavaSize": { - "type": "number", - "default": 0, - "description": "Radius of a sphere of lava. Optional." - }, "hasCometTail": { "type": "boolean", "default": false @@ -171,7 +132,7 @@ "useBasicCloudShader": { "type": "boolean", "default": false, - "description" : "Use Giant's deep shader or just apply the cloud texture as is." + "description": "Use Giant's deep shader or just apply the cloud texture as is." }, "fogTint": { "type": "object", @@ -585,6 +546,10 @@ "minimum": 0, "description": "Relative strenght of the light compared to the sun", "default": 1 + }, + "hasAtmosphere": { + "type": "boolean", + "default": true } } }, @@ -891,6 +856,110 @@ } } } + }, + "Water": { + "type": "object", + "properties": { + "radius": { + "type": "number", + "default": 0 + }, + "tint": { + "type": "object", + "properties": { + "R": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "G": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "B": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "A": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + } + } + }, + "curve": { + "type": "array", + "items": { + "type": "object", + "properties": { + "time": { + "type": "integer", + "default": 0 + }, + "value": { + "type": "integer", + "default": 0 + } + } + } + } + } + }, + "Lava": { + "type": "object", + "properties": { + "radius": { + "type": "number", + "default": 0 + }, + "curve": { + "type": "array", + "items": { + "type": "object", + "properties": { + "time": { + "type": "integer", + "default": 0 + }, + "value": { + "type": "integer", + "default": 0 + } + } + } + } + } + }, + "Sand": { + "type": "object", + "properties": { + "radius": { + "type": "number", + "default": 0 + }, + "curve": { + "type": "array", + "items": { + "type": "object", + "properties": { + "time": { + "type": "integer", + "default": 0 + }, + "value": { + "type": "integer", + "default": 0 + } + } + } + } + } } } } \ No newline at end of file