def _load_sprites(): """ Loads sprite code data so this module can use it. NOTE: if None is returnd, treat as failure :returns: dictionary of the following format: [0] - sprite code (without static) [1] - StaticSprite object """ sprite_list = [] # load all static sprites for sprite_filepath in spull.STATIC_CHARTS: with open(os.path.normcase(sprite_filepath), "r") as sprite_file: sprite_list.extend( spull.pull_sprite_list_from_file(sprite_file, True)) # generate dict of static sprites sprite_db = {} for sprite_code in sprite_list: sprite_obj = StaticSprite(sprite_code) # immediately quit if invalid if sprite_obj.invalid: return None # otherwise add sprite_db[sprite_code] = sprite_obj # make as atl if possible atl_sprite = sprite_obj.make_atl() if atl_sprite is not None: sprite_db[atl_sprite.spcode] = atl_sprite return sprite_db
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
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