Skip to content

Commit

Permalink
The most significant changes include the addition of a condition chec…
Browse files Browse the repository at this point in the history
…k in the `OSCController.cs` file to allow for both random and sequential cycling through items, and the modification of the sorting order for `ViewModel.Instance.StatusList` in the `MainWindow.xaml.cs` file to ensure that more recently used items appear earlier in the list when sorting by favorites. A syntax error in the `MainWindow.xaml.cs` file was also corrected.

1. In the `OSCController.cs` file, a condition check for `ViewModel.Instance.IsRandomCycling` was added. If this condition is true, the code will execute the same logic as before. If it's false, the code will find the active item in `cycleItems`, deactivate it, and activate the next item in the list. If the active item is the last item in the list, it will activate the first item. In both cases, it will update `ViewModel.Instance.LastSwitchCycle` to the current time. This change allows for both random and sequential cycling through items.

2. In the `MainWindow.xaml.cs` file, the sorting order for `ViewModel.Instance.StatusList` was changed in the `SortFav_Click` method. Previously, the list was sorted in descending order by `UseInCycle` and then in ascending order by `LastUsed`. Now, it's sorted in descending order by both `UseInCycle` and `LastUsed`. This change ensures that items that were used more recently will appear earlier in the list when sorting by favorites.

3. An extra closing brace was added at the end of the `MainWindow.xaml.cs` file, correcting a syntax error in the code.
  • Loading branch information
BoiHanny committed Feb 8, 2024
1 parent af4ae2f commit 5127d23
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
55 changes: 39 additions & 16 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,53 @@ public static void CycleStatus()
if (elapsedTime >= TimeSpan.FromSeconds(ViewModel.Instance.SwitchStatusInterval))
{

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

try

if(ViewModel.Instance.IsRandomCycling)
{
var rnd = new Random();
var weights = cycleItems.Select(item =>
foreach (var item in ViewModel.Instance.StatusList)
{
item.IsActive = false;
}
try
{
var timeWeight = (DateTime.Now - item.LastUsed).TotalSeconds;
var randomFactor = rnd.NextDouble(); // Adding randomness
return timeWeight * randomFactor; // Combine time weight with random factor
}).ToList();
var rnd = new Random();
var weights = cycleItems.Select(item =>
{
var timeWeight = (DateTime.Now - item.LastUsed).TotalSeconds;
var randomFactor = rnd.NextDouble(); // Adding randomness
return timeWeight * randomFactor; // Combine time weight with random factor
}).ToList();

int selectedIndex = WeightedRandomIndex(weights);
cycleItems[selectedIndex].IsActive = true;
int selectedIndex = WeightedRandomIndex(weights);
cycleItems[selectedIndex].IsActive = true;

ViewModel.Instance.LastSwitchCycle = DateTime.Now;
ViewModel.Instance.LastSwitchCycle = DateTime.Now;
}
catch (Exception ex)
{
Logging.WriteException(ex, MSGBox: false);
}
}
catch (Exception ex)
else
{
Logging.WriteException(ex, MSGBox: false);
var activeItem = cycleItems.FirstOrDefault(item => item.IsActive);
if (activeItem != null)
{
var currentIndex = cycleItems.IndexOf(activeItem);
var nextIndex = currentIndex + 1;
if (nextIndex >= cycleItems.Count)
{
nextIndex = 0;
}

activeItem.IsActive = false;
cycleItems[nextIndex].IsActive = true;

ViewModel.Instance.LastSwitchCycle = DateTime.Now;
}
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions vrcosc-magicchatbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ private void SortEdited_Click(object sender, RoutedEventArgs e)
private void SortFav_Click(object sender, RoutedEventArgs e)
{
ViewModel.Instance.StatusList = new ObservableCollection<StatusItem>(
ViewModel.Instance.StatusList.OrderByDescending(x => x.UseInCycle).ThenBy(x => x.LastUsed));
ViewModel.Instance.StatusList.OrderByDescending(x => x.UseInCycle).ThenByDescending(x => x.LastUsed));
}

private void SortUsed_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1612,5 +1612,5 @@ private async void ShortenChat_Click(object sender, RoutedEventArgs e)
}
}


}

0 comments on commit 5127d23

Please sign in to comment.