1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Add score importer

This commit is contained in:
Dean Herbert 2021-11-12 13:07:11 +09:00
parent 0dd23c46b0
commit a5df01ff47
2 changed files with 65 additions and 1 deletions

View File

@ -28,7 +28,7 @@ namespace osu.Game.Beatmaps
DateTimeOffset? LastUpdated { get; }
/// <summary>
/// The status of this beatmap set.
/// The "ranked" status of this beatmap set.
/// </summary>
BeatmapOnlineStatus Status { get; }

View File

@ -0,0 +1,64 @@
// 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 System.Threading;
using System.Threading.Tasks;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Models;
using osu.Game.Scoring.Legacy;
using Realms;
#nullable enable
namespace osu.Game.Stores
{
/// <summary>
/// Handles the storage and retrieval of Scores/WorkingScores.
/// </summary>
[ExcludeFromDynamicCompile]
public class ScoreImporter : RealmArchiveModelImporter<RealmScore>
{
private readonly RealmRulesetStore rulesets;
private readonly BeatmapManager beatmaps;
public override IEnumerable<string> HandledExtensions => new[] { ".osr" };
protected override string[] HashableFileTypes => new[] { ".osr" };
public ScoreImporter(RealmRulesetStore rulesets, RealmContextFactory contextFactory, Storage storage, BeatmapManager beatmaps)
: base(storage, contextFactory)
{
this.rulesets = rulesets;
this.beatmaps = beatmaps;
}
protected override RealmScore? CreateModel(ArchiveReader archive)
{
using (var stream = archive.GetStream(archive.Filenames.First(f => f.EndsWith(".osr", StringComparison.OrdinalIgnoreCase))))
{
try
{
// TODO: make work.
// return new DatabasedLegacyScoreDecoder(rulesets, beatmaps).Parse(stream).ScoreInfo;
return new RealmScore();
}
catch (LegacyScoreDecoder.BeatmapNotFoundException e)
{
Logger.Log(e.Message, LoggingTarget.Information, LogLevel.Error);
return null;
}
}
}
protected override Task Populate(RealmScore model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
=> Task.CompletedTask;
}
}