Class: Portal
Overview
An entity that provides access from one room to another.
Direct Known Subclasses
Instance Attribute Summary collapse
- #destination ⇒ Gamefic::Entity
-
#direction ⇒ Direction?
Get the ordinal direction of this Portal Portals have distinct direction and name properties so games can display a bare compass direction for exits, e.g., “south” vs.
Instance Method Summary collapse
- #instruction ⇒ Object
- #name ⇒ Object
-
#reverse ⇒ Room?
(also: #find_reverse)
Find the portal in the destination that returns to this portal’s parent.
- #synonyms ⇒ Object
Instance Attribute Details
#destination ⇒ Gamefic::Entity
7 8 9 |
# File 'lib/gamefic-standard/entities/portal.rb', line 7 def destination @destination end |
#direction ⇒ Direction?
Get the ordinal direction of this Portal Portals have distinct direction and name properties so games can display a bare compass direction for exits, e.g., “south” vs. “the southern door.”
A portal’s destination can also be nil, in which case it can be referenced in commands by its destination, e.g., “go to the house.”
17 18 19 |
# File 'lib/gamefic-standard/entities/portal.rb', line 17 def direction @direction end |
Instance Method Details
#instruction ⇒ Object
39 40 41 |
# File 'lib/gamefic-standard/entities/portal.rb', line 39 def instruction direction || (destination ? "to #{destination.definitely}" : name) end |
#name ⇒ Object
35 36 37 |
# File 'lib/gamefic-standard/entities/portal.rb', line 35 def name @name || direction&.name || destination.name end |
#reverse ⇒ Room? Also known as: find_reverse
Find the portal in the destination that returns to this portal’s parent
22 23 24 25 26 27 28 |
# File 'lib/gamefic-standard/entities/portal.rb', line 22 def reverse return nil if destination.nil? destination.children.that_are(Portal).find do |portal| portal.destination == parent end end |
#synonyms ⇒ Object
43 44 45 |
# File 'lib/gamefic-standard/entities/portal.rb', line 43 def synonyms "#{super} #{@destination} #{@direction} #{!direction.nil? ? direction.synonyms : ''}" end |