Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Made instance history keep threshold customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
RequiDev committed Apr 25, 2022
1 parent 45ebe34 commit 5043f4d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ReModCE/Components/InstanceHistoryComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MelonLoader.Preferences;
using ReMod.Core.UI.QuickMenu;
using ReMod.Core.VRChat;
using UnityEngine;
using VRC.Core;
using VRC.SDKBase;
Expand Down Expand Up @@ -35,9 +37,12 @@ internal class SavedWorld

private SavedWorld _currentSavedWorld;

private ConfigValue<int> InstanceHistoryThreshold;
private ReMenuButton _instanceHistoryThreshholdButton;

public InstanceHistoryComponent()
{

InstanceHistoryThreshold = new ConfigValue<int>(nameof(InstanceHistoryThreshold), 8);
if (File.Exists("UserData/ReModCE/instance_history.json"))
{
_instanceHistory = JsonConvert.DeserializeObject<List<SavedWorld>>(File.ReadAllText("UserData/ReModCE/instance_history.json"));
Expand All @@ -46,7 +51,7 @@ public InstanceHistoryComponent()
_instanceHistory ??= new List<SavedWorld>();

var history = _instanceHistory.ToList();
foreach (var instance in history.Where(instance => (DateTime.UtcNow - instance.JoinDate).TotalHours > 8))
foreach (var instance in history.Where(instance => (DateTime.UtcNow - instance.JoinDate).TotalHours > InstanceHistoryThreshold))
{
_instanceHistory.Remove(instance);
}
Expand Down Expand Up @@ -81,6 +86,11 @@ public override void OnUiManagerInit(UiManager uiManager)

_instanceSettingsDescendingToggle = _instanceSettingsMenu.AddToggle("Reverse Order",
"Reverse the order of the instances.", InstanceHistoryDescendingEnabled);
_instanceHistoryThreshholdButton = _instanceSettingsMenu.AddButton($"Keep Threshold: {InstanceHistoryThreshold}",
"For how many hours an instance is kept before getting deleted",
() => VRCUiPopupManager.field_Private_Static_VRCUiPopupManager_0.ShowInputPopup("Set the amount of hours",
InstanceHistoryThreshold, _instanceHistoryThreshholdButton, "Keep Threshold", new ValueRange<int>(1, 180)
));
}

//TODO: On restart (rejoining last world), queue the button move rather than execute immediately.
Expand Down

0 comments on commit 5043f4d

Please sign in to comment.