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 _build_menu(category): """ Builds menu options for a category May return None if errors occured """ is_positions = category == FilterSprite.POS selections = FilterSprite._sprite_map.get(category, None) if selections is None: return None sorted_keys = sorted(selections.keys()) menu = [] # now the items for code in sorted_keys: name = selections[code] if is_positions and type(name) is not str: menu.append((StaticSprite.lean_tostring(name), code)) else: menu.append((name, code)) return menu
def check_file(fpath, sp_dict, gen_if_missing): """ Checks the given file for sprite code correctness IN: fpath - filepath of the fie to check sp_dict - dict of currently available sprite codes gen_if_missing - True will attempt to generate the sprite if it is missing. RETURNS: list of SpriteMismatches, one for every sprite code that was bad """ sp_mismatches = list() ln_count = 1 #Loadd spritemap data StaticSprite._loadSpriteMapData() with open(fpath, "r") as rpy_file: for line in rpy_file: _code = try_extract_code(line.strip()) if _code and _code not in sp_dict: # we have a code but its not in the dict?! if gen_if_missing: # attempt to generate if possible gen_spr = StaticSprite(_code) if gen_spr.invalid: sp_mismatches.append( SpriteMismatch(_code, ln_count, fpath)) else: sp_dict[_code] = gen_spr else: sp_mismatches.append(SpriteMismatch( _code, ln_count, fpath)) ln_count += 1 return sp_mismatches
def _status(self, useheader, headerstring, shownose, showemote): """ Builds string representation of this Filter according to given status props :param useheader: True will use the block header from menutils, False will not :param headerstring: the string to use in the header :param shownose: True will show the nose part of the filter, False will not :param showemote: True will show the emote part of the filter, False will not """ # setup initial strings if useheader: msg = [menutils.header(headerstring)] else: msg = [self._tab + headerstring] # lean and position check if self.position is None: position = None is_lean = None elif self.is_lean: position = StaticSprite.lean_tostring(self.position) is_lean = True else: position = self.position is_lean = self.is_lean # now add each filter piece self.__fmt_flt(msg, "Position:", position) self.__fmt_flt(msg, "Is Lean:", is_lean) self.__fmt_flt(msg, "Eyes:", self.eyes) self.__fmt_flt(msg, "Eyebrows:", self.eyebrows) if shownose: self.__fmt_flt(msg, "Nose:", self.nose) self.__fmt_flt(msg, "Blush:", self.blush) self.__fmt_flt(msg, "Tears:", self.tears) self.__fmt_flt(msg, "Sweatdrop:", self.sweatdrop) if showemote: self.__fmt_flt(msg, "Emote:", self.emote) self.__fmt_flt(msg, "Mouth:", self.mouth) return "".join(msg)
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
def __init__( self, src, depth ): StaticSprite.__init__( self, config.folders['scenes'] + src ) self.depth = depth
def __init__(self, src, depth): StaticSprite.__init__(self, config.folders['scenes'] + src) self.depth = depth