Services

General

Common Service

class CommonService

Bases: object

An inheritable class that turns a class into a singleton, create an instance by invoking get().

Example usage:
class ExampleService(CommonService):
    @property
    def first_value(self) -> str:
        return 'yes'

# ExampleService.get() returns an instance of ExampleService.
# Calling ExampleService.get() again, will return the same instance.
ExampleService.get().first_value
classmethod get()

Retrieve an instance of the service

Returns:An instance of the service
Return type:The type of the inheriting class

Sim

Sim Outfit IO

class CommonSimOutfitIO(sim_info, outfit_category_and_index=None, override_outfit_parts=None)

Bases: sims4communitylib.logging.has_log.HasLog

Make changes to an outfit of a Sim.

Parameters:
  • sim_info (SimInfo) – An instance of a Sim.
  • outfit_category_and_index (Tuple[OutfitCategory, int], optional) – The OutfitCategory and Index of the Outfit being written to or read from. Default is the current outfit of the Sim.
  • initial_outfit_parts (Dict[BodyType, int], optional) – A library of body types and cas parts to use in place of the normal parts of their outfit. If set to None, OutfitParts will be loaded from the specified OutfitCategory and Index. Default is None.
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.

Parameters:
  • resend_outfits_after_apply (bool, optional) – If set to True, the outfits of the Sim will be re-sent after changes have been applied. Default is True.
  • change_sim_to_outfit_after_apply (bool, optional) – If set to True, the Sim will change to the outfit after the outfit is updated. Default is True.
  • apply_to_all_outfits_in_same_category (bool, optional) – 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.
  • apply_to_outfit_category_and_index (Tuple[OutfitCategory, int], optional) – 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.
Returns:

True, if changes were applied successfully. False, if not.

Return type:

bool

attach_cas_part(cas_part_id, body_type=BodyType.NONE)

Attach a CAS Part to the specified body type.

..note:: This will override the CAS Part located at the body type, if there is one.

Parameters:
  • cas_part_id (int) – The decimal identifier of a CAS Part.
  • body_type (Union[BodyType, int], optional) – The BodyType the CAS Part will be attached to. Default is the BodyType of the CAS Part
Returns:

True, if the CAS Part was attached successfully. False, if not.

Return type:

bool

body_types

The body types attached to the outfit.

Returns:A collection of body types attached to the outfit.
Return type:Tuple[Union[BodyType, int]]
cas_part_ids

The decimal identifiers of CAS Parts attached to the outfit.

Returns:A collection of decimal identifiers of CAS Parts attached to the outfit.
Return type:Tuple[int]
detach_body_type(body_type)

Detach the BodyType including the CAS Part attached to it from the outfit.

Parameters:body_type (Union[BodyType, int]) – The BodyType being detached.
Returns:True, if the Body Type was detached from the outfit successfully. False, if not.
Return type:bool
detach_cas_part(cas_part_id)

Detach a CAS Part from all body types of the Outfit.

Parameters:cas_part_id (int) – The decimal identifier of a CAS Part.
Returns:True, if the CAS Part was erased from all body types successfully. False, if not.
Return type:bool
get_cas_part_at_body_type(body_type)

Retrieve the CAS Part located at the specified body type.

Parameters:body_type (Union[BodyType, int]) – The BodyType to look at.
Returns:The decimal identifier of the CAS Part located at the specified body part or -1 if the Outfit does not have the body type or the body type is empty.
Return type:int
is_any_body_type_attached(body_types)

Determine if any of the specified BodyTypes are attached to the outfit.

Parameters:body_types (Union[BodyType, int]) – The BodyType to look for.
Returns:True, if any of the specified BodyTypes are attached to the outfit. False, if not.
Return type:bool
is_any_cas_part_attached(cas_part_ids)

Determine if any of the specified CAS Parts are attached to the outfit.

Parameters:cas_part_ids (Tuple[int]) – A collection of decimal identifiers of CAS Parts.
Returns:True, if any of the specified CAS Parts are attached to the outfit. False, if not.
Return type:bool
is_body_type_attached(body_type)

Determine if the specified BodyType is attached to the outfit.

Parameters:body_type (Union[BodyType, int]) – The BodyType to look for.
Returns:True, if the specified BodyType is attached to the outfit. False, if not.
Return type:bool
is_cas_part_attached(cas_part_id)

Determine if the specified CAS Part is attached to the outfit.

Parameters:cas_part_id (int) – The decimal identifier of a CAS Part.
Returns:True, if the specified CAS Part is attached to the outfit. False, if not.
Return type:bool
log_identifier

A string identifier for the log used by instances of the class.

Note

This is the text that will appear when logging messages.

Returns:The identifier of the log
Return type:str
mod_identity

The identity of the mod that owns this property

Warning

Override this property with the CommonModIdentity of your mod.

This is a MUST override to allow for proper Exception Handling and Logging!

Returns:An instance of CommonModIdentity
Return type:CommonModIdentity
Raises:NotImplementedError – Thrown when the property is not implemented.
outfit_category_and_index

The OutfitCategory and Index of the Outfit being written to.

Returns:The OutfitCategory and Index of the Outfit being written to.
Return type:Tuple[OutfitCategory, int]
sim_info

The Sim to apply Outfit changes to.

Returns:An instance of a Sim.
Return type:SimInfo

Resource

Posture Constraints

class CommonPostureConstraintService

Bases: sims4communitylib.services.common_service.CommonService

Utilities for providing and manipulating posture constraints of Sims.

static combine_constraints(constraints, fallback_constraints=(), debug_name='Combined')

Attempt to combine similar constraints into a constraint set.

Parameters:
  • constraints (Iterator[Constraint]) – A collection of Constraints.
  • fallback_constraints (Iterator[Constraint], optional) – A collection of Constraints to choose from as a fallback when the primary constraints fail to combine. Default is an empty collection.
  • debug_name (str, optional) – The name of the constraint set being created. Default is ‘Combined’.
Returns:

A constraint set containing the specified constraints, a Constraint chosen from one of the specified fallback constraints, or Nowhere when everything else fails.

Return type:

Union[_ConstraintSet, Constraint, Nowhere]

stand

A posture constraint for a Sim to stand at a target.

Returns:An instance of a Constraint.
Return type:Constraint
stand_or_swim_at_none

A posture constraint for a Sim to stand at a target or to swim at no target.

Returns:An instance of a Constraint.
Return type:Constraint
swim_at_none

A posture constraint for a Sim to swim at no target.

Returns:An instance of a Constraint.
Return type:Constraint