Skip to content

Commit

Permalink
Make Next/Previous animation behave exactly like Next/Previous [Main …
Browse files Browse the repository at this point in the history
…Layer]
  • Loading branch information
acidbubbles committed Dec 30, 2021
1 parent 3ae5afe commit 2927595
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
62 changes: 22 additions & 40 deletions src/AtomPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class AtomPlugin : MVRScript, IAtomPlugin
private Editor _controllerInjectedUI;
public PeerManager peers { get; private set; }

private JSONStorableStringChooser _animationLegacyJSON;
private JSONStorableAction _nextAnimationLegacyJSON;
private JSONStorableAction _previousAnimationLegacyJSON;
private JSONStorableStringChooser _animationJSON;
private JSONStorableAction _nextAnimationJSON;
private JSONStorableAction _previousAnimationJSON;
private JSONStorableAction _nextAnimationInMainLayerJSON;
private JSONStorableAction _previousAnimationInMainLayerJSON;
private JSONStorableFloat _scrubberJSON;
Expand Down Expand Up @@ -258,7 +258,7 @@ public void OnDestroy()

public void InitStorables()
{
_animationLegacyJSON = new JSONStorableStringChooser(StorableNames.Animation, new List<string>(), "", "Animation", val =>
_animationJSON = new JSONStorableStringChooser(StorableNames.Animation, new List<string>(), "", "Animation", val =>
{
if (string.IsNullOrEmpty(val)) return;
if (logger.triggers) logger.Log(logger.triggersCategory, $"Triggered '{StorableNames.Animation}' = '{val}'");
Expand All @@ -269,45 +269,27 @@ public void InitStorables()
animationEditContext.SelectAnimation(clip);
else if (animation.isPlaying)
animation.PlayClipByName(val, true);
_animationLegacyJSON.valNoCallback = "";
_animationJSON.valNoCallback = "";
})
{
isStorable = false,
isRestorable = false
};
RegisterStringChooser(_animationLegacyJSON);

_nextAnimationLegacyJSON = new JSONStorableAction(StorableNames.NextAnimationLegacy, () =>
{
if (logger.triggers) logger.Log(logger.triggersCategory, $"Triggered '{StorableNames.NextAnimationLegacy}'");
if (_animationLegacyJSON.choices.Count < 2) return;
var clip = string.IsNullOrEmpty(_animationLegacyJSON.val)
? animation.clips[0]
: animation.clips.First(c => c.animationName == _animationLegacyJSON.val);
var inLayer = animation.index.ByLayer(clip.animationLayer);
var i = inLayer.IndexOf(clip);
if (i < 0 || i > inLayer.Count - 2)
_animationLegacyJSON.val = inLayer[0].animationName;
else
_animationLegacyJSON.val = inLayer[i + 1].animationName;
RegisterStringChooser(_animationJSON);

_nextAnimationJSON = new JSONStorableAction(StorableNames.NextAnimation, () =>
{
if (logger.triggers) logger.Log(logger.triggersCategory, $"Triggered '{StorableNames.NextAnimation}'");
animationEditContext.GoToNextAnimation(animation.clips[0].animationLayer);
});
RegisterAction(_nextAnimationLegacyJSON);

_previousAnimationLegacyJSON = new JSONStorableAction(StorableNames.PreviousAnimationLegacy, () =>
{
if (logger.triggers) logger.Log(logger.triggersCategory, $"Triggered '{StorableNames.PreviousAnimationLegacy}'");
if (_animationLegacyJSON.choices.Count < 2) return;
var clip = string.IsNullOrEmpty(_animationLegacyJSON.val)
? animation.clips[0]
: animation.clips.First(c => c.animationName == _animationLegacyJSON.val);
var inLayer = animation.index.ByLayer(clip.animationLayer);
var i = inLayer.IndexOf(clip);
if (i < 1 || i > inLayer.Count - 1)
_animationLegacyJSON.val = inLayer[inLayer.Count - 1].animationName;
else
_animationLegacyJSON.val = inLayer[i - 1].animationName;
RegisterAction(_nextAnimationJSON);

_previousAnimationJSON = new JSONStorableAction(StorableNames.PreviousAnimation, () =>
{
if (logger.triggers) logger.Log(logger.triggersCategory, $"Triggered '{StorableNames.PreviousAnimation}'");
animationEditContext.GoToPreviousAnimation(animation.clips[0].animationLayer);
});
RegisterAction(_previousAnimationLegacyJSON);
RegisterAction(_previousAnimationJSON);

_nextAnimationInMainLayerJSON = new JSONStorableAction(StorableNames.NextAnimationInMainLayer, () =>
{
Expand Down Expand Up @@ -625,7 +607,7 @@ private void BindAnimation()
if (_freeControllerHook != null) _freeControllerHook.animationEditContext = animationEditContext;
if (enabled) _freeControllerHook.enabled = true;

_animationLegacyJSON.valNoCallback = "";
_animationJSON.valNoCallback = "";

peers.Ready();
BroadcastToControllers(nameof(IRemoteControllerPlugin.OnTimelineAnimationReady));
Expand Down Expand Up @@ -669,7 +651,7 @@ private void OnClipsListChanged()
{
var animationNames = animation.index.clipNames.ToList();

_animationLegacyJSON.choices = animationNames;
_animationJSON.choices = animationNames;

for (var i = 0; i < animationNames.Count; i++)
{
Expand Down Expand Up @@ -856,7 +838,7 @@ public void ChangeAnimationLegacy(string animationName)
animationEditContext.SelectAnimation(clip);
else if (animation.isPlaying)
animation.PlayClipByName(animationName, true);
_animationLegacyJSON.valNoCallback = "";
_animationJSON.valNoCallback = "";
}
catch (Exception exc)
{
Expand Down Expand Up @@ -884,7 +866,7 @@ public void VamTimelineConnectController(Dictionary<string, object> dict)
{
var proxy = SyncProxy.Wrap(dict);
// TODO: This or just use the storables dict already on storable??
proxy.animation = _animationLegacyJSON;
proxy.animation = _animationJSON;
proxy.isPlaying = _isPlayingJSON;
proxy.nextFrame = _nextFrameJSON;
proxy.play = _playJSON;
Expand Down
4 changes: 2 additions & 2 deletions src/ControllerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ private void InitStorables()
};
RegisterFloat(_timeJSON);

var nextAnimationJSON = new JSONStorableAction(StorableNames.NextAnimationLegacy, () =>
var nextAnimationJSON = new JSONStorableAction(StorableNames.NextAnimation, () =>
{
var i = _animationJSON.choices.IndexOf(_selectedLink?.animation.val);
if (i < 0 || i > _animationJSON.choices.Count - 2) return;
_animationJSON.val = _animationJSON.choices[i + 1];
});
RegisterAction(nextAnimationJSON);

var previousAnimationJSON = new JSONStorableAction(StorableNames.PreviousAnimationLegacy, () =>
var previousAnimationJSON = new JSONStorableAction(StorableNames.PreviousAnimation, () =>
{
var i = _animationJSON.choices.IndexOf(_selectedLink?.animation.val);
if (i < 1 || i > _animationJSON.choices.Count - 1) return;
Expand Down
4 changes: 2 additions & 2 deletions src/Interop/StorableNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace VamTimeline
public static class StorableNames
{
public const string Animation = "Animation";
public const string NextAnimationLegacy = "Next Animation";
public const string PreviousAnimationLegacy = "Previous Animation";
public const string NextAnimation = "Next Animation";
public const string PreviousAnimation = "Previous Animation";
public const string NextAnimationInMainLayer = "Next Animation (Main Layer)";
public const string PreviousAnimationInMainLayer = "Previous Animation (Main Layer)";
public const string Scrubber = "Scrubber";
Expand Down

0 comments on commit 2927595

Please sign in to comment.