Class: Gamefic::Sdk::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic-sdk/diagram.rb

Defined Under Namespace

Classes: Position

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#plotGamefic::Plot (readonly)

Returns:

  • (Gamefic::Plot)


21
22
23
# File 'lib/gamefic-sdk/diagram.rb', line 21

def plot
  @plot
end

Instance Method Details

#actionsObject



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.meta?,
      signature: act.signature
    }
  end
end

#commandsObject



78
79
80
81
82
83
84
# File 'lib/gamefic-sdk/diagram.rb', line 78

def commands
  {
    actions: actions,
    verbs: verbs,
    syntaxes: syntaxes
  }
end

#entitiesObject



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

#roomsObject



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

#syntaxesObject



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

Returns:

  • (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

#verbsObject



35
36
37
# File 'lib/gamefic-sdk/diagram.rb', line 35

def verbs
  plot.verbs
end