Esempio n. 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()
Esempio n. 2
0
def run_chk(quiet=False, inc_dev=False):
    """
    Main sprite checker workflow

    IN:
        quiet - True will suppress output
        inc_dev - True will include dev files in check, False will not
    """
    if not quiet:
        inc_dev = menutils.menu(menu_inc_dev)

        if inc_dev is None:
            return

    bad_codes = check_sprites(inc_dev=inc_dev)

    if len(bad_codes) == 0:
        # no bad codes
        if not quiet:
            print("All sprite codes accounted for!")
            menutils.e_pause()
        return

    # otherwise, bad codes found, we should write them out
    if not quiet:
        print("We found some invalid sprites. Writing results to " +
              BAD_CODE_FN)

    write_bad_codes(bad_codes)

    if not quiet:
        print("\nDone")
        menutils.e_pause()
Esempio n. 3
0
def run_gss(sprite_db, sprite_db_keys, quiet=False, sp_per_file=500):
    """
    Generates static sprites, and alises

    IN:
        quiet - supresses menus and stdout
        sp_per_file - max number of sprites allowed per file
    """
    # ask if okay to overwrite files
    if not quiet:
        print("\n" + MSG_OVERWRITE.format(", ".join(
            [spull.STATIC_PREFIX, spull.ALIAS_PREFIX, spull.ATL_PREFIX])))
        if not menutils.ask_continue():
            return

    # generate static sprites
    if not gen_sprite_files(list(
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.STATIC_PREFIX,
                            spull.STATIC_TEMPLATE,
                            __SP_STATIC_HEADER,
                            quiet=quiet,
                            sp_per_file=sp_per_file):
        return

    # now for filter sprites
    if not gen_sprite_files(filter(
            StaticSprite.as_is_closed_eyes,
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.ALIAS_PREFIX,
                            spull.ALIAS_TEMPLATE,
                            __SP_STATIC_HEADER,
                            spacing="\n",
                            tostring=StaticSprite.as_alias_static,
                            quiet=quiet,
                            sp_per_file=5000):
        return

    # and finally atl sprites
    if not gen_sprite_files(filter(
            StaticSprite.as_is_not_closed_eyes,
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.ATL_PREFIX,
                            spull.ATL_TEMPLATE,
                            __SP_STATIC_HEADER,
                            tostring=StaticSprite.as_atlify,
                            quiet=quiet,
                            sp_per_file=sp_per_file):
        return

    # done, print done
    if not quiet:
        menutils.e_pause()

    global _need_to_gen_sprites
    _need_to_gen_sprites = False
Esempio n. 4
0
def run_rpy_all(quiet=False):
    """
    Generates optimized image rpy for ALL images

    IN:
        quiet - True will suppress output
    """
    if not quiet:
        print("Generating sprite list....")

    sp_list = pull_sprite_list()

    if not quiet:
        print("Writing optimized rpy to " + SAVE_PATH_IO)

    write_zz_sprite_opt(sp_list)

    if not quiet:
        print("\nDone")
        menutils.e_pause()
Esempio n. 5
0
def run_spl(quiet=False):
    """
    Generates the sprite code list and writes it to file

    IN:
        quiet - True will suppress output
    """
    if not quiet:
        print("Generating sprite list....")

    sp_list = pull_sprite_list()

    if not quiet:
        print("Writing sprite list to " + SAVE_PATH)

    write_spritecodes(sp_list)

    if not quiet:
        print("\nDone")
        menutils.e_pause()
Esempio n. 6
0
def generate_expr_test(quiet=False):
    """
    Uses the expressions retrieved from the spritepuller utility,
    then cleans them(remove duplicates, remove old expressions),
    sorts them and finally generates a file named zzzz_dev_exprtest.rpy
    which adds an event which can be accessed in-game to check every single
    expression added

    IN:
        quiet - True will suppress output
    """
    if not quiet:
        print("\nPulling Sprites ...")
    # pull the sprites and put them in a set to remove duplicates
    sp_list = set(spp.pull_sprite_list())

    # pick only the new ones
    sp_list = [x for x in sp_list if len(x) > 3]

    # sort them
    sp_list.sort()

    if not quiet:
        print("\nWriting to file ...")

    with open(GDIR.REL_PATH_DEV+ EXPR_TEST_FN, "w") as outfile:

        # write the header
        outfile.write(__ZZ_EXPR_TEST_HEADER)

        for sp in sp_list:

            # write each line format will be 'm expr_code "expr_code"'
            outfile.write(__ZZ_EXPR_TEST_LINE.format(sp) + "\n")

        # write the footer
        outfile.write(__ZZ_EXPR_TEST_FOOTER)

    if not quiet:
        print("\nDone")
        menutils.e_pause()
Esempio n. 7
0
def run_gss(sprite_db, sprite_db_keys, quiet=False, sp_per_file=500):
    """
    Generates static sprites, and alises

    IN:
        quiet - supresses menus and stdout
        sp_per_file - max number of sprites allowed per file
    """
    # ask for draw function to use
    if not quiet:
        df_choice = True
        while df_choice is not None:
            df_choice = menutils.menu(menu_sdf, defindex=1)

            # if no choice was made here (or we aborted), then quit
            if df_choice is None:
                return

            # otherwise set and quit loop
            spr_module.draw_function = df_choice
            df_choice = None

    # ask if okay to overwrite files
    if not quiet:
        print("\n" + MSG_OVERWRITE.format(", ".join(
            [spull.STATIC_PREFIX, spull.ALIAS_PREFIX, spull.ATL_PREFIX])))
        if not menutils.ask_continue():
            return

    # generate static sprites
    if not gen_sprite_files(list(
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.STATIC_PREFIX,
                            spull.STATIC_TEMPLATE,
                            __SP_STATIC_HEADER,
                            quiet=quiet,
                            sp_per_file=sp_per_file):
        return

    # now for filter sprites
    if not gen_sprite_files(filter(
            StaticSprite.as_is_closed_eyes,
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.ALIAS_PREFIX,
                            spull.ALIAS_TEMPLATE,
                            __SP_STATIC_HEADER,
                            spacing="\n",
                            tostring=StaticSprite.as_alias_static,
                            quiet=quiet,
                            sp_per_file=5000):
        return

    # and finally atl sprites
    if not gen_sprite_files(filter(
            StaticSprite.as_is_not_closed_eyes,
            SortedKeySpriteDBIter(sprite_db, sprite_db_keys)),
                            spull.ATL_PREFIX,
                            spull.ATL_TEMPLATE,
                            __SP_STATIC_HEADER,
                            tostring=StaticSprite.as_atlify,
                            quiet=quiet,
                            sp_per_file=sp_per_file):
        return

    # done, print done
    if not quiet:
        menutils.e_pause()

    global _need_to_gen_sprites
    _need_to_gen_sprites = False
Esempio n. 8
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
Esempio n. 9
0
def gen_sprite_files(sprites,
                     file_prefix,
                     file_template,
                     file_header,
                     spacing="\n\n",
                     tostring=str,
                     quiet=False,
                     sp_per_file=500,
                     skip_pause=True,
                     skip_continue=True):
    """
    Generates sprite files. 

    IN:
        sprites - the list of sprite objects to generate stuff for
        file_prefix - the prefix for each filename
        file_template - the template for each filename
        file_header - the header to write at the top of each file
        spacing - spacing between items
            (Default: \n\n)
        tostring - to string function to use (must take a sprite object)
            (Default: str)
        quiet - True will supress menus and stdout
            (Default: False)
        sp_per_file - max number of sprites allowed per file
            (Default: 500)
        skip_pause - True will skip pause at end. False will not
            (Default: True)
        skip_continue - True will skip the continue. False will not

    RETURNS: True if successful, False if abort
    """
    # first, check if we will go over the max file limit
    if (int(len(sprites) / sp_per_file) + 1) > spull.MAX_FILE_LIMIT:
        # always show error messages
        print(MSG_OVER_FILE_LIMIT.format(len(sprites), spull.MAX_FILE_LIMIT))
        return False

    # ask user to continue
    if not (quiet or skip_continue):
        print(MSG_OVERWRITE.format(file_prefix))
        if not menutils.ask_continue():
            return False

    # setup file counts
    file_num = 0
    sp_count = 0

    # and file data
    filename = file_template.format(file_num)
    filepath = GDIR.REL_PATH_GAME + filename

    # create thef irst file
    if not quiet:
        print(MSG_GEN_FILE.format(filename), end="")
    output_file = open(os.path.normcase(filepath), "w")
    output_file.write(file_header)

    # begin loop over sprites
    for sprite_obj in sprites:

        if sp_count >= sp_per_file:
            # over the sprites per file limit. we should make new file.

            # increment counts
            sp_count = 0
            file_num += 1

            # close file and say done
            output_file.close()
            if not quiet:
                print("done")

            # setup next file stuff
            filename = file_template.format(file_num)
            filepath = GDIR.REL_PATH_GAME + filename

            # open file
            if not quiet:
                print(MSG_GEN_FILE.format(filename), end="")
            output_file = open(os.path.normcase(filepath), "w")
            output_file.write(file_header)

        # add sprite object to file
        output_file.write(tostring(sprite_obj))
        output_file.write(spacing)
        sp_count += 1

    # finally, close the last file and say done
    output_file.close()
    if not quiet:
        print("done")

        if not skip_pause:
            menutils.e_pause()

    return True