mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 08:40:34 +03:00
There is one tiny regression for a very, very corner case. In 3.46 if you use EDDB as the 'Station' provider and: 1. Dock at Station A, in System X 2. Jump out to System Y, which is also populated 3. Exit out of the game 4. (Re-)Start EDMC 5. Hit 'Update' to manually trigger CAPI data retrieval you will see a "×" character as the Station Name, and can click on it to take you to the EDDB *System* page. It is only there because of EDMC using systems.p to check if System Y is populated. With this version in that circumstance there's no way to know that System Y is populated, so the code assumes not and doesn't show the "×", and thus there's nothing to click to go to the EDDB *System* page for System Y. But so long as the user is actually running the game and EDMC together then populated status is detected from Journal events and the "×" will be there whenever you're undocked but in a populated system. Caveat: We know Frontier have allowed some systems that are technically populated, but show a Population of zero. This code assumes that means they're *not* populated.
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
#
|
||
# Station display and eddb.io lookup
|
||
#
|
||
|
||
import pickle
|
||
import csv
|
||
import os
|
||
from os.path import join
|
||
import sys
|
||
import urllib.parse
|
||
|
||
from config import config
|
||
|
||
|
||
STATION_UNDOCKED = u'×' # "Station" name to display when not docked = U+00D7
|
||
|
||
this = sys.modules[__name__] # For holding module globals
|
||
|
||
# (system_id, is_populated) by system_name
|
||
with open(join(config.respath, 'systems.p'), 'rb') as h:
|
||
this.system_ids = pickle.load(h)
|
||
|
||
# station_id by (system_id, station_name)
|
||
with open(join(config.respath, 'stations.p'), 'rb') as h:
|
||
this.station_ids = pickle.load(h)
|
||
|
||
|
||
# Main window clicks
|
||
def system_url(system_name):
|
||
if system_name:
|
||
return 'https://eddb.io/system/name/%s' % urllib.parse.quote(system_name)
|
||
else:
|
||
return ''
|
||
|
||
|
||
def station_url(system_name, station_name):
|
||
if this.station_marketid:
|
||
return 'https://eddb.io/station/market-id/{}'.format(this.station_marketid)
|
||
else:
|
||
return system_url(system_name)
|
||
|
||
|
||
def plugin_start3(plugin_dir):
|
||
return 'eddb'
|
||
|
||
def plugin_app(parent):
|
||
this.system_link = parent.children['system'] # system label in main window
|
||
this.system_population = None
|
||
this.station_marketid = None # Frontier MarketID
|
||
this.station_link = parent.children['station'] # station label in main window
|
||
this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED)
|
||
|
||
def prefs_changed(cmdr, is_beta):
|
||
if config.get('system_provider') == 'eddb':
|
||
this.system_link['url'] = system_url(system_link['text']) # Override standard URL function
|
||
|
||
|
||
def journal_entry(cmdr, is_beta, system, station, entry, state):
|
||
if config.get('system_provider') == 'eddb':
|
||
this.system_link['url'] = system_url(system) # Override standard URL function
|
||
|
||
if config.get('station_provider') == 'eddb':
|
||
if entry['event'] in ['StartUp', 'Location', 'FSDJump', 'CarrierJump']:
|
||
this.system_population = entry.get('Population')
|
||
|
||
if entry['event'] in ['StartUp', 'Location', 'Docked', 'CarrierJump']:
|
||
this.station_marketid = entry.get('MarketID')
|
||
elif entry['event'] in ['Undocked']:
|
||
this.station_marketid = None
|
||
|
||
this.station_link['text'] = station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '')
|
||
this.station_link.update_idletasks()
|
||
|
||
|
||
def cmdr_data(data, is_beta):
|
||
if config.get('system_provider') == 'eddb':
|
||
this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function
|
||
|
||
if config.get('station_provider') == 'eddb':
|
||
this.station_marketid = data['commander']['docked'] and data['lastStarport']['id']
|
||
this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (data['lastStarport']['name'] and data['lastStarport']['name'] != "" and STATION_UNDOCKED or '')
|
||
this.station_link.update_idletasks()
|