-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsosus_parser.py
More file actions
74 lines (58 loc) · 2.53 KB
/
sosus_parser.py
File metadata and controls
74 lines (58 loc) · 2.53 KB
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
"""This file contains the code used to parse all the locations
in campaign_data and give it back to the campaign_data object
Imports From:
sosus.py
Functions:
sosus_parser()
"""
from sosus import SOSUS
def sosus_parser(campaign_directory: str) -> list[SOSUS]:
"""Generate a list of Locations given a read campaign data file
Parameters:
campaign_directory: str | A filepath to a campaign data file containing Locations
Returns:
list[Locations] | A list of parsed Locations
"""
try:
with open(
f"{campaign_directory}\\campaign_data.txt", mode="r", encoding="utf-8"
) as campaign_data:
sosus_list: list[SOSUS] = []
reading_sosus = False
# Done to appease MyPy
current_sosus: SOSUS = SOSUS()
for line in campaign_data:
if line.strip() == "[SOSUS]":
reading_sosus = True
continue
if not reading_sosus:
continue
if line.strip() == "[PLAYER MISSIONS]":
reading_sosus = False
if current_sosus.name != "":
sosus_list.append(current_sosus)
continue
if line.strip().startswith("SOSUSName"):
if current_sosus.name != "":
sosus_list.append(current_sosus)
current_sosus = SOSUS()
current_sosus.name = line.strip().split("=")[1]
if line.strip().startswith("SOSUSStartPosition"):
current_sosus.start_location = (
float(line.split("=")[1].split(",")[0]),
float(line.split("=")[1].split(",")[1]),
)
if line.strip().startswith("SOSUSEndPosition"):
current_sosus.end_location = (
float(line.split("=")[1].split(",")[0]),
float(line.split("=")[1].split(",")[1]),
)
if line.strip().startswith("SOSUSAngle"):
current_sosus.angle = int(line.strip().split("=")[1])
if line.strip().startswith("SOSUSDetectionRange"):
current_sosus.detection_range = int(line.strip().split("=")[1])
if line.strip().startswith("SOSUSAlignment"):
current_sosus.alignment = line.strip().split("=")[1]
return sosus_list
except FileNotFoundError:
return []