Skip to content

Commit

Permalink
Fixed langversion for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rithik-b committed Mar 24, 2022
1 parent 0f1e0a5 commit c54910e
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 831 deletions.
189 changes: 95 additions & 94 deletions MorePlaylists/BeatSaver/BeatSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,125 +12,126 @@
using UnityEngine;
using Zenject;

namespace MorePlaylists.BeatSaver;

internal class BeatSaver : ISource, IInitializable, IDisposable
namespace MorePlaylists.BeatSaver
{
private readonly BeatSaverSharp.BeatSaver beatSaverInstance;
private readonly BeatSaverFiltersViewController filtersViewController;
private readonly BeatSaverListViewController listViewController;

private PlaylistPage? page;
public bool ExhaustedPlaylists { get; private set; }

private Sprite? logo;
public Sprite Logo
internal class BeatSaver : ISource, IInitializable, IDisposable
{
get
private readonly BeatSaverSharp.BeatSaver beatSaverInstance;
private readonly BeatSaverFiltersViewController filtersViewController;
private readonly BeatSaverListViewController listViewController;

private PlaylistPage? page;
public bool ExhaustedPlaylists { get; private set; }

private Sprite? logo;
public Sprite Logo
{
if (logo == null)
get
{
logo = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("MorePlaylists.Images.BeatSaver.png");
if (logo == null)
{
logo = BeatSaberMarkupLanguage.Utilities.FindSpriteInAssembly("MorePlaylists.Images.BeatSaver.png");
}
return logo;
}
return logo;
}
}

public BeatSaverFilterModel CurrentFilters => filtersViewController.filterOptions;
public IListViewController ListViewController => listViewController;
public IDetailViewController DetailViewController { get; }

public event Action<ViewController, ViewController.AnimationDirection>? ViewControllerRequested;
public event Action<ViewController, ViewController.AnimationDirection>? ViewControllerDismissRequested;
public BeatSaverFilterModel CurrentFilters => filtersViewController.filterOptions;
public IListViewController ListViewController => listViewController;
public IDetailViewController DetailViewController { get; }
public event Action<ViewController, ViewController.AnimationDirection>? ViewControllerRequested;
public event Action<ViewController, ViewController.AnimationDirection>? ViewControllerDismissRequested;

public BeatSaver(UBinder<Plugin, PluginMetadata> metadata, BeatSaverFiltersViewController filtersViewController, BeatSaverListViewController listViewController, BeatSaverDetailViewController detailViewController)
{
var options = new BeatSaverOptions(metadata.Value.Name, metadata.Value.HVersion.ToString());
beatSaverInstance = new BeatSaverSharp.BeatSaver(options);
public BeatSaver(UBinder<Plugin, PluginMetadata> metadata, BeatSaverFiltersViewController filtersViewController, BeatSaverListViewController listViewController, BeatSaverDetailViewController detailViewController)
{
var options = new BeatSaverOptions(metadata.Value.Name, metadata.Value.HVersion.ToString());
beatSaverInstance = new BeatSaverSharp.BeatSaver(options);

this.filtersViewController = filtersViewController;
this.listViewController = listViewController;
DetailViewController = detailViewController;
}

public void Initialize()
{
listViewController.FilterViewRequested += RequestFilterView;
listViewController.FilterClearRequested += ClearFilters;
this.filtersViewController = filtersViewController;
this.listViewController = listViewController;
DetailViewController = detailViewController;
}

filtersViewController.FiltersSet += OnFiltersSet;
filtersViewController.RequestDismiss += RequestFilterViewDismiss;
}
public void Initialize()
{
listViewController.FilterViewRequested += RequestFilterView;
listViewController.FilterClearRequested += ClearFilters;

filtersViewController.FiltersSet += OnFiltersSet;
filtersViewController.RequestDismiss += RequestFilterViewDismiss;
}

public void Dispose()
{
listViewController.FilterViewRequested -= RequestFilterView;
listViewController.FilterClearRequested -= ClearFilters;

filtersViewController.FiltersSet -= OnFiltersSet;
filtersViewController.RequestDismiss -= RequestFilterViewDismiss;
}
public void Dispose()
{
listViewController.FilterViewRequested -= RequestFilterView;
listViewController.FilterClearRequested -= ClearFilters;
filtersViewController.FiltersSet -= OnFiltersSet;
filtersViewController.RequestDismiss -= RequestFilterViewDismiss;
}

public async Task<List<IBeatSaverEntry>?> GetPage(bool refreshRequested, CancellationToken token)
{
List<IBeatSaverEntry>? entries = null;

if (refreshRequested || page == null)
public async Task<List<IBeatSaverEntry>?> GetPage(bool refreshRequested, CancellationToken token)
{
switch (CurrentFilters.FilterMode)
List<IBeatSaverEntry>? entries = null;

if (refreshRequested || page == null)
{
case FilterMode.Search:
page = await beatSaverInstance.SearchPlaylists(CurrentFilters.NullableSearchFilter, token: token);
break;

case FilterMode.User:
page = null;
if (CurrentFilters.UserName != null)
{
var user = await beatSaverInstance.User(CurrentFilters.UserName, token);
if (user != null)
switch (CurrentFilters.FilterMode)
{
case FilterMode.Search:
page = await beatSaverInstance.SearchPlaylists(CurrentFilters.NullableSearchFilter, token: token);
break;

case FilterMode.User:
page = null;
if (CurrentFilters.UserName != null)
{
page = await beatSaverInstance.UserPlaylists(user.ID, token: token);
entries = new List<IBeatSaverEntry> {new BeatSaverUserPlaylistEntry(user)};
var user = await beatSaverInstance.User(CurrentFilters.UserName, token);
if (user != null)
{
page = await beatSaverInstance.UserPlaylists(user.ID, token: token);
entries = new List<IBeatSaverEntry> {new BeatSaverUserPlaylistEntry(user)};
}
}
}
break;
break;
}
ExhaustedPlaylists = false;
}
ExhaustedPlaylists = false;
}
else
{
var newPage = await page.Next(token);
if (token.IsCancellationRequested)
else
{
return null;
var newPage = await page.Next(token);
if (token.IsCancellationRequested)
{
return null;
}
page = newPage;
}
page = newPage;
}

if (entries == null && (page == null || page.Empty))
{
ExhaustedPlaylists = true;
return null;
}
if (entries == null && (page == null || page.Empty))
{
ExhaustedPlaylists = true;
return null;
}

entries ??= new List<IBeatSaverEntry>();
if (page != null)
{
foreach (var playlist in page.Playlists)
entries ??= new List<IBeatSaverEntry>();
if (page != null)
{
entries.Add(new BeatSaverPlaylistEntry(playlist));
}
foreach (var playlist in page.Playlists)
{
entries.Add(new BeatSaverPlaylistEntry(playlist));
}
}
return entries;
}
return entries;
}

private void RequestFilterView() =>
ViewControllerRequested?.Invoke(filtersViewController, ViewController.AnimationDirection.Vertical);
private void RequestFilterView() =>
ViewControllerRequested?.Invoke(filtersViewController, ViewController.AnimationDirection.Vertical);

private void ClearFilters() => filtersViewController.ClearFilters();
private void ClearFilters() => filtersViewController.ClearFilters();

private void OnFiltersSet(BeatSaverFilterModel filterOptions) => listViewController.SetActiveFilter(filterOptions);
private void OnFiltersSet(BeatSaverFilterModel filterOptions) => listViewController.SetActiveFilter(filterOptions);

private void RequestFilterViewDismiss() => ViewControllerDismissRequested?.Invoke(filtersViewController, ViewController.AnimationDirection.Vertical);
private void RequestFilterViewDismiss() => ViewControllerDismissRequested?.Invoke(filtersViewController, ViewController.AnimationDirection.Vertical);
}
}
Loading

0 comments on commit c54910e

Please sign in to comment.