mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-08-05 07:40:12 +08:00
refactor(UXAssist): drive lifecycle and save dispatch via ModFeatureRegistry
This commit is contained in:
@@ -14,6 +14,9 @@ public static class UIFunctions
|
||||
AutoConstructUI.Init();
|
||||
StarmapFilterUI.Init();
|
||||
MilkyWayUI.Init();
|
||||
|
||||
UXAssist.RegisterExporter(ExportClusterUploadResults);
|
||||
UXAssist.RegisterImporter((r, version) => ImportClusterUploadResults(r, version));
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
@@ -97,9 +100,12 @@ public static class UIFunctions
|
||||
MilkyWayUI.Export(w);
|
||||
}
|
||||
|
||||
public static void ImportClusterUploadResults(BinaryReader r)
|
||||
public static void ImportClusterUploadResults(BinaryReader r, ushort version)
|
||||
{
|
||||
MilkyWayUI.Import(r);
|
||||
if (version > 1)
|
||||
MilkyWayUI.Import(r);
|
||||
else
|
||||
MilkyWayUI.ClearClusterUploadResults();
|
||||
}
|
||||
|
||||
public static void ClearClusterUploadResults()
|
||||
|
||||
@@ -135,6 +135,9 @@ public static class FactoryPatch
|
||||
EjectorBufferCount.SettingChanged += (_, _) => BuildingBufferPatch.TweakBuildingBuffer.RefreshEjectorBufferCount();
|
||||
SiloBufferCount.SettingChanged += (_, _) => BuildingBufferPatch.TweakBuildingBuffer.RefreshSiloBufferCount();
|
||||
PressShiftToTakeWholeBeltItemsEnabled.SettingChanged += (_, _) => BuildToolPatch.PressShiftToTakeWholeBeltItems.Enable(PressShiftToTakeWholeBeltItemsEnabled.Value);
|
||||
|
||||
UXAssist.RegisterExporter(Export);
|
||||
UXAssist.RegisterImporter((r, version) => Import(r, version));
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
@@ -219,7 +222,7 @@ public static class FactoryPatch
|
||||
BeltSignalPatch.Export(w);
|
||||
}
|
||||
|
||||
public static void Import(BinaryReader r)
|
||||
public static void Import(BinaryReader r, ushort version)
|
||||
{
|
||||
BeltSignalPatch.Import(r);
|
||||
}
|
||||
|
||||
+12
-21
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BepInEx;
|
||||
@@ -38,26 +39,23 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
#region IModCanSave
|
||||
private const ushort ModSaveVersion = 2;
|
||||
|
||||
private static readonly List<Action<BinaryWriter>> _exporters = [];
|
||||
private static readonly List<Action<BinaryReader, ushort>> _importers = [];
|
||||
|
||||
public static void RegisterExporter(Action<BinaryWriter> e) => _exporters.Add(e);
|
||||
public static void RegisterImporter(Action<BinaryReader, ushort> i) => _importers.Add(i);
|
||||
|
||||
public void Export(BinaryWriter w)
|
||||
{
|
||||
w.Write(ModSaveVersion);
|
||||
FactoryPatch.Export(w);
|
||||
UIFunctions.ExportClusterUploadResults(w);
|
||||
foreach (var e in _exporters) e(w);
|
||||
}
|
||||
|
||||
public void Import(BinaryReader r)
|
||||
{
|
||||
var version = r.ReadUInt16();
|
||||
if (version <= 0) return;
|
||||
FactoryPatch.Import(r);
|
||||
if (version > 1)
|
||||
{
|
||||
UIFunctions.ImportClusterUploadResults(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIFunctions.ClearClusterUploadResults();
|
||||
}
|
||||
foreach (var i in _importers) i(r, version);
|
||||
}
|
||||
|
||||
public void IntoOtherSave()
|
||||
@@ -284,17 +282,10 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
||||
private void Update()
|
||||
{
|
||||
if (VFInput.inputing) return;
|
||||
if (DSPGame.IsMenuDemo)
|
||||
{
|
||||
UIFunctions.OnInputUpdate();
|
||||
return;
|
||||
}
|
||||
LogisticsPatch.OnInputUpdate();
|
||||
UIFunctions.OnInputUpdate();
|
||||
ModFeatureRegistry.OnInputUpdateAll();
|
||||
if (DSPGame.IsMenuDemo) return;
|
||||
GamePatch.OnInputUpdate();
|
||||
FactoryPatch.OnInputUpdate();
|
||||
PlayerPatch.OnInputUpdate();
|
||||
|
||||
LogisticsPatch.OnUpdate();
|
||||
ModFeatureRegistry.OnUpdateAll();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user