Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time remaining storable #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/AtomAnimations/AtomAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ public float playTime
}
}

public float timeRemaining
{
get
{
for (var i = 0; i < clips.Count; ++i)
{
var clip = clips[i];

if (clip.playbackEnabled)
{
var length = clip.animationLength;
var time = clip.clipTime;
return length - time;
}
}

return 0;
}
}

private float _speed = 1f;
public float speed
{
Expand Down
7 changes: 7 additions & 0 deletions src/AtomPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class AtomPlugin : MVRScript, IAtomPlugin
public JSONStorableFloat speedJSON { get; private set; }
public JSONStorableBool lockedJSON { get; private set; }
public JSONStorableBool pausedJSON { get; private set; }
public JSONStorableFloat timeRemainingJSON { get; private set; }

private JSONStorableFloat _scrubberAnalogControlJSON;
private bool _scrubbing = false;
Expand Down Expand Up @@ -135,6 +136,7 @@ public void Update()
{
scrubberJSON.valNoCallback = animationEditContext.clipTime;
timeJSON.valNoCallback = animation.playTime;
timeRemainingJSON.valNoCallback = animation.timeRemaining;
}

if (_scrubberAnalogControlJSON.val != 0)
Expand Down Expand Up @@ -304,6 +306,10 @@ public void InitStorables()
};
RegisterBool(isPlayingJSON);


timeRemainingJSON = new JSONStorableFloat(StorableNames.TimeRemaining, 0f, 0f, float.MaxValue);
RegisterFloat(timeRemainingJSON);

stopJSON = new JSONStorableAction(StorableNames.Stop, () =>
{
if (animation == null) return;
Expand Down Expand Up @@ -703,6 +709,7 @@ private void OnEditorSettingsChanged(string propertyName)
private void OnIsPlayingChanged(AtomAnimationClip clip)
{
isPlayingJSON.valNoCallback = animation.isPlaying;
timeRemainingJSON.valNoCallback = animation.isPlaying ? animation.timeRemaining : 0;
_freeControllerHook.enabled = !animation.isPlaying;
peers.SendPlaybackState(clip);
}
Expand Down
1 change: 1 addition & 0 deletions src/Common/StorableNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class StorableNames
public const string Play = "Play";
public const string PlayIfNotPlaying = "Play If Not Playing";
public const string IsPlaying = "Is Playing";
public const string TimeRemaining = "Time Remaining";
public const string Stop = "Stop";
public const string StopIfPlaying = "Stop If Playing";
public const string StopAndReset = "Stop And Reset";
Expand Down