Skip to content

Commit

Permalink
Fixes for WithExplicitOverridingMasterList. Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 2, 2024
1 parent c831376 commit eef2461
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public sealed record BinaryWriteParameters
/// </summary>
public IEnumerable<ModKey>? ExtraIncludeMasters { get; init; }

/// <summary>
/// Specifies a list of masters to override
/// </summary>
public IEnumerable<ModKey>? OverrideMasters { get; init; }

/// <summary>
/// Logic to use to keep a mod's record count in sync
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,8 @@ public FileBinaryModdedWriteBuilder<TModGetter> WithExplicitOverridingMasterList
{
_param = _params._param with
{
OverrideMasters = modKeys
MastersListContent = new MastersListContentOverrideOption(modKeys.ToArray()),
MastersListOrdering = new MastersListOrderingByLoadOrder(modKeys.ToArray())
}
}
};
Expand Down Expand Up @@ -2051,7 +2052,8 @@ public FileBinaryWriteBuilder<TModGetter> WithExplicitOverridingMasterList(IEnum
{
_param = _params._param with
{
OverrideMasters = modKeys
MastersListContent = new MastersListContentOverrideOption(modKeys.ToArray()),
MastersListOrdering = new MastersListOrderingByLoadOrder(modKeys.ToArray())
}
}
};
Expand Down
60 changes: 60 additions & 0 deletions Mutagen.Bethesda.UnitTests/Plugins/Builders/WriteBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,64 @@ public void NoDataFolderWithHeaderMasters(
reimport.MasterReferences.Select(x => x.Master).Should()
.Equal(masterMod);
}

[Theory, MutagenAutoData]
public void ExtraIncludedMasters(
IFileSystem fileSystem,
ModKey masterMod,
ModKey modKey,
ModKey extraMaster,
DirectoryPath existingDir)
{
var master = new StarfieldMod(masterMod, StarfieldRelease.Starfield);
var masterWeapon = master.Weapons.AddNew();
var mod = new StarfieldMod(modKey, StarfieldRelease.Starfield);
mod.Weapons.GetOrAddAsOverride(masterWeapon);
var modPath = Path.Combine(existingDir, mod.ModKey.FileName);
mod.BeginWrite
.WithLoadOrder(masterMod, extraMaster)
.WithNoDataFolder()
.ToPath(modPath)
.WithFileSystem(fileSystem)
.WithExtraIncludedMasters(extraMaster)
.Write();

using var reimport = StarfieldMod.CreateFromBinaryOverlay(modPath, StarfieldRelease.Starfield,
new BinaryReadParameters()
{
FileSystem = fileSystem
});
reimport.MasterReferences.Select(x => x.Master).Should()
.Equal(masterMod, extraMaster);
}

[Theory, MutagenAutoData]
public void OverrideMasters(
IFileSystem fileSystem,
ModKey masterMod,
ModKey modKey,
ModKey overrideMaster,
DirectoryPath existingDir)
{
var master = new StarfieldMod(masterMod, StarfieldRelease.Starfield);
var masterWeapon = master.Weapons.AddNew();
var mod = new StarfieldMod(modKey, StarfieldRelease.Starfield);
mod.Weapons.GetOrAddAsOverride(masterWeapon);
var modPath = Path.Combine(existingDir, mod.ModKey.FileName);
mod.BeginWrite
.WithLoadOrder(masterMod, overrideMaster)
.WithNoDataFolder()
.ToPath(modPath)
.WithFileSystem(fileSystem)
.WithExplicitOverridingMasterList(overrideMaster, masterMod)
.Write();

using var reimport = StarfieldMod.CreateFromBinaryOverlay(modPath, StarfieldRelease.Starfield,
new BinaryReadParameters()
{
FileSystem = fileSystem
});
reimport.MasterReferences.Select(x => x.Master).Should()
.Equal(masterMod, overrideMaster);
}
}

0 comments on commit eef2461

Please sign in to comment.