59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Verse;
|
|
|
|
namespace BlaxZones
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class ZonesLog
|
|
{
|
|
private static readonly HashSet<string> logged = new HashSet<string>();
|
|
|
|
/// <summary>Logs "[Blax Zones] where failed" with the exception, once per key until the next reset.</summary>
|
|
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.
|
|
}
|
|
}
|
|
|
|
/// <summary>A one-time message (stand-downs, hints), not an error.</summary>
|
|
public static void MessageOnce(string key, string text)
|
|
{
|
|
if (logged.Add("msg:" + key))
|
|
Log.Message("[Blax Zones] " + text);
|
|
}
|
|
|
|
public static void ResetOnce() => logged.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class ZonesTestHooks
|
|
{
|
|
/// <summary>DeliveryRouter.TryFindDropSpot throws, to test that every routed path falls back to vanilla.</summary>
|
|
public static bool RouterThrows;
|
|
|
|
/// <summary>ZoneStore.AllZonesRef returns null, as when a game update renames ZoneManager.allZones.</summary>
|
|
public static bool AllZonesUnbound;
|
|
|
|
public static void Reset()
|
|
{
|
|
RouterThrows = false;
|
|
AllZonesUnbound = false;
|
|
}
|
|
}
|
|
}
|