Sha256: 040dc7962f4ea138a10bd1c3fec18f2135a81d2927e8aca5452bdb8718814701

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

module Standardized
  # @return [Boolean]
  attr_writer :itemized

  # @return [Boolean]
  attr_writer :portable

  # An optional description to use when itemizing entities in room
  # descriptions. The locale_description will be used instead of adding
  # the entity's name to a list.
  #
  # @return [String, nil]
  attr_accessor :locale_description

  # Itemized entities are automatically listed in room descriptions.
  #
  # @return [Boolean]
  def itemized?
    @itemized
  end

  # Portable entities can be taken with TAKE actions.
  #
  # @return [Boolean]
  def portable?
    @portable
  end

  # @return [Boolean]
  def attached?
    @attached ||= false
  end

  # @param bool [Boolean]
  def attached=(bool)
    @attached = if parent.nil?
                  # @todo Log attachment failure
                  false
                else
                  bool
                end
  end

  def parent=(new_parent)
    self.attached = false unless new_parent == parent
    super
  end

  # The entity's parent room (i.e., the closest ascendant that is a Room).
  #
  # @return [Room]
  def room
    ascendant = parent
    ascendant = ascendant.parent until ascendant.is_a?(Room) || ascendant.nil?
    ascendant
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gamefic-standard-3.2.4 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.2.3 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.2.2 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.2.1 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.2.0 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.1.0 lib/gamefic-standard/modules/standardized.rb
gamefic-standard-3.0.0 lib/gamefic-standard/modules/standardized.rb