Skip to content

Commit

Permalink
Sort should utilize HasWorkToDo logic. Print which triggered it
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Oct 16, 2024
1 parent 05ac7f1 commit 00ad56e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 66 deletions.
8 changes: 8 additions & 0 deletions Spriggit.CLI.Lib/Commands/Sort/SortCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public async Task<int> Run()
throw new ArgumentOutOfRangeException();
}

Console.WriteLine("Checking if there's any work to do.");
if (!sorter.HasWorkToDo(InputPath, GameRelease, DataFolder))
{
Console.WriteLine("No sorting to be done. Exiting.");
return 0;
}

await sorter.Run(InputPath, GameRelease, OutputPath, DataFolder);
Console.WriteLine("Sorting complete. Exiting.");
return 0;
}
}
61 changes: 40 additions & 21 deletions Spriggit.CLI.Lib/Commands/Sort/SortFallout4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool HasWorkToDo(
.FromPath(path)
.WithFileSystem(_fileSystem)
.Construct();
if (VirtualMachineAdapterHasWorkToDo(mod)) return true;
if (VirtualMachineAdaptersHaveWorkToDo(mod)) return true;
if (MorphGroupHasWorkToDo(mod)) return true;
return false;
}
Expand All @@ -36,8 +36,16 @@ private bool MorphGroupHasWorkToDo(IFallout4ModDisposableGetter mod)
.AsParallel())
{
var headData = race.HeadData;
if (HeadDataHasWorkToDo(headData?.Male)) return true;
if (HeadDataHasWorkToDo(headData?.Female)) return true;
if (HeadDataHasWorkToDo(headData?.Male))
{
Console.WriteLine($"{race} Male Head Data sorting to be done.");
return true;
}
if (HeadDataHasWorkToDo(headData?.Female))
{
Console.WriteLine($"{race} Female Head Data sorting to be done.");
return true;
}
}

return false;
Expand All @@ -55,38 +63,49 @@ private bool HeadDataHasWorkToDo(IHeadDataGetter? headData)
return false;
}

private bool VirtualMachineAdapterHasWorkToDo(IFallout4ModDisposableGetter mod)
private bool VirtualMachineAdaptersHaveWorkToDo(IFallout4ModDisposableGetter mod)
{
foreach (var hasVM in mod
.EnumerateMajorRecords<IHaveVirtualMachineAdapterGetter>()
.AsParallel())
{
if (hasVM.VirtualMachineAdapter is not {} vm) continue;
foreach (var script in vm.Scripts)
if (VirtualMachineAdapterHasWorkToDo(hasVM))
{
if (HasOutOfOrderScript(script)) return true;
Console.WriteLine($"{hasVM} Virtual Machine Adapter has sorting to be done.");
return true;
}
}

if (vm is IQuestAdapter questAdapter)
{
if (HasOutOfOrderScript(questAdapter.Script)) return true;
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
if (HasOutOfOrderScript(script)) return true;
}
}
return false;
}

if (vm is IPerkAdapterGetter perkAdapter)
{
if (HasOutOfOrderScript(perkAdapter.ScriptFragments?.Script)) return true;
}
private bool VirtualMachineAdapterHasWorkToDo(IHaveVirtualMachineAdapterGetter hasVM)
{
if (hasVM.VirtualMachineAdapter is not {} vm) return false;
foreach (var script in vm.Scripts)
{
if (HasOutOfOrderScript(script)) return true;
}

if (vm is IPackageAdapterGetter packageAdapter)
if (vm is IQuestAdapter questAdapter)
{
if (HasOutOfOrderScript(questAdapter.Script)) return true;
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
if (HasOutOfOrderScript(packageAdapter.ScriptFragments?.Script)) return true;
if (HasOutOfOrderScript(script)) return true;
}
}

if (vm is IPerkAdapterGetter perkAdapter)
{
if (HasOutOfOrderScript(perkAdapter.ScriptFragments?.Script)) return true;
}

if (vm is IPackageAdapterGetter packageAdapter)
{
if (HasOutOfOrderScript(packageAdapter.ScriptFragments?.Script)) return true;
}

return false;
}

Expand Down
31 changes: 21 additions & 10 deletions Spriggit.CLI.Lib/Commands/Sort/SortSkyrim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,40 @@ public bool HasWorkToDo(
.FromPath(path)
.WithFileSystem(_fileSystem)
.Construct();
if (HasVirtualMachineAdapterWorkToDo(mod)) return true;
if (VirtualMachineAdaptersHaveWorkToDo(mod)) return true;

return false;
}

private bool HasVirtualMachineAdapterWorkToDo(ISkyrimModDisposableGetter mod)
private bool VirtualMachineAdaptersHaveWorkToDo(ISkyrimModDisposableGetter mod)
{
foreach (var hasVM in mod
.EnumerateMajorRecords<IHaveVirtualMachineAdapterGetter>()
.AsParallel())
{
if (hasVM.VirtualMachineAdapter is not {} vm) continue;
foreach (var script in vm.Scripts)
if (VirtualMachineAdapterHasWorkToDo(hasVM))
{
if (HasOutOfOrderScript(script)) return true;
Console.WriteLine($"{hasVM} Virtual Machine Adapter has sorting to be done.");
return true;
}
}

return false;
}

private bool VirtualMachineAdapterHasWorkToDo(IHaveVirtualMachineAdapterGetter hasVM)
{
if (hasVM.VirtualMachineAdapter is not {} vm) return false;
foreach (var script in vm.Scripts)
{
if (HasOutOfOrderScript(script)) return true;
}

if (vm is IQuestAdapter questAdapter)
if (vm is IQuestAdapter questAdapter)
{
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
if (HasOutOfOrderScript(script)) return true;
}
if (HasOutOfOrderScript(script)) return true;
}
}

Expand Down
98 changes: 63 additions & 35 deletions Spriggit.CLI.Lib/Commands/Sort/SortStarfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public bool HasWorkToDo(
.WithDataFolder(dataFolder)
.WithFileSystem(_fileSystem)
.Construct();
if (VirtualMachineAdapterHasWorkToDo(mod)) return true;
if (VirtualMachineAdaptersHaveWorkToDo(mod)) return true;
if (RaceMorphGroupHasWorkToDo(mod)) return true;
if (NpcsHaveWorkToDo(mod)) return true;

Expand All @@ -40,8 +40,17 @@ private bool RaceMorphGroupHasWorkToDo(IStarfieldModDisposableGetter mod)
.AsParallel())
{
var charGen = race.ChargenAndSkintones;
if (ChargenHasWorkToDo(charGen?.Male)) return true;
if (ChargenHasWorkToDo(charGen?.Female)) return true;
if (ChargenHasWorkToDo(charGen?.Male))
{
Console.WriteLine($"{race} Male CharGen has sorting to be done.");
return true;
}

if (ChargenHasWorkToDo(charGen?.Female))
{
Console.WriteLine($"{race} Female CharGen has sorting to be done.");
return true;
}
}

return false;
Expand All @@ -54,9 +63,17 @@ private bool NpcsHaveWorkToDo(IStarfieldModDisposableGetter mod)
.AsParallel())
{
var morphGroupNames = npc.FaceMorphs.SelectMany(x => x.MorphGroups).Select(x => x.MorphGroup).ToArray();
if (!morphGroupNames.SequenceEqual(morphGroupNames.OrderBy(x => x))) return true;
if (!morphGroupNames.SequenceEqual(morphGroupNames.OrderBy(x => x)))
{
Console.WriteLine($"{npc} Morph Group Names sorting to be done.");
return true;
}
var morphBlendNames = npc.MorphBlends.Select(x => x.BlendName).ToArray();
if (!morphBlendNames.SequenceEqual(morphBlendNames.OrderBy(x => x))) return true;
if (!morphBlendNames.SequenceEqual(morphBlendNames.OrderBy(x => x)))
{
Console.WriteLine($"{npc} Morph Blend Names sorting to be done.");
return true;
}
}

return false;
Expand All @@ -74,51 +91,62 @@ private bool ChargenHasWorkToDo(IChargenAndSkintonesGetter? charGen)
return false;
}

private bool VirtualMachineAdapterHasWorkToDo(IStarfieldModDisposableGetter mod)
private bool VirtualMachineAdaptersHaveWorkToDo(IStarfieldModDisposableGetter mod)
{
foreach (var hasVM in mod
.EnumerateMajorRecords<IHaveVirtualMachineAdapterGetter>()
.AsParallel())
{
if (hasVM.VirtualMachineAdapter is not {} vm) continue;
foreach (var script in vm.Scripts)
if (VirtualMachineAdapterHasWorkToDo(hasVM))
{
if (HasOutOfOrderScript(script)) return true;
Console.WriteLine($"{hasVM} Virtual Machine Adapter has sorting to be done.");
return true;
}
}

if (vm is IVirtualMachineAdapterIndexedGetter indexedAdapter)
{
if (HasOutOfOrderScript(indexedAdapter.ScriptFragments?.Script)) return true;
}
return false;
}

if (vm is IQuestAdapter questAdapter)
{
if (HasOutOfOrderScript(questAdapter.Script)) return true;
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
if (HasOutOfOrderScript(script)) return true;
}
}
private bool VirtualMachineAdapterHasWorkToDo(IHaveVirtualMachineAdapterGetter hasVM)
{
if (hasVM.VirtualMachineAdapter is not {} vm) return false;
foreach (var script in vm.Scripts)
{
if (HasOutOfOrderScript(script)) return true;
}

if (vm is IPerkAdapterGetter perkAdapter)
{
if (HasOutOfOrderScript(perkAdapter.ScriptFragments?.Script)) return true;
}
if (vm is IVirtualMachineAdapterIndexedGetter indexedAdapter)
{
if (HasOutOfOrderScript(indexedAdapter.ScriptFragments?.Script)) return true;
}

if (vm is IPackageAdapterGetter packageAdapter)
if (vm is IQuestAdapter questAdapter)
{
if (HasOutOfOrderScript(questAdapter.Script)) return true;
foreach (var script in questAdapter.Aliases.SelectMany(x => x.Scripts))
{
if (HasOutOfOrderScript(packageAdapter.ScriptFragments?.Script)) return true;
if (HasOutOfOrderScript(script)) return true;
}
}

if (vm is ISceneAdapterGetter sceneAdapter)
{
if (HasOutOfOrderScript(sceneAdapter.ScriptFragments?.Script)) return true;
}
if (vm is IPerkAdapterGetter perkAdapter)
{
if (HasOutOfOrderScript(perkAdapter.ScriptFragments?.Script)) return true;
}

if (vm is IDialogResponsesAdapterGetter dialAdapter)
{
if (HasOutOfOrderScript(dialAdapter.ScriptFragments?.Script)) return true;
}
if (vm is IPackageAdapterGetter packageAdapter)
{
if (HasOutOfOrderScript(packageAdapter.ScriptFragments?.Script)) return true;
}

if (vm is ISceneAdapterGetter sceneAdapter)
{
if (HasOutOfOrderScript(sceneAdapter.ScriptFragments?.Script)) return true;
}

if (vm is IDialogResponsesAdapterGetter dialAdapter)
{
if (HasOutOfOrderScript(dialAdapter.ScriptFragments?.Script)) return true;
}

return false;
Expand Down

0 comments on commit 00ad56e

Please sign in to comment.