Skip to content

Commit

Permalink
Fixed Playlist.BeatSaber
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingabopp committed Jul 5, 2021
1 parent b7c3f45 commit 43b4c0f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 22 deletions.
32 changes: 32 additions & 0 deletions BeatSaberPlaylistsLib.BeatSaber/BeatSaberPlaylistsLib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 12 additions & 17 deletions BeatSaberPlaylistsLib.BeatSaber/Types/Playlist.BeatSaber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected static IEnumerator<YieldInstruction> SpriteLoadCoroutine()
BeatSaber.SharedCoroutineStarter.instance.StartCoroutine(SpriteLoadCoroutine());
}

#region IDeferredSpriteLoad
#region IDeferredSpriteLoad

/// <inheritdoc/>
public event EventHandler? SpriteLoaded;
Expand Down Expand Up @@ -185,10 +185,12 @@ public abstract partial class Playlist<T> : BeatSaber.IPlaylist, BeatSaber.IBeat
/// Returns a new array of IPreviewBeatmapLevels in this playlist.
/// </summary>
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
BeatSaber.IPreviewBeatmapLevel[] BeatSaber.IBeatmapLevelCollection.beatmapLevels {
BeatSaber.IPreviewBeatmapLevel[] BeatSaber.IBeatmapLevelCollection.beatmapLevels
{
get
{
Songs.ForEach(delegate(T s) {
Songs.ForEach(delegate (T s)
{
if (s is PlaylistSong playlistSong)
{
playlistSong.RefreshFromSongCore();
Expand All @@ -204,7 +206,8 @@ public BeatSaber.IPreviewBeatmapLevel[] BeatmapLevels
{
get
{
Songs.ForEach(delegate (T s) {
Songs.ForEach(delegate (T s)
{
if (s is PlaylistSong playlistSong)
{
playlistSong.RefreshFromSongCore();
Expand All @@ -220,12 +223,7 @@ public BeatSaber.IPreviewBeatmapLevel[] BeatmapLevels
{
if (beatmap == null)
return null;
IPlaylistSong? song = Add(new T()
{
LevelId = beatmap.levelID,
Name = beatmap.songName,
LevelAuthorName = beatmap.levelAuthorName,
});
IPlaylistSong? song = Add(CreateFromByLevelId(beatmap.levelID, beatmap.songName, null, beatmap.levelAuthorName));
song?.SetPreviewBeatmap(beatmap);
return song;
}
Expand All @@ -239,13 +237,10 @@ public BeatSaber.IPreviewBeatmapLevel[] BeatmapLevels
Difficulty difficulty = new Difficulty();
difficulty.BeatmapDifficulty = beatmap.difficulty;
difficulty.Characteristic = beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName;
IPlaylistSong? song = Add(new T()
{
LevelId = beatmap.level.levelID,
Name = beatmap.level.songName,
LevelAuthorName = beatmap.level.levelAuthorName,
Difficulties = new List<Difficulty>{ difficulty },
});
IPlaylistSong? song = Add(CreateFromByLevelId(beatmap.level.levelID, beatmap.level.songName, null, beatmap.level.levelAuthorName));
if (song != null)
song.Difficulties = new List<Difficulty> { difficulty };

song?.SetPreviewBeatmap(beatmap.level);
return song;
}
Expand Down
14 changes: 13 additions & 1 deletion BeatSyncPlaylistLibTests/Mock/MockPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override MockPlaylistSong CreateFrom(ISong song)
}

///<inheritdoc/>
protected override MockPlaylistSong CreateFrom(string songHash, string? songName, string? songKey, string? mapper)
protected override MockPlaylistSong CreateFromByHash(string songHash, string? songName, string? songKey, string? mapper)
{
return new MockPlaylistSong()
{
Expand All @@ -68,5 +68,17 @@ protected override MockPlaylistSong CreateFrom(string songHash, string? songName
LevelAuthorName = mapper
};
}

///<inheritdoc/>
protected override MockPlaylistSong CreateFromByLevelId(string levelId, string? songName, string? songKey, string? mapper)
{
return new MockPlaylistSong()
{
LevelId = levelId,
Name = songName,
Key = songKey,
LevelAuthorName = mapper
};
}
}
}
14 changes: 13 additions & 1 deletion Shared/Blist/BlistPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected override BlistPlaylistSong CreateFrom(ISong song)
}

///<inheritdoc/>
protected override BlistPlaylistSong CreateFrom(string songHash, string? songName, string? songKey, string? mapper)
protected override BlistPlaylistSong CreateFromByHash(string songHash, string? songName, string? songKey, string? mapper)
{
return new BlistPlaylistSong()
{
Expand All @@ -107,6 +107,18 @@ protected override BlistPlaylistSong CreateFrom(string songHash, string? songNam
};
}

///<inheritdoc/>
protected override BlistPlaylistSong CreateFromByLevelId(string levelId, string? songName, string? songKey, string? mapper)
{
return new BlistPlaylistSong()
{
LevelId = levelId,
Name = songName,
Key = songKey,
LevelAuthorName = mapper
};
}

///<inheritdoc/>
public override Stream GetCoverStream()
{
Expand Down
14 changes: 13 additions & 1 deletion Shared/Legacy/LegacyPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override LegacyPlaylistSong CreateFrom(ISong song)
}

///<inheritdoc/>
protected override LegacyPlaylistSong CreateFrom(string songHash, string? songName, string? songKey, string? mapper)
protected override LegacyPlaylistSong CreateFromByHash(string songHash, string? songName, string? songKey, string? mapper)
{
return new LegacyPlaylistSong()
{
Expand All @@ -83,6 +83,18 @@ protected override LegacyPlaylistSong CreateFrom(string songHash, string? songNa
};
}

///<inheritdoc/>
protected override LegacyPlaylistSong CreateFromByLevelId(string levelId, string? songName, string? songKey, string? mapper)
{
return new LegacyPlaylistSong()
{
LevelId = levelId,
Name = songName,
Key = songKey,
LevelAuthorName = mapper
};
}

///<inheritdoc/>
[DataMember]
[JsonProperty("playlistTitle", Order = -10)]
Expand Down
14 changes: 12 additions & 2 deletions Shared/Types/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ public IPlaylistSong this[int index]
/// <param name="songKey"></param>
/// <param name="mapper"></param>
/// <returns></returns>
protected abstract T CreateFrom(string songHash, string? songName, string? songKey, string? mapper);
protected abstract T CreateFromByHash(string songHash, string? songName, string? songKey, string? mapper);

/// <summary>
/// Creates a new <see cref="IPlaylistSong"/> of type <typeparamref name="T"/> from the given values.
/// </summary>
/// <param name="levelId"></param>
/// <param name="songName"></param>
/// <param name="songKey"></param>
/// <param name="mapper"></param>
/// <returns></returns>
protected abstract T CreateFromByLevelId(string levelId, string? songName, string? songKey, string? mapper);

/// <inheritdoc/>
public virtual IPlaylistSong? Add(ISong song)
Expand All @@ -183,7 +193,7 @@ public IPlaylistSong this[int index]

/// <inheritdoc/>
public virtual IPlaylistSong? Add(string songHash, string? songName, string? songKey, string? mapper) =>
Add(CreateFrom(songHash, songName, songKey, mapper));
Add(CreateFromByHash(songHash, songName, songKey, mapper));

/// <inheritdoc/>
public virtual IPlaylistSong? Add(IPlaylistSong item) => Add((ISong)item);
Expand Down

0 comments on commit 43b4c0f

Please sign in to comment.