Skip to content

Commit

Permalink
Added configuration UI and reworked the auto start logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SuplexLuthor committed Jan 29, 2022
1 parent 222941f commit c396002
Show file tree
Hide file tree
Showing 29 changed files with 1,117 additions and 414 deletions.
108 changes: 72 additions & 36 deletions BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,96 @@
using BigBoxAutoPlay.DataAccess;
using BigBoxAutoPlay.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using Unbroken.LaunchBox.Plugins;
using Unbroken.LaunchBox.Plugins.Data;

namespace BigBoxAutoPlay.AutoPlayers
{
public abstract class BigBoxAutoPlayer : IBigBoxAutoPlayer
public class BigBoxAutoPlayer
{
protected readonly BigBoxAutoPlaySettings bigBoxAutoPlaySettings;
protected Random random;

protected BigBoxAutoPlayer(BigBoxAutoPlaySettings _bigBoxAutoPlaySettings)
public static void AutoPlay(BigBoxAutoPlaySettings bigBoxAutoPlaySettings)
{
bigBoxAutoPlaySettings = _bigBoxAutoPlaySettings;
random = new Random(Guid.NewGuid().GetHashCode());
}
// shouldn't be called but check just in case
if(!bigBoxAutoPlaySettings.Enabled.GetValueOrDefault()) return;

public static IBigBoxAutoPlayer GetBigBoxAutoPlayer()
{
IBigBoxAutoPlayer bigBoxAutoPlayer;
IEnumerable<IGame> gamesQuery = PluginHelper.DataManager.GetAllGames();

if (!string.IsNullOrWhiteSpace(bigBoxAutoPlaySettings.FromPlaylist))
{
// todo: start from playlist games
IEnumerable<IPlaylist> allPlaylistsQuery = PluginHelper.DataManager.GetAllPlaylists();
IPlaylist playlist = allPlaylistsQuery.FirstOrDefault(p => p.PlaylistId == bigBoxAutoPlaySettings.FromPlaylist);

BigBoxAutoPlaySettings bigBoxAutoPlaySettings = DataService.GetSettings();
gamesQuery = playlist.GetAllGames(false);
}

switch(bigBoxAutoPlaySettings.AutoPlayType)
if (!string.IsNullOrWhiteSpace(bigBoxAutoPlaySettings.FromPlatform))
{
case BigBoxAutoPlayType.RandomGame:
bigBoxAutoPlayer = new BigBoxAutoPlayerRandomGame(bigBoxAutoPlaySettings);
break;
gamesQuery = gamesQuery.Where(g => g.Platform == bigBoxAutoPlaySettings.FromPlatform);
}

case BigBoxAutoPlayType.RandomFavorite:
bigBoxAutoPlayer = new BigBoxAutoPlayerRandomFavorite(bigBoxAutoPlaySettings);
break;
if (!string.IsNullOrWhiteSpace(bigBoxAutoPlaySettings.SpecificGameId))
{
gamesQuery = gamesQuery.Where(g => g.Id == bigBoxAutoPlaySettings.SpecificGameId);
}

case BigBoxAutoPlayType.RandomGameFromPlatform:
bigBoxAutoPlayer = new BigBoxAutoPlayerRandomGameFromPlatform(bigBoxAutoPlaySettings);
break;
if (bigBoxAutoPlaySettings.OnlyFavorites.GetValueOrDefault())
{
gamesQuery = gamesQuery.Where(g => g.Favorite);
}

case BigBoxAutoPlayType.RandomGameFromPlaylist:
bigBoxAutoPlayer = new BigBoxAutoPlayerRandomGameFromPlaylist(bigBoxAutoPlaySettings);
break;
if (!bigBoxAutoPlaySettings.IncludeBroken.GetValueOrDefault())
{
gamesQuery = gamesQuery.Where(g => !g.Broken);
}

case BigBoxAutoPlayType.SpecificGame:
bigBoxAutoPlayer = new BigBoxAutoPlayerSpecificGame(bigBoxAutoPlaySettings);
break;
if (!bigBoxAutoPlaySettings.IncludeHidden.GetValueOrDefault())
{
gamesQuery = gamesQuery.Where(g => !g.Hide);
}

case BigBoxAutoPlayType.Off:
bigBoxAutoPlayer = new BigBoxAutoPlayerNone(bigBoxAutoPlaySettings);
break;
autoPlayGame = null;

default:
bigBoxAutoPlayer = new BigBoxAutoPlayerNone(bigBoxAutoPlaySettings);
break;
if(gamesQuery.Count() > 1)
{
Random random = new Random(Guid.NewGuid().GetHashCode());

int gameCount = gamesQuery.Count();
int randomIndex = random.Next(0, gamesQuery.Count());
autoPlayGame = gamesQuery.ElementAt(randomIndex);
}
else if(gamesQuery.Count() == 1)
{
autoPlayGame = gamesQuery.FirstOrDefault();
}

if(autoPlayGame != null)
{
// filter to find the game
PluginHelper.BigBoxMainViewModel.ShowGame(autoPlayGame, FilterType.None);

// launch the game
PluginHelper.BigBoxMainViewModel.PlayGame(autoPlayGame, null, null, null);
}
}

private static IGame autoPlayGame = null;

return bigBoxAutoPlayer;
private static void DoAutoPlay(object sender, RunWorkerCompletedEventArgs e)
{
if (autoPlayGame != null)
{

}
}

public abstract void AutoPlay();
private static void DoBackgroundDelay(object sender, DoWorkEventArgs e)
{
Thread.Sleep(2000);
}
}
}
16 changes: 0 additions & 16 deletions BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerNone.cs

This file was deleted.

37 changes: 0 additions & 37 deletions BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerRandomFavorite.cs

This file was deleted.

42 changes: 0 additions & 42 deletions BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerRandomGame.cs

This file was deleted.

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerSpecificGame.cs

This file was deleted.

7 changes: 0 additions & 7 deletions BigBoxAutoPlay/AutoPlayers/IBigBoxAutoPlayer.cs

This file was deleted.

Loading

0 comments on commit c396002

Please sign in to comment.