171 lines
7.3 KiB
C#
171 lines
7.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace Rimworld_Animations {
|
|
public class PawnAnimationClip : BaseAnimationClip {
|
|
|
|
public List<PawnKeyframe> keyframes;
|
|
|
|
public List<AddonInfo> addons = new List<AddonInfo>();
|
|
public List<AddonKeyframe> addonKeyframes = new List<AddonKeyframe>();
|
|
|
|
public AltitudeLayer layer = AltitudeLayer.Pawn;
|
|
|
|
public Dictionary<int, bool> quiver = new Dictionary<int, bool>();
|
|
public SimpleCurve GenitalAngle = new SimpleCurve();
|
|
public SimpleCurve BodyAngle = new SimpleCurve();
|
|
public SimpleCurve HeadAngle = new SimpleCurve();
|
|
public SimpleCurve HeadBob = new SimpleCurve();
|
|
public SimpleCurve BodyOffsetX = new SimpleCurve();
|
|
public SimpleCurve BodyOffsetZ = new SimpleCurve();
|
|
public SimpleCurve HeadFacing = new SimpleCurve();
|
|
public SimpleCurve BodyFacing = new SimpleCurve();
|
|
|
|
public Dictionary<string, SimpleCurve> addonsPosX = new Dictionary<string, SimpleCurve>();
|
|
public Dictionary<string, SimpleCurve> addonsPosY = new Dictionary<string, SimpleCurve>();
|
|
|
|
public Dictionary<string, SimpleCurve> addonsRotation = new Dictionary<string, SimpleCurve>();
|
|
public Dictionary<string, SimpleCurve> addonsScale = new Dictionary<string, SimpleCurve>();
|
|
public Dictionary<string, Dictionary<int, bool>> addonsShouldRender = new Dictionary<string, Dictionary<int, bool>>();
|
|
|
|
|
|
public override void buildSimpleCurves() {
|
|
|
|
|
|
int duration = 0;
|
|
//getting the length of the whole clip
|
|
foreach(PawnKeyframe frame in keyframes) {
|
|
duration += frame.tickDuration;
|
|
}
|
|
|
|
foreach(AddonInfo addonInfo in addons)
|
|
{
|
|
addonsPosX.Add(addonInfo.name, new SimpleCurve());
|
|
addonsPosY.Add(addonInfo.name, new SimpleCurve());
|
|
addonsScale.Add(addonInfo.name, new SimpleCurve());
|
|
|
|
addonsRotation.Add(addonInfo.name, new SimpleCurve());
|
|
addonsShouldRender.Add(addonInfo.name, new Dictionary<int, bool>());
|
|
}
|
|
|
|
//guarantees loops don't get cut off mid-anim
|
|
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);
|
|
}
|
|
|
|
foreach (AddonInfo addon in addons)
|
|
{
|
|
if (frame.addonKeyframes.Exists(addonKeyframe => addonKeyframe.name == addon.name))
|
|
{
|
|
AddonKeyframe addonKeyframe = frame.addonKeyframes.Find(element => element.name == addon.name);
|
|
if (addonKeyframe.posX != null)
|
|
{
|
|
addonsPosX[addon.name].Add((float)keyframePosition / (float)duration, addonKeyframe.posX.Value, true);
|
|
}
|
|
|
|
if (addonKeyframe.posY != null)
|
|
{
|
|
addonsPosX[addon.name].Add((float)keyframePosition / (float)duration, addonKeyframe.posY.Value, true);
|
|
}
|
|
|
|
if (addonKeyframe.rotation != null)
|
|
{
|
|
addonsPosX[addon.name].Add((float)keyframePosition / (float)duration, addonKeyframe.rotation.Value, true);
|
|
}
|
|
|
|
if (addonKeyframe.scale != null)
|
|
{
|
|
addonsScale[addon.name].Add((float)keyframePosition / (float)duration, addonKeyframe.scale.Value, true);
|
|
}
|
|
|
|
if (addonKeyframe.render != null)
|
|
{
|
|
addonsShouldRender[addon.name].Add(keyframePosition, addonKeyframe.render.Value);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (frame.tickDuration != 1 && frame.quiver.HasValue) {
|
|
|
|
quiver.Add(keyframePosition, true);
|
|
quiver.Add(keyframePosition + frame.tickDuration - 1, false);
|
|
}
|
|
keyframePosition += frame.tickDuration;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|