public void PreviewBeatmapLevelUpdated(IPreviewBeatmapLevel beatmapLevel) // This is needed as it is impossible to get the IPlaylistSong through IDifficultyBeatmapLevel { if (beatmapLevel is IPlaylistSong) { selectedPlaylistSong = (IPlaylistSong)beatmapLevel; } }
public override bool Equals(IPlaylistSong other) { if (other == null) { return(false); } return(Hash == other?.Hash); }
/// <summary> /// Creates and returns a new <see cref="IPlaylistSong"/> of type <typeparamref name="T"/> with values populated from <paramref name="song"/>. /// </summary> /// <typeparam name="T">Target <see cref="IPlaylistSong"/> type.</typeparam> /// <param name="song">Song to clone the values from.</param> /// <returns>A new <see cref="IPlaylistSong"/> of type <typeparamref name="T"/>.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="song"/> is null.</exception> public static T ConvertTo <T>(this IPlaylistSong song) where T : IPlaylistSong, new() { if (song == null) { throw new ArgumentNullException(nameof(song), "song cannot be null"); } T ret = new T(); ret.Populate(song); return(ret); }
public void NoIdentifiers() { string? hash = null; string? levelId = null; string? key = null; string? songName = "Test"; string? levelAuthorName = "TestMapper"; IPlaylistSong songA = CreatePlaylistSong <LegacyPlaylistSong>(hash, levelId, songName, key, levelAuthorName); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Hash), "Song should not have Hash Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should not have LevelId Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Key), "Song should not have Key Identifier."); Assert.IsTrue(songA.Identifiers == Identifier.None, "Song should have None Identifier."); }
public void KeyOnly() { string? hash = null; string? levelId = null; string? key = "abcD"; string? songName = "Test"; string? levelAuthorName = "TestMapper"; IPlaylistSong songA = CreatePlaylistSong <LegacyPlaylistSong>(hash, levelId, songName, key, levelAuthorName); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Hash), "Song should not have Hash Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should not have LevelId Identifier."); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.Key), "Song should have Key Identifier."); Assert.IsFalse(songA.Identifiers == Identifier.None, "Song should not have None Identifier."); Assert.AreEqual(key.ToUpper(), songA.Key, "Song did not capitalize Key."); }
public static string GetIdentifierForPlaylistSong(IPlaylistSong playlistSong) { if (playlistSong.Identifiers.HasFlag(Identifier.Hash)) { return(playlistSong.Hash); } if (playlistSong.Identifiers.HasFlag(Identifier.Key)) { return(playlistSong.Key); } if (playlistSong.Identifiers.HasFlag(Identifier.LevelId)) { return(playlistSong.LevelId); } return(""); }
public void KeyOnly_ctor() { string? hash = null; string? levelId = null; string? key = "abcD"; string? songName = "Test"; string? levelAuthorName = "TestMapper"; string expectedKey = key.ToUpper(); IPlaylistSong songA = CreatePlaylistSongWithFactory(PlaylistSongFactory, hash, levelId, songName, key, levelAuthorName); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Hash), "Song should not have Hash Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should not have LevelId Identifier."); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.Key), "Song should have Key Identifier."); Assert.IsFalse(songA.Identifiers == Identifier.None, "Song should not have None Identifier."); Assert.IsTrue(expectedKey.Equals(songA.Key, StringComparison.OrdinalIgnoreCase), "Song did not assign the Key correctly."); Assert.AreEqual(expectedKey, songA.Key, "Song did not capitalize Key."); }
public static async Task <bool> UpdateSongKeyAsync(this IPlaylistSong song, bool overwrite = false) { if (song?.Hash == null || string.IsNullOrEmpty(song.Hash) || (!overwrite && !string.IsNullOrEmpty(song.Key))) { return(false); } var result = await WebUtils.SongInfoManager.GetSongByHashAsync(song.Hash, CancellationToken.None).ConfigureAwait(false); var scrapedSong = result.Song; if (scrapedSong == null) { return(false); } song.Key = scrapedSong.Key; return(true); }
public void HashOnly_EmptyLevelId_ctor() { string? hash = "sDFKLjSDLFKJ"; string? levelId = ""; string? key = null; string? songName = "Test"; string? levelAuthorName = "TestMapper"; string expectedHash = hash.ToUpper(); string expectedLevelId = PlaylistSong.CustomLevelIdPrefix + expectedHash; IPlaylistSong songA = CreatePlaylistSongWithFactory(PlaylistSongFactory, hash, levelId, songName, key, levelAuthorName); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.Hash), "Song should have Hash Identifier."); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should have LevelId Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Key), "Song should not have Key Identifier."); Assert.IsFalse(songA.Identifiers == Identifier.None, "Song should not have None Identifier."); Assert.AreEqual(expectedHash, songA.Hash, "Song did not capitalize Hash."); Assert.IsTrue(expectedLevelId.Equals(songA.LevelId, StringComparison.OrdinalIgnoreCase), "Song did not assign the correct LevelId."); Assert.AreEqual(expectedLevelId, songA.LevelId, "Song did not capitalize the hash part of the LevelId."); }
public void HashAndLevelId_NotMatched_HashFirst() { string? hash = "SDFKLJSDLFKj"; string? levelId = PlaylistSong.CustomLevelIdPrefix + hash + "D"; string? key = null; string? songName = "Test"; string? levelAuthorName = "TestMapper"; bool assignHashFirst = true; string expectedHash = hash.ToUpper() + "D"; string expectedLevelId = PlaylistSong.CustomLevelIdPrefix + hash.ToUpper() + "D"; IPlaylistSong songA = CreatePlaylistSong <LegacyPlaylistSong>(hash, levelId, songName, key, levelAuthorName, assignHashFirst); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.Hash), "Song should have Hash Identifier."); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should have LevelId Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Key), "Song should not have Key Identifier."); Assert.IsFalse(songA.Identifiers == Identifier.None, "Song should not have None Identifier."); Assert.AreEqual(expectedHash, songA.Hash, "Song did not change hash to match LevelId."); Assert.AreEqual(expectedLevelId, songA.LevelId, "Song did not keep the original LevelId."); }
/// <summary> /// Populates the target <see cref="IPlaylistSong"/> with values from <paramref name="song"/>. /// </summary> /// <param name="target"></param> /// <param name="song"></param> /// <param name="overwriteTarget">If true, overwrites existing values on <paramref name="target"/></param> public static void Populate(this IPlaylistSong target, ISong song, bool overwriteTarget = false) { if (target == null) { throw new ArgumentNullException(nameof(target), "target song cannot be null."); } if (song == null) { throw new ArgumentNullException(nameof(song), "source song cannot be null."); } if (overwriteTarget) { target.LevelId = song.LevelId; target.Hash = song.Hash; target.Key = song.Key; if (song is IPlaylistSong playlistSong) { target.DateAdded = playlistSong.DateAdded; } else { target.DateAdded = Utilities.CurrentTime; } target.Name = song.Name; target.LevelAuthorName = song.LevelAuthorName; } else { target.LevelId ??= song.LevelId; target.Hash ??= song.Hash; target.Key ??= song.Key; if (song is IPlaylistSong playlistSong) { target.DateAdded ??= playlistSong.DateAdded; } else { target.DateAdded ??= Utilities.CurrentTime; } target.Name ??= song.Name; target.LevelAuthorName ??= song.LevelAuthorName; } }
public void LevelIdOnly_EmptyHashFirst() { string songHash = "LSKDFJLKJSDf"; string? hash = ""; string? levelId = PlaylistSong.CustomLevelIdPrefix + songHash; string? key = null; string? songName = "Test"; string? levelAuthorName = "TestMapper"; bool assignHashFirst = true; string expectedHash = songHash.ToUpper(); string expectedLevelId = PlaylistSong.CustomLevelIdPrefix + expectedHash; IPlaylistSong songA = CreatePlaylistSong <LegacyPlaylistSong>(hash, levelId, songName, key, levelAuthorName, assignHashFirst); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.Hash), "Song should have Hash Identifier."); Assert.IsTrue(songA.Identifiers.HasFlag(Identifier.LevelId), "Song should have LevelId Identifier."); Assert.IsFalse(songA.Identifiers.HasFlag(Identifier.Key), "Song should not have Key Identifier."); Assert.IsFalse(songA.Identifiers == Identifier.None, "Song should not have None Identifier."); Assert.AreEqual(expectedLevelId, songA.LevelId, "Song did not capitalize the hash part of the LevelId."); Assert.IsTrue(expectedHash.Equals(songA.Hash, StringComparison.OrdinalIgnoreCase), "Song did not assign the correct LevelId."); Assert.AreEqual(expectedHash, songA.Hash, "Song did not capitalize Hash."); }
public override bool Equals(IPlaylistSong other) => this.LevelId == other.LevelId;
///<inheritdoc/> public abstract bool Equals(IPlaylistSong other);
internal static void RaisePlaylistSongSelected(IPlaylistSong playlistSong) => playlistSongSelected?.Invoke(playlistSong);