Add ModuleRestockHeatEffects

• Add ModuleRestockHeatEffects, which replaces ModuleHeatEffects and incorporates its own color changing module without the bugs of the stock one, as well as having an option to disable the built in blackbody glow.
• Minor changes to ModuleRestockISRUAnimation
pull/653/head
Andrew Cassidy 5 years ago
parent 1511e744d2
commit a506dc492e
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1

@ -19,4 +19,35 @@
name = ModuleRestockISRUAnimation
deployAnimationName = heater
}
MODULE
{
name = ModuleRestockHeatEffects
enableHeatEmissive = true
useCoreTemp = true
shaderProperty = _EmissiveColor
excludedRenderer = ISRU-125_heater
lerpMax = 2700
redCurve
{
key = 0 0 2 2
key = 1 1 0 0
}
greenCurve
{
key = 0 0 1 1
key = 1 1 1 1
}
blueCurve
{
key = 0 0 1 1
key = 1 1 1 1
}
alphaCurve
{
key = 0 1 0 0
key = 1 1 0 0
}
disableBlackbody = true
}
}

@ -0,0 +1,152 @@
using System;
using UnityEngine;
using System.Collections.Generic;
namespace Restock
{
public class ModuleRestockHeatEffects : PartModule
{
[KSPField] public bool enableHeatEmissive = false;
[KSPField] public string shaderProperty = string.Empty;
[KSPField] public FloatCurve redCurve= new FloatCurve();
[KSPField] public FloatCurve greenCurve = new FloatCurve();
[KSPField] public FloatCurve blueCurve = new FloatCurve();
[KSPField] public FloatCurve alphaCurve = new FloatCurve();
[KSPField] public double draperPoint = 798.0;
[KSPField] public double lerpMax = double.NaN;
[KSPField] public double lerpMin = 0.0;
[KSPField] public bool useCoreTemp = false;
[KSPField] public bool useSkinTemp = false;
[KSPField] public bool disableBlackbody = false;
[KSPField] public List<Renderer> renderers = new List<Renderer>();
private readonly string _shaderBlackbody = "_TemperatureColor";
private ModuleCoreHeat _coreHeatModule = null;
private int _shaderPropertyID;
private int _shaderBlackbodyID;
private double _lerpRange;
private Color _emissiveColor = new Color();
private MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();
public void Start()
{
Debug.Log("Start()");
if (base.vessel == null) return;
if (enableHeatEmissive)
{
if (useCoreTemp)
{
_coreHeatModule = base.part.FindModuleImplementing<ModuleCoreHeat>();
if (_coreHeatModule == null)
{
this.LogError("Part has no Core Heat module, skipping");
useCoreTemp = false;
}
}
if (double.IsNaN(lerpMax))
{
if (useCoreTemp)
{
lerpMax = _coreHeatModule.CoreShutdownTemp;
}
else
{
lerpMax = useSkinTemp ? part.skinMaxTemp : part.maxTemp;
}
}
_lerpRange = lerpMax - lerpMin - draperPoint;
_shaderPropertyID = Shader.PropertyToID(shaderProperty);
}
if (disableBlackbody)
{
_shaderBlackbodyID = Shader.PropertyToID(_shaderBlackbody);
}
}
public override void OnLoad(ConfigNode node)
{
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
Debug.Log("OnLoad()");
Debug.Log(node.ToString());
renderers = base.part.FindModelComponents<Renderer>();
if (node.HasValue("excludedRenderer"))
{
var excludedRenderers = new List<string>();
excludedRenderers.AddRange(node.GetValues("excludedRenderer"));
for (int i = renderers.Count - 1; i >= 0; i--)
{
if (renderers[i] == null || excludedRenderers.Contains(renderers[i].name))
{
renderers.RemoveAt(i);
}
}
}
}
public void LateUpdate()
{
if (!HighLogic.LoadedSceneIsFlight) return;
if (enableHeatEmissive)
{
var temp = 0.0;
if (useCoreTemp)
{
temp = _coreHeatModule.CoreTemperature;
}
else
{
temp = useSkinTemp ? base.part.skinTemperature : base.part.temperature;
}
var temp2 = (float) ((temp - draperPoint) / _lerpRange);
temp2 = Mathf.Clamp01(temp2);
_emissiveColor.r = redCurve.Evaluate(temp2);
_emissiveColor.g = greenCurve.Evaluate(temp2);
_emissiveColor.b = blueCurve.Evaluate(temp2);
_emissiveColor.a = alphaCurve.Evaluate(temp2);
_propertyBlock.SetColor(_shaderPropertyID, _emissiveColor);
}
if (disableBlackbody)
{
_propertyBlock.SetColor(_shaderBlackbodyID, Color.black);
}
foreach (var r in renderers)
{
r.SetPropertyBlock(_propertyBlock);
}
}
}
}

@ -4,38 +4,40 @@ using UnityEngine;
namespace Restock
{
public class ModuleRestockISRUAnimation: PartModule
public class ModuleRestockISRUAnimation : PartModule
{
[KSPField] public string activeAnimationName = "";
[KSPField] public string deployAnimationName = "";
[KSPField] public float deploySpeed = 1.0f;
[KSPField] public float retractSpeed = 1.0f;
public bool isDeployed = false;
public Animation DeployAnimation
{
get;
private set;
}
public Animation DeployAnimation { get; private set; }
private List<BaseConverter> _modules;
private bool _deployAnimationPresent = false;
public void Start()
{
if (base.vessel == null) return;
_modules = base.part.FindModulesImplementing<BaseConverter>();
_deployAnimationPresent = (deployAnimationName != string.Empty);
DeployAnimation = ((_deployAnimationPresent) ? base.part.FindModelAnimators(deployAnimationName)[0] : null);
foreach (var a in base.part.FindModelAnimators()) a.Stop();
foreach (var a in base.part.FindModelAnimators()) a.Stop();
}
public override void OnLoad(ConfigNode node)
{
if (!HighLogic.LoadedSceneIsFlight || base.vessel == null)
{
isDeployed = false;
return;
}
if (isDeployed)
{
PlayDeployAnimation(1000);
@ -45,17 +47,16 @@ namespace Restock
PlayDeployAnimation(-1000);
}
}
public void Update()
{
if (!HighLogic.LoadedSceneIsFlight || base.vessel == null) return;
if (!HighLogic.LoadedSceneIsFlight) return;
try
{
if (!CheatOptions.InfiniteElectricity)
{
var ecHash = PartResourceLibrary.ElectricityHashcode;
base.vessel.GetConnectedResourceTotals(ecHash, out var ecAmount, out _, true);
Debug.Log(ecAmount);
if (ecAmount < 0.1)
{
if (isDeployed) RetractModule();
@ -68,6 +69,7 @@ namespace Restock
{
if (m.ModuleIsActive()) enabledCount++;
}
if (isDeployed && enabledCount == 0) RetractModule();
else if (!isDeployed && enabledCount != 0) DeployModule();
}
@ -80,16 +82,16 @@ namespace Restock
public void DeployModule()
{
isDeployed = true;
PlayDeployAnimation(1);
PlayDeployAnimation(1 * deploySpeed);
}
public void RetractModule()
{
isDeployed = false;
PlayDeployAnimation(-1);
PlayDeployAnimation(-1 * retractSpeed);
}
private void PlayDeployAnimation(int speed)
private void PlayDeployAnimation(float speed)
{
if (_deployAnimationPresent)
{
@ -102,6 +104,7 @@ namespace Restock
{
deployAnimationState.time = 0.0f;
}
deployAnimationState.speed = speed;
DeployAnimation.Play(deployAnimationName);
}

@ -47,6 +47,7 @@
<Compile Include="MaterialModifiers\IMaterialModifier.cs" />
<Compile Include="MaterialModifiers\MaterialModifierParser.cs" />
<Compile Include="MaterialModifiers\TexturePropertyMaterialModifier.cs" />
<Compile Include="ModuleRestockHeatEffects.cs" />
<Compile Include="ModuleRestockISRUAnimation.cs" />
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
<Compile Include="ModuleRestockModifyMaterials.cs" />

Loading…
Cancel
Save