Skip to content

Commit

Permalink
The most significant changes include the removal of three files, the …
Browse files Browse the repository at this point in the history
…addition of a status check in `DataController.cs`, improved error handling in `HotkeyManagement.cs`, refactoring of the `CycleStatus` method in `OSCController.cs`, and various visual adjustments in `MainWindow.xaml`. Additionally, the message displayed when the dev egg mode is found was updated in `MainWindow.xaml.cs`.

1. The `MagicChatboxTests.csproj`, `OAuthService.cs`, and `PulsoidOAuthLib.csproj` files were completely removed from the project.
2. A new status check was added to `DataController.cs` to see if a status with the message 'BoiHanny' or 'Gun' exists. If such a status is found, `Egg_Dev` is set to true.
3. Error handling was improved in `HotkeyManagement.cs` when loading hotkey configurations. If the deserialization returns null or if there is a failure to parse a specific hotkey, an error message is logged and default hotkeys are added.
4. The `CycleStatus` method in `OSCController.cs` was refactored for better readability and performance. The status items are now set to inactive using a foreach loop instead of a LINQ expression. The selection of the next active status item was also improved.
5. In `MainWindow.xaml`, the size of the main window was reduced and the visibility of certain elements was changed. The background color of some elements was changed from `DarkSlateBlue` to a linear gradient. The `RenderOptions.BitmapScalingMode` was set to `HighQuality` or `NearestNeighbor` for several images.
6. The message displayed when the dev egg mode is found was updated in `MainWindow.xaml.cs` to include "go to options".
  • Loading branch information
BoiHanny committed Jan 25, 2024
2 parents 65e9910 + 053831e commit dae126e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 213 deletions.
32 changes: 0 additions & 32 deletions MagicChatboxTests/MagicChatboxTests.csproj

This file was deleted.

Empty file removed MagicChatboxTests/Usings.cs
Empty file.
121 changes: 0 additions & 121 deletions PulsoidOAuthLib/OAuthService.cs

This file was deleted.

9 changes: 0 additions & 9 deletions PulsoidOAuthLib/PulsoidOAuthLib.csproj

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ public static void LoadComponentStats()


{ "BlankEgg", (typeof(bool), "DEV") },
{ "Egg_Dev", (typeof(bool), "DEV") },

{ "SwitchStatusInterval", (typeof(int), "StatusSetting") },
{ "IsRandomCycling", (typeof(bool), "StatusSetting") },
Expand Down Expand Up @@ -661,6 +660,11 @@ public static void LoadStatusList()
return;
}
ViewModel.Instance.StatusList = JsonConvert.DeserializeObject<ObservableCollection<StatusItem>>(json);
// check if we have a status with the msg 'BoiHanny' or 'Gun'
if (ViewModel.Instance.StatusList.Any(x => x.msg == "boihanny" || x.msg == "sr4 series"))
{
ViewModel.Instance.Egg_Dev = true;
}
}
else
{
Expand Down
54 changes: 42 additions & 12 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/HotkeyManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,55 @@ public void SaveHotkeyConfigurations()

private void LoadHotkeyConfigurations()
{
if (!File.Exists(HotkeyConfigFile))
try
{
AddDefaultHotkeys();
SaveHotkeyConfigurations();
return;
}
if (!File.Exists(HotkeyConfigFile))
{
AddDefaultHotkeys();
SaveHotkeyConfigurations();
return;
}

var json = File.ReadAllText(HotkeyConfigFile);
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
var json = File.ReadAllText(HotkeyConfigFile);
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
if (deserialized == null)
{
// Log an error message stating that the deserialization returned null
Logging.WriteException(new Exception("Failed to deserialize hotkey configurations."), MSGBox: true);
AddDefaultHotkeys();
return;
}

_hotkeyActions.Clear();
foreach (var entry in deserialized)
_hotkeyActions.Clear();
foreach (var entry in deserialized)
{
if (!Enum.TryParse<Key>(entry.Value["Key"], out var key) ||
!Enum.TryParse<ModifierKeys>(entry.Value["Modifiers"], out var modifiers))
{
// Log an error message about the specific hotkey that failed to parse
Logging.WriteException(new Exception($"Failed to parse hotkey configuration for {entry.Key}."), MSGBox: true);
continue;
}

var action = GetActionForHotkey(entry.Key);
if (action == null)
{
// Log an error message stating that no action is defined for this hotkey
Logging.WriteException(new Exception($"No action defined for hotkey {entry.Key}."), MSGBox: true);
continue;
}

AddKeyBinding(entry.Key, key, modifiers, action);
}
}
catch (Exception ex)
{
var key = (Key)Enum.Parse(typeof(Key), entry.Value["Key"]);
var modifiers = (ModifierKeys)Enum.Parse(typeof(ModifierKeys), entry.Value["Modifiers"]);
AddKeyBinding(entry.Key, key, modifiers, GetActionForHotkey(entry.Key));
Logging.WriteException(ex, MSGBox: true);
}

}


private Action GetActionForHotkey(string hotkeyName)
{
return hotkeyName switch
Expand Down
38 changes: 17 additions & 21 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static void AddStatusMessage(List<string> Uncomplete)
CycleStatus();
}

var activeItem = ViewModel.Instance.StatusList.FirstOrDefault(item => item.IsActive == true);
StatusItem? activeItem = ViewModel.Instance.StatusList.FirstOrDefault(item => item.IsActive == true);
if (activeItem != null)
{
// Update LastUsed property for the active item
Expand Down Expand Up @@ -268,9 +268,8 @@ public static void AddWindowActivity(List<string> Uncomplete)

public static void CycleStatus()
{
if (ViewModel.Instance == null) return;

if (ViewModel.Instance.StatusList == null || !ViewModel.Instance.StatusList.Any()) return;
if (ViewModel.Instance == null || ViewModel.Instance.StatusList == null || !ViewModel.Instance.StatusList.Any())
return;

var cycleItems = ViewModel.Instance.StatusList.Where(item => item.UseInCycle).ToList();
if (cycleItems.Count == 0) return;
Expand All @@ -279,28 +278,24 @@ public static void CycleStatus()

if (elapsedTime >= TimeSpan.FromSeconds(ViewModel.Instance.SwitchStatusInterval))
{
// Reset all status items to inactive before setting the next one to active
ViewModel.Instance.StatusList.All(item => { item.IsActive = false; return true; });

foreach (var item in ViewModel.Instance.StatusList)
{
item.IsActive = false;
}

try
{
if (ViewModel.Instance.IsRandomCycling)
var rnd = new Random();
var weights = cycleItems.Select(item =>
{
// Calculate weights for each cycle item
var weights = cycleItems.Select(item =>
(DateTime.Now - item.LastUsed).TotalSeconds).ToList();

// Select a random index based on weights
int selectedIndex = WeightedRandomIndex(weights);
var timeWeight = (DateTime.Now - item.LastUsed).TotalSeconds;
var randomFactor = rnd.NextDouble(); // Adding randomness
return timeWeight * randomFactor; // Combine time weight with random factor
}).ToList();

cycleItems[selectedIndex].IsActive = true;
}
else
{
// Improved Sequential selection
ViewModel.Instance.StatusIndex = (ViewModel.Instance.StatusIndex + 1) % cycleItems.Count;
cycleItems[ViewModel.Instance.StatusIndex].IsActive = true;
}
int selectedIndex = WeightedRandomIndex(weights);
cycleItems[selectedIndex].IsActive = true;

ViewModel.Instance.LastSwitchCycle = DateTime.Now;
}
Expand All @@ -311,6 +306,7 @@ public static void CycleStatus()
}
}


private static int WeightedRandomIndex(List<double> weights)
{
Random rnd = new Random();
Expand Down
Loading

0 comments on commit dae126e

Please sign in to comment.