mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Code refactor
This commit is contained in:
parent
757badf4f6
commit
a55ba7b95b
232 changed files with 1282 additions and 936 deletions
|
@ -18,8 +18,12 @@ namespace RimWorldAnimationStudio
|
|||
public class PawnKeyframeEvent : UnityEvent<PawnKeyframe> { }
|
||||
public class ActorAddonEvent : UnityEvent<ActorAddon> { }
|
||||
public class AddonKeyframeEvent : UnityEvent<AddonKeyframe> { }
|
||||
public class ActorBodyEvent : UnityEvent<ActorBody> { }
|
||||
public class ActorBodyPartEvent : UnityEvent<ActorBodyPart> { }
|
||||
|
||||
// Event list
|
||||
public static UnityEvent onAnimationToggled = new UnityEvent();
|
||||
public static UnityEvent onAnimationChanged = new UnityEvent();
|
||||
public static UnityEvent onAnimationDefChanged = new UnityEvent();
|
||||
public static WorkspaceIntEvent onActorIDChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onStageIDChanged = new WorkspaceIntEvent();
|
||||
|
@ -29,13 +33,18 @@ namespace RimWorldAnimationStudio
|
|||
public static WorkspaceIntEvent onKeyframeCountChanged = new WorkspaceIntEvent();
|
||||
public static ActorEvent onActorChanged = new ActorEvent();
|
||||
public static AnimationStageEvent onAnimationStageChanged = new AnimationStageEvent();
|
||||
public static AnimationStageEvent onStageWindowSizeChanged = new AnimationStageEvent();
|
||||
public static PawnAnimationClipEvent onPawnAnimationClipChanged = new PawnAnimationClipEvent();
|
||||
public static PawnKeyframeEvent onPawnKeyframeChanged = new PawnKeyframeEvent();
|
||||
public static ActorAddonEvent onActorAddonChanged = new ActorAddonEvent();
|
||||
public static AddonKeyframeEvent onAddonKeyframeChanged = new AddonKeyframeEvent();
|
||||
public static UnityEvent onDefNamesChanged = new UnityEvent();
|
||||
public static ActorBodyEvent onActorBodySelected = new ActorBodyEvent();
|
||||
public static ActorBodyPartEvent onActorBodyPartSelected = new ActorBodyPartEvent();
|
||||
|
||||
// Event invoking
|
||||
public static void OnAnimationToggled() { onAnimationToggled.Invoke(); }
|
||||
public static void OnAnimationChanged() { onAnimationChanged.Invoke(); }
|
||||
public static void OnAnimationDefChanged() { onAnimationDefChanged.Invoke(); }
|
||||
public static void OnActorIDChanged() { onActorIDChanged.Invoke(Workspace.ActorID); }
|
||||
public static void OnStageIDChanged() { onStageIDChanged.Invoke(Workspace.ActorID); }
|
||||
|
@ -45,10 +54,13 @@ namespace RimWorldAnimationStudio
|
|||
public static void OnKeyframeCountChanged(PawnAnimationClip clip) { onKeyframeCountChanged.Invoke(clip.Keyframes.Count); }
|
||||
public static void OnActorChanged(Actor actor) { onActorChanged.Invoke(actor); }
|
||||
public static void OnAnimationStageChanged(AnimationStage stage) { onAnimationStageChanged.Invoke(stage); }
|
||||
public static void OnStageWindowSizeChanged(AnimationStage stage) { onStageWindowSizeChanged.Invoke(stage); }
|
||||
public static void OnPawnAnimationClipChanged(PawnAnimationClip clip) { onPawnAnimationClipChanged.Invoke(clip); }
|
||||
public static void OnPawnKeyframeChanged(PawnKeyframe keyframe) { onPawnKeyframeChanged.Invoke(keyframe); }
|
||||
public static void OnActorAddonChanged(ActorAddon actorAddon) { onActorAddonChanged.Invoke(actorAddon); }
|
||||
public static void OnAddonKeyframeChanged(AddonKeyframe addonKeyframe) { onAddonKeyframeChanged.Invoke(addonKeyframe); }
|
||||
public static void OnDefNamesChanged() { onDefNamesChanged.Invoke(); }
|
||||
public static void OnActorBodySelected(ActorBody actorBody) { onActorBodySelected.Invoke(actorBody); }
|
||||
public static void OnActorBodyPartSelected(ActorBodyPart bodyPart) { onActorBodyPartSelected.Invoke(bodyPart); }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,7 @@ namespace RimWorldAnimationStudio
|
|||
bool triggerEvent = stageID != value;
|
||||
stageID = value;
|
||||
|
||||
if (triggerEvent)
|
||||
{
|
||||
StageTick = Constants.minTick;
|
||||
EventsManager.OnStageIDChanged();
|
||||
}
|
||||
if (triggerEvent) { StageTick = Constants.minTick; EventsManager.OnStageIDChanged(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,12 +74,15 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
// Current save path
|
||||
public static string animationSavePath;
|
||||
|
||||
// Stage loop counts and stretching
|
||||
public static int stageLoopsNormal = 1;
|
||||
public static int stageLoopsQuick = 1;
|
||||
|
||||
// Stage controls
|
||||
private static float playBackSpeed = 1f;
|
||||
public static bool isAnimating;
|
||||
public static bool stretchKeyframes;
|
||||
|
||||
// Stage controls set / get
|
||||
public static float PlayBackSpeed { get { return playBackSpeed; } set { Mathf.Clamp(Workspace.playBackSpeed, 0.01f, 10f); } }
|
||||
|
||||
// Animation indices
|
||||
private static int stageID = 0;
|
||||
private static int actorID = 0;
|
||||
|
@ -96,17 +95,17 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public static Actor GetCurrentActor()
|
||||
{
|
||||
return animationDef?.Actors[ActorID];
|
||||
return GetActor(ActorID);
|
||||
}
|
||||
|
||||
public static AnimationStage GetCurrentAnimationStage()
|
||||
{
|
||||
return animationDef?.AnimationStages[StageID];
|
||||
return GetAnimationStage(StageID);
|
||||
}
|
||||
|
||||
public static PawnAnimationClip GetCurrentPawnAnimationClip()
|
||||
{
|
||||
return animationDef?.AnimationStages[StageID]?.AnimationClips[ActorID];
|
||||
return GetPawnAnimationClip(ActorID);
|
||||
}
|
||||
|
||||
public static PawnKeyframe GetCurrentPawnKeyframe(bool makeKeyframe = false)
|
||||
|
@ -122,28 +121,47 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public static Actor GetActor(int actorID)
|
||||
{
|
||||
return animationDef?.Actors[actorID];
|
||||
return animationDef?.Actors.ElementAtOrDefault(actorID);
|
||||
}
|
||||
|
||||
public static AnimationStage GetAnimationStage(int stageID)
|
||||
{
|
||||
return animationDef?.AnimationStages[stageID];
|
||||
return animationDef?.AnimationStages.ElementAtOrDefault(stageID);
|
||||
}
|
||||
|
||||
public static PawnAnimationClip GetPawnAnimationClip(int actorID)
|
||||
{
|
||||
return animationDef?.AnimationStages[StageID]?.AnimationClips[actorID];
|
||||
return GetCurrentAnimationStage()?.AnimationClips.ElementAtOrDefault(actorID);
|
||||
}
|
||||
|
||||
public static PawnKeyframe GetPawnKeyframe(int actorID, int keyframeID)
|
||||
public static PawnKeyframe GetPawnKeyframe(int keyframeID)
|
||||
{
|
||||
if (StageID < 0) return null;
|
||||
if (actorID < 0) return null;
|
||||
foreach (AnimationStage stage in animationDef?.AnimationStages)
|
||||
{
|
||||
foreach (PawnAnimationClip clip in stage.animationClips)
|
||||
{
|
||||
PawnKeyframe keyframe = clip.Keyframes.FirstOrDefault(x => x.keyframeID == keyframeID);
|
||||
|
||||
if (StageID >= animationDef.AnimationStages.Count) return null;
|
||||
if (actorID >= animationDef.AnimationStages[StageID].AnimationClips.Count) return null;
|
||||
if (keyframe != null) return keyframe;
|
||||
}
|
||||
}
|
||||
|
||||
return animationDef.AnimationStages[StageID].AnimationClips[actorID].Keyframes.FirstOrDefault(x => x.keyframeID == keyframeID);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PawnAnimationClip GetAnimationClipThatOwnsKeyframe(int keyframeID)
|
||||
{
|
||||
foreach (AnimationStage stage in animationDef?.AnimationStages)
|
||||
{
|
||||
foreach (PawnAnimationClip clip in stage.animationClips)
|
||||
{
|
||||
PawnKeyframe keyframe = clip.Keyframes.FirstOrDefault(x => x.keyframeID == keyframeID);
|
||||
|
||||
if (keyframe != null) return clip;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<PawnKeyframe> GetAllPawnKeyframesAtTick(int actorID, int atTick)
|
||||
|
@ -167,24 +185,6 @@ namespace RimWorldAnimationStudio
|
|||
return pawnKeyframes;
|
||||
}
|
||||
|
||||
public static PawnAnimationClip GetAnimationClipThatOwnsKeyframe(int keyframeID, out int clipID)
|
||||
{
|
||||
clipID = -1;
|
||||
|
||||
for (int i = 0; i < animationDef.AnimationStages[StageID].AnimationClips.Count; i++)
|
||||
{
|
||||
PawnAnimationClip clip = animationDef.AnimationStages[StageID].AnimationClips[i];
|
||||
|
||||
if (clip.Keyframes.Any(x => x.keyframeID == keyframeID))
|
||||
{
|
||||
clipID = i;
|
||||
return clip;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool DoesPawnKeyframeExistAtTick(int stageID, int actorID, int atTick)
|
||||
{
|
||||
return animationDef.AnimationStages[stageID].AnimationClips[actorID].Keyframes.Any(x => x.atTick == atTick);
|
||||
|
@ -195,11 +195,9 @@ namespace RimWorldAnimationStudio
|
|||
PawnKeyframe pawnKeyframe = null;
|
||||
PawnAnimationClip clip = GetPawnAnimationClip(actorID);
|
||||
|
||||
int stageTick = Workspace.StageTick;
|
||||
|
||||
foreach (PawnKeyframe keyframe in clip.Keyframes)
|
||||
{
|
||||
if (keyframe.atTick > stageTick)
|
||||
if (keyframe.atTick > StageTick)
|
||||
{ pawnKeyframe = keyframe; break; }
|
||||
}
|
||||
|
||||
|
@ -211,11 +209,9 @@ namespace RimWorldAnimationStudio
|
|||
PawnKeyframe pawnKeyframe = null;
|
||||
PawnAnimationClip clip = GetPawnAnimationClip(actorID);
|
||||
|
||||
int stageTick = Workspace.StageTick;
|
||||
|
||||
foreach (PawnKeyframe keyframe in clip.Keyframes)
|
||||
{
|
||||
if (keyframe.atTick < stageTick)
|
||||
if (keyframe.atTick < StageTick)
|
||||
{ pawnKeyframe = keyframe; }
|
||||
}
|
||||
|
||||
|
@ -227,11 +223,9 @@ namespace RimWorldAnimationStudio
|
|||
PawnKeyframe pawnKeyframe = null;
|
||||
PawnAnimationClip clip = GetPawnAnimationClip(actorID);
|
||||
|
||||
int stageTick = Workspace.StageTick;
|
||||
|
||||
foreach (PawnKeyframe keyframe in clip.Keyframes)
|
||||
{
|
||||
if (keyframe.atTick <= stageTick)
|
||||
if (keyframe.atTick <= StageTick)
|
||||
{ pawnKeyframe = keyframe; }
|
||||
}
|
||||
|
||||
|
@ -310,7 +304,6 @@ namespace RimWorldAnimationStudio
|
|||
animationDef = record.animationDef.Copy();
|
||||
StageID = record.stageID;
|
||||
|
||||
AnimationController.Instance.MakeTimelineDirty();
|
||||
StageCardManager.Instance.Initialize();
|
||||
}
|
||||
|
||||
|
@ -327,7 +320,7 @@ namespace RimWorldAnimationStudio
|
|||
RestoreToHistoricRecord(recordToRead);
|
||||
Debug.Log("Undoing : " + recordToStore.eventDesc);
|
||||
|
||||
EventsManager.OnAnimationDefChanged();
|
||||
EventsManager.OnAnimationChanged();
|
||||
}
|
||||
|
||||
public static void Redo()
|
||||
|
@ -342,7 +335,7 @@ namespace RimWorldAnimationStudio
|
|||
RestoreToHistoricRecord(recordToReadAndStore);
|
||||
Debug.Log("Redoing : " + recordToReadAndStore.eventDesc);
|
||||
|
||||
EventsManager.OnAnimationDefChanged();
|
||||
EventsManager.OnAnimationChanged();
|
||||
}
|
||||
|
||||
public static void ClearHistory()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue