Class: Hemi::Event::EventLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/hemi/event/event_loop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logic, events) ⇒ EventLoop

Returns a new instance of EventLoop.



4
5
6
7
8
9
# File 'lib/hemi/event/event_loop.rb', line 4

def initialize(logic, events)
  @logic  = logic
  @events = events.each_with_object({}) do |(key, action), hsh|
    hsh[SDL2::Key::Scan.const_get(key.upcase)] = action
  end
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



11
12
13
# File 'lib/hemi/event/event_loop.rb', line 11

def event
  @event
end

#eventsObject (readonly)

Returns the value of attribute events.



11
12
13
# File 'lib/hemi/event/event_loop.rb', line 11

def events
  @events
end

#logicObject (readonly)

Returns the value of attribute logic.



11
12
13
# File 'lib/hemi/event/event_loop.rb', line 11

def logic
  @logic
end

Instance Method Details

#handle(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/hemi/event/event_loop.rb', line 13

def handle(event)
  @event = event

  case event
  when SDL2::Event::KeyDown
    handle_key
  end

  @event = nil
end

#processObject



24
25
26
# File 'lib/hemi/event/event_loop.rb', line 24

def process
  logic.call
end