1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Simplify ship loadout and PaintJob handling

This commit is contained in:
Jonathan Harris 2017-04-27 23:47:15 +01:00
parent 2e63245859
commit 252e0ec654
2 changed files with 10 additions and 22 deletions

View File

@ -515,24 +515,13 @@ class AppWindow:
monitor.state['Loan'] = data['commander'].get('debt', 0) monitor.state['Loan'] = data['commander'].get('debt', 0)
self.edsm.setcredits(monitor.state['Credits'], monitor.state['Loan']) self.edsm.setcredits(monitor.state['Credits'], monitor.state['Loan'])
ship = companion.ship(data) ship = companion.ship(data)
if ship == self.edsm.lastship: if ship != self.edsm.lastship:
props = [] self.edsm.updateship(monitor.state['ShipID'],
else: monitor.state['ShipType'],
props = [ [
('linkToCoriolis', coriolis.url(data)), ('linkToCoriolis', coriolis.url(data)),
('linkToEDShipyard', edshipyard.url(data)), ('linkToEDShipyard', edshipyard.url(data)),
] ])
if monitor.state['PaintJob'] is None:
# Companion API server can lag, so prefer Journal. But paintjob only reported in Journal on change.
if monitor.state['ShipID'] != data['ship']['id']:
monitor.state['ShipID'] = data['ship']['id']
monitor.state['ShipIdent'] = None
monitor.state['ShipName'] = None
monitor.state['ShipType'] = data['ship']['name'].lower()
monitor.state['PaintJob'] = data['ship']['modules']['PaintJob'] and data['ship']['modules']['PaintJob']['module']['name'].lower() or ''
props.append(('paintJob', monitor.state['PaintJob']))
if props:
self.edsm.updateship(monitor.state['ShipID'], monitor.state['ShipType'], props)
self.edsm.lastship = ship self.edsm.lastship = ship
except Exception as e: except Exception as e:
# Not particularly important so silent on failure # Not particularly important so silent on failure
@ -765,7 +754,6 @@ class AppWindow:
elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip(): elif not data.get('ship') or not data['ship'].get('modules') or not data['ship'].get('name','').strip():
self.status['text'] = _("What are you flying?!") # Shouldn't happen self.status['text'] = _("What are you flying?!") # Shouldn't happen
elif (monitor.state['ShipID'] and data['ship']['id'] != monitor.state['ShipID']) or (monitor.state['ShipType'] and data['ship']['name'].lower() != monitor.state['ShipType']): elif (monitor.state['ShipID'] and data['ship']['id'] != monitor.state['ShipID']) or (monitor.state['ShipType'] and data['ship']['name'].lower() != monitor.state['ShipType']):
print shipname, data['ship']['name']
self.status['text'] = _('Error: Server is lagging') # Raised when Companion API server is returning old data, e.g. when the servers are too busy self.status['text'] = _('Error: Server is lagging') # Raised when Companion API server is returning old data, e.g. when the servers are too busy
else: else:
self.status['text'] = '' self.status['text'] = ''

View File

@ -346,8 +346,8 @@ class EDLogs(FileSystemEventHandler):
self.state['ShipIdent'] = entry['UserShipId'] self.state['ShipIdent'] = entry['UserShipId']
self.state['ShipName'] = entry.get('UserShipName') self.state['ShipName'] = entry.get('UserShipName')
self.state['ShipType'] = entry['Ship'].lower() self.state['ShipType'] = entry['Ship'].lower()
elif entry['event'] == 'ShipyardNew': elif entry['event'] == 'ShipyardBuy':
self.state['ShipID'] = entry['NewShipID'] self.state['ShipID'] = None
self.state['ShipIdent'] = None self.state['ShipIdent'] = None
self.state['ShipName'] = None self.state['ShipName'] = None
self.state['ShipType'] = entry['ShipType'].lower() self.state['ShipType'] = entry['ShipType'].lower()
@ -358,7 +358,7 @@ class EDLogs(FileSystemEventHandler):
self.state['ShipName'] = None self.state['ShipName'] = None
self.state['ShipType'] = entry['ShipType'].lower() self.state['ShipType'] = entry['ShipType'].lower()
self.state['PaintJob'] = None self.state['PaintJob'] = None
elif entry['event'] == 'Loadout': # Note: Precedes LoadGame, but also sent after changing ship elif entry['event'] == 'Loadout': # Note: Precedes LoadGame, ShipyardNew, follows ShipyardSwap, ShipyardBuy
self.state['ShipID'] = entry['ShipID'] self.state['ShipID'] = entry['ShipID']
self.state['ShipIdent'] = entry['ShipIdent'] self.state['ShipIdent'] = entry['ShipIdent']
self.state['ShipName'] = entry['ShipName'] self.state['ShipName'] = entry['ShipName']