Skip to content

Commit

Permalink
feeder: automatically select simulator unknown (in addition to VPX) w…
Browse files Browse the repository at this point in the history
…hen no simulator was previously selected
  • Loading branch information
stojy committed Sep 9, 2023
1 parent 7d95183 commit b0a5973
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions ClrVpin/Feeder/FeederResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ private void UpdateFilterOptionsBasedOnSelectedFileTypes()

// - enable simulator options and also default first option VPX if none are already selected
var isTableEnabled = Settings.SelectedOnlineFileTypeOptions.Contains(OnlineFileTypeEnum.Tables.GetDescription());
FeatureOptions.UpdateFeatureOptions(isTableEnabled, GameFiltersViewModel.SimulatorOptionsFilterView.ToList(), (int)SimulatorOptionEnum.VirtualPinballX);
FeatureOptions.EnableDisableFeatureOptions(isTableEnabled, GameFiltersViewModel.SimulatorOptionsFilterView.ToList());
if (isTableEnabled)
FeatureOptions.SelectDefaultFeatureTypes(GameFiltersViewModel.SimulatorOptionsFilterView.ToList(), (int)SimulatorOptionEnum.VirtualPinballX, (int)SimulatorOptionEnum.Unknown);

// backglass file - enable features
UpdateMiscFeatureState(new[] { OnlineFileTypeEnum.Backglasses }, MiscFeatureOptionEnum.FullDmd);
Expand All @@ -381,7 +383,7 @@ private void UpdateFilterOptionsBasedOnSelectedFileTypes()
// - automatically standard simulator options and also default first option VPX if none are already selected
var isTableOrBackglassEnabled = Settings.SelectedOnlineFileTypeOptions.ContainsAny(tableAndBackglassFileType.Select(x => x.GetDescription()));
if (isTableOrBackglassEnabled)
FeatureOptions.SelectDefaultFeatureType(GameFiltersViewModel.MiscFeaturesOptionsView.ToList(), (int)MiscFeatureOptionEnum.Standard);
FeatureOptions.SelectDefaultFeatureTypes(GameFiltersViewModel.MiscFeaturesOptionsView.ToList(), (int)MiscFeatureOptionEnum.Standard, (int)MiscFeatureOptionEnum.Standard);

UpdateOnlineGameFileDetails();
}
Expand All @@ -393,7 +395,7 @@ private void UpdateMiscFeatureState(IEnumerable<OnlineFileTypeEnum> onlineFileTy
var miscFeatureOptionItems = GameFiltersViewModel.MiscFeaturesOptionsView.Where(option => miscFeatureOptions.Contains(option.Id));

// update each of the relevant feature options
FeatureOptions.UpdateFeatureOptions(isFileTypeEnabled, miscFeatureOptionItems.ToList());
FeatureOptions.EnableDisableFeatureOptions(isFileTypeEnabled, miscFeatureOptionItems.ToList());
}

private void UpdateOnlineGameFileDetails()
Expand Down
20 changes: 11 additions & 9 deletions ClrVpin/Shared/FeatureType/FeatureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static ListCollectionView<FeatureType> CreateFeatureOptionsMultiSelection
}

// update multiple feature options
public static void UpdateFeatureOptions(bool isEnabled, List<FeatureType> featureTypes, int? defaultFeatureTypeEnum = null)
public static void EnableDisableFeatureOptions(bool isEnabled, List<FeatureType> featureTypes)
{
// enable/disable the features
featureTypes.ForEach(featureType =>
Expand All @@ -117,17 +117,19 @@ public static void UpdateFeatureOptions(bool isEnabled, List<FeatureType> featur
else
DisableFeatureType(featureType);
});

if (defaultFeatureTypeEnum != null)
SelectDefaultFeatureType(featureTypes, defaultFeatureTypeEnum.Value);
}

public static void SelectDefaultFeatureType(List<FeatureType> featureTypes, int defaultFeatureTypeEnum)
public static void SelectDefaultFeatureTypes(List<FeatureType> featureTypes, params int[] defaultFeatureTypeEnums)
{
// if the feature is enabled AND no options are active, then select the default feature type
var featureType = featureTypes.First(feature => feature.Id == defaultFeatureTypeEnum);
if (featureType.IsSupported && !featureTypes.Any(option => option.IsActive))
SelectFeatureType(featureType, true);
// do nothing if a feature type is already selected/active
if (featureTypes.Any(option => option.IsActive))
return;

// select all of the specified default feature types
var defaultFeatureTypes = featureTypes.Where(feature => defaultFeatureTypeEnums.Contains(feature.Id));
defaultFeatureTypes
.Where(defaultFeatureType => defaultFeatureType.IsSupported)
.ForEach(defaultFeatureType => SelectFeatureType(defaultFeatureType, true));
}

public static void DisableFeatureType(FeatureType featureType, string message = null)
Expand Down

0 comments on commit b0a5973

Please sign in to comment.