def hard_reset(game_object: GameObject, reset_reason: ResetReason = ResetReason.RESET_EXPECTED, source: Any = None, cause: Any = 'S4CL Hard Reset') -> bool: """hard_reset(game_object, reset_reason=ResetReason.RESET_EXPECTED, source=None, cause=None) Perform a hard reset on an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param reset_reason: The reason for the reset. Default is ResetReason.RESET_EXPECTED. :type reset_reason: ResetReason, optional :param source: The source of the reset. Default is the GameObject. :type source: Any, optional :param cause: The cause of the reset. Default is 'S4CL Hard Reset'. :type cause: Any, optional :return: True, if the reset was successful. False, if not. :rtype: bool """ if game_object is None: return True # noinspection PyBroadException try: game_object.reset(reset_reason, source=source or game_object, cause=cause) return True except: return False
def schedule_object_for_destroy(game_object: GameObject, source: str = None, cause: str = None, on_destroyed: Callable[[], None] = None, **kwargs) -> bool: """schedule_object_for_destroy(game_object, source=None, cause=None, on_destroyed=None, **kwargs) Schedule an Object to be destroyed. :param game_object: An instance of an Object. :type game_object: GameObject :param source: The source of the destruction. Default is None. :type source: str, optional :param cause: The cause of the destruction. Default is None. :type cause: str, optional :param on_destroyed: A callback that occurs after the Object is destroyed. Default is None. :type on_destroyed: Callable[[], None], optional :return: True, if the Object was successfully scheduled for destruction. False, if not. :rtype: bool """ if game_object is None: return False game_object.schedule_destroy_asap(post_delete_func=on_destroyed, source=source, cause=cause, **kwargs) return True
def soft_reset(game_object: GameObject, reset_reason: ResetReason = ResetReason.RESET_EXPECTED, hard_reset_on_exception: bool = False, source: Any = None, cause: Any = 'S4CL Soft Reset') -> bool: """soft_reset(game_object, reset_reason=ResetReason.RESET_EXPECTED, hard_reset_on_exception=False, source=None, cause=None) Perform a soft reset on an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param reset_reason: The reason for the reset. Default is ResetReason.RESET_EXPECTED. :type reset_reason: ResetReason, optional :param hard_reset_on_exception: If set to True, a hard reset of the Object will be attempted upon an error occurring. If set to False, nothing will occur if the reset failed. Default is False. :type hard_reset_on_exception: bool, optional :param source: The source of the reset. Default is the GameObject. :type source: Any, optional :param cause: The cause of the reset. Default is 'S4CL Soft Reset'. :type cause: Any, optional :return: True, if the reset was successful. False, if not. :rtype: bool """ if game_object is None: return True # noinspection PyBroadException try: if game_object.parent is not None and game_object.parent.is_sim and not game_object.parent.posture_state.is_carrying( game_object): CarryingObject.snap_to_good_location_on_floor( game_object, starting_transform=game_object.parent.transform, starting_routing_surface=game_object.parent.routing_surface ) location = game_object.location game_object.on_reset_send_op(reset_reason) game_object.location = location game_object.resend_location() if game_object.routing_component is not None: game_object.routing_component.on_reset_internal_state( reset_reason) if game_object.idle_component is not None: game_object.idle_component._refresh_active_idle() if game_object.linked_object_component is not None: game_object.linked_object_component._relink(update_others=True) return True except: if hard_reset_on_exception: return CommonObjectSpawnUtils.hard_reset( game_object, reset_reason=reset_reason, source=source, cause=cause) return False
def update_gap(self): self.gap_y = Pipe.find_gap_y(self) self.upper_pipe = GameObject( 0, 0, self.pipe_width, self.gap_y, ) self.lower_pipe = GameObject( 0, self.upper_pipe.height + self.gap_height, self.pipe_width, self.pipe_height - (self.gap_height + self.upper_pipe.height), )
def set_owning_household_id(game_object: GameObject, household_id: int) -> bool: """set_owning_household_id(game_object, household_id) Set the Household that owns the Object. :param game_object: An instance of an Object. :type game_object: GameObject :param household_id: The decimal identifier of a Household. :type household_id: int :return: True, if the Household was successfully set as the owner. False, if not. :rtype: bool """ if game_object is None or household_id == -1: return False game_object.set_household_owner_id(household_id) return True
def move_object_to_inventory(sim_info: SimInfo, game_object: GameObject) -> bool: """move_object_to_inventory(sim_info, game_object) Move an Object to the inventory of a Sim. :param sim_info: An instance of a Sim. :type sim_info: SimInfo :param game_object: An instance of an Object. :type game_object: GameObject :return: True, if the object was successfully moved to the inventory of the specified Sim. False, if not. :rtype: bool """ inventory = CommonSimInventoryUtils._get_inventory(sim_info) if inventory is None: return False game_object.update_ownership(sim_info, make_sim_owner=True) return inventory.player_try_add_object(game_object)
def destroy_object(game_object: GameObject, source: str = None, cause: str = None) -> bool: """destroy_object(game_object, source=None, cause=None) Destroy an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param source: The source of the destruction. :type source: str, optional :param cause: The cause of the destruction. :type cause: str, optional :return: True, if the Object was successfully destroyed. False, if not. :rtype: bool """ if game_object is None: return False game_object.destroy(source=source, cause=cause) return True
def add_game_tags(game_object: GameObject, tags: Tuple[int], persist: bool = False) -> bool: """add_game_tags(game_object, tags, persist=False) Add tags to an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param tags: A collection of Game Tags to add. :type tags: Tuple[int] :param persist: If True, the Tags will persist to all instances of the Object. If False, the Tags will persist only to the specified Object. Default is False. :type persist: bool, optional :return: True, if the Tags were successfully added. False, if not. :rtype: bool """ if game_object is None: return False game_object.append_tags(set(tags), persist=persist) return True
def get_owning_household_id(game_object: GameObject) -> int: """get_owning_household_id(game_object) Retrieve the decimal identifier of the Household that owns the Object. :param game_object: An instance of an Object. :type game_object: GameObject :return: The decimal identifier of the Household that owns the object. :rtype: int """ if game_object is None: return -1 return game_object.get_household_owner_id()
def fade_out(game_object: GameObject, fade_duration: float = 1.0, immediate: bool = False, additional_channels: Iterator[Tuple[int, int, int]] = None): """fade_out(game_object, fade_duration=1.0, immediate=False, additional_channels=None) Change the opacity of an Object from visible to invisible. :param game_object: An instance of an Object. :type game_object: GameObject :param fade_duration: The number of milliseconds the fade effect should take to complete. Default is 1.0. :type fade_duration: float, optional :param immediate: If set to True, fade out will occur immediately. Default is False. :type immediate: bool, optional :param additional_channels: A collection of additional channels. The order of the inner tuple is Manager Id, Object Id, and Mask. Default is None. :type additional_channels: Iterator[Tuple[int, int, int]], optional """ if game_object is None: return game_object.fade_out(fade_duration=fade_duration, immediate=immediate, additional_channels=additional_channels)
def get_game_tags(game_object: GameObject) -> Set[int]: """get_game_tags(game_object) Retrieve the tags of an Object. :param game_object: An instance of an Object. :type game_object: GameObject :return: A collection of tags the Object has. :rtype: Set[int] """ if game_object is None: return set() return game_object.get_tags()
def __init__(self, x, special_effect=None): self.lower_pipeImg = pygame.image.load(c.pipe_image_filename) self.upper_pipeImg = pygame.transform.rotate(self.lower_pipeImg, 180) self.pipe_height = c.ground_level self.gap_height = round(c.pipe_gap * self.pipe_height) self.gap_y = Pipe.find_gap_y(self) self.pipe_width = self.lower_pipeImg.get_width() self.upper_pipe = GameObject( x, 0, self.pipe_width, self.gap_y, ) self.lower_pipe = GameObject( x, self.upper_pipe.height + self.gap_height, self.pipe_width, self.pipe_height - (self.gap_height + self.upper_pipe.height), ) self.special_effect = special_effect self.copied = False self.copied_x = 0 self.pipe_copy = None
def has_game_tags(game_object: GameObject, tags: Tuple[int]) -> bool: """has_game_tags(game_object, tags) Determine if an Object has any of the specified tags. :param game_object: An instance of an Object. :type game_object: GameObject :param tags: A collection of tags to locate. :type tags: Tuple[int] :return: True, if the Object has any of the specified tags. False, if not. :rtype: bool """ if game_object is None: return False return game_object.has_any_tag(tags)
def set_opacity(game_object: GameObject, opacity: int) -> bool: """set_opacity(game_object, opacity) Set the opacity of an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param opacity: Determines how opaque the Object will be. :type opacity: int :return: True, if successful. False, if not. :rtype: bool """ if game_object is None or opacity is None: return False game_object.opacity = opacity return True
def set_persistence_group(game_object: GameObject, persistence_group: PersistenceGroups) -> bool: """set_persistence_group(game_object, persistence_group) Set the persistence group of an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param persistence_group: The PersistenceGroup of the Object. :type persistence_group: PersistenceGroups :return: True, if successful. False, if not. :rtype: bool """ if game_object is None or persistence_group is None: return False game_object.persistence_group = persistence_group return True
def set_location(game_object: GameObject, location: Vector3) -> bool: """set_location(game_object, location) Set the location of an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param location: The location to put the Object. :type location: Vector3 :return: True, if successful. False, if not. :rtype: bool """ if game_object is None or location is None: return False game_object.location = location return True
def get_sims_using_object(game_object: GameObject) -> Tuple[SimInfo]: """get_sims_using_object(game_object) Retrieve a collection of Sims using the object. :param game_object: An instance of an object. :type game_object: GameObject :return: A collection of Sims using the object. :rtype: Tuple[SimInfo] """ from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils if game_object is None: return tuple() sim_info_user_list: List[SimInfo] = [] for sim in game_object.get_users(sims_only=True): sim_info_user_list.append(CommonSimUtils.get_sim_info(sim)) return tuple(sim_info_user_list)
def is_in_use_by(game_object: GameObject, sim_info: SimInfo) -> bool: """is_in_use_by(game_object, sim_info) Determine if an Object is in use by the specified Sim. :param game_object: An instance of an object. :type game_object: GameObject :param sim_info: An instance of a Sim. :type sim_info: SimInfo :return: True, if the object is in use by the specified Sim. False, if not. :rtype: bool """ if game_object is None: return False from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils sim = CommonSimUtils.get_sim_instance(sim_info) if sim is None: return False return game_object.in_use_by(sim)
def get_bone_position(game_object: GameObject, bone_name: str) -> Union[CommonVector3, None]: """get_bone_position(game_object, bone_name) Retrieve the position of a joint bone on an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param bone_name: The name of the bone to retrieve the position of. :type bone_name: str :return: The position of the Object or None if the Object does not have the specified bone. :rtype: Union[CommonVector3, None] """ # noinspection PyBroadException try: return CommonVector3.from_vector3( game_object.get_joint_transform_for_joint( bone_name).translation) except: return None
def __init__(self, x, y, special_effect=None): self.img = pygame.image.load(c.bar_image_filename) GameObject.__init__(self, x, y, self.img.get_width(), self.img.get_height()) self.special_effect = special_effect
def _is_visible(_game_object: GameObject) -> bool: return not _game_object.is_hidden()
def __init__(self, x, y, w, h, color, special_effect=None): GameObject.__init__(self, x, y, w, h) self.color = color self.special_effect = special_effect self.moving_up = False