FurnitureType - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life

TinyLife.Objects

FurnitureType Class

A furniture type is basically a blueprint for Furniture objects.
Each furniture type can create a furniture instance and the type's data will be transferred to the instance.
Furniture types are automatically listed in the FurnitureTool if registered using Register(TypeSettings).

public class FurnitureType : MLEM.Misc.GenericDataHolder,
TinyLife.World.IPricedObject

Inheritance System.Object 🡒 MLEM.Misc.GenericDataHolder 🡒 FurnitureType

Implements IPricedObject

Fields

FurnitureType.Textures Field

The textures that this furniture type has.
Each texture is automatically loaded based on the registered MLEM.Data.DataTextureAtlas instances.
If a furniture type has multiple ColorMap entries (or multiple ColorSchemes), additional texture regions will automatically be created to the right of the original texture region.

public readonly Dictionary<Direction2,TextureRegion[]> Textures;

Field Value

System.Collections.Generic.Dictionary<MLEM.Misc.Direction2,MLEM.Textures.TextureRegion[]>

FurnitureType.Types Field

A list of all available furniture types. Register furniture types using Register(TypeSettings).

public static readonly IDictionary<string,FurnitureType> Types;

Field Value

System.Collections.Generic.IDictionary<System.String,FurnitureType>

Properties

FurnitureType.Rotations Property

The valid rotations that this furniture has, which are automatically determined based on the available Textures

public System.Collections.Generic.ICollection<MLEM.Misc.Direction2> Rotations { get; }

Property Value

System.Collections.Generic.ICollection<MLEM.Misc.Direction2>

FurnitureType.Settings Property

This furniture type's settings

public TinyLife.Objects.FurnitureType.TypeSettings Settings { get; }

Property Value

TypeSettings

Methods

FurnitureType.AreWallsInTheWay(Map, Vector2, Direction2) Method

Returns whether or not there would be walls in the way if this furniture type was placed at the given position with the given rotation

public bool AreWallsInTheWay(TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 pos, MLEM.Misc.Direction2 rotation);

Parameters

map Map
The map to place the furniture on

pos Microsoft.Xna.Framework.Vector2
The position that the furniture should be placed at

rotation MLEM.Misc.Direction2
The rotation that the furniture should have

Returns

System.Boolean
Whether there are walls in the way if the furniture gets placed in this location

FurnitureType.Construct(int[], Map, Vector2, Nullable<Guid>) Method

Constructs a new Furniture object from this furniture type

public TinyLife.Objects.Furniture Construct(int[] colors, TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 pos, System.Nullable<System.Guid> id=null);

Parameters

colors System.Int32[]
The indices of the colors that the furniture should have

map Map
The map that the furniture should be added to

pos Microsoft.Xna.Framework.Vector2
The position that the furniture should have

id System.Nullable<System.Guid>
The id that the furniture should have, or a random one by defualt

Returns

Furniture
A new furniture instance of this type

FurnitureType.DrawLayers(Map, Vector2, SpriteBatch, Vector2, Direction2, TextureRegion[], int[], float, bool, Furniture, AbstractSpot, Nullable<Color>, float, bool) Method

Draws the furniture type with the given data

public void DrawLayers(TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, Microsoft.Xna.Framework.Vector2 drawPos, MLEM.Misc.Direction2 rotation, MLEM.Textures.TextureRegion[] layers, int[] colors, float scale, bool pivot=true, TinyLife.Objects.Furniture parent=null, TinyLife.Objects.AbstractSpot spot=null, System.Nullable<Microsoft.Xna.Framework.Color> overrideColor=null, float depthOffset=0f, bool held=false);

Parameters

map Map
The map to draw the furniture type on

position Microsoft.Xna.Framework.Vector2
The position on the map that the furniture is at

batch Microsoft.Xna.Framework.Graphics.SpriteBatch
The sprite batch used for drawing

drawPos Microsoft.Xna.Framework.Vector2
The position that this furniture should be drawn at on the screen

rotation MLEM.Misc.Direction2
The rotation of the furniture

layers MLEM.Textures.TextureRegion[]
The textures to draw this furniture with

colors System.Int32[]
The indices in the ColorSchemes that the furniture should be drawn with

scale System.Single
The scale that the furniture should be drawn with

pivot System.Boolean
Whether or not the furniture should be shifted by its pivot point

parent Furniture
The parent that the furniture is attached to. Can be null.

spot AbstractSpot
The object spot that the furniture is on, or null if there is no parent

overrideColor System.Nullable<Microsoft.Xna.Framework.Color>
The color that should be used to draw this furniture instead of colors

depthOffset System.Single
A value that is added to the depth calculation for drawing this furniture type

held System.Boolean
Whether or not this item is currently being held by a Person

FurnitureType.GetBestRotation(Direction2) Method

Returns a MLEM.Misc.Direction2 that is closest to goal, but that this object is allowed to have.
The return value is guaranteed to be contained in Rotations and have the same verticality as goal, or be the same value.

public MLEM.Misc.Direction2 GetBestRotation(MLEM.Misc.Direction2 goal);

Parameters

goal MLEM.Misc.Direction2
The goal rotation

Returns

MLEM.Misc.Direction2
The closest possible rotation to the goal rotation

FurnitureType.GetCoveredTiles(Vector2, Point) Method

Returns a rectangle that contains all of the tiles which intersect with the furniture when placed at the given position, with the given size.

public static Microsoft.Xna.Framework.Rectangle GetCoveredTiles(Microsoft.Xna.Framework.Vector2 pos, Microsoft.Xna.Framework.Point size);

Parameters

pos Microsoft.Xna.Framework.Vector2
The position to place the furniture at

size Microsoft.Xna.Framework.Point
The size of the furniture

Returns

Microsoft.Xna.Framework.Rectangle
A rectangle with all of the tiles that are covered

FurnitureType.GetPrice() Method

Returns the price that this object can be bought or sold for.
Note that, like in the case of the Painting, the returned price isn't necessarily the full price that the object can be sold for. Instead, the price returned here should be the price that this object has when bought or sold from the FurnitureTool or similar.

public float GetPrice();

Returns

System.Single
The object's price

Implements GetPrice()

FurnitureType.GetReferenceTexture(Nullable<Direction2>) Method

Returns the reference texture of this furniture type for the given rotation.
The reference texture is the first layer of the texture for the given rotation.

public MLEM.Textures.TextureRegion GetReferenceTexture(System.Nullable<MLEM.Misc.Direction2> rotation=null);

Parameters

rotation System.Nullable<MLEM.Misc.Direction2>
The rotation to get the reference texture for. Defaults to DefaultRotation.

Returns

MLEM.Textures.TextureRegion
The reference texture for the given rotation

FurnitureType.GetSize(Direction2) Method

Returns the Size of this furniture type, modified based on the given rotation.

public Microsoft.Xna.Framework.Point GetSize(MLEM.Misc.Direction2 rotation);

Parameters

rotation MLEM.Misc.Direction2
The rotation to return the size for

Returns

Microsoft.Xna.Framework.Point
The modified size

FurnitureType.GetTexture(string, bool) Method

Returns a MLEM.Textures.TextureRegion with the given name, based on all of the textures in the base game and all GetCustomFurnitureTextures() textures.

public static MLEM.Textures.TextureRegion GetTexture(string name, bool throwIfNotFound=true);

Parameters

name System.String
The name of the texture to get

throwIfNotFound System.Boolean
Whether an exception should be thrown if the texture is not found

Returns

MLEM.Textures.TextureRegion
A texture region with the given name, or null if there is none

FurnitureType.GetTextures(string, int, Func<Direction2,bool>) Method

Create a dictionary of textures for all MLEM.Misc.Direction2Helper.Adjacent directions that have a texture registered for them.
Textures are gathered using GetCustomFurnitureTextures(), and textures need to be suffixed with the direction's string to be recognized.
This method is used for furniture of all kinds.

public static System.Collections.Generic.Dictionary<MLEM.Misc.Direction2,MLEM.Textures.TextureRegion[]> GetTextures(string name, int amount=1, System.Func<MLEM.Misc.Direction2,bool> shouldThrow=null);

Parameters

name System.String
The name of the texture to load

amount System.Int32
The amount of layers the texture has

shouldThrow System.Func<MLEM.Misc.Direction2,System.Boolean>
Whether an exception should be thrown if the texture is not found

Returns

System.Collections.Generic.Dictionary<MLEM.Misc.Direction2,MLEM.Textures.TextureRegion[]>
A dictionary of directions to texture layers

FurnitureType.GetWallsInTheWay(Map, Vector2, Direction2) Method

Returns a set of walls that would be in the way if this furniture type was placed at the given position with the given rotation

public System.Collections.Generic.IEnumerable<TinyLife.World.Wall> GetWallsInTheWay(TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 pos, MLEM.Misc.Direction2 rotation);

Parameters

map Map
The map to place the furniture on

pos Microsoft.Xna.Framework.Vector2
The position that the furniture should be placed at

rotation MLEM.Misc.Direction2
The rotation that the furniture should have

Returns

System.Collections.Generic.IEnumerable<Wall>
A set of walls that would be in the way

FurnitureType.HasCategory(ObjectCategory) Method

Returns whether this type's Settings have any of the supplied ObjectCategory values

public bool HasCategory(TinyLife.Objects.ObjectCategory category);

Parameters

category ObjectCategory
The category to query

Returns

System.Boolean
Whether the category is present

FurnitureType.Register(TypeSettings) Method

Registers a custom furniture type

public static TinyLife.Objects.FurnitureType Register(TinyLife.Objects.FurnitureType.TypeSettings settings);

Parameters

settings TypeSettings
The settings to apply to the custom furniture type

Returns

FurnitureType
The registered furniture type

FurnitureType.RegisterAll(IEnumerable<TypeSettings>) Method

Registers a set of custom furniture type and returns them

public static TinyLife.Objects.FurnitureType[] RegisterAll(System.Collections.Generic.IEnumerable<TinyLife.Objects.FurnitureType.TypeSettings> settings);

Parameters

settings System.Collections.Generic.IEnumerable<TypeSettings>
The settings to apply to the custom furniture type

Returns

FurnitureType[]
The registered furniture types