示例#1
0
 def end_bulk_policy_update(self, suspend_reason):
     if self._cache_suspended_key is suspend_reason:
         msg = S4Common_pb2.BoolValue()
         distributor = Distributor.instance()
         msg.value = False
         distributor.add_event(Consts_pb2.MSG_SUSPEND_CACHE_UPDATES, msg, immediate=True)
         self._cache_suspended_key = None
    def apply(self, resend_outfits_after_apply: bool=True, change_sim_to_outfit_after_apply: bool=True, apply_to_all_outfits_in_same_category: bool=False, apply_to_outfit_category_and_index: Tuple[OutfitCategory, int]=None) -> bool:
        """apply(resend_outfits_after_apply=True, change_sim_to_outfit_after_apply=True, apply_to_all_outfits_in_same_category=False, apply_to_outfit_category_and_index=None)

        Apply all changes made to the Outfit.

        :param resend_outfits_after_apply: If set to True, the outfits of the Sim will be re-sent after changes have been applied. Default is True.
        :type resend_outfits_after_apply: bool, optional
        :param change_sim_to_outfit_after_apply: If set to True, the Sim will change to the outfit after the outfit is updated. Default is True.
        :type change_sim_to_outfit_after_apply: bool, optional
        :param apply_to_all_outfits_in_same_category: If set to True, changes will be applied to all Outfits in the same category. If set to False, changes will only be applied to the outfit provided at initialization. Default is False.
        :type apply_to_all_outfits_in_same_category: bool, optional
        :param apply_to_outfit_category_and_index: The OutfitCategory and Index to apply changes to. If set to None, it will be the OutfitCategory and Index provided at initialization. Default is None.
        :type apply_to_outfit_category_and_index: Tuple[OutfitCategory, int], optional
        :return: True, if changes were applied successfully. False, if not.
        :rtype: bool
        """
        sim_name = CommonSimNameUtils.get_full_name(self.sim_info)
        self.log.format_with_message(
            'Applying changes to outfit',
            sim=sim_name,
            resend_outfits=resend_outfits_after_apply,
            change_to_outfit=change_sim_to_outfit_after_apply,
            apply_to_all_outfits_in_same_category=apply_to_all_outfits_in_same_category,
            apply_to_outfit_category_and_index=apply_to_outfit_category_and_index
        )
        apply_to_outfit_category_and_index = apply_to_outfit_category_and_index or self.outfit_category_and_index
        saved_outfits = self.sim_info.save_outfits()
        for saved_outfit in saved_outfits.outfits:
            if int(saved_outfit.category) != int(apply_to_outfit_category_and_index[0]):
                continue

            if apply_to_all_outfits_in_same_category:
                pass
            else:
                # noinspection PyUnresolvedReferences
                sub_outfit_data = self._to_outfit_data(saved_outfit.body_types_list.body_types, saved_outfit.parts.ids)
                if int(saved_outfit.outfit_id) != int(self._outfit_data.outfit_id) or sub_outfit_data != self._original_outfit_data:
                    continue

            saved_outfit.parts = S4Common_pb2.IdList()
            # noinspection PyUnresolvedReferences
            saved_outfit.parts.ids.extend(self._outfit_part_ids)
            saved_outfit.body_types_list = Outfits_pb2.BodyTypesList()
            # noinspection PyUnresolvedReferences
            saved_outfit.body_types_list.body_types.extend(self._outfit_body_types)
            if not apply_to_all_outfits_in_same_category:
                break

        self.sim_info._base.outfits = saved_outfits.SerializeToString()
        if change_sim_to_outfit_after_apply:
            self.sim_info._base.outfit_type_and_index = apply_to_outfit_category_and_index
        else:
            self.sim_info._base.outfit_type_and_index = self._current_outfit_category_and_index
        self.log.format_with_message('Finished flushing outfit changes.', sim=sim_name)
        if resend_outfits_after_apply:
            return CommonOutfitUtils.resend_outfits(self.sim_info)
        return True
示例#3
0
 def apply(self, apply_to_outfit_category=None, skip_client_update=False):
     '''
     Apply outfit editor current state to sim outfit data.
     :param apply_to_outfit_category: OutfitCategory -> outfit category, if None the passed in init outfit is used
     :param skip_client_update: bool -> skip resending sim outfit data to the client
     '''
     outfits_msg = self.sim_info.save_outfits()
     for outfit in outfits_msg.outfits:
         if apply_to_outfit_category:
             can_apply = int(outfit.category) == int(apply_to_outfit_category)
         else:
             can_apply = int(outfit.category) == int(self.outfit_category_and_index[0]) and (outfit.outfit_id == self.outfit_data.outfit_id and self._get_outfit_identifier(outfit.body_types_list.body_types, outfit.parts.ids) == self.outfit_identifier)
         while can_apply:
             outfit.parts = S4Common_pb2.IdList()
             outfit.parts.ids.extend(self.outfit_part_ids)
             outfit.body_types_list = Outfits_pb2.BodyTypesList()
             outfit.body_types_list.body_types.extend(self.outfit_body_types)
             if not apply_to_outfit_category:
                 break
     self.sim_info._base.outfits = outfits_msg.SerializeToString()
     if skip_client_update is False:
         self.sim_info.resend_outfits()
    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