mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
112 lines
4.8 KiB
C#
112 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class PawnAnimationClip : AnimationClip
|
|
{
|
|
[XmlAttribute("Class")] public string className = "Rimworld_Animations.PawnAnimationClip";
|
|
|
|
[XmlArray("keyframes"), XmlArrayItem("li")] public List<PawnKeyframe> keyframes = new List<PawnKeyframe>();
|
|
|
|
public AltitudeLayer layer = AltitudeLayer.Pawn;
|
|
|
|
[XmlIgnore] public Dictionary<int, bool> quiver = new Dictionary<int, bool>();
|
|
[XmlIgnore] public SimpleCurve GenitalAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadAngle = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadBob = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyOffsetX = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyOffsetZ = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve HeadFacing = new SimpleCurve();
|
|
[XmlIgnore] public SimpleCurve BodyFacing = new SimpleCurve();
|
|
|
|
public override void BuildSimpleCurves()
|
|
{
|
|
int duration = 0;
|
|
|
|
foreach (PawnKeyframe frame in keyframes)
|
|
{ duration += frame.tickDuration; }
|
|
|
|
this.duration = duration;
|
|
|
|
int keyframePosition = 0;
|
|
foreach (PawnKeyframe frame in keyframes)
|
|
{
|
|
if (frame.atTick.HasValue)
|
|
{
|
|
if (frame.bodyAngle.HasValue)
|
|
BodyAngle.Add((float)frame.atTick / (float)duration, frame.bodyAngle.Value, true);
|
|
|
|
if (frame.headAngle.HasValue)
|
|
HeadAngle.Add((float)frame.atTick / (float)duration, frame.headAngle.Value, true);
|
|
|
|
if (frame.bodyOffsetX.HasValue)
|
|
BodyOffsetX.Add((float)frame.atTick / (float)duration, frame.bodyOffsetX.Value, true);
|
|
|
|
if (frame.bodyOffsetZ.HasValue)
|
|
BodyOffsetZ.Add((float)frame.atTick / (float)duration, frame.bodyOffsetZ.Value, true);
|
|
|
|
if (frame.headFacing.HasValue)
|
|
HeadFacing.Add((float)frame.atTick / (float)duration, frame.headFacing.Value, true);
|
|
|
|
if (frame.bodyFacing.HasValue)
|
|
BodyFacing.Add((float)frame.atTick / (float)duration, frame.bodyFacing.Value, true);
|
|
|
|
if (frame.headBob.HasValue)
|
|
HeadBob.Add((float)frame.atTick / (float)duration, frame.headBob.Value, true);
|
|
|
|
if (frame.genitalAngle.HasValue)
|
|
GenitalAngle.Add((float)frame.atTick / (float)duration, frame.genitalAngle.Value, true);
|
|
|
|
if (frame.soundEffect != null)
|
|
{
|
|
SoundEffects.Add((int)frame.atTick, frame.soundEffect);
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if (frame.bodyAngle.HasValue)
|
|
BodyAngle.Add((float)keyframePosition / (float)duration, frame.bodyAngle.Value, true);
|
|
|
|
if (frame.headAngle.HasValue)
|
|
HeadAngle.Add((float)keyframePosition / (float)duration, frame.headAngle.Value, true);
|
|
|
|
if (frame.bodyOffsetX.HasValue)
|
|
BodyOffsetX.Add((float)keyframePosition / (float)duration, frame.bodyOffsetX.Value, true);
|
|
|
|
if (frame.bodyOffsetZ.HasValue)
|
|
BodyOffsetZ.Add((float)keyframePosition / (float)duration, frame.bodyOffsetZ.Value, true);
|
|
|
|
if (frame.headFacing.HasValue)
|
|
HeadFacing.Add((float)keyframePosition / (float)duration, frame.headFacing.Value, true);
|
|
|
|
if (frame.bodyFacing.HasValue)
|
|
BodyFacing.Add((float)keyframePosition / (float)duration, frame.bodyFacing.Value, true);
|
|
|
|
if (frame.headBob.HasValue)
|
|
HeadBob.Add((float)keyframePosition / (float)duration, frame.headBob.Value, true);
|
|
|
|
if (frame.genitalAngle.HasValue)
|
|
GenitalAngle.Add((float)keyframePosition / (float)duration, frame.genitalAngle.Value, true);
|
|
|
|
if (frame.soundEffect != null)
|
|
{
|
|
SoundEffects.Add(keyframePosition, frame.soundEffect);
|
|
}
|
|
|
|
if (frame.tickDuration != 1 && frame.quiver.HasValue)
|
|
{
|
|
|
|
quiver.Add(keyframePosition, true);
|
|
quiver.Add(keyframePosition + frame.tickDuration - 1, false);
|
|
}
|
|
|
|
keyframePosition += frame.tickDuration;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|