From 3e99fb5bd835245b8c498ed279a9a580dc3c986d Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 14 Jul 2022 16:45:22 -0500 Subject: [PATCH 1/5] Star collapse ramp texture and fix end color --- NewHorizons/Builder/Body/StarBuilder.cs | 20 ++++++-- .../StarEvolutionController.cs | 48 +++++++++++++------ .../Modules/VariableSize/StarModule.cs | 5 ++ NewHorizons/Schemas/body_schema.json | 4 ++ 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 27d52206..143f52dc 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -137,9 +137,19 @@ namespace NewHorizons.Builder.Body controller.size = starModule.size; controller.atmosphere = sunAtmosphere; controller.supernova = supernova; - controller.StartColour = starModule.tint; - controller.EndColour = starModule.endTint; - controller.WillExplode = starModule.goSupernova; + controller.startColour = starModule.tint?.ToColor(); + controller.endColour = starModule.tint != null ? starModule.tint.ToColor() * 4.5948f : null; + controller.willExplode = starModule.goSupernova; + if (!string.IsNullOrEmpty(starModule.starRampTexture)) + { + var ramp = ImageUtilities.GetTexture(mod, starModule.starRampTexture); + controller.normalRamp = ramp; + } + if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) + { + var ramp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); + controller.collapseRamp = ramp; + } surfaceAudio.SetStarEvolutionController(controller); starGO.SetActive(true); @@ -177,8 +187,8 @@ namespace NewHorizons.Builder.Body if (starModule.curve != null) controller.SetScaleCurve(starModule.curve); controller.size = starModule.size; controller.supernova = supernova; - controller.StartColour = starModule.tint; - controller.EndColour = starModule.endTint; + controller.startColour = starModule.tint?.ToColor(); + controller.endColour = starModule.tint != null ? starModule.tint.ToColor() * 4.5948f : null; controller.enabled = true; starGO.SetActive(true); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index d27486fb..054ade43 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -15,9 +15,11 @@ namespace NewHorizons.Components.SizeControllers { public GameObject atmosphere; public SupernovaEffectController supernova; - public bool WillExplode { get; set; } - public MColor StartColour { get; set; } - public MColor EndColour { get; set; } + public bool willExplode; + public Color? startColour; + public Color? endColour; + public Texture normalRamp; + public Texture collapseRamp; private Color _startColour; private Color _endColour; @@ -43,6 +45,8 @@ namespace NewHorizons.Components.SizeControllers private Material _collapseEndSurfaceMaterial; private Material _startSurfaceMaterial; private Material _endSurfaceMaterial; + private Texture _normalRamp; + private Texture _collapseRamp; private StarEvolutionController _proxy; @@ -60,31 +64,45 @@ namespace NewHorizons.Components.SizeControllers _endSurfaceMaterial = new Material(sun._endSurfaceMaterial); var supernovaSurfaceColorRamp = supernova._surface.sharedMaterial.GetTexture(ColorRamp); + if (normalRamp == null) + { + _normalRamp = supernovaSurfaceColorRamp; + } else + { + _normalRamp = normalRamp; + } + if (collapseRamp == null) + { + _collapseRamp = supernovaSurfaceColorRamp; + } else + { + _collapseRamp = collapseRamp; + } // Copy over the material that was set in star builder - _collapseStartSurfaceMaterial.SetTexture(ColorRamp, supernovaSurfaceColorRamp); - _collapseEndSurfaceMaterial.SetTexture(ColorRamp, supernovaSurfaceColorRamp); - _startSurfaceMaterial.SetTexture(ColorRamp, supernovaSurfaceColorRamp); - _endSurfaceMaterial.SetTexture(ColorRamp, supernovaSurfaceColorRamp); + _collapseStartSurfaceMaterial.SetTexture(ColorRamp, _collapseRamp); + _collapseEndSurfaceMaterial.SetTexture(ColorRamp, _collapseRamp); + _startSurfaceMaterial.SetTexture(ColorRamp, _normalRamp); + _endSurfaceMaterial.SetTexture(ColorRamp, _normalRamp); - if (StartColour == null) + if (startColour == null) { _startColour = _startSurfaceMaterial.color; } else { - _startColour = StartColour.ToColor(); + _startColour = startColour.Value; _startSurfaceMaterial.color = _startColour; } - if (EndColour == null) + if (endColour == null) { _endColour = _startColour; _endSurfaceMaterial.color = _startColour; } else { - _endColour = EndColour.ToColor(); + _endColour = endColour.Value; _endSurfaceMaterial.color = _endColour; } @@ -97,7 +115,7 @@ namespace NewHorizons.Components.SizeControllers _atmosphereRenderers = atmosphere?.transform?.Find("AtmoSphere")?.GetComponentsInChildren(); } - if (WillExplode) GlobalMessenger.AddListener("TriggerSupernova", Die); + if (willExplode) GlobalMessenger.AddListener("TriggerSupernova", Die); if (scaleCurve != null) { @@ -115,7 +133,7 @@ namespace NewHorizons.Components.SizeControllers public void OnDestroy() { - if (WillExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die); + if (willExplode) GlobalMessenger.RemoveListener("TriggerSupernova", Die); } public void SetProxy(StarEvolutionController proxy) @@ -165,12 +183,13 @@ namespace NewHorizons.Components.SizeControllers base.FixedUpdate(); // Only do colour transition stuff if they set an end colour - if (EndColour != null) + if (endColour != null) { // Use the age if theres no resizing happening, else make it get redder the larger it is or wtv var t = ageValue; if (maxScale > 0) t = CurrentScale / maxScale; currentColour = Color.Lerp(_startColour, _endColour, t); + supernova._surface._materials[0].SetTexture(ColorRamp, _normalRamp); supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); } else @@ -190,6 +209,7 @@ namespace NewHorizons.Components.SizeControllers currentColour = Color.Lerp(_endColour, Color.white, t); + supernova._surface._materials[0].SetTexture(ColorRamp, _collapseRamp); supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); // After the collapse is done we go supernova diff --git a/NewHorizons/External/Modules/VariableSize/StarModule.cs b/NewHorizons/External/Modules/VariableSize/StarModule.cs index 627fca8c..ea303ab0 100644 --- a/NewHorizons/External/Modules/VariableSize/StarModule.cs +++ b/NewHorizons/External/Modules/VariableSize/StarModule.cs @@ -61,6 +61,11 @@ namespace NewHorizons.External.Modules.VariableSize /// public string starRampTexture; + /// + /// Path to the texture to put as the star ramp while it is collapsing. Optional. + /// + public string starCollapseRampTexture; + /// /// How far the light from the star can reach. /// diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 61b75b12..9626080c 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1968,6 +1968,10 @@ "type": "string", "description": "Path to the texture to put as the star ramp. Optional." }, + "starRampCollapseTexture": { + "type": "string", + "description": "Path to the texture to put as the star ramp while it is collapsing. Optional." + }, "lightRadius": { "type": "number", "description": "How far the light from the star can reach.", From 2e00233253ebed84a20b630f110ea147136e8f99 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 14 Jul 2022 21:48:18 +0000 Subject: [PATCH 2/5] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 9626080c..7e079ea6 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1968,7 +1968,7 @@ "type": "string", "description": "Path to the texture to put as the star ramp. Optional." }, - "starRampCollapseTexture": { + "starCollapseRampTexture": { "type": "string", "description": "Path to the texture to put as the star ramp while it is collapsing. Optional." }, From ee1efa4d50e0b00326f5776d85792a454f7bc25c Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 14 Jul 2022 16:50:21 -0500 Subject: [PATCH 3/5] Get default ramps --- .../Components/SizeControllers/StarEvolutionController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 054ade43..698ae02d 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -66,14 +66,14 @@ namespace NewHorizons.Components.SizeControllers var supernovaSurfaceColorRamp = supernova._surface.sharedMaterial.GetTexture(ColorRamp); if (normalRamp == null) { - _normalRamp = supernovaSurfaceColorRamp; + _normalRamp = sun._startSurfaceMaterial.GetTexture(ColorRamp); } else { _normalRamp = normalRamp; } if (collapseRamp == null) { - _collapseRamp = supernovaSurfaceColorRamp; + _collapseRamp = sun._collapseStartSurfaceMaterial.GetTexture(ColorRamp); } else { _collapseRamp = collapseRamp; From 71c18ac3f03fadf9ca04891721d0d88587ebf128 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 14 Jul 2022 16:53:35 -0500 Subject: [PATCH 4/5] Only override collapse ramp --- .../Components/SizeControllers/StarEvolutionController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 698ae02d..89cf8e99 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -147,6 +147,7 @@ namespace NewHorizons.Components.SizeControllers _isCollapsing = true; _collapseStartSize = CurrentScale; _collapseTimer = 0f; + supernova._surface._materials[0].SetTexture(ColorRamp, _collapseRamp); if (_proxy != null) _proxy.Die(); } @@ -189,7 +190,6 @@ namespace NewHorizons.Components.SizeControllers var t = ageValue; if (maxScale > 0) t = CurrentScale / maxScale; currentColour = Color.Lerp(_startColour, _endColour, t); - supernova._surface._materials[0].SetTexture(ColorRamp, _normalRamp); supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); } else @@ -209,7 +209,6 @@ namespace NewHorizons.Components.SizeControllers currentColour = Color.Lerp(_endColour, Color.white, t); - supernova._surface._materials[0].SetTexture(ColorRamp, _collapseRamp); supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); // After the collapse is done we go supernova From 124d2dc4a1f37f5470a6e74acb8fb373c66ce371 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 14 Jul 2022 16:57:46 -0500 Subject: [PATCH 5/5] Remove unused mat --- .../Components/SizeControllers/StarEvolutionController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 89cf8e99..525b13f0 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -63,7 +63,6 @@ namespace NewHorizons.Components.SizeControllers _startSurfaceMaterial = new Material(sun._startSurfaceMaterial); _endSurfaceMaterial = new Material(sun._endSurfaceMaterial); - var supernovaSurfaceColorRamp = supernova._surface.sharedMaterial.GetTexture(ColorRamp); if (normalRamp == null) { _normalRamp = sun._startSurfaceMaterial.GetTexture(ColorRamp); @@ -147,7 +146,7 @@ namespace NewHorizons.Components.SizeControllers _isCollapsing = true; _collapseStartSize = CurrentScale; _collapseTimer = 0f; - supernova._surface._materials[0].SetTexture(ColorRamp, _collapseRamp); + supernova._surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); if (_proxy != null) _proxy.Die(); }