mirror of
https://github.com/ppy/osu.git
synced 2026-05-15 11:23:04 +08:00
8cb81974eb
The way that this works is that it plugs into the online request to retrieve the beatmap set that the client is already performing, and stores user tag data to the local realm database. This means that for now user tags will only populate for beatmaps that the user has displayed on song select which is obviously subpar. I plan to follow this change up by adding user tag state dumps to `online.db` and using that data for initial tag population to make the majority case (ranked beatmaps) work. Note that several decisions were made here that are potential discussion points: - `RealmPopulatingOnlineLookupSource` is set up such that it can be the middle man / redirection point for similar flows that we need and we are currently missing, such as storing guest difficulty information, or storing the user's current best score on a beatmap (handy for rank achieved sorting / filtering / etc.) - The user tags are stored in `BeatmapMetadata` which breaks the longstanding assumption that you can arbitrarily pull out a metadata instance from any of the beatmaps in a set and get essentially the same object back. I've attempted to constrain this some by not adding user tags to the `IBeatmapMetadataInfo` interface through which `BeatmapSetInfo` exposes metadata further, but I warn in advance that this is a temporary state of affairs and I will make it worse in the future when `BeatmapMetadata.Author` becomes `Authors` plural in order to support guest mapper display (and direct guest difficulty submission). - The syntax for searching via user tags is chosen to mostly match web - it's `tag=`, with support for all of the string matching modes song select already has (bare word for substring, `""` quotes for phrase isolated by whitespace, `""!` for exact full match).
92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
// 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 JetBrains.Annotations;
|
|
using Newtonsoft.Json;
|
|
using osu.Game.Models;
|
|
using osu.Game.Screens.SelectV2;
|
|
using osu.Game.Users;
|
|
using osu.Game.Utils;
|
|
using Realms;
|
|
|
|
namespace osu.Game.Beatmaps
|
|
{
|
|
/// <summary>
|
|
/// A realm model containing metadata for a beatmap.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// An instance of this object is stored against each beatmap difficulty.
|
|
/// It is also provided via <see cref="BeatmapSetInfo"/> for convenience and historical purposes.
|
|
/// Note that accessing the metadata via <see cref="BeatmapSetInfo"/> may result in indeterminate results
|
|
/// as metadata can meaningfully differ per beatmap in a set.
|
|
///
|
|
/// Note that difficulty name is not stored in this metadata but in <see cref="BeatmapInfo"/>.
|
|
/// </remarks>
|
|
[Serializable]
|
|
[MapTo("BeatmapMetadata")]
|
|
public class BeatmapMetadata : RealmObject, IBeatmapMetadataInfo, IDeepCloneable<BeatmapMetadata>
|
|
{
|
|
public string Title { get; set; } = string.Empty;
|
|
|
|
[JsonProperty("title_unicode")]
|
|
public string TitleUnicode { get; set; } = string.Empty;
|
|
|
|
public string Artist { get; set; } = string.Empty;
|
|
|
|
[JsonProperty("artist_unicode")]
|
|
public string ArtistUnicode { get; set; } = string.Empty;
|
|
|
|
public RealmUser Author { get; set; } = null!;
|
|
|
|
public string Source { get; set; } = string.Empty;
|
|
|
|
[JsonProperty(@"tags")]
|
|
public string Tags { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// The list of user-voted tags applicable to this beatmap.
|
|
/// This information is populated from online sources (<see cref="RealmPopulatingOnlineLookupSource"/>)
|
|
/// and can meaningfully differ between beatmaps of a single set.
|
|
/// </summary>
|
|
public IList<string> UserTags { get; } = null!;
|
|
|
|
/// <summary>
|
|
/// The time in milliseconds to begin playing the track for preview purposes.
|
|
/// If -1, the track should begin playing at 40% of its length.
|
|
/// </summary>
|
|
public int PreviewTime { get; set; } = -1;
|
|
|
|
public string AudioFile { get; set; } = string.Empty;
|
|
public string BackgroundFile { get; set; } = string.Empty;
|
|
|
|
public BeatmapMetadata(RealmUser? user = null)
|
|
{
|
|
Author = user ?? new RealmUser();
|
|
}
|
|
|
|
[UsedImplicitly] // Realm
|
|
private BeatmapMetadata()
|
|
{
|
|
}
|
|
|
|
IUser IBeatmapMetadataInfo.Author => Author;
|
|
|
|
public override string ToString() => this.GetDisplayTitle();
|
|
|
|
public BeatmapMetadata DeepClone() => new BeatmapMetadata(Author.DeepClone())
|
|
{
|
|
Title = Title,
|
|
TitleUnicode = TitleUnicode,
|
|
Artist = Artist,
|
|
ArtistUnicode = ArtistUnicode,
|
|
Source = Source,
|
|
Tags = Tags,
|
|
PreviewTime = PreviewTime,
|
|
AudioFile = AudioFile,
|
|
BackgroundFile = BackgroundFile
|
|
};
|
|
}
|
|
}
|