1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 08:22:56 +08:00

Moved all online score related parsing to its own class

This commit is contained in:
MrTheMake 2017-09-07 18:20:14 +02:00
parent f831832c59
commit 709aa1ed3d
4 changed files with 25 additions and 27 deletions

View File

@ -22,11 +22,8 @@ namespace osu.Game.Online.API.Requests
private void onSuccess(GetScoresResponse r) private void onSuccess(GetScoresResponse r)
{ {
foreach (Score score in r.Scores) foreach (OnlineScore score in r.Scores)
{ score.GetModsFor(beatmap.Ruleset);
score.Beatmap = beatmap;
score.Ruleset = beatmap.Ruleset;
}
} }
protected override WebRequest CreateWebRequest() protected override WebRequest CreateWebRequest()
@ -43,6 +40,6 @@ namespace osu.Game.Online.API.Requests
public class GetScoresResponse public class GetScoresResponse
{ {
[JsonProperty(@"scores")] [JsonProperty(@"scores")]
public IEnumerable<Score> Scores; public IEnumerable<OnlineScore> Scores;
} }
} }

View File

@ -0,0 +1,19 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using Newtonsoft.Json;
namespace osu.Game.Rulesets.Scoring
{
public class OnlineScore : Score
{
[JsonProperty(@"mods")]
private string[] modStrings { get; set; }
public void GetModsFor(RulesetInfo ruleset)
{
Mods = ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray();
}
}
}

View File

@ -2,7 +2,6 @@
// 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;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -28,27 +27,9 @@ namespace osu.Game.Rulesets.Scoring
public int Combo { get; set; } public int Combo { get; set; }
[JsonProperty(@"mods")]
private string[] modStrings { get; set; }
public RulesetInfo Ruleset; public RulesetInfo Ruleset;
private Mod[] mods; public Mod[] Mods;
public Mod[] Mods
{
get
{
// Evaluate the mod strings if necessary
return mods ?? (mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray());
}
set
{
mods = value;
// Assign the mod strings
modStrings = mods.Select(mod => mod.ShortenedName).ToArray();
}
}
[JsonProperty(@"user")] [JsonProperty(@"user")]
public User User; public User User;

View File

@ -128,6 +128,7 @@
<Compile Include="Overlays\Profile\Sections\RecentSection.cs" /> <Compile Include="Overlays\Profile\Sections\RecentSection.cs" />
<Compile Include="Graphics\Containers\ConstrainedIconContainer.cs" /> <Compile Include="Graphics\Containers\ConstrainedIconContainer.cs" />
<Compile Include="Rulesets\Mods\IApplicableToDifficulty.cs" /> <Compile Include="Rulesets\Mods\IApplicableToDifficulty.cs" />
<Compile Include="Rulesets\Scoring\OnlineScore.cs" />
<Compile Include="Users\UserCoverBackground.cs" /> <Compile Include="Users\UserCoverBackground.cs" />
<Compile Include="Overlays\UserProfileOverlay.cs" /> <Compile Include="Overlays\UserProfileOverlay.cs" />
<Compile Include="Overlays\Profile\ProfileHeader.cs" /> <Compile Include="Overlays\Profile\ProfileHeader.cs" />