Esempio n. 1
0
 private SyncProxy GetOrDispose(SyncProxy proxy)
 {
     if (proxy == null)
     {
         return(null);
     }
     if (proxy.storable == null)
     {
         var link = _links.FirstOrDefault(l => l == proxy);
         if (link != null)
         {
             _links.Remove(link);
         }
         proxy.Dispose();
         if (_selectedLink == proxy)
         {
             _selectedLink = null;
             if (_links.Count > 0)
             {
                 var replacement = GetOrDispose(_links[0]);
                 if (replacement != null && _selectedLink == null)
                 {
                     _selectedLink = replacement;
                 }
                 return(replacement);
             }
         }
         return(null);
     }
     return(proxy);
 }
Esempio n. 2
0
        private void SelectCurrentAtom(string uid)
        {
            _selectedLink = null;
            if (string.IsNullOrEmpty(uid))
            {
                return;
            }
            var parts = uid.Split('|');

            if (parts.Length != 2)
            {
                SuperController.LogError($"Invalid atom/storable name: {uid} - the '|' character is reserved");
                _atomsJSON.valNoCallback = "";
                return;
            }
            var mainLinkedAnimation = _links.Select(GetOrDispose).FirstOrDefault(la => la.storable.containingAtom.uid == parts[0] && la.storable.name == parts[1]);

            if (mainLinkedAnimation == null)
            {
                SuperController.LogError($"Atom/storable {uid} has been destroyed or is unavailable");
                _atomsJSON.valNoCallback = "";
                return;
            }

            _selectedLink = mainLinkedAnimation;
            RequestControlPanelInjection();

            _atomsJSON.valNoCallback = _selectedLink.storable.containingAtom.uid + "|" + _selectedLink.storable.name;
        }
Esempio n. 3
0
        private SyncProxy TryConnectAtom(JSONStorable storable)
        {
            foreach (var l in _links.ToArray())
            {
                GetOrDispose(l);
            }

            var existing = _links.FirstOrDefault(a => a.storable == storable);

            if (existing != null)
            {
                return(existing);
            }

            var proxy = new SyncProxy()
            {
                storable = storable
            };

            storable.SendMessage(nameof(IRemoteAtomPlugin.VamTimelineConnectController), proxy.dict, SendMessageOptions.RequireReceiver);

            if (!proxy.connected)
            {
                proxy.Dispose();
                return(null);
            }

            _links.Add(proxy);
            _links.Sort((SyncProxy s1, SyncProxy s2) => string.Compare(s1.storable.containingAtom.name, s2.storable.containingAtom.name));

            var list = new List <string>(_atomsJSON.choices)
            {
                proxy.storable.containingAtom.uid
            };

            list.Sort();
            _atomsJSON.choices = list;

            OnTimelineAnimationParametersChanged(storable);

            if (_selectedLink == null)
            {
                _selectedLink  = proxy;
                _atomsJSON.val = proxy.storable.containingAtom.uid;
            }

            return(proxy);
        }
Esempio n. 4
0
        private SyncProxy TryConnectAtom(MVRScript storable)
        {
            if (storable == null)
            {
                return(null);
            }

            foreach (var l in _links.ToArray())
            {
                GetOrDispose(l);
            }

            var existing = _links.FirstOrDefault(a => a.storable == storable);

            if (existing != null)
            {
                return(existing);
            }

            var proxy = new SyncProxy
            {
                storable = storable
            };

            storable.SendMessage(nameof(IRemoteAtomPlugin.VamTimelineConnectController), proxy.dict, SendMessageOptions.RequireReceiver);

            if (!proxy.connected)
            {
                proxy.Dispose();
                return(null);
            }

            _links.Add(proxy);
            _links.Sort((s1, s2) => string.CompareOrdinal(s1.label, s2.label));

            _atomsJSON.displayChoices = _links.Select(l => l.label).ToList();
            _atomsJSON.choices        = _links.Select(l => l.storable.containingAtom.uid + "|" + l.storable.name).ToList();

            OnTimelineAnimationParametersChanged(storable);

            if (_selectedLink == null)
            {
                _selectedLink  = proxy;
                _atomsJSON.val = proxy.storable.containingAtom.uid + "|" + proxy.storable.name;
            }

            return(proxy);
        }
Esempio n. 5
0
        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.isPlaying        = isPlayingJSON;
            proxy.nextFrame        = nextFrameJSON;
            proxy.play             = playJSON;
            proxy.playIfNotPlaying = playIfNotPlayingJSON;
            proxy.previousFrame    = previousFrameJSON;
            proxy.stop             = stopJSON;
            proxy.stopAndReset     = stopAndResetJSON;
            proxy.time             = timeJSON;
            proxy.connected        = true;
        }
Esempio n. 6
0
 private SyncProxy GetOrDispose(SyncProxy proxy)
 {
     if (proxy == null)
     {
         return(null);
     }
     if (proxy.storable == null)
     {
         var link = _links.FirstOrDefault(l => l == proxy);
         if (link != null)
         {
             _links.Remove(link);
         }
         proxy.Dispose();
         if (_selectedLink == proxy)
         {
             _selectedLink = null;
         }
         return(null);
     }
     return(proxy);
 }
Esempio n. 7
0
        private void SelectCurrentAtom(string uid)
        {
            if (_selectedLink != null)
            {
                _selectedLink = null;
            }
            if (string.IsNullOrEmpty(uid))
            {
                return;
            }
            var mainLinkedAnimation = _links.Select(GetOrDispose).FirstOrDefault(la => la.storable.containingAtom.uid == uid);

            if (mainLinkedAnimation == null)
            {
                _atomsJSON.valNoCallback = "";
                return;
            }

            _selectedLink = mainLinkedAnimation;
            RequestControlPanelInjection();

            _atomsJSON.valNoCallback = _selectedLink.storable.containingAtom.uid;
        }
Esempio n. 8
0
        private void HandleKeyboardShortcuts(SyncProxy proxy)
        {
            if (!_enableKeyboardShortcuts.val)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                PreviousFrame();
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                NextFrame();
            }
            else if (Input.GetKeyDown(KeyCode.Space))
            {
                if (proxy.isPlaying.val)
                {
                    Stop();
                }
                else
                {
                    Play();
                }
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                Stop();
            }
            else if (Input.GetKeyDown(KeyCode.PageUp))
            {
                if (_atomsJSON.choices.Count > 1 && _atomsJSON.val != _atomsJSON.choices[0])
                {
                    _atomsJSON.val = _atomsJSON.choices.ElementAtOrDefault(_atomsJSON.choices.IndexOf(_atomsJSON.val) - 1);
                }
            }
            else if (Input.GetKeyDown(KeyCode.PageDown))
            {
                if (_atomsJSON.choices.Count > 1 && _atomsJSON.val != _atomsJSON.choices[_atomsJSON.choices.Count - 1])
                {
                    _atomsJSON.val = _atomsJSON.choices.ElementAtOrDefault(_atomsJSON.choices.IndexOf(_atomsJSON.val) + 1);
                }
            }
            else if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(0));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(1));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(2));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(3));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(4));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(5));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(6));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(7));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                ChangeAnimation(proxy.animation.choices.ElementAtOrDefault(8));
            }
        }