Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/models/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Player

Returns a new instance of Player.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/models/player.rb', line 6

def initialize(data = {})
  @id = data[:id] || -1
  @local = data[:local] == 1
  @team = data[:team] || 0
  @name = data[:name] || '(connecting..)'
  @clan = data[:clan] || ''
  @country = data[:country] || -1
  @skin_parts = data[:skin_parts] || Array.new(6, 'standard')
  @skin_custom_colors = data[:skin_custom_colors] || Array.new(6, 0)
  @skin_colors = data[:skin_colors] || Array.new(6, 0)

  @score = data[:score] || 0
end

Instance Attribute Details

#clanObject

Returns the value of attribute clan.



4
5
6
# File 'lib/models/player.rb', line 4

def clan
  @clan
end

#countryObject

Returns the value of attribute country.



4
5
6
# File 'lib/models/player.rb', line 4

def country
  @country
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/models/player.rb', line 4

def id
  @id
end

#localObject

Returns the value of attribute local.



4
5
6
# File 'lib/models/player.rb', line 4

def local
  @local
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/models/player.rb', line 4

def name
  @name
end

#scoreObject

Returns the value of attribute score.



4
5
6
# File 'lib/models/player.rb', line 4

def score
  @score
end

#skin_colorsObject

Returns the value of attribute skin_colors.



4
5
6
# File 'lib/models/player.rb', line 4

def skin_colors
  @skin_colors
end

#skin_custom_colorsObject

Returns the value of attribute skin_custom_colors.



4
5
6
# File 'lib/models/player.rb', line 4

def skin_custom_colors
  @skin_custom_colors
end

#skin_partsObject

Returns the value of attribute skin_parts.



4
5
6
# File 'lib/models/player.rb', line 4

def skin_parts
  @skin_parts
end

#teamObject

Returns the value of attribute team.



4
5
6
# File 'lib/models/player.rb', line 4

def team
  @team
end

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/models/player.rb', line 20

def local?
  @local
end

#set_start_info(start_info) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/models/player.rb', line 24

def set_start_info(start_info)
  raise "expected: StartInfo got: #{start_info.class}" unless start_info.instance_of?(StartInfo)

  start_info = start_info.to_h
  @name = start_info[:name]
  @clan = start_info[:clan]
  @country = start_info[:country]
  @skin_parts = [
    start_info[:body],
    start_info[:marking],
    start_info[:decoration],
    start_info[:hands],
    start_info[:feet],
    start_info[:eyes]
  ]
  @skin_custom_colors = [
    start_info[:custom_color_body],
    start_info[:custom_color_marking],
    start_info[:custom_color_decoration],
    start_info[:custom_color_hands],
    start_info[:custom_color_feet],
    start_info[:custom_color_eyes]
  ]
  @skin_colors = [
    start_info[:color_body],
    start_info[:color_marking],
    start_info[:color_decoration],
    start_info[:color_hands],
    start_info[:color_feet],
    start_info[:color_eyes]
  ]
end