mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 03:42:16 +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.events = [] # Unsent events
|
||||||
this.cmdr = None
|
this.cmdr = None
|
||||||
this.multicrew = False # don't send captain's ship info to Inara while on a crew
|
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.undocked = False # just undocked
|
||||||
this.suppress_docked = False # Skip initial Docked event if started docked
|
this.suppress_docked = False # Skip initial Docked event if started docked
|
||||||
this.cargo = None
|
this.cargo = None
|
||||||
@ -169,8 +170,15 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
this.cmdr = cmdr
|
this.cmdr = cmdr
|
||||||
this.multicrew = bool(state['Role'])
|
this.multicrew = bool(state['Role'])
|
||||||
|
|
||||||
if entry['event'] == 'LoadGame':
|
if entry['event'] == 'LoadGame' or this.newuser:
|
||||||
# clear cached state
|
# 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.undocked = False
|
||||||
this.suppress_docked = False
|
this.suppress_docked = False
|
||||||
this.cargo = None
|
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).
|
# 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.
|
# 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):
|
if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(cmdr):
|
||||||
try:
|
try:
|
||||||
old_events = len(this.events) # Will only send existing events if we add a new event below
|
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
|
# Dump starting state to Inara
|
||||||
if (entry['event'] in ['StartUp', 'Cargo'] or this.newuser):
|
|
||||||
|
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():
|
for k,v in state['Rank'].iteritems():
|
||||||
if v is not None:
|
if v is not None:
|
||||||
add_event('setCommanderRankPilot', entry['timestamp'],
|
add_event('setCommanderRankPilot', entry['timestamp'],
|
||||||
@ -215,6 +230,34 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
('majorfactionReputation', v / 100.0),
|
('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':
|
elif entry['event'] == 'Promotion':
|
||||||
for k,v in state['Rank'].iteritems():
|
for k,v in state['Rank'].iteritems():
|
||||||
if k in entry:
|
if k in entry:
|
||||||
@ -224,9 +267,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
('rankValue', v[0]),
|
('rankValue', v[0]),
|
||||||
('rankProgress', 0),
|
('rankProgress', 0),
|
||||||
]))
|
]))
|
||||||
|
elif entry['event'] == 'EngineerProgress':
|
||||||
# Send engineer status to Inara on change (not available on startup)
|
|
||||||
if entry['event'] == 'EngineerProgress':
|
|
||||||
if 'Rank' in entry:
|
if 'Rank' in entry:
|
||||||
add_event('setCommanderRankEngineer', entry['timestamp'],
|
add_event('setCommanderRankEngineer', entry['timestamp'],
|
||||||
OrderedDict([
|
OrderedDict([
|
||||||
@ -240,7 +281,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
('rankStage', entry['Progress']),
|
('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':
|
if entry['event'] == 'PowerplayJoin':
|
||||||
add_event('setCommanderRankPower', entry['timestamp'],
|
add_event('setCommanderRankPower', entry['timestamp'],
|
||||||
OrderedDict([
|
OrderedDict([
|
||||||
@ -260,11 +301,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
('rankValue', 1),
|
('rankValue', 1),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
# Update ship
|
# Ship change
|
||||||
if (state['ShipID'] and # Unknown if started in Fighter or SRV
|
if entry['event'] == 'Loadout' and this.shipswap:
|
||||||
(entry['event'] in ['StartUp', 'Cargo'] or
|
|
||||||
(entry['event'] == 'Loadout' and this.shipswap) or
|
|
||||||
this.newuser)):
|
|
||||||
data = OrderedDict([
|
data = OrderedDict([
|
||||||
('shipType', state['ShipType']),
|
('shipType', state['ShipType']),
|
||||||
('shipGameID', state['ShipID']),
|
('shipGameID', state['ShipID']),
|
||||||
@ -283,17 +321,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
||||||
this.shipswap = False
|
this.shipswap = False
|
||||||
|
|
||||||
# Update location
|
# Location change
|
||||||
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
|
|
||||||
]))
|
|
||||||
|
|
||||||
elif entry['event'] == 'Docked':
|
elif entry['event'] == 'Docked':
|
||||||
if this.undocked:
|
if this.undocked:
|
||||||
# Undocked and now docking again. Don't send.
|
# 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']),
|
('shipType', state['ShipType']),
|
||||||
('shipGameID', state['ShipID']),
|
('shipGameID', state['ShipID']),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
elif entry['event'] == 'Undocked':
|
elif entry['event'] == 'Undocked':
|
||||||
this.undocked = True
|
this.undocked = True
|
||||||
this.station = None
|
this.station = None
|
||||||
|
|
||||||
elif entry['event'] == 'SupercruiseEntry':
|
elif entry['event'] == 'SupercruiseEntry':
|
||||||
if this.undocked:
|
if this.undocked:
|
||||||
# Staying in system after undocking - send any pending events from in-station action
|
# 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']),
|
('shipGameID', state['ShipID']),
|
||||||
]))
|
]))
|
||||||
this.undocked = False
|
this.undocked = False
|
||||||
|
|
||||||
elif entry['event'] == 'FSDJump':
|
elif entry['event'] == 'FSDJump':
|
||||||
this.undocked = False
|
this.undocked = False
|
||||||
this.system = None
|
this.system = None
|
||||||
@ -457,7 +482,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
|
|||||||
add_event('setCommanderShip', entry['timestamp'], ship)
|
add_event('setCommanderShip', entry['timestamp'], ship)
|
||||||
|
|
||||||
# Loadout
|
# Loadout
|
||||||
if entry['event'] == 'Loadout':
|
if entry['event'] == 'Loadout' and not this.newsession:
|
||||||
loadout = make_loadout(state)
|
loadout = make_loadout(state)
|
||||||
if this.loadout != loadout:
|
if this.loadout != loadout:
|
||||||
this.loadout = loadout
|
this.loadout = loadout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user