Class Extensions
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
PanelThe 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
ButtonThe 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
ElementThe 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
CompletionTypeThe 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
CompletionTypeThe first completion type
other
CompletionTypeA 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
CompletionTypeThe 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
CompletionTypeThe first completion type
other
CompletionTypeA 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
CanExecuteResultThe 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
CanExecuteResultThe first result
other
CanExecuteResultThe second result
Returns
- CanExecuteResult
The validity of both results
DrawIsoArea(SpriteBatch, RectangleF, float, Color, int, 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, int thickness, bool showSize = false, Func<Vector2, float, float> depth = null, float? defaultDepth = null)
Parameters
batch
SpriteBatchThe sprite batch to draw with
area
RectangleFThe area, in world space, to draw a rectangle around
floor
floatThe floor the area is on.
color
ColorThe color that the rectangle should have
thickness
intThe thickness of the line to draw, in pixels.
showSize
boolWhether 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, int, 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, int thickness, bool showSize, float depth)
Parameters
batch
SpriteBatchThe sprite batch to draw with
area
RectangleFThe area, in world space, to draw a rectangle around
floor
floatThe floor the area is on.
color
ColorThe color that the rectangle should have
thickness
intThe thickness of the line to draw, in pixels.
showSize
boolWhether the rectangle's size in world tiles should be displayed on the screen as a string in the center of the drawn rectangle
depth
floatThe depth that the area should have.
GetBedCategories(AgeGroup)
Returns a ObjectCategory combined flag for a sleeping spot for the given age
.
public static ObjectCategory GetBedCategories(this AgeGroup age)
Parameters
age
AgeGroupThe age.
Returns
- ObjectCategory
The sleeping spots.
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
QualityThe 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
AgeGroupThe age group whose days before aging to retrieve.
lifeSpan
LifeSpanThe 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
QualityThe 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
ObjectCategoryThe categories to get the default texture for
Returns
- string
The default texture
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
ObjectCategoryThe categories that an object has
Returns
- FurnitureTool.Tab
The tabs most fitting for the object
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
ClothesIntentionage
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
PregnancyAbilityThe 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
VoiceStyleThe 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
GenealogyTypeThe genealogy type
Returns
- GenealogyType
The genealogy type's opposite
GetPersonality(FoodRestriction, PersonLike)
Returns the PersonalityType that matches the given FoodType.FoodRestriction 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.FoodRestriction restriction, PersonLike person = null)
Parameters
restriction
FoodType.FoodRestrictionThe restriction whose personality to return.
person
PersonLikeThe 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 restriction 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
LifeSpanThe 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
QualityThe 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
ClothesIntentionThe 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 PersonLike A and B, and B and C, respectively. The returned GenealogyType is the genealogy between PersonLike 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
GenealogyTypeThe genealogy between A and B.
bToC
GenealogyTypeThe 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
MouseButtonThe 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
ButtonsThe 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
ElementThe element to query.
Returns
- bool
Whether the element is part of the active root.
IsAgeAppropriate(GenealogyType, AgeGroup, AgeGroup)
Returns whether the given GenealogyType is appropriate for a relationship between the given AgeGroup values.
public static bool IsAgeAppropriate(this GenealogyType type, AgeGroup myAge, AgeGroup otherAge)
Parameters
type
GenealogyTypeThe genealogy type in question
myAge
AgeGroupThe age group of the person that should have the
type
.otherAge
AgeGroupThe age group of the other person.
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
ClothesIntentionThe intention.
age
AgeGroupThe age group.
Returns
- bool
Whether the given
intention
is avilable for the givenage
.
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
intThe current time.
Returns
- bool
Whether the
time
is within theschedule
.
IsHorizontal(Direction2)
Returns whether the passed direction is considered horizontal. A horizontal direction is MLEM.Maths.Direction2.Left and MLEM.Maths.Direction2.Right. All other directions return false.
public static bool IsHorizontal(this Direction2 dir)
Parameters
dir
Direction2The direction to check horizontalness for
Returns
- bool
Whether or not the direction is horizontal
IsLockedFor(LockType, PersonLike, Lot)
Returns whether the given LockType is considered "locked" for the given PersonLike on the given Lot
public static bool IsLockedFor(this LockType type, PersonLike person, Lot lot)
Parameters
type
LockTypeThe lock type to query
person
PersonLikeThe person to query
lot
LotThe 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 and Eyes.
public static bool IsPartOfPerson(this ClothesLayer layer)
Parameters
layer
ClothesLayerThe clothes layer
Returns
- bool
Whether the clothes layer is part of the person
IsTextFieldSelected(UiSystem)
An extension method that determines whether any text fields in the given MLEM.Ui.UiSystem are currently selected.
public static bool IsTextFieldSelected(this UiSystem system)
Parameters
system
UiSystemThe ui system whose children to check.
Returns
- bool
Whether a MLEM.Ui.Elements.TextField is currently selected.
IsVertical(Direction2)
Returns whether the passed direction is considered vertical. A vertical direction is MLEM.Maths.Direction2.Up and MLEM.Maths.Direction2.Down. All other directions return false.
public static bool IsVertical(this Direction2 dir)
Parameters
dir
Direction2The 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(SerializerContext, EventHandler<ErrorEventArgs>, bool).
public static T JsonCopy<T>(this T obj)
Parameters
obj
TThe 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
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
LifeSpanThe 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.
ScreenContent(Channel)
An extension method that returns a string representing the screen content for the given channel
, which can be passed to TurnOn(string).
public static string ScreenContent(this Television.Channel channel)
Parameters
channel
Television.ChannelThe channel whose screen content to return.
Returns
- string
The channel's screen content.
SetInWorldSnapping(Tooltip)
Causes the given tooltip
to snap to the in-world cursor automatically.
public static void SetInWorldSnapping(this Tooltip tooltip)
Parameters
tooltip
TooltipThe tooltip.
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
RootElementThe root element that should pause the game
value
boolWhether the element should pause the game
Returns
- RootElement
The root element passed, for chaining
Slugify(string)
"Slugifies" the given name
, effectively removing all special characters and diacritics and turning it into a string that the game can use for file names and JSON entry keys. This method is used for the name of people, households and lots.
public static string Slugify(this string name)
Parameters
name
stringThe name to slugify.
Returns
- string
The slugified name.
ToLocalizedString(Quality)
Returns a localized string for the given Quality.
public static string ToLocalizedString(this Quality quality)
Parameters
quality
QualityThe 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
Vector2The position to convert
floor
floatThe floor that the position is on.
center
boolIf this is true, the position will be offset by half a tile, centering it on the screen
applyCameraRotation
boolWhether the game's current CameraRotation should be applied using ApplyCameraRotation(Vector2, bool, Direction2?)
borderOffset
boolWhether 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
floatThe 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
TimeSpanThe 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
TimeSpanThe 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
Vector2The 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.Maths.Direction2 as a side of a WallLike. Specifically, MLEM.Maths.Direction2.Up and MLEM.Maths.Direction2.Left return 0, any other directions return 1.
public static int ToWallSide(this Direction2 dir)
Parameters
dir
Direction2The 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
PoseThe 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
Vector2The position to convert
floor
floatThe floor that the position is on.
applyCameraRotation
boolWhether 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
TimeSpanThe in-game time to query.
Returns
- DayOfWeek
The weekday.