diff --git a/Assets/CineboxAndrew b/Assets/CineboxAndrew index d8d49e30..f8b6ab64 160000 --- a/Assets/CineboxAndrew +++ b/Assets/CineboxAndrew @@ -1 +1 @@ -Subproject commit d8d49e303bdd463c3f8d5e2d8c6c3f8718d2eeec +Subproject commit f8b6ab64ffbe90f0e5c2ce6a5eacc568715978a6 diff --git a/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-e.dds b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-e.dds new file mode 100644 index 00000000..9035e396 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-e.dds differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-n.dds b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-n.dds new file mode 100644 index 00000000..90439d3d Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1-n.dds differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1.dds b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1.dds new file mode 100644 index 00000000..a6e85a2c Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-1.dds differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-125-1.mu b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-125-1.mu new file mode 100644 index 00000000..c87cd65f Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Resource/restock-isru-125-1.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Patches/Resource/restock-isrus.cfg b/Distribution/Restock/GameData/ReStock/Patches/Resource/restock-isrus.cfg new file mode 100644 index 00000000..4da6a133 --- /dev/null +++ b/Distribution/Restock/GameData/ReStock/Patches/Resource/restock-isrus.cfg @@ -0,0 +1,22 @@ +// Patches applying art changes to ISRUs +// Contents: +// - Convert-O-Tron 125 (MiniISRU) + +// Convert-O-Tron 125 +@PART[MiniISRU] +{ + @author = Andrew Cassidy + + !MODEL {} + MODEL + { + model = ReStock/Assets/Resource/restock-isru-125-1 + scale = 1.0, 1.0, 1.0 + } + + MODULE + { + name = ModuleRestockISRUAnimation + deployAnimationName = heater + } +} \ No newline at end of file diff --git a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll index 2481f09f..70255aee 100644 Binary files a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll and b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll differ diff --git a/Source/Restock/ModuleRestockISRUAnimation.cs b/Source/Restock/ModuleRestockISRUAnimation.cs new file mode 100644 index 00000000..729978e4 --- /dev/null +++ b/Source/Restock/ModuleRestockISRUAnimation.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Restock +{ + public class ModuleRestockISRUAnimation: PartModule + { + [KSPField] public string activeAnimationName = ""; + + [KSPField] public string deployAnimationName = ""; + + public bool isDeployed = false; + + public Animation DeployAnimation + { + get; + private set; + } + + private List _modules; + + private bool _deployAnimationPresent = false; + + public void Start() + { + if (base.vessel == null) return; + _modules = base.part.FindModulesImplementing(); + + _deployAnimationPresent = (deployAnimationName != string.Empty); + DeployAnimation = ((_deployAnimationPresent) ? base.part.FindModelAnimators(deployAnimationName)[0] : null); + + foreach (var a in base.part.FindModelAnimators()) a.Stop(); + + } + + public override void OnLoad(ConfigNode node) + { + if (isDeployed) + { + PlayDeployAnimation(1000); + } + else + { + PlayDeployAnimation(-1000); + } + } + + public void Update() + { + if (!HighLogic.LoadedSceneIsFlight || base.vessel == null) 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(); + return; + } + } + + int enabledCount = 0; + foreach (var m in _modules) + { + if (m.ModuleIsActive()) enabledCount++; + } + if (isDeployed && enabledCount == 0) RetractModule(); + else if (!isDeployed && enabledCount != 0) DeployModule(); + } + catch (Exception e) + { + this.LogException("Failed to update animation module", e); + } + } + + public void DeployModule() + { + isDeployed = true; + PlayDeployAnimation(1); + } + + public void RetractModule() + { + isDeployed = false; + PlayDeployAnimation(-1); + } + + private void PlayDeployAnimation(int speed) + { + if (_deployAnimationPresent) + { + var deployAnimationState = DeployAnimation[deployAnimationName]; + if (speed < 0 && deployAnimationState.time < Mathf.Epsilon) + { + deployAnimationState.time = deployAnimationState.length; + } + else if (speed > 0 && deployAnimationState.time > deployAnimationState.length - Mathf.Epsilon) + { + deployAnimationState.time = 0.0f; + } + deployAnimationState.speed = speed; + DeployAnimation.Play(deployAnimationName); + } + } + } +} \ No newline at end of file diff --git a/Source/Restock/Restock.csproj b/Source/Restock/Restock.csproj index 69ebd600..489f1437 100644 --- a/Source/Restock/Restock.csproj +++ b/Source/Restock/Restock.csproj @@ -47,6 +47,7 @@ +