Bug fixes plus extra features

- Insert adds a new keyframe to the selected timeline
- New stages have frames cloned from the last frame of current stage
- Existing key are now replaced when another key is dropped on them
- Fixed bug where starting a new animation could result in errors
This commit is contained in:
AbstractConcept 2022-10-18 21:57:43 -05:00
parent ca22fa0c18
commit 2989d9a72c
137 changed files with 527 additions and 668 deletions

View file

@ -121,5 +121,12 @@ namespace RimWorldAnimationStudio
return true;
}
public int GetActorID()
{
if (Workspace.animationDef == null) return -1;
return Workspace.animationDef.actors.IndexOf(this);
}
}
}

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
@ -89,17 +90,46 @@ namespace RimWorldAnimationStudio
public override void ValidateData() { }
public bool MakeNew()
public int GetOwningActorID()
{
PawnKeyframe keyframeA = new PawnKeyframe();
keyframeA.tickDuration = Constants.defaultAnimationClipLength - 1;
keyframes.Add(keyframeA);
if (Workspace.animationDef == null) return -1;
PawnKeyframe keyframeB = new PawnKeyframe();
keyframes.Add(keyframeB);
return Workspace.animationDef.animationStages[Workspace.stageID].animationClips.IndexOf(this);
}
public bool MakeNew(int actorID = -1)
{
PawnKeyframe lastkeyframe = null;
if (actorID >= 0)
{ lastkeyframe = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID]?.keyframes?.Last(); }
if (lastkeyframe != null)
{
PawnKeyframe keyframeA = lastkeyframe.Copy();
keyframeA.atTick = null;
keyframeA.tickDuration = Constants.defaultAnimationClipLength - 1;
keyframeA.GenerateKeyframeID(actorID);
keyframes.Add(keyframeA);
PawnKeyframe keyframeB = lastkeyframe.Copy();
keyframeB.atTick = null;
keyframeB.tickDuration = 1;
keyframeB.GenerateKeyframeID(actorID);
keyframes.Add(keyframeB);
}
else
{
PawnKeyframe keyframeA = new PawnKeyframe();
keyframeA.tickDuration = Constants.defaultAnimationClipLength - 1;
keyframes.Add(keyframeA);
PawnKeyframe keyframeB = new PawnKeyframe();
keyframes.Add(keyframeB);
}
BuildSimpleCurves();
return true;
}
}

View file

@ -36,23 +36,31 @@ namespace RimWorldAnimationStudio
{ clip.keyframes = clip.keyframes.OrderBy(x => x.atTick).ToList(); }
}
public int GetStageID()
{
if (Workspace.animationDef == null) return -1;
return Workspace.animationDef.animationStages.IndexOf(this);
}
public bool MakeNew()
{
if (Workspace.animationDef == null)
{ Debug.LogWarning("Cannot make new animation stage - there is no AnimationDef"); return false; }
foreach(Actor actor in Workspace.animationDef.actors)
Workspace.animationDef.animationStages.Add(this);
foreach (Actor actor in Workspace.animationDef.actors)
{
PawnAnimationClip clip = new PawnAnimationClip();
if (clip.MakeNew())
if (clip.MakeNew(actor.GetActorID()))
{ animationClips.Add(clip); }
}
Initialize();
playTimeTicksQuick = playTimeTicks;
Workspace.animationDef.animationStages.Add(this);
return true;
}
}