Replace references to stock_objs with just stocks

The stock object is now the universal interface to stock metadata.
pull/8/head
Daniel Asher Resnick 2 years ago
parent 897b9ca58c
commit 302f758bf0
  1. 10
      src/app.rb
  2. 2
      src/lib/data.rb
  3. 10
      src/lib/data/gold.rb
  4. 2
      src/lib/data/troll.rb
  5. 6
      src/public/js/burning-service.js
  6. 4
      src/public/js/burning.js

@ -49,12 +49,12 @@ get '/traits' do
json DATA[:traits] json DATA[:traits]
end end
get '/stock_objs' do get '/stocks' do
json DATA[:stock_objs] json DATA[:stocks]
end end
get '/lifepaths/:stock' do get '/lifepaths/:stock' do
if DATA[:stock_objs].keys.include? params['stock'] if DATA[:stocks].keys.include? params['stock']
json DATA[:lifepaths][params['stock']] json DATA[:lifepaths][params['stock']]
else else
404 404
@ -62,7 +62,7 @@ get '/lifepaths/:stock' do
end end
get '/starting_stat_pts/:stock' do get '/starting_stat_pts/:stock' do
if DATA[:stock_objs].keys.include? params['stock'] if DATA[:stocks].keys.include? params['stock']
json DATA[:stat_pts][params['stock']] json DATA[:stat_pts][params['stock']]
else else
404 404
@ -70,7 +70,7 @@ get '/starting_stat_pts/:stock' do
end end
get '/resources/:stock' do get '/resources/:stock' do
if DATA[:stock_objs].keys.include? params['stock'] if DATA[:stocks].keys.include? params['stock']
json DATA[:resources][params['stock']] json DATA[:resources][params['stock']]
else else
404 404

@ -15,7 +15,7 @@ module Charred
def initialize def initialize
@data = {} @data = {}
@data[:stock_objs] = {} @data[:stocks] = {}
puts 'loading gold' puts 'loading gold'
load_gold(@data) load_gold(@data)

@ -13,11 +13,11 @@ module Charred
lifepaths = {} lifepaths = {}
resources = {} resources = {}
stat_pts = {} stat_pts = {}
stock_objs = {} stocks = {}
stocks = ['dwarf', 'elf', 'man', 'orc', 'roden', 'wolf'] gold_stocks = ['dwarf', 'elf', 'man', 'orc', 'roden', 'wolf']
stocks.each do |stock| gold_stocks.each do |stock|
file = File.read("data/gold/lifepaths/#{stock}.json") file = File.read("data/gold/lifepaths/#{stock}.json")
lifepaths[stock] = JSON.parse(file) lifepaths[stock] = JSON.parse(file)
@ -25,7 +25,7 @@ module Charred
resources[stock] = JSON.parse(file) resources[stock] = JSON.parse(file)
file = File.read("data/gold/stocks/#{stock}.json") file = File.read("data/gold/stocks/#{stock}.json")
stock_objs[stock] = Stock.new(JSON.parse(file)) stocks[stock] = Stock.new(JSON.parse(file))
end end
data.merge!({ data.merge!({
@ -34,7 +34,7 @@ module Charred
:lifepaths => lifepaths, :lifepaths => lifepaths,
:resources => resources, :resources => resources,
:stat_pts => stat_pts, :stat_pts => stat_pts,
:stock_objs => stock_objs :stocks => stocks
}) })
end end
end end

@ -22,7 +22,7 @@ module Charred
file = File.read("data/troll/stock.json") file = File.read("data/troll/stock.json")
stock = JSON.parse(file) stock = JSON.parse(file)
data[:stock_objs]['troll'] = Stock.new(stock) data[:stocks]['troll'] = Stock.new(stock)
end end
end end
end end

@ -292,10 +292,10 @@ function BurningDataService($http) {
var myself = this; var myself = this;
var stocks; var stocks;
$http.get("/stock_objs", {'timeout': 3000}). $http.get("/stocks", {'timeout': 3000}).
success(function(data,status,headers,config){ success(function(data,status,headers,config){
console.log(data); console.log(data);
myself.stock_objs = data; myself.stocks = data;
stocks = Object.keys(data); stocks = Object.keys(data);
for (var i = 0; i < stocks.length; i++) { for (var i = 0; i < stocks.length; i++) {
loadLifepathsForStock(stocks[i]); loadLifepathsForStock(stocks[i]);
@ -334,7 +334,7 @@ function BurningDataService($http) {
console.log("Loading starting stat points failed: asked to load pts for invalid stock " + stock); console.log("Loading starting stat points failed: asked to load pts for invalid stock " + stock);
return return
} }
myself.startingStatPts[stock] = new StartingStatPoints(myself.stock_objs[stock].starting_stats); myself.startingStatPts[stock] = new StartingStatPoints(myself.stocks[stock].starting_stats);
} }
/* Load resources from server */ /* Load resources from server */

@ -1024,7 +1024,7 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
return {"shade" : "", "exp" : 10 - $scope.statsByName["Will"].exp() + bonus}; return {"shade" : "", "exp" : 10 - $scope.statsByName["Will"].exp() + bonus};
} }
else if ( "Stride" == name ){ else if ( "Stride" == name ){
var stride = burningData.stock_objs[$scope.stock].stride; var stride = burningData.stocks[$scope.stock].stride;
stride += bonus; stride += bonus;
return {"shade" : "", "exp" : stride}; return {"shade" : "", "exp" : stride};
} }
@ -2316,7 +2316,7 @@ function setCommonTraits($scope, burningData){
if( $scope.selectedLifepaths.length == 0 ) if( $scope.selectedLifepaths.length == 0 )
return; return;
var common = burningData.stock_objs[$scope.stock].common_traits; var common = burningData.stocks[$scope.stock].common_traits;
if(common.length > 0){ if(common.length > 0){
for(var j = 0; j < common.length; j++){ for(var j = 0; j < common.length; j++){
var name = common[j]; var name = common[j];

Loading…
Cancel
Save