Module: Openra::Commands::Utils

Included in:
Replays::ExtractData, Replays::ExtractMetadata
Defined in:
lib/openra/commands/utils.rb

Instance Method Summary collapse

Instance Method Details

#cell(pos) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/openra/commands/utils.rb', line 11

def cell(pos)
  return if pos.zero?

  {
    x: pos >> 20,
    y: ((pos >> 4) & 0xFFF0) >> 4,
    layer: pos & 0xFF
  }
end

#time(msec) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/openra/commands/utils.rb', line 21

def time(msec)
  sec = msec / 1000
  mm, ss = sec.divmod(60)
  hh, mm = mm.divmod(60)

  {
    formatted: '%02d:%02d:%02d' % [hh, mm, ss],
    msec: msec.to_i
  }
end

#utf8(string) ⇒ Object



6
7
8
# File 'lib/openra/commands/utils.rb', line 6

def utf8(string)
  string.force_encoding('UTF-8')
end