define ton_face = {
    "mouth": {
        "neutral":      ["base","open"],
        "happy":        ["base","grin"],
        "naughty":      ["soft","base"],
        "horny":        ["horny","base"],
        "annoyed":      ["upset","annoyed"],
        "disgusted":    ["disgust","upset"],
        "angry":        ["clench","mad","upset"]
    },

    "eyes": {
        "neutral":      ["base"],
        "happy":        ["happyCl"],
        "naughty":      ["narrow"],
        "horny":        ["narrow"],
        "annoyed":      ["narrow","base"],
        "disgusted":    ["base"],
        "angry":        ["base"]
    },

    "eyebrows": {
        "neutral":      ["base"],
        "happy":        ["base","raised"],
        "naughty":      ["base","raised"],
        "horny":        ["base","raised"],
        "annoyed":      ["annoyed"],
        "disgusted":    ["raised","worried"],
        "angry":        ["angry"]
    },

    "pupils": {
        "neutral":      ["mid"],
        "happy":        ["mid"],
        "naughty":      ["mid","up","downR"],
        "horny":        ["mid","stare","down"],
        "annoyed":      ["mid","downR","R"],
        "disgusted":    ["mid","down"],
        "angry":        ["mid"]
    }
}

label update_tonks:

    # Chibi Update
    $ tonks_chibi.update()
    $ tonks_chibi.position(flip=False)
    $ tonks.xzoom = 1
    hide screen ton_cloth_pile

    $ tonks.get_equipped("hair").set_color(tonks_haircolor)
    return

label end_tonks_event:
    call ton_chibi("hide")
    hide tonks_main
    with d3
    pause.5

    call update_tonks

    $ active_girl = None
    $ tonks_busy = True
    $ tonks.wear("all")
    $ tonks.set_cum(None)

    $ renpy.stop_predict(tonks.get_image())
    $ renpy.stop_predict("characters/tonks/face/*.webp")

    call music_block
    jump main_room_menu

define character.tonks_say = Character("tonks_name", show_icon="tonks", dynamic=True)

init python:
    def ton(what, mouth=False, eyes=False, eyebrows=False, pupils=False, cheeks=None, tears=None,
        emote=None, face=None, xpos=None, ypos=None, pos=None, flip=None, trans=None, animation=False, hair=None, **kwargs):

        redraw = False
        tag = tonks.tag
        layer = tonks.layer
        #showing = renpy.showing(name=tag, layer=layer)

        if xpos != None or ypos != None:
            xpos = tonks.pos[0] if xpos == None else sprite_pos.get("x").get(xpos, xpos)
            ypos = tonks.pos[1] if ypos == None else sprite_pos.get("y").get(ypos, ypos)
            tonks.pos = (xpos, ypos)
            redraw = True

        head_only = tonks.pos[1] == sprite_pos.get("y").get("head")

        if any((mouth, eyes, eyebrows, pupils, cheeks, tears)):
            tonks.set_face(mouth=mouth, eyes=eyes, eyebrows=eyebrows, pupils=pupils, cheeks=cheeks, tears=tears)
            redraw = True

        tonks.set_emote(emote)

        if hair:
            if isinstance(hair, list):
                target_color = hair
            elif hair in ("neutral", "basic", "reset"):
                target_color = tonks_haircolor
            elif hair in ("red", "angry", "furious"):
                target_color = [[164, 34, 34, 255], [219, 83, 83, 255]]
            elif hair in ("orange", "upset", "annoyed"):
                target_color = [[228, 93, 34, 255], [246, 193, 170, 255]]
            elif hair in ("yellow", "happy", "cheerful"):
                target_color = [[255, 213, 23, 255], [255, 239, 167, 255]]
            elif hair in ("green", "disgusted"):
                target_color = [[111, 205, 75, 255], [200, 237, 186, 255]]
            elif hair in ("blue", "sad"):
                target_color = [[64, 75, 205, 255], [182, 186, 237, 255]]
            elif hair == "purple":
                target_color = [[205, 75, 205, 255], [237, 186, 237, 255]]
            elif hair in ("white", "scared"):
                target_color = [[238, 238, 241, 255], [249, 249, 250, 255]]
            elif hair in ("pink", "horny"):
                target_color = [[255, 105, 180, 255], [251, 205, 222, 255]]

            if target_color != tonks.get_equipped("hair").color:
                tonks.get_equipped("hair").set_color(target_color)
                redraw = True

        if animation != False:
            tonks.animation = animation
            redraw = True

        if flip != None:
            tonks.xzoom = -1 if flip else 1
            redraw = True

        if redraw:
            tonks.show()

            if not renpy.in_rollback():
                if trans:
                    renpy.with_statement(trans)
                else:
                    renpy.with_statement(d2)

        if what:
            character.tonks_say(what, **kwargs)

        if head_only:
            tonks.hide()
