forked from bozogs/vesseldataviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vessel.py
78 lines (64 loc) · 2.45 KB
/
vessel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import xml.etree.ElementTree as ET
class Vessel(object):
def __init__(self):
self.id = ""
self.side = ""
self.classname = ""
self.broadType = ""
self.front_shield = 0
self.back_shield = 0
self.description = ""
self.arcwidth = 0.0
self.arc_width_extent = 0.0
self.arc_x = 0.0
self.arc_x_start = 0.0
self.ordnance = {
"trp": 0,
"nuk": 0,
"min": 0,
"emp": 0,
"shk": 0,
"bea": 0,
"pro": 0,
"tag": 0
}
def setup(self, uid, xml_path):
tree = ET.parse(xml_path)
if not tree:
exit("No data")
self.root = tree.getroot()
self.id = uid
self._getArcData()
self._getOrdData()
return True
def _getArcData(self):
uid = self.id
root = self.root
vessel_arcwidth = \
root.find(".//vessel[@uniqueID='" + uid + "']/beam_port").attrib['arcwidth']
vessel_arc_x = \
self.root.find(".//vessel[@uniqueID='" + uid + "']/beam_port").attrib['x']
vessel_front_shield = root.find(".//vessel[@uniqueID='" + uid + "']/shields").attrib['front']
vessel_back_shield = root.find(".//vessel[@uniqueID='" + uid + "']/shields").attrib['back']
vessel_arc_width_extent = 360 * float(vessel_arcwidth)
vessel_arc_width_extent_half = round(vessel_arc_width_extent / 2)
#print(vessel_arc_width_extent)
if vessel_arc_x < "0":
vessel_arc_x_start = round((360 - float(vessel_arc_x)) + (90 + vessel_arc_width_extent_half))
#print("if:"+vessel_arc_x)
else:
vessel_arc_x_start = round((0 + float(vessel_arc_x)) + (90 - vessel_arc_width_extent_half))
#print("else:" + vessel_arc_x)
self.front_shield = vessel_front_shield
self.back_shield = vessel_back_shield
self.arcwidth = vessel_arcwidth
self.arc_width_extent = vessel_arc_width_extent
self.arc_x = vessel_arc_x
self.arc_x_start = vessel_arc_x_start
def _getOrdData(self):
root = self.root
uid = self.id
for ord_type in self.ordnance.keys():
elem = root.find(".//vessel[@uniqueID='" + uid + "']/torpedo_storage[@type='" + ord_type + "']")
if elem is not None:
self.ordnance[ord_type] = elem.attrib['amount']