Class: Gamefic::Sdk::Diagram
- Inherits:
-
Object
- Object
- Gamefic::Sdk::Diagram
- Defined in:
- lib/gamefic-sdk/diagram.rb
Defined Under Namespace
Classes: Position
Instance Attribute Summary collapse
- #plot ⇒ Gamefic::Plot readonly
Instance Method Summary collapse
- #actions ⇒ Object
- #commands ⇒ Object
- #entities ⇒ Object
- #get(type) ⇒ Object
-
#initialize(plot) ⇒ Diagram
constructor
A new instance of Diagram.
- #rooms ⇒ Object
- #syntaxes ⇒ Object
- #valid?(type) ⇒ Boolean
- #verbs ⇒ Object
Constructor Details
#initialize(plot) ⇒ Diagram
Returns a new instance of Diagram.
23 24 25 |
# File 'lib/gamefic-sdk/diagram.rb', line 23 def initialize plot @plot = plot end |
Instance Attribute Details
#plot ⇒ Gamefic::Plot (readonly)
21 22 23 |
# File 'lib/gamefic-sdk/diagram.rb', line 21 def plot @plot end |
Instance Method Details
#actions ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/gamefic-sdk/diagram.rb', line 68 def actions plot.actions.map do |act| { verb: act.verb, meta: act., signature: act.signature } end end |
#commands ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/gamefic-sdk/diagram.rb', line 78 def commands { actions: actions, verbs: verbs, syntaxes: syntaxes } end |
#entities ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gamefic-sdk/diagram.rb', line 55 def entities plot.initial_state[:entities].map do |e| e.transform_keys do |k| str = k.to_s if str.start_with?('@') str[1..-1] else str end end end end |
#get(type) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/gamefic-sdk/diagram.rb', line 27 def get type if valid?(type) send(type) else raise ArgumentError, "Unknown diagram type '#{type}'" end end |
#rooms ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gamefic-sdk/diagram.rb', line 39 def rooms clear position = Position.new plot.entities.that_are(Room).each do |room| proceed_from room, position next_x = right next_y = bottom if next_x > next_y position = Position.new(0, next_y + distance) else position = Position.new(next_x + distance, 0) end end elements.values end |
#syntaxes ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gamefic-sdk/diagram.rb', line 90 def syntaxes plot.syntaxes.map do |syn| { template: syn.template, command: syn.command, first_word: syn.first_word, verb: syn.verb } end end |
#valid?(type) ⇒ Boolean
101 102 103 |
# File 'lib/gamefic-sdk/diagram.rb', line 101 def valid? type %w[rooms entities actions verbs syntaxes commands].include?(type) end |
#verbs ⇒ Object
35 36 37 |
# File 'lib/gamefic-sdk/diagram.rb', line 35 def verbs plot.verbs end |