mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Initial scoremanager/scorestore structure
This commit is contained in:
@ -10,6 +10,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Scoring;
|
||||||
using DatabasedKeyBinding = osu.Game.Input.Bindings.DatabasedKeyBinding;
|
using DatabasedKeyBinding = osu.Game.Input.Bindings.DatabasedKeyBinding;
|
||||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -27,6 +28,7 @@ namespace osu.Game.Database
|
|||||||
public DbSet<FileInfo> FileInfo { get; set; }
|
public DbSet<FileInfo> FileInfo { get; set; }
|
||||||
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
public DbSet<RulesetInfo> RulesetInfo { get; set; }
|
||||||
public DbSet<SkinInfo> SkinInfo { get; set; }
|
public DbSet<SkinInfo> SkinInfo { get; set; }
|
||||||
|
public DbSet<Score> ScoreInfo { get; set; }
|
||||||
|
|
||||||
private readonly string connectionString;
|
private readonly string connectionString;
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -148,7 +148,7 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
this.frameworkConfig = frameworkConfig;
|
this.frameworkConfig = frameworkConfig;
|
||||||
|
|
||||||
ScoreStore.ScoreImported += score => Schedule(() => LoadScore(score));
|
ScoreManager.ItemAdded += score => Schedule(() => LoadScore(score));
|
||||||
|
|
||||||
if (!Host.IsPrimaryInstance)
|
if (!Host.IsPrimaryInstance)
|
||||||
{
|
{
|
||||||
|
@ -46,14 +46,14 @@ namespace osu.Game
|
|||||||
|
|
||||||
protected BeatmapManager BeatmapManager;
|
protected BeatmapManager BeatmapManager;
|
||||||
|
|
||||||
|
protected ScoreManager ScoreManager;
|
||||||
|
|
||||||
protected SkinManager SkinManager;
|
protected SkinManager SkinManager;
|
||||||
|
|
||||||
protected RulesetStore RulesetStore;
|
protected RulesetStore RulesetStore;
|
||||||
|
|
||||||
protected FileStore FileStore;
|
protected FileStore FileStore;
|
||||||
|
|
||||||
protected ScoreStore ScoreStore;
|
|
||||||
|
|
||||||
protected KeyBindingStore KeyBindingStore;
|
protected KeyBindingStore KeyBindingStore;
|
||||||
|
|
||||||
protected SettingsStore SettingsStore;
|
protected SettingsStore SettingsStore;
|
||||||
@ -154,14 +154,14 @@ namespace osu.Game
|
|||||||
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
|
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
|
||||||
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
|
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
|
||||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Audio, Host));
|
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(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||||
dependencies.Cache(new OsuColour());
|
dependencies.Cache(new OsuColour());
|
||||||
|
|
||||||
fileImporters.Add(BeatmapManager);
|
fileImporters.Add(BeatmapManager);
|
||||||
fileImporters.Add(ScoreStore);
|
fileImporters.Add(ScoreManager);
|
||||||
fileImporters.Add(SkinManager);
|
fileImporters.Add(SkinManager);
|
||||||
|
|
||||||
var defaultBeatmap = new DummyWorkingBeatmap(this);
|
var defaultBeatmap = new DummyWorkingBeatmap(this);
|
||||||
|
31
osu.Game/Scoring/ScoreManager.cs
Normal file
31
osu.Game/Scoring/ScoreManager.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +1,21 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System.Linq;
|
||||||
using System.IO;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.IPC;
|
|
||||||
using osu.Game.Rulesets.Scoring.Legacy;
|
|
||||||
|
|
||||||
namespace osu.Game.Scoring
|
namespace osu.Game.Scoring
|
||||||
{
|
{
|
||||||
public class ScoreStore : DatabaseBackedStore, ICanAcceptFiles
|
public class ScoreStore : MutableDatabaseBackedStore<Score>
|
||||||
{
|
{
|
||||||
private readonly BeatmapManager beatmaps;
|
public ScoreStore(IDatabaseContextFactory factory, Storage storage)
|
||||||
private readonly RulesetStore rulesets;
|
: base(factory, storage)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
this.beatmaps = beatmaps;
|
|
||||||
this.rulesets = rulesets;
|
|
||||||
|
|
||||||
if (importHost != null)
|
|
||||||
ipc = new ScoreIPCChannel(importHost, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] HandledExtensions => new[] { ".osr" };
|
protected override IQueryable<Score> AddIncludesForConsumption(IQueryable<Score> query)
|
||||||
|
=> base.AddIncludesForConsumption(query).Include(s => s.Files).ThenInclude(f => f.FileInfo);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user