Sha256: b46f3c80cbe602c760c4bbf0d09173c704ce052d793b38e434e6ab15bd53d552

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require_relative 'world_object'

module Woyo

class Way < WorldObject

  def initialize_object
    super
    attribute :going 
    exclusion :passable, :closed, :open  # defaults to closed: true 
    action :go do
      describe proc { self.context.going }
      #result   proc { self.context.passable } 
      execution do
        {
          go:       open?,
          location: open? ? self.to.id : nil
        }
      end
    end
  end

  # def go
  #   { go: open?, going: self.going }
  # end

  def world
    from ? from.world : nil
  end

  def close!
    closed!
  end

  def from
    @from ||= context
  end

  def to arg=nil
    if arg.nil?
      @to
    else
      self.to = arg
    end
  end

  def to= arg
    if arg.instance_of? Symbol
      case
      when from && arg == from.id
        @to = from                        # way loops back to the same location
      when world && world.locations[arg]
        @to = world.locations[arg]        # destination location already exists in world
      when world
        @to = world.location arg          # create destination location in world 
      else
        @to = Location.new arg            # create free-standing destination location
      end
      self.open!
    else
      raise "Symbol required, but #{arg.class} : '#{arg}' given."
    end
  end
  
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
woyo-world-0.0.9 lib/woyo/world/way.rb