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()
def run_lstc_setfilter(sprite_db, sprite_db_keys, ss_filter): """ Set filter settings """ choice = True while choice is not None: choice = menutils.menu(ss_filter.menu_flt_set) if choice is not None: # get a menu baesd on the category category_menu = FilterSprite.build_menu(choice) if category_menu is not None: code = menutils.menu(category_menu) # set if not none if code is not None: ss_filter.set_filter(choice, code)
def run(): """ Runs this module (menu-related) """ choice = menutils.menu(menu_main) if choice is None: return # otherwise we have a choice choice()
def run_lstc(sprite_db, sprite_db_keys): """ List codes submenu """ choice = True ss_filter = FilterSprite() while choice is not None: choice = menutils.menu(menu_lstc) if choice is not None: choice(sprite_db, sprite_db_keys, ss_filter)
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
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 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
## TODO ## we need a neato menu for everything # # VER: python 2.7 import spritepuller as spp import spritechecker as spc import testsgenerator as tg import menutils menu_main = [ ("MAS Dev Tools", "Utility: "), ("Sprite Puller", spp.run), ("Check Sprites", spc.run), ("Generate Expressions Test", tg.run) ] choice = True while choice is not None: choice = menutils.menu(menu_main) if choice is not None: choice()