Class: GameMachine::Protobuf::GameMessages

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/protobuf/game_messages.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_file) ⇒ GameMessages


6
7
8
9
# File 'server/lib/game_machine/protobuf/game_messages.rb', line 6

def initialize(message_file)
  @starting_field_number = 1000
  @messages = IO.readlines(message_file)
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages


5
6
7
# File 'server/lib/game_machine/protobuf/game_messages.rb', line 5

def messages
  @messages
end

#starting_field_numberObject (readonly)

Returns the value of attribute starting_field_number


5
6
7
# File 'server/lib/game_machine/protobuf/game_messages.rb', line 5

def starting_field_number
  @starting_field_number
end

Instance Method Details

#create_entity_fieldsObject


21
22
23
24
25
26
27
28
29
30
31
# File 'server/lib/game_machine/protobuf/game_messages.rb', line 21

def create_entity_fields
  [].tap do |fields|
    messages.each do |line|
      if line.match(/^\s*?(persistent)?_?message\s+?(\w+?)\s+?{/)
        name = $2[0,1].downcase + $2[1..-1]
        fields << "optional #{$2} #{name} = #{starting_field_number};"
        @starting_field_number += 1
      end
    end
  end
end

#persistent_messagesObject


11
12
13
14
15
16
17
18
19
# File 'server/lib/game_machine/protobuf/game_messages.rb', line 11

def persistent_messages
  [].tap do |message_names|
    messages.each do |line|
      if line.match(/^\s*?(local_persistent|persistent)_message\s+?(\w+?)\s+?{/)
        message_names << $2
      end
    end
  end
end