summaryrefslogtreecommitdiff
path: root/game/renpy.rpy
blob: 92ccc397ab36f2af4ffb3228b0a41d4d99a7012c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#################################################################################
#     This file is part of Mana Launcher.
#     Copyright (C) 2021  Jesusalva <jesusalva@tmw2.org>
#
#     Distributed under the MIT license.
#################################################################################

image TMW2 = "images/TMW2.png"

screen loading():
    zorder 100

    fixed:
        frame:
            xfill True
            yfill True
            background Frame("images/default.png", 0, 0)
        bar:
            value progress
            range 100
            xalign 0.5
            yalign 0.45
            xmaximum 0.75
        label "[statusmsg]":
            xalign 0.5
            yalign 0.55

# The game starts here.
label start:
    scene black

    show screen loading
    call before_main_menu

    # Run updater
    $ renpy.invoke_in_thread(CONFIGURE_LAUNCHER)

    # Estabilish the connection to server
    python:
        # Block the main thread until the socket connection is done
        while progress < 100:
            if responsive:
                sdelay()
            else:
                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
    if not responsive:
        jump die

    $ stdout("Connection established!")

    # Open game
    hide screen loading
    scene black
    show TMW2 at truecenter
    with Dissolve(0.5)
    pause 1.0
    hide TMW2 with dissolve
    #centered "Error"
    #if config.developer:
    #    "User ID: [vaultId]"
    while True:
        $ renpy.block_rollback()
        call screen mirrorlake
        #if config.developer:
        #    "Selected: [_return]"
        if _return is None or _return == "QUIT":
            $ stdout("Good bye!")
            $ renpy.quit()
            return
        scene black
        show TMW2 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).replace(" ", "\\ ")
            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"]}
            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)
                PWD=""
            else:
                auth2=r.json()
                PWD=" -U %s -P %s" % (auth2["user"], auth2["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
            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")
    return