Ejemplo n.º 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));
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 4
0
 public RunnabilityState(
     CheckRunnability settings,
     ILoadOrderGetter <IModListingGetter> loadOrder)
 {
     Settings  = settings;
     LoadOrder = loadOrder;
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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()));
 }
Ejemplo n.º 24
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 <IFallout4Mod, IFallout4ModGetter> ToMutableLinkCache(
     this ILoadOrderGetter <IFallout4ModGetter> immutableBaseCache,
     params IFallout4Mod[] mutableMods)
 {
     return(immutableBaseCache.ToMutableLinkCache <IFallout4Mod, IFallout4ModGetter>(mutableMods));
 }
Ejemplo n.º 25
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 <IFallout4Mod, IFallout4ModGetter> ToImmutableLinkCache(this ILoadOrderGetter <IModListingGetter <IFallout4ModGetter> > loadOrder)
 {
     return(loadOrder.ToImmutableLinkCache <IFallout4Mod, IFallout4ModGetter>());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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>());
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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);
 }