-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration UI and reworked the auto start logic
- Loading branch information
SuplexLuthor
committed
Jan 29, 2022
1 parent
222941f
commit c396002
Showing
29 changed files
with
1,117 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerRandomFavorite.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerRandomGameFromPlatform.cs
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerRandomGameFromPlaylist.cs
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
BigBoxAutoPlay/AutoPlayers/BigBoxAutoPlayerSpecificGame.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.