saving.rb
# Load items, creatures, and areas from the relevant
# JSON files. Yes it uses global variables, forgive me
Load items, creatures, and areas from the relevant
JSON files. Yes it uses global variables, forgive me
Load items creatures and areas from the relevant JSON files . Yes it uses global variables forgive me
def load_data
  $items = File.open("items.json") { |f| JSON.load f }
  $items.each do |k,v|
    type = k.split('_')[0].downcase
    if type == 'item'
      $items[k] = Item.new(v.internalize_keys)
    elsif type == 'weapon'
      $items[k] = Weapon.new(v.internalize_keys)
    elsif type == 'armor'
      $items[k] = Armor.new(v.internalize_keys)
    end
  end
  $creatures = File.open("creatures.json") { |f| JSON.load f }
  $creatures.each do |k,v|
    $creatures[k] = Creature.new(v.internalize_keys)
  end
  $areas = File.open("areas.json") { |f| JSON.load f }
  $areas.each do |k,v|
    $areas[k] = Area.new(v.internalize_keys)
    if $areas[k].creatures
      $areas[k].creatures.map! { |x| [x, $creatures[x].dup] }
    end
  end
end
def load_data $items = File . open ( "items.json" ) { | f | JSON . load f } $items . each do | k , v | type = k . split ( '_' ) [ 0 ] . downcase if type == 'item' $items [ k ] = Item . new ( v . internalize_keys ) elsif type == 'weapon' $items [ k ] = Weapon . new ( v . internalize_keys ) elsif type == 'armor' $items [ k ] = Armor . new ( v . internalize_keys ) end end $creatures = File . open ( "creatures.json" ) { | f | JSON . load f } $creatures . each do | k , v | $creatures [ k ] = Creature . new ( v . internalize_keys ) end $areas = File . open ( "areas.json" ) { | f | JSON . load f } $areas . each do | k , v | $areas [ k ] = Area . new ( v . internalize_keys ) if $areas [ k ] . creatures $areas [ k ] . creatures . map! { | x | [ x , $creatures [ x ] . dup ] } end end end
Load items, creatures, and areas from the relevant
JSON files.
Load items creatures and areas from the relevant JSON files .
# Can't pass the JSON hash directly as the keys must be # symbols not strings, we must convert them first # Can't use ids because creatures are different across areas, even if they # are the same type. Store a new instance of the actual creature instead