Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add difficulty calculation for maps loaded from osu!'s db. #676

Merged
merged 7 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 1 addition & 89 deletions Quaver.Shared/Database/Maps/MapDatabaseCache.cs
Expand Up @@ -30,11 +30,6 @@ public static class MapDatabaseCache
/// </summary>
public static readonly string DatabasePath = ConfigManager.GameDirectory + "/quaver.db";

/// <summary>
/// Dictates if we currently have loaded maps from other games.
/// </summary>
public static bool LoadedMapsFromOtherGames { get; private set; }

/// <summary>
/// List of maps to force update after editing them.
/// </summary>
Expand Down Expand Up @@ -236,82 +231,6 @@ public static Map FindSet(int id)
}
}

/// <summary>
/// Reads the osu!.db file defined in config and loads all of those maps into the cache.
/// </summary>
private static IEnumerable<Map> LoadOsuBeatmapDatabase()
{
try
{
var db = OsuDb.Read(ConfigManager.OsuDbPath.Value);
MapManager.OsuSongsFolder = Path.GetDirectoryName(ConfigManager.OsuDbPath.Value) + "/Songs/";

// Find all osu! maps that are 4K and 7K and order them by their difficulty value.
var osuBeatmaps = db.Beatmaps.Where(x => x.GameMode == GameMode.Mania && ( x.CircleSize == 4 || x.CircleSize == 7 )).ToList();
osuBeatmaps = osuBeatmaps.OrderBy(x => x.DiffStarRatingMania.ContainsKey(Mods.None) ? x.DiffStarRatingMania[Mods.None] : 0).ToList();

var osuToQuaverMaps = new List<Map>();

foreach (var map in osuBeatmaps)
{
var newMap = new Map
{
Md5Checksum = map.BeatmapChecksum,
Directory = map.FolderName,
Path = map.BeatmapFileName,
Artist = map.Artist,
Title = map.Title,
MapSetId = -1,
MapId = -1,
DifficultyName = map.Version,
RankedStatus = RankedStatus.NotSubmitted,
Creator = map.Creator,
AudioPath = map.AudioFileName,
AudioPreviewTime = map.AudioPreviewTime,
Description = $"",
Source = map.SongSource,
Tags = map.SongTags,
// ReSharper disable once CompareOfFloatsByEqualityOperator
Mode = map.CircleSize == 4 ? Quaver.API.Enums.GameMode.Keys4 : Quaver.API.Enums.GameMode.Keys7,
SongLength = map.TotalTime,
Game = MapGame.Osu,
BackgroundPath = "",
RegularNoteCount = map.CountHitCircles,
LongNoteCount = map.CountSliders,
};

// Get the BPM of the osu! maps
if (map.TimingPoints != null)
{
try
{
newMap.Bpm = Math.Round(60000 / map.TimingPoints.Find(x => x.MsPerQuarter > 0).MsPerQuarter, 0);
}
catch (Exception e)
{
newMap.Bpm = 0;
}
}

osuToQuaverMaps.Add(newMap);
}

return osuToQuaverMaps;
}
catch (Exception e)
{
Logger.Error(e, LogType.Runtime);

var game = GameBase.Game as QuaverGame;
var screen = game?.CurrentScreen;

if (screen != null)
NotificationManager.Show(NotificationLevel.Error, "Failed to load maps from other games. Is your db path correct in config?");

return new List<Map>();
}
}

/// <summary>
/// Fetches all maps, groups them into mapsets, sets them to allow them to be played.
/// </summary>
Expand All @@ -320,14 +239,7 @@ public static void OrderAndSetMapsets()
var maps = FetchAll();

if (ConfigManager.AutoLoadOsuBeatmaps.Value)
{
maps = maps.Concat(LoadOsuBeatmapDatabase()).ToList();
LoadedMapsFromOtherGames = true;
}
else
{
LoadedMapsFromOtherGames = false;
}
maps = maps.Concat(OtherGameMapDatabaseCache.Load()).ToList();

var mapsets = MapsetHelper.ConvertMapsToMapsets(maps);
MapManager.Mapsets = MapsetHelper.OrderMapsByDifficulty(MapsetHelper.OrderMapsetsByArtist(mapsets));
Expand Down
9 changes: 9 additions & 0 deletions Quaver.Shared/Database/Maps/OtherGameCacheAction.cs
@@ -0,0 +1,9 @@
namespace Quaver.Shared.Database.Maps
{
public enum OtherGameCacheAction
{
Add,
Delete,
Update
}
}
7 changes: 7 additions & 0 deletions Quaver.Shared/Database/Maps/OtherGameMap.cs
@@ -0,0 +1,7 @@
namespace Quaver.Shared.Database.Maps
{
public class OtherGameMap : Map
{

}
}