Sha256: 72c64e92fe6a190097957e426be735e3c1e935ccaf3101558cb1edb77d3bbb51
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
require 'actor' require 'graphical_actor_view' # ActorFactory is responsible for loading all Actors. It passes along required params such as # stage, input_manager, director, resource_manager. It also creates the ActorView # associated with the Actor and registers it to the Stage be drawn. class ActorFactory constructor :input_manager attr_accessor :stage_manager, :director # Returns a hash of actor params {:model_klass=>k, :view_klass=>v}. This is for performance reasons. def cached_actor_def(actor) @actor_cache ||= {} cached_actor = @actor_cache[actor] return cached_actor if cached_actor model_klass = ClassFinder.find(actor) view_klass = ClassFinder.find("#{actor}_view") actor_def = { :model_klass => model_klass, :view_klass => view_klass } @actor_cache[actor] = actor_def actor_def end # returns the newly created Actor after it and its ActorView has been created. def build(actor, stage, opts={}) actor_def = cached_actor_def actor actor_type = actor_def[:actor_type] basic_opts = { :stage => stage, :input => @input_manager, :director => @director, :resources => stage.resource_manager, :actor_type => actor } merged_opts = basic_opts.merge(opts) model = actor_def[:model_klass].new merged_opts view_klass = opts[:view] view_klass ||= actor_def[:view_klass] if model.is? :animated or model.is? :graphical or model.is? :physical view_klass ||= GraphicalActorView end view_klass.new stage, model if view_klass model.show unless opts[:hide] return model end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
gamebox-0.1.1 | lib/gamebox/actor_factory.rb |
gamebox-0.1.0 | lib/gamebox/actor_factory.rb |
gamebox-0.0.9 | lib/gamebox/actor_factory.rb |
gamebox-0.0.8 | lib/gamebox/actor_factory.rb |