Sha256: b511c6202dc0e72cd8032f12e5fd6e2533ddcca9b542f9b49fa0438fcf854176

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Gamefic
  module Standard
    # Common features of standard entities.
    #
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gamefic-standard-4.0.0 lib/gamefic/standard/standardized.rb
gamefic-standard-3.3.0 lib/gamefic-standard/standardized.rb