summaryrefslogtreecommitdiff
path: root/game/renpy.rpy
blob: 17fbae21a0d999fedffde836174d07e366fd534c (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
125
126
127
#################################################################################
#     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:
    $ statusmsg="Validating SSL Certificates..."
    scene black

    show screen loading
    call before_main_menu
    $ stdout("Before menu OK")

    # Build the Vault PEM, blocking and fatal
    $ build_vault()
    $ stdout("Vault PEM OK")

    # Run updater
    $ renpy.invoke_in_thread(CONFIGURE_LAUNCHER)
    $ stdout("Thread start OK")

    # 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


    $ stdout("Thread finish OK")

    # Kill the program
    if not responsive:
        jump die

    # Do we have a Vault ID?
    if not vaultId:
        call register

    # If we still don't have a Vault ID - something went wrong D:
    if not vaultId:
        $ status_update("{color=#F00}Failure! Vault ID could not be set.{/color}")
        jump die

    $ stdout("Connection established! User ID %d" % vaultId)

    # 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 expression Text("{color=#FFF}"+_("Game in session:\n%s" % (persistent.serverlist[_return]["Name"]))+"{/color}") at truecenter
        with None
        pause 0.01
        python:
            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:
                    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:
            scene black
            centered "{color=#FFF}{b}An error happened.{/b}\n\nPlease login again. If this issue persists, relaunch the app or {a=https://discord.gg/BQNTe68}contact us{/a}{/color}"
            $ stdout("Program died - unsucessful game launch")
            return

        # Automatically loop back
    # Will never reach this line
    return