Ejemplo n.º 1
0
    IEnumerator SimulateModule(Component component, Transform moduleTransform, MethodInfo method, string command)
    {
        // Simple Command
        if (typeof(IEnumerable <KMSelectable>).IsAssignableFrom(method.ReturnType))
        {
            IEnumerable <KMSelectable> selectableSequence = null;
            try
            {
                selectableSequence = (IEnumerable <KMSelectable>)method.Invoke(component, new object[] { command });
                if (selectableSequence == null)
                {
                    Debug.LogFormat("Twitch Plays handler reports invalid command (by returning null).", method.DeclaringType.FullName, method.Name);
                    yield break;
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            int initialStrikes = fakeInfo.strikes;
            int initialSolved  = fakeInfo.GetSolvedModuleNames().Count;
            foreach (KMSelectable selectable in selectableSequence)
            {
                DoInteractionStart(selectable);
                yield return(new WaitForSeconds(0.1f));

                DoInteractionEnd(selectable);

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    break;
                }
            }
            ;
        }

        // Complex Commands
        if (method.ReturnType == typeof(IEnumerator))
        {
            IEnumerator responseCoroutine = null;
            try
            {
                responseCoroutine = (IEnumerator)method.Invoke(component, new object[] { command });
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            if (responseCoroutine == null)
            {
                Debug.LogFormat("Twitch Plays handler reports invalid command (by returning null).", method.DeclaringType.FullName, method.Name);
                yield break;
            }

            if (!ComponentHelds.ContainsKey(component))
            {
                ComponentHelds[component] = new HashSet <KMSelectable>();
            }
            HashSet <KMSelectable> heldSelectables = ComponentHelds[component];

            int initialStrikes = fakeInfo.strikes;
            int initialSolved  = fakeInfo.GetSolvedModuleNames().Count;

            if (!responseCoroutine.MoveNext())
            {
                Debug.LogFormat("Twitch Plays handler reports invalid command (by returning empty sequence).", method.DeclaringType.FullName, method.Name);
                yield break;
            }

            if (responseCoroutine.Current is string)
            {
                var str = (string)responseCoroutine.Current;
                if (str.StartsWith("sendtochat"))
                {
                    Debug.Log("Twitch handler sent: " + str);
                }
                yield break;
            }

            while (responseCoroutine.MoveNext())
            {
                object currentObject = responseCoroutine.Current;
                if (currentObject is KMSelectable)
                {
                    KMSelectable selectable = (KMSelectable)currentObject;
                    if (heldSelectables.Contains(selectable))
                    {
                        DoInteractionEnd(selectable);
                        heldSelectables.Remove(selectable);
                        if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                        {
                            yield break;
                        }
                    }
                    else
                    {
                        DoInteractionStart(selectable);
                        heldSelectables.Add(selectable);
                    }
                }
                else if (currentObject is IEnumerable <KMSelectable> )
                {
                    foreach (var selectable in (IEnumerable <KMSelectable>)currentObject)
                    {
                        DoInteractionStart(selectable);
                        yield return(new WaitForSeconds(.1f));

                        DoInteractionEnd(selectable);
                    }
                }
                else if (currentObject is string)
                {
                    string currentString = (string)currentObject;
                    float  waitTime;
                    Match  match = Regex.Match(currentString, "^trywaitcancel ([0-9]+(?:\\.[0-9])?)((?: (?:.|\\n)+)?)$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                    if (match.Success && float.TryParse(match.Groups[1].Value, out waitTime))
                    {
                        yield return(new WaitForSeconds(waitTime));
                    }

                    Debug.Log("Twitch handler sent: " + currentObject);
                    yield return(currentObject);
                }
                else if (currentObject is Quaternion)
                {
                    moduleTransform.localRotation = (Quaternion)currentObject;
                }
                else
                {
                    yield return(currentObject);
                }

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    yield break;
                }
            }
        }
    }
Ejemplo n.º 2
0
    IEnumerator SimulateModule(Component component, Transform moduleTransform, MethodInfo method, string command)
    {
        // Simple Command
        if (method.ReturnType == typeof(KMSelectable[]))
        {
            KMSelectable[] selectableSequence = null;
            try
            {
                selectableSequence = (KMSelectable[])method.Invoke(component, new object[] { command });
                if (selectableSequence == null)
                {
                    yield break;
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            int initialStrikes = fakeInfo.strikes;
            int initialSolved  = fakeInfo.GetSolvedModuleNames().Count;
            foreach (KMSelectable selectable in selectableSequence)
            {
                DoInteractionStart(selectable);
                yield return(new WaitForSeconds(0.1f));

                DoInteractionEnd(selectable);

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    break;
                }
            }
            ;
        }

        // Complex Commands
        if (method.ReturnType == typeof(IEnumerator))
        {
            IEnumerator responseCoroutine = null;
            try
            {
                responseCoroutine = (IEnumerator)method.Invoke(component, new object[] { command });
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            if (responseCoroutine == null)
            {
                yield break;
            }

            if (!ComponentHelds.ContainsKey(component))
            {
                ComponentHelds[component] = new HashSet <KMSelectable>();
            }
            HashSet <KMSelectable> heldSelectables = ComponentHelds[component];

            int initialStrikes = fakeInfo.strikes;
            int initialSolved  = fakeInfo.GetSolvedModuleNames().Count;

            while (responseCoroutine.MoveNext())
            {
                object currentObject = responseCoroutine.Current;
                if (currentObject is KMSelectable)
                {
                    KMSelectable selectable = (KMSelectable)currentObject;
                    if (heldSelectables.Contains(selectable))
                    {
                        DoInteractionEnd(selectable);
                        heldSelectables.Remove(selectable);
                    }
                    else
                    {
                        DoInteractionStart(selectable);
                        heldSelectables.Add(selectable);
                    }
                }
                else if (currentObject is string)
                {
                    Debug.Log("Twitch handler sent: " + currentObject);
                    yield return(currentObject);
                }
                else if (currentObject is Quaternion)
                {
                    moduleTransform.localRotation = (Quaternion)currentObject;
                }
                else
                {
                    yield return(currentObject);
                }

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    yield break;
                }
            }
        }
    }
Ejemplo n.º 3
0
    IEnumerator SimulateModule(Component component, Transform moduleTransform, MethodInfo method, string command)
    {
        // Simple Command
        if (method.ReturnType == typeof(KMSelectable[]))
        {
            KMSelectable[] selectableSequence = null;
            try
            {
                selectableSequence = (KMSelectable[])method.Invoke(component, new object[] { command });
                if (selectableSequence == null)
                {
                    yield break;
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            int initialStrikes = fakeInfo.strikes;
            int initialSolved  = fakeInfo.GetSolvedModuleNames().Count;
            foreach (KMSelectable selectable in selectableSequence)
            {
                DoInteractionStart(selectable);
                yield return(new WaitForSeconds(0.1f));

                DoInteractionEnd(selectable);

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    break;
                }
            }
            ;
        }

        // Complex Commands
        if (method.ReturnType == typeof(IEnumerator))
        {
            IEnumerator responseCoroutine = null;
            try
            {
                responseCoroutine = (IEnumerator)method.Invoke(component, new object[] { command });
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", method.DeclaringType.FullName, method.Name);
                Debug.LogException(ex);
                yield break;
            }

            if (responseCoroutine == null)
            {
                yield break;
            }

            if (!ComponentHelds.ContainsKey(component))
            {
                ComponentHelds[component] = new HashSet <KMSelectable>();
            }
            HashSet <KMSelectable> heldSelectables = ComponentHelds[component];

            int  initialStrikes      = fakeInfo.strikes;
            int  initialSolved       = fakeInfo.GetSolvedModuleNames().Count;
            bool needQuaternionReset = false;
            Dictionary <Transform, int> transformLayers = new Dictionary <Transform, int>();

            while (responseCoroutine.MoveNext())
            {
                object currentObject = responseCoroutine.Current;
                if (currentObject is KMSelectable)
                {
                    KMSelectable selectable = (KMSelectable)currentObject;
                    if (heldSelectables.Contains(selectable))
                    {
                        DoInteractionEnd(selectable);
                        heldSelectables.Remove(selectable);
                        if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                        {
                            yield break;
                        }
                    }
                    else
                    {
                        DoInteractionStart(selectable);
                        heldSelectables.Add(selectable);
                    }
                }
                else if (currentObject is string)
                {
                    Debug.Log("Twitch handler sent: " + currentObject);
                    yield return(currentObject);
                }
                else if (currentObject is Quaternion)
                {
                    moduleTransform.localRotation = (Quaternion)currentObject;
                    needQuaternionReset           = true;
                }
                else if (currentObject is Quaternion[])
                {
                    Camera cam = TwitchPlaysCameraTransform.GetComponentInChildren <Camera>();
                    cam.cullingMask = 1 << 12;
                    Transform parentTransform = TwitchPlaysCameraTransform.parent;
                    foreach (Transform t in parentTransform.GetComponentsInChildren <Transform>())
                    {
                        if (!transformLayers.ContainsKey(t))
                        {
                            transformLayers[t] = t.gameObject.layer;
                        }
                        t.gameObject.layer = 12;
                    }

                    moduleTransform.localRotation = ((Quaternion[])currentObject)[0];
                    Quaternion quaternion = ((Quaternion[])currentObject)[1];
                    TwitchPlaysCameraTransform.localRotation = Quaternion.Euler(-quaternion.eulerAngles);
                    needQuaternionReset = true;
                }
                else
                {
                    yield return(currentObject);
                }

                if (fakeInfo.strikes != initialStrikes || fakeInfo.GetSolvedModuleNames().Count != initialSolved)
                {
                    break;
                }
            }
            if (needQuaternionReset)
            {
                moduleTransform.localRotation            = Quaternion.identity;
                TwitchPlaysCameraTransform.localRotation = Quaternion.identity;
                Camera cam = TwitchPlaysCameraTransform.GetComponentInChildren <Camera>();
                cam.cullingMask = -1;
                Transform parentTransform = TwitchPlaysCameraTransform.parent;
                foreach (Transform t in parentTransform.GetComponentsInChildren <Transform>())
                {
                    if (transformLayers.ContainsKey(t))
                    {
                        t.gameObject.layer = transformLayers[t];
                    }
                    else
                    {
                        t.gameObject.layer = 11;
                    }
                }
            }
        }
    }