Class: Worlds::Components::Travel

Inherits:
Component
  • Object
show all
Defined in:
lib/worlds/components/travel.rb

Instance Attribute Summary

Attributes inherited from Component

#commands, #owner

Instance Method Summary collapse

Methods inherited from Component

#initialize, #select, #update

Constructor Details

This class inherits a constructor from Worlds::Components::Component

Instance Method Details

#invoke(target) ⇒ Object

Parameters:

  • target (Area, Integer)

    an Area, or the index of an Area in the owner’s linked areas.



14
15
16
17
18
19
20
21
22
# File 'lib/worlds/components/travel.rb', line 14

def invoke(target)
  target = target.is_a?(Area) ? target : owner.area.linked_areas[target]

  owner.area&.entities&.delete(owner)
  target.entities << owner
  owner.area = target

  { color: :green, content: "You are now in #{target.name}" }
end

#select_headingObject



4
5
6
# File 'lib/worlds/components/travel.rb', line 4

def select_heading
  "Choose a destination:"
end

#select_optionsObject



8
9
10
# File 'lib/worlds/components/travel.rb', line 8

def select_options
  owner.area.linked_areas
end