Ejemplo n.º 1
0
        /// <summary>
        /// Checks if a collection of mods contains a mod that satisfies this dependency.
        /// </summary>
        public bool IsPresent(ModCollection mods, Version factorioVersion, out Mod mod)
        {
            bool result = false;

            mod = null;

            if (IsBase || IsInverted)
            {
                result = true;
            }
            else if (HasRestriction)
            {
                var comparison = comparisonFunctions[RestrictionComparison];

                var candidates = mods.Find(ModName, factorioVersion).Where(item => comparison(item.Version, RestrictionVersion));
                mod    = candidates.MaxBy(candidate => candidate.Version, new VersionComparer());
                result = mod != null;
            }
            else
            {
                var candidates = mods.Find(ModName, factorioVersion);
                mod    = candidates.MaxBy(candidate => candidate.Version, new VersionComparer());
                result = mod != null;
            }

            return(result);
        }
Ejemplo n.º 2
0
 private IEnumerable <Mod> GetTargetMods(ModCollection mods, Version factorioVersion)
 {
     if (HasVersionRestriction)
     {
         if (ExactRestriction)
         {
             if (mods.TryGetMod(ModName, ModVersion, out Mod mod))
             {
                 return(mod.EnumerateSingle());
             }
             else
             {
                 return(Enumerable.Empty <Mod>());
             }
         }
         else
         {
             return(mods.Find(ModName, factorioVersion).Where(item => item.Version >= ModVersion));
         }
     }
     else
     {
         return(mods.Find(ModName, factorioVersion));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Activates this dependency if possible.
        /// </summary>
        public void Activate(ModCollection mods, Version factorioVersion)
        {
            if (IsBase)
            {
                return;
            }

            var candidates = mods.Find(ModName, factorioVersion);

            if (HasRestriction)
            {
                var comparison = comparisonFunctions[RestrictionComparison];
                candidates = candidates.Where(candidate => comparison(candidate.Version, RestrictionVersion));
            }

            if (IsInverted)
            {
                foreach (var candidate in candidates)
                {
                    candidate.Active = false;
                }
            }
            else
            {
                if (!candidates.Any(candidate => candidate.Active, true))
                {
                    var max = candidates.MaxBy(candidate => candidate.Version, new VersionComparer());
                    max.Active = true;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if a collection of mods contains a mod that satisfies this dependency.
        /// </summary>
        public bool IsPresent(ModCollection mods, Version factorioVersion)
        {
            bool result = false;

            if (IsBase || IsInverted)
            {
                result = true;
            }
            else if (HasRestriction)
            {
                var comparison = comparisonFunctions[RestrictionComparison];

                var candidates = mods.Find(ModName, factorioVersion);
                foreach (var candidate in candidates)
                {
                    if (comparison(candidate.Version, RestrictionVersion))
                    {
                        result = true;
                        break;
                    }
                }
            }
            else
            {
                result = mods.ContainsbyFactorioVersion(ModName, factorioVersion);
            }

            Unsatisfied = !result;
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks if a collection of mods satisfies this dependency.
        /// </summary>
        public bool IsMet(ModCollection mods, Version factorioVersion)
        {
            bool result;

            if (IsBase || IsInverted)
            {
                result = true;
            }
            else
            {
                if (HasVersionRestriction)
                {
                    if (ExactRestriction)
                    {
                        result = mods.Contains(ModName, ModVersion);
                    }
                    else
                    {
                        var candidates = mods.Find(ModName, factorioVersion);
                        result = candidates.Any(item => item.Version >= ModVersion);
                    }
                }
                else
                {
                    result = mods.ContainsbyFactorioVersion(ModName, factorioVersion);
                }
            }

            Unsatisfied = !result;
            OnPropertyChanged(new PropertyChangedEventArgs(nameof(Unsatisfied)));

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks if a collection of mods satisfies this dependency and the dependency is active.
        /// </summary>
        public bool IsActive(ModCollection mods, Version factorioVersion)
        {
            if (IsBase || IsInverted)
            {
                return(true);
            }
            else if (HasRestriction)
            {
                var comparison = comparisonFunctions[RestrictionComparison];

                var candidates = mods.Find(ModName, factorioVersion);
                return(candidates.Any(candidate => candidate.Active && comparison(candidate.Version, RestrictionVersion)));
            }
            else
            {
                var candidates = mods.Find(ModName, factorioVersion);
                return(candidates.Any(candidate => candidate.Active));
            }
        }