Class: MPQ::SC2ReplayFile

Inherits:
Archive
  • Object
show all
Defined in:
lib/replay_file.rb

Defined Under Namespace

Classes: Attribute, InitData

Instance Method Summary collapse

Methods inherited from Archive

#initialize, #read_file, #read_table

Constructor Details

This class inherits a constructor from MPQ::Archive

Instance Method Details

#game_lengthObject

Game length is given as the number of frames.



12
13
14
# File 'lib/replay_file.rb', line 12

def game_length
  @game_length ||= user_data[3] / FRAMES_PER_SECOND
end

#game_versionObject

These are the numbers you see in the bottom left of the game’s menu. Use the ‘build` to change features, etc. based on game version. Use the rest when presenting a version to a person.



19
20
21
22
23
24
25
26
# File 'lib/replay_file.rb', line 19

def game_version
  @game_version ||= {
    :major => user_data[1][1],
    :minor => user_data[1][2],
    :patch => user_data[1][3],
    :build => user_data[1][4]
  }
end

#map_nameObject

The localized map name. Should probably translate it.



59
60
61
# File 'lib/replay_file.rb', line 59

def map_name
  details[1]
end

#playersObject

Player information is spread among a couple of files: the ‘replay.details` file and the `replay.attributes.events` file. Here we combine the information contained in each.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/replay_file.rb', line 31

def players
  return @players if defined? @players
  @players = details[0].map do |player|
    { :name => player[0],
    
      # This could probably be 'unknown' in some circumstances I haven't 
      # yet checked.
      :outcome => OUTCOMES[player[8]]
    }
  end

  # Unlike the `replay.initData` file, this method of determining race is
  # the same across all localizations.
  attributes.each do |attr|
    case attr.id.to_i
    when 0x01f4
      @players[attr.player - 1][:type] = ATTRIBUTES[:player_type][attr.sval]
    when 0x0bb9
      @players[attr.player - 1][:race] = ATTRIBUTES[:player_race][attr.sval]
    when 0x0bba
      @players[attr.player - 1][:color] = 
        ATTRIBUTES[:player_color][attr.sval]
    end
  end
  @players
end

#realmObject

Two-uppercase-character abbreviation, like ‘NA`.



73
74
75
# File 'lib/replay_file.rb', line 73

def realm
  initdata.rest.split('s2ma')[1][2, 2]
end

#start_dateObject

The start date of the game, probably off by a time zone or ten.



64
65
66
67
68
69
70
# File 'lib/replay_file.rb', line 64

def start_date
=begin
  FIXME: parse this as UTC (possibly requires use of time zone offset 
  present in details).
=end
  Time.at((details[5] - 116444735995904000) / 1e7)
end