Class GameImpl
- Namespace
- TinyLife
- Assembly
- TinyLife.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.InitializeUiSystem(UiStyle)MlemGame.InitializeInputHandler()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
BuildModeTimeOverride
A 24-hour-based time that is currently being displayed in the game over the actual TinyLife.GameImpl.CurrentGlobalTime. This can be set to change the lighting currently used in build mode.
public float? BuildModeTimeOverride
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
ActualCurrentTool
Returns the underlying tool that is actually opened, even if CurrentTool currently returns RemoveTool. In most situations, querying CurrentTool is preferred, as it represents the tool that is currently being displayed to the player.
public Tool ActualCurrentTool { get; }
Property Value
ActualSpeed
public GameSpeed ActualSpeed { get; }
Property Value
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
The current maximum floor that can be viewed by the player. The maximum viewable floor is determined by the maximum MaxFloor of the currently visible Lot instances.
public int CurrentMaxFloor { get; }
Property Value
CurrentMinFloor
The current minimum floor that can be viewed by the player. The minimum viewable floor is determined by the minimum MinFloor of the currently visible Lot instances.
public int CurrentMinFloor { get; }
Property Value
CurrentTool
Returns the Tool that is currently being displayed. Should always be set to either PlayModeTool or any of BuildTools. Note that, if the player is holding CTRL while in build mode, the RemoveTool will be returned instead of the tool that is really opened, in which case the latter can still be queried by using ActualCurrentTool.
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 (or VeryFastLimited) and the game CanBeExtremelyFast(), ExtremelyFast (or ExtremelyFastLimited) 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 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(MapInfo info, Action after = null)
Parameters
infoMapInfoThe info of the map to load and add.
afterActionAn 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 (or VeryFastLimited), the ExtremelyFast (or ExtremelyFastLimited) speed is automatically engaged.
public bool CanBeExtremelyFast()
Returns
- bool
Whether the game can become extremely fast
CanSwitchGameModes(bool)
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(bool includeLotRequirements = true)
Parameters
includeLotRequirementsboolWhether lot requirements should also be checked through AreRequirementsMet(). Note that this parameter is ignored while in the PlayModeTool, where lot requirements are never checked.
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
typeAchievementTypeThe type of achievement to complete.
Returns
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposingbool
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
gameTimeGameTimeThe 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
gameTimeGameTimeThe game's time
FollowPerson(PersonLike, bool, Action)
Causes the camera to follow the given person, optionally switching to the map the person is on.
public bool FollowPerson(PersonLike person, bool switchToMap = true, Action additionalAction = null)
Parameters
personPersonLikeThe person to follow.
switchToMapboolWhether to switch to the map the person is on.
additionalActionActionAn 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
switchToMapis false and the person's Map doesn't match the CurrentMap, or if the ui system IsTransitioning() while trying to switch the active map.
GetOwningSet(string)
Returns the Set that the object with the given name originated from, based on the detection of a prefix that matches a set name.
public static Set? GetOwningSet(string objectName)
Parameters
objectNamestringThe name of the object whose set to return.
Returns
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
lotLotThe 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
lotLotThe 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
lotLotThe 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
mapMapThe map to remove.
RotateCamera(bool)
Rotates the camera by 90 degrees in a clockwise or counter-clockwise direction.
public void RotateCamera(bool ccw)
Parameters
ccwboolWhether 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
mapMapThe map to change to.
inbetweenActionAn optional inbetween action, which is passed to Transition(Action, Action, TransitionType, TransitionType, float, float, float, Color?).
afterActionAn 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
sizePointThe size, in pixels, of the resulting screenshots
visibleAreaRectangleF?The area that should be marked as visible, in world space. This determines culling values.
visibleMatrixMatrix?A matrix that has a translation and scale that determines the visible area of the screenshot
lightmapRenderTarget2DThe light map to draw light onto, or null to use the default light map
ZoomCamera(float)
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(float delta)
Parameters
deltafloatThe 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). In the Post phase, the new game mode has already been applied.
public event Action<(GameImpl.GameMode PrevMode, GameImpl.GameMode Mode, EventPhase Phase)> OnSwitchGameMode