diff options
author | Jesusaves <cpntb1@ymail.com> | 2021-05-09 14:54:04 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2021-05-09 14:54:04 -0300 |
commit | 1f06c76949e124dfd3f51200da96b04f4ff97b2c (patch) | |
tree | 729940d982ef9c3eb58754cb0361cb405b262e26 | |
parent | 40c41ef24f7783f6d890614cc108e2e3fe94440e (diff) | |
download | renpy-1f06c76949e124dfd3f51200da96b04f4ff97b2c.tar.gz renpy-1f06c76949e124dfd3f51200da96b04f4ff97b2c.tar.bz2 renpy-1f06c76949e124dfd3f51200da96b04f4ff97b2c.tar.xz renpy-1f06c76949e124dfd3f51200da96b04f4ff97b2c.zip |
Move the game launching code to client.rpy and make it non-blocking.
Prevents launcher from being marked as unresponsive by the OS.
-rw-r--r-- | game/client.rpy | 51 | ||||
-rw-r--r-- | game/renpy.rpy | 67 | ||||
-rw-r--r-- | game/screens.rpy | 2 |
3 files changed, 74 insertions, 46 deletions
diff --git a/game/client.rpy b/game/client.rpy index e45d4ef..d114e17 100644 --- a/game/client.rpy +++ b/game/client.rpy @@ -21,6 +21,57 @@ init 2 python: return f + def launch_game(idx): + global progress, responsive + # TODO: use the proper discord RPC image + RPCUpdate(persistent.serverlist[idx]["Name"], "tmw2") + HOST=persistent.serverlist[idx]["Host"] + PORT=persistent.serverlist[idx]["Port"] + CMD=handle_client(launch=True) + OPT="-s %s -y evol2 -p %s" % (HOST, PORT) + stdout("%s %s" % (CMD, OPT)) + + ## Obtain access token from vault + ## TODO: Only skip failure if not dev + auth = {"vaultId": vaultId, + "token": vaultToken, + "world": persistent.serverlist[idx]["UUID"]} + PWD="" + try: + r=requests.post(VAULT_HOST+"/world_pass", json=auth, timeout=15.0) + if r.status_code != 200: + stdout("Get World Auth - Returned error code %d" % r.status_code) + else: + auth2=r.json() + PWD=" -U %s -P %s" % (auth2["user"], auth2["pass"]) + except: + pass + + ## Minimize to tray if set + if not renpy.mobile and persistent.iconify: + renpy.iconify() + + ## Launch your prefered game client, wait for it to finish + if renpy.windows: + app=execute("\"%s\" %s%s" % (CMD, OPT, PWD), shell=True) + else: + app=execute("%s %s%s" % (CMD, OPT, PWD), shell=True) + if app: + traceback.print_exc() + stdout("An error happened: %d" % app) + responsive = False + + # NOTE: Now we would like to un-minimize ourselves + # But we cannot =/ + # There's a few tricks but not very nice... + # https://stackoverflow.com/questions/45426203/minimize-window-with-python (Linux) + # https://stackoverflow.com/questions/2791489/how-do-i-take-out-the-focus-or-minimize-a-window-with-python/2792059 (Windows) + progress=100 + + # Clean discord RPC and go back to world selection menu + RPCUpdate("Main Menu", "tmw2") + return + def md5check_client(): renpy.notify("Checking md5sum...") try: diff --git a/game/renpy.rpy b/game/renpy.rpy index b32be46..6b3bafc 100644 --- a/game/renpy.rpy +++ b/game/renpy.rpy @@ -77,54 +77,31 @@ label start: $ renpy.quit() return scene black - show TMW2 at truecenter + show expression Text("{color=#FFF}"+_("Game in session:\n%s" % (persistent.serverlist[_return]["Name"]))+"{/color}") at truecenter with None pause 0.01 python: - # TODO: use the proper discord RPC image - RPCUpdate(persistent.serverlist[_return]["Name"], "tmw2") - HOST=persistent.serverlist[_return]["Host"] - PORT=persistent.serverlist[_return]["Port"] - CMD=handle_client(launch=True) - OPT="-s %s -y evol2 -p %s" % (HOST, PORT) - stdout("%s %s" % (CMD, OPT)) - - ## Obtain access token from vault - ## TODO: Only skip failure if not dev - auth = {"vaultId": vaultId, - "token": vaultToken, - "world": persistent.serverlist[_return]["UUID"]} - PWD="" - try: - r=requests.post(VAULT_HOST+"/world_pass", json=auth, timeout=15.0) - if r.status_code != 200: - stdout("Get World Auth - Returned error code %d" % r.status_code) + renpy.invoke_in_thread(launch_game, _return) + progress = 0 + # Block the main thread until the socket connection is done + while progress < 100: + if responsive: + sdelay() else: - auth2=r.json() - PWD=" -U %s -P %s" % (auth2["user"], auth2["pass"]) - except: - pass - - ## Minimize to tray if set - if not renpy.mobile and persistent.iconify: - renpy.iconify() - - ## Launch your prefered game client, wait for it to finish - if renpy.windows: - app=execute("\"%s\" %s%s" % (CMD, OPT, PWD), shell=True) - else: - app=execute("%s %s%s" % (CMD, OPT, PWD), shell=True) - if app: - traceback.print_exc() - stdout("An error happened: %d" % app) - - # NOTE: Now we would like to un-minimize ourselves - # But we cannot =/ - # There's a few tricks but not very nice... - # https://stackoverflow.com/questions/45426203/minimize-window-with-python (Linux) - # https://stackoverflow.com/questions/2791489/how-do-i-take-out-the-focus-or-minimize-a-window-with-python/2792059 (Windows) - - # Clean discord RPC and go back to main menu - RPCUpdate("Main Menu", "tmw2") + break + + # Maybe we are waiting some prompt + if SCR_PROMPT is not None: + SCR_RESULT = renpy.call_screen("confirm", SCR_PROMPT, + Return(True), Return(False)) + SCR_PROMPT = None + + # Kill the program instead of looping back + if not responsive: + centered "{color=#FFF}An error happened.{/color}" + jump die + + # Automatically loop back + # Will never reach this line return diff --git a/game/screens.rpy b/game/screens.rpy index 1342e26..386ef92 100644 --- a/game/screens.rpy +++ b/game/screens.rpy @@ -309,7 +309,7 @@ screen navigation(): textbutton _("End Replay") action EndReplay(confirm=True) - elif not main_menu: + elif not main_menu and config.developer: textbutton _("Main Menu") action MainMenu() |