Class: Demiurge::ActionItemInternal::ActionItemBlockRunner Private
- Inherits:
-
BlockRunner
- Object
- BlockRunner
- Demiurge::ActionItemInternal::ActionItemBlockRunner
- Defined in:
- lib/demiurge/action_item.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The ActionItemBlockRunner is a good, general-purpose block runner that supplies more context and more "gentle" object accessors to the block code. The methods of this class are generally intended to be used in the block code.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_intention ⇒ Demiurge::Intention?
readonly
private
The current intention, if any.
Attributes inherited from BlockRunner
Instance Method Summary collapse
-
#action(name, *args) ⇒ void
private
Create an action to be executed immediately.
-
#cancel_intention(reason, extra_info = {}) ⇒ void
private
Cancel the current intention.
-
#cancel_intention_if_present(reason, extra_info = {}) ⇒ void
private
Cancel the current intention.
-
#initialize(item, current_intention:) ⇒ ActionItemBlockRunner
constructor
private
The constructor.
-
#notification(data) ⇒ void
private
Send a notification, starting from the location of the ActionItem.
-
#position_to_location_and_tile_coords(position) ⇒ String, Integer
private
For tiled maps, cut the position string apart into a location and X and Y tile coordinates within that location.
-
#state ⇒ Demiurge::ActionItemInternal::ActionItemStateWrapper
private
Access the item's state via a state wrapper.
Constructor Details
#initialize(item, current_intention:) ⇒ ActionItemBlockRunner
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The constructor
263 264 265 266 |
# File 'lib/demiurge/action_item.rb', line 263 def initialize(item, current_intention:) super(item) @current_intention = current_intention end |
Instance Attribute Details
#current_intention ⇒ Demiurge::Intention? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The current intention, if any
256 257 258 |
# File 'lib/demiurge/action_item.rb', line 256 def current_intention @current_intention end |
Instance Method Details
#action(name, *args) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Create an action to be executed immediately. This doesn't go through an agent's action queue or make anybody busy. It just happens during the current tick, but it uses the normal allow/offer/execute/notify cycle.
316 317 318 319 320 |
# File 'lib/demiurge/action_item.rb', line 316 def action(name, *args) intention = ActionItemInternal::ActionIntention.new(engine, @item.name, name, *args) @item.engine.queue_intention(intention) nil end |
#cancel_intention(reason, extra_info = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Cancel the current intention. Raise a NoCurrentIntentionError if there isn't one.
338 339 340 341 342 343 |
# File 'lib/demiurge/action_item.rb', line 338 def cancel_intention(reason, extra_info = {}) raise ::Demiurge::Errors::NoCurrentIntentionError.new("No current intention in action of item #{@item.name}!", { "script_item": @item.name }, execution_context: @item.engine.execution_context) unless @current_intention @current_intention.cancel(reason, extra_info) nil end |
#cancel_intention_if_present(reason, extra_info = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Cancel the current intention. Do nothing if there isn't one.
351 352 353 |
# File 'lib/demiurge/action_item.rb', line 351 def cancel_intention_if_present(reason, extra_info = {}) @current_intention.cancel(reason, extra_info) if @current_intention end |
#notification(data) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Send a notification, starting from the location of the ActionItem. Any fields other than the special "type", "zone", "location" and "actor" fields will be sent as additional notification fields.
298 299 300 301 302 303 304 305 |
# File 'lib/demiurge/action_item.rb', line 298 def notification(data) type = data.delete("type") || data.delete(:type) || data.delete("type") || data.delete(:type) zone = to_demiurge_name(data.delete("zone") || data.delete(:zone) || @item.zone) location = to_demiurge_name(data.delete("location") || data.delete(:location) || @item.location) actor = to_demiurge_name(data.delete("actor") || data.delete(:actor) || @item) @item.engine.send_notification(data, type: type.to_s, zone: zone, location: location, actor: actor, include_context: true) nil end |
#position_to_location_and_tile_coords(position) ⇒ String, Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For tiled maps, cut the position string apart into a location and X and Y tile coordinates within that location.
328 329 330 |
# File 'lib/demiurge/action_item.rb', line 328 def position_to_location_and_tile_coords(position) ::Demiurge::TiledLocation.position_to_loc_coords(position) end |
#state ⇒ Demiurge::ActionItemInternal::ActionItemStateWrapper
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Access the item's state via a state wrapper. This only allows setting new fields or reading fields that already exist.
273 274 275 |
# File 'lib/demiurge/action_item.rb', line 273 def state @state_wrapper ||= ActionItemInternal::ActionItemStateWrapper.new(@item) end |