Sha256: 9a252862ed4ccd2f6cd245be4e62a2b7cbcb8fcf68afea38a1bed2703d746a68
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module Straightedge class Adapter include Straightedge::Figures attr_accessor :agent attr_reader :plane def initialize(agent: Director.new, plane: nil) @agent = agent adapt(plane) if plane end def adapt(plane) @plane = plane @plane.adapter = self @agent.prepare_stage([plane.width, plane.height]) end def kickstart @plane.display unless @plane.nil? end def render scene = @agent.current_scene.is_a?(Hash) ? Scene.new(agent.current_scene) : agent.current_scene scene.render(self) end # note the ordering is important, since e.g., grid < quad 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 def step @agent.orchestrate end def click(x,y) @agent.handle(:click, x, y) end end config.presenter_classes = {} config.adapter_class = Adapter end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
straightedge-0.1.2 | lib/straightedge/motor/adapter.rb |
straightedge-0.1.1 | lib/straightedge/motor/adapter.rb |