MapObject - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life

TinyLife.Objects

MapObject Class

An instance of this class represents an object that can be, or is, part of a Map.
If this object's Position is set to -1, -1, that is usually an indicator that the object is currently not in the world.

public class MapObject : MLEM.Misc.GenericDataHolder

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

Derived
Car
Furniture
Person

Constructors

MapObject.MapObject(Guid, Map, Vector2) Constructor

Creates a new map object with the given settings

public MapObject(System.Guid id, TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 position);

Parameters

id System.Guid
The object's id

map Map
The map the object should be on

position Microsoft.Xna.Framework.Vector2
The position that the object should have

Fields

MapObject.PersonRotationOrder Field

The order of MLEM.Misc.Direction2 that the texture atlas for Person has for its textures, from left to right

public static readonly Direction2[] PersonRotationOrder;

Field Value

MLEM.Misc.Direction2[]

Properties

MapObject.CurrentLot Property

A property that returns the CurrentLot that this object is currently on

public TinyLife.World.Lot CurrentLot { get; }

Property Value

Lot

MapObject.Id Property

The System.Guid of this object instance

public System.Guid Id { get; set; }

Property Value

System.Guid

MapObject.IsInWorld Property

A property that returns true if this object is currently present on a Map

public bool IsInWorld { get; }

Property Value

System.Boolean

MapObject.Map Property

The map that this object is currently on.
If this is null, the object is not currently on a map.

public TinyLife.World.Map Map { get; set; }

Property Value

Map

MapObject.Position Property

The position on the Map of this object.
If this is set to -1, -1, that is usually an indicator that the object is currently not in the world.

public virtual Microsoft.Xna.Framework.Vector2 Position { get; set; }

Property Value

Microsoft.Xna.Framework.Vector2

Methods

MapObject.ActionUpdate(Action, GameTime, TimeSpan, GameSpeed, bool) Method

This method is called when an Action that this object is involved in updates, which is every Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime) frame.
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 virtual void ActionUpdate(TinyLife.Actions.Action action, Microsoft.Xna.Framework.GameTime time, System.TimeSpan passedInGame, TinyLife.GameSpeed speed, bool isAuxiliary);

Parameters

action Action
The action

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

passedInGame System.TimeSpan
The amount of time that has passed, in game time

speed GameSpeed
The game's current speed setting

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

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

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

public virtual 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.

MapObject.DrawColumns(Map, Vector2, SpriteBatch, Vector2, TextureRegion, Color, float, Point, bool, Furniture, AbstractSpot, Direction2, float, bool, bool, bool, bool, bool) Method

Draws the given texture region in columns, which allows for depth calculation in isometric view to be possible.
Bigger objects, including all furniture, are drawn in this matter.

public static void DrawColumns(TinyLife.World.Map map, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, Microsoft.Xna.Framework.Vector2 drawPos, MLEM.Textures.TextureRegion texture, Microsoft.Xna.Framework.Color color, float scale, Microsoft.Xna.Framework.Point size, bool pivot=true, TinyLife.Objects.Furniture parent=null, TinyLife.Objects.AbstractSpot parentSpot=null, MLEM.Misc.Direction2 rotation=MLEM.Misc.Direction2.None, float depthOffset=0f, bool mirror=false, bool wallHanging=false, bool groundItem=false, bool ceilingHanging=false, bool editDrawPos=true);

Parameters

map Map
The map that the object is on

position Microsoft.Xna.Framework.Vector2
The position that the object is on, in world space

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

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

texture MLEM.Textures.TextureRegion
The texture region to draw

color Microsoft.Xna.Framework.Color
The color to draw with

scale System.Single
The scale to draw at

size Microsoft.Xna.Framework.Point
The size, in tiles, that this object has

pivot System.Boolean
The texture's pivot point, in texture-space pixels

parent Furniture
The object's parent object

parentSpot AbstractSpot
The object's parent spot

rotation MLEM.Misc.Direction2
The rotation that this object has, used for some calculations

depthOffset System.Single
A value that is added to the calculated object's depth

mirror System.Boolean
Whether or not to mirror the texture

wallHanging System.Boolean
Whether or not this object is hanging on a wall

groundItem System.Boolean
Whether or not this item is considered a ground item (that doesn't have any collisions)

ceilingHanging System.Boolean
Whether this object is hanging on the ceiling. If it is, its drawPos is offset by the height of walls

editDrawPos System.Boolean
Whether this object's drawPos should be changed based on this object's circumstances, especially based on its parentSpot

MapObject.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 virtual 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

MapObject.GetCategories(Person) Method

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

public virtual 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

MapObject.GetFreeActionSpotInfo(Person, ObjectCategory) Method

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

public virtual 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

MapObject.GetHoverInfo() Method

Returns a MLEM.Ui.Elements.Tooltip object that is displayed whenever the mouse is hovered over this object in the world.
By default, this method returns null, which will cause no tooltip to be displayed.

public virtual MLEM.Ui.Elements.Tooltip GetHoverInfo();

Returns

MLEM.Ui.Elements.Tooltip
The tooltip to display

MapObject.GetModCategory(string) Method

Adds and returns a custom ObjectCategory with the given name.
The returned category is guaranteed to be unique and mapped to the given name. Additionally, it can be used in combined flags, as it is not a combined flag itself.

public static TinyLife.Objects.ObjectCategory GetModCategory(string name);

Parameters

name System.String
The name that the category should have

Returns

ObjectCategory
A new object category

MapObject.GetVisibility() Method

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

public virtual TinyLife.Objects.Visibility GetVisibility();

Returns

Visibility
This object's visibility settings

MapObject.HasCategory(Person, ObjectCategory) Method

A shorthand that checks whether GetCategories(Person) overlaps with the given category flags

public bool HasCategory(TinyLife.Objects.Person person, TinyLife.Objects.ObjectCategory category);

Parameters

person Person
The person to query categories for

category ObjectCategory
A set of categories, one of which this object needs to match

Returns

System.Boolean
Whether this object contains at least one of the given categories

MapObject.Intersects(RectangleF) Method

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

public virtual 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

MapObject.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 virtual 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>()

MapObject.OnAdded() Method

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

public virtual void OnAdded();

MapObject.OnCameraRotationChanged(Direction2, Direction2) Method

This method is invoked when the game's camera rotation changes.
Additionally, the old and new rotations are passed.

public virtual void OnCameraRotationChanged(MLEM.Misc.Direction2 oldRotation, MLEM.Misc.Direction2 newRotation);

Parameters

oldRotation MLEM.Misc.Direction2
The old camera rotation

newRotation MLEM.Misc.Direction2
The new camera rotation

MapObject.OnRemoved() Method

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

public virtual void OnRemoved();

MapObject.SetMapAndValidate(Map) Method

This method is the same as Validate(), but it also sets the Map.

public bool SetMapAndValidate(TinyLife.World.Map map);

Parameters

map Map
The map to set

Returns

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

MapObject.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 virtual bool Validate();

Returns

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

Events

MapObject.OnCreated Event

An event that is invoked when a map object is created.
This event is invoked in the MapObject constructor.

public static event OnCreated;

Event Type

System.Action<MapObject>

MapObject.OnDraw Event

An event that is invoked when this object is drawn, right after Draw(GameTime, SpriteBatch, Vector2, Nullable<Color>) is called.
This event can be subscribed to using OnEventsAttachable.

public event OnDraw;

Event Type

DrawDelegate(GameTime, SpriteBatch, Vector2, Nullable<Color>)

MapObject.OnEventsAttachable Event

An event that is invoked when non-static events for an object are ready to be attached to.
This event is invoked in the MapObject constructor, and in the Validate() method.

public static event OnEventsAttachable;

Event Type

System.Action<MapObject>

MapObject.OnUpdate Event

An event that is invoked when this object is updated, right after Microsoft.Xna.Framework.IUpdateable.Update(Microsoft.Xna.Framework.GameTime) is called.
Note that, if this object does not extend Microsoft.Xna.Framework.IUpdateable, this event is not invoked.
This event can be subscribed to using OnEventsAttachable.

public event OnUpdate;

Event Type

UpdateDelegate(GameTime, TimeSpan, GameSpeed, EventPhase)

MapObject.OnValidated Event

An event that is invoked when a map object is validated.
This event si invoked in Validate(), which is usually called after subclass validation.

public static event OnValidated;

Event Type

System.Action<MapObject>