Skip to content

Commit

Permalink
Add: Choose with mod combinations should be saved in collection gener…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
Piotrekol committed Jul 30, 2021
1 parent d4cc04d commit 4841b03
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 78 deletions.
28 changes: 27 additions & 1 deletion App/Presenters/Controls/UserTopGeneratorPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using App.Interfaces;
using CollectionManager.DataTypes;
using CollectionManagerExtensionsDll.DataTypes;
using GuiComponents.Interfaces;

Expand Down Expand Up @@ -42,6 +45,28 @@ private void ViewOnStart(object sender, EventArgs eventArgs)
//TODO: show some sort of error on missing api key
if (string.IsNullOrEmpty(_view.ApiKey))
return;

var modCombinations = new List<Mods>();
if (!string.IsNullOrWhiteSpace(_view.AllowedModCombinations) &&
_view.AllowedModCombinations.Trim().ToLowerInvariant() != "all")
{
var strMods = _view.AllowedModCombinations.Trim().ToLowerInvariant();
var splitModCombinations = strMods.Split(',');
foreach (var splitModCombination in splitModCombinations)
{
var splitMods = Regex.Split(splitModCombination, @"([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;
}

modCombinations.Add(mods);
}
}


_model.GeneratorConfiguration = new CollectionGeneratorConfiguration()
{
CollectionNameSavePattern = _view.CollectionNamingFormat,
Expand All @@ -54,7 +79,8 @@ private void ViewOnStart(object sender, EventArgs eventArgs)
MaximumPp = _view.PpMax,
MinimumAcc = _view.AccMin,
MaximumAcc = _view.AccMax,
RanksToGet = (RankTypes)_view.AllowedScores
RanksToGet = (RankTypes)_view.AllowedScores,
ModCombinations = modCombinations
}
};
_model.EmitStart();
Expand Down
42 changes: 26 additions & 16 deletions CollectionManagerExtensionsDll/DataTypes/ScoreSaveConditions.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using CollectionManager.DataTypes;

namespace CollectionManagerExtensionsDll.DataTypes
{
public class ScoreSaveConditions
{
/// <summary>
/// Minimum pp on a score required for it to be egible for saving.
/// Minimum pp on a score required for it to be eligible for saving.
/// </summary>
public double MinimumPp { get; set; } = 0;
/// <summary>
/// Maximum pp on a score required for it to be egible for saving.
/// Maximum pp on a score required for it to be eligible for saving.
/// </summary>
public double MaximumPp { get; set; } = 2000;
/// <summary>
/// Minimum acc on a score required for it to be egible for saving.
/// Minimum acc on a score required for it to be eligible for saving.
/// </summary>
public double MinimumAcc { get; set; } = 0;
/// <summary>
/// Maximum acc on a score required for it to be egible for saving.
/// Maximum acc on a score required for it to be eligible for saving.
/// </summary>
public double MaximumAcc { get; set; } = 100;
/// <summary>
/// fetch scores thatare in specified rank range
/// fetch scores that are in specified rank range
/// </summary>
public RankTypes RanksToGet { get; set; } = RankTypes.All;
/// <summary>
/// fetch scores with specified mods
/// </summary>
public List<Mods> ModCombinations { get; set; } = new List<Mods>();

public bool IsEgibleForSaving(ApiScore score)
public bool IsEligibleForSaving(ApiScore score)
{
if (score.Pp < MinimumPp || score.Pp > MaximumPp)
return false;

if (ModCombinations.Count > 0 && ModCombinations.All(mod => score.EnabledMods != (int)mod))
return false;

switch (RanksToGet)
{
case RankTypes.All:
break;
default:
break;
/*case RankTypes.SAndBetter:
if (score.Rank.Contains("S"))
return false;
break;
case RankTypes.AAndWorse:
if (!score.Rank.Contains("S"))
return false;
break;
*/
/*case RankTypes.SAndBetter:
if (score.Rank.Contains("S"))
return false;
break;
case RankTypes.AAndWorse:
if (!score.Rank.Contains("S"))
return false;
break;
*/
}

//acc calc...(osu! mode)
var totalHits = score.Countmiss + score.Count50 + score.Count100 + score.Count300;
var pointsOfHits = score.Count50 * 50 + score.Count100 * 100 + score.Count300 * 300;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private Collections GetPlayerCollections(string username, string collectionNameS
var collections = new Collections();
foreach (var s in validScores)
{
if (configuration.IsEgibleForSaving(s))
if (configuration.IsEligibleForSaving(s))
{
string collectionName = CreateCollectionName(s, username, collectionNameSavePattern);
if (collectionsDict.ContainsKey(collectionName))
Expand Down Expand Up @@ -198,7 +198,7 @@ private IList<ApiScore> GetPlayerScores(string username, PlayMode gamemode, Scor
_scoreCache.Add(new UserModePair(username, gamemode), scores);
foreach (var s in scores)
{
if (configuration.IsEgibleForSaving(s))
if (configuration.IsEligibleForSaving(s))
egibleScores.Add(s);
}
return egibleScores;
Expand Down
3 changes: 1 addition & 2 deletions Common/Interfaces/Controls/IUserTopGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ public interface IUserTopGenerator
string CollectionNamingFormat { get; }
string CollectionNamingExample { set; }
int AllowedScores { get; }
string AllowedModCombinations { get; }
double PpMin { get; }
double PpMax { get; }
double AccMin { get; }
double AccMax { get; }
bool GroupByMods { get; }
bool MergeCollectionsWithSameName { get; }
int Gamemode { get; }

ICollectionListingView CollectionListing { get; }
Expand Down
107 changes: 52 additions & 55 deletions GuiComponents/Controls/UserTopGeneratorView.Designer.cs

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

3 changes: 1 addition & 2 deletions GuiComponents/Controls/UserTopGeneratorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ public string CollectionNamingExample
}

public int AllowedScores { get; private set; } = 0;
public string AllowedModCombinations => textBox_allowedMods.Text;
public string ApiKey => textBox_apiKey.Text;
public double PpMin => Convert.ToDouble(numericUpDown_minimumPP.Value);
public double PpMax => Convert.ToDouble(numericUpDown_maximumPP.Value);
public double AccMin => Convert.ToDouble(numericUpDown_accMin.Value);
public double AccMax => Convert.ToDouble(numericUpDown_accMax.Value);
public bool GroupByMods => checkBox_GroupByMods.Checked;
public bool MergeCollectionsWithSameName => checkBox_mergeCollections.Checked;
public int Gamemode => comboBox_gamemode.SelectedIndex;
public ICollectionListingView CollectionListing => collectionListingView1;

Expand Down

0 comments on commit 4841b03

Please sign in to comment.