Exemple #1
0
        public IPlayableAdapter Create(PlayableType playableType)
        {
            switch (playableType)
            {
            case PlayableType.Audio:
            {
                return(new AudioPlayerAdapter());

                break;
            }

            case PlayableType.Video:
            {
                return(new VideoPlayerAdapter());

                break;
            }

            case PlayableType.Image:
            {
                return(new ImagePlayerAdapter());

                break;
            }

            default:
            {
                return(new AudioPlayerAdapter());

                break;
            }
            }
        }
Exemple #2
0
        public IActionResult Get(string typeString, string typeIdString)
        {
            //Validate type as PlayableType and typeId as GUID id:
            if (!Enum.TryParse(typeof(PlayableType), typeString, true, out object typeObject) ||
                !Guid.TryParse(typeIdString, out Guid typeId))
            {
                return(NotFound());
            }

            PlayableType type = (PlayableType)typeObject;

            //Get IPlayable for the given type and id:
            IPlayable iPlayable = null;

            if (type == PlayableType.Playlist)                                                //user playlist
            {
                iPlayable = _helper.GetUserPlaylistById(this.HttpContext, typeId.ToString()); //Check if user is authenticated and owns such playlist.
            }
            else if (type == PlayableType.PublicPlaylist)                                     //public playlist
            {
                iPlayable = _context.PublicPlaylists.FirstOrDefault(x => x.PublicPlaylistId == typeId);
            }
            else if (type == PlayableType.Album) //album
            {
                iPlayable = _context.Albums.Include(x1 => x1.Artist).FirstOrDefault(x => x.AlbumId == typeId);
            }

            if (iPlayable == null)
            {
                return(NotFound()); //no playable was found
            }
            //Load entry to access PlayableId
            _context.Entry(iPlayable).Reference(x => x.Playable).Load();

            //Load necessary related playable data (independent of playable type):
            iPlayable.Playable = _context.Playables
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.Video)
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.PublicSong)
                                 .ThenInclude(x => x.Album)
                                 .ThenInclude(x => x.Artist)
                                 .Include(x => x.PlayableSongs)
                                 .ThenInclude(x => x.Song)
                                 .ThenInclude(x => x.PrivateSong)
                                 .FirstOrDefault(x => x.PlayableId == iPlayable.Playable.PlayableId);

            PlayableVM playableVM = new PlayableVM(iPlayable);

            return(Ok(playableVM));
        }
Exemple #3
0
            public PercentageItem(
                List <decimal> probabilities, PlayableType playability, bool alreadyPlayed, bool offMeta)
            {
                // TODO: setting?
                bool onlyShowFirst = true;

                if (probabilities.Count == 0)
                {
                    Percentage = "";
                }
                else if (onlyShowFirst || probabilities.All(prob => prob == probabilities[0]))
                {
                    // All instances are at the same probability, just show one number.
                    Percentage = DecimalToPercent(probabilities[0]);
                }
                else
                {
                    Percentage = String.Join(" / ", probabilities.Select(prob => DecimalToPercent(prob)));
                }

                // Show the optimal icon if this card is at opponent's available mana.
                bool showOptimal = (!alreadyPlayed && playability == PlayableType.AtAvailableMana);

                OptimalVisibility = showOptimal ? Visibility.Visible : Visibility.Collapsed;
                // Show a coin if the opponent can play this by using their coin.
                bool showCoin = (!alreadyPlayed && playability == PlayableType.AtAvailableManaWithCoin);

                CoinVisibility = showCoin ? Visibility.Visible : Visibility.Collapsed;
                // Show an X if this card does not fit into this deck according to the current meta.
                bool showX = (offMeta && !showOptimal && !showCoin);

                XVisibility = showX ? Visibility.Visible : Visibility.Collapsed;

                // Hide stats for cards if there's nothing to show them.
                ItemVisibility = (Percentage == "" && !showOptimal && !showCoin && !showX)
                                        ? Visibility.Hidden : Visibility.Visible;

                // Dim stats for cards that aren't playable yet or have already been played.
                ItemOpacity = ((playability == PlayableType.AboveAvailableMana || alreadyPlayed) ? .3 : 1);
            }
Exemple #4
0
 /// <summary>
 /// Construct the square object with the respective playable Type
 /// </summary>
 /// <param name="type"></param>
 public Square(PlayableType type)
 {
     Type = type;
 }