-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocations_parser.py
More file actions
94 lines (75 loc) · 3.4 KB
/
locations_parser.py
File metadata and controls
94 lines (75 loc) · 3.4 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""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:
location.py
Functions:
locations_parser()
"""
from location import Location
def locations_parser(campaign_directory: str) -> list[Location]:
"""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:
locations: list[Location] = []
current_location_id = -2
# Done to appease MyPy
current_location: Location = Location()
for line in campaign_data:
if line.strip() == "[Locations]":
current_location_id = -1
continue
if current_location_id == -2:
continue
if line.strip() == "[SOSUS]" or line.strip() == "[PLAYER MISSIONS]":
current_location_id = -2
if current_location_id != -1:
locations.append(current_location)
continue
if line.strip().startswith("Alignment"):
if current_location_id != -1:
locations.append(current_location)
current_location = Location()
current_location_id += 1
current_location.location_id = current_location_id
current_location.alignment = line.strip().split("=")[1]
if line.strip().startswith("BaseMapPosition"):
current_location.map_position = (
float(line.split("=")[1].split(",")[0]),
float(line.split("=")[1].split(",")[1]),
)
if line.strip().startswith("Function"):
current_location.functions = line.strip().split("=")[1].split(",")
if line.strip().startswith("RelatedSOSUS"):
current_location.related_sosus = (
line.strip().split("=")[1].split(",")
)
if line.strip().startswith("AircraftType"):
current_location.default_aircraft = (
line.strip().split("=")[1].split(",")
)
if line.strip().startswith("AircraftTypeInvaded"):
current_location.invaded_aircraft = (
line.strip().split("=")[1].split(",")
)
if line.strip().startswith("MissionTypes"):
current_location.mission_types = (
line.strip().split("=")[1].split(",")
)
if line.strip().startswith("LinksToWaypoint"):
current_location.sea_waypoints = (
line.strip().split("=")[1].split(",")
)
if line.strip().startswith("LinksToReigonWaypoint"):
current_location.land_waypoints = (
line.strip().split("=")[1].split(",")
)
return locations
except FileNotFoundError:
return []