From 23f3005d46cccd3b880039f95c8d656083e5ebde Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 20 May 2022 01:52:08 -0400 Subject: [PATCH] Lighting + Cloud refactor --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 4 +- .../Builder/Atmosphere/CloudsBuilder.cs | 71 +++++++--- .../Builder/Atmosphere/VolumesBuilder.cs | 4 +- NewHorizons/Builder/Body/ProxyBuilder.cs | 2 +- .../Builder/Orbital/OrbitlineBuilder.cs | 2 +- NewHorizons/Builder/Props/PropBuildManager.cs | 2 +- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 2 +- NewHorizons/External/Configs/PlanetConfig.cs | 41 +++++- .../External/Modules/AtmosphereModule.cs | 41 ++++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Handlers/TitleSceneHandler.cs | 6 +- NewHorizons/Main.cs | 4 +- NewHorizons/Schemas/body_schema.json | 125 ++++++++++++------ NewHorizons/Utility/MGradient.cs | 20 +++ 14 files changed, 235 insertions(+), 91 deletions(-) create mode 100644 NewHorizons/Utility/MGradient.cs diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index c26bac3c..f8cb0070 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -10,7 +10,7 @@ namespace NewHorizons.Builder.Atmosphere atmoGO.SetActive(false); atmoGO.transform.parent = sector?.transform ?? planetGO.transform; - if (atmosphereModule.HasAtmosphere) + if (atmosphereModule.UseAtmosphereShader) { GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere")); atmo.transform.parent = atmoGO.transform; @@ -18,7 +18,7 @@ namespace NewHorizons.Builder.Atmosphere atmo.transform.localScale = Vector3.one * atmosphereModule.Size * 1.2f; foreach (var meshRenderer in atmo.GetComponentsInChildren()) { - meshRenderer.material.SetFloat("_InnerRadius", atmosphereModule.Cloud != null ? atmosphereModule.Size : surfaceSize); + meshRenderer.material.SetFloat("_InnerRadius", atmosphereModule.Clouds != null ? atmosphereModule.Size : surfaceSize); meshRenderer.material.SetFloat("_OuterRadius", atmosphereModule.Size * 1.2f); if (atmosphereModule.AtmosphereTint != null) meshRenderer.material.SetColor("_SkyColor", atmosphereModule.AtmosphereTint.ToColor()); diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index 5abf1deb..dacdbd8f 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -10,9 +10,11 @@ namespace NewHorizons.Builder.Atmosphere { private static Shader _sphereShader = null; private static Material[] _gdCloudMaterials; + private static GameObject _lightningPrefab; + public static void Make(GameObject planetGO, Sector sector, AtmosphereModule atmo, IModBehaviour mod) { - Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32(); + if (_lightningPrefab == null) _lightningPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Clouds_GD/LightningGenerator_GD"); GameObject cloudsMainGO = new GameObject("Clouds"); cloudsMainGO.SetActive(false); @@ -23,16 +25,16 @@ namespace NewHorizons.Builder.Atmosphere GameObject cloudsBottomGO = new GameObject("BottomClouds"); cloudsBottomGO.SetActive(false); cloudsBottomGO.transform.parent = cloudsMainGO.transform; - cloudsBottomGO.transform.localScale = Vector3.one * (atmo.Size * 0.9f); + cloudsBottomGO.transform.localScale = Vector3.one * atmo.Clouds.InnerCloudRadius; TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_QM").GetComponent().tessellationMeshGroup; var bottomTSRMaterials = GameObject.Find("CloudsBottomLayer_QM").GetComponent().sharedMaterials; // If they set a colour apply it to all the materials else keep the default QM one - if (atmo.CloudTint != null) + if (atmo.Clouds.Tint != null) { - var bottomColor = cloudTint; + var bottomColor = atmo.Clouds.Tint.ToColor(); var bottomTSRTempArray = new Material[2]; @@ -74,15 +76,15 @@ namespace NewHorizons.Builder.Atmosphere fluidCLFV._density = 1.2f; var fluidType = FluidVolume.Type.CLOUD; - if (!string.IsNullOrEmpty(atmo.CloudFluidType)) + if (!string.IsNullOrEmpty(atmo.Clouds.FluidType)) { try { - fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), atmo.CloudFluidType.ToUpper()); + fluidType = (FluidVolume.Type)Enum.Parse(typeof(FluidVolume.Type), atmo.Clouds.FluidType.ToUpper()); } catch (Exception ex) { - Logger.LogError($"Couldn't parse fluid volume type [{atmo.CloudFluidType}]: {ex.Message}, {ex.StackTrace}"); + Logger.LogError($"Couldn't parse fluid volume type [{atmo.Clouds.FluidType}]: {ex.Message}, {ex.StackTrace}"); } } @@ -93,7 +95,32 @@ namespace NewHorizons.Builder.Atmosphere // Fix the rotations once the rest is done cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, 0, 0)); // For the base shader it has to be rotated idk - if (atmo.UseBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + if (atmo.Clouds.UseBasicCloudShader) cloudsMainGO.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(90, 0, 0)); + + // Lightning + if (atmo.Clouds.HasLightning) + { + var lightning = _lightningPrefab.InstantiateInactive(); + lightning.transform.parent = cloudsMainGO.transform; + lightning.transform.localPosition = Vector3.zero; + + var lightningGenerator = lightning.GetComponent(); + lightningGenerator._altitude = (atmo.Clouds.OuterCloudRadius + atmo.Clouds.InnerCloudRadius) / 2f; + lightningGenerator._audioSector = sector; + if (atmo.Clouds.LightningGradient != null) + { + var gradient = new GradientColorKey[atmo.Clouds.LightningGradient.Length]; + + for(int i = 0; i < atmo.Clouds.LightningGradient.Length; i++) + { + var pair = atmo.Clouds.LightningGradient[i]; + gradient[i] = new GradientColorKey(pair.Tint.ToColor(), pair.Time); + } + + lightningGenerator._lightColor.colorKeys = gradient; + } + lightning.SetActive(true); + } cloudsMainGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); cloudsBottomGO.transform.position = planetGO.transform.TransformPoint(Vector3.zero); @@ -106,18 +133,18 @@ namespace NewHorizons.Builder.Atmosphere public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) { - Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32(); + Color cloudTint = atmo.Clouds.Tint == null ? Color.white : atmo.Clouds.Tint.ToColor(); Texture2D image, cap, ramp; try { - image = ImageUtilities.GetTexture(mod, atmo.Cloud); + image = ImageUtilities.GetTexture(mod, atmo.Clouds.TexturePath); - if (atmo.CloudCap == null) cap = ImageUtilities.ClearTexture(128, 128); - else cap = ImageUtilities.GetTexture(mod, atmo.CloudCap); - if (atmo.CloudRamp == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); - else ramp = ImageUtilities.GetTexture(mod, atmo.CloudRamp); + if (atmo.Clouds.CapPath == null) cap = ImageUtilities.ClearTexture(128, 128); + else cap = ImageUtilities.GetTexture(mod, atmo.Clouds.CapPath); + if (atmo.Clouds.RampPath == null) ramp = ImageUtilities.CanvasScaled(image, 1, image.height); + else ramp = ImageUtilities.GetTexture(mod, atmo.Clouds.RampPath); } catch (Exception e) { @@ -128,7 +155,7 @@ namespace NewHorizons.Builder.Atmosphere GameObject cloudsTopGO = new GameObject("TopClouds"); cloudsTopGO.SetActive(false); cloudsTopGO.transform.parent = rootObject.transform; - cloudsTopGO.transform.localScale = Vector3.one * atmo.Size; + cloudsTopGO.transform.localScale = Vector3.one * atmo.Clouds.OuterCloudRadius; MeshFilter topMF = cloudsTopGO.AddComponent(); topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; @@ -139,19 +166,19 @@ namespace NewHorizons.Builder.Atmosphere if (_gdCloudMaterials == null) _gdCloudMaterials = GameObject.Find("CloudsTopLayer_GD").GetComponent().sharedMaterials; var tempArray = new Material[2]; - if (atmo.UseBasicCloudShader) + if (atmo.Clouds.UseBasicCloudShader) { var material = new Material(_sphereShader); - if (!atmo.ShadowsOnClouds) material.renderQueue = 2550; - material.name = atmo.ShadowsOnClouds ? "BasicShadowCloud" : "BasicCloud"; + if (atmo.Clouds.Unlit) material.renderQueue = 2550; + material.name = atmo.Clouds.Unlit ? "BasicCloud" : "BasicShadowCloud"; tempArray[0] = material; } else { var material = new Material(_gdCloudMaterials[0]); - if (!atmo.ShadowsOnClouds) material.renderQueue = 2550; - material.name = atmo.ShadowsOnClouds ? "AdvancedShadowCloud" : "AdvancedCloud"; + if (atmo.Clouds.Unlit) material.renderQueue = 2550; + material.name = atmo.Clouds.Unlit ? "AdvancedCloud" : "AdvancedShadowCloud"; tempArray[0] = material; } @@ -169,14 +196,14 @@ namespace NewHorizons.Builder.Atmosphere material.SetTexture("_CapTex", cap); } - if (!atmo.ShadowsOnClouds) + if (atmo.Clouds.Unlit) { cloudsTopGO.layer = LayerMask.NameToLayer("IgnoreSun"); } RotateTransform topRT = cloudsTopGO.AddComponent(); // Idk why but the axis is weird - topRT._localAxis = atmo.UseBasicCloudShader ? Vector3.forward : Vector3.up; + topRT._localAxis = atmo.Clouds.UseBasicCloudShader ? Vector3.forward : Vector3.up; topRT._degreesPerSecond = 10; topRT._randomizeRotationRate = false; diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index 5f3a79f6..545de8ff 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -40,9 +40,9 @@ namespace NewHorizons.Builder.Atmosphere ER._material = gdRuleset._material; var cloudMaterial = new Material(gdRuleset._cloudMaterial); - if (config.Atmosphere?.CloudTint != null) + if (config.Atmosphere?.Clouds?.Tint != null) { - cloudMaterial.SetColor("_FogColor", config.Atmosphere.CloudTint.ToColor32()); + cloudMaterial.SetColor("_FogColor", config.Atmosphere.Clouds.Tint.ToColor32()); } ER._cloudMaterial = cloudMaterial; diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index e7c7df5d..2ce8f45a 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Body GeometryBuilder.Make(newProxy, null, body.Config.Base.GroundSize); if (realSize < body.Config.Base.GroundSize) realSize = body.Config.Base.GroundSize; } - if (body.Config.Atmosphere?.Cloud != null) + if (body.Config.Atmosphere?.Clouds != null) { CloudsBuilder.MakeTopClouds(newProxy, body.Config.Atmosphere, body.Mod); if (realSize < body.Config.Atmosphere.Size) realSize = body.Config.Atmosphere.Size; diff --git a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs index 66396f27..d8fda4d7 100644 --- a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs +++ b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Orbital var color = Color.white; if (config.Orbit.Tint != null) color = config.Orbit.Tint.ToColor32(); else if (config.Star != null) color = config.Star.Tint.ToColor32(); - else if (config.Atmosphere != null && config.Atmosphere.CloudTint != null) color = config.Atmosphere.CloudTint.ToColor32(); + else if (config.Atmosphere?.Clouds?.Tint != null) color = config.Atmosphere.Clouds.Tint.ToColor32(); else if (config.Singularity != null) color = new Color(1f, 0.5f, 1f); else if (config.Water != null) color = new Color(0.5f, 0.5f, 1f); else if (config.Lava != null) color = new Color(1f, 0.5f, 0.5f); diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 52410373..b50ca21e 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -69,7 +69,7 @@ namespace NewHorizons.Builder.Props { try { - TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null); + TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Clouds != null); } catch (Exception ex) { diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index fa155830..19081f08 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -518,7 +518,7 @@ namespace NewHorizons.Builder.ShipLog if (starColor != null) return starColor.ToColor(); var atmoColor = body.Config.Atmosphere?.AtmosphereTint; - if (body.Config.Atmosphere?.Cloud != null && atmoColor != null) return atmoColor.ToColor(); + if (body.Config.Atmosphere?.Clouds != null && atmoColor != null) return atmoColor.ToColor(); if (body.Config?.HeightMap?.TextureMap != null) { diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index a8d913d9..0018f280 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -1,5 +1,7 @@ using NewHorizons.External.Modules; using NewHorizons.External.Modules.VariableSize; +using NewHorizons.Utility; +using UnityEngine; namespace NewHorizons.External.Configs { @@ -44,13 +46,15 @@ namespace NewHorizons.External.Configs if (ShipLog == null) ShipLog = new ShipLogModule(); } - public void Validate() + 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 +#pragma warning disable 612, 618 if (Base.WaterSize != 0) { Water = new WaterModule(); @@ -85,7 +89,38 @@ namespace NewHorizons.External.Configs { Base.AmbientLight = 0.5f; } - #pragma warning restore 612, 618 + + 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.CloudFluidType, + 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; + } + } +#pragma warning restore 612, 618 } } } diff --git a/NewHorizons/External/Modules/AtmosphereModule.cs b/NewHorizons/External/Modules/AtmosphereModule.cs index 2105a0f1..eef320fd 100644 --- a/NewHorizons/External/Modules/AtmosphereModule.cs +++ b/NewHorizons/External/Modules/AtmosphereModule.cs @@ -1,24 +1,32 @@ using NewHorizons.Utility; +using UnityEngine; + namespace NewHorizons.External.Modules { public class AtmosphereModule { public float Size { get; set; } - public MColor CloudTint { get; set; } - public string Cloud { get; set; } - public string CloudCap { get; set; } - public string CloudRamp { get; set; } - public string CloudFluidType { get; set; } - public bool UseBasicCloudShader { get; set; } - public bool ShadowsOnClouds { get; set; } = true; + public MColor AtmosphereTint { get; set; } public MColor FogTint { get; set; } public float FogDensity { get; set; } public float FogSize { get; set; } public bool HasRain { get; set; } public bool HasSnow { get; set; } public bool HasOxygen { get; set; } - public bool HasAtmosphere { get; set; } - public MColor AtmosphereTint { get; set; } + public bool UseAtmosphereShader { get; set; } + public CloudInfo Clouds { get; set; } + + + #region Obsolete + [System.Obsolete("CloudTint is deprecated, please use CloudInfo instead")] public MColor CloudTint { get; set; } + [System.Obsolete("CloudTint is deprecated, please use CloudInfo instead")] public string Cloud { get; set; } + [System.Obsolete("CloudCap is deprecated, please use CloudInfo instead")] public string CloudCap { get; set; } + [System.Obsolete("CloudRamp is deprecated, please use CloudInfo instead")] public string CloudRamp { get; set; } + [System.Obsolete("CloudFluidType is deprecated, please use CloudInfo instead")] public string CloudFluidType { get; set; } + [System.Obsolete("UseBasicCloudShader is deprecated, please use CloudInfo instead")] public bool UseBasicCloudShader { get; set; } + [System.Obsolete("ShadowsOnClouds is deprecated, please use CloudInfo instead")] public bool ShadowsOnClouds { get; set; } = true; + [System.Obsolete("HasAtmosphere is deprecated, please use UseAtmosphereShader instead")] public bool HasAtmosphere { get; set; } + #endregion Obsolete public class AirInfo { @@ -27,5 +35,20 @@ namespace NewHorizons.External.Modules public bool IsRaining { get; set; } public bool IsSnowing { get; set; } } + + public class CloudInfo + { + public float OuterCloudRadius { get; set; } + public float InnerCloudRadius { get; set; } + public MColor Tint { get; set; } + public string TexturePath { get; set; } + public string CapPath { get; set; } + public string RampPath { get; set; } + public string FluidType { get; set; } + public bool UseBasicCloudShader { get; set; } + public bool Unlit { get; set; } + public bool HasLightning { get; set; } + public MGradient[] LightningGradient { get; set; } + } } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 68cd3e8c..9132cfa8 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -447,7 +447,7 @@ namespace NewHorizons.Handlers AirBuilder.Make(go, sector, airInfo); - if (!string.IsNullOrEmpty(body.Config.Atmosphere.Cloud)) + if (!string.IsNullOrEmpty(body.Config.Atmosphere?.Clouds?.TexturePath)) { CloudsBuilder.Make(go, sector, body.Config.Atmosphere, body.Mod); SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, surfaceSize); diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index b2dfee2b..f0e82aa0 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -15,7 +15,7 @@ namespace NewHorizons.Handlers { //Try loading one planet why not //var eligible = BodyDict.Values.ToList().SelectMany(x => x).ToList().Where(b => (b.Config.HeightMap != null || b.Config.Atmosphere?.Cloud != null) && b.Config.Star == null).ToArray(); - var eligible = bodies.Where(b => (b.Config.HeightMap != null || b.Config.Atmosphere?.Cloud != null) && b.Config.Star == null && b.Config.CanShowOnTitle).ToArray(); + var eligible = bodies.Where(b => (b.Config.HeightMap != null || b.Config.Atmosphere?.Clouds != null) && b.Config.Star == null && b.Config.CanShowOnTitle).ToArray(); var eligibleCount = eligible.Count(); if (eligibleCount == 0) return; @@ -74,12 +74,12 @@ namespace NewHorizons.Handlers heightMap.MaxHeight = size; heightMap.MinHeight = body.Config.HeightMap.MinHeight * size / body.Config.HeightMap.MaxHeight; } - if (body.Config.Atmosphere != null && body.Config.Atmosphere.Cloud != null) + if (body.Config.Atmosphere?.Clouds?.TexturePath != null) { // Hacky but whatever I just want a sphere size = Mathf.Clamp(body.Config.Atmosphere.Size / 10, minSize, maxSize); heightMap.MaxHeight = heightMap.MinHeight = size + 1; - heightMap.TextureMap = body.Config.Atmosphere.Cloud; + heightMap.TextureMap = body.Config.Atmosphere.Clouds.TexturePath; } HeightMapBuilder.Make(titleScreenGO, null, heightMap, body.Mod); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index e6f90f9e..cdc0d03c 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -375,7 +375,7 @@ namespace NewHorizons try { var config = mod.ModHelper.Storage.Load(relativeDirectory); - config.Validate(); + config.MigrateAndValidate(); Logger.Log($"Loaded {config.Name}"); @@ -397,7 +397,7 @@ namespace NewHorizons } catch (Exception e) { - Logger.LogError($"Couldn't load {relativeDirectory}: {e.Message}, is your Json formatted correctly?"); + Logger.LogError($"Couldn't load {relativeDirectory}: {e.Message} {e.StackTrace}, is your Json formatted correctly?"); } return body; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index d2e433bf..0af3dbd7 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -60,21 +60,37 @@ "type": "object", "additionalProperties": false, "properties": { - "R": { + "r": { "$ref": "#/$defs/colorPart" }, - "G": { + "g": { "$ref": "#/$defs/colorPart" }, - "B": { + "b": { "$ref": "#/$defs/colorPart" }, - "A": { + "a": { "$ref": "#/$defs/colorPart", "default": 255 } } }, + "gradient": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "time": { + "type": "number", + "default": 0 + }, + "tint": { + "$ref": "#/$defs/color" + } + } + } + }, "angle": { "type": "number", "default": 0, @@ -288,44 +304,6 @@ "default": 0, "description": "Scale height of the atmosphere" }, - "cloudTint": { - "$ref": "#/$defs/color", - "description": "Colour of the cloud layer. Only relevant if \"cloud\" has a value" - }, - "cloud": { - "type": "string", - "description": "Relative filepath to the cloud texture, if the planet has clouds." - }, - "cloudCap": { - "type": "string", - "description": "Relative filepath to the cloud cap texture, if the planet has clouds." - }, - "cloudRamp": { - "type": "string", - "description": "Relative filepath to the cloud ramp texture, if the planet has clouds. If you don't put anything here it will be auto-generated." - }, - "cloudFluidType": { - "type": "string", - "default": "CLOUD", - "description": "Fluid type for sounds/effects when colliding with this cloud.", - "enum": [ - "NONE", - "WATER", - "CLOUD", - "SAND", - "PLASMA" - ] - }, - "useBasicCloudShader": { - "type": "boolean", - "default": false, - "description": "Set to `false` in order to use Giant's deep shader. Set to `true` to just apply the cloud texture as is." - }, - "shadowsOnClouds": { - "type": "boolean", - "default": true, - "description": "If the top layer should have shadows. Set to false if you're making a brown dwarf." - }, "fogTint": { "$ref": "#/$defs/color", "description": "Colour of fog on the planet, if you put fog." @@ -354,7 +332,7 @@ "default": false, "description": "Lets you survive on the planet without a suit." }, - "hasAtmosphere": { + "useAtmosphereShader": { "type": "boolean", "default": false, "description": "Whether we use an atmospheric shader on the planet. Doesn't affect clouds, fog, rain, snow, oxygen, etc. Purely visual." @@ -362,6 +340,67 @@ "atmosphereTint": { "$ref": "#/$defs/color", "description": "Colour of atmospheric shader on the planet." + }, + "clouds": { + "type": "object", + "additionalProperties": false, + "properties": { + "outerCloudRadius": { + "type": "number", + "description": "Radius from the center to the outer layer of the clouds." + }, + "innerCloudRadius": { + "type": "number", + "description": "Radius from the center to the inner layer of the clouds." + }, + "tint": { + "$ref": "#/$defs/color", + "description": "Colour of the inner cloud layer." + }, + "texturePath": { + "type": "string", + "description": "Relative filepath to the cloud texture, if the planet has clouds." + }, + "capPath": { + "type": "string", + "description": "Relative filepath to the cloud cap texture, if the planet has clouds." + }, + "rampPath": { + "type": "string", + "description": "Relative filepath to the cloud ramp texture, if the planet has clouds. If you don't put anything here it will be auto-generated." + }, + "fluidType": { + "type": "string", + "default": "CLOUD", + "description": "Fluid type for sounds/effects when colliding with this cloud.", + "enum": [ + "NONE", + "WATER", + "CLOUD", + "SAND", + "PLASMA" + ] + }, + "useBasicCloudShader": { + "type": "boolean", + "default": false, + "description": "Set to `false` in order to use Giant's deep shader. Set to `true` to just apply the cloud texture as is." + }, + "unlit": { + "type": "boolean", + "default": false, + "description": "If the top layer shouldn't have shadows. Set to true if you're making a brown dwarf for example." + }, + "hasLightning": { + "type": "boolean", + "default": false, + "description": "Add lightning to this planet like on Giant's Deep." + }, + "lightningGradient": { + "$ref": "#/$defs/gradient", + "description": "Colour gradient of the lightning, time is in seconds." + } + } } } }, diff --git a/NewHorizons/Utility/MGradient.cs b/NewHorizons/Utility/MGradient.cs new file mode 100644 index 00000000..4848cdc4 --- /dev/null +++ b/NewHorizons/Utility/MGradient.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Utility +{ + public class MGradient + { + public MGradient(float time, MColor tint) + { + Time = time; + Tint = tint; + } + + public float Time { get; } + public MColor Tint { get; } + } +}