Exemple #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken token = JToken.Load(reader);
            string value = token.Value <string>();

            return(GameCompatibleVersion.Parse(value));
        }
Exemple #2
0
        /// <summary>
        /// Sets the active state of a mod.
        /// </summary>
        /// <param name="name">The mods name.</param>
        /// <param name="value">The new active state of the mod.</param>
        public void SetActive(string name, bool value, GameCompatibleVersion version, Version factorioVersion, bool isOnly, bool isDefault)
        {
            if (TryGetMod(name, out var mod))
            {
                if ((factorioVersion >= FactorioVersion.DisableBehaviourSwitch) && !isOnly && !isDefault)
                {
                    if (value || (mod.Version == version))
                    {
                        mod.Enabled = value;
                        mod.Version = value ? version : null;
                    }
                }
                else
                {
                    mod.Enabled = value;
                    mod.Version = null;
                }
            }
            else
            {
                mod = CreateTemplate(name, value, version, factorioVersion);
                Mods.Add(mod);
            }

            Save();
        }
Exemple #3
0
 private ModTemplate CreateTemplate(string name, bool enabled, GameCompatibleVersion version, Version factorioVersion)
 {
     if (factorioVersion >= FactorioVersion.DisableBehaviourSwitch)
     {
         return(new ModTemplate(name, enabled, version));
     }
     else
     {
         return(new ModTemplate(name, enabled, null));
     }
 }
        /// <summary>
        /// Tries to get the specified mod.
        /// </summary>
        /// <param name="name">The name of the mod.</param>
        /// <param name="version">The mods version.</param>
        /// <param name="mod">Out. The requested mod.</param>
        /// <returns>Return true if the collection contained the specified mod, otherwise false.</returns>
        public bool TryGetMod(string name, GameCompatibleVersion version, out Mod mod)
        {
            foreach (var m in this)
            {
                if (string.Equals(m.Name, name, StringComparison.InvariantCultureIgnoreCase) && (m.Version == version))
                {
                    mod = m;
                    return(true);
                }
            }

            mod = null;
            return(false);
        }
Exemple #5
0
        public static void SetActive(string name, GameCompatibleVersion version, Version factorioVersion, bool value, bool isOnly, bool isDefault)
        {
            if (Contains(factorioVersion, out var list))
            {
                list.SetActive(name, value, version, factorioVersion, isOnly, isDefault);
                list.Save();
            }
            else
            {
                list         = ModTemplateList.Load(Path.Combine(App.Instance.Settings.GetModDirectory(factorioVersion).FullName, "mod-list.json"));
                list.Version = factorioVersion;
                TemplateLists.Add(list);

                list.SetActive(name, value, version, factorioVersion, isOnly, isDefault);
                list.Save();
            }
        }
Exemple #6
0
        public static bool GetActive(string name, GameCompatibleVersion version, Version factorioVersion, bool isOnly)
        {
            ModTemplateList list;

            if (Contains(factorioVersion, out list))
            {
                return(list.GetActive(name, version, factorioVersion, isOnly));
            }
            else
            {
                list         = ModTemplateList.Load(Path.Combine(App.Instance.Settings.GetModDirectory(factorioVersion).FullName, "mod-list.json"));
                list.Version = factorioVersion;
                TemplateLists.Add(list);

                return(list.GetActive(name, version, factorioVersion, isOnly));
            }
        }
Exemple #7
0
 public int Compare(GameCompatibleVersion x, GameCompatibleVersion y)
 {
     if ((x == null) && (y == null))
     {
         return(0);
     }
     else if (x == null)
     {
         return(-1);
     }
     else if (y == null)
     {
         return(1);
     }
     else
     {
         return(x.CompareTo(y));
     }
 }
Exemple #8
0
 /// <summary>
 /// Gets the active state of a mod.
 /// </summary>
 /// <param name="name">The mods name.</param>
 /// <returns>Returns if the specified mod is active.</returns>
 public bool GetActive(string name, GameCompatibleVersion version, Version factorioVersion, bool isOnly)
 {
     if (TryGetMod(name, out var mod))
     {
         if ((factorioVersion >= FactorioVersion.DisableBehaviourSwitch) && !isOnly)
         {
             return(mod.Enabled && (mod.Version == version));
         }
         else
         {
             mod.Version = null;
             return(mod.Enabled);
         }
     }
     else
     {
         mod = CreateTemplate(name, App.Instance.Settings.ActivateNewMods, version, factorioVersion);
         Mods.Add(mod);
         Save();
         return(mod.Enabled);
     }
 }
Exemple #9
0
 public ModpackTemplateMod(string name, Version factorioVersion, GameCompatibleVersion version)
 {
     Name            = name;
     FactorioVersion = factorioVersion;
     Version         = version;
 }
 /// <summary>
 /// Checks if the collection contains a mod.
 /// </summary>
 /// <param name="name">The name of the mod.</param>
 /// <param name="version">The mods version.</param>
 /// <returns>Returns true if the collection contains the mod, otherwise false.</returns>
 public bool Contains(string name, GameCompatibleVersion version)
 {
     return(this.Any(mod =>
                     string.Equals(mod.Name, name, StringComparison.InvariantCultureIgnoreCase) &&
                     (mod.Version == version)));
 }
Exemple #11
0
 public ModTemplate(string name, bool enabled, GameCompatibleVersion version)
 {
     Name    = name;
     Enabled = enabled;
     Version = version;
 }