From 96e9170746fb40c2dd6df2e39296a5e9023c2ccd Mon Sep 17 00:00:00 2001 From: Piranha91 Date: Fri, 1 Dec 2023 02:34:33 -0800 Subject: [PATCH] Added "Distribute to non-forced NPCs" toggle to whole-config rules --- .../ViewModels/VM_ConfigDistributionRules.cs | 45 ++++++------ .../Views/UC_ConfigDistributionRules.xaml | 70 ++++++++++--------- SynthEBD/Classes_Core/Models/AssetPack.cs | 2 + .../Classes_Core/ViewModels/VM_AssetPack.cs | 2 +- .../Patcher/Asset Patching/AssetSelector.cs | 12 ++-- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_ConfigDistributionRules.cs b/SynthEBD/Classes_Aux/ViewModels/VM_ConfigDistributionRules.cs index d669c814..086406e6 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_ConfigDistributionRules.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_ConfigDistributionRules.cs @@ -89,6 +89,7 @@ public VM_ConfigDistributionRules(ObservableCollection raceGrou public VM_RaceGroupingCheckboxList DisallowedRaceGroupings { get; set; } public ObservableCollection AllowedAttributes { get; set; } = new(); public ObservableCollection DisallowedAttributes { get; set; } = new(); + public bool DistributionEnabled { get; set; } = true; public bool AllowUnique { get; set; } = true; public bool AllowNonUnique { get; set; } = true; public ObservableCollection AddKeywords { get; set; } = new(); @@ -122,6 +123,7 @@ public void CopyInViewModelFromModel(AssetPack.ConfigDistributionRules model, Ob _attributeCreator.CopyInFromModels(model.AllowedAttributes, AllowedAttributes, parentAssetPack.AttributeGroupMenu.Groups, true, null); _attributeCreator.CopyInFromModels(model.DisallowedAttributes, DisallowedAttributes, parentAssetPack.AttributeGroupMenu.Groups, false, null); foreach (var x in DisallowedAttributes) { x.DisplayForceIfOption = false; } + DistributionEnabled = model.DistributionEnabled; AllowUnique = model.AllowUnique; AllowNonUnique = model.AllowNonUnique; VM_CollectionMemberString.CopyInObservableCollectionFromICollection(model.AddKeywords, AddKeywords); @@ -139,30 +141,31 @@ public void CopyInViewModelFromModel(AssetPack.ConfigDistributionRules model, Ob } } - public static AssetPack.ConfigDistributionRules DumpViewModelToModel(VM_ConfigDistributionRules viewModel) + public AssetPack.ConfigDistributionRules DumpViewModelToModel() { var model = new AssetPack.ConfigDistributionRules(); - model.AllowedRaces = viewModel.AllowedRaces.ToHashSet(); - model.AllowedRaceGroupings = viewModel.AllowedRaceGroupings.RaceGroupingSelections.Where(x => x.IsSelected).Select(x => x.SubscribedMasterRaceGrouping.Label).ToHashSet(); - model.DisallowedRaces = viewModel.DisallowedRaces.ToHashSet(); - model.DisallowedRaceGroupings = viewModel.DisallowedRaceGroupings.RaceGroupingSelections.Where(x => x.IsSelected).Select(x => x.SubscribedMasterRaceGrouping.Label).ToHashSet(); - model.AllowedAttributes = VM_NPCAttribute.DumpViewModelsToModels(viewModel.AllowedAttributes); - model.DisallowedAttributes = VM_NPCAttribute.DumpViewModelsToModels(viewModel.DisallowedAttributes); - model.AllowUnique = viewModel.AllowUnique; - model.AllowNonUnique = viewModel.AllowNonUnique; - model.AddKeywords = viewModel.AddKeywords.Select(x => x.Content).ToHashSet(); - model.ProbabilityWeighting = viewModel.ProbabilityWeighting; - model.WeightRange = viewModel.WeightRange; - - model.AllowedBodyGenDescriptors = viewModel.AllowedBodyGenDescriptors?.DumpToHashSet() ?? null; - model.AllowedBodyGenMatchMode = viewModel.AllowedBodyGenDescriptors?.MatchMode ?? DescriptorMatchMode.All; - model.DisallowedBodyGenDescriptors = viewModel.DisallowedBodyGenDescriptors?.DumpToHashSet() ?? null; - model.DisallowedBodyGenMatchMode = viewModel.DisallowedBodyGenDescriptors?.MatchMode ?? DescriptorMatchMode.Any; - model.AllowedBodySlideDescriptors = viewModel.AllowedBodySlideDescriptors.DumpToHashSet(); - model.AllowedBodySlideMatchMode = viewModel.AllowedBodySlideDescriptors.MatchMode; - model.DisallowedBodySlideDescriptors = viewModel.DisallowedBodySlideDescriptors.DumpToHashSet(); - model.DisallowedBodySlideMatchMode = viewModel.DisallowedBodySlideDescriptors.MatchMode; + model.AllowedRaces = AllowedRaces.ToHashSet(); + model.AllowedRaceGroupings = AllowedRaceGroupings.RaceGroupingSelections.Where(x => x.IsSelected).Select(x => x.SubscribedMasterRaceGrouping.Label).ToHashSet(); + model.DisallowedRaces = DisallowedRaces.ToHashSet(); + model.DisallowedRaceGroupings = DisallowedRaceGroupings.RaceGroupingSelections.Where(x => x.IsSelected).Select(x => x.SubscribedMasterRaceGrouping.Label).ToHashSet(); + model.AllowedAttributes = VM_NPCAttribute.DumpViewModelsToModels(AllowedAttributes); + model.DisallowedAttributes = VM_NPCAttribute.DumpViewModelsToModels(DisallowedAttributes); + model.DistributionEnabled = DistributionEnabled; + model.AllowUnique = AllowUnique; + model.AllowNonUnique = AllowNonUnique; + model.AddKeywords = AddKeywords.Select(x => x.Content).ToHashSet(); + model.ProbabilityWeighting = ProbabilityWeighting; + model.WeightRange = WeightRange; + + model.AllowedBodyGenDescriptors = AllowedBodyGenDescriptors?.DumpToHashSet() ?? new(); + model.AllowedBodyGenMatchMode = AllowedBodyGenDescriptors?.MatchMode ?? DescriptorMatchMode.All; + model.DisallowedBodyGenDescriptors = DisallowedBodyGenDescriptors?.DumpToHashSet() ?? new(); + model.DisallowedBodyGenMatchMode = DisallowedBodyGenDescriptors?.MatchMode ?? DescriptorMatchMode.Any; + model.AllowedBodySlideDescriptors = AllowedBodySlideDescriptors.DumpToHashSet(); + model.AllowedBodySlideMatchMode = AllowedBodySlideDescriptors.MatchMode; + model.DisallowedBodySlideDescriptors = DisallowedBodySlideDescriptors.DumpToHashSet(); + model.DisallowedBodySlideMatchMode = DisallowedBodySlideDescriptors.MatchMode; return model; } diff --git a/SynthEBD/Classes_Aux/Views/UC_ConfigDistributionRules.xaml b/SynthEBD/Classes_Aux/Views/UC_ConfigDistributionRules.xaml index c432f263..bdd8f4a8 100644 --- a/SynthEBD/Classes_Aux/Views/UC_ConfigDistributionRules.xaml +++ b/SynthEBD/Classes_Aux/Views/UC_ConfigDistributionRules.xaml @@ -36,25 +36,29 @@ + - Allow Unique NPCs - + Distribute to non-forced NPCs + + + Allow Unique NPCs + - Allow Non-Unique NPCs - + Allow Non-Unique NPCs + - - + + - Allowed Races - + Allowed Races + - Allowed Race Groupings - + Allowed Race Groupings + @@ -62,11 +66,11 @@ - Disallowed Races - + Disallowed Races + - Disallowed Race Groupings - + Disallowed Race Groupings + @@ -74,10 +78,10 @@ - Allowed NPC Attributes - + Allowed NPC Attributes + - + @@ -85,9 +89,9 @@ - Disallowed NPC Attributes - - + Disallowed NPC Attributes + + @@ -95,16 +99,16 @@ - Allowed NPC Weight Range - + Allowed NPC Weight Range + - Add Keywords to NPC - - + Add Keywords to NPC + + @@ -116,18 +120,18 @@ - Allowed BodyGen Descriptors - + Allowed BodyGen Descriptors + - Disallowed BodyGen Descriptors - + Disallowed BodyGen Descriptors + - Allowed BodySlide Descriptors - + Allowed BodySlide Descriptors + - Disallowed BodySlide Descriptors - + Disallowed BodySlide Descriptors + diff --git a/SynthEBD/Classes_Core/Models/AssetPack.cs b/SynthEBD/Classes_Core/Models/AssetPack.cs index 00fab091..431841ea 100644 --- a/SynthEBD/Classes_Core/Models/AssetPack.cs +++ b/SynthEBD/Classes_Core/Models/AssetPack.cs @@ -43,6 +43,7 @@ public class ConfigDistributionRules : IProbabilityWeighted public HashSet DisallowedRaceGroupings { get; set; } = new(); public HashSet AllowedAttributes { get; set; } = new(); public HashSet DisallowedAttributes { get; set; } = new(); + public bool DistributionEnabled { get; set; } = true; public bool AllowUnique { get; set; } = true; public bool AllowNonUnique { get; set; } = true; public HashSet AddKeywords { get; set; } = new(); @@ -71,6 +72,7 @@ public static AssetPack.Subgroup CreateInheritanceParent(ConfigDistributionRules subgroup.DisallowedRaceGroupings = new HashSet(rules.DisallowedRaceGroupings ?? new()); subgroup.AllowedAttributes = new HashSet(rules.AllowedAttributes ?? new()); subgroup.DisallowedAttributes = new HashSet(rules.DisallowedAttributes ?? new()); + subgroup.DistributionEnabled = rules.DistributionEnabled; subgroup.AllowUnique = rules.AllowUnique; subgroup.AllowNonUnique = rules.AllowNonUnique; subgroup.AddKeywords = new HashSet(rules.AddKeywords ?? new()); diff --git a/SynthEBD/Classes_Core/ViewModels/VM_AssetPack.cs b/SynthEBD/Classes_Core/ViewModels/VM_AssetPack.cs index fa573f06..47c6aeec 100644 --- a/SynthEBD/Classes_Core/ViewModels/VM_AssetPack.cs +++ b/SynthEBD/Classes_Core/ViewModels/VM_AssetPack.cs @@ -585,7 +585,7 @@ public AssetPack DumpViewModelToModel() model.ReplacerGroups = VM_AssetPackDirectReplacerMenu.DumpViewModelToModels(ReplacersMenu); - model.DistributionRules = VM_ConfigDistributionRules.DumpViewModelToModel(DistributionRules); + model.DistributionRules = DistributionRules.DumpViewModelToModel(); model.InstallationToken = InstallationToken; model.FilePath = SourcePath; diff --git a/SynthEBD/Patcher/Asset Patching/AssetSelector.cs b/SynthEBD/Patcher/Asset Patching/AssetSelector.cs index 88e9598f..57843b66 100644 --- a/SynthEBD/Patcher/Asset Patching/AssetSelector.cs +++ b/SynthEBD/Patcher/Asset Patching/AssetSelector.cs @@ -601,7 +601,7 @@ public HashSet FilterValidConfigsForNPC(HashSet FilterValidConfigsForNPC(HashSet FilterValidConfigsForNPC(HashSet /// The number of ForceIf attributes within this subgroup that were matched by the current NPC /// - private bool SubgroupValidForCurrentNPC(FlattenedSubgroup subgroup, NPCInfo npcInfo, AssetPackAssignmentMode mode, List assignedBodyGen, List assignedBodySlides) + private bool SubgroupValidForCurrentNPC(FlattenedSubgroup subgroup, NPCInfo npcInfo, AssetPackAssignmentMode mode, List assignedBodyGen, List assignedBodySlides, string reportStringType) { - var reportString = "Subgroup " + subgroup.GetDetailedID_NameString(false); + var reportString = reportStringType + " " + subgroup.GetDetailedID_NameString(false) + " "; if (npcInfo.SpecificNPCAssignment != null && npcInfo.SpecificNPCAssignment.SubgroupIDs.Contains(subgroup.Id)) { _logger.LogReport(reportString + "is valid because it is specifically assigned by user.", false, npcInfo); @@ -1004,7 +1004,7 @@ private bool SubgroupValidForCurrentNPC(FlattenedSubgroup subgroup, NPCInfo npcI // Distribution Enabled if (subgroup.ForceIfMatchCount == 0 && !subgroup.DistributionEnabled) { - _logger.LogReport(reportString + "is invalid because its distribution is disabled to random NPCs, it is not a Specific NPC Assignment, and the NPC does not match and of its ForceIf attributes.", false, npcInfo); + _logger.LogReport(reportString + "is invalid because its distribution is disabled to random NPCs, it is not a Specific NPC Assignment, and the NPC does not match any of its ForceIf attributes.", false, npcInfo); return false; }