make toggle state persistent
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"total": 85508,
|
||||
"total": 87144,
|
||||
"sessions": [
|
||||
{
|
||||
"begin": "2026-03-11T23:50:47+01:00",
|
||||
@@ -135,6 +135,11 @@
|
||||
"begin": "2026-05-23T00:34:04+02:00",
|
||||
"end": "2026-05-23T01:10:47+02:00",
|
||||
"duration": 2202
|
||||
},
|
||||
{
|
||||
"begin": "2026-05-23T01:10:47+02:00",
|
||||
"end": "2026-05-23T01:38:03+02:00",
|
||||
"duration": 1636
|
||||
}
|
||||
]
|
||||
}
|
||||
7
ChestPreview/ChestPreview/Configs/State.cs
Normal file
7
ChestPreview/ChestPreview/Configs/State.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ChestPreview.Configs;
|
||||
|
||||
public class State
|
||||
{
|
||||
public bool PreviewNearbyToggleActive { get; set; } = false;
|
||||
public bool PreviewToggleActive { get; set; } = false;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace ChestPreview.Core;
|
||||
public class ChestPreviewModSystem : ModSystem
|
||||
{
|
||||
internal const string CONFIG_FILENAME = "chestpreview.json";
|
||||
internal const string STATE_FILENAME = "chestpreview-state.json";
|
||||
internal const string CONFIGLIB_DOMAIN = "chestpreview";
|
||||
internal const string PREVIEW_CONTAINERS_HOTKEY_CODE = "chestpreview-preview-containers";
|
||||
internal const string PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE = "chestpreview-preview-containers-nearby";
|
||||
@@ -22,8 +23,7 @@ public class ChestPreviewModSystem : ModSystem
|
||||
private StorageHoverHudRenderer? storageHoverHudRenderer;
|
||||
private WorldBillboardRenderer? worldBillboardRenderer;
|
||||
|
||||
public bool PreviewNearbyToggleActive { get; private set; } = false;
|
||||
public bool PreviewToggleActive { get; private set; } = false;
|
||||
public State State { get; } = new();
|
||||
|
||||
public override bool ShouldLoad(EnumAppSide forSide) => forSide is EnumAppSide.Client;
|
||||
|
||||
@@ -45,7 +45,8 @@ public class ChestPreviewModSystem : ModSystem
|
||||
hotkeyCode: TOGGLE_PREVIEW_CONTAINERS_HOTKEY_CODE,
|
||||
keycomb =>
|
||||
{
|
||||
PreviewToggleActive = !PreviewToggleActive;
|
||||
State.PreviewToggleActive = !State.PreviewToggleActive;
|
||||
api.StoreModConfig(State, STATE_FILENAME);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -53,7 +54,8 @@ public class ChestPreviewModSystem : ModSystem
|
||||
hotkeyCode: TOGGLE_PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE,
|
||||
keycomb =>
|
||||
{
|
||||
PreviewNearbyToggleActive = !PreviewNearbyToggleActive;
|
||||
State.PreviewNearbyToggleActive = !State.PreviewNearbyToggleActive;
|
||||
api.StoreModConfig(State, STATE_FILENAME);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -84,10 +86,14 @@ public class ChestPreviewModSystem : ModSystem
|
||||
public Config LoadClientConfig(ICoreClientAPI api)
|
||||
{
|
||||
Config config;
|
||||
State state;
|
||||
|
||||
try
|
||||
{
|
||||
config = api.LoadModConfig<Config>(CONFIG_FILENAME) ?? new Config();
|
||||
state = api.LoadModConfig<State>(STATE_FILENAME) ?? new State();
|
||||
State.PreviewNearbyToggleActive = state.PreviewNearbyToggleActive;
|
||||
State.PreviewToggleActive = state.PreviewToggleActive;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -106,6 +112,7 @@ public class ChestPreviewModSystem : ModSystem
|
||||
config.PreviewNearbyRadius = config.PreviewNearbyRadius;
|
||||
|
||||
api.StoreModConfig(config, CONFIG_FILENAME);
|
||||
api.StoreModConfig(State, STATE_FILENAME);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
|
||||
private readonly Config config = config;
|
||||
private readonly List<BlockEntity> nearbyContainerEntities = [];
|
||||
private float nearbyScanAccumulator;
|
||||
private Lazy<ChestPreviewModSystem> coreModSystem = new Lazy<ChestPreviewModSystem>(() => api.ModLoader.GetModSystem<ChestPreviewModSystem>());
|
||||
private readonly Lazy<State> state = new(() => api.ModLoader.GetModSystem<ChestPreviewModSystem>().State);
|
||||
|
||||
public void CollectTargets(float deltaTime, List<PreviewTarget> targets)
|
||||
{
|
||||
@@ -87,10 +87,10 @@ internal partial class PreviewTargetProvider(ICoreClientAPI api, Config config)
|
||||
var previewKeyHeld = IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_HOTKEY_CODE);
|
||||
var previewNearbyKeyHeld = IsHotkeyHeld(ChestPreviewModSystem.PREVIEW_CONTAINERS_NEARBY_HOTKEY_CODE);
|
||||
|
||||
if (coreModSystem.Value.PreviewNearbyToggleActive || previewNearbyKeyHeld)
|
||||
if (state.Value.PreviewNearbyToggleActive || previewNearbyKeyHeld)
|
||||
return PreviewModes.ON_NEARBY_CONTAINERS;
|
||||
|
||||
if (coreModSystem.Value.PreviewToggleActive || previewKeyHeld)
|
||||
if (state.Value.PreviewToggleActive || previewKeyHeld)
|
||||
return PreviewModes.Normalize(config.Mode);
|
||||
|
||||
return PreviewModes.NONE;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"OrekiWoof"
|
||||
],
|
||||
"description": "see containers' contents without having to open them",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.0",
|
||||
"dependencies": {
|
||||
"game": "1.21.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user