Пример #1
0
    static IEnumerator TestComponents(List <KtaneModule> modules)
    {
        IEnumerable <BombComponent> untestedComponents = GetUntestedComponents(modules);
        Dictionary <string, string> nameMap            = GetNameMap(modules);

        GameObject fakeModule = new GameObject();

        gameObjects.Add(fakeModule);
        TwitchModule module = fakeModule.AddComponent <TwitchModule>();

        module.enabled = false;

        HashSet <string>          unsupportedModules = new HashSet <string>();
        Dictionary <string, bool> supportStatus      = new Dictionary <string, bool>();

        ComponentSolverFactory.SilentMode = true;

        // Try to create a ComponentSolver for each module so we can see what modules are supported.
        foreach (BombComponent bombComponent in untestedComponents)
        {
            ComponentSolver solver = null;
            try
            {
                module.BombComponent = bombComponent.GetComponent <BombComponent>();

                solver = ComponentSolverFactory.CreateSolver(module);

                module.StopAllCoroutines();                 // Stop any coroutines to prevent any exceptions or from affecting the next module.
            }
            catch (Exception e)
            {
                DebugHelper.LogException(e, $"Couldn't create a component solver for \"{bombComponent.GetModuleDisplayName()}\" during startup for the following reason:");
            }

            ModuleData.DataHasChanged |= solver != null;

            DebugHelper.Log(solver != null
                                ? $"Found a solver of type \"{solver.GetType().FullName}\" for component \"{bombComponent.GetModuleDisplayName()}\". This module is {(solver.UnsupportedModule ? "not supported" : "supported")} by Twitch Plays."
                                : $"No solver found for component \"{bombComponent.GetModuleDisplayName()}\". This module is not supported by Twitch Plays.");

            string moduleID = bombComponent.GetComponent <KMBombModule>()?.ModuleType ?? bombComponent.GetComponent <KMNeedyModule>()?.ModuleType;
            if (solver?.UnsupportedModule != false && moduleID != null)
            {
                unsupportedModules.Add(moduleID);
            }

            supportStatus[bombComponent.GetModuleDisplayName()] = !(solver?.UnsupportedModule != false && moduleID != null);

            yield return(null);
        }

        ComponentSolverFactory.SilentMode = false;
        ModuleData.WriteDataToFile();
        Object.Destroy(fakeModule);

        // Always disable the modules from the spreadsheet
        var disabledSheet = new GoogleSheet("1G6hZW0RibjW7n72AkXZgDTHZ-LKj0usRkbAwxSPhcqA", "1849453757", "modulename");

        yield return(disabledSheet);

        if (disabledSheet.Success && TwitchPlaySettings.data.AllowSheetDisabledModules)
        {
            foreach (var row in disabledSheet.GetRows())
            {
                if (!nameMap.TryGetValue(row["modulename"], out string moduleID))
                {
                    DebugHelper.Log($"Couldn't map \"{row["modulename"]}\" to a module ID when disabling modules from the spreadsheet.");
                    continue;
                }

                unsupportedModules.Add(moduleID);
            }
        }

        // Always disable modules that are marked as "Unplayable"
        foreach (var moduleInfo in modules)
        {
            if (moduleInfo.Compatibility != "Unplayable")
            {
                continue;
            }

            unsupportedModules.Add(moduleInfo.ModuleID);
        }

        // Using the list of unsupported module IDs stored in unsupportedModules, make a Mod Selector profile.
        string profilesPath = Path.Combine(Application.persistentDataPath, "ModProfiles");

        if (Directory.Exists(profilesPath))
        {
            Dictionary <string, object> profileData = new Dictionary <string, object>()
            {
                { "DisabledList", unsupportedModules },
                { "Operation", 1 }
            };

            File.WriteAllText(Path.Combine(profilesPath, "TP_Supported.json"), SettingsConverter.Serialize(profileData));
        }

        alertProgressBar.localScale = Vector3.one;

        // Send a message to chat if any modules aren't marked as having support
        if (supportStatus.Values.Count(status => status) > 0)
        {
            var supportedList = supportStatus.Where(pair => pair.Value).Select(pair => pair.Key).Join(", ");
            IRCConnection.SendMessage($"These modules have TP support: {supportedList}");
            alertText.text = $"These modules have TP support: {supportedList}";
            yield return(new WaitForSeconds(4));
        }
        else
        {
            alertText.text = "Support checks passed succesfully!";
            yield return(new WaitForSeconds(2));
        }

        // Log out the full results of the testing
        DebugHelper.Log($"Support testing results:\n{supportStatus.OrderByDescending(pair => pair.Value).Select(pair => $"{pair.Key} - {(pair.Value ? "" : "Not ")}Supported").Join("\n")}");
    }
    static IEnumerator TestComponents(IEnumerable <BombComponent> untestedComponents)
    {
        GameObject fakeModule = new GameObject();

        gameObjects.Add(fakeModule);
        TwitchModule module = fakeModule.AddComponent <TwitchModule>();

        module.enabled = false;

        List <string>             unsupportedModules = new List <string>();
        Dictionary <string, bool> supportStatus      = new Dictionary <string, bool>();

        ComponentSolverFactory.SilentMode = true;

        // Try to create a ComponentSolver for each module so we can see what modules are supported.
        foreach (BombComponent bombComponent in untestedComponents)
        {
            ComponentSolver solver = null;
            try
            {
                module.BombComponent = bombComponent.GetComponent <BombComponent>();

                solver = ComponentSolverFactory.CreateSolver(module);

                module.StopAllCoroutines();                 // Stop any coroutines to prevent any exceptions or from affecting the next module.
            }
            catch (Exception e)
            {
                DebugHelper.LogException(e, $"Couldn't create a component solver for \"{bombComponent.GetModuleDisplayName()}\" during startup for the following reason:");
            }

            ModuleData.DataHasChanged |= solver != null;

            DebugHelper.Log(solver != null
                                ? $"Found a solver of type \"{solver.GetType().FullName}\" for component \"{bombComponent.GetModuleDisplayName()}\". This module is {(solver.UnsupportedModule ? "not supported" : "supported")} by Twitch Plays."
                                : $"No solver found for component \"{bombComponent.GetModuleDisplayName()}\". This module is not supported by Twitch Plays.");

            string moduleID = bombComponent.GetComponent <KMBombModule>()?.ModuleType ?? bombComponent.GetComponent <KMNeedyModule>()?.ModuleType;
            if (solver?.UnsupportedModule != false && moduleID != null)
            {
                unsupportedModules.Add(moduleID);
            }

            supportStatus[bombComponent.GetModuleDisplayName()] = !(solver?.UnsupportedModule != false && moduleID != null);

            yield return(null);
        }

        ComponentSolverFactory.SilentMode = false;
        ModuleData.WriteDataToFile();
        Object.Destroy(fakeModule);

        // Using the list of unsupported module IDs stored in unsupportedModules, make a Mod Selector profile.
        string profilesPath = Path.Combine(Application.persistentDataPath, "ModProfiles");

        if (Directory.Exists(profilesPath))
        {
            Dictionary <string, object> profileData = new Dictionary <string, object>()
            {
                { "DisabledList", unsupportedModules },
                { "Operation", 1 }
            };

            File.WriteAllText(Path.Combine(profilesPath, "TP_Supported.json"), SettingsConverter.Serialize(profileData));
        }

        alertProgressBar.localScale = Vector3.one;

        // Send a message to chat if any modules aren't marked as having support
        if (supportStatus.Values.Count(status => status) > 0)
        {
            var supportedList = supportStatus.Where(pair => pair.Value).Select(pair => pair.Key).Join(", ");
            IRCConnection.SendMessage($"Let the Scoring Team know that the following modules have TP support: {supportedList}");
            alertText.text = $"These modules have TP support: {supportedList}";
            yield return(new WaitForSeconds(4));
        }
        else
        {
            alertText.text = "Support checks passed succesfully!";
            yield return(new WaitForSeconds(2));
        }

        // Log out the full results of the testing
        DebugHelper.Log($"Support testing results:\n{supportStatus.OrderByDescending(pair => pair.Value).Select(pair => $"{pair.Key} - {(pair.Value ? "" : "Not ")}Supported").Join("\n")}");
    }