1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 12:53:11 +08:00

more fixes (almost compiles, except ruleset and manager)

This commit is contained in:
Dean Herbert 2021-12-13 17:37:27 +09:00
parent e711a6d355
commit 53792811b2
17 changed files with 71 additions and 40 deletions

View File

@ -12,7 +12,9 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Scoring;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Scores.IO;
namespace osu.Game.Tests.Beatmaps.IO
{
@ -61,6 +63,15 @@ namespace osu.Game.Tests.Beatmaps.IO
Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);
}
private static Task createScoreForBeatmap(OsuGameBase osu, BeatmapInfo beatmapInfo)
{
return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo
{
OnlineID = 2,
BeatmapInfo = beatmapInfo,
}, new ImportScoreTest.TestArchiveReader());
}
private static void checkBeatmapSetCount(OsuGameBase osu, int expected, bool includeDeletePending = false)
{
var manager = osu.Dependencies.Get<BeatmapManager>();

View File

@ -164,7 +164,6 @@ namespace osu.Game.Tests.Resources
},
BeatmapInfo = beatmap,
Ruleset = beatmap.Ruleset,
RulesetID = beatmap.Ruleset.ID ?? 0,
Mods = new Mod[] { new TestModHardRock(), new TestModDoubleTime() },
TotalScore = 2845370,
Accuracy = 0.95,

View File

@ -7,6 +7,7 @@ using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Models;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources;
@ -157,10 +158,10 @@ namespace osu.Game.Tests.Visual.Ranking
public void TestSelectMultipleScores()
{
var firstScore = TestResources.CreateTestScoreInfo();
var secondScore = TestResources.CreateTestScoreInfo();
firstScore.RealmUser = new RealmUser { Username = "A" };
firstScore.UserString = "A";
secondScore.UserString = "B";
var secondScore = TestResources.CreateTestScoreInfo();
secondScore.RealmUser = new RealmUser { Username = "B" };
createListStep(() => new ScorePanelList());
@ -178,7 +179,7 @@ namespace osu.Game.Tests.Visual.Ranking
AddStep("select second score", () =>
{
InputManager.MoveMouseTo(list.ChildrenOfType<ScorePanel>().Single(p => p.Score == secondScore));
InputManager.MoveMouseTo(list.ChildrenOfType<ScorePanel>().Single(p => p.Score.Equals(secondScore)));
InputManager.Click(MouseButton.Left);
});
@ -303,6 +304,6 @@ namespace osu.Game.Tests.Visual.Ranking
=> AddUntilStep("first panel centred", () => Precision.AlmostEquals(list.ChildrenOfType<ScorePanel>().First().ScreenSpaceDrawQuad.Centre.X, list.ScreenSpaceDrawQuad.Centre.X, 1));
private void assertScoreState(ScoreInfo score, bool expanded)
=> AddUntilStep($"score expanded = {expanded}", () => (list.ChildrenOfType<ScorePanel>().Single(p => p.Score == score).State == PanelState.Expanded) == expanded);
=> AddUntilStep($"score expanded = {expanded}", () => (list.ChildrenOfType<ScorePanel>().Single(p => p.Score.Equals(score)).State == PanelState.Expanded) == expanded);
}
}

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Overlays;
@ -19,6 +20,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Stores;
using osu.Game.Tests.Resources;
using osu.Game.Users;
using osuTK;
@ -43,7 +45,7 @@ namespace osu.Game.Tests.Visual.SongSelect
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RealmRulesetStore>(), () => beatmapManager, LocalStorage, dependencies.Get<RealmContextFactory>(), Scheduler));
return dependencies;
}

View File

@ -24,6 +24,7 @@ using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Stores;
using osu.Game.Tests.Resources;
using osuTK;
using osuTK.Input;
@ -85,7 +86,7 @@ namespace osu.Game.Tests.Visual.UserInterface
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RealmRulesetStore>(), () => beatmapManager, LocalStorage, dependencies.Get<RealmContextFactory>(), Scheduler));
beatmapInfo = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).GetResultSafely().Value.Beatmaps[0];

View File

@ -399,7 +399,7 @@ namespace osu.Game.Online.Leaderboards
if (Score.Files.Count > 0)
items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => new LegacyScoreExporter(storage).Export(Score)));
if (Score.ID != 0)
if (Score.IsManaged)
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new LocalScoreDeleteDialog(Score))));
return items.ToArray();

View File

@ -224,7 +224,7 @@ namespace osu.Game
dependencies.Cache(RulesetStore = new RulesetStore(realmFactory, Storage));
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, realmFactory, Scheduler, Host, () => difficultyCache, LocalConfig));
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, realmFactory, Scheduler, Host, () => difficultyCache, LocalConfig));
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, realmFactory, RulesetStore, API, Audio, Resources, Host, defaultBeatmap, performOnlineLookups: true));
dependencies.Cache(BeatmapDownloader = new BeatmapModelDownloader(BeatmapManager, API));

View File

@ -107,7 +107,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{
set
{
if (score == value)
if (score.Equals(value))
return;
score = value;
@ -115,7 +115,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
accuracyColumn.Text = value.DisplayAccuracy;
maxComboColumn.Text = value.MaxCombo.ToLocalisableString(@"0\x");
ppColumn.Alpha = value.BeatmapInfo?.Status.GrantsPerformancePoints() == true ? 1 : 0;
ppColumn.Alpha = value.BeatmapInfo.Status.GrantsPerformancePoints() ? 1 : 0;
ppColumn.Text = value.PP?.ToLocalisableString(@"N0");
statisticsColumns.ChildrenEnumerable = value.GetStatisticsForDisplay().Select(createStatisticsColumn);

View File

@ -45,8 +45,8 @@ namespace osu.Game.Scoring.Legacy
sw.Write((byte)(score.ScoreInfo.Ruleset.OnlineID));
sw.Write(LATEST_VERSION);
sw.Write(score.ScoreInfo.BeatmapInfo.MD5Hash);
sw.Write(score.ScoreInfo.UserString);
sw.Write(FormattableString.Invariant($"lazer-{score.ScoreInfo.UserString}-{score.ScoreInfo.Date}").ComputeMD5Hash());
sw.Write(score.ScoreInfo.User.Username);
sw.Write(FormattableString.Invariant($"lazer-{score.ScoreInfo.User.Username}-{score.ScoreInfo.Date}").ComputeMD5Hash());
sw.Write((ushort)(score.ScoreInfo.GetCount300() ?? 0));
sw.Write((ushort)(score.ScoreInfo.GetCount100() ?? 0));
sw.Write((ushort)(score.ScoreInfo.GetCount50() ?? 0));

View File

@ -6,14 +6,14 @@ using System.Linq;
using osu.Framework.IO.Stores;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Rulesets;
using osu.Game.Scoring.Legacy;
using osu.Game.Stores;
namespace osu.Game.Scoring
{
public class LegacyDatabasedScore : Score
{
public LegacyDatabasedScore(ScoreInfo score, RulesetStore rulesets, BeatmapManager beatmaps, IResourceStore<byte[]> store)
public LegacyDatabasedScore(ScoreInfo score, RealmRulesetStore rulesets, BeatmapManager beatmaps, IResourceStore<byte[]> store)
{
ScoreInfo = score;

View File

@ -12,6 +12,7 @@ using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Models;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
@ -44,14 +45,27 @@ namespace osu.Game.Scoring
[MapTo("User")]
public RealmUser RealmUser { get; set; } = null!;
public IUser User
// TODO: this is a bit temporary to account for the fact that this class is used to ferry API user data to certain UI components.
// Eventually we should either persist enough information to realm to not require the API lookups, or perform the API lookups locally.
private APIUser? user;
public APIUser User
{
get => RealmUser;
set => RealmUser = new RealmUser
get => user ??= new APIUser
{
OnlineID = value.OnlineID,
Username = value.Username
Username = RealmUser.Username,
Id = RealmUser.OnlineID,
};
set
{
user = value;
RealmUser = new RealmUser
{
OnlineID = user.OnlineID,
Username = user.Username
};
}
}
public long TotalScore { get; set; }
@ -72,6 +86,7 @@ namespace osu.Game.Scoring
{
get => new BeatmapInfo();
// .. todo
// ReSharper disable once ValueParameterNotUsed
set => Beatmap = new RealmBeatmap(new RealmRuleset("osu", "osu!", "wangs", 0), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());
}
@ -89,6 +104,8 @@ namespace osu.Game.Scoring
return JsonConvert.DeserializeObject<Dictionary<HitResult, int>>(StatisticsJson) ?? new Dictionary<HitResult, int>();
}
// .. todo
// ReSharper disable once ValueParameterNotUsed
set => JsonConvert.SerializeObject(StatisticsJson);
}

View File

@ -20,6 +20,7 @@ using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Stores;
namespace osu.Game.Scoring
{
@ -37,7 +38,7 @@ namespace osu.Game.Scoring
this.difficulties = difficulties;
this.configManager = configManager;
scoreModelManager = new ScoreModelManager(rulesets, beatmaps, storage, contextFactory, importHost);
scoreModelManager = new ScoreModelManager(rulesets, beatmaps, storage, contextFactory);
}
public Score GetScore(ScoreInfo score) => scoreModelManager.GetScore(score);
@ -125,8 +126,9 @@ namespace osu.Game.Scoring
/// <returns>The total score.</returns>
public async Task<long> GetTotalScoreAsync([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised, CancellationToken cancellationToken = default)
{
if (score.Beatmap == null)
return score.TotalScore;
// TODO: ??
// if (score.Beatmap == null)
// return score.TotalScore;
int beatmapMaxCombo;
double accuracy = score.Accuracy;
@ -150,7 +152,7 @@ namespace osu.Game.Scoring
beatmapMaxCombo = score.Beatmap.MaxCombo.Value;
else
{
if (score.Beatmap.ID == 0 || difficulties == null)
if (!score.Beatmap.IsManaged || difficulties == null)
{
// We don't have enough information (max combo) to compute the score, so use the provided score.
return score.TotalScore;

View File

@ -11,7 +11,6 @@ using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Rulesets;
using osu.Game.Scoring.Legacy;
using osu.Game.Stores;
using Realms;
@ -26,10 +25,10 @@ namespace osu.Game.Scoring
protected override string[] HashableFileTypes => new[] { ".osr" };
private readonly RulesetStore rulesets;
private readonly RealmRulesetStore rulesets;
private readonly Func<BeatmapManager> beatmaps;
public ScoreModelManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmContextFactory contextFactory)
public ScoreModelManager(RealmRulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, RealmContextFactory contextFactory)
: base(storage, contextFactory)
{
this.rulesets = rulesets;

View File

@ -226,8 +226,6 @@ namespace osu.Game.Screens.Play
// ensure the score is in a consistent state with the current player.
Score.ScoreInfo.BeatmapInfo = Beatmap.Value.BeatmapInfo;
Score.ScoreInfo.Ruleset = ruleset.RulesetInfo;
if (ruleset.RulesetInfo.OnlineID >= 0)
Score.ScoreInfo.RulesetID = ruleset.RulesetInfo.OnlineID;
Score.ScoreInfo.Mods = gameplayMods;
dependencies.CacheAs(GameplayState = new GameplayState(playableBeatmap, ruleset, gameplayMods, Score));
@ -1045,7 +1043,8 @@ namespace osu.Game.Screens.Play
//
// Until we better define the server-side logic behind this, let's not store the online ID to avoid potential unique constraint
// conflicts across various systems (ie. solo and multiplayer).
long? onlineScoreId = score.ScoreInfo.OnlineID;
long onlineScoreId = score.ScoreInfo.OnlineID;
score.ScoreInfo.OnlineID = -1;
await scoreManager.Import(score.ScoreInfo, replayReader).ConfigureAwait(false);

View File

@ -107,7 +107,7 @@ namespace osu.Game.Screens.Ranking.Contracted
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = score.UserString,
Text = score.RealmUser.Username,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.SemiBold)
},
new FillFlowContainer

View File

@ -158,7 +158,7 @@ namespace osu.Game.Screens.Ranking
trackingContainer.Show();
if (SelectedScore.Value == score)
if (SelectedScore.Value.Equals(score))
{
SelectedScore.TriggerChange();
}
@ -185,10 +185,10 @@ namespace osu.Game.Screens.Ranking
private void selectedScoreChanged(ValueChangedEvent<ScoreInfo> score)
{
// avoid contracting panels unnecessarily when TriggerChange is fired manually.
if (score.OldValue != score.NewValue)
if (!score.OldValue.Equals(score.NewValue))
{
// Contract the old panel.
foreach (var t in flow.Where(t => t.Panel.Score == score.OldValue))
foreach (var t in flow.Where(t => t.Panel.Score.Equals(score.OldValue)))
{
t.Panel.State = PanelState.Contracted;
t.Margin = new MarginPadding();
@ -269,7 +269,7 @@ namespace osu.Game.Screens.Ranking
/// </summary>
/// <param name="score">The <see cref="ScoreInfo"/> to find the corresponding <see cref="ScorePanel"/> for.</param>
/// <returns>The <see cref="ScorePanel"/>.</returns>
public ScorePanel GetPanelForScore(ScoreInfo score) => flow.Single(t => t.Panel.Score == score).Panel;
public ScorePanel GetPanelForScore(ScoreInfo score) => flow.Single(t => t.Panel.Score.Equals(score)).Panel;
/// <summary>
/// Detaches a <see cref="ScorePanel"/> from its <see cref="ScorePanelTrackingContainer"/>, allowing the panel to be moved elsewhere in the hierarchy.
@ -332,13 +332,13 @@ namespace osu.Game.Screens.Ranking
{
public override IEnumerable<Drawable> FlowingChildren => applySorting(AliveInternalChildren);
public int GetPanelIndex(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).Count();
public int GetPanelIndex(ScoreInfo score) => applySorting(Children).TakeWhile(s => !s.Panel.Score.Equals(score)).Count();
[CanBeNull]
public ScoreInfo GetPreviousScore(ScoreInfo score) => applySorting(Children).TakeWhile(s => s.Panel.Score != score).LastOrDefault()?.Panel.Score;
public ScoreInfo GetPreviousScore(ScoreInfo score) => applySorting(Children).TakeWhile(s => !s.Panel.Score.Equals(score)).LastOrDefault()?.Panel.Score;
[CanBeNull]
public ScoreInfo GetNextScore(ScoreInfo score) => applySorting(Children).SkipWhile(s => s.Panel.Score != score).ElementAtOrDefault(1)?.Panel.Score;
public ScoreInfo GetNextScore(ScoreInfo score) => applySorting(Children).SkipWhile(s => !s.Panel.Score.Equals(score)).ElementAtOrDefault(1)?.Panel.Score;
private IEnumerable<ScorePanelTrackingContainer> applySorting(IEnumerable<Drawable> drawables) => drawables.OfType<ScorePanelTrackingContainer>()
.OrderByDescending(GetLayoutPosition)

View File

@ -142,7 +142,7 @@ namespace osu.Game.Screens.Ranking.Statistics
LoadComponentAsync(rows, d =>
{
if (Score.Value != newScore)
if (!Score.Value.Equals(newScore))
return;
spinner.Hide();