Sha256: 20b7e955e1473a539253b9585b4d77e46ea7b5fc1b13549206e25b62fecab0d7

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

module DebugHelpers
  def actors(type=nil)
    matching_actors = []
    ObjectSpace.each_object do |obj|
      if obj.class == Actor 
        if type.nil? || obj.actor_type == type
          matching_actors << obj 
        end
      end
    end
    log "found #{matching_actors.size} actors"
    matching_actors
  end

  def current_stage
    game.stage_manager.current_stage
  end

  def reload_behavior(behavior_name)
    behavior = behavior_name.to_sym
    log "reloading behavior: [#{behavior}]"
    load "behaviors/#{behavior}.rb"

    actors.each do |act|

      if act.has_behavior?(behavior)
        behaviors = act.instance_variable_get('@behaviors')
        beh_opts = behaviors[behavior].opts

        factory = act.this_object_context[:behavior_factory]
        act.remove_behavior behavior

        factory.add_behavior(act, behavior, beh_opts)
      end
    end
  end

  def load_actor(actor_type)
    type = actor_type.to_sym
    log "loading actor: [#{type}]"
    load "actors/#{type}.rb"
  end

  module_function :reload_behavior, :actors, :load_actor

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gamebox-0.5.5 lib/gamebox/core/debug_helpers.rb
gamebox-0.5.4 lib/gamebox/core/debug_helpers.rb
gamebox-0.5.2 lib/gamebox/core/debug_helpers.rb
gamebox-0.5.1 lib/gamebox/core/debug_helpers.rb
gamebox-0.5.0 lib/gamebox/core/debug_helpers.rb
gamebox-0.4.1 lib/gamebox/core/debug_helpers.rb
gamebox-0.4.0 lib/gamebox/core/debug_helpers.rb
gamebox-0.4.0.rc11 lib/gamebox/core/debug_helpers.rb