From 63a8e05401507e7bf13a790bccab731eb9007177 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Fri, 10 Mar 2023 23:33:40 -0600 Subject: [PATCH] Check subsetting based on new born property Also cleans up a lot of filtering logic --- src/public/js/burning.js | 56 +++++++++++----------------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/src/public/js/burning.js b/src/public/js/burning.js index a9dda43..8d32214 100644 --- a/src/public/js/burning.js +++ b/src/public/js/burning.js @@ -1937,56 +1937,30 @@ function calculateAge($scope){ $scope.age = age; } +function isSubsetting(setting) { return !Object.values(setting).some((lp) => lp.born); } + function calculateSettingNames($scope, burningData){ - var settingNames = null; + let stockSettings = burningData.lifepaths[$scope.stock]; + $scope.settingNames = Object.keys(stockSettings); var lastCurrentSetting = $scope.currentSetting; - if ( ! $scope.enforceLifepathReqts ) { - // Display all settings and subsettings - settingNames = []; - for(key in burningData.lifepaths[$scope.stock]){ - settingNames.push(key); - } - } - else if ( $scope.selectedLifepaths.length == 0 ){ - // All settings are allowed. Subsettings have no Born lifepath so don't include them. - settingNames = []; - for(key in burningData.lifepaths[$scope.stock]){ - if( key.toLowerCase().indexOf("subsetting") < 0 ){ - settingNames.push(key); - } + if ($scope.enforceLifepathReqts){ + if ( $scope.selectedLifepaths.length == 0 ){ + // All settings are allowed. Subsettings have no Born lifepath so don't include them. + $scope.settingNames = $scope.settingNames.filter(s => !isSubsetting(stockSettings[s])); } - } - else { - // Only settings that are leads from the last lifepath are allowed - var lastLifepath = $scope.selectedLifepaths[$scope.selectedLifepaths.length-1]; - settingNames = []; - var all = Object.keys(burningData.lifepaths[$scope.stock]); - for(var i = 0; i < all.length; i++){ - //console.log("calculateSettingNames: checking if '"+all[i]+"' is allowed"); - var setting = all[i]; - - if ( lastLifepath.setting == setting ){ - settingNames.push(setting); - continue; - } - - if ( lastLifepath.leads ){ - for(var j = 0; j < lastLifepath.keyLeads.length; j++){ - var lead = lastLifepath.keyLeads[j]; - //console.log("calculateSettingNames: checking lead: '"+lead+"' is allowed"); + else { + // Only settings that are leads from the last lifepath are allowed + var lastLifepath = $scope.selectedLifepaths[$scope.selectedLifepaths.length-1]; - if( setting == lead ){ - settingNames.push(setting); - } - } - } + // Doing this filtering instead of something like [lastLifepath.setting, ...lastLifepath.leads] + // accomplishes two things: only presents settings present in this server and maintains relative order. + $scope.settingNames = $scope.settingNames.filter(s => s == lastLifepath.setting + || (lastLifepath.leads && lastLifepath.leads.includes(s))); } } - $scope.settingNames = settingNames; - var currentSettingNeedsUpdate = true; for(var i = 0; i < $scope.settingNames.length; i++){ if( $scope.settingNames[i] == lastCurrentSetting){