Sha256: b24b2c8f477d0c12b459f6aec1a14612a3a3b96adb1cceb31dc3ac2449fdea66

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

# An entity that provides access from one room to another.
#
class Portal < Thing
  # @return [Gamefic::Entity]
  attr_accessor :destination

  # 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."
  #
  # @return [Direction, nil]
  attr_reader :direction

  # Find the portal in the destination that returns to this portal's parent
  #
  # @return [Room, nil]
  def reverse
    return nil if destination.nil?

    destination.children.that_are(Portal).find do |portal|
      portal.destination == parent
    end
  end
  alias find_reverse reverse

  def direction= dir
    @direction = Direction.find(dir)
  end

  def name
    @name || direction&.name || destination.name
  end

  def instruction
    direction || (destination ? "to #{destination.definitely}" : name)
  end

  def synonyms
    "#{super} #{@destination} #{@direction} #{!direction.nil? ? direction.synonyms : ''}"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamefic-standard-3.2.4 lib/gamefic-standard/entities/portal.rb
gamefic-standard-3.2.3 lib/gamefic-standard/entities/portal.rb
gamefic-standard-3.2.2 lib/gamefic-standard/entities/portal.rb
gamefic-standard-3.2.1 lib/gamefic-standard/entities/portal.rb