Class: Openra::Commands::Replays::ExtractMetadata

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/openra/commands/replays/extract_metadata.rb

Instance Method Summary collapse

Methods included from Utils

#cell, #time, #utf8

Instance Method Details

#call(filepath) ⇒ Object



9
10
11
12
13
14
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
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/openra/commands/replays/extract_metadata.rb', line 9

def call(filepath)
  replay = Openra::Replays::Replay.new(filepath)

  {
    mod: replay..mod,
    version: replay..version,
    file: {
      hash: replay.file_hash
    },
    map: {
      name: utf8(replay..map_name),
      hash: replay..map_hash
    },
    game: {
      type: replay.players.each_with_object(Hash.new(0)) { |player, hash|
        if player.team.nil?
          hash[SecureRandom.uuid] += 1
        else
          hash[player.team] += 1
        end
      }.values.join('v'),
      start_time: replay..start_time.iso8601,
      end_time: replay..end_time.iso8601,
      duration: time((replay..end_time - replay..start_time) * 1000)
    },
    players: replay.players.map { |player|
      {
        player_index: player.client_index,
        name: utf8(player.name),
        fingerprint: player.fingerprint,
        color: player.color,
        spawn: {
          random: player&.is_random_spawn,
          point: player.spawn_point
        },
        faction: {
          random: player&.is_random_faction,
          chosen: player.faction_name.downcase,
          actual: player&.faction_id
        },
        team: player&.team,
        is_bot: player&.is_bot || false,
        is_winner: player&.outcome == 'Won',
        outcome_time: player.outcome_time.iso8601
      }
    }
  }
end