Class: DemoReaderDefrag

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, hint_for_time = nil) ⇒ DemoReaderDefrag

Returns a new instance of DemoReaderDefrag.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/demo_reader_defrag.rb', line 10

def initialize(filename, hint_for_time = nil)
  @filename = filename
  @hint_for_time = hint_for_time

  @game = "Defrag"
  @version = -1
  @mapname = nil
  @time = nil
  @time_in_msec = nil
  @playernames = []
  @scoreboards = []
  @gamemode = nil
  @player = nil
  @basegamedir = nil
  @gamedir = nil
  @valid = false
  @raw = nil

  self.init()
end

Instance Attribute Details

#basegamedirObject (readonly)

Returns the value of attribute basegamedir.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def basegamedir
  @basegamedir
end

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def filename
  @filename
end

#gameObject (readonly)

Returns the value of attribute game.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def game
  @game
end

#gamedirObject (readonly)

Returns the value of attribute gamedir.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def gamedir
  @gamedir
end

#gamemodeObject (readonly)

Returns the value of attribute gamemode.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def gamemode
  @gamemode
end

#mapnameObject (readonly)

Returns the value of attribute mapname.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def mapname
  @mapname
end

#playerObject (readonly)

Returns the value of attribute player.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def player
  @player
end

#playernamesObject (readonly)

Returns the value of attribute playernames.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def playernames
  @playernames
end

#scoreboardsObject (readonly)

Returns the value of attribute scoreboards.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def scoreboards
  @scoreboards
end

#timeObject (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def time
  @time
end

#validObject (readonly)

Returns the value of attribute valid.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def valid
  @valid
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/demo_reader_defrag.rb', line 6

def version
  @version
end

Instance Method Details

#initObject



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

def init
  out = DM68.parse_file(@filename)
  @raw = YAML.load(out)

  raise out unless @raw

  @version = @raw['server_info']['protocol'].to_i
  @mapname = @raw['server_info']['mapname'].downcase

  @scoreboards = @raw['prints']
  @basegamedir = @raw['server_info']['gamename']
  @gamedir = @raw['system_info']['fs_game']

  if @raw['server_info']['defrag_vers'].to_i > 0
    @gamemode = @raw['server_info']['df_promode'].to_i.zero? ? 'vq3' : 'cpm'

    time_hint = extract_time_from_filename(@hint_for_time || @filename)
    @time = extract_time(@raw['prints'], time_hint)

    @player = extract_player(@raw['prints'], @time)
    @playernames << @player # just support one player atm
  end

  @valid = true
end

#time_in_msecObject



61
62
63
64
65
66
67
68
69
# File 'lib/demo_reader_defrag.rb', line 61

def time_in_msec
  return @time_in_msec unless @time_in_msec.nil?

  # time str to int
  if @time.kind_of? String
    min, sec, msec = @time.scan(/^([0-9]+):([0-9]+)\.([0-9]+)$/).flatten.map { |x| x.to_i }
    @time_in_msec = msec + sec * 1000 + min * 60 * 1000
  end
end