define whatsThisMttkMod = "MttkModKeys 1.5.3"

define mttkModLicense = """
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
    OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
    GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    .
    ANY USAGE, READING, LEARNING FROM OR USE IN CONJUNCTION BY OR WITH
    MACHINE LEARNING, DEEP LEARNING, ARTIFICIAL INTELLIGENCE OR SIMILIAR
    IS STRICTLY FORBIDDEN."""

init 66 python:#"configuration"-consts
    ## for keyboard-devices
    ##you may want to look at ../../renpy/test/testkey.py
    ##between "pygame_sdl2." and " :" for examples of the keyboard-key-codes
    ##~Warning~: changed keyboard-codes will not be checked by the MOD...(dunno what happens on illegal ones or K_UNKNOWN...)
    ## must be strings else default will be set later      (##by default keymaps are lists of strings, KEEP it to strings here)
    renpy.config.keymap[ "quickSave" ] = "K_F5"
    renpy.config.keymap[ "quickLoad" ] = "K_F9"


    ## for touch-devices
    ##(same)~Warning~: changed gestures(and their values) will not be checked by the MOD...(dunno what happens on ???...)
    ## quick-gestures + screenshot
    mttkModStrGestureForQuickLoad = "s_e"
    mttkModStrGestureForQuickSave = "n_w"
    mttkModStrGestureForScreenShot = "s_e_n"
    ## default gestures
    mttkModDictDefaultGestures = { "n" : "game_menu", "s" : "hide_windows", "e" : "toggle_skip", "w" : "rollback" }
    ##some more gestures are: n_s_w_e_w_e: progress_screen ; n_w_s:console ; e_w_e: fast_skip ; n_s_n: performance# they will not be handled by this MOD
    ## (pot.) TODO console, director, (full-)inspector for full-MOD



    if renpy.exports.variant( "touch" ):## longpress_duration
        try:#on "touch"-devices alternate(screen action) by default is routed to longpress
            if renpy.config.longpress_duration < 1.5:
                renpy.config.longpress_duration = 1.5
        except:#RenPy-default is 0.5sec and that is too short FOR ME!
            pass#imho nearly impossible, since even RenPy 6.18.3 knows about config.longpress_duration
init 88 python:
    try:##this re-"activates" (standard) quick-save-load, if has been disabled by dev #(?)
        renpy.config.has_quicksave = True
    except:
        if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):#notify myself if full MOD
            setMttkVar( "lstInitOK", False, 0 )#critical coz just shall not be...
            getMttkVar( "lstInitOK" ).append( "Keys: exception on setting config.has_quicksave=True !" )
    ## no check for isinstance( renpy.config.underlay[ 0 ], renpy.display.behavior.Keymap ):#coz in the end, I can't do anything about it
    renpy.config.underlay[ 0 ].keymap[ "quickSave" ] = QuickSave()##the following 2 lines "route" (standard) quick-save-load      (##the full MOD will alter these !)
    renpy.config.underlay[ 0 ].keymap[ "quickLoad" ] = QuickLoad()#both create an instance of renpy.Keymap
    if not isinstance( renpy.config.keymap[ "quickSave" ], mttkstrtyp ):##check for keyboard-key-string
        renpy.config.keymap[ "quickSave" ] = "K_F5"
        if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
            getMttkVar( "lstInitOK" ).append( "Keys: user has given not a STRING for quickSave!" )
    if not isinstance( renpy.config.keymap[ "quickLoad" ], mttkstrtyp ):
        renpy.config.keymap[ "quickLoad" ] = "K_F9"
        if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
            getMttkVar( "lstInitOK" ).append( "Keys: user has given not a STRING for quickLoad!" )
    if "screenshot" in renpy.config.keymap:##add print-screen-key to screenshot
        if mttkModIsList( renpy.config.keymap[ "screenshot" ] ):#if ( isinstance( renpy.config.keymap[ "screenshot" ], _list ) or type( renpy.config.keymap[ "screenshot" ] ) == mttkModTypePyList or isinstance( renpy.config.keymap[ "screenshot" ], list ) ):
            renpy.config.keymap[ "screenshot" ].append( 'K_PRINTSCREEN' )
    if not "save_page_prev" in renpy.config.keymap:##with Renpy 8.4.0.nightly came usage of mousewheel for file_slots pagination
        renpy.config.keymap[ "save_page_prev" ] = "mousedown_4"##mousewheel up
    if not "save_page_next" in renpy.config.keymap:##not sure if I like it...
        renpy.config.keymap[ "save_page_next" ] = "mousedown_5"##mousewheel down


    def mttkModDefScreenshotCopy():## for touch-devices
        """ only for personal use - unchecked, unsafe - not fit for anything """
        import os.path
        import os###startMttkMod#dest = config.renpy_base###this is the reason to copy the def!
        if renpy.config.searchpath[ 0 ] != renpy.config.renpy_base:
            dest = renpy.config.searchpath[ 0 ]
        else:
            dest = config.renpy_base
        try:#I dunno about mac. the org def has no try-except-block around it
            if renpy.macapp:#this is just me being too cautious
                dest = os.path.expanduser("~/Desktop")
        except:
            return#better no screenshot than an exception? ##tell me mac-people...
        try:#safety, coz I just don't know anything about renpy.store._screenshot_pattern
            pattern = renpy.store._screenshot_pattern or config.screenshot_pattern
        except:
            pattern = config.screenshot_pattern###endMttkMod
        i = 1# Try to pick a filename.
        while True:
            fn = os.path.join(dest, pattern % i)
            if not os.path.exists(fn):
                break
            i += 1
        try:
            dn = os.path.dirname(fn)
            if not os.path.exists(dn):
                os.makedirs(dn)
        except Exception:
            pass
        try:
            if not renpy.screenshot(fn):
                renpy.notify(__("Failed to save screenshot as %s.") % fn)
                return
        except Exception:
            import traceback
            traceback.print_exc()
            renpy.notify(__("Failed to save screenshot as %s.") % fn)
            return
        if config.screenshot_callback is not None:
            config.screenshot_callback(fn)
        return

    if mttkModIntRPYver < 69900:#renpy.version_tuple < ( 6, 99, 0 ):##Gestures came with RenPy 6.99(.0)(changelog) ; confirmed seen in 6.99.14
        if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
            setMttkVar( "lstInitOK", False, 0 )#critical coz you use the MOD outside of its limitations!
            getMttkVar( "lstInitOK" ).append( "Keys: RenPy-version pot. TOO SMALL for gestures!" )
    else:##for MttkMod we consider RenPy-ver greater 6.99.0 ! older versions shall not get gesture-support from the MOD
        if renpy.config.dispatch_gesture is not None:
            if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                setMttkVar( "lstInitOK", False, 0 )#critical coz MOD must make amends!
                getMttkVar( "lstInitOK" ).append( "Keys: DEV has an own def for gestures: MODded ones may not work!" )
        if not hasattr( renpy.config, "gestures" ):#but in the end...it doesn't matter for the config.var
            renpy.config.gestures = { }#ex: unknown config-var
            if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                setMttkVar( "lstInitOK", False, 0 )
                getMttkVar( "lstInitOK" ).append( "Keys: had no config.gestures !" )
        elif mttkModIsDict( renpy.config.gestures ):
            pass
        else:#NOT checking for string or else...
            renpy.config.gestures = { }#this'll make a RevertableDict
            if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                setMttkVar( "lstInitOK", False, 0 )
                getMttkVar( "lstInitOK" ).append( "Keys: config.gestures was NOT a dict !" )
        if renpy.exports.variant( "touch" ):#checks only if "touch" in renpy.config.variants ; but let's use exports, coz these tend to be up/downward compatible, like forever (#intern renpy mostly uses if renpy.display.touch: )
            if not isinstance( mttkModStrGestureForQuickLoad, mttkstrtyp ):
                mttkModStrGestureForQuickLoad = "s_e"
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                    getMttkVar( "lstInitOK" ).append( "Keys: user has given not a STRING for mttkModStrGestureForQuickLoad!" )
            if not isinstance( mttkModStrGestureForQuickSave, mttkstrtyp ):
                mttkModStrGestureForQuickSave = "n_w"
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                    getMttkVar( "lstInitOK" ).append( "Keys: user has given not a STRING for mttkModStrGestureForQuickSave!" )
            if not isinstance( mttkModStrGestureForScreenShot, mttkstrtyp ):
                mttkModStrGestureForScreenShot = "s_e_n"
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                    getMttkVar( "lstInitOK" ).append( "Keys: user has given not a STRING for mttkModStrGestureForScreenShot!" )
            if not mttkModIsDict( mttkModDictDefaultGestures ):
                mttkModDictDefaultGestures = { "n" : "game_menu", "s" : "hide_windows", "e" : "toggle_skip", "w" : "rollback" }
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):## I am NOT checking for keys and values being strings....
                    getMttkVar( "lstInitOK" ).append( "Keys: user has given not a DICT for mttkModDictDefaultGestures!" )

            if mttkModStrGestureForQuickLoad in renpy.config.gestures:
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                    getMttkVar( "lstInitOK" ).append( "Keys: gesture for quickLoad already used!" )
            else:
                renpy.config.gestures[ mttkModStrGestureForQuickLoad ] = "quickLoad"#renpy.config.gestures[ "s_e" ] = "quickLoad"
            if mttkModStrGestureForQuickSave in renpy.config.gestures:##check if quick-gestures already exist else add
                if renpy.loadable( "zMttkModFolder/zMttkModSupport.rpyc" ):
                    getMttkVar( "lstInitOK" ).append( "Keys: gesture for quickSave already used!" )
            else:
                renpy.config.gestures[ mttkModStrGestureForQuickSave ] = "quickSave"#renpy.config.gestures[ "n_w" ] = "quickSave"
            try:##add screenshot-gesture s_e_n
                if renpy.config.searchpath[ 0 ] != renpy.config.renpy_base:
                    renpy.config.underlay[ 0 ].keymap[ "mttkModScreenshotCopy" ] = Function( mttkModDefScreenshotCopy )
                    renpy.config.keymap[ "mttkModScreenshotCopy" ] = None#needed to prevent an exception with enabled dev-mode#or mttkModPyList() #once: renpy.minstore.python_list()
                    renpy.config.gestures[ mttkModStrGestureForScreenShot ] = "mttkModScreenshotCopy"
                else:
                    renpy.config.gestures[ mttkModStrGestureForScreenShot ] = "screenshot"
            except:
                renpy.config.gestures[ mttkModStrGestureForScreenShot ] = "screenshot"
            for mttkModStrTmp in mttkModDictDefaultGestures:##silently add default gestures if they do not exist
                if mttkModStrTmp not in renpy.config.gestures:
                    renpy.config.gestures[ mttkModStrTmp ] = mttkModDictDefaultGestures[ mttkModStrTmp ]



##eof

