class Sc20XX::Application

Public Class Methods

logger() click to toggle source
# File lib/sc20XX/application.rb, line 89
def self.logger
  @logger ||= Logger.new('debug.log')
end
new(client) click to toggle source
# File lib/sc20XX/application.rb, line 22
def initialize(client)
  $stderr.reopen('debug.log', 'w')
  @canvas = UI::Canvas.new

  @splash_controller = Controller.new(
    Splash.new(
      UI::Rect.new(0, 0, Curses.cols, Curses.lines)))

  @player_controller = PlayerController.new(
    PlayerView.new(
      UI::Rect.new(0, 0, Curses.cols, 5)), client)

  @track_controller = TrackController.new(
    TracksTable.new(
      UI::Rect.new(0, 5, Curses.cols, Curses.lines - 5)), client)

  @track_controller.bind_to(TrackCollection.new(client))

  @track_controller.events.on(:select) do |track|
    @player_controller.play(track)
  end

  @player_controller.events.on(:complete) do
    @track_controller.next_track
  end
end

Public Instance Methods

handle(key) click to toggle source

TODO: look at active controller and send key to active controller instead

# File lib/sc20XX/application.rb, line 72
def handle(key)
  case key
  when :left, :right, :space, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine
    @player_controller.events.trigger(:key, key)
  when :down, :up, :enter, :u, :f, :s, :j, :k
    @track_controller.events.trigger(:key, key)
  end
end
main() click to toggle source
# File lib/sc20XX/application.rb, line 49
def main
  loop do
    if @workaround_was_called_once_already
      handle UI::Input.get(-1)
    else
      @workaround_was_called_once_already = true
      handle UI::Input.get(0)
      @track_controller.load
      @track_controller.render
    end

    break if stop?
  end
ensure
  @canvas.close
end
run() click to toggle source
# File lib/sc20XX/application.rb, line 66
def run
  @splash_controller.render
  main
end
stop() click to toggle source
# File lib/sc20XX/application.rb, line 81
def stop
  @stop = true
end
stop?() click to toggle source
# File lib/sc20XX/application.rb, line 85
def stop?
  @stop == true
end