Runnable Classes

Runnable

class CommonRunnable(context)

Bases: HasClassLog, Generic[CommonRunnableContextType]

This class is used when you want to have something reoccurring again and again.

Parameters:

context (CommonRunnableContext) – A context containing information about the runnable as well as actions the runnable should perform.

property cancel_stop_reason

A reason for the runnable to be stopped for a cancel reasons.

property context

A context containing information about the runnable as well as actions the runnable should perform.

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

property invalid_stop_reason

A reason for the runnable to be stopped for invalid reasons.

property is_paused

The runnable is stopped.

property is_running

The runnable is running.

property is_starting

The runnable is starting.

property is_stopped

The runnable is stopped.

property is_stopping

The runnable is stopping.

property is_waiting_for_start

The runnable is waiting to start.

property milliseconds_per_update

The number of milliseconds between updates.

restart(restart_reason, *_, **__)

Restart the runnable.

Parameters:

restart_reason (Union[int, CommonInt, CommonIntFlags]) – The reason for the restart.

Returns:

True, if the runnable has been restarted successfully. False, if not.

Return type:

CommonExecutionResult

should_update(milliseconds_since_last_update)

Determine if the runnable should update.

Parameters:

milliseconds_since_last_update (int) – The number of milliseconds since the last update.

Returns:

True, if the update should continue. False, if not.

Return type:

CommonExecutionResult

start(*_, **__)

Start the runnable.

Returns:

True, if the runnable has successfully been started. False, if not.

Return type:

CommonExecutionResult

property start_after_wait_reason

A reason for the runnable to be stopped after waiting for it to start.

stop(stop_reason, *_, force_stop=False, **__)

Stop the runnable.

Parameters:
  • stop_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the runnable is being stopped for.

  • force_stop (bool, optional) – If True, the is_stopping state will not be checked and the runner will be forced to stop. Default is False.

Returns:

True, if the runnable has been stopped successfully. False, if not.

Return type:

CommonExecutionResult

property unknown_stop_reason

A reason for the runnable to be stopped for unknown reasons.

update(milliseconds_since_last_update, *_, **__)

Update the runnable.

Note

This function is invoked automatically by the runnable itself.

Parameters:

milliseconds_since_last_update (int) – The number of milliseconds since the last update.

Returns:

True, if the update is successful. False, if not.

Return type:

CommonExecutionResult

Runnable With Sims

class CommonRunnableWithSims(context)

Bases: CommonRunnable[CommonRunnableContextWithSimsType], Generic[CommonRunnableContextWithSimsType, CommonRunnableSimContextType]

This class is used when you want to have something reoccurring again and again. Specifically when it involves something reoccurring for Sims again and again.

Parameters:

context (CommonRunnableContextWithSims) – A context containing information about the runnable as well as actions the runnable should perform, including which Sims to perform the actions with.

add_sim_context(sim_context, add_reason, restart_after_add=True)

Add a Sim Context to the context.

Parameters:
  • sim_context (CommonRunnableSimContextType) – A Sim Context.

  • add_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the Sim Context is being added.

  • restart_after_add (bool, optional) – If True, the Runnable will be restarted after the Sim is added. If False, the Runnable will not be restarted after add. Default is True.

Returns:

True, if the context was added successfully. False, if not.

Return type:

CommonExecutionResult

property cancel_stop_reason

A reason for the runnable to be stopped for a cancel reasons.

property context

A context containing information about the runnable as well as actions the runnable should perform.

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

get_sim_context(sim_info)

Retrieve the Sim Context for a Sim.

Parameters:

sim_info (SimInfo) – An instance of a Sim.

Returns:

The Sim Context matching the Sim or None if no context matches.

Return type:

Union[CommonRunnableSimContext, None]

has_sim_context(sim_info)

Determine if a Sim Context exists for a Sim.

Parameters:

sim_info (SimInfo) – An instance of a Sim.

Returns:

True, if a Sim Context exists for the Sim. False, if not.

Return type:

bool

property invalid_stop_reason

A reason for the runnable to be stopped for invalid reasons.

remove_sim(sim_info, remove_reason, *_, restart_after_remove=False, **__)

Remove a Sim from the context.

Parameters:
  • sim_info (SimInfo) – An instance of a Sim.

  • remove_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the Sim is being removed.

  • restart_after_remove (bool, optional) – If True, the Runnable will be restarted after the Sim is removed. If False, the Runnable will not be restarted after remove. Default is True.

Returns:

True, if the sim was removed from the context successfully. False, if not.

Return type:

CommonExecutionResult

remove_sim_context(sim_context, remove_reason, *_, restart_after_remove=True, **__)

Remove a Sim Context from the context.

Parameters:
  • sim_context (CommonRunnableSimContextType) – A Sim Context.

  • remove_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context is being removed.

  • restart_after_remove (bool, optional) – If True, the Runnable will be restarted after the Sim is removed. If False, the Runnable will not be restarted after remove. Default is True.

Returns:

True, if the Sim Context was removed from the context successfully. False, if not.

Return type:

CommonExecutionResult

property sim_contexts

A collection of Sim Contexts within the context.

property sims_as_sim

Retrieves a collection of Sim Instances for the Sims.

property sims_as_sim_id

Retrieves a collection of decimal identifiers for the Sims.

property sims_as_sim_info

Retrieves a collection of Sim Info for the Sims.

property start_after_wait_reason

A reason for the runnable to be stopped after waiting for it to start.

property unknown_stop_reason

A reason for the runnable to be stopped for unknown reasons.

Runnable Context

class CommonRunnableContext

Bases: CommonSerializable, HasClassLog

A context used by a runnable.

clear_total_milliseconds()

clear_time_since_setup()

Clear the total time passed since the context was set up.

Return type:

None

clone(*_, **__)

Create a clone of the context.

Returns:

A cloned version of this context.

Return type:

CommonRunnableContext

classmethod deserialize(data)

Deserialize the object from a JSON Serializable form.

Returns:

The deserialized form of the object or None if it fails to deserialize.

Return type:

Union[CommonSerializableType, None]

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

initialize(*_, **__)

Initialize the context.

Returns:

True, if successful. False, if not.

Return type:

CommonExecutionResult

restart(restart_reason, *_, **__)

Restart the context.

Parameters:

restart_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context to be restarted.

Returns:

True, if successful. False, if not.

Return type:

CommonExecutionResult

serialize()

Serialize the object into a JSON Serializable form.

Returns:

A serializable representation of the object.

Return type:

Union[str, Dict[str, Any]]

setup(*_, **__)

Setup the context.

Returns:

True, if successful. False, if not.

Return type:

CommonExecutionResult

property should_run_on_game_time

Determine if the context should be run using game time or if it should be run using real time.

property should_track_total_time

Determine if the total time in milliseconds should be tracked. Default is False.

should_update(milliseconds_since_last_update, *_, **__)

Determine if the context should update.

Parameters:

milliseconds_since_last_update (int) – The number of milliseconds since the last update.

Returns:

True, if the context should update. False, if not.

Return type:

CommonExecutionResult

teardown(teardown_reason, *_, **__)

Teardown the context.

Parameters:

teardown_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context to be torn down.

Returns:

True, if successful. False, if not.

Return type:

CommonExecutionResult

property total_milliseconds

A counter for the total number of milliseconds the context has been running for.

update(milliseconds_since_last_update, *_, **__)

Update the context.

Parameters:

milliseconds_since_last_update (int) – The number of milliseconds since the last update.

Returns:

True, if successful. False, if not.

Return type:

CommonExecutionResult

Runnable Context With Sims

class CommonRunnableContextWithSims(sim_contexts)

Bases: CommonRunnableContext, Generic[CommonRunnableSimContextType]

A context used by a runnable.

add_sim_context(sim_context, *_, **__)

Add a Sim Context to the context.

Parameters:

sim_context (CommonRunnableSimContextType) – A Sim Context.

Returns:

True, if the context was added successfully. False, if not.

Return type:

CommonExecutionResult

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

get_sim_context(sim_info)

Retrieve the Sim Context for a Sim.

Parameters:

sim_info (SimInfo) – An instance of a Sim.

Returns:

The Sim Context matching the Sim or None if no context matches.

Return type:

Union[CommonRunnableSimContextType, None]

has_sim_context(sim_info)

Determine if a Sim Context exists for a Sim.

Parameters:

sim_info (SimInfo) – An instance of a Sim.

Returns:

True, if a Sim Context exists for the Sim. False, if not.

Return type:

bool

remove_sim(sim_info, remove_reason, *_, **__)

Remove a Sim from the context.

Parameters:
  • sim_info (SimInfo) – An instance of a Sim.

  • remove_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the Sim is being removed.

Returns:

True, if the sim was removed from the context successfully. False, if not.

Return type:

CommonExecutionResult

remove_sim_context(sim_context, remove_reason, *_, **__)

Remove a Sim Context from the context.

Parameters:
  • sim_context (CommonRunnableSimContextType) – A Sim Context.

  • remove_reason (Union[int, CommonInt, CommonIntFlags]) – The reason the context is being removed.

Returns:

True, if the Sim Context was removed from the context successfully. False, if not.

Return type:

CommonExecutionResult

classmethod sim_context_type()

The context type for Sim info.

Return type:

Type[TypeVar(CommonRunnableSimContextType, bound= CommonRunnableSimContext)]

property sim_contexts

A collection of Sim Contexts within the context.

property sims_as_sim

Retrieves a collection of Sim Instances for the Sims.

property sims_as_sim_id

Retrieves a collection of decimal identifiers for the Sims.

property sims_as_sim_info

Retrieves a collection of Sim Info for the Sims.

Runnable Object Context

class CommonRunnableObjectContext(game_object)

Bases: CommonRunnableContext

A context used by a runnable that contains information about an Object.

Parameters:

game_object (Union[GameObject, None]) – The game object the context is for.

property game_object

The Game Object this context is for.

property game_object_id

The decimal identifier of the Game Object this context is for.

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

Runnable Sim Context

class CommonRunnableSimContext(sim_info)

Bases: CommonRunnableContext

A context used by a runnable that contains information about a Sim.

Parameters:

sim_info (SimInfo) – The Sim the context is for.

classmethod get_log_identifier()

A string identifier for the log of the class.

Note

This is the text that will appear when logging messages.

Returns:

The identifier for the log

Return type:

str

classmethod get_mod_identity()

Retrieve the identity of the mod that owns the class.

Warning

Override this function 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 function is not implemented.

property sim

The instance of the Sim this context is for.

property sim_full_name

The full name of the Sim this context is for.

property sim_id

The decimal identifier of the Sim this context is for.

property sim_info

The Sim this context is for.

property sim_type

The type of Sim.

Runnable State