def from_hashable(
         cls, data: Dict[str, Any]) -> Union['CSFSliderTemplate', None]:
     """Create a template from a library of data."""
     log = cls.get_log()
     template_name = data.get('template_name', None)
     if template_name is None:
         log.error('Missing template name.')
         return None
     source_sim_name = data.get('source_sim_name', None)
     if source_sim_name is None:
         log.format_error_with_message('Missing Source Sim Name.',
                                       template_name=template_name)
         return None
     source_sim_age_str = data.get('source_sim_age', None)
     if source_sim_age_str is None:
         log.format_error_with_message('Missing Source Sim Age.',
                                       template_name=template_name)
         return None
     source_sim_age = CommonResourceUtils.get_enum_by_name(
         source_sim_age_str, CommonAge, default_value=CommonAge.INVALID)
     if source_sim_age == CommonAge.INVALID:
         log.format_error_with_message('The Source Sim Age was invalid.',
                                       template_name=template_name)
         return None
     source_sim_species_str = data.get('source_sim_species', None)
     if source_sim_species_str is None:
         log.format_error_with_message('Missing Source Sim Species.',
                                       template_name=template_name)
         return None
     source_sim_species = CommonResourceUtils.get_enum_by_name(
         source_sim_species_str,
         CommonSpecies,
         default_value=CommonSpecies.INVALID)
     if source_sim_species == CommonSpecies.INVALID:
         log.format_error_with_message(
             'The Source Sim Species was invalid.',
             template_name=template_name)
         return None
     slider_data = data.get('slider_data', None)
     if slider_data is None:
         log.format_error_with_message('Missing slider data.',
                                       template_name=template_name)
         return None
     return cls(template_name, source_sim_name, source_sim_age,
                source_sim_species, slider_data)
    def get_outfit_category_by_name(name: str) -> OutfitCategory:
        """get_outfit_category_by_name(name)

        Retrieve an OutfitCategory by its a name.

        :param name: The name of an outfit category.
        :type name: str
        :return: The OutfitCategory with the specified name or OutfitCategory.CURRENT_OUTFIT if no outfit category was found using the specified name.
        :rtype: OutfitCategory
        """
        upper_case_name = str(name).upper().strip()
        return CommonResourceUtils.get_enum_by_name(upper_case_name, OutfitCategory, default_value=OutfitCategory.CURRENT_OUTFIT)
Пример #3
0
def _spawn_human_sims(count: int = 100,
                      gender_str: str = 'male',
                      age_str: str = 'adult',
                      _connection: int = None):
    output = CheatOutput(_connection)
    gender: Gender = CommonResourceUtils.get_enum_by_name(gender_str.upper(),
                                                          Gender,
                                                          default_value=None)
    if gender is None:
        output('{} is not a valid gender'.format(gender_str))
        return
    age: Age = CommonResourceUtils.get_enum_by_name(age_str.upper(),
                                                    Age,
                                                    default_value=None)
    if age is None:
        output('{} is not a valid age'.format(age_str))
        return
    if count <= 0:
        output('Please enter a count above zero.')
        return
    output('Spawning {} Sims of Gender: {} and Age: {}.'.format(
        count, gender.name, age.name))
    try:
        active_sim_info = CommonSimUtils.get_active_sim_info()
        active_sim_location = CommonSimLocationUtils.get_location(
            active_sim_info)
        for x in range(count):
            created_sim_info = CommonSimSpawnUtils.create_human_sim_info(
                gender=gender, age=age, first_name=str(x), last_name=str(x))
            CommonSimSpawnUtils.spawn_sim(created_sim_info,
                                          location=active_sim_location)
    except Exception as ex:
        CommonExceptionHandler.log_exception(ModInfo.get_identity(),
                                             'Error spawning Sims.',
                                             exception=ex)
    output('Done spawning Sims.')