-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathEDSystemMap.py
More file actions
143 lines (122 loc) · 5.99 KB
/
EDSystemMap.py
File metadata and controls
143 lines (122 loc) · 5.99 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from __future__ import annotations
import json
import os
from EDAP_data import GuiFocusSystemMap
from EDlogger import logger
from Screen_Regions import scale_region, Quad
from StatusParser import StatusParser
from time import sleep
class EDSystemMap:
""" Handles the System Map. """
def __init__(self, ed_ap, screen, keys, cb, is_odyssey=True):
self.ap = ed_ap
self.ocr = ed_ap.ocr
self.is_odyssey = is_odyssey
self.screen = screen
self.keys = keys
self.status_parser = StatusParser()
self.ap_ckb = cb
# The rect is top left x, y, and bottom right x, y in fraction of screen resolution
self.reg = {'full_panel': {'rect': [0.1, 0.1, 0.9, 0.9]},
'cartographics': {'rect': [0.0, 0.0, 0.25, 0.25]},
}
self.sub_reg = {'cartographics': {'rect': [0.0, 0.0, 0.15, 0.15]}}
self.load_calibrated_regions()
def load_calibrated_regions(self):
calibration_file = 'configs/ocr_calibration.json'
if os.path.exists(calibration_file):
with open(calibration_file, 'r') as f:
calibrated_regions = json.load(f)
for key, value in self.reg.items():
calibrated_key = f"EDSystemMap.{key}"
if calibrated_key in calibrated_regions:
self.reg[key]['rect'] = calibrated_regions[calibrated_key]['rect']
# Scale the regions based on the sub-region.
self.reg['cartographics']['rect'] = scale_region(self.reg['full_panel']['rect'],
self.sub_reg['cartographics']['rect'])
def set_sys_map_dest_bookmark(self, ap, bookmark_type: str, bookmark_position: int) -> bool:
""" Set the System Map destination using a bookmark.
@param ap: ED_AP reference.
@param bookmark_type: The bookmark type (Favorite, Body, Station, Settlement or Navigation), Favorite
being the default if no match is made with the other options. Navigation is unique in that it uses
the Nav Panel instead of the System Map.
@param bookmark_position: The position in the bookmark list, starting at 1 for the first bookmark.
@return: True if bookmark could be selected, else False
"""
if self.is_odyssey and bookmark_position != -1:
# Check if this is a nav-panel bookmark
if not bookmark_type.lower().startswith("nav"):
res = self.goto_system_map()
if not res:
return False
ap.keys.send('UI_Left') # Go to BOOKMARKS
sleep(.5)
ap.keys.send('UI_Select') # Select BOOKMARKS
sleep(.25)
ap.keys.send('UI_Right') # Go to FAVORITES
sleep(.25)
# If bookmark type is Fav, do nothing as this is the first item
if bookmark_type.lower().startswith("bod"):
ap.keys.send('UI_Down', repeat=1) # Go to BODIES
elif bookmark_type.lower().startswith("sta"):
ap.keys.send('UI_Down', repeat=2) # Go to STATIONS
elif bookmark_type.lower().startswith("set"):
ap.keys.send('UI_Down', repeat=3) # Go to SETTLEMENTS
sleep(.25)
ap.keys.send('UI_Select') # Select bookmark type, moves you to bookmark list
ap.keys.send('UI_Left') # Sometimes the first bookmark is not selected, so we try to force it.
ap.keys.send('UI_Right')
sleep(.25)
ap.keys.send('UI_Down', repeat=bookmark_position - 1)
sleep(.25)
ap.keys.send('UI_Select', hold=3.0)
# Close System Map
ap.keys.send('SystemMapOpen')
sleep(0.5)
return True
elif bookmark_type.lower().startswith("nav"):
# TODO - Move to, or call Nav Panel code instead?
# This is a nav-panel bookmark
# Goto cockpit view
self.ap.ship_control.goto_cockpit_view()
# get to the Left Panel menu: Navigation
ap.keys.send("HeadLookReset")
ap.keys.send("UIFocus", state=1)
ap.keys.send("UI_Left")
ap.keys.send("UIFocus", state=0) # this gets us over to the Nav panel
ap.keys.send('UI_Up', hold=4)
ap.keys.send('UI_Down', repeat=bookmark_position - 1)
sleep(1.0)
ap.keys.send('UI_Select')
sleep(0.25)
ap.keys.send('UI_Select')
ap.keys.send("UI_Back")
ap.keys.send("HeadLookReset")
return True
return False
def goto_system_map(self) -> bool:
""" Open System Map if we are not there.
"""
if self.status_parser.get_gui_focus() != GuiFocusSystemMap:
logger.debug("Opening System Map")
# Goto cockpit view
self.ap.ship_control.goto_cockpit_view()
# Goto System Map
self.ap.keys.send('SystemMapOpen')
if self.ap.debug_overlay:
stn_svcs = Quad.from_rect(self.reg['full_panel']['rect'])
self.ap.overlay.overlay_quad_pct('system map', stn_svcs, (0, 255, 0), 2, 5)
self.ap.overlay.overlay_paint()
# Wait for screen to appear. The text is the same, regardless of language.
res = self.ocr.wait_for_text(self.ap, ["CARTOGRAPHICS"], self.reg['cartographics'], timeout=15)
if not res:
if self.status_parser.get_gui_focus() != GuiFocusSystemMap:
logger.warning("Unable to open System Map")
return False
return True
else:
logger.debug("System Map is already open")
self.keys.send('UI_Left')
self.keys.send('UI_Up', hold=2)
self.keys.send('UI_Left')
return True