Skip to content

Commit

Permalink
Merge pull request #676 from Swan/other-games-diff-calc
Browse files Browse the repository at this point in the history
Add difficulty calculation for maps loaded from osu!'s db.
  • Loading branch information
Swan committed Mar 5, 2019
2 parents 502a18a + 84075f9 commit 545bb3a
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 101 deletions.
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
{

}
}

0 comments on commit 545bb3a

Please sign in to comment.