diff --git a/.gitignore b/.gitignore index bfd776d..d056835 100644 --- a/.gitignore +++ b/.gitignore @@ -107,4 +107,8 @@ venv.bak/ .mypy_cache/ # VSCode -.vscode/ \ No newline at end of file +.vscode/ +.vs/ +/config.py +/myNotebook.py +/l10n.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/EDMC-Discord-Presence.iml b/.idea/EDMC-Discord-Presence.iml new file mode 100644 index 0000000..86df155 --- /dev/null +++ b/.idea/EDMC-Discord-Presence.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..72a8a68 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e19d45e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/L10n/en.template b/L10n/en.template new file mode 100644 index 0000000..18de470 --- /dev/null +++ b/L10n/en.template @@ -0,0 +1,44 @@ +/* Language name */ +"!Language" = "English"; + +/* Idle message. [load.py] */ +"Connecting CMDR Interface" = "Connecting CMDR Interface" + +/* Details of system. [load.py] */ +"In system {system}" = "In system {system}" + +/* If docked. [load.py] */ +"Docked at {station}" = "Docked at {station}" + +/* While jumping. [load.py] */ +"Jumping" = "Jumping" + +/* If Hyperspace jumping. [load.py] */ +"Jumping to system {system}" = "Jumping to system {system}" + +/* If Supercruise jumping. [load.py] */ +"Preparing for supercruise" = "Preparing for supercruise" + +/* When supercruising. [load.py] */ +"Supercruising" = "Supercruising" + +/* When in normal space. [load.py] */ +"Flying in normal space" = "Flying in normal space" + +/* When in normal space and near a station. [load.py] */ +"Flying near {station}" = "Flying near {station}" + +/* When approaching a body. [load.py] */ +"Approaching {body}" = "Approaching {body}" + +/* When landed on a body. [load.py] */ +"Landed on {body}" = "Landed on {body}" + +/* After taking off from a body. [load.py] */ +"Flying around {body}" = "Flying around {body}" + +/* When in SRV. [load.py] */ +"In SRV on {body}" = "In SRV on {body}" + +/* When in SRV and ship has taken off. [load.py] */ +"In SRV on {body}, ship in orbit" = "In SRV on {body}, ship in orbit" diff --git a/L10n/fr.strings b/L10n/fr.strings new file mode 100644 index 0000000..006ebe9 --- /dev/null +++ b/L10n/fr.strings @@ -0,0 +1,44 @@ +/* Language name */ +"!Language" = "Français"; + +/* Idle message. [load.py] */ +"Connecting CMDR Interface" = "Interfaçage au Vaissea" + +/* Details of system. [load.py] */ +"In system {system}" = "Dans le système {system}" + +/* If docked. [load.py] */ +"Docked at {station}" = "Docké à {station}" + +/* While jumping. [load.py] */ +"Jumping" = "Saut" + +/* If Hyperspace jumping. [load.py] */ +"Jumping to system {system}" = "Saut vers {system}" + +/* If Supercruise jumping. [load.py] */ +"Preparing for supercruise" = "Préparation d\'un saut en supercruise" + +/* When supercruising. [load.py] */ +"Supercruising" = "Supercruise" + +/* When in normal space. [load.py] */ +"Flying in normal space" = "En vol dans l\'espace" + +/* When in normal space and near a station. [load.py] */ +"Flying near {station}" = "En vol près de {station}" + +/* When approaching a body. [load.py] */ +"Approaching {body}" = "En approche de {body}" + +/* When landed on a body. [load.py] */ +"Landed on {body}" = "Posé sur {body}" + +/* After taking off from a body. [load.py] */ +"Flying around {body}" = "Vol autour de {body}" + +/* When in SRV. [load.py] */ +"In SRV on {body}" = "En SRV sur {body}" + +/* When in SRV and ship has taken off. [load.py] */ +"In SRV on {body}, ship in orbit" = "En SRV sur {body}, vaisseau en orbite" diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..b723d01 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..9a51a28 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "7e7ef69da7248742e869378f8421880cf8f0017f96d94d086813baa518a65489" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/README.md b/README.md index a25610b..1eb5188 100644 Binary files a/README.md and b/README.md differ diff --git a/load.py b/load.py index 04aaafd..4a84f63 100644 --- a/load.py +++ b/load.py @@ -19,14 +19,21 @@ import sys import time import ctypes -import Tkinter as tk +import tkinter as tk import myNotebook as nb from config import config +import l10n +import functools -CLIENT_ID = '386149818227097610' +_ = functools.partial(l10n.Translations.translate, context=__file__) -VERSION = '1.1.0' +CLIENT_ID = b'386149818227097610' +VERSION = '2.0.0' + +# Add global var for Planet name (landing + around) +planet = '' +landingPad = '2' # # From discrod-rpc.h # @@ -40,15 +47,15 @@ class DiscordRichPresence(ctypes.Structure): _fields_ = [ - ('state', ctypes.c_char_p), # max 128 bytes - ('details', ctypes.c_char_p), # max 128 bytes + ('state', ctypes.c_char_p), # max 128 bytes + ('details', ctypes.c_char_p), # max 128 bytes ('startTimestamp', ctypes.c_int64), ('endTimestamp', ctypes.c_int64), ('largeImageKey', ctypes.c_char_p), # max 32 bytes ('largeImageText', ctypes.c_char_p), # max 128 bytes ('smallImageKey', ctypes.c_char_p), # max 32 bytes ('smallImageText', ctypes.c_char_p), # max 128 bytes - ('partyId', ctypes.c_char_p), # max 128 bytes + ('partyId', ctypes.c_char_p), # max 128 bytes ('partySize', ctypes.c_int), ('partyMax', ctypes.c_int), ('matchSecret', ctypes.c_char_p), # max 128 bytes @@ -68,9 +75,9 @@ class DiscordJoinRequest(ctypes.Structure): ReadyProc = ctypes.CFUNCTYPE(None) DisconnectedProc = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p) # errorCode, message -ErroredProc = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p) # errorCode, message -JoinGameProc = ctypes.CFUNCTYPE(None, ctypes.c_char_p) # joinSecret -SpectateGameProc = ctypes.CFUNCTYPE(None, ctypes.c_char_p) # spectateSecret +ErroredProc = ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p) # errorCode, message +JoinGameProc = ctypes.CFUNCTYPE(None, ctypes.c_char_p) # joinSecret +SpectateGameProc = ctypes.CFUNCTYPE(None, ctypes.c_char_p) # spectateSecret JoinRequestProc = ctypes.CFUNCTYPE(None, ctypes.POINTER(DiscordJoinRequest)) @@ -85,10 +92,11 @@ class DiscordEventHandlers(ctypes.Structure): ] -DISCORD_REPLY_NO, DISCORD_REPLY_YES, DISCORD_REPLY_IGNORE = range(3) +DISCORD_REPLY_NO, DISCORD_REPLY_YES, DISCORD_REPLY_IGNORE = list(range(3)) Discord_Initialize = discord_rpc.Discord_Initialize -Discord_Initialize.argtypes = [ctypes.c_char_p, ctypes.POINTER(DiscordEventHandlers), ctypes.c_int, ctypes.c_char_p] # applicationId, handlers, autoRegister, optionalSteamId +Discord_Initialize.argtypes = [ctypes.c_char_p, ctypes.POINTER(DiscordEventHandlers), ctypes.c_int, + ctypes.c_char_p] # applicationId, handlers, autoRegister, optionalSteamId Discord_Shutdown = discord_rpc.Discord_Shutdown Discord_Shutdown.argtypes = None Discord_UpdatePresence = discord_rpc.Discord_UpdatePresence @@ -96,33 +104,34 @@ class DiscordEventHandlers(ctypes.Structure): Discord_Respond = discord_rpc.Discord_Respond Discord_Respond.argtypes = [ctypes.c_char_p, ctypes.c_int] # userid, reply + # # Callback handlers # def ready(): - print 'ready' + print('ready') def disconnected(errorCode, message): - print 'disconnected', errorCode, message + print('disconnected', errorCode, message) def errored(errorCode, message): - print 'errored', errorCode, message + print('errored', errorCode, message) def joinGame(joinSecret): - print 'joinGame', joinSecret + print('joinGame', joinSecret) def spectateGame(spectateSecret): - print 'spectateGame', spectateSecret + print('spectateGame', spectateSecret) def joinRequest(request): - print 'joinRequest', request.userId, request.username, request.avatar + print('joinRequest', request.userId, request.username, request.avatar) event_handlers = DiscordEventHandlers(ReadyProc(ready), @@ -134,20 +143,22 @@ def joinRequest(request): Discord_Initialize(CLIENT_ID, event_handlers, True, None) -this = sys.modules[__name__] # For holding module globals +this = sys.modules[__name__] # For holding module globals -this.presence_state = 'Connecting CMDR Interface' -this.presence_details = '' +this.presence_state = _('Connecting CMDR Interface').encode() +this.presence_details = b'' this.time_start = time.time() + def update_presence(): presence = DiscordRichPresence() - if config.getint("disable_presence")==0: + if config.getint("disable_presence") == 0: presence.state = this.presence_state presence.details = this.presence_details presence.startTimestamp = int(this.time_start) Discord_UpdatePresence(presence) + this.disablePresence = None @@ -162,6 +173,7 @@ def plugin_prefs(parent, cmdr, is_beta): return frame + def prefs_changed(cmdr, is_beta): """ Save settings. @@ -169,6 +181,12 @@ def prefs_changed(cmdr, is_beta): config.set('disable_presence', this.disablePresence.get()) update_presence() + +def plugin_start3(plugin_dir): + update_presence() + return 'DiscordPresence' + + def plugin_start(): update_presence() return 'DiscordPresence' @@ -179,45 +197,70 @@ def plugin_stop(): def journal_entry(cmdr, is_beta, system, station, entry, state): + global planet + global landingPad if entry['event'] == 'StartUp': - this.presence_state = 'In %s' % system + this.presence_state = _('In system {system}').format(system=system).encode() if station is None: - this.presence_details = 'Flying in normal space' + this.presence_details = _('Flying in normal space').encode() else: - this.presence_details = 'Docked at %s' % station + this.presence_details = _('Docked at {station}').format(station=station).encode() elif entry['event'] == 'Location': - this.presence_state = 'In %s' % system + this.presence_state = _('In system {system}').format(system=system).encode() if station is None: - this.presence_details = 'Flying in normal space' + this.presence_details = _('Flying in normal space').encode() else: - this.presence_details = 'Docked at %s' % station + this.presence_details = _('Docked at {station}').format(station=station).encode() elif entry['event'] == 'StartJump': - this.presence_state = 'Jumping' + this.presence_state = _('Jumping').encode() if entry['JumpType'] == 'Hyperspace': - this.presence_details = 'Jumping to %s' % entry['StarSystem'] + this.presence_details = _('Jumping to system {system}').format(system=entry['StarSystem']).encode() elif entry['JumpType'] == 'Supercruise': - this.presence_details = 'Preparing for supercruise' + this.presence_details = _('Preparing for supercruise').encode() elif entry['event'] == 'SupercruiseEntry': - this.presence_state = 'In %s' % system - this.presence_details = 'Supercruising' + this.presence_state = _('In system {system}').format(system=system).encode() + this.presence_details = _('Supercruising').encode() elif entry['event'] == 'SupercruiseExit': - this.presence_state = 'In %s' % system - this.presence_details = 'Flying in normal space' + this.presence_state = _('In system {system}').format(system=system).encode() + this.presence_details = _('Flying in normal space').encode() elif entry['event'] == 'FSDJump': - this.presence_state = 'In %s' % system - this.presence_details = 'Supercruising' + this.presence_state = _('In system {system}').format(system=system).encode() + this.presence_details = _('Supercruising').encode() elif entry['event'] == 'Docked': - this.presence_state = 'In %s' % system - this.presence_details = 'Docked at %s' % station + this.presence_state = _('In system {system}').format(system=system).encode() + this.presence_details = _('Docked at {station}').format(station=station).encode() elif entry['event'] == 'Undocked': - this.presence_state = 'In %s' % system - this.presence_details = 'Flying in normal space' + this.presence_state = _('In system {system}').format(system=system) + this.presence_details = _('Flying in normal space').encode() elif entry['event'] == 'ShutDown': - this.presence_state = 'Connecting CMDR Interface' - this.presence_details = '' + this.presence_state = _('Connecting CMDR Interface').encode() + this.presence_details = b'' + elif entry['event'] == 'DockingGranted': + landingPad = entry['LandingPad'] elif entry['event'] == 'Music': if entry['MusicTrack'] == 'MainMenu': - this.presence_state = 'Connecting CMDR Interface' - this.presence_details = '' + this.presence_state = _('Connecting CMDR Interface').encode() + this.presence_details = b'' + # Todo: This elif might not be executed on undocked. Functionality can be improved + elif entry['event'] == 'Undocked' or entry['event'] == 'DockingCancelled' or entry['event'] == 'DockingTimeout': + this.presence_details = _('Flying near {station}').format(station=entry['StationName']).encode() + # Planetary events + elif entry['event'] == 'ApproachBody': + this.presence_details = _('Approaching {body}').format(body=entry['Body']).encode() + planet = entry['Body'] + elif entry['event'] == 'Touchdown' and entry['PlayerControlled']: + this.presence_details = _('Landed on {body}').format(body=planet).encode() + elif entry['event'] == 'Liftoff' and entry['PlayerControlled']: + if entry['PlayerControlled']: + this.presence_details = _('Flying around {body}').format(body=planet).encode() + else: + this.presence_details = _('In SRV on {body}, ship in orbit').format(body=planet).encode() + elif entry['event'] == 'LeaveBody': + this.presence_details = _('Supercruising').encode() + + # EXTERNAL VEHICLE EVENTS + elif entry['event'] == 'LaunchSRV': + this.presence_details = _('In SRV on {body}').format(body=planet).encode() + elif entry['event'] == 'DockSRV': + this.presence_details = _('Landed on {body}').format(body=planet).encode() update_presence() -