forked from ppy/osu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegacyScoreConversionCommand.cs
More file actions
112 lines (90 loc) · 4.71 KB
/
LegacyScoreConversionCommand.cs
File metadata and controls
112 lines (90 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// 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;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using McMaster.Extensions.CommandLineUtils;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Scoring.Legacy;
using Realms;
namespace PerformanceCalculator.Difficulty
{
[Command(Name = "legacy-score-conversion", Description = "Performs score conversion for a stable score with the given parameters.")]
[HelpOption("-?|-h|--help")]
public class LegacyScoreConversionCommand
{
[UsedImplicitly]
[Required]
[Argument(0, Name = "beatmap", Description = "Required. Can be either a path to beatmap file (.osu) or beatmap ID.")]
public string Beatmap { get; } = null!;
[UsedImplicitly]
[Required]
[Option(CommandOptionType.SingleValue, Template = "-r|--ruleset:<ruleset-id>", Description = "The ruleset to perform score total conversion in.\n"
+ "Values: 0 - osu!, 1 - osu!taiko, 2 - osu!catch, 3 - osu!mania")]
[AllowedValues("0", "1", "2", "3")]
public int Ruleset { get; }
[UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mods <mod>", Description = "One for each mod. The mods to compute the difficulty with."
+ "Values: hr, dt, hd, fl, ez, 4k, 5k, etc...")]
public string[] Mods { get; } = [];
[Option(CommandOptionType.SingleValue, Template = "--greats", Description = "Number of greats.")]
public int Greats { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--goods", Description = "Number of goods.")]
public int Goods { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--mehs", Description = "Number of mehs.")]
public int Mehs { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--misses", Description = "Number of misses.")]
public int Misses { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--geki", Description = "Number of gekis.")]
public int Gekis { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--katu", Description = "Number of katus.")]
public int Katus { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--max-combo", Description = "Max combo achieved by user.")]
public int MaxCombo { get; set; }
[Option(CommandOptionType.SingleValue, Template = "--score", Description = "Total score achieved by user.")]
public int TotalScore { get; set; }
[UsedImplicitly]
public virtual void OnExecute(CommandLineApplication app, IConsole console)
{
var ruleset = LegacyHelper.GetRulesetFromLegacyID(Ruleset);
var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(Beatmap);
Mod[] mods = [ruleset.CreateMod<ModClassic>()!, .. getMods(ruleset)];
var beatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);
var scoreInfo = new ScoreInfo(beatmap.BeatmapInfo, ruleset.RulesetInfo)
{
IsLegacyScore = true,
LegacyTotalScore = TotalScore,
MaxCombo = MaxCombo,
Mods = mods,
};
scoreInfo.SetCount300(Greats);
scoreInfo.SetCount100(Goods);
scoreInfo.SetCount50(Mehs);
scoreInfo.SetCountGeki(Gekis);
scoreInfo.SetCountKatu(Katus);
scoreInfo.SetCountMiss(Misses);
LegacyScoreDecoder.PopulateMaximumStatistics(scoreInfo, workingBeatmap);
StandardisedScoreMigrationTools.UpdateFromLegacy(scoreInfo, workingBeatmap);
console.WriteLine($"Converted total score: {scoreInfo.TotalScore}");
}
private Mod[] getMods(Ruleset ruleset)
{
if (Mods.Length == 0)
return Array.Empty<Mod>();
var availableMods = ruleset.CreateAllMods().ToList();
var mods = new List<Mod>();
foreach (string modString in Mods)
{
Mod? newMod = availableMods?.FirstOrDefault(m => string.Equals(m.Acronym, modString, StringComparison.OrdinalIgnoreCase));
if (newMod == null)
throw new ArgumentException($"Invalid mod provided: {modString}");
mods.Add(newMod);
}
return mods.ToArray();
}
}
}