Class: Worlds::World
- Inherits:
-
Object
- Object
- Worlds::World
- Defined in:
- lib/worlds/world.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Attribute Summary collapse
-
#areas ⇒ Object
readonly
Returns the value of attribute areas.
Class Method Summary collapse
Instance Method Summary collapse
- #demo_setup ⇒ Object
-
#initialize ⇒ World
constructor
A new instance of World.
- #input(input) ⇒ Object
- #update(ms) ⇒ Object
Constructor Details
#initialize ⇒ World
Returns a new instance of World.
28 29 30 |
# File 'lib/worlds/world.rb', line 28 def initialize @areas = [] end |
Class Attribute Details
.instance ⇒ Object (readonly)
Returns the value of attribute instance.
12 13 14 |
# File 'lib/worlds/world.rb', line 12 def instance @instance end |
Instance Attribute Details
#areas ⇒ Object (readonly)
Returns the value of attribute areas.
9 10 11 |
# File 'lib/worlds/world.rb', line 9 def areas @areas end |
Class Method Details
.input(input) ⇒ Object
20 21 22 |
# File 'lib/worlds/world.rb', line 20 def self.input(input) instance.input(input) end |
.setup ⇒ Object
15 16 17 18 |
# File 'lib/worlds/world.rb', line 15 def self.setup @instance = new @instance.demo_setup end |
.update(ms) ⇒ Object
24 25 26 |
# File 'lib/worlds/world.rb', line 24 def self.update(ms) instance.update(ms) end |
Instance Method Details
#demo_setup ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/worlds/world.rb', line 63 def demo_setup hero = Entity.new hero.components << Components::Travel.new(hero, commands: %w[travel t go leave]) Entity.player = hero clock = Entity.new clock.components << Components::Ticker.new(clock) street = Area.new("a quiet street") street.entities << hero shop = Area.new("Rolf's Clock Shop") shop.linked_areas << street shop.entities << clock street.linked_areas << shop @areas << street @areas << shop output = Entity.player.components.find { _1.is_a? Components::Travel }.invoke(street) [output] end |
#input(input) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/worlds/world.rb', line 32 def input(input) Entity.player.components.each do |component| if component.commands.include? input[:command] if input[:type] == :select selection_index = input[:selection] - 1 if selection_index >= component..count return { color: :red, content: "Invalid selection" } end return component.invoke(selection_index) else return [component.select] || [component.invoke] end end end nil end |