Search Results for

    Show / Hide Table of Contents

    Class Extensions

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

    Inheritance
    System.Object
    Extensions
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: TinyLife.Utilities
    Assembly: Tiny Life.dll
    Syntax
    public static class Extensions

    Methods

    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.

    Declaration
    public static Button AddHoverAnimation(this Button button)
    Parameters
    Type Name Description
    MLEM.Ui.Elements.Button button

    The button to add the hover animation to

    Returns
    Type Description
    MLEM.Ui.Elements.Button

    The button, for chaining

    BothCompleted(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.

    Declaration
    public static CompletionType BothCompleted(this CompletionType type, Func<CompletionType> other)
    Parameters
    Type Name Description
    CompletionType type

    The first completion type

    System.Func<CompletionType> other

    A function to gather the second completion type

    Returns
    Type Description
    CompletionType

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

    BothValid(CanExecuteResult, Func<CanExecuteResult>)

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

    Declaration
    public static CanExecuteResult BothValid(this CanExecuteResult result, Func<CanExecuteResult> other)
    Parameters
    Type Name Description
    TinyLife.Actions.CanExecuteResult result

    The first result

    System.Func<TinyLife.Actions.CanExecuteResult> other

    The second result

    Returns
    Type Description
    TinyLife.Actions.CanExecuteResult

    The validity of both results

    CanTakeOff(ClothesLayer)

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

    Declaration
    public static bool CanTakeOff(this ClothesLayer layer)
    Parameters
    Type Name Description
    ClothesLayer layer

    The clothes layer

    Returns
    Type Description
    System.Boolean

    Whether the clothes layer can be taken off

    DrawIsoArea(SpriteBatch, RectangleF, Color, Boolean, Single)

    Draws an isometric rectangle with the given data

    Declaration
    public static void DrawIsoArea(this SpriteBatch batch, RectangleF area, Color color, bool showSize = false, float depth = 1F)
    Parameters
    Type Name Description
    Microsoft.Xna.Framework.Graphics.SpriteBatch batch

    The sprite batch to draw with

    MLEM.Misc.RectangleF area

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

    Microsoft.Xna.Framework.Color color

    The color that the rectangle should have

    System.Boolean showSize

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

    System.Single depth

    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.

    Declaration
    public static float GetChanceModifier(this Quality quality)
    Parameters
    Type Name Description
    Quality quality

    The quality to query

    Returns
    Type Description
    System.Single

    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.

    Declaration
    public static int GetDaysBeforeAging(this AgeGroup group, LifeSpan lifeSpan)
    Parameters
    Type Name Description
    AgeGroup group

    The age group whose days before aging to retrieve.

    LifeSpan lifeSpan

    The life span whose multiplier to use.

    Returns
    Type Description
    System.Int32

    The amount of days before a person ages up.

    Exceptions
    Type Condition
    System.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.

    Declaration
    public static int GetDecorativeRating(this Quality quality)
    Parameters
    Type Name Description
    Quality quality

    The quality to query

    Returns
    Type Description
    System.Int32

    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.

    Declaration
    public static string GetDefaultDirtyOverlayTextureName(this ObjectCategory category)
    Parameters
    Type Name Description
    ObjectCategory category

    The categories to get the default texture for

    Returns
    Type Description
    System.String

    The default texture

    GetDefaultTab(ObjectCategory)

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

    Declaration
    public static FurnitureTool.Tab GetDefaultTab(this ObjectCategory categories)
    Parameters
    Type Name Description
    ObjectCategory categories

    The categories that an object has

    Returns
    Type Description
    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.

    Declaration
    public static float GetDepth(this ClothesLayer layer)
    Parameters
    Type Name Description
    ClothesLayer layer

    The clothes layer

    Returns
    Type Description
    System.Single

    The default render depth

    GetDescription(ClothesIntention)

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

    Declaration
    public static IEnumerable<string> GetDescription(this ClothesIntention intentions)
    Parameters
    Type Name Description
    ClothesIntention intentions
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.String>

    This clothes item's intention description

    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.

    Declaration
    public static GenealogyType GetOpposite(this GenealogyType type)
    Parameters
    Type Name Description
    GenealogyType type

    The genealogy type

    Returns
    Type Description
    GenealogyType

    The genealogy type's opposite

    GetPersonality(FoodType.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.

    Declaration
    public static PersonalityType GetPersonality(this FoodType.FoodIntolerance intolerance, Person person = null)
    Parameters
    Type Name Description
    FoodType.FoodIntolerance intolerance

    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
    Type Description
    PersonalityType

    The matching personality for the given food intolerance flag.

    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.

    Declaration
    public static float GetPriceModifier(this Quality quality)
    Parameters
    Type Name Description
    Quality quality

    The quality to query

    Returns
    Type Description
    System.Single

    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).

    Declaration
    public static float GetRequiredMatchPercentage(this ClothesIntention intention)
    Parameters
    Type Name Description
    ClothesIntention intention

    The intention to query.

    Returns
    Type Description
    System.Single

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

    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, Nullable<Vector2>, Func<Boolean>).

    Declaration
    public static TextureRegion Icon(this Buttons button)
    Parameters
    Type Name Description
    Microsoft.Xna.Framework.Input.Buttons button

    The button whose icon to return.

    Returns
    Type Description
    MLEM.Textures.TextureRegion

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

    Icon(MouseButton)

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

    Declaration
    public static TextureRegion Icon(this MouseButton button)
    Parameters
    Type Name Description
    MLEM.Input.MouseButton button

    The button whose icon to return.

    Returns
    Type Description
    MLEM.Textures.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.

    Declaration
    public static bool IsActiveRoot(this Element element)
    Parameters
    Type Name Description
    MLEM.Ui.Elements.Element element

    The element to query.

    Returns
    Type Description
    System.Boolean

    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.

    Declaration
    public static bool IsAgeAppropriate(this GenealogyType type, AgeGroup age)
    Parameters
    Type Name Description
    GenealogyType type

    The genealogy type in question

    AgeGroup age

    The age group in question

    Returns
    Type Description
    System.Boolean

    Whether the given genealogy type is appropriate for the given age

    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.

    Declaration
    public static bool IsHorizontal(this Direction2 dir)
    Parameters
    Type Name Description
    MLEM.Misc.Direction2 dir

    The direction to check horizontalness for

    Returns
    Type Description
    System.Boolean

    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

    Declaration
    public static bool IsLockedFor(this LockType type, Person person, Lot lot)
    Parameters
    Type Name Description
    LockType type

    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
    Type Description
    System.Boolean

    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.

    Declaration
    public static bool IsPartOfPerson(this ClothesLayer layer)
    Parameters
    Type Name Description
    ClothesLayer layer

    The clothes layer

    Returns
    Type Description
    System.Boolean

    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.

    Declaration
    public static bool IsVertical(this Direction2 dir)
    Parameters
    Type Name Description
    MLEM.Misc.Direction2 dir

    The direction to check verticalness for

    Returns
    Type Description
    System.Boolean

    Whether or not the direction is vertical

    JsonCopy<T>(T)

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

    Declaration
    public static T JsonCopy<T>(this T obj)
    Parameters
    Type Name Description
    T obj

    The object to copy

    Returns
    Type Description
    T

    A copy of the object

    Type Parameters
    Name Description
    T

    The type of the object

    Multiplier(LifeSpan)

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

    Declaration
    public static float Multiplier(this LifeSpan lifeSpan)
    Parameters
    Type Name Description
    LifeSpan lifeSpan

    The life span whose multiplier to retrieve.

    Returns
    Type Description
    System.Single

    The life span's multiplier.

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

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

    OneCompleted(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.

    Declaration
    public static CompletionType OneCompleted(this CompletionType type, Func<CompletionType> other)
    Parameters
    Type Name Description
    CompletionType type

    The first completion type

    System.Func<CompletionType> other

    A function to gather the second completion type

    Returns
    Type Description
    CompletionType

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

    SetPauseGame(RootElement, Boolean)

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

    Declaration
    public static RootElement SetPauseGame(this RootElement root, bool value = true)
    Parameters
    Type Name Description
    MLEM.Ui.RootElement root

    The root element that should pause the game

    System.Boolean value

    Whether the element should pause the game

    Returns
    Type Description
    MLEM.Ui.RootElement

    The root element passed, for chaining

    ToLocalizedString(Quality)

    Returns a localized string for the given Quality.

    Declaration
    public static string ToLocalizedString(this Quality quality)
    Parameters
    Type Name Description
    Quality quality

    The quality

    Returns
    Type Description
    System.String

    A localized string representing the quality

    ToScreenPos(Vector2, Boolean, Boolean, Boolean)

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

    Declaration
    public static Vector2 ToScreenPos(this Vector2 position, bool center = false, bool applyCameraRotation = true, bool borderOffset = false)
    Parameters
    Type Name Description
    Microsoft.Xna.Framework.Vector2 position

    The position to convert

    System.Boolean center

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

    System.Boolean applyCameraRotation

    Whether the game's current CameraRotation should be applied using ApplyCameraRotation(Vector2, Boolean, Nullable<Direction2>)

    System.Boolean borderOffset

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

    Returns
    Type Description
    Microsoft.Xna.Framework.Vector2

    The draw-space position

    ToSellingPriceString(Single)

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

    Declaration
    public static string ToSellingPriceString(this float value)
    Parameters
    Type Name Description
    System.Single value

    The value to display

    Returns
    Type Description
    System.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.

    Declaration
    public static string ToSimpleLocalizedString(this TimeSpan time)
    Parameters
    Type Name Description
    System.TimeSpan time

    The time to localize

    Returns
    Type Description
    System.String

    A simple localized string for the time span

    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.

    Declaration
    public static Vector2 ToVisualY(this Vector2 pos)
    Parameters
    Type Name Description
    Microsoft.Xna.Framework.Vector2 pos

    The position to turn into a visual y position

    Returns
    Type Description
    Microsoft.Xna.Framework.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 Wall. Specifically, MLEM.Misc.Direction2.Up and MLEM.Misc.Direction2.Left return 0, any other directions return 1.

    Declaration
    public static int ToWallSide(this Direction2 dir)
    Parameters
    Type Name Description
    MLEM.Misc.Direction2 dir

    The direction to convert into a wall side

    Returns
    Type Description
    System.Int32

    The corresponding wall side

    ToWorking(Person.Pose)

    Converts the given Person.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.

    Declaration
    public static Person.Pose ToWorking(this Person.Pose pose)
    Parameters
    Type Name Description
    Person.Pose pose

    The pose to convert to a working pose

    Returns
    Type Description
    Person.Pose

    The working version of the given pose

    ToWorldPos(Vector2, Boolean)

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

    Declaration
    public static Vector2 ToWorldPos(this Vector2 position, bool applyCameraRotation = true)
    Parameters
    Type Name Description
    Microsoft.Xna.Framework.Vector2 position

    The position to convert

    System.Boolean applyCameraRotation

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

    Returns
    Type Description
    Microsoft.Xna.Framework.Vector2

    The world-space position

    Weekday(TimeSpan)

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

    Declaration
    public static DayOfWeek Weekday(this TimeSpan time)
    Parameters
    Type Name Description
    System.TimeSpan time

    The in-game time to query.

    Returns
    Type Description
    System.DayOfWeek

    The weekday.

    ☀
    ☾
    In This Article
    Back to top
    © 2021-2022 Ellpeck – Impressum – Privacy – Status
    ☀
    ☾