lib/demiurge/dsl.rb
def on_notification(event, action_name, options = {}, &block)
      @built_item.state["on_handlers"] ||= {}
      @built_item.state["on_handlers"][event] = action_name
      register_built_action("name" => action_name, "block" => block)

      location = options[:location] || options["location"] || @built_item.location
      zone = options[:zone] || options["zone"] || location.zone_name || @built_item.zone_name
      item = options[:actor] || options["actor"] || :all

      @engine.subscribe_to_notifications type: event, zone: zone, location: location, actor: item do |notification|
        # To keep this statedump-safe, need to look up the item again
        # every time. @built_item isn't guaranteed to last.
        @engine.item_by_name(@name).run_action(action_name, notification)
      end
      nil
    end
# The specified action will be called for notifications of the
# appropriate type.
# @todo Figure out timing of the subscription - right now it will use the item's location midway through parsing the DSL!
#
# @param event [String] The name of the notification to subscribe to
# @param action_name [String] The action name of the new action
# @param options [Hash] Additional specifications about what/how to subscribe
# @option options [String,:all] location The location name to subscribe for - defaults to this item's location
# @option options [String,:all] zone The zone name to subscribe for - defaults to this item's zone
# @option options [String,:all] actor The acting item name to subscribe for - defaults to any item
# @yield [Hash] Receives notification hashes when these notifications occur
# @return [void]
# @since 0.0.1
The specified action will be called for notifications of the
appropriate type.
The specified action will be called for notifications of the appropriate type .
def on_notification(event, action_name, options = {}, &block)
      @built_item.state["on_handlers"] ||= {}
      @built_item.state["on_handlers"][event] = action_name
      register_built_action("name" => action_name, "block" => block)
      location = options[:location] || options["location"] || @built_item.location
      zone = options[:zone] || options["zone"] || location.zone_name || @built_item.zone_name
      item = options[:actor] || options["actor"] || :all
      @engine.subscribe_to_notifications type: event, zone: zone, location: location, actor: item do |notification|
        @engine.item_by_name(@name).run_action(action_name, notification)
      end
      nil
    end
def on_notification ( event , action_name , options = { } , & block ) @built_item . state [ "on_handlers" ] ||= { } @built_item . state [ "on_handlers" ] [ event ] = action_name register_built_action ( "name" => action_name , "block" => block ) location = options [ :location ] || options [ "location" ] || @built_item . location zone = options [ :zone ] || options [ "zone" ] || location . zone_name || @built_item . zone_name item = options [ :actor ] || options [ "actor" ] || :all @engine . subscribe_to_notifications type : event , zone : zone , location : location , actor : item do | notification | @engine . item_by_name ( @name ) . run_action ( action_name , notification ) end nil end
The specified action will be called for notifications of the
appropriate type.
The specified action will be called for notifications of the appropriate type .
# To keep this statedump-safe, need to look up the item again # every time. @built_item isn't guaranteed to last.
None
void
event
The name of the notification to subscribe to
The name of the notification to subscribe to
action_name
The action name of the new action
The action name of the new action
options
actor The acting item name to subscribe for - defaults to any item
actor The acting item name to subscribe for - defaults to any item
any item
block
]
Receives notification hashes when these notifications occur
Receives notification hashes when these notifications occur
todo
Figure out timing of the subscription - right now it will use the item's location midway through parsing the DSL!
Figure out timing of the subscription - right now it will use the item ' s location midway through parsing the DSL!
since
None