Lookup stocks by adjective field

Don't use a hardcoded list of values in the source...
pull/8/head
Daniel Asher Resnick 2 years ago
parent bb908d9bfd
commit 74ed09d830
  1. 14
      src/public/js/burning-service.js
  2. 69
      src/public/js/burning.js

@ -301,7 +301,6 @@ function BurningDataService($http) {
var myself = this; var myself = this;
var stocks;
// Log events // Log events
this.registerEvent("stocksLoaded", function() { this.registerEvent("stocksLoaded", function() {
@ -325,8 +324,7 @@ function BurningDataService($http) {
// DEBUG: // DEBUG:
// console.log(data); // console.log(data);
myself.stocks = data; myself.stocks = data;
stocks = Object.keys(data); for (var stock of Object.keys(data)) {
for (var stock of stocks) {
myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats); myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats);
myself.defineStockEvent(stock, "lifepathsLoaded"); myself.defineStockEvent(stock, "lifepathsLoaded");
myself.defineStockEvent(stock, "resourcesLoaded"); myself.defineStockEvent(stock, "resourcesLoaded");
@ -339,11 +337,6 @@ function BurningDataService($http) {
/* Load lifepaths from server */ /* Load lifepaths from server */
this.loadLifepathsForStock = function(stock){ this.loadLifepathsForStock = function(stock){
if( ! isValidStock(stock) ){
console.log("Loading lifepaths failed: asked to load lifepaths for invalid stock " + stock);
return
}
$http.get("/lifepaths/" + stock, {'timeout': 3000} ). $http.get("/lifepaths/" + stock, {'timeout': 3000} ).
success(function(data,status,headers,config){ success(function(data,status,headers,config){
myself.lifepaths[stock] = data; myself.lifepaths[stock] = data;
@ -357,11 +350,6 @@ function BurningDataService($http) {
/* Load resources from server */ /* Load resources from server */
this.loadResourcesForStock = function(stock){ this.loadResourcesForStock = function(stock){
if( ! isValidStock(stock) ){
console.log("Loading resources failed: asked to load for invalid stock " + stock);
return
}
$http.get("/resources/" + stock, {'timeout': 3000} ). $http.get("/resources/" + stock, {'timeout': 3000} ).
success(function(data,status,headers,config){ success(function(data,status,headers,config){
myself.resources[stock] = data; myself.resources[stock] = data;

@ -409,7 +409,6 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
calculateUnspentSkillPoints($scope); calculateUnspentSkillPoints($scope);
} }
burningData.registerEvent("stocksLoaded", function() { burningData.registerEvent("stocksLoaded", function() {
$scope.stocks = [{ name: "Select a stock" }] $scope.stocks = [{ name: "Select a stock" }]
$scope.stocks = $scope.stocks.concat(Object.values(burningData.stocks)); $scope.stocks = $scope.stocks.concat(Object.values(burningData.stocks));
@ -938,7 +937,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
for(var key in burningData.skills){ for(var key in burningData.skills){
if ( !(key in $scope.lifepathSkills) && !(key in $scope.generalSkills) ){ if ( !(key in $scope.lifepathSkills) && !(key in $scope.generalSkills) ){
var displaySkill = burningData.skills[key]; var displaySkill = burningData.skills[key];
if ( !displaySkill.stock || restrictionStockToValidStock(displaySkill.stock) == $scope.stock ) { if ( !displaySkill.stock || restrictionStockToValidStock(burningData.stocks, displaySkill.stock) == $scope.stock ) {
result.push(key); result.push(key);
} }
} }
@ -1187,30 +1186,6 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
return list; return list;
} }
/*
$scope.specialTraitsForDisplay = function(){
var list = [];
for(var traitName in burningData.traits) {
var trait = burningData.traits[traitName];
if ('restrict' in trait){
if ( trait.restrict.indexOf(validStockToRestrictionStock($scope.stock)) >= 0 &&
(trait.restrict.indexOf("special") >= 0 || trait.restrict.indexOf("character") >= 0) ){
list.push(new DisplayTrait(traitName, burningData.traits));
}
} else {
// No restriction! As long as cost > 0 (cost 0 is for traits with no cost; not purchaseable)
if ( trait.cost > 0 ) {
list.push(new DisplayTrait(traitName, burningData.traits));
}
}
}
return list;
}
*/
$scope.addLifepathTrait = function(traitName){ $scope.addLifepathTrait = function(traitName){
if ( $scope.unspentTraitPoints < 1 && $scope.enforcePointLimits ) if ( $scope.unspentTraitPoints < 1 && $scope.enforcePointLimits )
@ -2758,7 +2733,7 @@ function calculateSpecialTraitsForDisplay($scope, burningData){
var trait = burningData.traits[traitName]; var trait = burningData.traits[traitName];
if ('restrict' in trait){ if ('restrict' in trait){
if ( trait.restrict.indexOf(validStockToRestrictionStock($scope.stock)) >= 0 && if ( trait.restrict.indexOf(validStockToRestrictionStock(burningData.stocks, $scope.stock)) >= 0 &&
(trait.restrict.indexOf("special") >= 0 || trait.restrict.indexOf("character") >= 0) ){ (trait.restrict.indexOf("special") >= 0 || trait.restrict.indexOf("character") >= 0) ){
list.push(new DisplayTrait(traitName, burningData.traits)); list.push(new DisplayTrait(traitName, burningData.traits));
} }
@ -2806,44 +2781,12 @@ function calculateUnspentResourcePoints($scope){
$scope.unspentResourcePoints = unspentResourcePoints; $scope.unspentResourcePoints = unspentResourcePoints;
} }
function isValidStock(stock){ function restrictionStockToValidStock(stocks, stockAdjective){
return stock == "man" || stock == "elf" || stock == "orc" || stock == "dwarf" || stock == "roden" || stock == "wolf" || stock =="troll"; return Object.values(stocks).findLast(s => s.adjective == stockAdjective).key;
}
function restrictionStockToValidStock(stock){
if ( stock == "mannish" )
return "man";
else if ( stock == "elven" )
return "elf";
else if ( stock == "orcish" )
return "orc";
else if ( stock == "dwarven" )
return "dwarf";
else if ( stock == "wolfish" )
return "wolf";
else if ( stock == "roden" )
return "roden";
else if ( stock == "trollish" )
return "troll";
} }
function validStockToRestrictionStock(stock){ function validStockToRestrictionStock(stocks, stockName){
return stocks[stockName].adjective;
if ( stock == "man" )
return "mannish";
else if ( stock == "elf" )
return "elven";
else if ( stock == "orc" )
return "orcish";
else if ( stock == "dwarf" )
return "dwarven";
else if ( stock == "roden" )
return "roden";
else if ( stock == "wolf" )
return "wolfish";
else if ( stock == "troll" )
return "trollish";
} }
function attributeModifyingQuestions($scope, attribute) function attributeModifyingQuestions($scope, attribute)

Loading…
Cancel
Save