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
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
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