mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Port SlideShowVM
This commit is contained in:
parent
648ee949c3
commit
7048854f12
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -26,12 +22,12 @@ namespace Wabbajack
|
||||
{
|
||||
}
|
||||
|
||||
public CPUDisplayVM(CPUStatus cpu)
|
||||
public CPUDisplayVM(IJob cpu)
|
||||
{
|
||||
AbsorbStatus(cpu);
|
||||
}
|
||||
|
||||
public void AbsorbStatus(CPUStatus cpu)
|
||||
public void AbsorbStatus(IJob cpu)
|
||||
{
|
||||
bool starting = cpu.IsWorking && !IsWorking;
|
||||
if (starting)
|
||||
@ -39,7 +35,7 @@ namespace Wabbajack
|
||||
StartTime = DateTime.Now;
|
||||
}
|
||||
|
||||
ID = cpu.ID;
|
||||
ID = cpu.;
|
||||
Msg = cpu.Msg;
|
||||
ProgressPercent = cpu.ProgressPercent;
|
||||
IsWorking = cpu.IsWorking;
|
||||
|
@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Media.Imaging;
|
||||
using DynamicData;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs.DownloadStates;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Extensions;
|
||||
@ -34,7 +38,7 @@ namespace Wabbajack.View_Models
|
||||
|
||||
public const int PreloadAmount = 4;
|
||||
|
||||
public SlideShow(InstallerVM appState)
|
||||
public SlideShow(InstallerVM appState, ServiceProvider provider)
|
||||
{
|
||||
Installer = appState;
|
||||
|
||||
@ -85,15 +89,15 @@ namespace Wabbajack.View_Models
|
||||
return modList.SourceModList.Archives
|
||||
.Select(m => m.State)
|
||||
.OfType<IMetaState>()
|
||||
.Where(x => x.URL != default && x.ImageURL != default)
|
||||
.DistinctBy(x => x.URL)
|
||||
.Where(x => x.LinkUrl != default && x.ImageURL != default)
|
||||
.DistinctBy(x => x.LinkUrl)
|
||||
// Shuffle it
|
||||
.Shuffle(_random)
|
||||
.AsObservableChangeSet(x => x.URL);
|
||||
.AsObservableChangeSet(x => x.LinkUrl);
|
||||
})
|
||||
// Switch to the new list after every ModList change
|
||||
.Switch()
|
||||
.Transform(mod => new ModVM(mod))
|
||||
.Transform(mod => new ModVM(provider.GetService<ILogger<ModVM>>(), mod))
|
||||
.DisposeMany()
|
||||
// Filter out any NSFW slides if we don't want them
|
||||
.AutoRefreshOnObservable(slide => this.WhenAny(x => x.ShowNSFW))
|
||||
@ -122,10 +126,10 @@ namespace Wabbajack.View_Models
|
||||
VisitURLCommand = ReactiveCommand.Create(
|
||||
execute: () =>
|
||||
{
|
||||
UIUtils.OpenWebsite(TargetMod.State.URL);
|
||||
UIUtils.OpenWebsite(TargetMod.State.LinkUrl);
|
||||
return Unit.Default;
|
||||
},
|
||||
canExecute: this.WhenAny(x => x.TargetMod.State.URL)
|
||||
canExecute: this.WhenAny(x => x.TargetMod.State.LinkUrl)
|
||||
.Select(x =>
|
||||
{
|
||||
//var regex = new Regex("^(http|https):\\/\\/");
|
||||
|
@ -12,6 +12,28 @@ public static class IEnumerableExtensions
|
||||
foreach (var i in coll) f(i);
|
||||
}
|
||||
|
||||
#region Shuffle
|
||||
/// https://stackoverflow.com/questions/5807128/an-extension-method-on-ienumerable-needed-for-shuffling
|
||||
|
||||
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng)
|
||||
{
|
||||
return source.ShuffleIterator(rng);
|
||||
}
|
||||
|
||||
private static IEnumerable<T> ShuffleIterator<T>(
|
||||
this IEnumerable<T> source, Random rng)
|
||||
{
|
||||
var buffer = source.ToList();
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
int j = rng.Next(i, buffer.Count);
|
||||
yield return buffer[j];
|
||||
|
||||
buffer[j] = buffer[i];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public static IEnumerable<TOut> TryKeep<TIn, TOut>(this IEnumerable<TIn> coll, Func<TIn, (bool, TOut)> fn)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user