Class: Gamefic::Sdk::Diagram
- Inherits:
-
Object
- Object
- Gamefic::Sdk::Diagram
- Defined in:
- lib/gamefic-sdk/diagram.rb
Defined Under Namespace
Classes: Position
Constant Summary collapse
- DIAGRAMMABLE =
%w[entities responses verbs syntaxes commands scenes].freeze
Instance Attribute Summary collapse
- #plot ⇒ Gamefic::Plot readonly
Instance Method Summary collapse
- #commands ⇒ Object
- #entities ⇒ Object
- #get(type) ⇒ Object
-
#initialize(plot) ⇒ Diagram
constructor
A new instance of Diagram.
- #responses ⇒ Object
- #rooms ⇒ Object
- #scenes ⇒ Object
- #syntaxes ⇒ Object
- #valid?(type) ⇒ Boolean
- #verbs ⇒ Object
Constructor Details
#initialize(plot) ⇒ Diagram
Returns a new instance of Diagram.
25 26 27 |
# File 'lib/gamefic-sdk/diagram.rb', line 25 def initialize plot @plot = plot end |
Instance Attribute Details
#plot ⇒ Gamefic::Plot (readonly)
23 24 25 |
# File 'lib/gamefic-sdk/diagram.rb', line 23 def plot @plot end |
Instance Method Details
#commands ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/gamefic-sdk/diagram.rb', line 77 def commands { responses: responses, verbs: verbs, syntaxes: syntaxes } end |
#entities ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/gamefic-sdk/diagram.rb', line 57 def entities plot.entities.map do |ent| { name: ent.name, type: ent.class, parent: ent.parent&.name } end end |
#get(type) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gamefic-sdk/diagram.rb', line 29 def get type if valid?(type) send(type) else raise ArgumentError, "Unknown diagram type '#{type}'" end end |
#responses ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/gamefic-sdk/diagram.rb', line 67 def responses plot.playbook.responses.map do |act| { verb: act.verb, meta: act., # signature: act.signature } end end |
#rooms ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gamefic-sdk/diagram.rb', line 41 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 |
#scenes ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/gamefic-sdk/diagram.rb', line 100 def scenes plot.scenebook.scenes.map do |scene| { name: scene.name, type: scene.type } end end |
#syntaxes ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gamefic-sdk/diagram.rb', line 89 def syntaxes plot.syntaxes.map do |syn| { template: syn.template, command: syn.command, synonym: syn.synonym, verb: syn.verb } end end |
#valid?(type) ⇒ Boolean
109 110 111 |
# File 'lib/gamefic-sdk/diagram.rb', line 109 def valid? type DIAGRAMMABLE.include?(type) end |
#verbs ⇒ Object
37 38 39 |
# File 'lib/gamefic-sdk/diagram.rb', line 37 def verbs plot.verbs end |