Furniture - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life

TinyLife.Objects

Furniture Class

A furniture is an instance of a FurnitureType which is placed in the world, or in a Person's hand.
To register a custom furniture, use Register(TypeSettings).

public class Furniture : TinyLife.Objects.MapObject,
TinyLife.World.IPricedObject

Inheritance System.Object 🡒 MLEM.Misc.GenericDataHolder 🡒 MapObject 🡒 Furniture

Derived
BreakableFurniture
CornerFurniture
Fence
FoodTypedItem
Gravestone
LightFurniture
OverlayWallHanging
Painting
Puddle

Implements IPricedObject

Constructors

Furniture.Furniture(Guid, FurnitureType, int[], Map, Vector2) Constructor

Creates a new furniture instance.
By default, this is done using Construct(int[], Map, Vector2, Nullable<Guid>).

public Furniture(System.Guid id, TinyLife.Objects.FurnitureType type, int[] colors, TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 pos);

Parameters

id System.Guid
The id to apply to the created furniture instance

type FurnitureType
The type to create an instance of

colors System.Int32[]
The colors to apply to the furniture

map Map
The map to create the furniture on

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

Fields

Furniture.Colors Field

The indices of the colors that this furniture has.
Refer to ColorSchemes for the actual colors that these indices represent.

public int[] Colors;

Field Value

System.Int32[]

Furniture.DevaluedThroughUse Field

A field that gets set to true in ActionUpdate(Action, GameTime, TimeSpan, GameSpeed, bool).
If this value is true, the GetPrice() of this object is greatly reduced.

public bool DevaluedThroughUse;

Field Value

System.Boolean

Furniture.IsStatic Field

A field that is true for objects that are part of the exported base map that the current map is created from

public bool IsStatic;

Field Value

System.Boolean

Furniture.Rotation Field

The current rotation of this furniture.
Since furniture has a wide variety of looks, the specific value of the rotation doesn't necessarily have much practical meaning.

public Direction2 Rotation;

Field Value

MLEM.Misc.Direction2

Furniture.Type Field

The FurnitureType that this furniture has

public readonly FurnitureType Type;

Field Value

FurnitureType

Properties

Furniture.Area Property

A MLEM.Misc.RectangleF that represents the area that this furniture piece is currently taking up, based on its GetSize(Direction2) and its Position

public MLEM.Misc.RectangleF Area { get; }

Property Value

MLEM.Misc.RectangleF

Furniture.AreUtilitiesDisabled Property

Returns whether utilities are disabled on the current lot.
This is a shorthand for AreUtilitiesDisabled(Nullable<TimeSpan>).

public bool AreUtilitiesDisabled { get; }

Property Value

System.Boolean

Furniture.HasParent Property

Returns whether a ParentFurniture for this furniture exists.
Note that, if this object is not in the world, or the ParentFurniture is not currently in the world, this property will still be true.

public bool HasParent { get; }

Property Value

System.Boolean

Furniture.ParentFurniture Property

The Furniture that this furniture is currently latched on to.
If this value is non-null, ParentObjectSpot returns the object spot that this furniture is in.

public TinyLife.Objects.Furniture ParentFurniture { get; }

Property Value

Furniture

Furniture.ParentObjectSpot Property

The ObjectSpot that this furniture is currently in.
If this value is non-null, ParentFurniture returns the furniture that this object spot belongs to.

public TinyLife.Objects.ObjectSpot ParentObjectSpot { get; }

Property Value

ObjectSpot

Furniture.VisualPosition Property

The position (in world space) that this furniture is at.
This only differs from this object's Position if the ParentObjectSpot's YOffset is non-zero.

public Microsoft.Xna.Framework.Vector2 VisualPosition { get; }

Property Value

Microsoft.Xna.Framework.Vector2

Methods

Furniture.AddChild(Furniture, Direction2, Nullable<Vector2>) Method

Adds a child to this furniture, setting its parent (SetParent(Furniture, ObjectSpot)) to this furniture and adding it to this furniture's Map.
The object spot selected is the first available object spot.

public bool AddChild(TinyLife.Objects.Furniture item, MLEM.Misc.Direction2 rotation, System.Nullable<Microsoft.Xna.Framework.Vector2> position=null);

Parameters

item Furniture
The furniture to add as the child

rotation MLEM.Misc.Direction2
The rotation that the furniture should have, can be the same as the previous rotation

position System.Nullable<Microsoft.Xna.Framework.Vector2>
The position that the object spot to add this child to should be closest too. If null, no position will be preferred. Defaults to null.

Returns

System.Boolean
If there was a free object spot to add the furniture to

Furniture.AddChild<T>(FurnitureType, Direction2, int[], Nullable<Guid>, Nullable<Vector2>) Method

Adds a child to this furniture, setting its parent (SetParent(Furniture, ObjectSpot)) to this furniture.

public T AddChild<T>(TinyLife.Objects.FurnitureType type, MLEM.Misc.Direction2 rotation, int[] colors=null, System.Nullable<System.Guid> id=null, System.Nullable<Microsoft.Xna.Framework.Vector2> position=null)
    where T : TinyLife.Objects.Furniture;

Type parameters

T
The type of furniture that the child is

Parameters

type FurnitureType
The type of furniture to construct as the child

rotation MLEM.Misc.Direction2
The desired rotation of the child furniture

colors System.Int32[]
The colors that the child should have

id System.Nullable<System.Guid>
The id that the child should have, random by default

position System.Nullable<Microsoft.Xna.Framework.Vector2>
The position that the object spot to add this child to should be closest too. If null, no position will be preferred. Defaults to null.

Returns

T
The child that was added, or null if it doesn't match the type specified

Furniture.Draw(GameTime, SpriteBatch, Vector2, Vector2, Nullable<Color>, Direction2, int[], float, bool, Furniture, AbstractSpot, float, bool) Method

Draws this furniture in the world with the given settings.
This is a more generalized version of Draw(GameTime, SpriteBatch, Vector2, Nullable<Color>)

public virtual void Draw(Microsoft.Xna.Framework.GameTime time, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, Microsoft.Xna.Framework.Vector2 pos, Microsoft.Xna.Framework.Vector2 drawPos, System.Nullable<Microsoft.Xna.Framework.Color> overrideColor, MLEM.Misc.Direction2 rotation, int[] colors, float drawScale, bool pivot, TinyLife.Objects.Furniture parent, TinyLife.Objects.AbstractSpot parentSpot, float depthOffset, bool held);

Parameters

time Microsoft.Xna.Framework.GameTime
The game time

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

pos Microsoft.Xna.Framework.Vector2
The position, in world space, that the furniture is at

drawPos Microsoft.Xna.Framework.Vector2
The position, in draw space, to draw the furniture at

overrideColor System.Nullable<Microsoft.Xna.Framework.Color>
An optional color to override the default colors of the furniture

rotation MLEM.Misc.Direction2
The rotation of the furniture

colors System.Int32[]
The colors to draw the furniture with

drawScale System.Single
The scale to draw the furniture with

pivot System.Boolean
Whether or not to move the furniture by its texture's pivot point

parent Furniture
The object that this furniture is latched on to, or null if there is none

parentSpot AbstractSpot
The object spot that this furntiture is in, or null if there is none

depthOffset System.Single
A value that is added onto the calculated depth of the object

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

Furniture.Draw(GameTime, SpriteBatch, Vector2, Nullable<Color>) Method

Draws this object on the current Map, at the current Position.

public sealed override void Draw(Microsoft.Xna.Framework.GameTime time, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, Microsoft.Xna.Framework.Vector2 drawPos, System.Nullable<Microsoft.Xna.Framework.Color> overrideColor);

Parameters

time Microsoft.Xna.Framework.GameTime
The current time

batch Microsoft.Xna.Framework.Graphics.SpriteBatch
The sprite batch to use for drawing

drawPos Microsoft.Xna.Framework.Vector2
The position, in draw space, to draw this furniture at

overrideColor System.Nullable<Microsoft.Xna.Framework.Color>
The color that should be used instead of this object's actual color. If null, the object's regular color should be used.

Furniture.DrawUi(GameTime, SpriteBatch, Element, float, int[]) Method

Draws this furniture in a ui context, rather than a world context.
Scale is determined based on the element that is passed.

public void DrawUi(Microsoft.Xna.Framework.GameTime time, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, MLEM.Ui.Elements.Element element, float drawScale, int[] colors);

Parameters

time Microsoft.Xna.Framework.GameTime
The current game time

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

element MLEM.Ui.Elements.Element
The element to calculate scaling based on

drawScale System.Single
The scale to draw the furniture with

colors System.Int32[]
The colors to draw the furniture with

Furniture.GetActionSpotInfo(Person, ActionSpot, Direction2) Method

Returns a ActionInfo that corresponds to the given ActionSpot and rotation

public TinyLife.Actions.ActionInfo GetActionSpotInfo(TinyLife.Objects.Person person, TinyLife.Objects.ActionSpot spot, MLEM.Misc.Direction2 direction=MLEM.Misc.Direction2.None);

Parameters

person Person
The person to query free action spots for

spot ActionSpot
The action spot to return an info for

direction MLEM.Misc.Direction2
The direction to offset the ActionLocation by. Defaults to MLEM.Misc.Direction2.None.

Returns

ActionInfo
A new action info with the given settings

Furniture.GetAiPriority(Person, ObjectCategory) Method

Returns an integer that represents a priority for the PersonAi's interaction with this object.
A higher priority means that this object will be picked over other objects (with lower priority).
The default return value is 0, meaning that no special priority is assigned to this object.
For any Furniture with the Bed category that is the person's LastBedSleptIn, 10 is returned.

public override int GetAiPriority(TinyLife.Objects.Person person, TinyLife.Objects.ObjectCategory categories);

Parameters

person Person
The person whose AI is attempting to interact with this object

categories ObjectCategory
The categories that are relevant for the ai interaction

Returns

System.Int32
This object's priority

Furniture.GetCategories(Person) Method

Returns a set of ObjectCategory flags that this object has, based on the given Person.

public sealed override TinyLife.Objects.ObjectCategory GetCategories(TinyLife.Objects.Person person);

Parameters

person Person
The person to query categories for

Returns

ObjectCategory
A set of categories that this object has

Furniture.GetChildren<T>() Method

Returns a list of all of the children of this furniture.
Children are all furnitures in the world that have their ParentFurniture set to this furniture instance.

public System.Collections.Generic.IEnumerable<T> GetChildren<T>()
    where T : TinyLife.Objects.MapObject;

Type parameters

T

Returns

System.Collections.Generic.IEnumerable<T>
A list of this furniture's children

Furniture.GetDescription() Method

Returns a set of lines that are displayed in build mode when this furniture is hovered over, either in the buy menu or in the FurnitureStorage.
By default, info about Reliability and ElectricityRating is returned.

public virtual System.Collections.Generic.IEnumerable<string> GetDescription();

Returns

System.Collections.Generic.IEnumerable<System.String>
A set of description lines for this furniture item

Furniture.GetFreeActionSpot(Person, ObjectCategory) Method

Returns the first free action spot from GetFreeActionSpots(Person, ObjectCategory).

public (TinyLife.Objects.ActionSpot,MLEM.Misc.Direction2) GetFreeActionSpot(TinyLife.Objects.Person person, TinyLife.Objects.ObjectCategory context=null);

Parameters

person Person
The person to query free action spots for

context ObjectCategory
The object category that this action spot needs to have

Returns

<ActionSpot,MLEM.Misc.Direction2>
A free action spot and the direction it's free in, or an empty tuple if there is no free action spot

Furniture.GetFreeActionSpotInfo(Person, ObjectCategory) Method

Returns the first free action spot, packed into an ActionInfo.

public override TinyLife.Actions.ActionInfo GetFreeActionSpotInfo(TinyLife.Objects.Person person, TinyLife.Objects.ObjectCategory context=null);

Parameters

person Person
The person to query free action spots for

context ObjectCategory
The object category that this action spot needs to have

Returns

ActionInfo
The first free action spot as an ActionInfo

Furniture.GetFreeActionSpots(Person, ObjectCategory) Method

Returns a list of ActionSpot instances that are part of this furniture, which are considered free.
Free, in this instance, is any spot that has the given category and is not currently occupied by another person.

public System.Collections.Generic.IEnumerable<(TinyLife.Objects.ActionSpot,MLEM.Misc.Direction2)> GetFreeActionSpots(TinyLife.Objects.Person person, TinyLife.Objects.ObjectCategory context);

Parameters

person Person
The person to query free action spots for

context ObjectCategory
The object category that this action spot needs to have

Returns

System.Collections.Generic.IEnumerable<<ActionSpot,MLEM.Misc.Direction2>>
A set of action spots and the directions which they're free in

Furniture.GetFreeObjectSpot(FurnitureType, Nullable<Vector2>) Method

Returns the first free ObjectSpot on this furniture.
Free, in this case, is any object spot that isn't already occupied by a different furniture.

public TinyLife.Objects.ObjectSpot GetFreeObjectSpot(TinyLife.Objects.FurnitureType type, System.Nullable<Microsoft.Xna.Framework.Vector2> position=null);

Parameters

type FurnitureType
The furniture type to find a free object spot for

position System.Nullable<Microsoft.Xna.Framework.Vector2>
The position that the object spot should be closest too. If null, no position will be preferred. Defaults to null.

Returns

ObjectSpot
A free object spot, or null if there is none

Furniture.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 virtual float GetPrice();

Returns

System.Single
The object's price

Implements GetPrice()

Furniture.GetVisibility() Method

Returns the visibility settings of this object.
By default, WhenVisible is returned.
For Furniture, its Visibility is returned instead.

public override TinyLife.Objects.Visibility GetVisibility();

Returns

Visibility
This object's visibility settings

Furniture.Intersects(RectangleF) Method

Returns whether this map object intersects with the given rectangle.
This is used for GetObjects<T>(RectangleF)

public override bool Intersects(MLEM.Misc.RectangleF rectangle);

Parameters

rectangle MLEM.Misc.RectangleF
The area that should be checked for

Returns

System.Boolean
true if this object intersects with the given rectangle

Furniture.NotifyNeighbors() Method

Notifies all of the neighboring Furniture objects of a change by calling their OnNeighborChanged(Furniture) methods.
This is used by things like fences, which change their orientation if their neighbors are added or removed.

public void NotifyNeighbors();

Furniture.OnActionCompleted(Action, CompletionType, bool) Method

This method is called when an Action that this object is involved in is completed.
This object counts as involved in the action if its ActionInfo's GetInvolvedObjects<T>(ObjectCategory, bool) includes this object.
By default, this method does nothing.

public override void OnActionCompleted(TinyLife.Actions.Action action, TinyLife.Actions.Action.CompletionType type, bool isAuxiliary);

Parameters

action Action
The action

type CompletionType
The type of the action's completion

isAuxiliary System.Boolean
Whether this object counts as an auxiliary object. If this value is false, the object is th eGetActionObject<T>()

Furniture.OnAdded() Method

This method is called when this object is added to a Map.
By default, it does nothing.

public override void OnAdded();

Furniture.OnNeighborChanged(Furniture) Method

This method gets called when any neighboring furniture changes. The neighboring furniture is passed.
By default, this method does nothing, so calling base is not necessary.

protected virtual void OnNeighborChanged(TinyLife.Objects.Furniture neighbor);

Parameters

neighbor Furniture
The neighbor furniture that changed

Furniture.OnRemoved() Method

This method is called when this object is removed from a Map.
By default, it does nothing.

public override void OnRemoved();

Furniture.RemoveChildren<T>(Predicate<T>) Method

Removes all of the children from this furniture that match the given predicate.
Children are all furnitures in the world that have their ParentFurniture set to this furniture instance.

public System.Collections.Generic.IEnumerable<T> RemoveChildren<T>(System.Predicate<T> predicate=null)
    where T : TinyLife.Objects.Furniture;

Type parameters

T
The type of children to remove

Parameters

predicate System.Predicate<T>
The predicate to check children against. If null, all children will be removed.

Returns

System.Collections.Generic.IEnumerable<T>
The children that were removed from this furniture

Furniture.SetChild(ObjectSpot, Furniture, Direction2) Method

Sets the child element in the given object spot to the given furniture and adds it to this furniture's Map.
If there are already children in the given object spot, those are removed prior to adding the new child.

public void SetChild(TinyLife.Objects.ObjectSpot spot, TinyLife.Objects.Furniture item, MLEM.Misc.Direction2 rotation);

Parameters

spot ObjectSpot
The spot to add the child to

item Furniture
The furniture to add to the spot

rotation MLEM.Misc.Direction2
The desired rotation of the child furniture

Furniture.SetChild(ObjectSpot, FurnitureType, Direction2, int[], Nullable<Guid>) Method

Sets the child element in the given object spot to the given furniture and adds it to this furniture's Map.
If there are already children in the given object spot, those are removed prior to adding the new child.

public void SetChild(TinyLife.Objects.ObjectSpot spot, TinyLife.Objects.FurnitureType type, MLEM.Misc.Direction2 rotation, int[] colors=null, System.Nullable<System.Guid> id=null);

Parameters

spot ObjectSpot
The spot to add the child to

type FurnitureType
The type of furniture to construct as the child

rotation MLEM.Misc.Direction2
The desired rotation of the child furniture

colors System.Int32[]
The colors that the child should have

id System.Nullable<System.Guid>
The id that the child should have, random by default

Furniture.SetParent(Furniture, ObjectSpot) Method

Sets the parent of this furniture, changing its Position and settings its ParentObjectSpot value.
Note that this does not add the object to the map (AddObject(MapObject)).
When modifying furniture in the world, it is preferred to use SetChild(ObjectSpot, Furniture, Direction2) on the parent furniture instead.

public void SetParent(TinyLife.Objects.Furniture parent, TinyLife.Objects.ObjectSpot spot);

Parameters

parent Furniture
The parent furniture to slot into

spot ObjectSpot
The object spot to slot into

Furniture.Validate() Method

This method is called when this object is loaded from disk.
Returning false on this method causes the object to be removed from the map.
By default, this method invokes OnValidated and OnEventsAttachable.

public override bool Validate();

Returns

System.Boolean
false if the object is not valid, true otherwise