Skip to content

Commit

Permalink
Merge branch 'known-masters' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 14, 2024
2 parents 629cd15 + 6bd9c11 commit be5183e
Show file tree
Hide file tree
Showing 32 changed files with 1,130 additions and 437 deletions.
2 changes: 2 additions & 0 deletions Mutagen.Bethesda.Core.UnitTests/Placeholders/TestMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public uint GetRecordCount()
public bool IsMediumMaster { get; set; }
public bool ListsOverriddenForms { get; }

public MasterStyle MasterStyle { get; }

IGroup? IMod.TryGetTopLevelGroup(Type type)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal static IModFlagsGetter GetFlags(ModKey modKey, MasterStyle style)
modGetter.ModKey.Returns(modKey);
modGetter.CanBeSmallMaster.Returns(true);
modGetter.CanBeMediumMaster.Returns(true);
modGetter.MasterStyle.Returns(style);
switch (style)
{
case MasterStyle.Full:
Expand Down
35 changes: 35 additions & 0 deletions Mutagen.Bethesda.Core/Extensions/LoadOrderExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mutagen.Bethesda.Plugins.Exceptions;
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Plugins.Records;
using Noggog;

namespace Mutagen.Bethesda;

Expand Down Expand Up @@ -78,6 +79,19 @@ public static IEnumerable<TModItem> ResolveAllModsExist<TModItem>(this IEnumerab
return loadOrder.Select(x => x.Mod!);
}

/// <summary>
/// Converts any listings that have mods into Mods. Will not throw
/// </summary>
/// <param name="loadOrder">Listings to convert</param>
/// <returns>Mods contained in the listings that exist</returns>
public static IEnumerable<TModItem> ResolveExistingMods<TModItem>(this IEnumerable<IModListingGetter<TModItem>> loadOrder)
where TModItem : class, IModKeyed
{
return loadOrder
.Select(x => x.Mod)
.NotNull();
}

/// <summary>
/// Converts listings to Mods. Will throw if any mods do not exist
/// </summary>
Expand All @@ -92,6 +106,19 @@ public static LoadOrder<TModItem> ResolveAllModsExist<TModItem>(
return new LoadOrder<TModItem>(ResolveAllModsExist<TModItem>(loadOrder.ListedOrder), disposeItems: disposeItems ?? loadOrder.DisposingItems);
}

/// <summary>
/// Converts any listings that have mods into Mods. Will not throw
/// </summary>
/// <param name="loadOrder">Listings to convert</param>
/// <returns>Mods contained in the listings that exist</returns>
public static LoadOrder<TModItem> ResolveExistingMods<TModItem>(
this ILoadOrderGetter<IModListingGetter<TModItem>> loadOrder,
bool? disposeItems = null)
where TModItem : class, IModKeyed
{
return new LoadOrder<TModItem>(ResolveExistingMods<TModItem>(loadOrder.ListedOrder), disposeItems: disposeItems ?? loadOrder.DisposingItems);
}

/// <summary>
/// Converts ModKeys to LoadOrderListing objects
/// </summary>
Expand Down Expand Up @@ -149,4 +176,12 @@ public static LoadOrder<TRetListing> Transform<TListing, TRetListing>(this ILoad
loadOrder.ListedOrder
.Select(transformer));
}

public static LoadOrder<TListing> Where<TListing>(this ILoadOrderGetter<TListing> loadOrder, Func<TListing, bool> filter)
where TListing : IModKeyed
{
return new LoadOrder<TListing>(
loadOrder.ListedOrder
.Where(filter));
}
}
3 changes: 2 additions & 1 deletion Mutagen.Bethesda.Core/Mutagen.Bethesda.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<Compile Include="Plugins\Exceptions\FormIDCompactionOutOfBoundsException.cs" />
<Compile Include="Plugins\Exceptions\LowerFormIDRangeDisallowedException.cs" />
<Compile Include="Plugins\Exceptions\MissingGameLibsException.cs" />
<Compile Include="Plugins\Exceptions\MissingLoadOrderException.cs" />
<Compile Include="Plugins\Exceptions\MissingModMappingException.cs" />
<Compile Include="Plugins\Exceptions\UnmappableFormIDException.cs" />
<Compile Include="Plugins\Exceptions\MalformedDataException.cs" />
<Compile Include="Plugins\Exceptions\ModHeaderMalformedException.cs" />
Expand Down Expand Up @@ -498,6 +498,7 @@
<DefaultPackFolder>content</DefaultPackFolder>
<BuildAction>Compile</BuildAction>
</Compile>
<Compile Include="Plugins\Records\KeyedMasterStyle.cs" />
<Compile Include="Plugins\Records\Loqui\IModRegistration.cs" />
<Compile Include="Plugins\Records\Mapping\AbstractInterfaceMapping.cs">
<CodeLanguage>cs</CodeLanguage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Plugins.Records;
using Mutagen.Bethesda.Strings;
using Noggog;

namespace Mutagen.Bethesda.Plugins.Binary.Parameters;

Expand All @@ -15,9 +16,9 @@ public record BinaryReadParameters
public StringsReadParameters? StringsParam { get; init; }

/// <summary>
/// Load order. Required for games with Separated Load Order lists per master type
/// Required for games with Separated Load Order lists per master type
/// </summary>
public ILoadOrderGetter<IModFlagsGetter>? LoadOrder { get; init; }
public IReadOnlyCache<IModMasterStyledGetter, ModKey>? MasterFlagsLookup { get; init; }

/// <summary>
/// Whether to use multithreading when possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public sealed record BinaryWriteParameters
public ALowerRangeDisallowedHandlerOption LowerRangeDisallowedHandler { get; init; } = new AddPlaceholderMasterIfLowerRangeDisallowed();

/// <summary>
/// Load order. Required for games with Separated Load Order lists per master type
/// Required for games with Separated Load Order lists per master type
/// </summary>
public ILoadOrderGetter<IModMasterFlagsGetter>? LoadOrder { get; init; }
public IReadOnlyCache<IModMasterStyledGetter, ModKey>? MasterFlagsLookup { get; init; }

/// <summary>
/// Whether to use multithreading when possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Align(
interest.InterestingTypes.Add("QUST");
interest.InterestingTypes.Add("REFR");

var masters = SeparatedMasterPackage.Factory(gameMode, inputPath, loadOrder: null, fileSystem: null);
var masters = SeparatedMasterPackage.Factory(gameMode, inputPath, masterFlagLookup: null, fileSystem: null);
var meta = new ParsingMeta(gameMode, inputPath.ModKey, masters);

using (var inputStream = new MutagenBinaryReadStream(inputPath, meta))
Expand Down
14 changes: 12 additions & 2 deletions Mutagen.Bethesda.Core/Plugins/Binary/Streams/ParsingMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static ParsingMeta Factory(
{
var header = ModHeaderFrame.FromPath(modPath, release, fileSystem: param.FileSystem);
var rawMasters = MasterReferenceCollection.FromModHeader(modPath.ModKey, header);
var masters = SeparatedMasterPackage.Factory(release, modPath, header.MasterStyle, rawMasters, param.LoadOrder);
var masters = SeparatedMasterPackage.Factory(release, modPath, header.MasterStyle, rawMasters, param.MasterFlagsLookup);
var meta = new ParsingMeta(GameConstants.Get(release), modPath.ModKey, masters);
meta.Absorb(param);
return meta;
Expand All @@ -150,9 +150,19 @@ public static ParsingMeta Factory(
var header = ModHeaderFrame.FromStream(stream, modKey, release);
var rawMasters = MasterReferenceCollection.FromModHeader(modKey, header);
stream.Position = 0;
var masters = SeparatedMasterPackage.Factory(release, modKey, header.MasterStyle, rawMasters, param.LoadOrder);
var masters = SeparatedMasterPackage.Factory(release, modKey, header.MasterStyle, rawMasters, param.MasterFlagsLookup);
var meta = new ParsingMeta(GameConstants.Get(release), modKey, masters);
meta.Absorb(param);
return meta;
}

public static ParsingMeta FactoryNoMasters(
BinaryReadParameters param,
GameRelease release,
ModKey modKey)
{
var meta = new ParsingMeta(GameConstants.Get(release), modKey, null!);
meta.Absorb(param);
return meta;
}
}
Loading

0 comments on commit be5183e

Please sign in to comment.