示例#1
0
 /// <summary>
 /// Creates a new linking package relative to a load order.<br/>
 /// Will resolve links to the highest overriding mod containing the record being sought. <br/>
 /// Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become
 /// incorrect if modifications occur on content already cached.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to construct the package relative to</param>
 /// <param name="prefs">Caching preferences</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static ImmutableLoadOrderLinkCache ToUntypedImmutableLinkCache <TMod>(
     this ILoadOrderGetter <TMod> loadOrder,
     LinkCachePreferences?prefs = null)
     where TMod : class, IModGetter
 {
     return(new ImmutableLoadOrderLinkCache(loadOrder.ListedOrder, GameCategoryHelper.TryFromModType <TMod>(), prefs ?? LinkCachePreferences.Default));
 }
示例#2
0
 /// <summary>
 /// Asserts a given mod is in the collection of keys.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to query</param>
 /// <param name="modKey">ModKey to look for</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMod(this ILoadOrderGetter loadOrder, ModKey modKey, string?message = null)
 {
     if (!HasMod(loadOrder, modKey))
     {
         throw new MissingModException(loadOrder.ListedOrder, message: message);
     }
 }
示例#3
0
 /// <summary>
 /// Asserts a given mod is in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">Listings to look through</param>
 /// <param name="modKey">ModKey to look for</param>
 /// <param name="enabled">Whether the ModKey should be enabled/disabled.  Default is no preference</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMod(this ILoadOrderGetter <IModListingGetter> loadOrder, ModKey modKey, bool?enabled = null, string?message = null)
 {
     if (!HasMod(loadOrder, modKey, enabled))
     {
         throw new MissingModException(modKey, message: message);
     }
 }
示例#4
0
 public RunnabilityState(
     CheckRunnability settings,
     ILoadOrderGetter <IModListingGetter> loadOrder)
 {
     Settings  = settings;
     LoadOrder = loadOrder;
 }
示例#5
0
        /// <summary>
        /// Asserts all of a given set of ModKeys are in the collection of listings.
        /// </summary>
        /// <param name="loadOrder">Listings to look through</param>
        /// <param name="enabled">Whether the ModKey should be enabled/disabled</param>
        /// <param name="message">Message to attach to exception if mod doesn't exist</param>
        /// <param name="modKeys">ModKey to look for</param>
        /// <exception cref="MissingModException">
        /// Thrown if given mod is not on the collection of listings
        /// </exception>
        public static void AssertHasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, bool enabled, string?message, params ModKey[] modKeys)
        {
            if (modKeys.Length == 0)
            {
                return;
            }
            if (modKeys.Length == 1)
            {
                AssertHasMod(loadOrder, modKeys[0], enabled);
            }
            var set = modKeys.ToHashSet();

            foreach (var listing in loadOrder.ListedOrder)
            {
                if (listing.Enabled == enabled &&
                    set.Remove(listing.ModKey) &&
                    set.Count == 0)
                {
                    return;
                }
            }
            if (set.Count > 0)
            {
                throw new MissingModException(set, message: message);
            }
        }
示例#6
0
 /// <summary>
 /// Will find and return the most overridden version of each record in the load order of the given type
 /// USAGE NOTE: <br/>
 /// Typically you should only supply the Getter interfaces for the type. <br/>
 /// A setter interface being given can result in no records being found, as most LoadOrders are readonly.
 /// </summary>
 /// <typeparam name="TMod">Mod type that the load order contains</typeparam>
 /// <typeparam name="TMajor">
 /// Type of record to search for and iterate. <br/>
 /// USAGE NOTE: <br/>
 /// Typically you should only supply the Getter interfaces for the type. <br/>
 /// A setter interface being given can result in no records being found, as most LoadOrders are readonly.
 /// </typeparam>
 /// <param name="loadOrder">LoadOrder to iterate over</param>
 /// <param name="includeDeletedRecords">Whether to include deleted records in the output</param>
 /// <returns>Enumerable of the most overridden version of each record of the given type, optionally including deleted ones</returns>
 public static IEnumerable <TMajor> WinningOverrides <TMod, TMajor>(
     this ILoadOrderGetter <TMod> loadOrder,
     bool includeDeletedRecords = false)
     where TMod : class, IModGetter
     where TMajor : class, IMajorRecordCommonGetter
 {
     return(loadOrder.PriorityOrder.WinningOverrides <TMajor>(includeDeletedRecords: includeDeletedRecords));
 }
示例#7
0
 /// <summary>
 /// Will find and return the most overridden version of each record in the load order of the given type
 /// USAGE NOTE: <br/>
 /// Typically you should only supply the Getter interfaces for the type. <br/>
 /// A setter interface being given can result in no records being found, as most LoadOrders are readonly.
 /// </summary>
 /// <typeparam name="TMod">Mod type that the load order contains</typeparam>
 /// <param name="loadOrder">LoadOrder to iterate over</param>
 /// <param name="type">
 /// Type of record to search for and iterate. <br/>
 /// USAGE NOTE: <br/>
 /// Typically you should only supply the Getter interfaces for the type. <br/>
 /// A setter interface being given can result in no records being found, as most LoadOrders are readonly.
 /// </param>
 /// <param name="includeDeletedRecords">Whether to include deleted records in the output</param>
 /// <returns>Enumerable of the most overridden version of each record of the given type, optionally including deleted ones</returns>
 public static IEnumerable <IMajorRecordGetter> WinningOverrides <TMod>(
     this ILoadOrderGetter <TMod> loadOrder,
     Type type,
     bool includeDeletedRecords = false)
     where TMod : class, IModGetter
 {
     return(loadOrder.PriorityOrder.WinningOverrides(type, includeDeletedRecords: includeDeletedRecords));
 }
示例#8
0
 /// <summary>
 /// Creates a new linking package relative to a load order.<br/>
 /// Will resolve links to the highest overriding mod containing the record being sought. <br/>
 /// Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become
 /// incorrect if modifications occur on content already cached.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to construct the package relative to</param>
 /// <param name="prefs">Caching preferences</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static ImmutableLoadOrderLinkCache <TMod, TModGetter> ToImmutableLinkCache <TMod, TModGetter>(
     this ILoadOrderGetter <TModGetter> loadOrder,
     LinkCachePreferences?prefs = null)
     where TMod : class, IContextMod <TMod, TModGetter>, TModGetter
     where TModGetter : class, IContextGetterMod <TMod, TModGetter>
 {
     return(new ImmutableLoadOrderLinkCache <TMod, TModGetter>(loadOrder.ListedOrder, prefs ?? LinkCachePreferences.Default));
 }
示例#9
0
        /// <summary>
        /// Checks whether a given mod is in the collection of listings.
        /// </summary>
        /// <param name="loadOrder">Listings to look through</param>
        /// <param name="modKey">ModKey to look for</param>
        /// <param name="enabled">Whether the ModKey should be enabled/disabled.  Default is no preference</param>
        /// <returns>True if ModKey is in the listings, with the desired enabled state</returns>
        public static bool HasMod(this ILoadOrderGetter <IModListingGetter> loadOrder, ModKey modKey, bool?enabled = null)
        {
            if (loadOrder.TryGetValue(modKey, out var listing))
            {
                return(enabled == null || listing.Enabled == enabled);
            }

            return(false);
        }
示例#10
0
 public static TListing GetIfEnabled <TListing>(this ILoadOrderGetter <TListing> loadOrder, ModKey modKey)
     where TListing : IModListingGetter
 {
     if (TryGetIfEnabled(loadOrder, modKey, out var listing))
     {
         return(listing);
     }
     throw new MissingModException(modKey);
 }
示例#11
0
 public static TMod GetIfEnabledAndExists <TMod>(this ILoadOrderGetter <IModListingGetter <TMod> > loadOrder, ModKey modKey)
     where TMod : class, IModGetter
 {
     if (TryGetIfEnabledAndExists <TMod>(loadOrder, modKey, out var mod))
     {
         return(mod);
     }
     throw new MissingModException(modKey);
 }
示例#12
0
 /// <summary>
 /// Will find and return the most overridden version of each record in the list of mods of the given type. <br/>
 /// <br />
 /// Additionally, it will come wrapped in a context object that has knowledge of where each record came from. <br/>
 /// This context helps when trying to override deep records such as Cells/PlacedObjects/etc, as the context is able to navigate
 /// and insert the record into the proper location for you. <br />
 /// <br />
 /// This system is overkill for simpler top-level records.
 /// </summary>
 /// <typeparam name="TMod">Setter Mod type to target</typeparam>
 /// <typeparam name="TModGetter">Getter Mod type to target</typeparam>
 /// <param name="loadOrder">LoadOrder to iterate over</param>
 /// <param name="linkCache">LinkCache to use when creating parent objects</param>
 /// <param name="type">
 /// Type of record to search for and iterate. <br/>
 /// USAGE NOTE: <br/>
 /// Typically you should only supply the Getter interfaces for the type. <br/>
 /// A setter interface being given can result in no records being found, as most LoadOrders are readonly.
 /// </param>
 /// <param name="includeDeletedRecords">Whether to include deleted records in the output</param>
 /// <returns>Enumerable of the most overridden version of each record of the given type, optionally including deleted ones</returns>
 public static IEnumerable <IModContext <TMod, TModGetter, IMajorRecord, IMajorRecordGetter> > WinningOverrideContexts <TMod, TModGetter>(
     this ILoadOrderGetter <TModGetter> loadOrder,
     ILinkCache linkCache,
     Type type,
     bool includeDeletedRecords = false)
     where TMod : class, IMod, TModGetter
     where TModGetter : class, IModGetter, IMajorRecordContextEnumerable <TMod, TModGetter>
 {
     return(loadOrder.PriorityOrder.WinningOverrideContexts <TMod, TModGetter>(linkCache, type, includeDeletedRecords: includeDeletedRecords));
 }
示例#13
0
 /// <summary>
 /// Creates a mutable load order link cache by combining an existing immutable load order cache,
 /// plus a set of mods to be put at the end of the load order and allow to be mutable.
 /// </summary>
 /// <param name="immutableBaseCache">LoadOrderCache to use as the immutable base</param>
 /// <param name="mutableMods">Set of mods to place at the end of the load order, which are allowed to be modified afterwards</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static MutableLoadOrderLinkCache <TMod, TModGetter> ToMutableLinkCache <TMod, TModGetter>(
     this ILoadOrderGetter <IModListingGetter <TModGetter> > immutableBaseCache,
     params TMod[] mutableMods)
     where TMod : class, IContextMod <TMod, TModGetter>, TModGetter
     where TModGetter : class, IContextGetterMod <TMod, TModGetter>
 {
     return(new MutableLoadOrderLinkCache <TMod, TModGetter>(
                immutableBaseCache.ToImmutableLinkCache <TMod, TModGetter>(),
                mutableMods));
 }
示例#14
0
 /// <summary>
 /// Checks whether all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to query</param>
 /// <param name="modKeys">ModKeys to look for</param>
 /// <returns>True if all ModKeys are present in the listings</returns>
 public static bool HasMods(this ILoadOrderGetter loadOrder, IEnumerable <ModKey> modKeys)
 {
     foreach (var key in modKeys)
     {
         if (!loadOrder.ContainsKey(key))
         {
             return(false);
         }
     }
     return(true);
 }
示例#15
0
        public static bool TryGetIfEnabledAndExists <TMod>(this ILoadOrderGetter <IModListingGetter <TMod> > loadOrder, ModKey modKey, [MaybeNullWhen(false)] out TMod item)
            where TMod : class, IModGetter
        {
            if (!TryGetIfEnabled(loadOrder, modKey, out var listing))
            {
                item = default;
                return(false);
            }

            item = listing.Mod;
            return(item != null);
        }
示例#16
0
 /// <summary>
 /// Creates a new linking package relative to a load order.<br/>
 /// Will resolve links to the highest overriding mod containing the record being sought. <br/>
 /// Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become
 /// incorrect if modifications occur on content already cached.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to construct the package relative to</param>
 /// <param name="prefs">Caching preferences</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static ImmutableLoadOrderLinkCache <TMod, TModGetter> ToImmutableLinkCache <TMod, TModGetter>(
     this ILoadOrderGetter <IModListingGetter <TModGetter> > loadOrder,
     LinkCachePreferences?prefs = null)
     where TMod : class, IContextMod <TMod, TModGetter>, TModGetter
     where TModGetter : class, IContextGetterMod <TMod, TModGetter>
 {
     return(new ImmutableLoadOrderLinkCache <TMod, TModGetter>(
                loadOrder
                .Select(listing => listing.Value.Mod)
                .NotNull(),
                prefs ?? LinkCachePreferences.Default));
 }
示例#17
0
        /// <summary>
        /// Checks whether all of a given set of ModKeys are in the collection of listings.
        /// </summary>
        /// <param name="loadOrder">Listings to look through</param>
        /// <param name="modKeys">ModKeys to look for</param>
        /// <returns>True if all ModKeys are present in the listings</returns>
        public static bool HasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, params ModKey[] modKeys)
        {
            foreach (var key in modKeys)
            {
                if (!loadOrder.ContainsKey(key))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#18
0
        public static bool TryGetIfEnabled <TListing>(this ILoadOrderGetter <TListing> loadOrder, ModKey modKey, [MaybeNullWhen(false)] out TListing item)
            where TListing : IModListingGetter
        {
            if (loadOrder.TryGetValue(modKey, out var listing) &&
                listing.Enabled)
            {
                item = listing;
                return(true);
            }

            item = default;
            return(false);
        }
示例#19
0
        public static bool TryGetIndex <TListing>(this ILoadOrderGetter <TListing> loadOrder, int index, [MaybeNullWhen(false)] out TListing listing)
            where TListing : IModKeyed
        {
            var result = loadOrder.TryGetAtIndex(index);

            if (result == null)
            {
                listing = default;
                return(false);
            }

            listing = result;
            return(true);
        }
示例#20
0
        /// <summary>
        /// Checks whether all of a given set of ModKeys are in the collection of listings.
        /// </summary>
        /// <param name="loadOrder">Listings to look through</param>
        /// <param name="enabled">Whether the ModKey should be enabled/disabled</param>
        /// <param name="modKeys">ModKey to look for</param>
        /// <returns>True if all ModKeys are present in the listings, with the desired enabled state</returns>
        public static bool HasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, bool enabled, params ModKey[] modKeys)
        {
            if (modKeys.Length == 0)
            {
                return(true);
            }
            if (modKeys.Length == 1)
            {
                return(HasMod(loadOrder, modKeys[0], enabled));
            }
            var set = modKeys.ToHashSet();

            foreach (var listing in loadOrder.ListedOrder)
            {
                if (listing.Enabled == enabled &&
                    set.Remove(listing.ModKey) &&
                    set.Count == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#21
0
 /// <summary>
 /// Asserts all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">Listings to look through</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <param name="modKeys">ModKeys to look for</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, string?message, params ModKey[] modKeys)
 {
     AssertHasMods(loadOrder.ListedOrder.Select(x => x.ModKey), message, modKeys);
 }
示例#22
0
 /// <summary>
 /// Asserts all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">Listings to look through</param>
 /// <param name="enabled">Whether the ModKey should be enabled/disabled</param>
 /// <param name="modKeys">ModKey to look for</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, bool enabled, params ModKey[] modKeys)
 {
     AssertHasMods(loadOrder, enabled, message: null, modKeys: modKeys);
 }
示例#23
0
 /// <summary>
 /// Checks whether all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">Listings to look through</param>
 /// <param name="enabled">Whether the ModKey should be enabled/disabled</param>
 /// <param name="modKeys">ModKey to look for</param>
 /// <returns>True if all ModKeys are present in the listings, with the desired enabled state</returns>
 public static bool HasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, bool enabled, IEnumerable <ModKey> modKeys)
 {
     return(HasMods(loadOrder, enabled, modKeys.ToArray()));
 }
 /// <summary>
 /// Creates a mutable load order link cache by combining an existing immutable load order cache,
 /// plus a set of mods to be put at the end of the load order and allow to be mutable.
 /// </summary>
 /// <param name="immutableBaseCache">LoadOrderCache to use as the immutable base</param>
 /// <param name="mutableMods">Set of mods to place at the end of the load order, which are allowed to be modified afterwards</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static MutableLoadOrderLinkCache <IFallout4Mod, IFallout4ModGetter> ToMutableLinkCache(
     this ILoadOrderGetter <IFallout4ModGetter> immutableBaseCache,
     params IFallout4Mod[] mutableMods)
 {
     return(immutableBaseCache.ToMutableLinkCache <IFallout4Mod, IFallout4ModGetter>(mutableMods));
 }
 /// <summary>
 /// Creates a new linking package relative to a load order.<br/>
 /// Will resolve links to the highest overriding mod containing the record being sought. <br/>
 /// Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become
 /// incorrect if modifications occur on content already cached.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to construct the package relative to</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static ImmutableLoadOrderLinkCache <IFallout4Mod, IFallout4ModGetter> ToImmutableLinkCache(this ILoadOrderGetter <IModListingGetter <IFallout4ModGetter> > loadOrder)
 {
     return(loadOrder.ToImmutableLinkCache <IFallout4Mod, IFallout4ModGetter>());
 }
示例#26
0
 /// <summary>
 /// Asserts all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">Listings to look through</param>
 /// <param name="enabled">Whether the ModKey should be enabled/disabled</param>
 /// <param name="modKeys">ModKey to look for</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMods(this ILoadOrderGetter <IModListingGetter> loadOrder, bool enabled, IEnumerable <ModKey> modKeys, string?message = null)
 {
     AssertHasMods(loadOrder, enabled, message: message, modKeys: modKeys.ToArray());
 }
示例#27
0
 /// <summary>
 /// Creates a new linking package relative to a load order.<br/>
 /// Will resolve links to the highest overriding mod containing the record being sought. <br/>
 /// Modification of the target LoadOrder, or Mods on the LoadOrder is not safe.  Internal caches can become
 /// incorrect if modifications occur on content already cached.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to construct the package relative to</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static ImmutableLoadOrderLinkCache <IOblivionMod, IOblivionModGetter> ToImmutableLinkCache(this ILoadOrderGetter <IOblivionModGetter> loadOrder)
 {
     return(loadOrder.ToImmutableLinkCache <IOblivionMod, IOblivionModGetter>());
 }
示例#28
0
 /// <summary>
 /// Creates a mutable load order link cache by combining an existing immutable load order cache,
 /// plus a set of mods to be put at the end of the load order and allow to be mutable.
 /// </summary>
 /// <param name="immutableBaseCache">LoadOrderCache to use as the immutable base</param>
 /// <param name="mutableMods">Set of mods to place at the end of the load order, which are allowed to be modified afterwards</param>
 /// <returns>LinkPackage attached to given LoadOrder</returns>
 public static MutableLoadOrderLinkCache <IOblivionMod, IOblivionModGetter> ToMutableLinkCache(
     this ILoadOrderGetter <IModListingGetter <IOblivionModGetter> > immutableBaseCache,
     params IOblivionMod[] mutableMods)
 {
     return(immutableBaseCache.ToMutableLinkCache <IOblivionMod, IOblivionModGetter>(mutableMods));
 }
示例#29
0
 /// <summary>
 /// Asserts all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to query</param>
 /// <param name="modKeys">ModKeys to look for</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMods(this ILoadOrderGetter loadOrder, IEnumerable <ModKey> modKeys, string?message = null)
 {
     AssertHasMods(loadOrder, message: message, modKeys: modKeys.ToArray());
 }
示例#30
0
 /// <summary>
 /// Asserts all of a given set of ModKeys are in the collection of listings.
 /// </summary>
 /// <param name="loadOrder">LoadOrder to query</param>
 /// <param name="message">Message to attach to exception if mod doesn't exist</param>
 /// <param name="modKeys">ModKeys to look for</param>
 /// <exception cref="MissingModException">
 /// Thrown if given mod is not on the collection of listings
 /// </exception>
 public static void AssertHasMods(this ILoadOrderGetter loadOrder, string?message, params ModKey[] modKeys)
 {
     AssertHasMods(loadOrder.ListedOrder, message, modKeys);
 }