Module: Metro::EventDictionary

Extended by:
EventDictionary
Included in:
EventDictionary
Defined in:
lib/metro/events/event_dictionary.rb

Instance Method Summary collapse

Instance Method Details

#add(params = {}) ⇒ Object

Examples:

Adding a new SceneEvent to the Dictionary


SceneEventDictionary.add target: scene_name, type: event_type, args: args, block: block


20
21
22
23
24
# File 'lib/metro/events/event_dictionary.rb', line 20

def add(params = {})
  target = params[:target]
  event = EventFactory.new params[:type], params[:args], &params[:block]
  events[target] = events_for_target(target).push event
end

#eventsObject

All defined events within this dictionary.



11
12
13
# File 'lib/metro/events/event_dictionary.rb', line 11

def events
  @events ||= HashWithIndifferentAccess.new
end

#events_for_target(scene_name) ⇒ Object

Return the events for the specified target



37
38
39
# File 'lib/metro/events/event_dictionary.rb', line 37

def events_for_target(scene_name)
  events[scene_name] ||= []
end

#events_for_targets(*list) ⇒ Object

Return all the events for all the specified targets.



29
30
31
32
# File 'lib/metro/events/event_dictionary.rb', line 29

def events_for_targets(*list)
  found_events = Array(list).flatten.compact.map {|s| events_for_target(s) }.flatten.compact
  found_events
end

#reset!Object

When the game is reset the event dictionary needs to flush out all of the events that it has loaded as the game files will be reloaded. All metro related components will not be removed as those files are not reloaded when the game is reloaded.



46
47
48
# File 'lib/metro/events/event_dictionary.rb', line 46

def reset!
  events.delete_if { |name,events| ! name.start_with? "metro/" }
end