using System;
using Verse;
namespace BlaxZones
{
///
/// All Blax state of one map (design: "Zone store, safe to remove from a save"): our zones while
/// saving and loading, and every cache. No Blax zone or field ever enters a vanilla save list.
/// ZoneManager stays the only zone registry while the game runs; this component keeps no zone list.
///
/// Zones' own code never creates this component: vanilla's Map.FillComponents adds it. Every
/// patch reads it with Of(map) and routes to vanilla on null.
///
/// The class is split by owner. This file (integrator) wires the MapComponent overrides to the
/// package parts:
/// - MapComponent_BlaxZones.Store.cs (Store): ExposeStore, the loaded-zone list, RegisterLoadedZones.
/// - MapComponent_BlaxZones.Rules.cs (Rules): reach cache per district, unusable cells per zone,
/// the red overlay, the inspect line.
/// - MapComponent_BlaxZones.Router.cs (Router): cell order per zone.
///
public partial class MapComponent_BlaxZones : MapComponent
{
public MapComponent_BlaxZones(Map map) : base(map)
{
}
/// The map's component, or null (no map, or Zones was removed from this game).
public static MapComponent_BlaxZones Of(Map map) => map?.GetComponent();
public override void ExposeData()
{
base.ExposeData();
ExposeStore();
}
public override void FinalizeInit()
{
base.FinalizeInit();
ZonesLog.ResetOnce();
try
{
ClearRouterCaches();
ClearRuleCaches();
}
catch (Exception e)
{
ZonesLog.Once("Map init", e);
}
}
public override void MapComponentTick()
{
try
{
TickRules();
TradeShipsDropSpotHint.Check(map);
}
catch (Exception e)
{
ZonesLog.Once("Map tick", e);
}
}
public override void MapComponentUpdate()
{
try
{
UpdateOverlay();
}
catch (Exception e)
{
ZonesLog.Once("Zone overlay", e);
}
}
/// Drops caches only. Never deletes or deregisters zones of the removed map; vanilla doesn't either.
public override void MapRemoved()
{
try
{
ClearRouterCaches();
ClearRuleCaches();
}
catch (Exception e)
{
ZonesLog.Once("Map removal", e);
}
}
/// Called by Zone_Delivery.AddCell and RemoveCell.
public void Notify_ZoneCellsChanged(Zone_Delivery zone)
{
try
{
DropRouterCaches(zone);
DropRuleCaches(zone);
}
catch (Exception e)
{
ZonesLog.Once("Zone cell change", e);
}
}
/// Called by Zone_Delivery.PostDeregister: the zone left ZoneManager, drop everything keyed by it.
public void Notify_ZoneRemoved(Zone_Delivery zone)
{
try
{
DropRouterCaches(zone);
DropRuleCaches(zone);
}
catch (Exception e)
{
ZonesLog.Once("Zone removal", e);
}
}
}
}