2021-04-07 20:35:33 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-04-07 20:35:33 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using osu.Game.Extensions ;
using osu.Game.Rulesets.Objects ;
2021-04-10 19:02:22 +08:00
namespace osu.Game.Rulesets.Edit.Checks.Components
2021-04-07 20:35:33 +08:00
{
public class Issue
{
/// <summary>
/// The time which this issue is associated with, if any, otherwise null.
/// </summary>
public double? Time ;
/// <summary>
/// The hitobjects which this issue is associated with. Empty by default.
/// </summary>
public IReadOnlyList < HitObject > HitObjects ;
/// <summary>
2021-04-12 14:32:52 +08:00
/// The template which this issue is using. This provides properties such as the <see cref="IssueType"/>, and the <see cref="IssueTemplate.UnformattedMessage"/>.
2021-04-07 20:35:33 +08:00
/// </summary>
public IssueTemplate Template ;
2021-04-12 16:08:08 +08:00
/// <summary>
/// The check that this issue originates from.
/// </summary>
2021-04-12 21:47:26 +08:00
public ICheck Check = > Template . Check ;
2021-04-12 16:08:08 +08:00
2021-04-07 20:35:33 +08:00
/// <summary>
2021-04-12 14:27:12 +08:00
/// The arguments that give this issue its context, based on the <see cref="IssueTemplate"/>. These are then substituted into the <see cref="IssueTemplate.UnformattedMessage"/>.
/// This could for instance include timestamps, which diff is being compared to, what some volume is, etc.
2021-04-07 20:35:33 +08:00
/// </summary>
public object [ ] Arguments ;
2021-04-12 21:47:26 +08:00
public Issue ( IssueTemplate template , params object [ ] args )
2021-04-07 20:35:33 +08:00
{
Time = null ;
2021-04-10 19:02:22 +08:00
HitObjects = Array . Empty < HitObject > ( ) ;
2021-04-07 20:35:33 +08:00
Template = template ;
Arguments = args ;
}
2021-04-12 21:47:26 +08:00
public Issue ( double? time , IssueTemplate template , params object [ ] args )
: this ( template , args )
2021-04-07 20:35:33 +08:00
{
Time = time ;
}
2021-04-12 21:47:26 +08:00
public Issue ( HitObject hitObject , IssueTemplate template , params object [ ] args )
: this ( template , args )
2021-04-10 19:02:22 +08:00
{
Time = hitObject . StartTime ;
HitObjects = new [ ] { hitObject } ;
}
2021-04-12 21:47:26 +08:00
public Issue ( IEnumerable < HitObject > hitObjects , IssueTemplate template , params object [ ] args )
: this ( template , args )
2021-04-07 20:35:33 +08:00
{
2021-04-10 19:02:22 +08:00
var hitObjectList = hitObjects . ToList ( ) ;
Time = hitObjectList . FirstOrDefault ( ) ? . StartTime ;
HitObjects = hitObjectList ;
2021-04-07 20:35:33 +08:00
}
2021-04-12 14:37:41 +08:00
public override string ToString ( ) = > Template . GetMessage ( Arguments ) ;
2021-04-07 20:35:33 +08:00
public string GetEditorTimestamp ( )
{
2021-04-10 19:02:22 +08:00
return Time = = null ? string . Empty : Time . Value . ToEditorFormattedString ( ) ;
2021-04-07 20:35:33 +08:00
}
}
}