Check subsetting based on new born property

Also cleans up a lot of filtering logic
pull/11/head
Daniel Asher Resnick 2 years ago
parent e9361b625b
commit 63a8e05401
  1. 48
      src/public/js/burning.js

@ -1937,55 +1937,29 @@ function calculateAge($scope){
$scope.age = age; $scope.age = age;
} }
function isSubsetting(setting) { return !Object.values(setting).some((lp) => lp.born); }
function calculateSettingNames($scope, burningData){ function calculateSettingNames($scope, burningData){
var settingNames = null; let stockSettings = burningData.lifepaths[$scope.stock];
$scope.settingNames = Object.keys(stockSettings);
var lastCurrentSetting = $scope.currentSetting; var lastCurrentSetting = $scope.currentSetting;
if ( ! $scope.enforceLifepathReqts ) { if ($scope.enforceLifepathReqts){
// Display all settings and subsettings if ( $scope.selectedLifepaths.length == 0 ){
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. // All settings are allowed. Subsettings have no Born lifepath so don't include them.
settingNames = []; $scope.settingNames = $scope.settingNames.filter(s => !isSubsetting(stockSettings[s]));
for(key in burningData.lifepaths[$scope.stock]){
if( key.toLowerCase().indexOf("subsetting") < 0 ){
settingNames.push(key);
}
}
} }
else { else {
// Only settings that are leads from the last lifepath are allowed // Only settings that are leads from the last lifepath are allowed
var lastLifepath = $scope.selectedLifepaths[$scope.selectedLifepaths.length-1]; 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 ){ // Doing this filtering instead of something like [lastLifepath.setting, ...lastLifepath.leads]
settingNames.push(setting); // accomplishes two things: only presents settings present in this server and maintains relative order.
continue; $scope.settingNames = $scope.settingNames.filter(s => s == lastLifepath.setting
} || (lastLifepath.leads && lastLifepath.leads.includes(s)));
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");
if( setting == lead ){
settingNames.push(setting);
} }
} }
}
}
}
$scope.settingNames = settingNames;
var currentSettingNeedsUpdate = true; var currentSettingNeedsUpdate = true;
for(var i = 0; i < $scope.settingNames.length; i++){ for(var i = 0; i < $scope.settingNames.length; i++){

Loading…
Cancel
Save