Load stock data on stock change or char upload

Extracts the loading logic to a common method returning a promise,
both places 'then' the promise.
pull/8/head
Daniel Asher Resnick 2 years ago
parent 30f477a2e0
commit c8adc19846
  1. 5
      src/public/js/burning-serialize.js
  2. 24
      src/public/js/burning.js

@ -2,7 +2,7 @@ function loadCurrentCharacterFromStruct($scope, charStruct, burningData, appropr
$scope.name = charStruct.name; $scope.name = charStruct.name;
$scope.gender = charStruct.gender; $scope.gender = charStruct.gender;
$scope.stock = charStruct.stock; $scope.stock = charStruct.stock;
$scope.ensureStockLoaded($scope.stock).then(() => {
// Appropriate weapons must be loaded before calculateLifepathSkills is called. // Appropriate weapons must be loaded before calculateLifepathSkills is called.
if(serverSettings.storageType != 'server'){ if(serverSettings.storageType != 'server'){
appropriateWeapons.appropriateWeapons = charStruct.approp_weapons; appropriateWeapons.appropriateWeapons = charStruct.approp_weapons;
@ -173,7 +173,8 @@ function loadCurrentCharacterFromStruct($scope, charStruct, burningData, appropr
$scope.attributeModifierQuestionResults = loadAttributeModifierQuestionResultsFromSave($scope, charStruct.attr_mod_questions); $scope.attributeModifierQuestionResults = loadAttributeModifierQuestionResultsFromSave($scope, charStruct.attr_mod_questions);
$scope.brutalLifeWithdrawn = charStruct.brutal_life_withdrawn; $scope.brutalLifeWithdrawn = charStruct.brutal_life_withdrawn;
$scope.$digest();
});
} }
function convertCurrentCharacterToStruct($scope, appropriateWeapons) { function convertCurrentCharacterToStruct($scope, appropriateWeapons) {

@ -364,14 +364,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
$scope.stockSelected = true; $scope.stockSelected = true;
} }
let loadPromises = []; $scope.ensureStockLoaded($scope.stock).then(() => {
if(!burningData.resources[$scope.stock]) {
loadPromises.push(burningData.loadResourcesForStock($scope.stock));
}
if(!burningData.lifepaths[$scope.stock]) {
loadPromises.push(burningData.loadLifepathsForStock($scope.stock));
}
Promise.all(loadPromises).then(() => {
var oldName = $scope.name; var oldName = $scope.name;
// Make a blank character sheet // Make a blank character sheet
$scope.initialize($scope.stock); $scope.initialize($scope.stock);
@ -386,9 +379,21 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateSpecialTraitsForDisplay($scope, burningData); calculateSpecialTraitsForDisplay($scope, burningData);
calculateGearSelectionLists($scope, burningData); calculateGearSelectionLists($scope, burningData);
calculatePropertySelectionLists($scope, burningData); calculatePropertySelectionLists($scope, burningData);
$scope.$digest();
}); });
} }
$scope.ensureStockLoaded = function(stock) {
let loadPromises = [];
if(!burningData.lifepaths[stock]) {
loadPromises.push(burningData.loadLifepathsForStock(stock));
}
if(!burningData.resources[stock]) {
loadPromises.push(burningData.loadResourcesForStock(stock));
}
return Promise.all(loadPromises);
};
$scope.onSettingChange = function(){ $scope.onSettingChange = function(){
calculateCurrentSettingLifepathNames($scope, burningData); calculateCurrentSettingLifepathNames($scope, burningData);
@ -413,8 +418,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
} }
burningData.whenStocksLoaded.then(() => { burningData.whenStocksLoaded.then(() => {
$scope.stocks = [{ name: "Select a stock" }]; $scope.stocks = [{ name: "Select a stock" }, ...Object.values(burningData.stocks)];
$scope.stocks = $scope.stocks.concat(Object.values(burningData.stocks));
$scope.stockSelected = false; $scope.stockSelected = false;
$scope.$digest(); $scope.$digest();
}); });

Loading…
Cancel
Save