#This script is launched when you use the FLAGTEST item
#It allows tracking and modifying of the flag specified in fireEvent

from eventAPI import *
from APIUtils import *
from SDLKeys import SDLK_SPACE, SDLK_KP_MINUS, SDLK_KP_PLUS

def fireEvent(e, flag="kssAD"):
    x = getTag(e, flag)
    if (x == 0):
        showMessage(e, ["0"])
        choice(e, x, flag)
    elif (x == 1):
        showMessage(e, ["1"])
        choice(e, x, flag)
    elif (x == 2):
        showMessage(e, ["2"])
        choice(e, x, flag)
    elif (x == 3):
        showMessage(e, ["3"])
        choice(e, x, flag)
    elif (x == 4):
        showMessage(e, ["4"])
        choice(e, x, flag)
    elif (x == 5):
        showMessage(e, ["5"])
        choice(e, x, flag)
    elif (x == 6):
        showMessage(e, ["6"])
        choice(e, x, flag)
    elif (x == 7):
        showMessage(e, ["7"])
        choice(e, x, flag)
    elif (x == 8):
        showMessage(e, ["8"])
        choice(e, x, flag)
    elif (x == 9):
        showMessage(e, ["9"])
        choice(e, x, flag)
    elif (x == 10):
        showMessage(e, ["10"])
        choice(e, x, flag)
    elif (x == 11):
        showMessage(e, ["11"])
        choice(e, x, flag)
    elif (x == 12):
        showMessage(e, ["12"])
        choice(e, x, flag)
    elif (x == 13):
        showMessage(e, ["13"])
        choice(e, x, flag)
    elif (x == 14):
        showMessage(e, ["14"])
        choice(e, x, flag)
    elif (x == 15):
        showMessage(e, ["15"])
        choice(e, x, flag)
    else:
        choice(e, x, flag)

def choice(e, x, flag):
    ch = optionInput(e, ["Modify flag ?","","(NumPlus) to raise","(NumMinus) to lower"], ["(Space) to exit"], [SDLK_SPACE, SDLK_KP_MINUS, SDLK_KP_PLUS])
    if (ch == SDLK_KP_PLUS):
        x +=1
        setTag(e, flag, x)
        fireEvent(e)
    elif (ch == SDLK_KP_MINUS):
        x -=1
        setTag(e, flag, x)
        fireEvent(e)
    else:
        return 1



    
