public void SetNextEpisode(bool onlyRandom) { if (PlaylistObjects.Count == 0) { return; } // find the next episode to play NextEpisode = null; if (DefaultPlayOrderEnum == PlaylistPlayOrder.Sequential && !onlyRandom) { while (true) { foreach (VM_PlaylistItem pli in PlaylistObjects) { if (pli.ItemType == PlaylistItemType.Episode) { VM_AnimeEpisode_User epTemp = pli.PlaylistItem as VM_AnimeEpisode_User; if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; break; } } if (pli.ItemType == PlaylistItemType.AnimeSeries) { VM_AnimeSeries_User ser = (VM_AnimeSeries_User)pli.PlaylistItem; VM_MainListHelper.Instance.UpdateAll(); ser.RefreshEpisodes(); List <VM_AnimeEpisode_User> eps = ser.AllEpisodes.OrderBy(a => a.EpisodeType).ThenBy(a => a.EpisodeNumber).ToList(); bool foundEp = false; foreach (VM_AnimeEpisode_User epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } } if (foundEp) { break; } } } break; } } else // random { // get all the candidate episodes List <VM_AnimeEpisode_User> canidateEps = new List <VM_AnimeEpisode_User>(); foreach (VM_PlaylistItem pli in PlaylistObjects) { if (pli.ItemType == PlaylistItemType.Episode) { VM_AnimeEpisode_User epTemp = pli.PlaylistItem as VM_AnimeEpisode_User; if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } if (pli.ItemType == PlaylistItemType.AnimeSeries) { VM_AnimeSeries_User ser = (VM_AnimeSeries_User)pli.PlaylistItem; VM_MainListHelper.Instance.UpdateAll(); ser.RefreshEpisodes(); List <VM_AnimeEpisode_User> eps = ser.AllEpisodes; foreach (VM_AnimeEpisode_User epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } } } } // pick a random object from the play list if (canidateEps.Count > 0) { NextEpisode = canidateEps[epRandom.Next(0, canidateEps.Count)]; } } if (NextEpisode != null) { NextEpisode.SetTvDBInfo(); NextEpisode.RefreshAnime(); AniDB_Anime = NextEpisode.AniDBAnime; if (VM_MainListHelper.Instance.AllSeriesDictionary.ContainsKey(NextEpisode.AnimeSeriesID)) { Series = VM_MainListHelper.Instance.AllSeriesDictionary[NextEpisode.AnimeSeriesID]; } } }
public void SetNextEpisode(bool onlyRandom) { if (PlaylistObjects.Count == 0) { return; } // find the next episode to play NextEpisode = null; if (DefaultPlayOrderEnum == PlaylistPlayOrder.Sequential && !onlyRandom) { bool foundEp = false; while (!foundEp) { foreach (PlaylistItemVM pli in PlaylistObjects) { if (pli.ItemType == JMMClient.PlaylistItemType.Episode) { AnimeEpisodeVM epTemp = pli.PlaylistItem as AnimeEpisodeVM; if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } if (pli.ItemType == JMMClient.PlaylistItemType.AnimeSeries) { AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM; ser.RefreshBase(); ser.RefreshEpisodes(); List <AnimeEpisodeVM> eps = ser.AllEpisodes; List <SortPropOrFieldAndDirection> sortCriteria = new List <SortPropOrFieldAndDirection>(); sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeType", false, JMMClient.SortType.eInteger)); sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, JMMClient.SortType.eInteger)); eps = Sorting.MultiSort <AnimeEpisodeVM>(eps, sortCriteria); foreach (AnimeEpisodeVM epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { NextEpisode = epTemp; foundEp = true; break; } } } if (foundEp) { break; } } } break; } } else // random { // get all the candidate episodes List <AnimeEpisodeVM> canidateEps = new List <AnimeEpisodeVM>(); foreach (PlaylistItemVM pli in PlaylistObjects) { if (pli.ItemType == JMMClient.PlaylistItemType.Episode) { AnimeEpisodeVM epTemp = pli.PlaylistItem as AnimeEpisodeVM; if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } if (pli.ItemType == JMMClient.PlaylistItemType.AnimeSeries) { AnimeSeriesVM ser = pli.PlaylistItem as AnimeSeriesVM; ser.RefreshBase(); ser.RefreshEpisodes(); List <AnimeEpisodeVM> eps = ser.AllEpisodes; foreach (AnimeEpisodeVM epTemp in eps) { if (epTemp.EpisodeTypeEnum == EpisodeType.Episode || epTemp.EpisodeTypeEnum == EpisodeType.Special) { if (CanUseEpisode(this, epTemp)) { canidateEps.Add(epTemp); } } } } } // pick a random object from the play list if (canidateEps.Count > 0) { NextEpisode = canidateEps[epRandom.Next(0, canidateEps.Count)]; } } if (NextEpisode != null) { NextEpisode.SetTvDBInfo(); NextEpisode.RefreshAnime(); AniDB_Anime = NextEpisode.AniDB_Anime; if (MainListHelperVM.Instance.AllSeriesDictionary.ContainsKey(NextEpisode.AnimeSeriesID)) { Series = MainListHelperVM.Instance.AllSeriesDictionary[NextEpisode.AnimeSeriesID]; } } }