mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-16 01:00:42 +03:00
Rationalise startup handling
This commit is contained in:
parent
8f835b49eb
commit
2f7ffc6c31
@ -35,7 +35,8 @@ this.queue = Queue() # Items to be sent to Inara by worker thread
|
||||
this.events = [] # Unsent events
|
||||
this.cmdr = None
|
||||
this.multicrew = False # don't send captain's ship info to Inara while on a crew
|
||||
this.newuser = False # just entered API Key
|
||||
this.newuser = False # just entered API Key - send state immediately
|
||||
this.newsession = True # starting a new session - wait for Cargo event
|
||||
this.undocked = False # just undocked
|
||||
this.suppress_docked = False # Skip initial Docked event if started docked
|
||||
this.cargo = None
|
||||
@ -169,8 +170,15 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
this.cmdr = cmdr
|
||||
this.multicrew = bool(state['Role'])
|
||||
|
||||
if entry['event'] == 'LoadGame':
|
||||
if entry['event'] == 'LoadGame' or this.newuser:
|
||||
# clear cached state
|
||||
if entry['event'] == 'LoadGame':
|
||||
# User setup Inara API while at the loading screen - proceed as for new session
|
||||
this.newuser = False
|
||||
this.newsession = True
|
||||
else:
|
||||
this.newuser = True
|
||||
this.newsession = False
|
||||
this.undocked = False
|
||||
this.suppress_docked = False
|
||||
this.cargo = None
|
||||
@ -190,15 +198,22 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
|
||||
|
||||
# Send location and status on new game or StartUp. Assumes Cargo is the last event on a new game (other than Docked).
|
||||
# Always send an update on Docked, FSDJump, Undocked+SuperCruise, Promotion and EngineerProgress.
|
||||
# Always send an update on Docked, FSDJump, Undocked+SuperCruise, Promotion, EngineerProgress and PowerPlay affiliation.
|
||||
# Also send material and cargo (if changed) whenever we send an update.
|
||||
|
||||
if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(cmdr):
|
||||
try:
|
||||
old_events = len(this.events) # Will only send existing events if we add a new event below
|
||||
|
||||
# Send rank info to Inara on startup or change
|
||||
if (entry['event'] in ['StartUp', 'Cargo'] or this.newuser):
|
||||
# Dump starting state to Inara
|
||||
|
||||
if (this.newuser or
|
||||
entry['event'] == 'StartUp' or
|
||||
(this.newsession and entry['event'] == 'Cargo')):
|
||||
this.newuser = False
|
||||
this.newsession = False
|
||||
|
||||
# Send rank info to Inara on startup
|
||||
for k,v in state['Rank'].iteritems():
|
||||
if v is not None:
|
||||
add_event('setCommanderRankPilot', entry['timestamp'],
|
||||
@ -215,6 +230,34 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('majorfactionReputation', v / 100.0),
|
||||
]))
|
||||
|
||||
# Update location
|
||||
add_event('setCommanderTravelLocation', entry['timestamp'],
|
||||
OrderedDict([
|
||||
('starsystemName', system),
|
||||
('stationName', station), # Can be None
|
||||
]))
|
||||
|
||||
# Update ship
|
||||
if state['ShipID']: # Unknown if started in Fighter or SRV
|
||||
data = OrderedDict([
|
||||
('shipType', state['ShipType']),
|
||||
('shipGameID', state['ShipID']),
|
||||
('shipName', state['ShipName']), # Can be None
|
||||
('shipIdent', state['ShipIdent']), # Can be None
|
||||
('isCurrentShip', True),
|
||||
])
|
||||
if state['HullValue']:
|
||||
data['shipHullValue'] = state['HullValue']
|
||||
if state['ModulesValue']:
|
||||
data['shipModulesValue'] = state['ModulesValue']
|
||||
data['shipRebuyCost'] = state['Rebuy']
|
||||
add_event('setCommanderShip', entry['timestamp'], data)
|
||||
|
||||
this.loadout = make_loadout(state)
|
||||
add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
||||
|
||||
|
||||
# Promotions
|
||||
elif entry['event'] == 'Promotion':
|
||||
for k,v in state['Rank'].iteritems():
|
||||
if k in entry:
|
||||
@ -224,9 +267,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('rankValue', v[0]),
|
||||
('rankProgress', 0),
|
||||
]))
|
||||
|
||||
# Send engineer status to Inara on change (not available on startup)
|
||||
if entry['event'] == 'EngineerProgress':
|
||||
elif entry['event'] == 'EngineerProgress':
|
||||
if 'Rank' in entry:
|
||||
add_event('setCommanderRankEngineer', entry['timestamp'],
|
||||
OrderedDict([
|
||||
@ -240,7 +281,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('rankStage', entry['Progress']),
|
||||
]))
|
||||
|
||||
# Send PowerPlay status to Inara on change (not available on startup, and promotion not available at all)
|
||||
# PowerPlay status change
|
||||
if entry['event'] == 'PowerplayJoin':
|
||||
add_event('setCommanderRankPower', entry['timestamp'],
|
||||
OrderedDict([
|
||||
@ -260,11 +301,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('rankValue', 1),
|
||||
]))
|
||||
|
||||
# Update ship
|
||||
if (state['ShipID'] and # Unknown if started in Fighter or SRV
|
||||
(entry['event'] in ['StartUp', 'Cargo'] or
|
||||
(entry['event'] == 'Loadout' and this.shipswap) or
|
||||
this.newuser)):
|
||||
# Ship change
|
||||
if entry['event'] == 'Loadout' and this.shipswap:
|
||||
data = OrderedDict([
|
||||
('shipType', state['ShipType']),
|
||||
('shipGameID', state['ShipID']),
|
||||
@ -283,17 +321,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
||||
this.shipswap = False
|
||||
|
||||
# Update location
|
||||
if (entry['event'] in ['StartUp', 'Cargo'] or this.newuser) and system:
|
||||
this.undocked = False
|
||||
this.system = None
|
||||
this.station = None
|
||||
add_event('setCommanderTravelLocation', entry['timestamp'],
|
||||
OrderedDict([
|
||||
('starsystemName', system),
|
||||
('stationName', station), # Can be None
|
||||
]))
|
||||
|
||||
# Location change
|
||||
elif entry['event'] == 'Docked':
|
||||
if this.undocked:
|
||||
# Undocked and now docking again. Don't send.
|
||||
@ -309,11 +337,9 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('shipType', state['ShipType']),
|
||||
('shipGameID', state['ShipID']),
|
||||
]))
|
||||
|
||||
elif entry['event'] == 'Undocked':
|
||||
this.undocked = True
|
||||
this.station = None
|
||||
|
||||
elif entry['event'] == 'SupercruiseEntry':
|
||||
if this.undocked:
|
||||
# Staying in system after undocking - send any pending events from in-station action
|
||||
@ -324,7 +350,6 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
('shipGameID', state['ShipID']),
|
||||
]))
|
||||
this.undocked = False
|
||||
|
||||
elif entry['event'] == 'FSDJump':
|
||||
this.undocked = False
|
||||
this.system = None
|
||||
@ -457,7 +482,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||||
add_event('setCommanderShip', entry['timestamp'], ship)
|
||||
|
||||
# Loadout
|
||||
if entry['event'] == 'Loadout':
|
||||
if entry['event'] == 'Loadout' and not this.newsession:
|
||||
loadout = make_loadout(state)
|
||||
if this.loadout != loadout:
|
||||
this.loadout = loadout
|
||||
|
Loading…
x
Reference in New Issue
Block a user