init python early:
    if renpy.version_tuple < (7,5,0,22061501):
        raise RuntimeWarning("Your Ren'Py launcher is outdated, the current minimal requirement is 7.5.0.22061501+\nPlease perform an update and try launching the game again.")

    from renpy.uguu import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION

    def get_gpu_info():
        try:
            info = "\n".join([glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION)])
        except:
            info = "ERR: Unknown or incompatible driver."
        return info

    def get_renderer():
        return "DirectX" if preferences.renderer == "angle2" else "OpenGL"

init python:
    config.missing_image_callback = missing_image_func

    if config.developer:
        renpy.arguments.register_command("whitespace", save_whitespace)
    else:
        config.missing_label_callback = missing_label_func
        config.return_not_found_label = "missing_return"

init -1 python:

    def missing_image_func(path):
        global systemerror
        systemerror = ["Missing image", path]
        file, ext = os.path.splitext(path)

        if renpy.loadable(file + ".png"):
            return Image(file + ".png")

        if config.developer:
            raise IOError("Missing image: {}".format(path))
        return Image("images/blank.webp")

    def missing_label_func(name):
        global systemerror
        systemerror = ["Missing label", name]
        return "missing_label"

    def TBA_message(msg="Currently unavailable, check in later versions of the game."):
        renpy.show_screen("blktone")
        renpy.with_statement(d3)
        renpy.say(nar, msg)
        renpy.hide_screen("blktone")
        renpy.with_statement(d3)
        return

    def save_whitespace(refresh=False):
        """
        Generates a whitespace information file.
        """
        global whitespace_dict

        ap = renpy.arguments.ArgumentParser("Generates a whitespace information file.", require_command=False)
        ap.add_argument("--refresh", action="store_true", help="Recalculate for all images.")
        args = ap.parse_args()
        if args.refresh or refresh:
            whitespace_dict = {}

        path = os.path.normpath(config.gamedir)
        images = []
        for root, dirs, files in os.walk(path):
            for file in fnmatch.filter(files, "*.webp"):
                img = os.path.join(root, file).replace("\\", "/").split("/game/")[1]
                images.append(img)

        c = len(images)
        for i, img in enumerate(images):
            # stdout causes issues on Windows

            # sys.stdout.write("\rCalculating whitespace... {:3.0f}%".format(i / float(c - 1) * 100.0))
            # sys.stdout.flush()
            crop_whitespace(img)

        file = os.path.normpath(config.gamedir + "/images.whitespace")
        with open(file, "w") as f:
            for img, box in sorted(whitespace_dict.iteritems()):
                f.write(u"{}:{},{},{},{}\n".format(img, *box))

        print "\rCalculating whitespace... Done!"
        return False

label missing_label():
    $ renpy.choice_for_skipping()
    $ err_msg1 = systemerror[0]
    $ err_msg2 = systemerror[1]
    "{color=#7a0000}System{/color}" "Uh-oh. Looks like you've encountered a bug. Don't worry, we will try to return you back to the office after displaying the error message, your save file won't be affected."
    "{color=#7a0000}System{/color}" "{color=#7a0000}Error:{/color} [err_msg1] '{color=#7a0000}[err_msg2]{/color}'\n\n\n{size=-4}You can report this bug on our {a=https://discord.gg/7PD57yt}discord{/a}.{/size}"
    $ active_girl = None
    $ systemerror = [None, None]
    jump main_room

label missing_return():
    $ renpy.choice_for_skipping()
    "{color=#7a0000}System{/color}" "Uh-oh. Looks like you've encountered a bug. Don't worry, we will try to return you back to the office after displaying the error message, your save file won't be affected."
    "{color=#7a0000}System{/color}" "{color=#7a0000}Error:{/color} Point of no return.\n\n\n{size=-4}You can report this bug on our {a=https://discord.gg/7PD57yt}discord{/a}.{/size}"
    $ active_girl = None
    jump main_room

screen placeholder():
    tag cg
    zorder 16 # above dolls

    add Placeholder("bg")
    add Placeholder("girl")


init 2000 python hide:
    def set_screen_layer(layer, *screens):
        for scr_name in screens:
            for _, scr in renpy.display.screen.get_all_screen_variants(scr_name):
                scr.layer = layer

    set_screen_layer("interface", "_performance", "_image_load_log")
