Skip to content

Commit

Permalink
Add: 'mods' search modifier
Browse files Browse the repository at this point in the history
works just like selecting mods ingame & searching with them (only star rating is affected in search)
  • Loading branch information
Piotrekol committed Sep 23, 2018
1 parent 1dc0e7b commit 61bb66e
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 58 deletions.
3 changes: 3 additions & 0 deletions App/Misc/BeatmapListFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
using System.Windows.Forms;
using BrightIdeasSoftware;
using CollectionManager.DataTypes;
using CollectionManager.Enums;
using CollectionManagerExtensionsDll.Modules.BeatmapFilter;

namespace App.Misc
{
public class BeatmapListFilter: IModelFilter
{
private readonly BeatmapFilter _beatmapFilter;
public Mods CurrentMods => _beatmapFilter.CurrentMods;
public PlayMode CurrentPlayMode => _beatmapFilter.CurrentPlayMode;
private string _searchString;
private readonly object _searchStringLockingObject = new object();
private Timer timer;
Expand Down
6 changes: 6 additions & 0 deletions App/Presenters/Controls/BeatmapListingPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using CollectionManager.DataTypes;
using App.Interfaces;
using App.Misc;
using GuiComponents.Interfaces;

namespace App.Presenters.Controls
Expand Down Expand Up @@ -44,6 +45,11 @@ public BeatmapListingPresenter(IBeatmapListingView view, IBeatmapListingModel mo

private void _model_FilteringFinished(object sender, EventArgs e)
{
if (_model.GetFilter() is BeatmapListFilter filter)
{
_view.SetCurrentPlayMode(filter.CurrentPlayMode);
_view.SetCurrentMods(filter.CurrentMods);
}
_view.FilteringFinished();
}

Expand Down
2 changes: 1 addition & 1 deletion CollectionManagerDll/DataTypes/Beatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public double Stars(PlayMode playMode, Mods mods=Mods.Omod)
mods = mods & Mods.MapChanging;
if (ModPpStars.ContainsKey(_playMode) && ModPpStars[_playMode].ContainsKey((int)mods))
return ModPpStars[_playMode][(int)mods];
return 0d;
return -1d;
}

public double MaxBpm { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="Modules\CollectionListGenerator\ListTypes\RedditCodeGenerator.cs" />
<Compile Include="Modules\CollectionListGenerator\ListTypes\OsuBbCodeGenerator.cs" />
<Compile Include="Modules\CollectionListGenerator\ListTypes\UserListGenerator.cs" />
<Compile Include="Modules\DifficultyCalculator.cs" />
<Compile Include="Modules\DownloadManager\API\CookieAwareWebClient.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using CollectionManager.DataTypes;
using CollectionManager.Enums;
Expand Down Expand Up @@ -58,9 +59,17 @@ public void UpdateSearch(string searchString)
{
BeatmapHashHidden[beatmap.Md5] = false;
}

if (!words.Any(s => s.Contains("mods")))
{
CurrentMods = Mods.Omod;
}

foreach (string w in words)
{
searchFilter filter = GetSearchFilter(w);
if(filter==null)
continue;

foreach (var b in _beatmaps)
{
Expand All @@ -72,6 +81,10 @@ public void UpdateSearch(string searchString)
}
}
}

public Mods CurrentMods { get; private set; } = Mods.Omod;
public PlayMode CurrentPlayMode { get; private set; } = PlayMode.Osu;
private double GetStars(Beatmap b) => b.Stars(CurrentPlayMode, CurrentMods);
/// <summary>
/// Returns beatmapFilter delegate for specified searchWord.
/// Unimplemented: key/keys/speed/played/unplayed
Expand All @@ -96,10 +109,9 @@ private searchFilter GetSearchFilter(string searchWord)
num = Double.Parse(matchNum.Groups[0].Value, nfi);
switch (key)
{

case "star":
case "stars":
return delegate (Beatmap b) { return isPatternMatch(Math.Round(b.StarsNomod, 2), op, num); };
return delegate (Beatmap b) { return isPatternMatch(Math.Round(GetStars(b), 2), op, num); };

case "cs":
return delegate (Beatmap b) { return isPatternMatch(Math.Round((double)b.CircleSize, 1), op, num) && b.PlayMode != PlayMode.OsuMania && b.PlayMode != PlayMode.Taiko; };
Expand Down Expand Up @@ -131,6 +143,16 @@ private searchFilter GetSearchFilter(string searchWord)

switch (key)
{
case "mods":
var splitMods = Regex.Split(val, @"([A-Za-z]{2})").Where(s=>!string.IsNullOrEmpty(s)).ToList();
Mods mods = Mods.Omod;
foreach (var mod in splitMods)
{
if (Enum.TryParse(mod, true, out Mods parsedMod))
mods |= parsedMod;
}
CurrentMods = mods;
return null;
case "artist":
var artist = val.Replace(SpaceReplacement, " ");
return delegate (Beatmap b) { return isArtistMatch(b, artist); };
Expand All @@ -143,6 +165,7 @@ private searchFilter GetSearchFilter(string searchWord)
break;
case "mode":
num = descriptorToNum(val, ModePairs);
CurrentPlayMode = (PlayMode)num;
return delegate (Beatmap b) { return isPatternMatch((double)b.PlayMode, op, num); };
case "status":
num = descriptorToNum(val, StatusPairs);
Expand Down
122 changes: 122 additions & 0 deletions CollectionManagerExtensionsDll/Modules/DifficultyCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using CollectionManager.DataTypes;

namespace CollectionManagerExtensionsDll.Modules
{
public class DifficultyCalculator
{
public class DifficultyCalculatorResult
{
public float Od { get; set; }
public float Ar { get; set; }
public float Cs { get; set; }
public float Hp { get; set; }
public double MinBpm { get; set; }
public double MaxBpm { get; set; }
}
readonly float od0_ms = 79.5f,
od10_ms = 19.5f,
ar0_ms = 1800f,
ar5_ms = 1200f,
ar10_ms = 450f;

readonly float od_ms_step = 6,
ar_ms_step1 = 120, // ar0-5
ar_ms_step2 = 150; // ar5-10

public DifficultyCalculatorResult ApplyMods(Beatmap map, Mods mods, DifficultyCalculatorResult result=null)
{
if(result==null)
result = new DifficultyCalculatorResult();

result.Od = map.OverallDifficulty;
result.Ar = map.ApproachRate;
result.Cs = map.CircleSize;
result.Hp = map.HpDrainRate;
result.MinBpm = map.MinBpm;
result.MaxBpm = map.MaxBpm;

if ((mods & Mods.MapChanging) == 0)
{
return result;
}

float speed = 1;
if ((mods & Mods.Dt) != 0 || (mods & Mods.Nc) != 0)
speed *= 1.5f;
if ((mods & Mods.Ht) != 0)
speed *= 0.75f;

float od_multiplier = 1;
if ((mods & Mods.Hr) != 0)
od_multiplier *= 1.4f;
if ((mods & Mods.Ez) != 0)
od_multiplier *= 0.5f;

result.Od *= od_multiplier;
float odms = od0_ms - (float)Math.Ceiling(od_ms_step * result.Od);
//hp
if ((mods & Mods.Ez) != 0)
result.Hp *= 0.5f;
else if ((mods & Mods.Hr) != 0)
result.Hp *= 1.4f;

//bpm
double modifier = 1;
if ((mods & Mods.Dt) != 0)
{
modifier *= 1.5;
}
else if ((mods & Mods.Ht) != 0)
{
modifier *= 0.75;
}

result.MinBpm *= modifier;
result.MaxBpm *= modifier;

//ar
float ar_multiplier = 1;

if ((mods & Mods.Hr) != 0)
ar_multiplier *= 1.4f;
if ((mods & Mods.Ez) != 0)
ar_multiplier *= 0.5f;

result.Ar *= ar_multiplier;
float arms = result.Ar <= 5
? (ar0_ms - ar_ms_step1 * result.Ar)
: (ar5_ms - ar_ms_step2 * (result.Ar - 5));

//cs
float cs_multiplier = 1;
if ((mods & Mods.Hr) != 0)
cs_multiplier *= 1.3f;
if ((mods & Mods.Ez) != 0)
cs_multiplier *= 0.5f;

// stats must be capped to 0-10 before HT/DT which bring them to a range
// of -4.42 to 11.08 for OD and -5 to 11 for AR
odms = Math.Min(od0_ms, Math.Max(od10_ms, odms));
arms = Math.Min(ar0_ms, Math.Max(ar10_ms, arms));

// apply speed-changing mods
odms /= speed;
arms /= speed;

// convert OD and AR back into their stat form
//od = (-(odms - od0_ms)) / od_ms_step;
result.Od = (od0_ms - odms) / od_ms_step;
result.Ar = result.Ar <= 5.0f
? ((ar0_ms - arms) / ar_ms_step1)
: (5.0f + (ar5_ms - arms) / ar_ms_step2);

result.Cs *= cs_multiplier;
result.Cs = Math.Max(0.0f, Math.Min(10.0f, result.Cs));

return result;
}

}
}
3 changes: 3 additions & 0 deletions Common/Interfaces/Controls/IBeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using BrightIdeasSoftware;
using CollectionManager.DataTypes;
using CollectionManager.Enums;
using Gui.Misc;

namespace GuiComponents.Interfaces
Expand All @@ -20,6 +21,8 @@ public interface IBeatmapListingView
event GuiHelpers.BeatmapListingActionArgs BeatmapOperation;
event GuiHelpers.BeatmapsEventArgs BeatmapsDropped;

void SetCurrentPlayMode(PlayMode playMode);
void SetCurrentMods(Mods mods);
void SetBeatmaps(IEnumerable beatmaps);
void SetFilter(IModelFilter filter);
void FilteringStarted();
Expand Down
Loading

0 comments on commit 61bb66e

Please sign in to comment.