refactor: remove single-owner helpers and redundant plumbing

Return feature-only helpers to their owners, remove inactive scaffolding and duplicate state, and reuse existing calculation and UI work without changing public contracts or gameplay.

Record repository-wide coverage, justified retentions, independent reviews and validation, including baseline dashboard fixture failures.

Assisted-by: Cindy (https://cindy.app)
This commit is contained in:
soarqin committed 2026-11-09 02:36:52 +08:00
1 parent 325536fc79
commit ba2648a3e3
60 files changed
+1094 -994

No files matched your search

@@ -16,7 +16,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static Dictionary<int, BeltSignal>[] _signalBelts;
private static Dictionary<long, int> _portalFrom;
private static Dictionary<int, HashSet<long>> _portalTo;
private static int _signalBeltsCapacity;
private static bool _initialized;
private static ProductionCatalog _sourceCatalog;
private static ProductionItem _preferredProliferator;
@@ -50,7 +49,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
_signalBelts = null;
_portalFrom = null;
_portalTo = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -84,7 +82,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
GameLogicProc.OnGameBegin -= OnGameBegin;
_initialized = false;
_signalBelts = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -181,7 +178,6 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
{
if (DSPGame.IsMenuDemo) return;
_signalBelts = new Dictionary<int, BeltSignal>[64];
_signalBeltsCapacity = 64;
_portalFrom = [];
_portalTo = [];
@@ -225,13 +221,12 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
{
Dictionary<int, BeltSignal> obj;
if (index < 0) return null;
if (index >= _signalBeltsCapacity)
if (index >= _signalBelts.Length)
{
var newCapacity = _signalBeltsCapacity * 2;
var newCapacity = _signalBelts.Length * 2;
var newSignalBelts = new Dictionary<int, BeltSignal>[newCapacity];
Array.Copy(_signalBelts, newSignalBelts, _signalBeltsCapacity);
Array.Copy(_signalBelts, newSignalBelts, _signalBelts.Length);
_signalBelts = newSignalBelts;
_signalBeltsCapacity = newCapacity;
}
else
{
@@ -246,7 +241,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static Dictionary<int, BeltSignal> GetSignalBelts(int index)
{
return index >= 0 && index < _signalBeltsCapacity ? _signalBelts[index] : null;
return index >= 0 && _signalBelts != null && index < _signalBelts.Length ? _signalBelts[index] : null;
}
private static void SetSignalBelt(int factory, int beltId, int signalId, int number)
+30 -2
View File
@@ -17,7 +17,7 @@ internal static class TechClickHandler
}
catch (Exception e)
{
TechLog.Warn($"click handling failed: {e}");
CheatEnabler.Logger.LogWarning($"[TechTweaks] click handling failed: {e}");
}
}
@@ -40,7 +40,7 @@ internal static class TechClickHandler
return;
}
if (!TechKeyCombo.TryDecode(out int steps))
if (!TryDecodeModifiers(out int steps))
{
return;
}
@@ -54,4 +54,32 @@ internal static class TechClickHandler
TechUnlock.Run(history, techProto, steps);
}
}
private static bool TryDecodeModifiers(out int steps)
{
steps = 0;
if (VFInput.shift)
{
if (VFInput.alt) return false;
steps = VFInput.control ? 100 : 1;
return true;
}
if (VFInput.control)
{
if (VFInput.alt) return false;
steps = 10;
return true;
}
if (VFInput.alt)
{
// Alt applies or reverts every level available to this click.
steps = int.MaxValue;
return true;
}
return false;
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ internal static class TechDowngrade
{
if (!TryGetLastAppliedLevel(history, techProto, out int lastApplied) || steps <= 0) return;
int target = steps == TechKeyCombo.LevelToMax
int target = steps == int.MaxValue
? techProto.Level - 1
: System.Math.Max(techProto.Level - 1, lastApplied - steps);
Targets.Clear();
+4 -4
View File
@@ -410,7 +410,7 @@ namespace CheatEnabler.Patches.Tech
// a downgrade can walk thousands of levels and must not flood the log.
if (UnknownFuncsWarned.Add(func))
{
TechLog.Warn($"revert: no inverse known for tech function {func} (value={value}, level={level}); " +
CheatEnabler.Logger.LogWarning($"[TechTweaks] revert: no inverse known for tech function {func} (value={value}, level={level}); " +
"the field was left untouched. A game update may have added a new function.");
}
@@ -429,7 +429,7 @@ namespace CheatEnabler.Patches.Tech
ModeConfig freeMode = Configs.freeMode;
if (freeMode == null)
{
TechLog.Warn($"recompute of tech function {func} skipped: Configs.freeMode is not available");
CheatEnabler.Logger.LogWarning($"[TechTweaks] recompute of tech function {func} skipped: Configs.freeMode is not available");
return;
}
@@ -819,7 +819,7 @@ namespace CheatEnabler.Patches.Tech
if (Configs.freeMode == null || history.gameData == null || player?.mecha == null ||
player.package?.grids == null || player.deliveryPackage?.grids == null)
{
TechLog.Warn("downgrade skipped: game data is not ready");
CheatEnabler.Logger.LogWarning("[TechTweaks] downgrade skipped: game data is not ready");
return false;
}
@@ -836,7 +836,7 @@ namespace CheatEnabler.Patches.Tech
int func = proto.UnlockFunctions[j];
if (!(func is >= 1 and <= 45 or >= 61 and <= 86 or 99))
{
TechLog.Warn($"downgrade skipped: unsupported tech function {func} in tech {proto.ID}");
CheatEnabler.Logger.LogWarning($"[TechTweaks] downgrade skipped: unsupported tech function {func} in tech {proto.ID}");
UIRealtimeTip.Popup(Localization.TechDowngradeUnsupportedFunction.Translate());
return false;
}
-59
View File
@@ -1,59 +0,0 @@
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// The key-modifier semantics shared by the upgrade and the downgrade side.
///
/// Both directions use the same modifier mapping:
///
/// <list type="table">
/// <item><term>Shift</term><description>+1 / -1</description></item>
/// <item><term>Ctrl</term><description>+10 / -10</description></item>
/// <item><term>Ctrl + Shift</term><description>+100 / -100</description></item>
/// <item><term>Alt</term><description>to MAX / back to locked</description></item>
/// <item><term>Shift + Alt, Ctrl + Alt</term><description>ignored</description></item>
/// </list>
/// </summary>
internal static class TechKeyCombo
{
/// <summary>Sentinel for the "Alt" combination: apply or revert everything this click can.</summary>
public const int LevelToMax = int.MaxValue;
/// <summary>
/// Decodes the currently held modifiers.
/// Returns false when the combination carries no meaning and the click must be left alone.
/// </summary>
public static bool TryDecode(out int steps)
{
steps = 0;
if (VFInput.shift)
{
if (VFInput.alt)
{
return false;
}
steps = VFInput.control ? 100 : 1;
return true;
}
if (VFInput.control)
{
if (VFInput.alt)
{
return false;
}
steps = 10;
return true;
}
if (VFInput.alt)
{
steps = LevelToMax;
return true;
}
return false;
}
}
-16
View File
@@ -1,16 +0,0 @@
namespace CheatEnabler.Patches.Tech;
/// <summary>
/// Single funnel for the tech unlock / downgrade feature's log output.
///
/// Only real problems are reported: a Harmony target that no longer resolves, a tech function without
/// a known inverse, or a refused package resize. Those are conditions the player or the maintainer
/// needs to know about after a game update.
/// </summary>
internal static class TechLog
{
public static void Warn(string message)
{
CheatEnabler.Logger.LogWarning("[TechTweaks] " + message);
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ internal static class TechUnlock
{
// Mirrors the built-in maxLevel argument: "to MAX" passes the default, the other combinations
// pass -(steps) so the loop advances exactly `steps` levels.
int maxLevel = steps == TechKeyCombo.LevelToMax ? 10000 : -steps;
int maxLevel = steps == int.MaxValue ? 10000 : -steps;
UnlockTechRecursive(history, techProto, maxLevel);