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