class Straightedge::Adapter

Attributes

agent[RW]
plane[R]

Public Class Methods

new(agent: Director.new, plane: nil) click to toggle source
# File lib/straightedge/motor/adapter.rb, line 7
def initialize(agent: Director.new, plane: nil)
  @agent = agent
  adapt(plane) if plane
end

Public Instance Methods

adapt(plane) click to toggle source
# File lib/straightedge/motor/adapter.rb, line 12
def adapt(plane)
  @plane = plane
  @plane.adapter = self
  @agent.prepare_stage([plane.width, plane.height])
end
click(x,y) click to toggle source
# File lib/straightedge/motor/adapter.rb, line 47
def click(x,y)
  @agent.handle(:click, x, y)
end
kickstart() click to toggle source
# File lib/straightedge/motor/adapter.rb, line 18
def kickstart
  @plane.display unless @plane.nil?
end
presenter_for(figure) click to toggle source

note the ordering is important, since e.g., grid < quad

# File lib/straightedge/motor/adapter.rb, line 28
def presenter_for(figure)
  figures_and_presenters = Straightedge.config.presenter_classes 
  matched_class = figures_and_presenters.keys.detect { |k| figure.class <= k }

  klass = if matched_class
            figures_and_presenters[matched_class]
          else
            raise "no presenter class for #{figure}"
          end

  new_presenter = klass.new
  new_presenter.on(@plane) unless @plane.nil?
  new_presenter
end
render() click to toggle source
# File lib/straightedge/motor/adapter.rb, line 22
def render
  scene = @agent.current_scene.is_a?(Hash) ? Scene.new(agent.current_scene) : agent.current_scene
  scene.render(self)
end
step() click to toggle source
# File lib/straightedge/motor/adapter.rb, line 43
def step
  @agent.orchestrate
end