From 3d72d3f4920925f6e4b0abf2d0211c00b08ad98e Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 6 Feb 2024 09:47:56 -0300 Subject: Optimize Soul Data loading --- __main__.py | 63 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/__main__.py b/__main__.py index 463db7f..faf4048 100755 --- a/__main__.py +++ b/__main__.py @@ -248,6 +248,31 @@ def update_serverlist(hosti): traceback.print_exc() return False +## Updates your soul data +def update_soul(): + global vaultId, vaultToken, mySoul + ## Fetch soul data + ## TODO: Doing this here is too inefficient!! + auth = {"vaultId": vaultId, + "token": vaultToken} + + r=vault.post(VAULT_HOST+"/souldata", json=auth, timeout=15.0) + if r.status_code != 200: + raise Exception("Request error: %d" % r.status_code) + dat=r.json() + mySoul["level"]=dat["soulv"] + mySoul["exp"]=dat["soulx"] + mySoul["next"]=dat["varlv"] + mySoul["up"]=dat["lvlup"] + mySoul["home"]=dat["homew"] + for s in serverlist: + if mySoul["home"] == s["UUID"]: + mySoul["home"] = s["Name"] + break + if mySoul["home"] == "VAULT": + mySoul["home"]="Not Set" + return + ## Show a game info def info_game(idx): showinfo(title=serverlist[idx]["Name"], @@ -304,7 +329,7 @@ def do_real_launch(idx, PWD): CMD=CMD.replace(" ", "\\ ") CWD=CMD[:-1] - ## TODO: Handle server type and client + ## Handle server type and client (WIP) if not sys.platform.startswith('win'): if pref["plus"]: CMD+="manaplus" @@ -398,6 +423,7 @@ os.environ["APPIMAGELAUNCHER_DISABLE"]="1" ## Construct session data update_serverlist(SERVERLIST) vaultId = -1 +mySoul={} saveMail = None savePass = None @@ -452,11 +478,12 @@ def settings(): if not sys.platform.startswith('win'): c3 = tk.Checkbutton(root, text="Use original Mana client", variable=prefMana, bg="#0c3251", fg="#f70") canva.create_window(200, 110, window=c3) - c4 = tk.Checkbutton(root, text="Use ManaPlus client", variable=prefPlus, bg="#0c3251", fg="#f70") - canva.create_window(200, 135, window=c4) + #TODO: Download link broken + #c4 = tk.Checkbutton(root, text="Use ManaPlus client", variable=prefPlus, bg="#0c3251", fg="#f70") + #canva.create_window(200, 135, window=c4) c5 = tk.Checkbutton(root, text="Verbose logging", variable=prefLogs, bg="#0c3251", fg="#f70") canva.create_window(200, 160, window=c5) - # TODO: "Download/Update GPL clients" button + # "Download/Update GPL clients" button button = HoverButton(text="Download GPL clients", command=_downloadClient, bg="#cc6600", fg="#fff", activebackground="#ee9933", font="helvetica 12", height=-10) canva.create_window(200, 190, window=button) # TODO: Account Linking and Unlinking @@ -477,6 +504,7 @@ def _settingSave(): pref["mana"] = prefMana.get() pref["plus"] = prefPlus.get() _savePref() + update_soul() # <- Update soul data before canvas is destroyed world_select() return @@ -484,7 +512,7 @@ def _downloadClient(): ## TODO: Show progress bars if askyesno("Mana Launcher", "Do you want to download or update the game clients?\n\nThey are licensed under GPLv2 or later. Up to 150 MB of disk space will be required."): ## Manaverse for Linux - if False and not sys.platform.startswith('win'): + if not sys.platform.startswith('win'): with open("manaplus/ManaVerse.AppImage", 'wb') as f: f.write(requests.get("https://updates.tmw2.org/mana/linux/ManaPlus-x86_64.AppImage", allow_redirects=True).content) execute("chmod +x \"%s\"" % "manaplus/ManaVerse.AppImage", shell=True) @@ -509,7 +537,7 @@ def _downloadClient(): ################################################################################# ###### World Selection Screen def world_select(): - global canva, serverlist + global canva, serverlist, mySoul canva.destroy() canva = tk.Canvas(root, width=400, height=600, bg="#0c3251") canva.pack() @@ -517,28 +545,6 @@ def world_select(): label1.config(font=('helvetica', 14)) canva.create_window(200, 30, window=label1) - ## Fetch soul data - ## TODO: Doing this here is too inefficient!! - auth = {"vaultId": vaultId, - "token": vaultToken} - - r=vault.post(VAULT_HOST+"/souldata", json=auth, timeout=15.0) - if r.status_code != 200: - raise Exception("Request error: %d" % r.status_code) - dat=r.json() - mySoul={} - mySoul["level"]=dat["soulv"] - mySoul["exp"]=dat["soulx"] - mySoul["next"]=dat["varlv"] - mySoul["up"]=dat["lvlup"] - mySoul["home"]=dat["homew"] - for s in serverlist: - if mySoul["home"] == s["UUID"]: - mySoul["home"] = s["Name"] - break - if mySoul["home"] == "VAULT": - mySoul["home"]="Not Set" - ## Not really necessary? Or just TODO? ## Without these, max is 10 worlds #scrollbar = tk.Scrollbar(canva, orient=tk.VERTICAL) @@ -626,6 +632,7 @@ def login(): ## Change the display print("Connected to vault! vaultId = %d" % vaultId) + update_soul() # <- Update soul data before canvas is destroyed ## Do not jump to world selection if it is a new account - show the app intro if newUser: greeting=""" -- cgit v1.2.3-70-g09d2