mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:13:21 +08:00
Merge pull request #15633 from smoogipoo/difficulty-attribute-helpers
Add difficulty attribute formatting
This commit is contained in:
commit
18dd4ab6d1
@ -1,12 +1,35 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Difficulty
|
||||
{
|
||||
public class CatchDifficultyAttributes : DifficultyAttributes
|
||||
{
|
||||
[JsonProperty("approach_rate")]
|
||||
public double ApproachRate { get; set; }
|
||||
|
||||
public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes()
|
||||
{
|
||||
foreach (var v in base.ToDatabaseAttributes())
|
||||
yield return v;
|
||||
|
||||
// Todo: osu!catch should not output star rating in the 'aim' attribute.
|
||||
yield return (ATTRIB_ID_AIM, StarRating);
|
||||
yield return (ATTRIB_ID_APPROACH_RATE, ApproachRate);
|
||||
yield return (ATTRIB_ID_MAX_COMBO, MaxCombo);
|
||||
}
|
||||
|
||||
public override void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values)
|
||||
{
|
||||
base.FromDatabaseAttributes(values);
|
||||
|
||||
StarRating = values[ATTRIB_ID_AIM];
|
||||
ApproachRate = values[ATTRIB_ID_APPROACH_RATE];
|
||||
MaxCombo = (int)values[ATTRIB_ID_MAX_COMBO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,38 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Difficulty
|
||||
{
|
||||
public class ManiaDifficultyAttributes : DifficultyAttributes
|
||||
{
|
||||
[JsonProperty("great_hit_window")]
|
||||
public double GreatHitWindow { get; set; }
|
||||
|
||||
[JsonProperty("score_multiplier")]
|
||||
public double ScoreMultiplier { get; set; }
|
||||
|
||||
public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes()
|
||||
{
|
||||
foreach (var v in base.ToDatabaseAttributes())
|
||||
yield return v;
|
||||
|
||||
// Todo: osu!mania doesn't output MaxCombo attribute for some reason.
|
||||
yield return (ATTRIB_ID_STRAIN, StarRating);
|
||||
yield return (ATTRIB_ID_GREAT_HIT_WINDOW, GreatHitWindow);
|
||||
yield return (ATTRIB_ID_SCORE_MULTIPLIER, ScoreMultiplier);
|
||||
}
|
||||
|
||||
public override void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values)
|
||||
{
|
||||
base.FromDatabaseAttributes(values);
|
||||
|
||||
StarRating = values[ATTRIB_ID_STRAIN];
|
||||
GreatHitWindow = values[ATTRIB_ID_GREAT_HIT_WINDOW];
|
||||
ScoreMultiplier = values[ATTRIB_ID_SCORE_MULTIPLIER];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,77 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Difficulty
|
||||
{
|
||||
public class OsuDifficultyAttributes : DifficultyAttributes
|
||||
{
|
||||
[JsonProperty("aim_strain")]
|
||||
public double AimStrain { get; set; }
|
||||
|
||||
[JsonProperty("speed_strain")]
|
||||
public double SpeedStrain { get; set; }
|
||||
|
||||
[JsonProperty("flashlight_rating")]
|
||||
public double FlashlightRating { get; set; }
|
||||
|
||||
[JsonProperty("slider_factor")]
|
||||
public double SliderFactor { get; set; }
|
||||
|
||||
[JsonProperty("approach_rate")]
|
||||
public double ApproachRate { get; set; }
|
||||
|
||||
[JsonProperty("overall_difficulty")]
|
||||
public double OverallDifficulty { get; set; }
|
||||
|
||||
public double DrainRate { get; set; }
|
||||
|
||||
public int HitCircleCount { get; set; }
|
||||
|
||||
public int SliderCount { get; set; }
|
||||
|
||||
public int SpinnerCount { get; set; }
|
||||
|
||||
public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes()
|
||||
{
|
||||
foreach (var v in base.ToDatabaseAttributes())
|
||||
yield return v;
|
||||
|
||||
yield return (ATTRIB_ID_AIM, AimStrain);
|
||||
yield return (ATTRIB_ID_SPEED, SpeedStrain);
|
||||
yield return (ATTRIB_ID_OVERALL_DIFFICULTY, OverallDifficulty);
|
||||
yield return (ATTRIB_ID_APPROACH_RATE, ApproachRate);
|
||||
yield return (ATTRIB_ID_MAX_COMBO, MaxCombo);
|
||||
yield return (ATTRIB_ID_STRAIN, StarRating);
|
||||
|
||||
if (ShouldSerializeFlashlightRating())
|
||||
yield return (ATTRIB_ID_FLASHLIGHT, FlashlightRating);
|
||||
|
||||
yield return (ATTRIB_ID_SLIDER_FACTOR, SliderFactor);
|
||||
}
|
||||
|
||||
public override void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values)
|
||||
{
|
||||
base.FromDatabaseAttributes(values);
|
||||
|
||||
AimStrain = values[ATTRIB_ID_AIM];
|
||||
SpeedStrain = values[ATTRIB_ID_SPEED];
|
||||
OverallDifficulty = values[ATTRIB_ID_OVERALL_DIFFICULTY];
|
||||
ApproachRate = values[ATTRIB_ID_APPROACH_RATE];
|
||||
MaxCombo = (int)values[ATTRIB_ID_MAX_COMBO];
|
||||
StarRating = values[ATTRIB_ID_STRAIN];
|
||||
FlashlightRating = values.GetValueOrDefault(ATTRIB_ID_FLASHLIGHT);
|
||||
SliderFactor = values[ATTRIB_ID_SLIDER_FACTOR];
|
||||
}
|
||||
|
||||
// Used implicitly by Newtonsoft.Json to not serialize flashlight property in some cases.
|
||||
[UsedImplicitly]
|
||||
public bool ShouldSerializeFlashlightRating() => Mods.Any(m => m is ModFlashlight);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,46 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
|
||||
namespace osu.Game.Rulesets.Taiko.Difficulty
|
||||
{
|
||||
public class TaikoDifficultyAttributes : DifficultyAttributes
|
||||
{
|
||||
[JsonProperty("stamina_strain")]
|
||||
public double StaminaStrain { get; set; }
|
||||
|
||||
[JsonProperty("rhythm_strain")]
|
||||
public double RhythmStrain { get; set; }
|
||||
|
||||
[JsonProperty("colour_strain")]
|
||||
public double ColourStrain { get; set; }
|
||||
|
||||
[JsonProperty("approach_rate")]
|
||||
public double ApproachRate { get; set; }
|
||||
|
||||
[JsonProperty("great_hit_window")]
|
||||
public double GreatHitWindow { get; set; }
|
||||
|
||||
public override IEnumerable<(int attributeId, object value)> ToDatabaseAttributes()
|
||||
{
|
||||
foreach (var v in base.ToDatabaseAttributes())
|
||||
yield return v;
|
||||
|
||||
yield return (ATTRIB_ID_MAX_COMBO, MaxCombo);
|
||||
yield return (ATTRIB_ID_STRAIN, StarRating);
|
||||
yield return (ATTRIB_ID_GREAT_HIT_WINDOW, GreatHitWindow);
|
||||
}
|
||||
|
||||
public override void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values)
|
||||
{
|
||||
base.FromDatabaseAttributes(values);
|
||||
|
||||
MaxCombo = (int)values[ATTRIB_ID_MAX_COMBO];
|
||||
StarRating = values[ATTRIB_ID_STRAIN];
|
||||
GreatHitWindow = values[ATTRIB_ID_GREAT_HIT_WINDOW];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,87 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Rulesets.Difficulty.Skills;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Rulesets.Difficulty
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the difficulty of a beatmap, as output by a <see cref="DifficultyCalculator"/>.
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class DifficultyAttributes
|
||||
{
|
||||
protected const int ATTRIB_ID_AIM = 1;
|
||||
protected const int ATTRIB_ID_SPEED = 3;
|
||||
protected const int ATTRIB_ID_OVERALL_DIFFICULTY = 5;
|
||||
protected const int ATTRIB_ID_APPROACH_RATE = 7;
|
||||
protected const int ATTRIB_ID_MAX_COMBO = 9;
|
||||
protected const int ATTRIB_ID_STRAIN = 11;
|
||||
protected const int ATTRIB_ID_GREAT_HIT_WINDOW = 13;
|
||||
protected const int ATTRIB_ID_SCORE_MULTIPLIER = 15;
|
||||
protected const int ATTRIB_ID_FLASHLIGHT = 17;
|
||||
protected const int ATTRIB_ID_SLIDER_FACTOR = 19;
|
||||
|
||||
/// <summary>
|
||||
/// The mods which were applied to the beatmap.
|
||||
/// </summary>
|
||||
public Mod[] Mods { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The skills resulting from the difficulty calculation.
|
||||
/// </summary>
|
||||
public Skill[] Skills { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The combined star rating of all skill.
|
||||
/// </summary>
|
||||
[JsonProperty("star_rating", Order = -3)]
|
||||
public double StarRating { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum achievable combo.
|
||||
/// </summary>
|
||||
[JsonProperty("max_combo", Order = -2)]
|
||||
public int MaxCombo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates new <see cref="DifficultyAttributes"/>.
|
||||
/// </summary>
|
||||
public DifficultyAttributes()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new <see cref="DifficultyAttributes"/>.
|
||||
/// </summary>
|
||||
/// <param name="mods">The mods which were applied to the beatmap.</param>
|
||||
/// <param name="skills">The skills resulting from the difficulty calculation.</param>
|
||||
/// <param name="starRating">The combined star rating of all skills.</param>
|
||||
public DifficultyAttributes(Mod[] mods, Skill[] skills, double starRating)
|
||||
{
|
||||
Mods = mods;
|
||||
Skills = skills;
|
||||
StarRating = starRating;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts this <see cref="DifficultyAttributes"/> to osu-web compatible database attribute mappings.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See: osu_difficulty_attribs table.
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<(int attributeId, object value)> ToDatabaseAttributes() => Enumerable.Empty<(int, object)>();
|
||||
|
||||
/// <summary>
|
||||
/// Reads osu-web database attribute mappings into this <see cref="DifficultyAttributes"/> object.
|
||||
/// </summary>
|
||||
/// <param name="values">The attribute mappings.</param>
|
||||
public virtual void FromDatabaseAttributes(IReadOnlyDictionary<int, double> values)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user