Skip to main content

GameModeManager

A static class in Root.Township, the global namespace.

Static owner of the current GameMode: hosting a server, joining one, or a local test. Starts, swaps and stops modes, and handles the hold Ctrl+Q to quit key. Both sides.

Fields​

6 private and internal fields
MemberWhat it is
private static GameServerInfo currentGameServerInfoBacking field for CurrentGameServerInfo.
private static GameMode currentModeBacking field for CurrentMode.
private static Logger loggerNLog logger for this class.
private static readonly Key[] quitKeysThe quit key combination: Q and Left Ctrl.
private static IKeyBoardTriggerHandler triggerHandlerHandle for the registered quit key press, removed when the mode stops.
private static readonly Lazy<IValidVersionService> validVersionServiceLazily resolved version check service.

Properties​

MemberWhat it is
static GameServerInfo CurrentGameServerInfo { get; }The server last joined through JoinServer or a deep link. Not cleared when the mode stops.
static GameMode CurrentMode { get; }The active game mode, or null when none is running.

Events​

MemberWhat it is
static event Action ModeChangedRaised when a mode starts or stops.

Methods​

MemberWhat it is
static async Task<bool> JoinServer(GameServerInfo server)Client: checks the version, then starts a JoinedServerGameMode for the given server.
static async Task<bool> JoinServerFromServerViaDeeplink(GameServerInfo server)Checks the version, stops the current mode without returning to the menu, unloads the game scene and joins the deep link server.
static async Task<bool> StartLocalTest(IServerAccess server = null)Starts a LocalTestGameMode on the given server access, or the local one from MenuSettings.
static async Task<bool> StartServer(IServerAccess server, bool isHeadless, bool isExternalLaunch = false, int port = 1757, bool isRunningLocally = true)Starts a ServerHostingGameMode for the given server, headless flag and port (1757 by default).
static async Task StopCurrentModeAsync(string reason, bool isReturningToMenu = true)Stops the current mode. Unless quitting, then returns to the main menu, or on a headless server quits after 10 seconds.
8 private and internal methods
MemberWhat it is
private static async void CheckQuitKeyDuration(Key key)Counts down while Q and Left Ctrl are held, and after 5 seconds stops the current mode and returns to the menu.
private static async Task<bool> IsClientVersionUpToDate()Checks the version with IValidVersionService and shows an update popup if it isn't valid.
private static bool IsGameQuitKeyCombinationPressed()True while both Q and Left Ctrl are held.
private static void OnGameModeStarted(GameMode gameMode)Tells the mode it started, registers the quit key and raises ModeChanged.
private static void OnGameModeStartFailed(GameMode gameMode)Tells the mode it failed and fades the screen back in.
private static void OnModeChanged()Raises ModeChanged.
private static async Task<bool> StartGameModeAsync(GameMode newMode)Activates a new mode and makes it current if it started. Fails if a mode is already active.
private static async Task<bool> SwapGameMode(GameMode newMode)Stops the current mode, unloads the game scene and starts the new mode. Used for deep link joins.