Esempio n. 1
0
    public static void WriteDataToFile()
    {
        if (!DataHasChanged || ComponentSolverFactory.SilentMode)
        {
            return;
        }
        string path = Path.Combine(Application.persistentDataPath, usersSavePath);

        DebugHelper.Log($"ModuleData: Writing file {path}");

        try
        {
            var infoList = ComponentSolverFactory
                           .GetModuleInformation()
                           .OrderBy(info => info.moduleDisplayName)
                           .ThenBy(info => info.moduleID)
                           .Select(info =>
            {
                var fileInfo   = lastRead.FirstOrDefault(file => file.moduleID == info.moduleID);
                var dictionary = new Dictionary <string, object>();
                foreach (var field in infoFields)
                {
                    if (!(info.CallMethod <bool?>($"ShouldSerialize{field.Name}") ?? true))
                    {
                        continue;
                    }

                    var value = field.GetValue(info);
                    if (field.Name == "moduleScore")
                    {
                        value = fileInfo?.moduleScore;
                    }
                    else if (field.Name == "moduleScoreIsDynamic")
                    {
                        value = fileInfo?.moduleScoreIsDynamic;
                    }

                    dictionary[field.Name] = value;
                }

                return(dictionary);
            })
                           .ToList();

            File.WriteAllText(path, SettingsConverter.Serialize(infoList));
        }
        catch (FileNotFoundException)
        {
            DebugHelper.LogWarning($"ModuleData: File {path} was not found.");
            return;
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex);
            return;
        }

        DataHasChanged = false;
        DebugHelper.Log($"ModuleData: Writing of file {path} completed successfully.");
    }
Esempio n. 2
0
    public static void WriteDataToFile()
    {
        if (!DataHasChanged || ComponentSolverFactory.SilentMode)
        {
            return;
        }
        string path = Path.Combine(Application.persistentDataPath, usersSavePath);

        DebugHelper.Log($"ModuleData: Writing file {path}");

        try
        {
            List <ModuleInformation> infoList = ComponentSolverFactory.GetModuleInformation().ToList();
            infoList = infoList.OrderBy(info => info.moduleDisplayName).ThenBy(info => info.moduleID).ToList();

            File.WriteAllText(path, SettingsConverter.Serialize(infoList));            //JsonConvert.SerializeObject(infoList, Formatting.Indented));
        }
        catch (FileNotFoundException)
        {
            DebugHelper.LogWarning($"ModuleData: File {path} was not found.");
            return;
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex);
            return;
        }

        DataHasChanged = false;
        DebugHelper.Log($"ModuleData: Writing of file {path} completed successfully.");
    }
    string resolveMissionID(string targetID, out string failureMessage)
    {
        failureMessage = null;
        ModManager     modManager = ModManager.Instance;
        List <Mission> missions   = modManager.ModMissions;

        Mission mission = missions.FirstOrDefault(x => Regex.IsMatch(x.name, "mod_.+_" + Regex.Escape(targetID), RegexOptions.CultureInvariant | RegexOptions.IgnoreCase));

        if (mission == null)
        {
            failureMessage = $"Unable to find a mission with an ID of \"{targetID}\".";
            return(null);
        }

        List <string> availableMods = GameInfo.GetAvailableModuleInfo().Where(x => x.IsMod).Select(y => y.ModuleId).ToList();

        if (MultipleBombs.Installed())
        {
            availableMods.Add("Multiple Bombs");
        }
        HashSet <string>         missingMods = new HashSet <string>();
        List <ModuleInformation> modules     = ComponentSolverFactory.GetModuleInformation().ToList();

        GeneratorSetting     generatorSetting = mission.GeneratorSetting;
        List <ComponentPool> componentPools   = generatorSetting.ComponentPools;

        foreach (ComponentPool componentPool in componentPools)
        {
            List <string> modTypes = componentPool.ModTypes;
            if (modTypes == null || modTypes.Count == 0)
            {
                continue;
            }
            foreach (string mod in modTypes.Where(x => !availableMods.Contains(x)))
            {
                missingMods.Add(modules.FirstOrDefault(x => x.moduleID == mod)?.moduleDisplayName ?? mod);
            }
        }
        if (missingMods.Count > 0)
        {
            failureMessage = $"Mission \"{targetID}\" was found, however, the following mods are not installed / loaded: {string.Join(", ", missingMods.OrderBy(x => x).ToArray())}";
            return(null);
        }

        return(mission.name);
    }