Class: LZRTag::Map::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/lzrtag/map/map_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#centerpointObject

Returns the value of attribute centerpoint.



10
11
12
# File 'lib/lzrtag/map/map_set.rb', line 10

def centerpoint
  @centerpoint
end

#zonesObject (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

#clearObject



43
44
45
# File 'lib/lzrtag/map/map_set.rb', line 43

def clear()
	@mqtt.publish_to "Lasertag/Game/Zones", "", retain: true;
end

#publishObject



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_hObject



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_jsonObject



36
37
38
# File 'lib/lzrtag/map/map_set.rb', line 36

def to_json()
	return self.to_h().to_json();
end