Skip to content

Commit

Permalink
Merge pull request #167 from snjo/DEVELOP
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BobPalmer authored Nov 8, 2016
2 parents 18740b2 + 274c6e9 commit 964c2ea
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 14 deletions.
115 changes: 107 additions & 8 deletions Firespitter/animation/FSanimateGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public class FSanimateGeneric : PartModule
[KSPField]
public Vector4 defaultWindowRect = new Vector4(550f, 300f, 150f, 100f);

// animationRampspeed is how quickly it gets up to speed. 1 meaning it gets to full speed (as defined by
// the animSpeed and customAnimationSpeed) immediately, less than that will ramp up over time
[KSPField]
public float animationRampSpeed = 1f;
// When the mod starts, what speed to set the initial animSpeed to
[KSPField]
public float startAnimSpeed = 1f;
// Multiplier to be used when in reverse mode
[KSPField]
public float reverseAnimSpeed = 1f;

[KSPField(isPersistant = true)]
public bool isAnimating = false;
Expand Down Expand Up @@ -68,6 +78,15 @@ public class FSanimateGeneric : PartModule
//private bool showMenu = false;
//private Rect windowRect; // = new Rect(550f, 300f, 150f, 100f);


// The following are for the new functionality for the animation ramp ability

private enum RampDirection { none, up, down };
private RampDirection rampDirection = RampDirection.none;
private float ramp = 0;
private float unstartedSpeed;
private bool animSpeediInited = false;

[KSPAction("Toggle")]
public void toggleAction(KSPActionParam param)
{
Expand All @@ -93,16 +112,19 @@ public void toggleEvent()
{
Actions["toggleAction"].guiName = toggleActionName;
}
anim[animationName].speed = -1f * customAnimationSpeed;
// Following two commented out lines (anim[animationName].speed =, and anim.Play) now taken care of in LateUpdate
//anim[animationName].speed = -1f * customAnimationSpeed;
if (anim[animationName].normalizedTime == 0f || anim[animationName].normalizedTime == 1f)
anim[animationName].normalizedTime = 1f;
anim.Play(animationName);

//anim.Play(animationName);
startDeployed = false; // to get the hangar toggle button state right
if (startRetractEffect != string.Empty)
{
part.Effect(startRetractEffect);
Debug.Log("start retract effect");
}
rampDirection = RampDirection.down;
}
else
{
Expand All @@ -112,16 +134,19 @@ public void toggleEvent()
{
Actions["toggleAction"].guiName = toggleActionName;
}
anim[animationName].speed = 1f * customAnimationSpeed;
// Following two commented out lines (anim[animationName].speed =, and anim.Play) now taken care of in LateUpdate
//anim[animationName].speed = 1f * customAnimationSpeed;
if (anim[animationName].normalizedTime == 0f || anim[animationName].normalizedTime == 1f)
anim[animationName].normalizedTime = 0f;
anim.Play(animationName);

//anim.Play(animationName);
startDeployed = true; // to get the hangar toggle button state right
if (startDeployEffect != string.Empty)
{
part.Effect(startDeployEffect);
Debug.Log("start deploy effect");
}
rampDirection = RampDirection.up;
}

reverseAnimation = !reverseAnimation;
Expand All @@ -138,7 +163,7 @@ public void toggleEvent()
public override void OnStart(PartModule.StartState state)
{
base.OnStart(state);

anim = part.FindModelAnimators(animationName).FirstOrDefault();
if (anim != null)
{
Expand Down Expand Up @@ -172,7 +197,7 @@ public override void OnStart(PartModule.StartState state)
}
else
{
animSpeed = -1f * customAnimationSpeed;
animSpeed = -1f * customAnimationSpeed * reverseAnimSpeed;
//this fixes the animation running on entering the scene, but mayn not be good for paused animations
//animTime = 0f;
}
Expand All @@ -183,8 +208,10 @@ public override void OnStart(PartModule.StartState state)

//set up animation state according to persistent values
anim[animationName].layer = layer;
anim[animationName].speed = animSpeed;
anim.Play(animationName);
// Following two commented out lines now taken care of in LateUpdate
//anim[animationName].speed = animSpeed * startAnimSpeed;

//anim.Play(animationName);
anim[animationName].normalizedTime = animTime;

if (reverseAnimation)
Expand Down Expand Up @@ -223,6 +250,78 @@ public override void OnStart(PartModule.StartState state)
//popup.sections[0].elements[0].buttons[0].toggle(reverseAnimation);
}

//
// Process the ramping in LateUpdate
//
public void LateUpdate()
{
if (!HighLogic.LoadedSceneIsFlight && !HighLogic.LoadedSceneIsEditor) return;

if (anim != null)
{
switch (rampDirection)
{
case RampDirection.up:
if (ramp < 1f)
{
if (ramp < 0)
{
if (reverseAnimSpeed == 0)
ramp = 0;
else
ramp += animationRampSpeed / reverseAnimSpeed;
}
else
ramp += animationRampSpeed;
}
if (ramp > 1f)
ramp = 1f;
break;
case RampDirection.down:
if (ramp > -1f)
{
if (ramp < 0)
{
if (reverseAnimSpeed != 0)
ramp -= animationRampSpeed / reverseAnimSpeed;
}
else
ramp -= animationRampSpeed;
}
if (ramp < -1f)
{
ramp = -1f;
//rampDirection = RampDirection.up;
}
break;
}
if (/* reverseAnimation && */ ramp < 0)
{
anim[animationName].speed = 1f * customAnimationSpeed * reverseAnimSpeed * ramp;
}
else
{
anim[animationName].speed = 1f * customAnimationSpeed * ramp;
}
if (rampDirection == RampDirection.none)
{
if (!animSpeediInited)
{
anim[animationName].speed = animSpeed * startAnimSpeed;
animSpeediInited = true;
unstartedSpeed = anim[animationName].speed;
ramp = startAnimSpeed;
}
else
anim[animationName].speed = unstartedSpeed;
}
// Debug.Log("rampDirection: " + rampDirection.ToString() + " animSpeed: " + animSpeed.ToString() + " startAnimSpeed: " + startAnimSpeed.ToString() + " anim[animationName].speed: " + anim[animationName].speed.ToString());
// I don't think that this causes a problem, to call it every time here even if the speed didn't change. Also catches any other
// changes
anim.Play(animationName);
}
}

//public void guiToggleEvent()
//{
// toggleEvent();
Expand Down
22 changes: 16 additions & 6 deletions For release/Firespitter/Firespitter.version
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
"VERSION": {
"MAJOR": 7,
"MINOR": 4,
"PATCH": 1
"PATCH": 2
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 2,
"PATCH": 0
}
"KSP_VERSION":{
"MAJOR":1,
"MINOR":2,
"PATCH":1
},
"KSP_VERSION_MIN":{
"MAJOR":1,
"MINOR":2,
"PATCH":0
},
"KSP_VERSION_MAX":{
"MAJOR":1,
"MINOR":2,
"PATCH":1
}
}
Binary file modified For release/Firespitter/Plugins/Firespitter.dll
Binary file not shown.
Binary file modified For release/Firespitter/Plugins/Firespitter.dll.mdb
Binary file not shown.

0 comments on commit 964c2ea

Please sign in to comment.