def _setup_dialog_rows(
        self,
        sim_info: SimInfo,
        _dialog: UiOutfitPicker,
        outfit_list: Iterator[Tuple[OutfitCategory, int]]=()
    ):
        self.log.debug('Adding rows.')
        sim_id = CommonSimUtils.get_sim_id(sim_info)
        added_rows = False
        current_outfit = CommonOutfitUtils.get_current_outfit(sim_info)
        for (outfit_category, outfit_index) in outfit_list:
            # noinspection PyTypeChecker
            if not CommonOutfitUtils.has_outfit(sim_info, (outfit_category, outfit_index)) and not CommonOutfitUtils.has_outfit(sim_info, (int(outfit_category), outfit_index)):
                self.log.format_with_message('Sim does not have outfit.', sim=sim_info, outfit_category_and_index=(outfit_category, outfit_index))
                continue
            added_rows = True
            _dialog.add_row(
                OutfitPickerRow(
                    sim_id,
                    outfit_category,
                    outfit_index,
                    is_enable=True,
                    is_selected=(outfit_category, outfit_index) == current_outfit,
                    tag=(outfit_category, outfit_index)
                )
            )

        for row in self.rows:
            _dialog.add_row(row)

        if not added_rows and len(self.rows) == 0:
            raise AssertionError('No rows have been provided. Add rows to the dialog before attempting to display it.')
 def __init__(self, sim_info: SimInfo, outfit_category_and_index: Tuple[OutfitCategory, int]=None, initial_outfit_parts: Dict[BodyType, int]=None, mod_identity: CommonModIdentity=None):
     super().__init__()
     self._mod_identity = mod_identity
     self._sim_info: SimInfo = sim_info
     self._current_outfit_category_and_index = CommonOutfitUtils.get_current_outfit(sim_info)
     self._outfit_category_and_index: Tuple[OutfitCategory, int] = outfit_category_and_index or self._current_outfit_category_and_index
     self._outfit_data: OutfitData = None
     self._outfit_parts: Dict[BodyType, int] = None
     self._original_outfit_data: FrozenSet[int] = None
     self._outfit_body_types: List[Union[BodyType, int]] = None
     self._outfit_part_ids: List[int] = None
     self._load(initial_outfit_parts=initial_outfit_parts)
コード例 #3
0
    def has_cas_part_attached(
            sim_info: SimInfo,
            cas_part_id: int,
            body_type: Union[BodyType, int, None] = BodyType.NONE,
            outfit_category_and_index: Tuple[OutfitCategory,
                                             int] = None) -> bool:
        """has_cas_part_attached(sim_info, cas_part_id, body_type=BodyType.NONE, outfit_category_and_index=None)

        Determine if a Sim has the specified CAS part attached to their outfit.

        :param sim_info: The SimInfo of the Sim to check.
        :type sim_info: SimInfo
        :param cas_part_id: A decimal identifier of the CAS part to locate.
        :type cas_part_id: int
        :param body_type: The BodyType the CAS part will be located at. If no value is provided, it defaults to the BodyType of the CAS part itself. If set to None, the CAS part will be located within any BodyType.
        :type body_type: Union[BodyType, int, None], optional
        :param outfit_category_and_index: The outfit category and index of the Sims outfit to check. Default is the Sims current outfit.
        :type outfit_category_and_index: Union[Tuple[OutfitCategory, int], None], optional
        :return: True, if the Sims outfit contain the specified CAS part. False, if the Sims outfit does not contain the specified CAS part.
        :rtype: bool
        """
        log.format_with_message(
            'Checking if CAS part is attached to Sim.',
            sim=sim_info,
            cas_part_id=cas_part_id,
            body_type=body_type,
            outfit_category_and_index=outfit_category_and_index)
        if body_type == BodyType.NONE:
            body_type = CommonCASUtils.get_body_type_of_cas_part(cas_part_id)
        if outfit_category_and_index is None:
            outfit_category_and_index = CommonOutfitUtils.get_current_outfit(
                sim_info)
        log.format(body_type=body_type,
                   outfit_category_and_index=outfit_category_and_index)
        outfit_parts = CommonOutfitUtils.get_outfit_parts(
            sim_info, outfit_category_and_index=outfit_category_and_index)
        if not outfit_parts:
            log.debug('No body parts found.')
            return False
        log.format_with_message('Found body parts from outfit.',
                                body_parts=outfit_parts)
        if body_type is None:
            log.debug('No BodyType specified.')
            return cas_part_id in outfit_parts.values()
        if body_type not in outfit_parts:
            log.debug('Specified BodyType not found within body parts.')
            return False
        log.debug('BodyType found within Sims outfit parts.')
        attached_cas_part_id = outfit_parts[body_type]
        log.format(attached_cas_part_id=attached_cas_part_id)
        return cas_part_id == attached_cas_part_id
コード例 #4
0
    def get_body_type_cas_part_is_attached_to(
        sim_info: SimInfo,
        cas_part_id: int,
        outfit_category_and_index: Tuple[OutfitCategory, int] = None
    ) -> Union[BodyType, int]:
        """get_body_type_cas_part_is_attached_to(sim_info, cas_part_id, outfit_category_and_index=None)

        Retrieve the BodyType that a CAS part is attached to within a Sims outfit.

        :param sim_info: The SimInfo of the Sim to check.
        :type sim_info: SimInfo
        :param cas_part_id: A decimal identifier of the CAS part to locate.
        :type cas_part_id: int
        :param outfit_category_and_index: The outfit category and index of the Sims outfit to check. If None, the current outfit of the Sim will be used.
        :type outfit_category_and_index: Tuple[OutfitCategory, int], optional
        :return: The BodyType the specified CAS part id is attached to or BodyType.NONE if the CAS part is not found or the Sim does not have body parts for their outfit.
        :rtype: Union[BodyType, int]
        """
        log.format_with_message(
            'Retrieving BodyType for CAS part.',
            sim=sim_info,
            cas_part_id=cas_part_id,
            outfit_category_and_index=outfit_category_and_index)
        if outfit_category_and_index is None:
            outfit_category_and_index = CommonOutfitUtils.get_current_outfit(
                sim_info)
        log.format(cas_part_id=cas_part_id,
                   outfit_category_and_index=outfit_category_and_index)
        outfit_parts = CommonOutfitUtils.get_outfit_parts(
            sim_info, outfit_category_and_index=outfit_category_and_index)
        if not outfit_parts:
            log.debug('No body parts found on Sim!')
            return BodyType.NONE
        log.format_with_message('Found body parts from outfit.',
                                body_parts=outfit_parts)
        for body_type in outfit_parts.keys():
            if cas_part_id != outfit_parts[body_type]:
                continue
            # noinspection PyBroadException
            try:
                body_type = BodyType(body_type)
            except:
                body_type = body_type
            log.format_with_message(
                'Found the BodyType the specified CAS part is attached to.',
                body_type=body_type)
            return body_type
        log.debug('No BodyType was found matching the specified CAS part.')
        return BodyType.NONE
コード例 #5
0
    def swap_gender(sim_info: SimInfo, update_gender_options: bool=True) -> bool:
        """swap_gender(sim_info, update_gender_options=True)

        Swap the Gender of a Sim to it's opposite. i.e. Change a Sim from Male to Female or from Female to Male.

        :param sim_info: An instance of a Sim.
        :type sim_info: SimInfo
        :param update_gender_options: If True, gender option traits such as Toilet Usage, Clothing Preference, Pregnancy, and Body Frame will be updated to reflect the vanilla settings for each gender\
        For example, if a Human Sim is swapping from Female to Male, their gender options will be updated to Toilet Standing, Cannot Be Impregnated, Can Impregnate, Mens Wear clothing preference, and Masculine Frame.\
        If False, gender option traits will not be updated.\
        Default is True.
        :type update_gender_options: bool, optional
        :return: True, if the Gender of the Sim was swapped successfully. False, if not.
        :rtype: bool
        """
        from sims4communitylib.utils.sims.common_sim_gender_option_utils import CommonSimGenderOptionUtils
        result = False
        frame = CommonSimGenderOptionUtils.has_masculine_frame(sim_info)
        prefers_menswear = CommonSimGenderOptionUtils.prefers_menswear(sim_info)
        can_impregnate = CommonSimGenderOptionUtils.can_impregnate(sim_info)
        can_be_impregnated = CommonSimGenderOptionUtils.can_be_impregnated(sim_info)
        can_reproduce = CommonSimGenderOptionUtils.can_reproduce(sim_info)
        uses_toilet_standing = CommonSimGenderOptionUtils.uses_toilet_standing(sim_info)
        has_breasts = CommonSimGenderOptionUtils.has_breasts(sim_info)
        saved_outfits = sim_info.save_outfits()
        current_outfit = CommonOutfitUtils.get_current_outfit(sim_info)
        if CommonGenderUtils.is_male(sim_info):
            result = CommonGenderUtils.set_gender(sim_info, Gender.FEMALE)
            if update_gender_options:
                CommonSimGenderOptionUtils.update_gender_options_to_vanilla_female(sim_info)
        elif CommonGenderUtils.is_female(sim_info):
            result = CommonGenderUtils.set_gender(sim_info, Gender.MALE)
            if update_gender_options:
                CommonSimGenderOptionUtils.update_gender_options_to_vanilla_male(sim_info)
        if not update_gender_options:
            CommonSimGenderOptionUtils.update_body_frame(sim_info, frame)
            CommonSimGenderOptionUtils.update_clothing_preference(sim_info, prefers_menswear)
            CommonSimGenderOptionUtils.update_can_impregnate(sim_info, can_impregnate)
            CommonSimGenderOptionUtils.update_can_be_impregnated(sim_info, can_be_impregnated)
            CommonSimGenderOptionUtils.update_can_reproduce(sim_info, can_reproduce)
            CommonSimGenderOptionUtils.update_toilet_usage(sim_info, uses_toilet_standing)
            CommonSimGenderOptionUtils.update_has_breasts(sim_info, has_breasts)
            sim_info.load_outfits(saved_outfits)
            CommonOutfitUtils.resend_outfits(sim_info)
            CommonOutfitUtils.set_current_outfit(sim_info, current_outfit)
        return result
コード例 #6
0
    def get_cas_part_id_at_body_type(
            sim_info: SimInfo,
            body_type: Union[BodyType, int],
            outfit_category_and_index: Tuple[OutfitCategory,
                                             int] = None) -> int:
        """get_cas_part_id_at_body_type(sim_info, body_type, outfit_category_and_index=None)

        Retrieve the CAS part identifier attached to the specified BodyType within a Sims outfit.

        :param sim_info: The SimInfo of the Sim to check.
        :type sim_info: SimInfo
        :param body_type: The BodyType to check.
        :type body_type: Union[BodyType, int]
        :param outfit_category_and_index: The outfit category and index of the Sims outfit to check. Default is the Sims current outfit.
        :type outfit_category_and_index: Tuple[OutfitCategory, int], optional
        :return: The CAS part identifier attached to the specified BodyType or -1 if the BodyType is not found.
        :rtype: int
        """
        log.format_with_message(
            'Checking if CAS part is attached to Sim.',
            sim=sim_info,
            body_type=body_type,
            outfit_category_and_index=outfit_category_and_index)
        if outfit_category_and_index is None:
            outfit_category_and_index = CommonOutfitUtils.get_current_outfit(
                sim_info)
        log.format(body_type=body_type,
                   outfit_category_and_index=outfit_category_and_index)
        outfit_parts = CommonOutfitUtils.get_outfit_parts(
            sim_info, outfit_category_and_index=outfit_category_and_index)
        if not outfit_parts:
            log.debug('No body_parts found on Sim.')
            return -1
        log.format_with_message('Found body parts from outfit.',
                                body_parts=outfit_parts)
        if body_type not in outfit_parts:
            log.debug(
                'The specified BodyType was not found within the Sims outfit.')
            return -1
        log.debug(
            'BodyType has been found within Sims outfit parts. Returning the CAS part belonging to it.'
        )
        return outfit_parts[body_type]
コード例 #7
0
    def get_body_type_cas_part_is_attached_to(
        sim_info: SimInfo,
        cas_part_id: int,
        outfit_category_and_index: Tuple[OutfitCategory,
                                         int] = None) -> BodyType:
        """get_body_type_cas_part_is_attached_to(sim_info, cas_part_id, outfit_category_and_index=None)

        Retrieve the BodyType that a cas part is attached to within a Sims outfit.

        :param sim_info: The SimInfo of the Sim to check.
        :type sim_info: SimInfo
        :param cas_part_id: A decimal identifier of the CAS part to locate.
        :type cas_part_id: int
        :param outfit_category_and_index: The outfit category and index of the Sims outfit to check. Default is the Sims current outfit.
        :type outfit_category_and_index: Tuple[OutfitCategory, int], optional
        :return: The BodyType the specified cas part id is attached to or -1 if the cas part is not found.
        :rtype: BodyType
        """
        log.format_with_message(
            'Retrieving BodyType for cas part.',
            sim=sim_info,
            cas_part_id=cas_part_id,
            outfit_category_and_index=outfit_category_and_index)
        if outfit_category_and_index is None:
            outfit_category_and_index = CommonOutfitUtils.get_current_outfit(
                sim_info)
        log.format(cas_part_id=cas_part_id,
                   outfit_category_and_index=outfit_category_and_index)
        outfit_parts = CommonOutfitUtils.get_outfit_parts(
            sim_info, outfit_category_and_index=outfit_category_and_index)
        if not outfit_parts:
            log.debug('No body parts found.')
            return BodyType.NONE
        log.format_with_message('Found body parts from outfit.',
                                body_parts=outfit_parts)
        for body_type in outfit_parts.keys():
            if cas_part_id != outfit_parts[body_type]:
                continue
            log.format_with_message('Found BodyType.',
                                    body_type=BodyType(body_type))
            return BodyType(body_type)
        log.debug('No BodyType found matching the cas part.')
        return BodyType.NONE
コード例 #8
0
    def attach_cas_part_to_sim(
        sim_info: SimInfo,
        cas_part_id: int,
        body_type: Union[BodyType, int] = BodyType.NONE,
        outfit_category_and_index: Union[Tuple[OutfitCategory, int],
                                         None] = None
    ) -> bool:
        """attach_cas_part_to_sim(sim_info, cas_part_id, body_type=BodyType.NONE, outfit_category_and_index=None)

        Add a CAS part at the specified BodyType to the Sims outfit.

        :param sim_info: The SimInfo of a Sim to add the CAS part to.
        :type sim_info: SimInfo
        :param cas_part_id: The decimal identifier of a CAS part to attach to the Sim.
        :type cas_part_id: int
        :param body_type: The BodyType the CAS part will be attached to. If no value is provided or it is None, the BodyType of the CAS part itself will be used.
        :type body_type: Union[BodyType, int], optional
        :param outfit_category_and_index: The outfit category and index of the Sims outfit to modify. If no value is provided, the Sims current outfit will be used.
        :type outfit_category_and_index: Union[Tuple[OutfitCategory, int], None], optional
        :return: True if the CAS part was successfully attached to the Sim. False if the CAS part was not successfully attached to the Sim.
        :rtype: bool
        """
        log.format_with_message(
            'Attempting to attach CAS part to Sim',
            sim=sim_info,
            cas_part_id=cas_part_id,
            body_type=body_type,
            outfit_category_and_index=outfit_category_and_index)
        if cas_part_id == -1 or cas_part_id is None:
            raise RuntimeError('No cas_part_id was provided.')
        log.debug('Pre-saving outfits.')
        saved_outfits = sim_info.save_outfits()
        if outfit_category_and_index is None:
            outfit_category_and_index = CommonOutfitUtils.get_current_outfit(
                sim_info)
        log.format_with_message(
            'Using outfit category and index.',
            outfit_category_and_index=outfit_category_and_index)
        outfit_data = CommonOutfitUtils.get_outfit_data(
            sim_info, outfit_category_and_index=outfit_category_and_index)
        outfit_identifier = frozenset(
            dict(zip(list(outfit_data.body_types),
                     list(outfit_data.part_ids))).items())
        if body_type is None or body_type == BodyType.NONE:
            body_type = CommonCASUtils.get_body_type_of_cas_part(cas_part_id)
        log.format_with_message('Using body_type', body_type=body_type)
        for outfit in saved_outfits.outfits:
            log.format_with_message('Attempting to update outfit.',
                                    outfit=outfit)
            # noinspection PyUnresolvedReferences
            _outfit_identifier = frozenset(
                dict(
                    zip(list(outfit.body_types_list.body_types),
                        list(outfit.parts.ids))).items())
            if int(outfit.category) != int(
                    outfit_category_and_index[0]
            ) or outfit.outfit_id != outfit_data.outfit_id or _outfit_identifier != outfit_identifier:
                log.format_with_message(
                    'Outfit is not the outfit we want to update, skipping.',
                    outfit_id=outfit.outfit_id,
                    outfit_category=outfit.category)
                continue
            log.debug('Updating outfit.')
            # noinspection PyUnresolvedReferences
            previous_cas_parts_list = list(outfit.parts.ids)
            if cas_part_id not in previous_cas_parts_list:
                log.format_with_message('Adding CAS part id.',
                                        cas_part_id=cas_part_id)
                previous_cas_parts_list.append(cas_part_id)
            outfit.parts = S4Common_pb2.IdList()
            # noinspection PyUnresolvedReferences
            outfit.parts.ids.extend(previous_cas_parts_list)
            # noinspection PyUnresolvedReferences
            previous_body_types_list = list(outfit.body_types_list.body_types)
            if body_type not in previous_body_types_list:
                log.format_with_message('Adding BodyType.',
                                        body_type=body_type)
                previous_body_types_list.append(body_type)
            outfit.body_types_list = Outfits_pb2.BodyTypesList()
            # noinspection PyUnresolvedReferences
            outfit.body_types_list.body_types.extend(previous_body_types_list)
            log.debug('Done updating outfit.')
        log.debug('Done updating outfits.')
        sim_info._base.outfits = saved_outfits.SerializeToString()
        sim_info._base.outfit_type_and_index = outfit_category_and_index
        log.debug('Resending outfits.')
        CommonOutfitUtils.resend_outfits(sim_info)
        log.debug('Done adding CAS part to Sim.')
        return True