Begin moving stock data to objects

pull/8/head
Daniel Asher Resnick 2 years ago
parent 988312d9c4
commit 43cca46dde
  1. 4
      src/app.rb
  2. 2
      src/lib/data.rb
  3. 22
      src/lib/stock.rb
  4. 20
      src/public/js/burning-service.js

@ -49,6 +49,10 @@ get '/traits' do
json DATA[:traits] json DATA[:traits]
end end
get '/stock_objs' do
json DATA[:stock_objs]
end
get '/lifepaths/:stock' do get '/lifepaths/:stock' do
if DATA[:stocks].include? params['stock'] if DATA[:stocks].include? params['stock']
json DATA[:lifepaths][params['stock']] json DATA[:lifepaths][params['stock']]

@ -2,6 +2,7 @@ require_relative 'data/gold'
require_relative 'data/wizard' require_relative 'data/wizard'
require_relative 'data/dark_elf' require_relative 'data/dark_elf'
require_relative 'data/troll' require_relative 'data/troll'
require_relative 'stock'
module Charred module Charred
class Data class Data
@ -29,6 +30,7 @@ module Charred
@data[:traits] = @data[:traits].sort.to_h @data[:traits] = @data[:traits].sort.to_h
@data[:skills] = @data[:skills].sort.to_h @data[:skills] = @data[:skills].sort.to_h
@data[:stock_objs] = @data[:stocks].map { |s| Stock.new s, s }
end end
def verbose_merge(to, from) def verbose_merge(to, from)

@ -0,0 +1,22 @@
module Charred
# module Stock
class Stock
attr :key
attr :name
def initialize(key, name)
@key = key
@name = name
end
def as_json(options = {})
{
"key" => key,
"name" => name
}
end
def to_json(*a)
as_json.to_json(*a)
end
# end
end
end

@ -290,7 +290,20 @@ function BurningDataService($http) {
} }
} }
var stocks = ["man", "dwarf", "elf", "orc", "roden", "wolf", "troll"]; var stocks;
$http.get("/stock_objs", {'timeout': 3000}).
success(function(data,status,headers,config){
stocks = data.map(s => s.key);
for (var i = 0; i < stocks.length; i++) {
loadLifepathsForStock(stocks[i]);
loadStartingStatPtsForStock(stocks[i]);
loadResourcesForStock(stocks[i]);
}
console.log("Stocks fetched from server: " + stocks)
}).
error(function(data,status,headers,config){
console.log("Error: Getting stocks from server failed: HTTP code " + status + ": " + data);
});
var myself = this; var myself = this;
/* Load lifepaths from server */ /* Load lifepaths from server */
@ -350,11 +363,6 @@ function BurningDataService($http) {
}); });
} }
for (var i = 0; i < stocks.length; i++) {
loadLifepathsForStock(stocks[i]);
loadStartingStatPtsForStock(stocks[i]);
loadResourcesForStock(stocks[i]);
}
/* Load skills from server */ /* Load skills from server */
$http.get("/skills", {'timeout': 3000} ). $http.get("/skills", {'timeout': 3000} ).

Loading…
Cancel
Save