define whatsThisMttkMod = "6MttkModSupport 1.5.4 python (early)"

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 -969 python:# my lousy PYsix-workarounds
    ### renpy/compat came somewhere between (7, 3, 5, vc_version)(no compat) and (7, 4, 4, vc_version)(has compat)
    ### changelog suggests 7.4.0 - further on this is taken as given
    from sys import version_info as sys_version_info
    mttkModPYver = "unknown"
    try:
        if sys_version_info[ 0 ] > 2:
            mttkModPYver = ">2"
        else:
            mttkModPYver = "<=2"
    except:
        mttkModPYver = "FAIL"

    ### str - unicode - basestring
    ### this kinda mimics (copies) renpy/compat ... backdrafts: 1) isle-solution 2) pot. double code

    if mttkModPYver == "<=2":
        mtkStr = unicode
        if isinstance( basestring, tuple ):
            mttkstrtyp = tuple( basestring )#for compat < RenPy 8.0.0
        else:
            mttkstrtyp = ( basestring, )
        import __builtin__ as mttkModModBuiltin_s#for my usage of "original" python list, dict and set
    else:
        mtkStr = str
        mttkstrtyp = ( str, )
        import builtins as mttkModModBuiltin_s#su (and pot. py-object)





































    ###-dict() : PY3: dict.items(), dict.keys(), and dict.values() are view objects ; PY2 (shallow) copies
    ### NEED to be done at invocation: decide to wrap(list or tuple) or (pot.) be satisfied with a view...






    ### in PY2 'long' was available - NEVER use it!


    ### .tobytes() has an entry in future.utils too ; but seems NOT to affect my use from memoryview ; DON'T use else !


    ### range <-> xrange ("officially" no xrange in PY3) (try avoid using 'em)
    ### NEED to be done at invocation: decide to wrap in a list or (pot.) be satisfied with a range-object...





    ### pot. undocumented...list-method list.sort() or the underlying operator "<" is now more strict!
    ### while PY2 sorted tuple and string(tuple smaller than string), PY3 throws an exception



    ### special RenPy-prob (python-)list versus RevertableList (and dict) (and set)

    mttkModPyList = mttkModModBuiltin_s.__dict__[ "list" ]#1.5.3. "future"-safety and simplification #was once #renpy.minstore.python_list()
    mttkModTypePyList = type( mttkModPyList() )#this mainly solves the problem of: isinstance( list, list ) == False ; but also str( type( python_list ) ) = PY2: "<type 'list'>" ; PY3: "<class 'list'>"
    def mttkModIsList( obj = None ):#"shortcut"-def for: if ( type( amIaList ) == mttkModTypePyList or isinstance( amIaList, list ) ):
        try:
            if ( isinstance( obj, list ) or type( obj ) == mttkModTypePyList ):#PYsix: PY2="<type 'list'>" ; PY3="<class 'list'>"
                return True
            elif ( isinstance( obj, _list ) or isinstance( obj, python_list ) ):#minstore.py (for keymap)
                return True
        except:
            return False
        return False
    mttkModPyDict = mttkModModBuiltin_s.__dict__[ "dict" ]#yes, I KNOW...it sure does NOT look like a "simplification"
    mttkModTypePyDict = type( mttkModPyDict() )#...(but it doesn't need a (min)store...)
    def mttkModIsDict( obj = None ):
        try:
            if ( isinstance( obj, dict ) or type( obj ) == mttkModTypePyDict ):
                return True
            elif ( isinstance( obj, _dict ) or isinstance( obj, python_dict ) ):
                return True
        except:
            return False
        return False
    mttkModPySet = mttkModModBuiltin_s.__dict__[ "set" ]#all seen in RenPy 6.18.3(__builtin__-explicitly only in 6.99.13) (and 8.0.3 )
    mttkModTypePySet = type( mttkModPySet() )
    def mttkModIsSet( obj = None ):
        try:
            if ( isinstance( obj, set ) or type( obj ) == mttkModTypePySet ):
                return True
            elif ( isinstance( obj, _set ) or isinstance( obj, python_set ) ):
                return True
        except:
            return False
        return False
    mttkModPyObj = mttkModModBuiltin_s.__dict__[ "object" ]#check(?)
    mttkModTypePyObj = type( mttkModPyObj() )
    def mttkModIsObj( obj = None ):##tho this (nearly???) should ALWAYS hit...
        try:
            if ( isinstance( obj, object ) or type( obj ) == mttkModTypePyObj ):
                return True
            elif ( isinstance( obj, _object ) or isinstance( obj, python_object ) ):
                return True
        except:
            return False
        return False


    ### these are only the "things" pot. affecting ME...there are MORE !


    ### da Mattock-only1-persistent-var
    if persistent.mttkModDictAllVars is None:
        persistent.mttkModDictAllVars = mttkModPyDict()#
    elif type( persistent.mttkModDictAllVars ) != mttkModTypePyDict:
        persistent.mttkModDictAllVars = mttkModPyDict()
    def getMttkVar( var = None, dkey = None ):
        """
        using persistent.mttkModDictAllVars (which shall be a python-dict() )
        if that is not a dict: None will be returned
        if the 'key' of the dict is non-existant (also) None is returned

        handling dictionaries within this dictionary is being done by dkey != None (tho not really needed)
        if then var is not a python-dict, None is returned, else: persistent.mttkModDictAllVars[ var ][ dkey ]

        and finally on any pot error...None is returned
        """
        if persistent.mttkModDictAllVars is None:
            return None
        elif type( persistent.mttkModDictAllVars ) != mttkModTypePyDict:#
            return None
        rv = None
        try:
            if var in persistent.mttkModDictAllVars:
                rv = persistent.mttkModDictAllVars[ var ]
        except:
            rv = None
        if ( rv is not None and dkey is not None):
            if type( rv ) != mttkModTypePyDict:
                return None
            pDict = rv
            try:
                rv = pDict[ dkey ]
            except:
                rv = None
            pDict = None
        return rv
    def setMttkVar( var = None, val = None, lidx = None, dkey = None, toggle = False, delete = False ):
        """
        using persistent.mttkModDictAllVars (which shall be a python-dict() )
        if it is not, it will be created.
        then the dict-item
        persistent.mttkModDictAllVars[ var ] = val
        will be set. (pot. overriding an existing one)

        when told to delete(=True) del persistent.mttkModDictAllVars[ var ] will be done
        (for list do del getMttkVar( var )[ lidx ] )
        (for dict do del getMttkVar( var )[ dkey ] )

        handling lists within this dictionary is being done by lidx != None
        this shall always create a python-list, if it is not already one
        var is the list-name, lidx the list-index and val the value for that index to be set
        empty list by: lidx='mttkModEmptyList'
        (re-)create list by: var, val, lidx='mttkModCreateList' -> persistent.mttkModDictAllVars[ var ] = [ val ]
        the value of the list-index can be toggled too (making it a bool, see down)

        handling dictionaries within this dictionary is being done by dkey != None
        this shall always create a python-dict, if it is not already one
        var is the dict-name, dkey the dict-key-name and val the dict-value for the dict-key to be set
        empty dict by: dkey='mttkModEmptyDict'
        the value of the dict-key can be toggled too (making it a bool, see down)

        ( set's don't have special treatment (atm) )

        WARNING if both lidx != None and dkey != None
        NOTHING will be done!

        when told to toggle ( toggle=='1' or bool(toggle)==True (string or bool))
        val is turned into a bool (bool(val) ) and the opposite is set
        special case: IF toggle=='1' (instead bools 'True' or 'False') integers '1' or '0' are set
        (on exception while getting val from dict, False/0 will be set)

        if var is None or on exception while setting: NOTHING will be done!
        (and never will be returned anything)
        """
        if var is None:
            return
        if persistent.mttkModDictAllVars is None:
            persistent.mttkModDictAllVars = mttkModPyDict()
        elif type( persistent.mttkModDictAllVars ) != mttkModTypePyDict:
            persistent.mttkModDictAllVars = mttkModPyDict()
        try:
            delete = bool( delete )
        except:
            delete = False
        if delete:
            try:
                del persistent.mttkModDictAllVars[ var ]
            except:
                pass
            return
        try:#
            if toggle:#
                if mtkStr( toggle ) != "1":#
                    toggle = bool( toggle )
        except:
            toggle = False
        if lidx is not None:
            if dkey is not None:
                return
            try:
                if ( lidx == "mttkModEmptyList" or lidx == "mttkModCreateList" ):
                    persistent.mttkModDictAllVars[ var ] = mttkModPyList()#
                elif type( persistent.mttkModDictAllVars[ var ] ) != mttkModTypePyList:
                    persistent.mttkModDictAllVars[ var ] = mttkModPyList()
            except:
                pass
        elif dkey is not None:
            try:
                if dkey == "mttkModEmptyDict":
                    persistent.mttkModDictAllVars[ var ] = mttkModPyDict()
                elif type( persistent.mttkModDictAllVars[ var ] ) != mttkModTypePyDict:
                    persistent.mttkModDictAllVars[ var ] = mttkModPyDict()
            except:
                pass
        if toggle:#True or 1
            try:
                if lidx is not None:
                    if dkey is not None:#safety
                        return
                    if bool( getMttkVar( var )[ lidx ] ):
                        val = False
                    else:
                        val = True
                elif dkey is not None:
                    if bool( getMttkVar( var )[ dkey ] ):
                        val = False
                    else:
                        val = True
                else:
                    if bool( getMttkVar( var ) ):
                        val = False
                    else:
                        val = True
            except:
                val = False
            try:
                if mtkStr( toggle ) == "1":#
                    if val:
                        val = 1
                    else:
                        val = 0
            except:#
                pass#
        if lidx is not None:
            if dkey is not None:#safety
                return
            try:
                if lidx == "mttkModCreateList":
                    persistent.mttkModDictAllVars[ var ].append( val )
                elif lidx != "mttkModEmptyList":
                    persistent.mttkModDictAllVars[ var ][ lidx ] = val
            except:
                pass
        elif dkey is not None:
            try:
                if dkey != "mttkModEmptyDict":
                    persistent.mttkModDictAllVars[ var ][ dkey ] = val
            except:
                pass
        else:
            try:
                persistent.mttkModDictAllVars[ var ] = val
            except:#
                pass#
        return

    setMttkVar( "lstInitOK", True, "mttkModCreateList" )



##eof

