Skip to main content

MapManager

A class in Root.Township, Alta.Map.

Tracks which map pieces each player has discovered, either one shared map for everyone or a map per player saved in player data. Singleton MapManager.Instance; the server loads and saves, clients keep one local copy.

Constructors​

MemberWhat it is
MapManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

7 private and internal fields
MemberWhat it is
private bool isUsingSharedMapBacking field for IsUsingSharedMap.
private static Logger loggerLogger for this class; discovery is logged at Info.
private Dictionary<IPlayer, PlayerMapManager> managersServer: map manager for each player, when maps are not shared.
private PlayerMapManager singleManagerThe shared map on the server, or the local player's map on a client.
private MethodSyncClass<PlayerMapManager> syncMapManagerMethod sync (SyncA) for the whole map.
private MethodSyncStruct<MapManager.MapPieceIdentifier> syncPieceDiscoveryMethod sync (SyncB) for one discovered piece.
private IUnityUpdateMethod updateMovingLandmarksUpdate handle; not used in this class.

Properties​

MemberWhat it is
static MapManager Instance { get; private set; }The active map manager.
bool IsUsingSharedMap { get; }Whether all players share one map.

Methods​

MemberWhat it is
async void DiscoverPiece(IPlayer player, Map map, int pieceIndex)Server: marks a map piece found for the player and sends it to everyone (shared map) or just that player.
async Task<PlayerMapManager> GetMapManager(IPlayer player)Gets the shared map manager, or loads the player's own one from their map save file.
PlayerMapManager GetSharedManager()Returns the single manager: the shared map on the server, or the local map on a client.
override async void Initialize()Creates the syncs; the server loads the shared map or the host player's map, and clients start with an empty map.
override async void OnConnected(Player player)Server: loads the player's map (or uses the shared one) and sends it to them.
override async void OnDisconnected(Player player)Server: writes and unloads the player's map save file and forgets their manager.
4 private and internal methods
MemberWhat it is
private void Awake()Sets Instance, or destroys itself if another one exists.
private async Task<PlayerMapManager> SetupPlayer(IPlayer player)Server: loads a player's map save file and stores a manager for them.
private void SyncMapManager(IPlayer player, Stream stream, PlayerMapManager manager)Sends a whole map manager; clients read it into their single local manager.
private void SyncPieceDiscovery(IPlayer player, Stream stream, MapManager.MapPieceIdentifier piece)Sends one discovered map piece (map and index 0 to 127); clients mark it found.