Skip to content

Commit

Permalink
change alert fuel when switching ships
Browse files Browse the repository at this point in the history
  • Loading branch information
Numerlor committed Jul 29, 2019
1 parent f89f7ef commit 71e990f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 14 additions & 2 deletions hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import main_windows
import popups
import workers
from appinfo import SHIP_STATS


class Hub(QtCore.QObject):
Expand All @@ -16,7 +17,7 @@ class Hub(QtCore.QObject):
quit_worker_signal = QtCore.pyqtSignal()

stop_alert_worker_signal = QtCore.pyqtSignal()
modifier_signal = QtCore.pyqtSignal(int)
alert_fuel_signal = QtCore.pyqtSignal(int, int)

def __init__(self, settings):
super().__init__()
Expand Down Expand Up @@ -100,6 +101,7 @@ def start_worker(self, journal, data_values, index):
self.worker.sys_signal.connect(self.main_window.grayout)
self.worker.route_finished_signal.connect(self.end_route_pop)
self.worker.game_shut_signal.connect(self.restart_worker)
self.worker.fuel_signal.connect(self.get_max_fuel)
self.worker.start()

if self.visual_alert or self.sound_alert:
Expand All @@ -117,6 +119,16 @@ def restart_worker(self, route_data, route_index):
w.worker_signal.connect(self.start_worker)
w.close_signal.connect(self.main_window.disconnect_signals)

def get_max_fuel(self, json):
fsd = next(item for item in json['Modules'] if item['Slot'] == "FrameShiftDrive")
self.max_fuel = SHIP_STATS['FSD'][fsd['Item']][0]
if 'Engineering' in fsd:
for blueprint in fsd['Engineering']['Modifiers']:
if blueprint['Label'] == 'MaxFeulPerJump':
self.max_fuel = blueprint['Value']

self.alert_fuel_signal.emit(self.max_fuel, self.modifier)

def set_theme(self):
""" Set dark/default theme depending on user setting"""
if self.dark:
Expand Down Expand Up @@ -167,7 +179,7 @@ def change_editable_settings(self, values):
self.start_alert_worker()

self.modifier = values[10]
self.modifier_signal.emit(values[10])
self.alert_fuel_signal.emit(self.max_fuel, self.modifier)

self.sound_path = values[11]
self.player = workers.SoundPlayer(values[11])
Expand Down
5 changes: 4 additions & 1 deletion main_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ def current_range(self, index):
self.cargo_slider.setValue(ship_cargo)

def set_max_fuel(self, index):
print("DAS")
with open(self.journals[index], encoding='utf-8') as f:
lines = [json.loads(line) for line in f]
try:
Expand All @@ -556,6 +555,10 @@ def set_max_fuel(self, index):
fsd = next((i for i in loadout['Modules']
if i['Slot'] == "FrameShiftDrive"))
max_fuel = SHIP_STATS['FSD'][fsd['Item']][0]
if 'Engineering' in fsd:
for blueprint in fsd['Engineering']['Modifiers']:
if blueprint['Label'] == 'MaxFeulPerJump':
max_fuel = blueprint['Value']
self.fuel_signal.emit(max_fuel)

def calculate_range(self, cargo):
Expand Down
15 changes: 8 additions & 7 deletions workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AhkWorker(QtCore.QThread):
sys_signal = QtCore.pyqtSignal(int, bool) # signal to move grayout to index
route_finished_signal = QtCore.pyqtSignal() # route end reached signal
game_shut_signal = QtCore.pyqtSignal(list, int) # signal for game shutdown

fuel_signal = QtCore.pyqtSignal(dict)
def __init__(self, parent, journal, data_values, settings, start_index):
super(AhkWorker, self).__init__(parent)
self.journal = journal
Expand Down Expand Up @@ -64,6 +64,7 @@ def main(self):
self.sys_signal.emit(self.list_index, self.dark)
for line in self.follow_file(open(self.journal, encoding='utf-8')):
loaded = json.loads(line)

if (loaded['event'] == "FSDJump" and
loaded['StarSystem'].casefold() in self.systems[self.list_index:]):
self.list_index = self.systems.index(loaded['StarSystem'].casefold()) + 1
Expand All @@ -79,7 +80,8 @@ def main(self):
self.sys_signal.emit(self.list_index, self.dark)

elif loaded['event'] == "Loadout":
pass
# update max fuel for alerts
self.fuel_signal.emit(loaded)

elif loaded['event'] == "Shutdown":
self.game_shut_signal.emit(self.data_values, self.list_index)
Expand Down Expand Up @@ -167,14 +169,13 @@ class FuelAlert(QtCore.QThread):
def __init__(self, parent, max_fuel, file, modifier):
super(FuelAlert, self).__init__(parent)
self.file = file
self.max_fuel = max_fuel
self.loop = True
self.alert = False

self.set_jump_fuel(modifier)
self.set_jump_fuel(max_fuel, modifier)
parent.stop_alert_worker_signal.connect(self.stop_loop)
parent.next_jump_signal.connect(self.change_alert)
parent.modifier_signal.connect(self.set_jump_fuel)
parent.alert_fuel_signal.connect(self.set_jump_fuel)

def run(self):
self.main(self.file)
Expand All @@ -199,8 +200,8 @@ def main(self, path):
except KeyError:
pass

def set_jump_fuel(self, modifier):
self.jump_fuel = self.max_fuel * modifier / 100
def set_jump_fuel(self, max_fuel, modifier):
self.jump_fuel = max_fuel * modifier / 100

def change_alert(self, status):
self.alert = status
Expand Down

0 comments on commit 71e990f

Please sign in to comment.