def load(self) -> Iterator[CSFSlider]:
        """load()

        Loads all Sliders.

        :return: An iterable of Sliders.
        :rtype: Iterator[CSFSlider]
        """
        snippet_names: Tuple[str] = self.snippet_names

        for snippet_package in CommonResourceUtils.load_instances_with_any_tags(
                Types.SNIPPET, snippet_names):
            try:
                sliders: Tuple[CSFSlider] = tuple(self._load(snippet_package))

                for slider in sliders:
                    slider: CSFSlider = slider
                    if slider is None:
                        continue
                    (is_valid_result, is_valid_reason) = slider.is_valid()
                    if is_valid_result:
                        yield slider
            except Exception as ex:
                self.log.format_error(
                    'Error while parsing sliders from \'{}\''.format(
                        snippet_package),
                    exception=ex)
        def _on_yes_selected(_: Any):
            from sims4controlmenu.dialogs.modify_sim_data.modify_skills.operations.set_skill_level import \
                S4CMSetSkillLevelsSimOp
            skill_manager = CommonResourceUtils.get_instance_manager(Types.STATISTIC)
            sim = CommonSimUtils.get_sim_instance(sim_info)
            for skill in skill_manager.get_ordered_types(only_subclasses_of=Skill):
                skill: Skill = skill
                if not S4CMSetSkillLevelsSimOp()._is_skill_allowed_for_modification(sim_info, skill):
                    continue
                if not skill.can_add(sim):
                    self.verbose_log.format_with_message('Failed, Skill is not allowed for Sim.', skill=skill, sim=sim_info)
                    continue
                skill_levels = tuple(range(0, skill.max_level + 1))
                chosen_skill_level = random.choice(skill_levels)
                if chosen_skill_level == 0:
                    if CommonSimSkillUtils.has_skill(sim_info, skill):
                        CommonSimSkillUtils.remove_skill(sim_info, skill)
                else:
                    CommonSimSkillUtils.set_current_skill_level(sim_info, skill, int(chosen_skill_level))

            CommonBasicNotification(
                S4CMSimModifySkillsStringId.RANDOMIZED_SKILL_LEVELS_OF_SIM_TITLE,
                S4CMSimModifySkillsStringId.RANDOMIZED_SKILL_LEVELS_OF_SIM_DESCRIPTION,
                title_tokens=(sim,),
                description_tokens=(sim,)
            ).show(icon=IconInfoData(obj_instance=sim))
            _on_close()
Esempio n. 3
0
    def remove_relationship_bit(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_bit_id: int
    ) -> bool:
        """remove_relationship_bit(sim_info, target_sim_info, relationship_bit_id)

        Remove a relationship bit between two sims.

        .. note::

            If the relationship bit is UNIDIRECTIONAL, it will only be removed from sim_info in the direction of the Target.
            i.e. Sim will have no longer have relationship bit towards Target, but Target will still have relationship bit towards Sim.

            One example is the Caregiver relationship:

            - Sim is caregiver of Target.
            - Target is being cared for by Sim.

        :param sim_info: The source Sim of the Relationship Bit.
        :type sim_info: SimInfo
        :param target_sim_info: The target Sim of the Relationship Bit.
        :type target_sim_info: SimInfo
        :param relationship_bit_id: The identifier of the Relationship Bit to remove.
        :type relationship_bit_id: int
        :return: True, if the relationship bit was removed successfully. False, if not.
        :rtype: bool
        """
        relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
        if relationship_bit_instance is None:
            return False
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        sim_info.relationship_tracker.remove_relationship_bit(target_sim_id, relationship_bit_instance)
        return True
Esempio n. 4
0
    def get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info: SimInfo, relationship_bit_ids: Iterator[int]) -> Iterator[SimInfo]:
        """
            Retrieve an Iterator of SimInfo for all Sims that have the specified relationship bits with the specified Sim.

            Note: For UNIDIRECTIONAL relationship bits, the direction is sim_info has relationship bit with target_sim_info
            Caregiver example:
            The Caregiver has a relationship bit pointed at Toddler (The Caregiver would show "caregiving ward" when hovering over the toddler in the relationships panel)
            The toddler would NOT have the relationship bit.
            Sim is Caregiver of Toddler.
        """
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        for relationship in sim_info.relationship_tracker:
            if relationship.sim_id_a != sim_id:
                target_sim_id = relationship.sim_id_a
            else:
                target_sim_id = relationship.sim_id_b
            target_sim_info = CommonSimUtils.get_sim_info(target_sim_id)
            if target_sim_info is None or CommonSimUtils.get_sim_instance(target_sim_info) is None:
                continue
            for relationship_bit_id in relationship_bit_ids:
                relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
                if relationship_bit_instance is None:
                    continue
                if relationship.has_bit(sim_id, relationship_bit_instance):
                    yield target_sim_info
                    break
Esempio n. 5
0
    def change_relationship_level_of_sims(
        sim_info: SimInfo,
        target_sim_info: SimInfo,
        relationship_track_id: int,
        level: float
    ) -> bool:
        """change_relationship_level_of_sims(sim_info, target_sim_info, relationship_track_id, level)

        Change the level of a relationship track between two Sims.

        :param sim_info: The sim that owns the relationship track.
        :type sim_info: SimInfo
        :param target_sim_info: The target of the relationship track.
        :type target_sim_info: SimInfo
        :param relationship_track_id: The identifier of the Relationship Track to change.
        :type relationship_track_id: int
        :param level: The amount to add to the relationship track (Can be positive or negative).
        :type level: float
        :return: True, if the relationship track was changed successfully. False, if not.
        :rtype: bool
        """
        relationship_track = CommonResourceUtils.load_instance(Types.STATISTIC, relationship_track_id)
        if relationship_track is None:
            return False
        target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
        sim_info.relationship_tracker.add_relationship_score(target_sim_id, level, relationship_track)
        return True
Esempio n. 6
0
 def _load_statistic_instance(
         statistic_id: Union[int,
                             CommonStatisticId]) -> Union[Statistic, None]:
     statistic_instance = CommonResourceUtils.load_instance(
         Types.STATISTIC, statistic_id)
     if statistic_instance is None:
         return None
     return statistic_instance
 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)
Esempio n. 8
0
    def load_unchecked_square_icon() -> Any:
        """load_unchecked_square_icon()

        Get the Resource Key for the UNCHECKED_SQUARE_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_UNCHECKED_SQUARE_ICON)
Esempio n. 9
0
    def load_question_mark_icon() -> Any:
        """load_question_mark_icon()

        Get the Resource Key for the QUESTION_MARK_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_QUESTION_MARK_ICON)
Esempio n. 10
0
    def load_arrow_navigate_into_icon() -> Any:
        """load_arrow_navigate_into_icon()

        Get the Resource Key for the ARROW_NAVIGATE_INTO_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_ARROW_NAVIGATE_INTO_ICON)
Esempio n. 11
0
    def load_arrow_right_icon() -> Any:
        """load_arrow_right_icon()

        Get the Resource Key for the ARROW_RIGHT_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_ARROW_RIGHT_ICON)
    def load_x_icon() -> Any:
        """load_x_icon()

        Get the Resource Key for the X_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_X_ICON)
    def load_checked_circle_icon() -> Any:
        """load_checked_circle_icon()

        Get the Resource Key for the CHECKED_CIRCLE_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_CHECKED_CIRCLE_ICON)
    def load_text_next_icon() -> Any:
        """load_text_next_icon()

        Get the Resource Key for the TEXT_NEXT_SQUARE_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_TEXT_NEXT_SQUARE_ICON)
    def load_blank_square_icon() -> Any:
        """load_blank_square_icon()

        Get the Resource Key for the BLANK_SQUARE_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_BLANK_SQUARE_ICON)
Esempio n. 16
0
    def get_venue_of_current_lot() -> Venue:
        """get_venue_of_current_lot()

        Retrieve a Venue for the current lot.

        :return: The Venue of the current lot.
        :rtype: Venue
        """
        return CommonResourceUtils.load_instance(Types.VENUE, CommonLocationUtils.get_current_venue_type())
Esempio n. 17
0
    def load_six_sided_dice_icon() -> Any:
        """load_six_sided_dice_icon()

        Get the Resource Key for the SIX_SIDED_DICE_ICON.

        :return: An identifier for the icon.
        :rtype: Any
        """
        return CommonResourceUtils.get_resource_key(Types.PNG, CommonIconId.S4CLIB_SIX_SIDED_DICE_ICON)
Esempio n. 18
0
 def _opposite_display_name(self) -> int:
     if self.__opposite_display_name is None:
         relationship_bit_id: int = self.opposite_relationship_bit_id
         relationship_bit: RelationshipBit = CommonResourceUtils.load_instance(
             Types.RELATIONSHIP_BIT, relationship_bit_id)
         if relationship_bit is None:
             self.__opposite_display_name = 0
         # noinspection PyUnresolvedReferences
         self.__opposite_display_name = relationship_bit.display_name
     return self.__opposite_display_name
 def _load_outfit_parts_from_packages_gen(self) -> Iterator[OCOutfitPart]:
     self.log.debug('Loading outfit parts from packages.')
     outfit_part_collections = CommonResourceUtils.load_instances_with_any_tags(
         Types.SNIPPET, ('outfit_parts_list', ))
     for outfit_part_collection in outfit_part_collections:
         for package_outfit_part in outfit_part_collection.outfit_parts_list:
             outfit_part = OCOutfitPart.load_from_package(
                 package_outfit_part, self.log)
             if outfit_part is None:
                 continue
             yield outfit_part
    def load_interaction_by_id(interaction_id: Union[int, CommonInteractionId]) -> Union[Interaction, None]:
        """load_interaction_by_id(interaction_id)

        Load an instance of an Interaction by its decimal identifier.

        :param interaction_id: The decimal identifier of an Interaction.
        :type interaction_id: Union[int, CommonInteractionId]
        :return: An instance of an Interaction matching the decimal identifier or None if not found.
        :rtype: Union[Interaction, None]
        """
        return CommonResourceUtils.load_instance(Types.INTERACTION, interaction_id)
    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)
Esempio n. 22
0
 def get_relationship_level_of_sims(
     sim_info: SimInfo,
     target_sim_info: SimInfo,
     relationship_track_id: int
 ) -> float:
     """
         Retrieve the level of a relationship track between two sims.
     """
     relationship_track = CommonResourceUtils.load_instance(Types.STATISTIC, relationship_track_id)
     if relationship_track is None:
         return 0.0
     target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
     return sim_info.relationship_tracker.get_relationship_score(target_sim_id, relationship_track)
Esempio n. 23
0
    def load_situation_by_id(situation_id: Union[int, CommonSituationId]) -> Union[Situation, None]:
        """load_situation_by_id(situation_id)

        Load an instance of a Situation by its decimal identifier.

        :param situation_id: The decimal identifier of a Situation.
        :type situation_id: Union[int, CommonSituationId]
        :return: An instance of a Situation matching the decimal identifier or None if not found.
        :rtype: Union[Situation, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.SITUATION, situation_id)
    def load_trait_by_id(trait_id: Union[int, CommonTraitId]) -> Union[Trait, None]:
        """load_trait_by_id(trait_id)

        Load an instance of a Trait by its decimal identifier.

        :param trait_id: The decimal identifier of a Trait.
        :type trait_id: Union[int, CommonTraitId]
        :return: An instance of a Trait matching the decimal identifier or None if not found.
        :rtype: Union[Trait, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.TRAIT, trait_id)
Esempio n. 25
0
    def load_statistic_by_id(
            statistic_id: Union[int,
                                CommonStatisticId]) -> Union[Statistic, None]:
        """load_statistic(statistic_id)

        Load an instance of a Statistic by its decimal identifier.

        :param statistic_id: The decimal identifier of a Statistic.
        :type statistic_id: Union[int, CommonStatisticId]
        :return: An instance of a Statistic matching the decimal identifier or None if not found.
        :rtype: Union[Statistic, None]
        """
        return CommonResourceUtils.load_instance(Types.STATISTIC, statistic_id)
Esempio n. 26
0
    def load_buff_by_id(
            buff_id: Union[int, CommonBuffId]) -> Union[Buff, None]:
        """load_buff_by_id(buff_id)

        Load an instance of a Buff by its decimal identifier.

        :param buff_id: The decimal identifier of a Buff.
        :type buff_id: Union[int, CommonBuffId]
        :return: An instance of a Buff matching the decimal identifier or None if not found.
        :rtype: Union[Buff, None]
        """
        from sims4.resources import Types
        from sims4communitylib.utils.common_resource_utils import CommonResourceUtils
        return CommonResourceUtils.load_instance(Types.BUFF, buff_id)
Esempio n. 27
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.')
        def _on_yes_selected(_: Any):
            skill_manager = CommonResourceUtils.get_instance_manager(
                Types.STATISTIC)
            sim = CommonSimUtils.get_sim_instance(sim_info)
            for skill in skill_manager.get_ordered_types(
                    only_subclasses_of=Skill):
                skill: Skill = skill
                if not CommonSimSkillUtils.has_skill(sim_info, skill):
                    continue
                CommonSimSkillUtils.remove_skill(sim_info, skill)

            CommonBasicNotification(
                S4CMSimModifySkillsStringId.REMOVED_ALL_SKILLS_TITLE,
                S4CMSimModifySkillsStringId.REMOVED_ALL_SKILLS_DESCRIPTION,
                title_tokens=(sim, ),
                description_tokens=(sim, )).show(icon=IconInfoData(
                    obj_instance=sim))
            _on_close()
Esempio n. 29
0
 def add_relationship_bit(
     sim_info: SimInfo,
     target_sim_info: SimInfo,
     relationship_bit_id: int
 ) -> bool:
     """
         Add a relationship bit between two sims.
         Note: If the relationship bit is UNIDIRECTIONAL, it will only be added to sim_info in the direction of the Target.
         i.e. Sim will have relationship bit towards Target, but Target will not have relationship bit towards Sim.
         One example is the Caregiver relationship:
         - Sim is caregiver of Target.
         - Target is being cared for by Sim.
     """
     relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
     if relationship_bit_instance is None:
         return False
     target_sim_id = CommonSimUtils.get_sim_id(target_sim_info)
     sim_info.relationship_tracker.add_relationship_bit(target_sim_id, relationship_bit_instance)
     return True
Esempio n. 30
0
    def get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info: SimInfo, relationship_bit_ids: Iterator[int], instanced_only: bool=True) -> Iterator[SimInfo]:
        """get_sim_info_of_all_sims_with_relationship_bits_generator(sim_info, relationship_bit_ids, instanced_only=True)

        Retrieve an Iterator of SimInfo for all Sims that have the specified relationship bits with the specified Sim.

        .. note::

            For UNIDIRECTIONAL relationship bits, the direction is sim_info has relationship bit with target_sim_info
            Caregiver example:

            - The Caregiver has a relationship bit pointed at Toddler (The Caregiver would show "caregiving ward" when hovering over the toddler in the relationships panel)
            - The toddler would NOT have the relationship bit.
            - Sim is Caregiver of Toddler.

        :param sim_info: The Sim to locate relationship bits on.
        :type sim_info: SimInfo
        :param relationship_bit_ids: A collection of identifiers for relationship bits to locate connections with.
        :type relationship_bit_ids: Iterator[int]
        :param instanced_only: If True, only Sims that are currently loaded will be returned.
        :type instanced_only: bool, optional
        :return: An iterable of Sims that have any of the specified relationship bits with the specified Sim.
        :rtype: Iterator[SimInfo]
        """
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        for relationship in sim_info.relationship_tracker:
            if relationship.sim_id_a != sim_id:
                target_sim_id = relationship.sim_id_a
            else:
                target_sim_id = relationship.sim_id_b
            target_sim_info = CommonSimUtils.get_sim_info(target_sim_id)
            if target_sim_info is None:
                continue
            if instanced_only and CommonSimUtils.get_sim_instance(target_sim_info) is None:
                continue
            for relationship_bit_id in relationship_bit_ids:
                relationship_bit_instance = CommonResourceUtils.load_instance(Types.RELATIONSHIP_BIT, relationship_bit_id)
                if relationship_bit_instance is None:
                    continue
                if relationship.has_bit(sim_id, relationship_bit_instance):
                    yield target_sim_info
                    break