Table of Contents

Class Extensions

Namespace
TinyLife.Utilities
Assembly
Tiny Life.dll

A set of extensions for dealing with various things required by Tiny Life.

public static class Extensions
Inheritance
Extensions
Inherited Members

Methods

AddGamepadScrolling(Panel)

Adds the ability to use a gamepad to scroll to the given MLEM.Ui.Elements.Panel.

public static void AddGamepadScrolling(this Panel panel)

Parameters

panel Panel

The panel to add gamepad scrolling to.

AddHoverAnimation(Button)

Adds a hover animation to the given MLEM.Ui.Elements.Button. The hover animation will automatically start playing when the mouse enters the button.

public static Button AddHoverAnimation(this Button button)

Parameters

button Button

The button to add the hover animation to

Returns

Button

The button, for chaining

AddProgressArrows(Element, Func<float>, Func<float>, Func<float>, Func<Color>)

Adds a set of three progress arrows as an overlay to the passed element and displays a varying number of them based on additional parameters. This method is used for the skill, need and relationship bars.

public static (Group, Image[]) AddProgressArrows(this Element element, Func<float> getValue, Func<float> minDelta, Func<float> deltaPerArrow, Func<Color> color)

Parameters

element Element

The element to add the progress arrows to.

getValue Func<float>

A function that returns a current value.

minDelta Func<float>

A function that determines how much the value returned by getValue needs to change every update frame for an arrow to display.

deltaPerArrow Func<float>

A function that determines how much the value returned by getValue needs to change every update frame to display additional arrows beyond the first one.

color Func<Color>

A function that returns the color the arrows should have.

Returns

(Group, Image[])

AnyActive(CompletionType, Func<CompletionType>)

A helper method to return Active if one of the completion types is Active. If this is not the case, the first completion type that is different is returned.

public static CompletionType AnyActive(this CompletionType type, Func<CompletionType> other)

Parameters

type CompletionType

The first completion type

other Func<CompletionType>

A function to gather the second completion type

Returns

CompletionType

Active if one of the completion types is Active, or the other's completion type

AnyActive(CompletionType, CompletionType)

A helper method to return Active if one of the completion types is Active. If this is not the case, the first completion type that is different is returned.

public static CompletionType AnyActive(this CompletionType type, CompletionType other)

Parameters

type CompletionType

The first completion type

other CompletionType

A function to gather the second completion type

Returns

CompletionType

Active if one of the completion types is Active, or the other's completion type

AnyInactive(CompletionType, Func<CompletionType>)

A helper method to return Active if both of the completion types are Active. If this is not the case, the first completion type that is different is returned.

public static CompletionType AnyInactive(this CompletionType type, Func<CompletionType> other)

Parameters

type CompletionType

The first completion type

other Func<CompletionType>

A function to gather the second completion type

Returns

CompletionType

The first non-active completion type, or Active if there is none

AnyInactive(CompletionType, CompletionType)

A helper method to return Active if both of the completion types are Active. If this is not the case, the first completion type that is different is returned.

public static CompletionType AnyInactive(this CompletionType type, CompletionType other)

Parameters

type CompletionType

The first completion type

other CompletionType

A function to gather the second completion type

Returns

CompletionType

The first non-active completion type, or Active if there is none

BothValid(CanExecuteResult, Func<CanExecuteResult>)

A helper method to return Valid only if both passed CanExecuteResult values are Valid. If this is not the case, the validity of the result is returned if it is not Valid, and otherwise, the validity of the other is returned.

public static CanExecuteResult BothValid(this CanExecuteResult result, Func<CanExecuteResult> other)

Parameters

result CanExecuteResult

The first result

other Func<CanExecuteResult>

The second result

Returns

CanExecuteResult

The validity of both results

BothValid(CanExecuteResult, CanExecuteResult)

A helper method to return Valid only if both passed CanExecuteResult values are Valid. If this is not the case, the validity of the result is returned if it is not Valid, and otherwise, the validity of the other is returned.

public static CanExecuteResult BothValid(this CanExecuteResult result, CanExecuteResult other)

Parameters

result CanExecuteResult

The first result

other CanExecuteResult

The second result

Returns

CanExecuteResult

The validity of both results

CanTakeOff(ClothesLayer)

Returns whether the given ClothesLayer can be taken off in the character creator.

public static bool CanTakeOff(this ClothesLayer layer)

Parameters

layer ClothesLayer

The clothes layer

Returns

bool

Whether the clothes layer can be taken off

DrawIsoArea(SpriteBatch, RectangleF, float, Color, bool, Func<Vector2, float, float>, float?)

Draws an isometric rectangle with the given data using a pixelated tile texture.

public static void DrawIsoArea(this SpriteBatch batch, RectangleF area, float floor, Color color, bool showSize = false, Func<Vector2, float, float> depth = null, float? defaultDepth = null)

Parameters

batch SpriteBatch

The sprite batch to draw with

area RectangleF

The area, in world space, to draw a rectangle around

floor float

The floor the area is on.

color Color

The color that the rectangle should have

showSize bool

Whether the rectangle's size in world tiles should be displayed on the screen as a string in the center of the drawn rectangle

depth Func<Vector2, float, float>

An optional function that returns depth that each position should have.

defaultDepth float?

The default depth to use if depth is null.

DrawIsoArea(SpriteBatch, RectangleF, float, Color, bool, float)

Draws an isometric rectangle with the given data using a pixelated tile texture.

public static void DrawIsoArea(this SpriteBatch batch, RectangleF area, float floor, Color color, bool showSize, float depth)

Parameters

batch SpriteBatch

The sprite batch to draw with

area RectangleF

The area, in world space, to draw a rectangle around

floor float

The floor the area is on.

color Color

The color that the rectangle should have

showSize bool

Whether the rectangle's size in world tiles should be displayed on the screen as a string in the center of the drawn rectangle

depth float

The depth that the area should have.

GetChanceModifier(Quality)

Returns a chance modifier for the given Quality, which is always greater than 0 and less than or equal to 1. This is useful for calculating the chance of something happening based on the quality of an object. The returned values are as follows: Terrible: 0.05, Good: 0.55, Great: 0.75, Perfect: 0.9, Masterpiece: 1, Else: 0.4.

public static float GetChanceModifier(this Quality quality)

Parameters

quality Quality

The quality to query

Returns

float

The chance modifier for this quality

GetDaysBeforeAging(AgeGroup, LifeSpan)

Returns the amount of days that have to pass until a person in the given AgeGroup with the given LifeSpan ages up.

public static int GetDaysBeforeAging(this AgeGroup group, LifeSpan lifeSpan)

Parameters

group AgeGroup

The age group whose days before aging to retrieve.

lifeSpan LifeSpan

The life span whose multiplier to use.

Returns

int

The amount of days before a person ages up.

Exceptions

ArgumentOutOfRangeException

Thrown when the given lifeSpan is not defined.

GetDecorativeRating(Quality)

Returns the decorative rating of an object with the given Quality. The returned values are as follows: Terrible: -2, Good: 1, Great: 1, Perfect: 2, Masterpiece: 3, Else: 0.

public static int GetDecorativeRating(this Quality quality)

Parameters

quality Quality

The quality to query

Returns

int

The decorative rating for this quality

GetDefaultDirtyOverlayTextureName(ObjectCategory)

Returns the default DirtyOverlayTextureName to use for the given set of ObjectCategory flags. If none of the flags match a default overlay texture, this method will return null.

public static string GetDefaultDirtyOverlayTextureName(this ObjectCategory category)

Parameters

category ObjectCategory

The categories to get the default texture for

Returns

string

The default texture

GetDefaultPose(AgeGroup)

Returns the default pose that a Person should have based on the given age.

public static Pose GetDefaultPose(this AgeGroup age)

Parameters

age AgeGroup

The age.

Returns

Pose

The age's default pose.

GetDefaultTab(ObjectCategory)

Returns the default FurnitureTool.Tab flags that the given ObjectCategory flag combination should be sorted into

public static FurnitureTool.Tab GetDefaultTab(this ObjectCategory categories)

Parameters

categories ObjectCategory

The categories that an object has

Returns

FurnitureTool.Tab

The tabs most fitting for the object

GetDepth(ClothesLayer)

Returns the default depth for the ClothesLayer when rendering. The default value is the index of the layer in the Layers array.

public static float GetDepth(this ClothesLayer layer)

Parameters

layer ClothesLayer

The clothes layer

Returns

float

The default render depth

GetDescription(ClothesIntention, AgeGroup?)

Returns a set of strings (split into multiple lines) that describes the given ClothesIntention flags in a localized fashion.

public static IEnumerable<string> GetDescription(this ClothesIntention intentions, AgeGroup? age = null)

Parameters

intentions ClothesIntention
age AgeGroup?

Returns

IEnumerable<string>

This clothes item's intention description

GetMostFittingStyle(PregnancyAbility)

Returns the most fitting StylePreference for the given PregnancyAbility.

public static StylePreference GetMostFittingStyle(this PregnancyAbility ability)

Parameters

ability PregnancyAbility

The pregnancy ability.

Returns

StylePreference

The most fitting style preference.

GetMostFittingStyle(VoiceStyle)

Returns the most fitting StylePreference for the given VoiceStyle.

public static StylePreference GetMostFittingStyle(this VoiceStyle voice)

Parameters

voice VoiceStyle

The voice style.

Returns

StylePreference

The most fitting style preference.

GetOpposite(GenealogyType)

Returns the opposite of the given GenealogyType. The "opposite" is the relationship that the other partner of this GenealogyType will have. For example, the opposite of Parent is Child and vice versa.

public static GenealogyType GetOpposite(this GenealogyType type)

Parameters

type GenealogyType

The genealogy type

Returns

GenealogyType

The genealogy type's opposite

GetPersonality(FoodIntolerance, Person)

Returns the PersonalityType that matches the given FoodType.FoodIntolerance flag. If multiple values are set, the personality that is considered most important is returned. If the person is set, a personality will only be returned if the person has it.

public static PersonalityType GetPersonality(this FoodType.FoodIntolerance intolerance, Person person = null)

Parameters

intolerance FoodType.FoodIntolerance

The intolerance whose personality to return.

person Person

The person who needs to have the personality for it to be returned. If this is null, the most important personality is always returned.

Returns

PersonalityType

The matching personality for the given food intolerance flag.

GetPregnancyHours(LifeSpan)

Returns the amount of hours that a person should be pregnant for based on the given lifeSpan.

public static int GetPregnancyHours(this LifeSpan lifeSpan)

Parameters

lifeSpan LifeSpan

The life span.

Returns

int

The amount of hours that a pregnancy should last.

GetPriceModifier(Quality)

Returns a multiplier that an object's price should be multiplied with based on the given Quality. The returned values are as follows: Terrible: 0.5, Good: 1.5, Great: 2, Perfect: 3, Masterpiece: 5, Else: 1.

public static float GetPriceModifier(this Quality quality)

Parameters

quality Quality

The quality to query

Returns

float

The price modifier for the object

GetRequiredMatchPercentage(ClothesIntention)

Returns the percentage that an Outfit has to match the given ClothesIntention for it to be allowed to be used for an outfit. To find the current percentage of an Outfit, use GetIntentionPercentage(ClothesIntention).

public static float GetRequiredMatchPercentage(this ClothesIntention intention)

Parameters

intention ClothesIntention

The intention to query.

Returns

float

The percentage that the intention needs to match for it to be allowed.

GetTransitive(GenealogyType, GenealogyType)

Given the GenealogyType of two relationships, returns the transitive genealogy that results from the two given genealogies. The given genealogies are the ones in relationships between Person A and B, and B and C, respectively. The returned GenealogyType is the genealogy between Person A and C. If null is returned, the transitive genealogy cannot reliably be gathered from the given information.

public static GenealogyType? GetTransitive(this GenealogyType aToB, GenealogyType bToC)

Parameters

aToB GenealogyType

The genealogy between A and B.

bToC GenealogyType

The genealogy between B and C.

Returns

GenealogyType?

The genealogy between A and C, or null if the genealogy cannot be reliably gathered.

Exceptions

ArgumentOutOfRangeException

If any undefined GenealogyType is passed as a parameter.

Icon(MouseButton)

Returns a texture region that contains the icon that the given MLEM.Input.MouseButton should display.

public static TextureRegion Icon(this MouseButton button)

Parameters

button MouseButton

The button whose icon to return.

Returns

TextureRegion

The button's icon, or null if the button is invalid or has no icon.

Icon(Buttons)

Returns a texture region that contains the icon that the given Microsoft.Xna.Framework.Input.Buttons should display. This method is used by GamepadHint(Anchor, Func<Options, Buttons>, Vector2, Vector2?, Func<bool>).

public static TextureRegion Icon(this Buttons button)

Parameters

button Buttons

The button whose icon to return.

Returns

TextureRegion

The button's icon, or null if the button is invalid or has no icon.

IsActiveRoot(Element)

Returns whether the given MLEM.Ui.Elements.Element is currently considered to be part of the active MLEM.Ui.RootElement.

public static bool IsActiveRoot(this Element element)

Parameters

element Element

The element to query.

Returns

bool

Whether the element is part of the active root.

IsAgeAppropriate(GenealogyType, AgeGroup)

Returns whether the given GenealogyType is approriate for a person with the given AgeGroup. If this method returns false, the genealogy type should not be applied to a Relationship whose main person has the given age.

public static bool IsAgeAppropriate(this GenealogyType type, AgeGroup age)

Parameters

type GenealogyType

The genealogy type in question

age AgeGroup

The age group in question

Returns

bool

Whether the given genealogy type is appropriate for the given age

IsAvailableForAge(ClothesIntention, AgeGroup)

Returns whether the given ClothesIntention is avilable for the given AgeGroup. This method only returns false for certain intentions for the baby age group.

public static bool IsAvailableForAge(this ClothesIntention intention, AgeGroup age)

Parameters

intention ClothesIntention

The intention.

age AgeGroup

The age group.

Returns

bool

Whether the given intention is avilable for the given age.

IsBetween((int Start, int End), int)

Returns whether the given time range is between the given time. If the time range ranges into the next day, the correct value is still calculated.

public static bool IsBetween(this (int Start, int End) schedule, int time)

Parameters

schedule (int Start, int End)

The schedule with its start and end time. Can be between two days.

time int

The current time.

Returns

bool

Whether the time is within the schedule.

IsHorizontal(Direction2)

Returns whether the passed direction is considered horizontal. A horizontal direction is MLEM.Misc.Direction2.Left and MLEM.Misc.Direction2.Right. All other directions return false.

public static bool IsHorizontal(this Direction2 dir)

Parameters

dir Direction2

The direction to check horizontalness for

Returns

bool

Whether or not the direction is horizontal

IsLockedFor(LockType, Person, Lot)

Returns whether the given LockType is considered "locked" for the given Person on the given Lot

public static bool IsLockedFor(this LockType type, Person person, Lot lot)

Parameters

type LockType

The lock type to query

person Person

The person to query

lot Lot

The lot that the object locked with the given type is on

Returns

bool

Whether the lock type is considered locked for the person

IsPartOfPerson(ClothesLayer)

Returns whether the given ClothesLayer is part of a person physically. This methdo returns true for Body, Arms and Eyes.

public static bool IsPartOfPerson(this ClothesLayer layer)

Parameters

layer ClothesLayer

The clothes layer

Returns

bool

Whether the clothes layer is part of the person

IsVertical(Direction2)

Returns whether the passed direction is considered vertical. A vertical direction is MLEM.Misc.Direction2.Up and MLEM.Misc.Direction2.Down. All other directions return false.

public static bool IsVertical(this Direction2 dir)

Parameters

dir Direction2

The direction to check verticalness for

Returns

bool

Whether or not the direction is vertical

JsonCopy<T>(T)

Copies the given object using a Newtonsoft.Json.JsonSerializer created using CreateSerializerSettings(EventHandler<ErrorEventArgs>).

public static T JsonCopy<T>(this T obj)

Parameters

obj T

The object to copy

Returns

T

A copy of the object

Type Parameters

T

The type of the object

Length((int Start, int End))

Returns the length of the given schedule. If the time range ranges into the next day, the correct value is still calculated.

public static int Length(this (int Start, int End) schedule)

Parameters

schedule (int Start, int End)

The schedule.

Returns

int

The length of the given schedule.

Multiplier(LifeSpan)

Returns the multiplier that the given LifeSpan applies to a person's life span.

public static float Multiplier(this LifeSpan lifeSpan)

Parameters

lifeSpan LifeSpan

The life span whose multiplier to retrieve.

Returns

float

The life span's multiplier.

Exceptions

ArgumentOutOfRangeException

Thrown when the given lifeSpan is not defined, or Infinite.

SetPauseGame(RootElement, bool)

Sets a flag for a MLEM.Ui.RootElement that causes it to pause the game if it is displayed

public static RootElement SetPauseGame(this RootElement root, bool value = true)

Parameters

root RootElement

The root element that should pause the game

value bool

Whether the element should pause the game

Returns

RootElement

The root element passed, for chaining

ToLocalizedString(Quality)

Returns a localized string for the given Quality.

public static string ToLocalizedString(this Quality quality)

Parameters

quality Quality

The quality

Returns

string

A localized string representing the quality

ToScreenPos(Vector2, float, bool, bool, bool)

Converts the given world-space position into a draw-space position

public static Vector2 ToScreenPos(this Vector2 position, float floor, bool center = false, bool applyCameraRotation = true, bool borderOffset = false)

Parameters

position Vector2

The position to convert

floor float

The floor that the position is on.

center bool

If this is true, the position will be offset by half a tile, centering it on the screen

applyCameraRotation bool

Whether the game's current CameraRotation should be applied using ApplyCameraRotation(Vector2, bool, Direction2?)

borderOffset bool

Whether the map border offset should be applied to the camera rotation using ApplyCameraRotation(Vector2, bool, Direction2?). This value only has an effect if applyCameraRotation is true

Returns

Vector2

The draw-space position

ToSellingPriceString(float)

Returns a localized string that says "Sells for", followed by the passed value in tiny bucks

public static string ToSellingPriceString(this float value)

Parameters

value float

The value to display

Returns

string

A selling price string that contains the value, in tiny bucks

ToSimpleLocalizedString(TimeSpan)

Returns a string, localized using Localization, that represents the largest value of the time span. If the time span includes multiple days, a string representing just days is returned. Otherwise, the full hours are returned, and otherwise, the full minutes are returned.

public static string ToSimpleLocalizedString(this TimeSpan time)

Parameters

time TimeSpan

The time to localize

Returns

string

A simple localized string for the time span

ToTimestampString(TimeSpan)

Turns the given timeSpan into a nicely displayed timestamp in 12- or 24-hour format, based on the currently selected Localization language.

public static string ToTimestampString(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The time span to display.

Returns

string

The displayed timestamp.

ToVisualY(Vector2)

Returns the given offset, but translated based on the game's current CameraRotation. For any vector that is passed to this method, the translation that it represents will not be based on cardinal directions, but on directions related to the screen's orientation.

public static Vector2 ToVisualY(this Vector2 pos)

Parameters

pos Vector2

The position to turn into a visual y position

Returns

Vector2

The given position translated into virtual y space

ToWallSide(Direction2)

Returns an integer that represents the given MLEM.Misc.Direction2 as a side of a WallLike. Specifically, MLEM.Misc.Direction2.Up and MLEM.Misc.Direction2.Left return 0, any other directions return 1.

public static int ToWallSide(this Direction2 dir)

Parameters

dir Direction2

The direction to convert into a wall side

Returns

int

The corresponding wall side

ToWorking(Pose)

Converts the given Pose to a version in which a person is looking as if they were working on something. For all standing poses, this returns WorkingStanding, and for all sitting poses, WorkingSitting is returned. If a pose has no working variant, the pose itself is returned.

public static Pose ToWorking(this Pose pose)

Parameters

pose Pose

The pose to convert to a working pose

Returns

Pose

The working version of the given pose

ToWorldPos(Vector2, float, bool)

Converts the given draw-space position into a world-space position

public static Vector2 ToWorldPos(this Vector2 position, float floor, bool applyCameraRotation = true)

Parameters

position Vector2

The position to convert

floor float

The floor that the position is on.

applyCameraRotation bool

Whether the game's current CameraRotation should be applied using ApplyInverseCameraRotation(Vector2, Direction2?)

Returns

Vector2

The world-space position

Weekday(TimeSpan)

Returns the DayOfWeek that the given in-game time represents.

public static DayOfWeek Weekday(this TimeSpan time)

Parameters

time TimeSpan

The in-game time to query.

Returns

DayOfWeek

The weekday.