class Rubygoal::Recorder

Attributes

frames[R]
game[R]

Public Class Methods

new(game) click to toggle source
# File lib/rubygoal/recorder.rb, line 5
def initialize(game)
  @game   = game
  @frames = []
end

Public Instance Methods

to_hash() click to toggle source
# File lib/rubygoal/recorder.rb, line 14
def to_hash
  {
    teams: {
      home: @game.coach_home.name,
      away: @game.coach_away.name
    },
    score: [@game.score_home, @game.score_away],
    frames: @frames
  }
end
update() click to toggle source
# File lib/rubygoal/recorder.rb, line 10
def update
  @frames << frame_info
end

Private Instance Methods

frame_info() click to toggle source
# File lib/rubygoal/recorder.rb, line 29
def frame_info
  frame = {
    time: @game.time.round(0),
    score: [@game.score_home, @game.score_away],
    ball: [
      @game.ball.position.x.round(0),
      @game.ball.position.y.round(0)
    ],
    home: team_info(@game.team_home),
    away: team_info(@game.team_away)
  }
  last_kicker_info(frame) if Rubygoal.configuration.record_last_kicker

  frame
end
last_kicker_info(frame) click to toggle source
# File lib/rubygoal/recorder.rb, line 56
def last_kicker_info(frame)
  if @game.ball.last_kicker
    frame[:last_kicker] = [
      @game.ball.last_kicker[:name],
      @game.ball.last_kicker[:side]
    ]
  end
end
team_info(team) click to toggle source
# File lib/rubygoal/recorder.rb, line 45
def team_info(team)
  team.players.map do |_, player|
    [
      player.position.x.round(0),
      player.position.y.round(0),
      player.rotation.round(0),
      player.type[0]
    ]
  end
end