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. 56
      src/public/js/burning.js

@ -1937,56 +1937,30 @@ 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 = []; // All settings are allowed. Subsettings have no Born lifepath so don't include them.
for(key in burningData.lifepaths[$scope.stock]){ $scope.settingNames = $scope.settingNames.filter(s => !isSubsetting(stockSettings[s]));
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);
}
} }
} 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 ){
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");
if( setting == lead ){ // 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.
} $scope.settingNames = $scope.settingNames.filter(s => s == lastLifepath.setting
} || (lastLifepath.leads && lastLifepath.leads.includes(s)));
}
} }
} }
$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++){
if( $scope.settingNames[i] == lastCurrentSetting){ if( $scope.settingNames[i] == lastCurrentSetting){

Loading…
Cancel
Save