Code refactor

This commit is contained in:
AbstractConcept 2022-10-28 00:28:51 -05:00
parent 757badf4f6
commit a55ba7b95b
232 changed files with 1282 additions and 936 deletions

View file

@ -31,20 +31,20 @@ namespace RimWorldAnimationStudio
[XmlIgnore] public List<ActorAddon> Addons
{
get { return addons.NullOrEmpty() ? addons = new List<ActorAddon>() : addons; }
set { addons = value.NotNullOrEmpty() ? value : null; EventsManager.OnPawnAnimationClipChanged(this); }
set { addons = value.NotNullOrEmpty() ? value : null; }
}
[XmlIgnore] public List<PawnKeyframe> Keyframes
{
get { return keyframes.NullOrEmpty() ? keyframes = new List<PawnKeyframe>() : keyframes; }
set { keyframes = value.NotNullOrEmpty() ? value : null; EventsManager.OnPawnAnimationClipChanged(this); }
set { keyframes = value.NotNullOrEmpty() ? value : null; }
}
[XmlIgnore]
public List<string> Tags
{
get { return tags.NullOrEmpty() ? tags = new List<string>() : tags; }
set { tags = value.NotNullOrEmpty() ? value : null; EventsManager.OnPawnAnimationClipChanged(this); }
set { tags = value.NotNullOrEmpty() ? value : null; }
}
// Local data
@ -235,7 +235,7 @@ namespace RimWorldAnimationStudio
foreach (PawnKeyframe keyframe in keyframesToClone)
{
PawnAnimationClip clip = Workspace.GetAnimationClipThatOwnsKeyframe(keyframe.keyframeID, out int clipID);
PawnAnimationClip clip = Workspace.GetAnimationClipThatOwnsKeyframe(keyframe.keyframeID);
if (clip == null)
{ Debug.LogWarning("Cannot clone pawn keyframe - no clip owns this keyframe"); continue; }
@ -244,7 +244,7 @@ namespace RimWorldAnimationStudio
{ Debug.LogWarning("Cannot clone pawn keyframe - a keyframe already exists at this tick"); return; }
PawnKeyframe cloneFrame = keyframe.Copy();
cloneFrame.GenerateKeyframeID(clipID);
cloneFrame.GenerateKeyframeID(clip.GetOwningActorID());
cloneFrame.atTick = Workspace.StageTick;
PawnKeyframe nextKeyframe = clip.Keyframes.FirstOrDefault(x => x.atTick > Workspace.StageTick);
@ -301,8 +301,8 @@ namespace RimWorldAnimationStudio
if (Workspace.DoesPawnKeyframeExistAtTick(Workspace.StageID, targetActorID, tickToPasteAt))
{
PawnKeyframe oldKeyframe = Workspace.animationDef.AnimationStages[Workspace.StageID].AnimationClips[targetActorID].Keyframes.First(x => x.atTick == tickToPasteAt);
RemovePawnKeyframe(targetActorID, oldKeyframe.keyframeID, true);
PawnKeyframe oldKeyframe = Workspace.GetPawnAnimationClip(targetActorID).Keyframes.First(x => x.atTick == tickToPasteAt);
Workspace.GetAnimationClipThatOwnsKeyframe(oldKeyframe.keyframeID).RemovePawnKeyframe(oldKeyframe.keyframeID, true);
}
PawnKeyframe clonedKeyframe = copiedKeyframe.Copy();
@ -330,34 +330,28 @@ namespace RimWorldAnimationStudio
Workspace.RecordEvent("Keyframe pasted");
}
public void RemovePawnKeyframe()
public void RemovePawnKeyframe(int keyframeID, bool force = false)
{
foreach (int keyframeID in Workspace.keyframeID)
{
if (Workspace.GetAnimationClipThatOwnsKeyframe(keyframeID, out int clipID) != null)
{ RemovePawnKeyframe(clipID, keyframeID); }
}
}
public void RemovePawnKeyframe(int actorID, int keyframeID, bool force = false)
{
PawnKeyframe keyframe = Workspace.GetPawnKeyframe(actorID, keyframeID);
PawnAnimationClip clip = Workspace.animationDef.AnimationStages[Workspace.StageID].AnimationClips[actorID];
if (keyframe == null || clip == null) return;
PawnKeyframe keyframe = Workspace.GetPawnKeyframe(keyframeID);
if (keyframe == null || IsOwnerOfKeyframe(keyframeID) == false) return;
if (keyframe.atTick == Constants.minTick && force == false)
{ Debug.LogWarning("Cannot delete key frame - the first key frame of an animation clip cannot be deleted"); return; }
if (clip.Keyframes.Count <= 2 && force == false)
if (Keyframes.Count <= 2 && force == false)
{ Debug.LogWarning("Cannot delete key frame - an animation clip must have two or more keyframes"); return; }
clip.Keyframes.Remove(keyframe);
clip.BuildSimpleCurves();
Keyframes.Remove(keyframe);
BuildSimpleCurves();
Workspace.RecordEvent("Keyframe deletion");
}
public bool IsOwnerOfKeyframe(int keyframeID)
{
return Keyframes.Any(x => x.keyframeID == keyframeID);
}
public float GetStageTickPercentage()
{
return (float)(Workspace.StageTick % duration) / duration;