Class: LZRTag::Map::Set
- Inherits:
-
Object
- Object
- LZRTag::Map::Set
- Defined in:
- lib/lzrtag/map/map_set.rb
Instance Attribute Summary collapse
-
#centerpoint ⇒ Object
Returns the value of attribute centerpoint.
-
#zones ⇒ Object
readonly
Returns the value of attribute zones.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(mqtt, zones = Array.new()) ⇒ Set
constructor
A new instance of Set.
- #publish ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(mqtt, zones = Array.new()) ⇒ Set
Returns a new instance of Set.
12 13 14 15 16 17 |
# File 'lib/lzrtag/map/map_set.rb', line 12 def initialize(mqtt, zones = Array.new()) @mqtt = mqtt; @zones = zones; @centerpoint = Array.new(); end |
Instance Attribute Details
#centerpoint ⇒ Object
Returns the value of attribute centerpoint.
10 11 12 |
# File 'lib/lzrtag/map/map_set.rb', line 10 def centerpoint @centerpoint end |
#zones ⇒ Object (readonly)
Returns the value of attribute zones.
8 9 10 |
# File 'lib/lzrtag/map/map_set.rb', line 8 def zones @zones end |
Instance Method Details
#clear ⇒ Object
43 44 45 |
# File 'lib/lzrtag/map/map_set.rb', line 43 def clear() @mqtt.publish_to "Lasertag/Game/Zones", "", retain: true; end |
#publish ⇒ Object
40 41 42 |
# File 'lib/lzrtag/map/map_set.rb', line 40 def publish() @mqtt.publish_to "Lasertag/Zones", self.to_json, qos: 1, retain: true; end |
#to_h ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lzrtag/map/map_set.rb', line 19 def to_h() outData = Hash.new(); if(@centerpoint.length != 3) raise ArgumentError, "Center point needs to be set!" end outData[:centerpoint] = @centerpoint outData[:zones] = Array.new(); @zones.each do |z| outData[:zones] << z.to_h; end return outData; end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/lzrtag/map/map_set.rb', line 36 def to_json() return self.to_h().to_json(); end |