From 64f81f9dcaec0024924d4d700f09fcf85d6ce0d9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 22 May 2022 16:25:53 -0700 Subject: [PATCH] make color good --- .../Builder/Atmosphere/AtmosphereBuilder.cs | 2 +- .../Builder/Atmosphere/CloudsBuilder.cs | 6 +++--- NewHorizons/Builder/Atmosphere/FogBuilder.cs | 4 ++-- .../Builder/Atmosphere/VolumesBuilder.cs | 2 +- NewHorizons/Builder/Body/FunnelBuilder.cs | 4 ++-- NewHorizons/Builder/Body/LavaBuilder.cs | 4 ++-- NewHorizons/Builder/Body/ProcGenBuilder.cs | 2 +- NewHorizons/Builder/Body/ProxyBuilder.cs | 6 +++--- NewHorizons/Builder/Body/SandBuilder.cs | 4 ++-- NewHorizons/Builder/Body/StarBuilder.cs | 18 +++++++++--------- NewHorizons/Builder/Body/WaterBuilder.cs | 6 +++--- .../Builder/Orbital/OrbitlineBuilder.cs | 8 ++++---- NewHorizons/Builder/Props/ProjectionBuilder.cs | 2 +- NewHorizons/Builder/Props/TornadoBuilder.cs | 4 ++-- NewHorizons/Builder/Props/VolcanoBuilder.cs | 4 ++-- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 10 +++++----- .../Builder/ShipLog/RumorModeBuilder.cs | 4 ++-- .../SizeControllers/StarEvolutionController.cs | 4 ++-- NewHorizons/Utility/MColor.cs | 4 +--- 19 files changed, 48 insertions(+), 50 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs index c60ae6a3..67de6b32 100644 --- a/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AtmosphereBuilder.cs @@ -24,7 +24,7 @@ namespace NewHorizons.Builder.Atmosphere 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()); + meshRenderer.material.SetColor(SkyColor, atmosphereModule.atmosphereTint); } atmo.SetActive(true); diff --git a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs index ea20d434..6b2bff82 100644 --- a/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/CloudsBuilder.cs @@ -39,7 +39,7 @@ namespace NewHorizons.Builder.Atmosphere // If they set a colour apply it to all the materials else keep the default QM one if (atmo.clouds.tint != null) { - var bottomColor = atmo.clouds.tint.ToColor(); + var bottomColor = atmo.clouds.tint; var bottomTSRTempArray = new Material[2]; @@ -119,7 +119,7 @@ namespace NewHorizons.Builder.Atmosphere 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); + gradient[i] = new GradientColorKey(pair.Tint, pair.Time); } lightningGenerator._lightColor.colorKeys = gradient; @@ -138,7 +138,7 @@ namespace NewHorizons.Builder.Atmosphere public static GameObject MakeTopClouds(GameObject rootObject, AtmosphereModule atmo, IModBehaviour mod) { - Color cloudTint = atmo.clouds.tint?.ToColor() ?? Color.white; + Color cloudTint = atmo.clouds.tint ?? Color.white; Texture2D image, cap, ramp; diff --git a/NewHorizons/Builder/Atmosphere/FogBuilder.cs b/NewHorizons/Builder/Atmosphere/FogBuilder.cs index 2ee92b02..be8f9345 100644 --- a/NewHorizons/Builder/Atmosphere/FogBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/FogBuilder.cs @@ -30,7 +30,7 @@ namespace NewHorizons.Builder.Atmosphere PFC.fogExponent = 1f; PFC.fogColorRampTexture = dbPlanetaryFogController.fogColorRampTexture; PFC.fogColorRampIntensity = 1f; - PFC.fogTint = atmo.fogTint.ToColor(); + PFC.fogTint = atmo.fogTint; GameObject lodFogGO = new GameObject("LODFogSphere"); lodFogGO.SetActive(false); @@ -42,7 +42,7 @@ namespace NewHorizons.Builder.Atmosphere MeshRenderer lodMR = lodFogGO.AddComponent(); lodMR.material = new Material(brambleLODFog.GetComponent().material); - lodMR.material.color = atmo.fogTint.ToColor(); + lodMR.material.color = atmo.fogTint; lodMR.material.renderQueue = 1000; /* diff --git a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs index 6a960870..e5dfc508 100644 --- a/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/VolumesBuilder.cs @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Atmosphere var cloudMaterial = new Material(gdRuleset._cloudMaterial); if (config.Atmosphere?.clouds?.tint != null) { - cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint.ToColor32()); + cloudMaterial.SetColor(FogColor, config.Atmosphere.clouds.tint); } ER._cloudMaterial = cloudMaterial; diff --git a/NewHorizons/Builder/Body/FunnelBuilder.cs b/NewHorizons/Builder/Body/FunnelBuilder.cs index 5f9ccd93..3f6b22ec 100644 --- a/NewHorizons/Builder/Body/FunnelBuilder.cs +++ b/NewHorizons/Builder/Body/FunnelBuilder.cs @@ -70,7 +70,7 @@ namespace NewHorizons.Builder.Body materials[i] = new Material(waterMaterials[i]); if (module.tint != null) { - materials[i].SetColor(FogColor, module.tint.ToColor()); + materials[i].SetColor(FogColor, module.tint); } } @@ -117,7 +117,7 @@ namespace NewHorizons.Builder.Body if (module.tint != null) { - lavaMaterial.SetColor(EmissionColor, module.tint.ToColor()); + lavaMaterial.SetColor(EmissionColor, module.tint); } proxyGO.GetComponentInChildren().material = lavaMaterial; diff --git a/NewHorizons/Builder/Body/LavaBuilder.cs b/NewHorizons/Builder/Body/LavaBuilder.cs index 9d2f40df..fde7cbe0 100644 --- a/NewHorizons/Builder/Body/LavaBuilder.cs +++ b/NewHorizons/Builder/Body/LavaBuilder.cs @@ -32,7 +32,7 @@ namespace NewHorizons.Builder.Body lavaSphere.transform.localScale = Vector3.one; lavaSphere.transform.name = "LavaSphere"; lavaSphere.GetComponent().material.SetFloat(HeightScale, heightScale); - if (module.tint != null) lavaSphere.GetComponent().material.SetColor(EmissionColor, module.tint.ToColor()); + if (module.tint != null) lavaSphere.GetComponent().material.SetColor(EmissionColor, module.tint); var sectorCullGroup = lavaSphere.GetComponent(); sectorCullGroup.SetSector(sector); @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Body proxyLavaSphere.transform.localScale = Vector3.one; proxyLavaSphere.name = "LavaSphere_Proxy"; proxyLavaSphere.GetComponent().material.SetFloat(HeightScale, heightScale); - if (module.tint != null) proxyLavaSphere.GetComponent().material.SetColor(EmissionColor, module.tint.ToColor()); + if (module.tint != null) proxyLavaSphere.GetComponent().material.SetColor(EmissionColor, module.tint); var sectorProxy = moltenCoreProxy.GetComponent(); sectorProxy._renderers = new List { proxyLavaSphere.GetComponent() }; diff --git a/NewHorizons/Builder/Body/ProcGenBuilder.cs b/NewHorizons/Builder/Body/ProcGenBuilder.cs index af13da22..af85572d 100644 --- a/NewHorizons/Builder/Body/ProcGenBuilder.cs +++ b/NewHorizons/Builder/Body/ProcGenBuilder.cs @@ -27,7 +27,7 @@ namespace NewHorizons.Builder.Body var cubeSphereMR = icosphere.AddComponent(); cubeSphereMR.material = new Material(Shader.Find("Standard")); - cubeSphereMR.material.color = module.color != null ? module.color.ToColor() : Color.white; + cubeSphereMR.material.color = module.color != null ? module.color : Color.white; var cubeSphereMC = icosphere.AddComponent(); cubeSphereMC.sharedMesh = mesh; diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index 33510c62..64f8fcd0 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -77,18 +77,18 @@ namespace NewHorizons.Builder.Body if (realSize < body.Config.Lava.size) realSize = body.Config.Lava.size; var material = new Material(lavaMaterial); - if (body.Config.Lava.tint != null) material.SetColor(EmissionColor, body.Config.Lava.tint.ToColor()); + if (body.Config.Lava.tint != null) material.SetColor(EmissionColor, body.Config.Lava.tint); sphere.GetComponent().material = material; } if (body.Config.Water != null) { - var colour = body.Config.Water.tint?.ToColor() ?? Color.blue; + var colour = body.Config.Water.tint ?? Color.blue; AddColouredSphere(newProxy, body.Config.Water.size, body.Config.Water.Curve, colour); if (realSize < body.Config.Water.size) realSize = body.Config.Water.size; } if (body.Config.Sand != null) { - var colour = body.Config.Sand.Tint?.ToColor() ?? Color.yellow; + var colour = body.Config.Sand.Tint ?? Color.yellow; AddColouredSphere(newProxy, body.Config.Sand.Size, body.Config.Sand.Curve, colour); if (realSize < body.Config.Sand.Size) realSize = body.Config.Sand.Size; } diff --git a/NewHorizons/Builder/Body/SandBuilder.cs b/NewHorizons/Builder/Body/SandBuilder.cs index 261a3434..a6037315 100644 --- a/NewHorizons/Builder/Body/SandBuilder.cs +++ b/NewHorizons/Builder/Body/SandBuilder.cs @@ -24,8 +24,8 @@ namespace NewHorizons.Builder.Body new Material(sandMaterials[1]) }; GameObject.Destroy(oldMR); - sandMR.sharedMaterials[0].color = module.Tint.ToColor32(); - sandMR.sharedMaterials[1].color = module.Tint.ToColor32(); + sandMR.sharedMaterials[0].color = module.Tint; + sandMR.sharedMaterials[1].color = module.Tint; } var collider = GameObject.Instantiate(GameObject.Find("TowerTwin_Body/SandSphere_Draining/Collider"), sandGO.transform); diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 0d93e1ae..07972a93 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -42,13 +42,13 @@ namespace NewHorizons.Builder.Body PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent(); if (starModule.tint != null) { - fog.fogTint = starModule.tint.ToColor(); + fog.fogTint = starModule.tint; sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one; foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren()) { - lod.material.SetColor(SkyColor, starModule.tint.ToColor()); - lod.material.SetColor(AtmosFar, starModule.tint.ToColor()); - lod.material.SetColor(AtmosNear, starModule.tint.ToColor()); + lod.material.SetColor(SkyColor, starModule.tint); + lod.material.SetColor(AtmosFar, starModule.tint); + lod.material.SetColor(AtmosNear, starModule.tint); lod.material.SetFloat(InnerRadius, starModule.size); lod.material.SetFloat(OuterRadius, starModule.size * OuterRadiusRatio); } @@ -90,7 +90,7 @@ namespace NewHorizons.Builder.Body light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; - if (starModule.lightTint != null) lightColour = starModule.lightTint.ToColor(); + if (starModule.lightTint != null) lightColour = starModule.lightTint; light.color = lightColour; ambientLight.color = lightColour; @@ -177,7 +177,7 @@ namespace NewHorizons.Builder.Body if (starModule.tint != null) { - var flareTint = starModule.tint.ToColor(); + var flareTint = starModule.tint; var emitter = solarFlareEmitter.GetComponent(); emitter.tint = flareTint; foreach (var controller in solarFlareEmitter.GetComponentsInChildren()) @@ -195,7 +195,7 @@ namespace NewHorizons.Builder.Body { TessellatedSphereRenderer surface = sunSurface.GetComponent(); - var colour = starModule.tint.ToColor(); + var colour = starModule.tint; var sun = GameObject.Find("Sun_Body"); var mainSequenceMaterial = sun.GetComponent().GetValue("_startSurfaceMaterial"); @@ -211,7 +211,7 @@ namespace NewHorizons.Builder.Body if (starModule.endTint != null) { - var endColour = starModule.endTint.ToColor(); + var endColour = starModule.endTint; darkenedColor = new Color(endColour.r * mod, endColour.g * mod, endColour.b * mod); } @@ -233,7 +233,7 @@ namespace NewHorizons.Builder.Body if (starModule.supernovaTint != null) { - var colour = starModule.supernovaTint.ToColor(); + var colour = starModule.supernovaTint; var supernovaMaterial = new Material(supernova._supernovaMaterial); var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Effects_SUN_Supernova_d.png"), Color.white, colour); diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index acca5a7d..bf0aaa12 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -40,8 +40,8 @@ namespace NewHorizons.Builder.Body tempArray[i] = new Material(GDSharedMaterials[i]); if (module.tint != null) { - tempArray[i].color = module.tint.ToColor(); - tempArray[i].SetColor("_FogColor", module.tint.ToColor()); + tempArray[i].color = module.tint; + tempArray[i].SetColor("_FogColor", module.tint); } } @@ -85,7 +85,7 @@ namespace NewHorizons.Builder.Body if (module.tint != null) { - var adjustedColour = module.tint.ToColor() / 4f; + var adjustedColour = (Color)module.tint / 4f; adjustedColour.a = adjustedColour.a * 4f; fogGO.GetComponent().material.color = adjustedColour; } diff --git a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs index 61a8b61a..0d494251 100644 --- a/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs +++ b/NewHorizons/Builder/Orbital/OrbitlineBuilder.cs @@ -57,13 +57,13 @@ 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?.clouds?.tint != null) color = config.Atmosphere.clouds.tint.ToColor32(); + if (config.Orbit.Tint != null) color = config.Orbit.Tint; + else if (config.Star != null) color = config.Star.tint; + else if (config.Atmosphere?.clouds?.tint != null) color = config.Atmosphere.clouds.tint; 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); - else if (config.Atmosphere != null && config.Atmosphere.fogTint != null) color = config.Atmosphere.fogTint.ToColor32(); + else if (config.Atmosphere != null && config.Atmosphere.fogTint != null) color = config.Atmosphere.fogTint; var fade = isMoon; diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 4b111c86..2a5bd451 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -185,7 +185,7 @@ namespace NewHorizons.Builder.Props var ambientLight = new SlideAmbientLightModule(); ambientLight._intensity = slideInfo.ambientLightIntensity; ambientLight._range = slideInfo.ambientLightRange; - ambientLight._color = slideInfo.ambientLightColor.ToColor(); + ambientLight._color = slideInfo.ambientLightColor; ambientLight._spotIntensityMod = slideInfo.spotIntensityMod; modules.Add(ambientLight); } diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index b7f0d6ef..9f39864c 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -148,7 +148,7 @@ namespace NewHorizons.Builder.Props if (info.tint != null) { - ApplyTint(tornadoGO, info.tint.ToColor(), false, downwards); + ApplyTint(tornadoGO, info.tint, false, downwards); } if (info.wanderRate != 0) @@ -205,7 +205,7 @@ namespace NewHorizons.Builder.Props if (info.tint != null) { - ApplyTint(hurricaneGO, info.tint.ToColor(), true, false); + ApplyTint(hurricaneGO, info.tint, true, false); } if (info.wanderRate != 0) diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index a9e04b51..ef649ddf 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -50,8 +50,8 @@ namespace NewHorizons.Builder.Props meteor.transform.localScale = Vector3.one * info.scale; var mat = meteor.GetComponentInChildren().material; - mat.SetColor(Color1, info.stoneTint?.ToColor() ?? defaultStoneTint); - mat.SetColor(EmissionColor, info.lavaTint?.ToColor() ?? defaultLavaTint); + mat.SetColor(Color1, info.stoneTint ?? defaultStoneTint); + mat.SetColor(EmissionColor, info.lavaTint ?? defaultLavaTint); var detectors = meteor.transform.Find("ConstantDetectors").gameObject; GameObject.Destroy(detectors.GetComponent()); diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 5b13fe77..8950f14a 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -521,10 +521,10 @@ namespace NewHorizons.Builder.ShipLog } var starColor = body.Config?.Star?.tint; - if (starColor != null) return starColor.ToColor(); + if (starColor != null) return starColor; var atmoColor = body.Config.Atmosphere?.atmosphereTint; - if (body.Config.Atmosphere?.clouds != null && atmoColor != null) return atmoColor.ToColor(); + if (body.Config.Atmosphere?.clouds != null && atmoColor != null) return atmoColor; if (body.Config?.HeightMap?.textureMap != null) { @@ -538,13 +538,13 @@ namespace NewHorizons.Builder.ShipLog } var waterColor = body.Config.Water?.tint; - if (waterColor != null) return waterColor.ToColor(); + if (waterColor != null) return waterColor; var lavaColor = body.Config.Lava?.tint; - if (lavaColor != null) return lavaColor.ToColor(); + if (lavaColor != null) return lavaColor; var sandColor = body.Config.Sand?.Tint; - if (sandColor != null) return sandColor.ToColor(); + if (sandColor != null) return sandColor; } catch (Exception) { diff --git a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs index 23c50ea2..f2b14b76 100644 --- a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs @@ -31,8 +31,8 @@ namespace NewHorizons.Builder.ShipLog { CuriosityName newName = (CuriosityName)8 + _rawNameToCuriosityName.Count; _rawNameToCuriosityName.Add(newColor.id, newName); - _curiosityColors.Add(newName, newColor.color.ToColor()); - _curiosityHighlightColors.Add(newName, newColor.highlightColor.ToColor()); + _curiosityColors.Add(newName, newColor.color); + _curiosityHighlightColors.Add(newName, newColor.highlightColor); } } } diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 25b18414..84f7b87b 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -66,7 +66,7 @@ namespace NewHorizons.Components.SizeControllers } else { - _startColour = startColour.ToColor(); + _startColour = startColour; _startSurfaceMaterial.color = _startColour; } @@ -77,7 +77,7 @@ namespace NewHorizons.Components.SizeControllers } else { - _endColour = endColour.ToColor(); + _endColour = endColour; _endSurfaceMaterial.color = _endColour; } diff --git a/NewHorizons/Utility/MColor.cs b/NewHorizons/Utility/MColor.cs index 2212bac0..c4c1ad70 100644 --- a/NewHorizons/Utility/MColor.cs +++ b/NewHorizons/Utility/MColor.cs @@ -37,8 +37,6 @@ namespace NewHorizons.Utility [System.ComponentModel.DataAnnotations.Range(0f, int.MaxValue)] public int a; - public Color32 ToColor32() => new Color32((byte)r, (byte)g, (byte)b, (byte)a); - - public Color ToColor() => new Color(r / 255f, g / 255f, b / 255f, a / 255f); + public static implicit operator Color(MColor c) => new Color(c.r / 255f, c.g / 255f, c.b / 255f, c.a / 255f); } }