mirror of
https://github.com/ppy/osu-tools.git
synced 2025-06-08 07:17:01 +09:00
Restructure to support multiple commands
This commit is contained in:
parent
8478be8ff8
commit
b46ff79c58
6 changed files with 112 additions and 48 deletions
12
PerformanceCalculator/PerformanceCalculator/CommandBase.cs
Normal file
12
PerformanceCalculator/PerformanceCalculator/CommandBase.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace PerformanceCalculator
|
||||
{
|
||||
[HelpOption("-?|-h|--help")]
|
||||
public abstract class CommandBase
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using JetBrains.Annotations;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
||||
namespace PerformanceCalculator.Performance
|
||||
{
|
||||
public class PerformanceCommand : ProcessorCommand
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[Required, FileExists]
|
||||
[Argument(0, Name = "beatmap", Description = "Required. The beatmap corresponding to the replays.")]
|
||||
public string Beatmap { get; }
|
||||
|
||||
[UsedImplicitly]
|
||||
[FileExists]
|
||||
[Option("-r|--replay", Description = "One for each replay. The replay file.")]
|
||||
public string[] Replays { get; }
|
||||
|
||||
protected override Processor CreateProcessor() => new PerformanceProcessor(this);
|
||||
}
|
||||
}
|
|
@ -1,40 +1,31 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-tools/master/LICENCE
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace PerformanceCalculator
|
||||
namespace PerformanceCalculator.Performance
|
||||
{
|
||||
public class Calculator : Component
|
||||
public class PerformanceProcessor : Processor
|
||||
{
|
||||
private readonly string beatmapFile;
|
||||
private readonly string[] replayFiles;
|
||||
private readonly IConsole console;
|
||||
private readonly PerformanceCommand command;
|
||||
|
||||
public Calculator(string beatmapFile, string[] replayFiles, IConsole console)
|
||||
public PerformanceProcessor(PerformanceCommand command)
|
||||
{
|
||||
this.beatmapFile = beatmapFile;
|
||||
this.replayFiles = replayFiles;
|
||||
this.console = console;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
private WorkingBeatmap workingBeatmap;
|
||||
private Ruleset ruleset;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BeatmapManager beatmaps, ScoreStore scores, GameHost host)
|
||||
protected override void Execute(BeatmapManager beatmaps, ScoreStore scores)
|
||||
{
|
||||
if (workingBeatmap == null)
|
||||
beatmaps.Import(new SingleFileArchiveReader(beatmapFile));
|
||||
beatmaps.Import(new SingleFileArchiveReader(command.Beatmap));
|
||||
|
||||
foreach (var f in replayFiles)
|
||||
foreach (var f in command.Replays)
|
||||
{
|
||||
var score = scores.ReadReplayFile(f);
|
||||
|
||||
|
@ -53,13 +44,11 @@ namespace PerformanceCalculator
|
|||
var categoryAttribs = new Dictionary<string, double>();
|
||||
double pp = ruleset.CreatePerformanceCalculator(converted, score).Calculate(categoryAttribs);
|
||||
|
||||
console.Out.WriteLine(f);
|
||||
command.Console.Out.WriteLine(f);
|
||||
foreach (var kvp in categoryAttribs)
|
||||
console.Out.WriteLine($"{kvp.Key.PadRight(15)}: {kvp.Value}");
|
||||
console.Out.WriteLine($"{"pp".PadRight(15)}: {pp}");
|
||||
command.Console.Out.WriteLine($"{kvp.Key.PadRight(15)}: {kvp.Value}");
|
||||
command.Console.Out.WriteLine($"{"pp".PadRight(15)}: {pp}");
|
||||
}
|
||||
|
||||
host.Exit();
|
||||
}
|
||||
}
|
||||
}
|
23
PerformanceCalculator/PerformanceCalculator/Processor.cs
Normal file
23
PerformanceCalculator/PerformanceCalculator/Processor.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace PerformanceCalculator
|
||||
{
|
||||
public abstract class Processor : Component
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BeatmapManager beatmaps, ScoreStore scores, GameHost host)
|
||||
{
|
||||
Execute(beatmaps, scores);
|
||||
host.Exit();
|
||||
}
|
||||
|
||||
protected abstract void Execute(BeatmapManager beatmaps, ScoreStore scores);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
|
||||
namespace PerformanceCalculator
|
||||
{
|
||||
public abstract class ProcessorCommand : CommandBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The console.
|
||||
/// </summary>
|
||||
public IConsole Console { get; private set; }
|
||||
|
||||
public void OnExecute(CommandLineApplication app, IConsole console)
|
||||
{
|
||||
Console = console;
|
||||
|
||||
using (var host = new HeadlessGameHost("performance"))
|
||||
{
|
||||
var game = new OsuGameBase();
|
||||
game.OnLoadComplete += _ => game.Add(CreateProcessor());
|
||||
|
||||
host.Run(game);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Processor CreateProcessor();
|
||||
}
|
||||
}
|
|
@ -1,39 +1,23 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-tools/master/LICENCE
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using JetBrains.Annotations;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game;
|
||||
using PerformanceCalculator.Performance;
|
||||
|
||||
namespace PerformanceCalculator
|
||||
{
|
||||
public class Program
|
||||
[Command("main")]
|
||||
[Subcommand("performance", typeof(PerformanceCommand))]
|
||||
public class Program : CommandBase
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
=> CommandLineApplication.Execute<Program>(args);
|
||||
|
||||
[UsedImplicitly]
|
||||
[Required, FileExists]
|
||||
[Option(Template = "-b|--beatmap", Description = "Required. The beatmap for the replays.")]
|
||||
public string Beatmap { get; }
|
||||
|
||||
[UsedImplicitly]
|
||||
[Required, FileExists]
|
||||
[Option(Template = "-r|--replay", Description = "One or more replays to calculate the performance for.")]
|
||||
public string[] Replays { get; }
|
||||
|
||||
[UsedImplicitly]
|
||||
public void OnExecute(CommandLineApplication app, IConsole console)
|
||||
|
||||
public int OnExecute(CommandLineApplication app, IConsole console)
|
||||
{
|
||||
using (var host = new HeadlessGameHost("performance"))
|
||||
{
|
||||
var game = new OsuGameBase();
|
||||
game.OnLoadComplete += _ => game.Add(new Calculator(Beatmap, Replays, console));
|
||||
|
||||
host.Run(game);
|
||||
}
|
||||
console.WriteLine("You must specify a subcommand.");
|
||||
app.ShowHelp();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue