Ejemplo n.º 1
0
        def _inner_test_class(cls):
            name_of_class = cls.__name__
            if CommonLogRegistry is not None:
                cls.test_log_log = CommonLogRegistry.get().register_log(
                    mod_name, name_of_class)
                cls.test_log_log.enable()
                cls.test_log = lambda val: cls.test_log_log.debug(val)
            else:
                cls.test_log = lambda val: print(val)
            for method_name in dir(cls):
                method = getattr(cls, method_name)
                if not hasattr(method, 'is_test'):
                    continue

                def _test_function(class_name, test_name, test_method, *_,
                                   **__):
                    @wraps(test_method)
                    def _wrapper(*args, **kwargs):
                        arguments = (_ + args)
                        new_test_name = '{} (Arguments: {}, Keyword Arguments: {})'.format(
                            test_name, arguments, (kwargs, __))
                        # noinspection PyBroadException
                        try:
                            test_method(*(_ + args), **kwargs, **__)
                            cls.test_log(
                                CommonTestService._format_test_result(
                                    CommonTestResultType.SUCCESS,
                                    new_test_name))
                        except AssertionError:
                            cls.test_log(
                                CommonTestService._format_test_result(
                                    CommonTestResultType.FAILED,
                                    new_test_name,
                                    stacktrace=format_exc()))
                            return CommonTestResultType.FAILED
                        except Exception:
                            cls.test_log(
                                CommonTestService._format_test_result(
                                    CommonTestResultType.FAILED,
                                    new_test_name,
                                    stacktrace=format_exc()))
                            return CommonTestResultType.FAILED
                        return CommonTestResultType.SUCCESS

                    CommonTestService.get().add_test(test_name,
                                                     _wrapper,
                                                     class_name=class_name)

                if hasattr(
                        method,
                        'test_parameters') and len(method.test_parameters) > 0:
                    idx = 1
                    for test_args, test_kwargs in method.test_parameters:
                        _test_function(name_of_class,
                                       '{} {}'.format(method_name, str(idx)),
                                       method, *test_args, **test_kwargs)
                        idx += 1
                else:
                    _test_function(name_of_class, method_name, method)
            return cls
Ejemplo n.º 2
0
 def log(self) -> CommonLog:
     """ The Log for this class. """
     if self._log is None:
         mod_name = 'Missing Mod Name'
         if self.mod_identity is not None:
             mod_name = self.mod_identity.name
         self._log = CommonLogRegistry.get().register_log(
             mod_name, self.log_identifier)
     return self._log
Ejemplo n.º 3
0
    def log(self) -> CommonLog:
        """The Log for this class.

        .. note:: It uses the `mod_identity` and `log_identifier` when logging.
        """
        if self._log is None:
            mod_name = 'Missing Mod Name'
            if self.mod_identity is not None:
                mod_name = self.mod_identity.name
            self._log = CommonLogRegistry.get().register_log(mod_name, self.log_identifier)
        return self._log
Ejemplo n.º 4
0
    def log(self) -> CommonLog:
        """The log for instances of the class.

        .. note:: It uses the `mod_identity` and `log_identifier` when logging.

        :return: An instance of CommonLog
        :rtype: CommonLog
        """
        if self._log is None:
            mod_name = CommonModIdentity._get_mod_name(self.mod_identity)
            self._log = CommonLogRegistry.get().register_log(
                mod_name, self.log_identifier)
        return self._log
    def get_log(cls) -> CommonLog:
        """get_log()

        The Log for this class.

        .. note:: It uses the `mod_identity` and `log_identifier` when logging.
        """
        if not hasattr(cls, '_log') or getattr(cls, '_log', None) is None:
            mod_name = 'Missing Mod Name'
            if cls.get_mod_identity() is not None:
                mod_name = cls.get_mod_identity().name
            setattr(cls, '_log', CommonLogRegistry.get().register_log(mod_name, cls.get_log_identifier()))
        return getattr(cls, '_log', None)
    def get_log(cls) -> CommonLog:
        """get_log()

        Retrieve a log for the class.

        .. note:: This function uses the :func:`~get_mod_identity` and :func:`~get_log_identifier` functions when logging.

        :return: An instance of CommonLog
        :rtype: CommonLog
        """
        if not hasattr(cls, '_log') or getattr(cls, '_log', None) is None:
            mod_name = 'Missing Mod Name'
            if cls.get_mod_identity() is not None:
                mod_name = cls.get_mod_identity().name
            setattr(
                cls, '_log',
                CommonLogRegistry.get().register_log(mod_name,
                                                     cls.get_log_identifier()))
        return getattr(cls, '_log', None)
"""
The Sims 4 Community Library is licensed under the Creative Commons Attribution 4.0 International public license (CC BY 4.0).
https://creativecommons.org/licenses/by/4.0/
https://creativecommons.org/licenses/by/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Any, Callable, Iterator

from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.mod_support.mod_identity import CommonModIdentity
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.common_log_registry import CommonLog, CommonLogRegistry

func_utils_log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name, 's4clib_common_function_utils')


class CommonFunctionUtils:
    """Utilities for manipulating functions.

    """

    @staticmethod
    def noop(*_, **__) -> None:
        """noop(*_, **__)

        An empty function that does nothing. Useful when you need something to do nothing.

        .. note:: Use this when you want something to do nothing.

        """
"""
The Sims 4 Community Library is licensed under the Creative Commons Attribution 4.0 International public license (CC BY 4.0).
https://creativecommons.org/licenses/by/4.0/
https://creativecommons.org/licenses/by/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Union

from sims.sim_info import SimInfo
from sims.sim_info_types import Species
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.common_log_registry import CommonLogRegistry

log = CommonLogRegistry.get().register_log(ModInfo.get_identity(),
                                           'common_species_utils')


class CommonSpeciesUtils:
    """Utilities for manipulating and checking the Species of Sims.

    """
    @staticmethod
    def get_species(sim_info: SimInfo) -> Union[Species, None]:
        """get_species(sim_info)

        Retrieve the Species of a sim.

        :param sim_info: The Sim to get the Species of.
        :type sim_info: SimInfo
        :return: The Species of the Sim or None if the Sim does not have a Species.
Copyright (c) COLONOLNUTTY
"""
import sims4.commands
from typing import Any, Union, Iterator
from distributor.shared_messages import IconInfoData
from protocolbuffers.Localization_pb2 import LocalizedString
from sims4communitylib.enums.strings_enum import CommonStringId
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.localization.common_localized_string_colors import CommonLocalizedStringColor
from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizationUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry
from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
from ui.ui_dialog_notification import UiDialogNotification
log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name,
                                           'common_basic_notification')


class CommonBasicNotification:
    """CommonBasicNotification(\
        title_identifier,\
        description_identifier,\
        title_tokens=(),\
        description_tokens=(),\
        urgency=UiDialogNotification.UiDialogNotificationUrgency.DEFAULT,\
        information_level=UiDialogNotification.UiDialogNotificationLevel.SIM,\
        expand_behavior=UiDialogNotification.UiDialogNotificationExpandBehavior.USER_SETTING\
    )

    A basic notification.
Ejemplo n.º 10
0
This file is part of the Sims 4 Community Library, licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International public license (CC BY-NC-ND 4.0).
https://creativecommons.org/licenses/by-nc-nd/4.0/
https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Callable, Any, Dict, List
from functools import wraps
from traceback import format_exc
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.services.common_service import CommonService
try:
    from sims4communitylib.utils.common_log_registry import CommonLogRegistry

    community_test_log_log = CommonLogRegistry.get().register_log(
        ModInfo.MOD_NAME, 'community_test_log')
    community_test_log_log.enable()

    def community_test_log(val: str):
        community_test_log_log.debug(val)
except ModuleNotFoundError:
    CommonLogRegistry = None

    def community_test_log(val: str):
        pass


class CommonTestResultType:
    """ Use to identify the results of running a test. """
    FAILED = 'FAILED'
    SUCCESS = 'SUCCESS'
from pprint import pformat
from protocolbuffers.Localization_pb2 import LocalizedString
from sims4communitylib.dialogs.common_choice_outcome import CommonChoiceOutcome
from sims4communitylib.dialogs.utils.common_dialog_utils import CommonDialogUtils
from sims4communitylib.enums.strings_enum import CommonStringId
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.common_function_utils import CommonFunctionUtils
from sims4communitylib.utils.common_icon_utils import CommonIconUtils
from sims4communitylib.utils.localization.common_localized_string_colors import CommonLocalizedStringColor
from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizationUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry
from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
from ui.ui_dialog_picker import UiObjectPicker, ObjectPickerRow

log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name,
                                           'choose_object_dialog')


class CommonChooseObjectDialog:
    """
        Create a dialog that asks the player to make a choice.
    """
    def __init__(self,
                 title_identifier: Union[int, LocalizedString],
                 description_identifier: Union[int, LocalizedString],
                 choices: Tuple[ObjectPickerRow],
                 title_tokens: Tuple[Any] = (),
                 description_tokens: Tuple[Any] = (),
                 per_page: int = 25):
        """
            Create a dialog for displaying a list of objects.
This file is part of the Outfit Customization mod licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International public license (CC BY-NC-ND 4.0).
https://creativecommons.org/licenses/by-nc-nd/4.0/
https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Tuple, Union

from cnoutfitcustomization.modinfo import ModInfo
from cnoutfitcustomization.outfit_parts.outfit_part import OCOutfitPart
from sims.outfits.outfit_enums import BodyType
from sims.sim_info import SimInfo
from sims4communitylib.utils.cas.common_cas_utils import CommonCASUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry

log = CommonLogRegistry.get().register_log(ModInfo.get_identity(),
                                           'oc_outfit_part_utils')


class OCOutfitPartUtils:
    """ Utilities for managing outfit parts of sims. """
    @staticmethod
    def remove_outfit_parts(sim_info: SimInfo,
                            outfit_parts: Tuple[OCOutfitPart]):
        """ Remove the specified outfit parts from a sim. """
        log.format_with_message('Removing outfit parts',
                                outfit_parts=outfit_parts)
        for outfit_part in outfit_parts:
            if OCOutfitPartUtils.remove_cas_part(sim_info,
                                                 outfit_part.part_id,
                                                 body_type=None):
                log.format_with_message('Removed outfit part.',
The Sims 4 Community Library is licensed under the Creative Commons Attribution 4.0 International public license (CC BY 4.0).
https://creativecommons.org/licenses/by/4.0/
https://creativecommons.org/licenses/by/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Callable, Any, Dict, List
from functools import wraps
from traceback import format_exc
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.services.common_service import CommonService
try:
    from sims4communitylib.utils.common_log_registry import CommonLogRegistry

    community_test_log_log = CommonLogRegistry.get().register_log(
        ModInfo.get_identity().name, 'community_test_log')
    community_test_log_log.enable()

    def _community_test_log(val: str):
        community_test_log_log.debug(val)
except ModuleNotFoundError:
    CommonLogRegistry = None

    def _community_test_log(_: str):
        pass


class CommonTestResultType:
    """Use to identify the results of running a test.

    """
Ejemplo n.º 14
0
"""
The Sims 4 Community Library is licensed under the Creative Commons Attribution 4.0 International public license (CC BY 4.0).
https://creativecommons.org/licenses/by/4.0/
https://creativecommons.org/licenses/by/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from sims.sim_info import SimInfo
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.common_log_registry import CommonLogRegistry
from sims4communitylib.utils.sims.common_age_utils import CommonAgeUtils
from sims4communitylib.utils.sims.common_species_utils import CommonSpeciesUtils

log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name,
                                           's4cl_age_species_utils')


class CommonAgeSpeciesUtils:
    """Utilities for checking the age and species of Sims.

    """
    @staticmethod
    def is_baby_human(sim_info: SimInfo) -> bool:
        """is_baby_human(sim_info)

        Determine if a sim is a Baby Human.

        :param sim_info: The Sim to check.
        :type sim_info: SimInfo
        :return: True, if the Sim is a Baby Human. False, if the Sim is not.
        :rtype: bool
from typing import Tuple
from cnoutfitcustomization.modinfo import ModInfo
from cnoutfitcustomization.outfit_parts.outfit_part import OCOutfitPartAvailableFor
from cnoutfitcustomization.outfit_parts.outfit_parts_loader import OCOutfitPartsLoader
from protocolbuffers import Dialog_pb2
from sims.outfits.outfit_enums import BodyType
from sims.sim_info_types import Gender, Age
from sims4.resources import Types
from sims4communitylib.enums.common_species import CommonSpecies
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.utils.cas.common_cas_utils import CommonCASUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry
from sims4.commands import Command, CommandType, CheatOutput
from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizationUtils

log = CommonLogRegistry.get().register_log(ModInfo.get_identity(),
                                           'oc_load_vanilla_cas_parts')


@Command('oc.load_vanilla_cas_parts', command_type=CommandType.Live)
def _oc_load_vanilla_cas_parts(_connection: int = None):
    output = CheatOutput(_connection)
    try:
        output('Loading')
        # noinspection PyUnresolvedReferences
        cas_part_resource_keys = list(sims4.resources.list(type=Types.CASPART))
        for key in cas_part_resource_keys:

            cas_part_id = key.instance
            body_type = CommonCASUtils.get_body_type_of_cas_part(cas_part_id)
            if body_type not in BodyType:
                continue
Ejemplo n.º 16
0
"""
from pprint import pformat
from typing import Union, Iterator

import services
from sims.household import Household
from sims.sim_info import SimInfo
from sims.sim_spawner import SimSpawner
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.sims.common_sim_name_utils import CommonSimNameUtils
from sims4communitylib.utils.sims.common_sim_state_utils import CommonSimStateUtils
from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry

log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name, 's4cl_household_utils')


class CommonHouseholdUtils:
    """Utilities for manipulating households.

    """
    @staticmethod
    def get_active_household() -> Union[Household, None]:
        """get_active_household()

        Retrieve the Household of the Active Sim.

        :return: The Household of the Active Sim or None if no household is found.
        :rtype: Union[Household, None]
        """
"""
The Sims 4 Community Library is licensed under the Creative Commons Attribution 4.0 International public license (CC BY 4.0).
https://creativecommons.org/licenses/by/4.0/
https://creativecommons.org/licenses/by/4.0/legalcode

Copyright (c) COLONOLNUTTY
"""
from typing import Tuple, Union
from sims.outfits.outfit_enums import OutfitCategory, BodyType
from sims.sim_info import SimInfo
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.services.sim.cas.common_sim_outfit_io import CommonSimOutfitIO
from sims4communitylib.utils.common_log_registry import CommonLogRegistry

log = CommonLogRegistry.get().register_log(ModInfo.get_identity(), 's4cl_common_cas_utils')


class CommonCASUtils:
    """Utilities for manipulating the CAS parts of Sims.

    """

    @staticmethod
    def is_cas_part_loaded(cas_part_id: int) -> bool:
        """is_cas_part_loaded(cas_part_id)

        Determine if a CAS part is loaded within the game.

        .. note:: If the CAS part is part of a package that is not installed, it will be considered as not loaded.

        .. note:: A CAS part is considered as "loaded" when the BodyType it has can be found within the sims.outfits.outfit_enums.BodyType enum.
Ejemplo n.º 18
0
Copyright (c) COLONOLNUTTY
"""
import sims4.commands
from typing import Tuple, Any, Callable, Union

from protocolbuffers.Localization_pb2 import LocalizedString
from sims4communitylib.enums.strings_enum import CommonStringId
from sims4communitylib.exceptions.common_exceptions_handler import CommonExceptionHandler
from sims4communitylib.modinfo import ModInfo
from sims4communitylib.utils.common_function_utils import CommonFunctionUtils
from sims4communitylib.utils.localization.common_localized_string_colors import CommonLocalizedStringColor
from sims4communitylib.utils.localization.common_localization_utils import CommonLocalizationUtils
from sims4communitylib.utils.common_log_registry import CommonLogRegistry
from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
from ui.ui_dialog import UiDialogOkCancel
log = CommonLogRegistry.get().register_log(ModInfo.get_identity().name, 'ok_cancel_dialog')


class CommonOkCancelDialog:
    """
        Use to create a prompt dialog.
    """
    def __init__(self,
                 title_identifier: Union[int, LocalizedString],
                 description_identifier: Union[int, LocalizedString],
                 title_tokens: Tuple[Any]=(),
                 description_tokens: Tuple[Any]=(),
                 ok_text_identifier: Union[int, LocalizedString]=CommonStringId.OK,
                 ok_text_tokens: Tuple[Any]=(),
                 cancel_text_identifier: Union[int, LocalizedString]=CommonStringId.CANCEL,
                 cancel_text_tokens: Tuple[Any]=()):