1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Initial scoremanager/scorestore structure

This commit is contained in:
smoogipoo 2018-11-28 16:47:10 +09:00
parent 3fe4a36845
commit 4ba7690e04
6 changed files with 45 additions and 97 deletions

View File

@ -10,6 +10,7 @@ using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.IO;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using DatabasedKeyBinding = osu.Game.Input.Bindings.DatabasedKeyBinding;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
using osu.Game.Skinning;
@ -27,6 +28,7 @@ namespace osu.Game.Database
public DbSet<FileInfo> FileInfo { get; set; }
public DbSet<RulesetInfo> RulesetInfo { get; set; }
public DbSet<SkinInfo> SkinInfo { get; set; }
public DbSet<Score> ScoreInfo { get; set; }
private readonly string connectionString;

View File

@ -1,46 +0,0 @@
// 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.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Platform;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.IPC
{
public class ScoreIPCChannel : IpcChannel<ScoreImportMessage>
{
private readonly ScoreStore scores;
public ScoreIPCChannel(IIpcHost host, ScoreStore scores = null)
: base(host)
{
this.scores = scores;
MessageReceived += msg =>
{
Debug.Assert(scores != null);
ImportAsync(msg.Path).ContinueWith(t =>
{
if (t.Exception != null) throw t.Exception;
}, TaskContinuationOptions.OnlyOnFaulted);
};
}
public async Task ImportAsync(string path)
{
if (scores == null)
{
//we want to contact a remote osu! to handle the import.
await SendMessageAsync(new ScoreImportMessage { Path = path });
return;
}
scores.ReadReplayFile(path);
}
}
public class ScoreImportMessage
{
public string Path;
}
}

View File

@ -148,7 +148,7 @@ namespace osu.Game
{
this.frameworkConfig = frameworkConfig;
ScoreStore.ScoreImported += score => Schedule(() => LoadScore(score));
ScoreManager.ItemAdded += score => Schedule(() => LoadScore(score));
if (!Host.IsPrimaryInstance)
{

View File

@ -46,14 +46,14 @@ namespace osu.Game
protected BeatmapManager BeatmapManager;
protected ScoreManager ScoreManager;
protected SkinManager SkinManager;
protected RulesetStore RulesetStore;
protected FileStore FileStore;
protected ScoreStore ScoreStore;
protected KeyBindingStore KeyBindingStore;
protected SettingsStore SettingsStore;
@ -154,14 +154,14 @@ namespace osu.Game
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Audio, Host));
dependencies.Cache(ScoreStore = new ScoreStore(contextFactory, Host, BeatmapManager, RulesetStore));
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, BeatmapManager, Host.Storage, contextFactory, Host));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
dependencies.Cache(new OsuColour());
fileImporters.Add(BeatmapManager);
fileImporters.Add(ScoreStore);
fileImporters.Add(ScoreManager);
fileImporters.Add(SkinManager);
var defaultBeatmap = new DummyWorkingBeatmap(this);

View File

@ -0,0 +1,31 @@
// 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.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Rulesets;
namespace osu.Game.Scoring
{
public class ScoreManager : ArchiveModelManager<Score, ScoreFileInfo>
{
public override string[] HandledExtensions => new[] { ".osr" };
protected override string ImportFromStablePath => "Replays";
public ScoreManager(RulesetStore rulesets, BeatmapManager beatmaps, Storage storage, IDatabaseContextFactory contextFactory, IIpcHost importHost = null)
: base(storage, contextFactory, new ScoreStore(contextFactory, storage), importHost)
{
}
protected override Score CreateModel(ArchiveReader archive) => new Score();
protected override void Populate(Score model, ArchiveReader archive)
{
if (archive == null)
return;
}
}
}

View File

@ -1,60 +1,21 @@
// 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;
using System.IO;
using osu.Framework.Logging;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IPC;
using osu.Game.Rulesets.Scoring.Legacy;
namespace osu.Game.Scoring
{
public class ScoreStore : DatabaseBackedStore, ICanAcceptFiles
public class ScoreStore : MutableDatabaseBackedStore<Score>
{
private readonly BeatmapManager beatmaps;
private readonly RulesetStore rulesets;
private const string replay_folder = @"replays";
public event Action<Score> ScoreImported;
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
private ScoreIPCChannel ipc;
public ScoreStore(DatabaseContextFactory factory, IIpcHost importHost = null, BeatmapManager beatmaps = null, RulesetStore rulesets = null) : base(factory)
public ScoreStore(IDatabaseContextFactory factory, Storage storage)
: base(factory, storage)
{
this.beatmaps = beatmaps;
this.rulesets = rulesets;
if (importHost != null)
ipc = new ScoreIPCChannel(importHost, this);
}
public string[] HandledExtensions => new[] { ".osr" };
public void Import(params string[] paths)
{
foreach (var path in paths)
{
var score = ReadReplayFile(path);
if (score != null)
ScoreImported?.Invoke(score);
}
}
public Score ReadReplayFile(string replayFilename)
{
if (File.Exists(replayFilename))
{
using (var stream = File.OpenRead(replayFilename))
return new DatabasedLegacyScoreParser(rulesets, beatmaps).Parse(stream);
}
Logger.Log($"Replay file {replayFilename} cannot be found", LoggingTarget.Information, LogLevel.Error);
return null;
}
protected override IQueryable<Score> AddIncludesForConsumption(IQueryable<Score> query)
=> base.AddIncludesForConsumption(query).Include(s => s.Files).ThenInclude(f => f.FileInfo);
}
}