Skip to content

Commit

Permalink
Add loop beatmap on collection
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloYeew committed Feb 3, 2025
1 parent 6601cd4 commit a8db5f5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Renako.Game/Audio/RenakoAudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public partial class RenakoAudioManager : CompositeDrawable
[Resolved]
private GameHost host { get; set; }

[Resolved]
private BeatmapManager beatmapManager { get; set; }

[BackgroundDependencyLoader]
private void load(AudioManager audioManagerSource)
{
Expand Down Expand Up @@ -88,6 +91,11 @@ private void changeTrackOnBeatmapSetChanged(BeatmapSet oldBeatmapSet, BeatmapSet
}

Track.Start();

Track.Completed += () =>
{
beatmapManager.NextBeatmapSet();
};
}

/// <summary>
Expand Down
44 changes: 44 additions & 0 deletions Renako.Game/Beatmaps/BeatmapManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;

namespace Renako.Game.Beatmaps;

/// <summary>
/// Class that contain all function related to beatmap and collection of beatmaps.
/// </summary>
public partial class BeatmapManager : CompositeDrawable
{
[Resolved]
private BeatmapsCollection beatmapsCollection { get; set; }

[Resolved]
private WorkingBeatmap workingBeatmap { get; set; }

// [BackgroundDependencyLoader]
// private void load(BeatmapsCollection beatmapsCollection, WorkingBeatmap workingBeatmap)
// {
// this.beatmapsCollection = beatmapsCollection;
// this.workingBeatmap = workingBeatmap;
// }

/// <summary>
/// Set the working beatmap to the next beatmap in the collection.
/// </summary>
/// <param name="random">Whether to set the next beatmap randomly.</param>
public void NextBeatmapSet(bool random = false)
{
if (random)
{
workingBeatmap.BeatmapSet = beatmapsCollection.BeatmapSets[RNG.Next(beatmapsCollection.BeatmapSets.Count)];
}
else
{
int currentBeatmapSetIndex = beatmapsCollection.BeatmapSets.IndexOf(workingBeatmap.BeatmapSet);

workingBeatmap.BeatmapSet = currentBeatmapSetIndex == beatmapsCollection.BeatmapSets.Count - 1 ? beatmapsCollection.BeatmapSets[0] : beatmapsCollection.BeatmapSets[currentBeatmapSetIndex + 1];

workingBeatmap.Beatmap = beatmapsCollection.GetFirstBeatmapFromBeatmapSet(workingBeatmap.BeatmapSet);
}
}
}
10 changes: 10 additions & 0 deletions Renako.Game/Beatmaps/BeatmapsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public Beatmap[] GetBeatmapsFromBeatmapSet(BeatmapSet beatmapSet, bool sortByDif
return beatmaps;
}

/// <summary>
/// Get the first <see cref="Beatmap"/> from the <see cref="BeatmapSet"/> for set as default.
/// </summary>
/// <param name="beatmapSet">The <see cref="BeatmapSet"/> to get the <see cref="Beatmap"/> from</param>
/// <returns>The first <see cref="Beatmap"/> from the <see cref="BeatmapSet"/></returns>
public Beatmap GetFirstBeatmapFromBeatmapSet(BeatmapSet beatmapSet)
{
return GetBeatmapsFromBeatmapSet(beatmapSet, false).FirstOrDefault();
}

/// <summary>
/// Get the min and max difficulty rating from <see cref="Beatmap"/> in the <see cref="BeatmapSet"/>
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions Renako.Game/RenakoGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ protected override void LoadComplete()
else
{
WorkingBeatmap.BeatmapSet = BeatmapsCollection.GetRandomBeatmapSet();
Beatmap[] beatmapsList = BeatmapsCollection.GetBeatmapsFromBeatmapSet(WorkingBeatmap.BeatmapSet);
if (beatmapsList.Length > 0)
WorkingBeatmap.Beatmap = beatmapsList[0];
WorkingBeatmap.Beatmap = BeatmapsCollection.GetFirstBeatmapFromBeatmapSet(WorkingBeatmap.BeatmapSet);
}

RenakoAudioManager.Track?.Stop();
Expand Down
4 changes: 4 additions & 0 deletions Renako.Game/RenakoGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public partial class RenakoGameBase : osu.Framework.Game

protected WorkingBeatmap WorkingBeatmap;

protected BeatmapManager BeatmapManager;

protected RenakoGameBase()
{
// Ensure game and tests scale with window size and screen DPI.
Expand Down Expand Up @@ -105,6 +107,8 @@ private void load()
dependencies.CacheAs(LocalConfig);
dependencies.CacheAs(BeatmapsCollection = new BeatmapsCollection());
dependencies.CacheAs(WorkingBeatmap = new WorkingBeatmap());
dependencies.CacheAs(BeatmapManager = new BeatmapManager());
Add(BeatmapManager);
dependencies.CacheAs(this);
}

Expand Down

0 comments on commit a8db5f5

Please sign in to comment.