Class GameImpl
- Namespace
- TinyLife
- Assembly
- Tiny Life.dll
The main class for Tiny Life, which houses a set of important game-wide properties.
public class GameImpl : MlemGame, IDisposable
- Inheritance
-
GameMlemGameGameImpl
- Implements
- Inherited Members
-
MlemGame.GraphicsDeviceManagerMlemGame.Update(GameTime)MlemGame.Draw(GameTime)MlemGame.InitializeDefaultUiStyle(SpriteBatch)MlemGame.InputMlemGame.SpriteBatchMlemGame.InputHandlerMlemGame.UiSystemMlemGame.OnLoadContentMlemGame.PreUpdateMlemGame.OnUpdateMlemGame.PreDrawMlemGame.OnDrawGame.Dispose()Game.Exit()Game.ResetElapsedTime()Game.SuppressDraw()Game.RunOneFrame()Game.Run()Game.Run(GameRunBehavior)Game.Tick()Game.BeginDraw()Game.EndDraw()Game.BeginRun()Game.EndRun()Game.UnloadContent()Game.Initialize()Game.LaunchParametersGame.ComponentsGame.InactiveSleepTimeGame.MaxElapsedTimeGame.IsActiveGame.IsMouseVisibleGame.TargetElapsedTimeGame.IsFixedTimeStepGame.ServicesGame.ContentGame.GraphicsDeviceGame.WindowGame.ActivatedGame.DeactivatedGame.DisposedGame.Exiting
- Extension Methods
Fields
Achievements
A set of Achievement instances being tracked on this map. Achievements are automatically added to this collection if they are registered as AchievementType instances. To complete an achievement that doesn't have any goals manually, use CompleteAchievement(AchievementType).
public readonly HashSet<Achievement> Achievements
Field Value
CurrentCursor
The CursorType that is currently used. This is reset to Default at the start of every update.
public CursorType CurrentCursor
Field Value
Version
The game's version, gathered from the assembly
public static readonly NuGetVersion Version
Field Value
- NuGetVersion
Properties
Camera
The game's in-world camera, created in LoadContent()
public Camera Camera { get; }
Property Value
- Camera
CurrentHousehold
The household that is currently being played, or null if in the main menu, editing a lot or on the map select screen
public Household CurrentHousehold { get; }
Property Value
CurrentLot
The lot that is currently being played on or edited, or null if in the main menu or on the map select screen
public Lot CurrentLot { get; }
Property Value
CurrentMap
The map that the game's Camera is currently on. If no maps are loaded (ie we're not in game), this property returns null.
public Map CurrentMap { get; }
Property Value
CurrentMaps
The maps that are currently loaded, along with their names. If no maps are loaded (ie we're not in game), this collection is null.
public Dictionary<string, Map> CurrentMaps { get; }
Property Value
CurrentMaxFloor
public int CurrentMaxFloor { get; }
Property Value
CurrentMinFloor
public int CurrentMinFloor { get; }
Property Value
CurrentTool
The Tool that is currently selected. Should always be set to either PlayModeTool or any of BuildTools.
public Tool CurrentTool { get; set; }
Property Value
CursorPosition
The position that the game's cursor is currently at. If gamepad controls are being used, an internal cursor position is returned. Otherwise, MLEM.Input.InputHandler.MousePosition is returned.
public Vector2 CursorPosition { get; }
Property Value
- Vector2
FollowingPerson
The PersonLike that the camera is currently locked onto
public PersonLike FollowingPerson { get; }
Property Value
GraphicsMetrics
The game's graphics metrics, gathered at the end of every DoDraw(GameTime) call
public GraphicsMetrics GraphicsMetrics { get; }
Property Value
- GraphicsMetrics
Instance
The game's singleton instance
public static GameImpl Instance { get; }
Property Value
Listener
The game's Microsoft.Xna.Framework.Audio.AudioListener that is automatically moved to the Camera's position
public AudioListener Listener { get; }
Property Value
- AudioListener
Mode
The GameImpl.GameMode that is currently active
public GameImpl.GameMode Mode { get; }
Property Value
Money
The money that the CurrentHousehold has, or MaxValue if there is no active household
public float Money { get; set; }
Property Value
SaveName
The name of the save file that is currently being played, or null if in the main menu
public string SaveName { get; }
Property Value
Speed
The current GameSpeed. Note that, if the current speed is VeryFast and the game CanBeExtremelyFast(), ExtremelyFast is returned. You can cause any ui MLEM.Ui.RootElement instances to pause the game by using SetPauseGame(RootElement, bool).
public GameSpeed Speed { get; set; }
Property Value
Methods
AddMapToSave(MapInfo, Action)
Adds a map with the given PerSaveOptions.MapInfo to the currently active save game, additionally invoking all required events. This method causes a loading screen to appear, so its actions are not invoked immediately.
public void AddMapToSave(PerSaveOptions.MapInfo info, Action after = null)
Parameters
info
PerSaveOptions.MapInfoThe info of the map to load and add.
after
ActionAn action that is invoked after the map has been added successfully, and after the loading screen has been removed.
CanBeExtremelyFast()
Returns whether the game allows changing the speed to ExtremelyFast at the current time. If this returns true, and Speed is set to VeryFast, the ExtremelyFast speed is automatically engaged.
public bool CanBeExtremelyFast()
Returns
- bool
Whether the game can become extremely fast
CanSwitchGameModes()
Returns whether the game mode of the game can currently be switched. This method checks the CharacterCreator if it is active, as well as the CurrentTool and the CurrentLot's requirements.
public bool CanSwitchGameModes()
Returns
- bool
Whether the game can currently switch game modes.
CompleteAchievement(AchievementType)
Completes the achievement in this map's Achievements collection with the given AchievementType.
public bool CompleteAchievement(AchievementType type)
Parameters
type
AchievementTypeThe type of achievement to complete.
Returns
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
DoDraw(GameTime)
This method is called in MLEM.Startup.MlemGame.Draw(Microsoft.Xna.Framework.GameTime). It is the version that should be overridden by implementors to draw game content.
protected override void DoDraw(GameTime gameTime)
Parameters
gameTime
GameTimeThe game's time
DoUpdate(GameTime)
This method is called in MLEM.Startup.MlemGame.Update(Microsoft.Xna.Framework.GameTime). It is the version that should be overridden by implementors to update game content.
protected override void DoUpdate(GameTime gameTime)
Parameters
gameTime
GameTimeThe game's time
FadeKeyboardLighting(Color)
Fades the keyboard lighting at a constant speed to make it result in the passed color. This method only has an effect if the game is running on desktop, and the user has a lighting-capable keyboard.
public void FadeKeyboardLighting(Color newColor)
Parameters
newColor
ColorThe color to fade to; transparency is ignored
FollowPerson(PersonLike, bool, Action)
Causes the camera to follow the given person
, optionally switching to the map the person is on using SwitchMap(Map, Action, Action).
public bool FollowPerson(PersonLike person, bool switchToMap = true, Action additionalAction = null)
Parameters
person
PersonLikeThe person to follow.
switchToMap
boolWhether to switch to the map the person is on.
additionalAction
ActionAn optional additional action that should be invoked when the camera is moved, which is passed to Transition(Action, Action, TransitionType, TransitionType, float, float, float, Color?) when switching maps, or invoked immediately when not switching maps.
Returns
- bool
Whether following the person was successful, which is false if
switchToMap
is false and the person's Map doesn't match the CurrentMap, or if the ui system IsTransitioning() while trying to switch the active map.
IsCursorOnUi()
Returns true if the mouse is currently on top of any ui element in the MLEM.Ui.UiSystem or the system's auto-navigation cursor is currently being used.
public bool IsCursorOnUi()
Returns
- bool
true if the cursor is currently on the ui.
IsLotVisible(Lot)
Returns whether the given lot is considered visible to the player. Note that passing the CurrentHousehold's Lot will always cause this method to return true.
public bool IsLotVisible(Lot lot)
Parameters
lot
LotThe lot to query
Returns
- bool
Whether the lot is visible
LoadContent()
Override this to load graphical resources required by the game.
protected override void LoadContent()
MarkLotNonVisible(Lot)
Marks a lot non-visible if it's currently visible to the player.
public void MarkLotNonVisible(Lot lot)
Parameters
lot
LotThe lot to remove visibility for
MarkLotVisible(Lot)
Marks the given lot as visible for the player. The method VisitLot(Lot) should be used in favor of this method in most cases. By default, visibility lasts for 30 seconds of real time.
public void MarkLotVisible(Lot lot)
Parameters
lot
LotThe lot to mark as visible
RemoveMapFromSave(Map)
Removes the given Map from the currently active save game, additionally causing its PrepareForPermanentRemoval() method to be invoked.
public void RemoveMapFromSave(Map map)
Parameters
map
MapThe map to remove.
RotateCamera(bool)
Rotates the camera by 90 degrees in a clockwise or counter-clockwise direction.
public void RotateCamera(bool ccw)
Parameters
ccw
boolWhether the rotation should be counter-clockwise.
SwitchGameMode(GameMode)
Switches the game mode to the given mode, and sets up all of the required data. Note that some game modes require certain data to be set prior to calling this method.
public void SwitchGameMode(GameImpl.GameMode mode)
Parameters
SwitchMap(Map, Action, Action)
Switches the game's CurrentMap to the given map, additionally displaying a transition and resetting various UI states. OnCurrentGameMapChanged(Map, Map) is also invoked.
public void SwitchMap(Map map, Action inbetween = null, Action after = null)
Parameters
map
MapThe map to change to.
inbetween
ActionAn optional inbetween action, which is passed to Transition(Action, Action, TransitionType, TransitionType, float, float, float, Color?).
after
ActionAn optional after action, which is passed to Transition(Action, Action, TransitionType, TransitionType, float, float, float, Color?).
TakeScreenshot(Point, RectangleF?, Matrix?, RenderTarget2D)
Takes a screenshot and stores it in the default location, using a file name that contains the current date and time
public void TakeScreenshot(Point size, RectangleF? visibleArea = null, Matrix? visibleMatrix = null, RenderTarget2D lightmap = null)
Parameters
size
PointThe size, in pixels, of the resulting screenshots
visibleArea
RectangleF?The area that should be marked as visible, in world space. This determines culling values.
visibleMatrix
Matrix?A matrix that has a translation and scale that determines the visible area of the screenshot
lightmap
RenderTarget2DThe light map to draw light onto, or null to use the default light map
ZoomCamera(int)
Zooms the camera by the given delta
, either towards the center of the camera's viewport, or toward the CursorPosition if it is not on the UI.
public void ZoomCamera(int delta)
Parameters
delta
intThe delta to zoom by.
Events
OnFinalizingGameContent
An event that is raised when this game's content is about to finish loading. Note that "finalize" in this context refers not to object destruction, but to the completion of the loading process.
public event Action OnFinalizingGameContent
Event Type
OnFinishedLoading
An event that is raised when the game's loading screen fades out.
public event Action OnFinishedLoading
Event Type
OnSwitchGameMode
An event that is raised in SwitchGameMode(GameMode).
public event Action<GameImpl.GameMode, EventPhase> OnSwitchGameMode