コード例 #1
0
def run_lstc_showfilter(sprite_db, sprite_db_keys, ss_filter):
    """
    Show filter settings
    """
    menutils.clear_screen()
    print(str(ss_filter))
    menutils.e_pause()
コード例 #2
0
def make_sprite_bc(sprite_db, sprite_db_keys):
    """
    Makes sprite using just a code and adds it to sprite database.
    NOTE: keys should be regenerated after this by the caller

    RETURNS: True if sprite creation successful, False if not
    """
    not_valid_code = True
    sprite_created = False
    while not_valid_code:
        menutils.clear_screen()
        print("\n\n")
        trycode = raw_input("Enter a sprite code: ")

        # build a static sprite with the code
        new_sprite = StaticSprite(trycode)

        # and atl version
        atl_sprite = new_sprite.make_atl()

        if new_sprite.invalid or atl_sprite.invalid:
            # if invalid, ask user if they want to continue
            print("\nSprite code {0} is invalid.\n".format(trycode))
            if not menutils.ask("Try again", def_no=False):
                return sprite_created

        elif new_sprite.spcode in sprite_db:
            # check if already exists
            print("\nSprite code {0} already exists!\n".format(
                new_sprite.spcode))
            if not menutils.ask("Try again", def_no=False):
                return sprite_created

        else:
            # valid sprite, means we should show it and ask for confirm
            filter_spr = FilterSprite.from_ss(new_sprite)
            print(
                filter_spr._status(
                    True, "Selected Sprite Settings - " + new_sprite.spcode,
                    True, True))

            # spacing
            print("\n\n")

            # ask to create the sprite
            if not menutils.ask("Create sprite"):
                print("\nSprite discarded.\n")

            else:
                # user said yes!
                # add sprite to db and prompt for more
                sprite_db[new_sprite.spcode] = new_sprite
                sprite_db[atl_sprite.spcode] = atl_sprite
                sprite_created = True
                print("\nSprite created.\n")

            if not menutils.ask("Create another sprite", def_no=False):
                return sprite_created
コード例 #3
0
def run():
    """
    Runs this module (menu related)
    """
    # first load all sprites
    print("Loading sprites...", end="")
    sprite_db = _load_sprites()

    # abort if failed
    if sprite_db is None:
        print("\nERROR in loading sprites. Aborting...")
        return

    # now sort keys
    sprite_db_keys = sorted(sprite_db.keys())

    # otherwise success
    print("DONE")

    choice = True
    while choice is not None:

        # set apropriate title text
        if _need_to_gen_sprites:
            title_entry = ("Sprite Maker" + MSG_UNSAVED, "Option: ")
        else:
            title_entry = ("Sprite Maker", "Option: ")

        menu_main[0] = title_entry

        choice = menutils.menu(menu_main)

        if choice is not None:
            result = choice(sprite_db, sprite_db_keys)

            # only make sprite returns a value, which is the updated keys
            # list
            if result is not None:
                sprite_db_keys = result

        elif _need_to_gen_sprites:
            # user hit None, but we should make sure that they wanted to leave
            # without saving changes
            menutils.clear_screen()
            print("\n\n" + MSG_WARN_GEN)
            if not menutils.ask("Leave this menu"):
                choice = True
コード例 #4
0
def make_sprite(sprite_db, sprite_db_keys):
    """
    Makes a sprite and adds it to the sprite database.
    NOTE: keys should be regenerated after this by the caller

    RETURNS: True if sprite creation successful, False if not
    """
    sprite_obj = FilterSprite()
    sprite_code = []

    # this is the order we ask for sprites as it is the order of the
    # sprite code
    sprite_parts = (
        (FilterSprite.POS, False),
        (FilterSprite.EYE, False),
        (FilterSprite.EYB, False),
        # NOTE: we skip nose because there is only 1
        #        FilterSprite.NSE,
        (FilterSprite.BLH, True),
        (FilterSprite.TRS, True),
        (FilterSprite.SWD, True),
        # NOTE: emote skipped
        #        FilterSprite.EMO,
        (FilterSprite.MTH, False),
    )

    for sp_cat, is_optional in sprite_parts:
        sel_not_chosen = True

        # loop until user selection
        while sel_not_chosen:

            # generate menu
            sel_menu = FilterSprite.build_selection_menu(sp_cat,
                                                         optional=is_optional,
                                                         headeradd=" - " +
                                                         "".join(sprite_code))

            # if optional, we set the default to optional, which is always
            # the last item
            if is_optional:
                defindex = len(sel_menu) - 1
            else:
                defindex = None

            # now run teh menu
            sel_code = menutils.menu(sel_menu, defindex)

            if sel_code is not None:
                # a selection was chosen, check if optinal

                if sel_code != FilterSprite.OPTIONAL:
                    # actual code selected, update the filter sprite and
                    # the sprite code list
                    sprite_code.append(sel_code)
                    sprite_obj.set_filter(sp_cat, sel_code)

                # mark as selected
                sel_not_chosen = False

            else:
                # Exit was reached, verify if we actually want to exit
                print("\nExiting will abort the creation of this sprite!\n")
                if menutils.ask("Discard this sprite"):
                    return False

    # if we reached here, we should have a sprite now
    menutils.clear_screen()

    # lets double check if this is a duplicate
    sprite_code = "".join(sprite_code)
    if sprite_code in sprite_db:
        print("\n\nSprite code {0} already exists! Aborting...".format(
            sprite_code))
        menutils.e_pause()
        return False

    # otherwise, no duplicate
    # lets show the user and then confirm
    print(
        sprite_obj._status(True, "Selected Sprite Settings - " + sprite_code,
                           False, False))

    # TODO: ask user if they would want to see a preview. Get libpng and
    #   generate a composite image with the appropraite paths. This is
    #   really a stretch since exp_previewer covers this already.

    # spacing
    print("\n\n")

    # ask to create the sprite
    if not menutils.ask("Create sprite"):
        print("\nSprite discarded.")
        menutils.e_pause()
        return False

    # user said yes!
    # create the sprite
    real_sprite = StaticSprite(sprite_code)

    # now determine if we need an atl variant
    atl_sprite = real_sprite.make_atl()

    # print and abort if errors occured
    if real_sprite.invalid or (atl_sprite is not None and atl_sprite.invalid):
        menutils.clear_screen()
        print("\n\nError making this sprite. Notify devs to fix.")
        menutils.e_pause()
        return False

    # otherwise we ok
    sprite_db[real_sprite.spcode] = real_sprite

    if atl_sprite is not None:
        sprite_db[atl_sprite.spcode] = atl_sprite

    return True