Class: InitDataParser
- Inherits:
-
Object
- Object
- InitDataParser
- Defined in:
- lib/herostats/init_data_parser.rb
Instance Method Summary collapse
-
#initialize(game) ⇒ InitDataParser
constructor
A new instance of InitDataParser.
- #load_events(file) ⇒ Object
- #parse(file) ⇒ Object
Constructor Details
#initialize(game) ⇒ InitDataParser
Returns a new instance of InitDataParser.
4 5 6 |
# File 'lib/herostats/init_data_parser.rb', line 4 def initialize(game) @game = game end |
Instance Method Details
#load_events(file) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/herostats/init_data_parser.rb', line 8 def load_events(file) file = file.read file = file.gsub("}\n{", "},\n{") file = file.gsub("]\n{", "],\n{") JSON.parse("[#{file}]") end |
#parse(file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/herostats/init_data_parser.rb', line 15 def parse(file) events = load_events(file) events.each do |event| if event.class == Hash event['m_syncLobbyState'].each do |k, v| #puts v case k when 'm_userInitialData' #{"m_testAuto"=>false, "m_mount"=>"", "m_observe"=>0, "m_teamPreference"=>{"m_team"=>nil}, "m_toonHandle"=>"", "m_customInterface"=>false, "m_highestLeague"=>0, "m_clanTag"=>"", "m_testMap"=>false, "m_clanLogo"=>nil, "m_examine"=>false, "m_testType"=>0, "m_combinedRaceLevels"=>4294967295, "m_randomSeed"=>0, "m_racePreference"=>{"m_race"=>nil}, "m_skin"=>"", "m_hero"=>"", "m_name"=>"Biscuit"} v.each do |initial_data| player = Player.new player.name = initial_data['m_name'] puts player.name @game.add_player(player) unless player.name.empty? end when 'm_lobbyState' v['m_slots'].each_with_index do |slot, index| @game.players[index + 1].hero = slot['m_hero'] unless index > 9 #puts "#{game.players[index].name} #{game.players[index].hero}" #puts slot end when 'm_gameDescription' end end end end @game end |