Table of Contents

Class MapModeManager

Namespace
Map.MapModes
Assembly
MapAssembly.dll

Central manager for the map mode system Handles mode switching, texture updates, and handler coordination Performance: <0.1ms mode switching, efficient texture scheduling

public class MapModeManager : MonoBehaviour
Inheritance
object
MapModeManager

Properties

CurrentMode

public MapMode CurrentMode { get; }

Property Value

MapMode

IsInitialized

public bool IsInitialized { get; }

Property Value

bool

Methods

ApplyPaletteChanges()

Apply pending palette changes to GPU. Call after a batch of UpdateProvinceColor calls.

public void ApplyPaletteChanges()

ForceTextureUpdate()

Force an immediate texture update for the current map mode

public void ForceTextureUpdate()

ForceUpdateIfActive(IMapModeHandler)

Force texture update only if the given handler is currently active. Called by GradientMapMode.MarkDirty() to trigger event-driven updates.

public void ForceUpdateIfActive(IMapModeHandler handler)

Parameters

handler IMapModeHandler

GetCustomModeArrayIndex(int)

Get the array index for a registered custom mode. Returns -1 if not registered.

public int GetCustomModeArrayIndex(int customModeId)

Parameters

customModeId int

Returns

int

GetHandler(MapMode)

Get a specific map mode handler (for GAME layer to mark dirty) Returns null if handler not registered

public IMapModeHandler GetHandler(MapMode mode)

Parameters

mode MapMode

Returns

IMapModeHandler

GetPaletteInfo()

Get palette dimensions and province limit info. GAME map modes need this to know capacity.

public (int maxProvinces, int maxModes, int rowsPerMode) GetPaletteInfo()

Returns

(int totalBytes, int provinceBytes, int lookupBytes)

GetProvinceTooltip(ushort)

public string GetProvinceTooltip(ushort provinceId)

Parameters

provinceId ushort

Returns

string

Initialize(GameState, Material, ProvinceMapping, object)

Initialize the map mode system ENGINE provides MECHANISM, GAME controls WHEN to initialize Called by GAME layer after handlers are registered

public void Initialize(GameState gameStateRef, Material material, ProvinceMapping mapping, object gameSystem = null)

Parameters

gameStateRef GameState
material Material
mapping ProvinceMapping
gameSystem object

Optional game-specific province system - engine passes through without knowing type

InvalidateAllMapModes()

Mark all map mode handlers as dirty so they recalculate on next activation. Call after loading a save to ensure all modes reflect the loaded state.

public void InvalidateAllMapModes()

RebindTextures()

Rebind all map mode textures to the material Call this after other systems rebind base textures to prevent losing map mode texture bindings

public void RebindTextures()

RegisterCustomMapMode(int)

Register a custom map mode and get its array index. Called by GAME layer when creating custom map modes.

public int RegisterCustomMapMode(int customModeId)

Parameters

customModeId int

Unique ID for this custom mode (typically ShaderModeID from handler)

Returns

int

Palette index for this mode, or -1 if full

RegisterHandler(MapMode, IMapModeHandler)

Register a map mode handler - called by GAME layer during initialization Enables dependency injection: ENGINE provides mechanism, GAME provides policy

public void RegisterHandler(MapMode mode, IMapModeHandler handler)

Parameters

mode MapMode
handler IMapModeHandler

RequestDeferredUpdate(IMapModeHandler)

Request a deferred texture update for next frame. Multiple requests within same frame are batched into single update. Called by GradientMapMode.MarkDirty() to prevent multiple rebuilds per tick.

public void RequestDeferredUpdate(IMapModeHandler handler)

Parameters

handler IMapModeHandler

SetMapMode(MapMode, bool)

public void SetMapMode(MapMode mode, bool forceUpdate = false)

Parameters

mode MapMode
forceUpdate bool

UpdateMaterial(Material)

Update material reference when material is swapped Called by GAME layer (VisualStyleManager) when material changes

public void UpdateMaterial(Material newMaterial)

Parameters

newMaterial Material

UpdateProvinceColor(int, int, Color32)

Update a single province's color for a custom map mode. Use UpdateProvinceColors for batch updates.

public void UpdateProvinceColor(int paletteIndex, int provinceID, Color32 color)

Parameters

paletteIndex int
provinceID int
color Color32

UpdateProvinceColors(int, Dictionary<int, Color32>)

Update province colors for a custom map mode. Called by GAME map mode handlers when their data changes.

public void UpdateProvinceColors(int paletteIndex, Dictionary<int, Color32> provinceColors)

Parameters

paletteIndex int

Index returned from RegisterCustomMapMode

provinceColors Dictionary<int, Color32>

Dictionary mapping province ID to color