Skip to content

Commit

Permalink
Initial mix in skipping implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Piranha91 authored and Piranha91 committed Jan 25, 2023
1 parent 6f10039 commit e97ae4a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
1 change: 1 addition & 0 deletions SynthEBD/Classes_Core/Models/NPCAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MixInAssignment
public string AssetPackName { get; set; } = "";
public List<string> SubgroupIDs { get; set; } = new();
public List<AssetReplacerAssignment> AssetReplacerAssignments { get; set; } = new();
public bool DeclinedAssignment { get; set; } = false;
}
}

Expand Down
6 changes: 4 additions & 2 deletions SynthEBD/Classes_Core/ViewModels/VM_ConsistencyAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static VM_ConsistencyAssignment GetViewModelFromModel(NPCAssignment model
{
mixInVM.SubgroupIDs.Add(new VM_CollectionMemberString(id, mixInVM.SubgroupIDs));
}
mixInVM.DeclinedAssignment = mixIn.DeclinedAssignment;
viewModel.MixInAssignments.Add(mixInVM);
}
foreach(var replacer in model.AssetReplacerAssignments)
Expand Down Expand Up @@ -126,6 +127,7 @@ public static VM_ConsistencyAssignment GetViewModelFromModel(NPCAssignment model

viewModel.DispName = model.DispName;
viewModel.NPCFormKey = model.NPCFormKey;

return viewModel;
}

Expand All @@ -138,7 +140,7 @@ public NPCAssignment DumpViewModelToModel()
model.MixInAssignments.Clear();
foreach (var mixInVM in MixInAssignments)
{
model.MixInAssignments.Add(new NPCAssignment.MixInAssignment() { AssetPackName = mixInVM.AssetPackName, SubgroupIDs = mixInVM.SubgroupIDs.Select(x => x.Content).ToList() });
model.MixInAssignments.Add(new NPCAssignment.MixInAssignment() { AssetPackName = mixInVM.AssetPackName, SubgroupIDs = mixInVM.SubgroupIDs.Select(x => x.Content).ToList(), DeclinedAssignment = mixInVM.DeclinedAssignment });
}
model.AssetReplacerAssignments.Clear();
foreach (var replacer in AssetReplacements)
Expand Down Expand Up @@ -188,7 +190,7 @@ public VM_MixInConsistencyAssignment(ObservableCollection<VM_MixInConsistencyAss
public string AssetPackName { get; set; }
public ObservableCollection<VM_CollectionMemberString> SubgroupIDs { get; set; } = new();
public ObservableCollection<VM_MixInConsistencyAssignment> ParentCollection { get; set; }

public bool DeclinedAssignment { get; set; } = false;
public RelayCommand DeleteCommand { get; set; }
}
}
10 changes: 7 additions & 3 deletions SynthEBD/Classes_Core/Views/UC_ConsistencyAssignment.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="SynthEBD.UC_ConsistencyAssignment"
<UserControl x:Class="SynthEBD.UC_ConsistencyAssignment"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -72,7 +72,7 @@
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding AssetPackName}" ToolTip="Name of Mix-In config file assigned to this NPC" ToolTipService.IsEnabled="{Binding Source={x:Static local:TooltipController.Instance}, Path=DisplayToolTips}"/>
<Button Margin="5 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding DeleteCommand}" Foreground="Firebrick">X</Button>
</StackPanel>
</StackPanel>

<!--Subgroup List -->
<TextBlock Text="Subgroups: " ToolTip="Subgroups from the Mix-In config file assigned to this NPC" ToolTipService.IsEnabled="{Binding Source={x:Static local:TooltipController.Instance}, Path=DisplayToolTips}"/>
Expand All @@ -92,7 +92,11 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- End Subgroup List-->
<!-- End Subgroup List-->
<StackPanel Orientation="Horizontal">
<TextBlock Text="Declined" ToolTip="Subgroups from the Mix-In config file assigned to this NPC" ToolTipService.IsEnabled="{Binding Source={x:Static local:TooltipController.Instance}, Path=DisplayToolTips}"/>
<CheckBox IsChecked="{Binding DeclinedAssignment}"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
Expand Down
22 changes: 19 additions & 3 deletions SynthEBD/Patcher/Asset Patching/AssetSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public void RecordAssetConsistencyAndLinkedNPCs(SubgroupCombination assignedComb
}
}

public void RecordAssetConsistencyAndLinkedNPCs(SubgroupCombination assignedCombination, NPCInfo npcInfo, string mixInName) // MixIn
public void RecordAssetConsistencyAndLinkedNPCs(SubgroupCombination assignedCombination, NPCInfo npcInfo, string mixInName, bool declinedViaProbability) // MixIn
{
if (_patcherState.GeneralSettings.bEnableConsistency)
{
Expand All @@ -828,13 +828,29 @@ public void RecordAssetConsistencyAndLinkedNPCs(SubgroupCombination assignedComb
{
var mixInAssignment = new NPCAssignment.MixInAssignment();
mixInAssignment.AssetPackName = mixInName;
mixInAssignment.SubgroupIDs = assignedCombination.ContainedSubgroups.Where(x => x.Id != AssetPack.ConfigDistributionRules.SubgroupIDString).Select(x => x.Id).ToList();
if (declinedViaProbability)
{
mixInAssignment.DeclinedAssignment = true;
}
else
{
mixInAssignment.SubgroupIDs = assignedCombination.ContainedSubgroups.Where(x => x.Id != AssetPack.ConfigDistributionRules.SubgroupIDString).Select(x => x.Id).ToList();
mixInAssignment.DeclinedAssignment = false;
}
npcInfo.ConsistencyNPCAssignment.MixInAssignments.Add(mixInAssignment);
}
else
{
consistencyMixIn.AssetPackName = mixInName;
consistencyMixIn.SubgroupIDs = assignedCombination.ContainedSubgroups.Where(x => x.Id != AssetPack.ConfigDistributionRules.SubgroupIDString).Select(x => x.Id).ToList();
if (declinedViaProbability)
{
consistencyMixIn.DeclinedAssignment = true;
}
else
{
consistencyMixIn.SubgroupIDs = assignedCombination.ContainedSubgroups.Where(x => x.Id != AssetPack.ConfigDistributionRules.SubgroupIDString).Select(x => x.Id).ToList();
consistencyMixIn.DeclinedAssignment = false;
}
}
}
if (npcInfo.LinkGroupMember == NPCInfo.LinkGroupMemberType.Primary && assignedCombination != null)
Expand Down
6 changes: 3 additions & 3 deletions SynthEBD/Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private void MainLoop(
#region Primary Asset assignment
if (_assetsStatsTracker.HasGenderedConfigs[currentNPCInfo.Gender])
{
assignedPrimaryComboAndBodyShape = _assetAndBodyShapeSelector.ChooseCombinationAndBodyShape(out assetsAssigned, out bodyShapeAssigned, primaryAssetPacks, bodyGenConfigs, oBodySettings, currentNPCInfo, blockBodyShape, AssetAndBodyShapeSelector.AssetPackAssignmentMode.Primary, null, assignedCombinations);
assignedPrimaryComboAndBodyShape = _assetAndBodyShapeSelector.ChooseCombinationAndBodyShape(out assetsAssigned, out bodyShapeAssigned, primaryAssetPacks, bodyGenConfigs, oBodySettings, currentNPCInfo, blockBodyShape, AssetAndBodyShapeSelector.AssetPackAssignmentMode.Primary, null, assignedCombinations, out _);
if (assetsAssigned)
{
assignedCombinations.Add(assignedPrimaryComboAndBodyShape.AssignedCombination);
Expand Down Expand Up @@ -520,11 +520,11 @@ private void MainLoop(
var currentMixIn = mixInAssetPacks.Where(x => x.GroupName == item).FirstOrDefault();
if (currentMixIn != null)
{
var assignedMixIn = _assetAndBodyShapeSelector.ChooseCombinationAndBodyShape(out bool mixInAssigned, out _, new HashSet<FlattenedAssetPack>() { currentMixIn }, bodyGenConfigs, oBodySettings, currentNPCInfo, true, AssetAndBodyShapeSelector.AssetPackAssignmentMode.MixIn, assignedPrimaryComboAndBodyShape, assignedCombinations);
var assignedMixIn = _assetAndBodyShapeSelector.ChooseCombinationAndBodyShape(out bool mixInAssigned, out _, new HashSet<FlattenedAssetPack>() { currentMixIn }, bodyGenConfigs, oBodySettings, currentNPCInfo, true, AssetAndBodyShapeSelector.AssetPackAssignmentMode.MixIn, assignedPrimaryComboAndBodyShape, assignedCombinations, out bool mixInDeclined);
if (mixInAssigned)
{
assignedCombinations.Add(assignedMixIn.AssignedCombination);
_assetSelector.RecordAssetConsistencyAndLinkedNPCs(assignedMixIn.AssignedCombination, currentNPCInfo, currentMixIn.GroupName);
_assetSelector.RecordAssetConsistencyAndLinkedNPCs(assignedMixIn.AssignedCombination, currentNPCInfo, currentMixIn.GroupName, mixInDeclined);
assetsAssigned = true;
}
}
Expand Down
30 changes: 24 additions & 6 deletions SynthEBD/Patcher/Shared/AssetAndBodyShapeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public enum AssetPackAssignmentMode
/// <param name="availableAssetPacks">Asset packs available to the current NPC</param>
/// <param name="npcInfo">NPC info class</param>
/// <returns></returns>
public AssetAndBodyShapeAssignment ChooseCombinationAndBodyShape(out bool assetsAssigned, out bool bodyShapeAssigned, HashSet<FlattenedAssetPack> availableAssetPacks, BodyGenConfigs bodyGenConfigs, Settings_OBody oBodySettings, NPCInfo npcInfo, bool blockBodyShape, AssetPackAssignmentMode mode, AssetAndBodyShapeAssignment currentAssignments, List<SubgroupCombination> previousAssignments)
public AssetAndBodyShapeAssignment ChooseCombinationAndBodyShape(out bool assetsAssigned, out bool bodyShapeAssigned, HashSet<FlattenedAssetPack> availableAssetPacks, BodyGenConfigs bodyGenConfigs, Settings_OBody oBodySettings, NPCInfo npcInfo, bool blockBodyShape, AssetPackAssignmentMode mode, AssetAndBodyShapeAssignment currentAssignments, List<SubgroupCombination> previousAssignments, out bool mixInDeclined)
{
AssetAndBodyShapeAssignment assignment = new AssetAndBodyShapeAssignment();
SubgroupCombination chosenCombination = new SubgroupCombination();
assetsAssigned = false;
bodyShapeAssigned = false;
mixInDeclined = false;

string subSectionLabel = string.Empty;
string reportLine = string.Empty;
Expand Down Expand Up @@ -177,13 +178,17 @@ public AssetAndBodyShapeAssignment ChooseCombinationAndBodyShape(out bool assets
if (!selectedFromLinkedNPC)
{
_logger.LogReport("Choosing Asset Combination and BodyGen for " + npcInfo.LogIDstring, false, npcInfo);
chosenCombination = GenerateCombinationWithBodyShape(availableAssetPacks, bodyGenConfigs, oBodySettings, assignment, npcInfo, blockBodyShape, mode, currentAssignments, previousAssignments); // chosenMorphs is populated by reference within ChooseRandomCombination

switch (_patcherState.GeneralSettings.BodySelectionMode)
if (!(mode == AssetPackAssignmentMode.MixIn && availableAssetPacks.Any() && SkipMixInByProbability(availableAssetPacks.First(), npcInfo)))
{
case BodyShapeSelectionMode.BodyGen: bodyShapeAssigned = assignment.AssignedBodyGenMorphs.Any(); break;
case BodyShapeSelectionMode.BodySlide: bodyShapeAssigned = assignment.AssignedOBodyPreset != null; break;
case BodyShapeSelectionMode.None: break;
chosenCombination = GenerateCombinationWithBodyShape(availableAssetPacks, bodyGenConfigs, oBodySettings, assignment, npcInfo, blockBodyShape, mode, currentAssignments, previousAssignments); // chosenMorphs is populated by reference within ChooseRandomCombination

switch (_patcherState.GeneralSettings.BodySelectionMode)
{
case BodyShapeSelectionMode.BodyGen: bodyShapeAssigned = assignment.AssignedBodyGenMorphs.Any(); break;
case BodyShapeSelectionMode.BodySlide: bodyShapeAssigned = assignment.AssignedOBodyPreset != null; break;
case BodyShapeSelectionMode.None: break;
}
}
}

Expand Down Expand Up @@ -387,4 +392,17 @@ public static void ClearStatusFlags(BodyShapeSelectorStatusFlag flags)
flags = ~BodyShapeSelectorStatusFlag.MatchesConsistency;
flags = ~BodyShapeSelectorStatusFlag.ConsistencyMorphIsInvalid;
}

private bool SkipMixInByProbability(FlattenedAssetPack mixInPack, NPCInfo npcInfo)
{
if (!BoolByProbability.Decide(mixInPack.DistributionRules.ProbabilityWeighting))
{
_logger.LogReport("Mix In " + mixInPack.GroupName + " was chosen at random to NOT be assigned.", false, npcInfo);
return true;
}
else
{
return false;
}
}
}

0 comments on commit e97ae4a

Please sign in to comment.