Extensions - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life

TinyLife.Utilities

Extensions Class

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

public static class Extensions

Inheritance System.Object 🡒 Extensions

Methods

Extensions.AddHoverAnimation(Button) Method

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 MLEM.Ui.Elements.Button AddHoverAnimation(this MLEM.Ui.Elements.Button button);

Parameters

button MLEM.Ui.Elements.Button
The button to add the hover animation to

Returns

MLEM.Ui.Elements.Button
The button, for chaining

Extensions.BothCompleted(CompletionType, Func<CompletionType>) Method

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 TinyLife.Actions.Action.CompletionType BothCompleted(this TinyLife.Actions.Action.CompletionType type, System.Func<TinyLife.Actions.Action.CompletionType> other);

Parameters

type CompletionType
The first completion type

other System.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

Extensions.BothValid(CanExecuteResult, Func<CanExecuteResult>) Method

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 TinyLife.Actions.ActionType.CanExecuteResult BothValid(this TinyLife.Actions.ActionType.CanExecuteResult result, System.Func<TinyLife.Actions.ActionType.CanExecuteResult> other);

Parameters

result CanExecuteResult
The first result

other System.Func<CanExecuteResult>
The second result

Returns

CanExecuteResult
The validity of both results

Extensions.CloseLater(Element) Method

Closes the given MLEM.Ui.Elements.Element, removing it from its root, in the next frame.
This is useful if the element is closed early in the update loop, and the user's click has not been fully processed yet.

public static void CloseLater(this MLEM.Ui.Elements.Element element);

Parameters

element MLEM.Ui.Elements.Element
The element to close

Extensions.DrawIsoArea(SpriteBatch, RectangleF, Color, bool) Method

Draws an isometric rectangle with the given data

public static void DrawIsoArea(this Microsoft.Xna.Framework.Graphics.SpriteBatch batch, MLEM.Misc.RectangleF area, Microsoft.Xna.Framework.Color color, bool showSize=false);

Parameters

batch Microsoft.Xna.Framework.Graphics.SpriteBatch
The sprite batch to draw with

area MLEM.Misc.RectangleF
The area, in world space, to draw a rectangle around

color Microsoft.Xna.Framework.Color
The color that the rectangle should have

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

Extensions.GetChanceModifier(Quality) Method

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 TinyLife.Skills.Quality quality);

Parameters

quality Quality
The quality to query

Returns

System.Single
The chance modifier for this quality

Extensions.GetDecorativeRating(Quality) Method

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 TinyLife.Skills.Quality quality);

Parameters

quality Quality
The quality to query

Returns

System.Int32
The decorative rating for this quality

Extensions.GetDefaultTab(ObjectCategory) Method

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

public static TinyLife.Tools.FurnitureTool.Tab GetDefaultTab(this TinyLife.Objects.ObjectCategory categories);

Parameters

categories ObjectCategory
The categories that an object has

Returns

Tab
The tabs most fitting for the object

Extensions.GetOpposite(GenealogyType) Method

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 TinyLife.GenealogyType GetOpposite(this TinyLife.GenealogyType type);

Parameters

type GenealogyType
The genealogy type

Returns

GenealogyType
The genealogy type's opposite

Extensions.GetPriceModifier(Quality) Method

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 TinyLife.Skills.Quality quality);

Parameters

quality Quality
The quality to query

Returns

System.Single
The price modifier for the object

Extensions.GetTimeSpan(IGenericDataHolder, string) Method

Gets a time span from the object's generic data.
The time span is stored as a System.Double, which represents the amount of milliseconds that it contains.

public static System.TimeSpan GetTimeSpan(this MLEM.Misc.IGenericDataHolder holder, string name);

Parameters

holder MLEM.Misc.IGenericDataHolder
The object holder

name System.String
The name of the time span to get

Returns

System.TimeSpan
The time span

See Also

Extensions.IsHorizontal(Direction2) Method

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 MLEM.Misc.Direction2 dir);

Parameters

dir MLEM.Misc.Direction2
The direction to check horizontalness for

Returns

System.Boolean
Whether or not the direction is horizontal

Extensions.IsLockedFor(LockType, Person, Lot) Method

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

public static bool IsLockedFor(this TinyLife.World.LockType type, TinyLife.Objects.Person person, TinyLife.World.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

System.Boolean
Whether the lock type is considered locked for the person

Extensions.IsVertical(Direction2) Method

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 MLEM.Misc.Direction2 dir);

Parameters

dir MLEM.Misc.Direction2
The direction to check verticalness for

Returns

System.Boolean
Whether or not the direction is vertical

Extensions.JsonCopy<T>(T) Method

Copies the given object using the TinyLife.SaveHandler.Serializer.

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

Type parameters

T
The type of the object

Parameters

obj T
The object to copy

Returns

T
A copy of the object

Extensions.OneCompleted(CompletionType, Func<CompletionType>) Method

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 TinyLife.Actions.Action.CompletionType OneCompleted(this TinyLife.Actions.Action.CompletionType type, System.Func<TinyLife.Actions.Action.CompletionType> other);

Parameters

type CompletionType
The first completion type

other System.Func<CompletionType>
A function to gather the second completion type

Returns

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

Extensions.SetTimeSpan(IGenericDataHolder, string, TimeSpan) Method

Sets a time span to the object's generic data.
The time span is stored as a System.Double, which represents the amount of milliseconds that it contains.

public static void SetTimeSpan(this MLEM.Misc.IGenericDataHolder holder, string name, System.TimeSpan value);

Parameters

holder MLEM.Misc.IGenericDataHolder
The object holder

name System.String
The name of the time span to get

value System.TimeSpan
The time span to set

See Also

Extensions.ToLocalizedString(Quality) Method

Returns a localized string for the given Quality.

public static string ToLocalizedString(this TinyLife.Skills.Quality quality);

Parameters

quality Quality
The quality

Returns

System.String
A localized string representing the quality

Extensions.ToScreenPos(Vector2, bool, bool, bool) Method

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

public static Microsoft.Xna.Framework.Vector2 ToScreenPos(this Microsoft.Xna.Framework.Vector2 position, bool center=false, bool applyCameraRotation=true, bool borderOffset=false);

Parameters

position Microsoft.Xna.Framework.Vector2
The position to convert

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

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

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

Returns

Microsoft.Xna.Framework.Vector2
The draw-space position

Extensions.ToSellingPriceString(float) Method

Returns a string of the structure "$0.##" that displays the given value as a price in dollars.

public static string ToSellingPriceString(this float value);

Parameters

value System.Single
The price

Returns

System.String
The price as a string

Extensions.ToSimpleLocalizedString(TimeSpan) Method

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 System.TimeSpan time);

Parameters

time System.TimeSpan
The time to localize

Returns

System.String
A simple localized string for the time span

Extensions.ToSoundPos(Vector2) Method

Converts the given in-world position to a position that can be used for an Microsoft.Xna.Framework.Audio.AudioEmitter

public static Microsoft.Xna.Framework.Vector3 ToSoundPos(this Microsoft.Xna.Framework.Vector2 worldPos);

Parameters

worldPos Microsoft.Xna.Framework.Vector2
The world position to convert

Returns

Microsoft.Xna.Framework.Vector3
The sound-space position

Extensions.ToVisualY(Vector2) Method

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 Microsoft.Xna.Framework.Vector2 ToVisualY(this Microsoft.Xna.Framework.Vector2 pos);

Parameters

pos Microsoft.Xna.Framework.Vector2
The position to turn into a visual y position

Returns

Microsoft.Xna.Framework.Vector2
The given position translated into virtual y space

Extensions.ToWallSide(Direction2) Method

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.

public static int ToWallSide(this MLEM.Misc.Direction2 dir);

Parameters

dir MLEM.Misc.Direction2
The direction to convert into a wall side

Returns

System.Int32
The corresponding wall side

Extensions.ToWorking(Pose) Method

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.

public static TinyLife.Objects.Person.Pose ToWorking(this TinyLife.Objects.Person.Pose pose);

Parameters

pose Pose
The pose to convert to a working pose

Returns

Pose
The working version of the given pose

Exceptions

System.ArgumentOutOfRangeException
If the given pose does not have a working version

Extensions.ToWorldPos(Vector2, bool) Method

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

public static Microsoft.Xna.Framework.Vector2 ToWorldPos(this Microsoft.Xna.Framework.Vector2 position, bool applyCameraRotation=true);

Parameters

position Microsoft.Xna.Framework.Vector2
The position to convert

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

Returns

Microsoft.Xna.Framework.Vector2
The world-space position