/// <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)); }
/// <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); } }
/// <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); } }
public RunnabilityState( CheckRunnability settings, ILoadOrderGetter <IModListingGetter> loadOrder) { Settings = settings; LoadOrder = loadOrder; }
/// <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); } }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
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); }
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); }
/// <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)); }
/// <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)); }
/// <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); }
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); }
/// <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)); }
/// <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); }
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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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>()); }
/// <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()); }
/// <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>()); }
/// <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)); }
/// <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()); }
/// <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); }