Module: Chingu::Helpers::InputDispatcher

Included in:
GameState, Window
Defined in:
lib/chingu/helpers/input_dispatcher.rb

Overview

Methods for parsing and dispatching Chingus input-maps Mixed into Chingu::Window and Chingu::GameState

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) input_clients (readonly)

Returns the value of attribute input_clients



29
30
31
# File 'lib/chingu/helpers/input_dispatcher.rb', line 29

def input_clients
  @input_clients
end

Instance Method Details

- (Object) add_input_client(object)

Called by input_clients to add themselves from forwarding.



32
33
34
# File 'lib/chingu/helpers/input_dispatcher.rb', line 32

def add_input_client(object)
  @input_clients << object    unless @input_clients.include?(object)
end

- (Object) dispatch_button_down(id, object)

Dispatch button press to one of your clients.



42
43
44
45
46
47
# File 'lib/chingu/helpers/input_dispatcher.rb', line 42

def dispatch_button_down(id, object)
  return unless Input::CONSTANT_TO_SYMBOL[id]
  if actions = object.input[Input::CONSTANT_TO_SYMBOL[id].first]
    dispatch_actions(actions)
  end
end

- (Object) dispatch_button_up(id, object)

Dispatch button release to one of your clients.



50
51
52
53
54
55
# File 'lib/chingu/helpers/input_dispatcher.rb', line 50

def dispatch_button_up(id, object)
  return unless Input::CONSTANT_TO_SYMBOL[id]
  if actions = object.input[:released_#{Input::CONSTANT_TO_SYMBOL[id].first}"]
    dispatch_actions(actions)
  end
end

- (Object) dispatch_input_for(object, prefix = "holding_")

Dispatches input-mapper for any given object



60
61
62
63
64
65
66
67
# File 'lib/chingu/helpers/input_dispatcher.rb', line 60

def dispatch_input_for(object, prefix = "holding_")
  pattern = /^#{prefix}/
  object.input.each do |symbol, actions|
    if symbol.to_s =~ pattern and $window.button_down?(Input::SYMBOL_TO_CONSTANT[$'.to_sym])
      dispatch_actions(actions)
    end
  end
end

- (Object) remove_input_client(object)

Called by input_clients to remove themselves from forwarding.



37
38
39
# File 'lib/chingu/helpers/input_dispatcher.rb', line 37

def remove_input_client(object)
  @input_clients.delete(object)
end