Skip to content

Commit

Permalink
RunAGroup creates a seed mod as a starting point
Browse files Browse the repository at this point in the history
closes #444
  • Loading branch information
Noggog committed Apr 17, 2024
1 parent 5ead445 commit 9cf6739
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
46 changes: 46 additions & 0 deletions Synthesis.Bethesda.Execution/Running/Runner/CreateEmptyPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.IO.Abstractions;
using Mutagen.Bethesda.Environments.DI;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Plugins.Records;
using Noggog;
using Serilog;
using Synthesis.Bethesda.Execution.Profile;

namespace Synthesis.Bethesda.Execution.Running.Runner;

public interface ICreateEmptyPatch
{
FilePath Create(ModKey modKey, RunParameters runParameters);
}

public class CreateEmptyPatch : ICreateEmptyPatch
{
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly IGameReleaseContext _gameReleaseContext;
public IProfileDirectories ProfileDirectories { get; }

public CreateEmptyPatch(
ILogger logger,
IFileSystem fileSystem,
IProfileDirectories profileDirectories,
IGameReleaseContext gameReleaseContext)
{
_logger = logger;
_fileSystem = fileSystem;
_gameReleaseContext = gameReleaseContext;
ProfileDirectories = profileDirectories;
}

public FilePath Create(ModKey modKey, RunParameters runParameters)
{
var path = new FilePath(Path.Combine(ProfileDirectories.WorkingDirectory, "Seed Mod", modKey.FileName));
_logger.Information("Creating seed mod at {Path}", path);
path.Directory?.Create(_fileSystem);
var mod = ModInstantiator.Activator(modKey, _gameReleaseContext.Release,
headerVersion: runParameters.HeaderVersionOverride,
forceUseLowerFormIDRanges: runParameters.FormIDRangeMode.ToForceBool());
mod.WriteToBinary(path, fileSystem: _fileSystem);
return path;
}
}
20 changes: 15 additions & 5 deletions Synthesis.Bethesda.Execution/Running/Runner/GroupRunPreparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Plugins;
using Noggog;
using Synthesis.Bethesda.Execution.Groups;
using Synthesis.Bethesda.Execution.Settings;
Expand All @@ -7,30 +7,37 @@ namespace Synthesis.Bethesda.Execution.Running.Runner;

public interface IGroupRunPreparer
{
Task Prepare(
Task<FilePath> Prepare(
IGroupRun groupRun,
IReadOnlySet<ModKey> blackListedMods,
RunParameters runParameters);
}

public class GroupRunPreparer : IGroupRunPreparer
{
private readonly ICreateEmptyPatch _createEmptyPatch;
public IGroupRunLoadOrderPreparer GroupRunLoadOrderPreparer { get; }
public IRunPersistencePreparer PersistencePreparer { get; }

public GroupRunPreparer(
IGroupRunLoadOrderPreparer groupRunLoadOrderPreparer,
IRunPersistencePreparer persistencePreparer)
IRunPersistencePreparer persistencePreparer,
ICreateEmptyPatch createEmptyPatch)
{
_createEmptyPatch = createEmptyPatch;
GroupRunLoadOrderPreparer = groupRunLoadOrderPreparer;
PersistencePreparer = persistencePreparer;
}

public async Task Prepare(
public async Task<FilePath> Prepare(
IGroupRun groupRun,
IReadOnlySet<ModKey> blackListedMods,
RunParameters runParameters)
{
var seedPatch = Task.Run(() =>
{
return _createEmptyPatch.Create(groupRun.ModKey, runParameters);
});
await Task.WhenAll(
Task.Run(() =>
{
Expand All @@ -39,6 +46,9 @@ await Task.WhenAll(
Task.Run(() =>
{
PersistencePreparer.Prepare(runParameters.PersistenceMode, runParameters.PersistencePath);
})).ConfigureAwait(false);
}),
seedPatch).ConfigureAwait(false);

return await seedPatch;
}
}
4 changes: 2 additions & 2 deletions Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<bool> Run(
}
}

await GroupRunPreparer.Prepare(
var sourcePath = await GroupRunPreparer.Prepare(
groupRun,
groupRun.BlacklistedMods,
runParameters).ConfigureAwait(false);
Expand All @@ -57,7 +57,7 @@ await GroupRunPreparer.Prepare(
groupRun,
groupRun.Patchers,
cancellation,
null,
sourcePath,
runParameters).ConfigureAwait(false);

if (finalPath == null) return false;
Expand Down

0 comments on commit 9cf6739

Please sign in to comment.