From 0e321daa9f3066993e8b8bd943ef785cc1c577f4 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Sun, 25 Dec 2022 13:16:38 -0600 Subject: [PATCH] Load troll data --- src/data/troll/stock.json | 99 +++++++++++++++++++++++++++++++++++++++ src/lib/data.rb | 2 +- src/lib/data/troll.rb | 7 ++- src/lib/stock.rb | 17 +++---- 4 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/data/troll/stock.json diff --git a/src/data/troll/stock.json b/src/data/troll/stock.json new file mode 100644 index 0000000..a1139c4 --- /dev/null +++ b/src/data/troll/stock.json @@ -0,0 +1,99 @@ +{ + "key": "troll", + "name": "Troll", + "stride": 7, + "common_traits": [ + "Black Nails", + "Fangs", + "Night Blooded", + "Night Eyed (Troll)", + "Massive Stature (Troll)", + "Stone's Age", + "Tough (Troll)", + "Troll Skin", + "Voracious Carnivore" + ], + "starting_stats": + [ + { + "range": [ + 1, + 5 + ], + "m": 3, + "p": 11 + }, + { + "range": [ + 6, + 12 + ], + "m": 4, + "p": 14 + }, + { + "range": [ + 13, + 19 + ], + "m": 4, + "p": 17 + }, + { + "range": [ + 20, + 27 + ], + "m": 4, + "p": 19 + }, + { + "range": [ + 28, + 57 + ], + "m": 4, + "p": 20 + }, + { + "range": [ + 58, + 80 + ], + "m": 4, + "p": 19 + }, + { + "range": [ + 81, + 124 + ], + "m": 4, + "p": 18 + }, + { + "range": [ + 125, + 213 + ], + "m": 5, + "p": 17 + }, + { + "range": [ + 214, + 390 + ], + "m": 5, + "p": 16 + }, + { + "range": [ + 391, + 712 + ], + "m": 6, + "p": 15 + } + ] +} diff --git a/src/lib/data.rb b/src/lib/data.rb index c9a07d3..1470d96 100644 --- a/src/lib/data.rb +++ b/src/lib/data.rb @@ -15,6 +15,7 @@ module Charred def initialize @data = {} + @data[:stock_objs] = {} puts 'loading gold' load_gold(@data) @@ -30,7 +31,6 @@ module Charred @data[:traits] = @data[:traits].sort.to_h @data[:skills] = @data[:skills].sort.to_h - @data[:stock_objs] = @data[:stocks].map { |s| Stock.new s } end def verbose_merge(to, from) diff --git a/src/lib/data/troll.rb b/src/lib/data/troll.rb index 86e8f19..3842318 100644 --- a/src/lib/data/troll.rb +++ b/src/lib/data/troll.rb @@ -1,4 +1,5 @@ require 'json' +require_relative '../stock' module Charred module Troll @@ -24,6 +25,10 @@ module Charred file = File.read("data/troll/starting_stat_pts.json") stats = JSON.parse(file) data[:stat_pts]['troll'] = stats + + file = File.read("data/troll/stock.json") + stock = JSON.parse(file) + data[:stock_objs]['troll'] = Stock.new(stock) end end -end \ No newline at end of file +end diff --git a/src/lib/stock.rb b/src/lib/stock.rb index 0086c68..094ffd1 100644 --- a/src/lib/stock.rb +++ b/src/lib/stock.rb @@ -1,6 +1,6 @@ module Charred class Stock - @@default_stride = 6 + @@default_stride = 7 attr :key attr :name @@ -9,14 +9,15 @@ module Charred attr :settings attr :starting_stats - def initialize(key, name = key, stride = @@default_stride) - @key = key - @name = name - @stride = stride - @common_traits = [] - @settings = [] - @starting_stats = [] + def initialize(h) + @key = h["key"] + @name = h["name"] + @stride = h["stride"] || @@default_stride + @common_traits = h["common_traits"] + @settings = h["settings"] + @starting_stats = h["starting_stats"] end + def as_json(options = {}) { "key" => key,