using System; using System.Collections.Generic; using Verse; namespace BlaxZones { /// /// One-time error logging for hook bodies. Every hook sits in try/catch and logs through here, so /// a broken hook logs once per game instead of every call. The flags reset in /// MapComponent_BlaxZones.FinalizeInit, so a failure in a later game logs again. /// public static class ZonesLog { private static readonly HashSet logged = new HashSet(); /// Logs "[Blax Zones] where failed" with the exception, once per key until the next reset. public static void Once(string where, Exception e) { try { if (logged.Add(where)) Log.Error("[Blax Zones] " + where + " failed (logged once per game): " + e); } catch { // Logging must never throw into a hook. } } /// A one-time message (stand-downs, hints), not an error. public static void MessageOnce(string key, string text) { if (logged.Add("msg:" + key)) Log.Message("[Blax Zones] " + text); } public static void ResetOnce() => logged.Clear(); } /// /// Switches the test mod flips to force failure paths. Not game state: nothing here is saved and /// the test runner resets every field after each test. /// public static class ZonesTestHooks { /// DeliveryRouter.TryFindDropSpot throws, to test that every routed path falls back to vanilla. public static bool RouterThrows; /// ZoneStore.AllZonesRef returns null, as when a game update renames ZoneManager.allZones. public static bool AllZonesUnbound; /// /// Routing a quest reward group throws at this routed group of one drop (0 the first, -1 never), after /// its things went into the pod's container and before the pod falls, to test the fallback. /// public static int RoutedGroupThrowsAt = -1; public static void Reset() { RouterThrows = false; AllZonesUnbound = false; RoutedGroupThrowsAt = -1; } } }