mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 05:32:54 +08:00
Merge branch 'master' into new-interfaces
This commit is contained in:
commit
1d99bc280f
1
.github/workflows/diffcalc.yml
vendored
1
.github/workflows/diffcalc.yml
vendored
@ -53,6 +53,7 @@ jobs:
|
|||||||
diffcalc:
|
diffcalc:
|
||||||
name: Run
|
name: Run
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
|
timeout-minutes: 1440
|
||||||
if: needs.metadata.outputs.continue == 'yes'
|
if: needs.metadata.outputs.continue == 'yes'
|
||||||
needs: metadata
|
needs: metadata
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -51,11 +51,11 @@
|
|||||||
<Reference Include="Java.Interop" />
|
<Reference Include="Java.Interop" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.918.0" />
|
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1004.0" />
|
||||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.929.0" />
|
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.929.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Transitive Dependencies">
|
<ItemGroup Label="Transitive Dependencies">
|
||||||
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
|
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
|
||||||
<PackageReference Include="Realm" Version="10.5.0" />
|
<PackageReference Include="Realm" Version="10.6.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -140,10 +140,10 @@ namespace osu.Desktop
|
|||||||
switch (activity)
|
switch (activity)
|
||||||
{
|
{
|
||||||
case UserActivity.InGame game:
|
case UserActivity.InGame game:
|
||||||
return game.Beatmap.ToString();
|
return game.BeatmapInfo.ToString();
|
||||||
|
|
||||||
case UserActivity.Editing edit:
|
case UserActivity.Editing edit:
|
||||||
return edit.Beatmap.ToString();
|
return edit.BeatmapInfo.ToString();
|
||||||
|
|
||||||
case UserActivity.InLobby lobby:
|
case UserActivity.InLobby lobby:
|
||||||
return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value;
|
return privacyMode.Value == DiscordRichPresenceMode.Limited ? string.Empty : lobby.Room.Name.Value;
|
||||||
|
@ -71,9 +71,9 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
|
|||||||
originalTargetColumns = TargetColumns;
|
originalTargetColumns = TargetColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetColumnCountForNonConvert(BeatmapInfo beatmap)
|
public static int GetColumnCountForNonConvert(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
var roundedCircleSize = Math.Round(beatmap.BaseDifficulty.CircleSize);
|
var roundedCircleSize = Math.Round(beatmapInfo.BaseDifficulty.CircleSize);
|
||||||
return (int)Math.Max(1, roundedCircleSize);
|
return (int)Math.Max(1, roundedCircleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ namespace osu.Game.Rulesets.Mania
|
|||||||
{
|
{
|
||||||
private FilterCriteria.OptionalRange<float> keys;
|
private FilterCriteria.OptionalRange<float> keys;
|
||||||
|
|
||||||
public bool Matches(BeatmapInfo beatmap)
|
public bool Matches(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
return !keys.HasFilter || (beatmap.RulesetID == new ManiaRuleset().LegacyID && keys.IsInRange(ManiaBeatmapConverter.GetColumnCountForNonConvert(beatmap)));
|
return !keys.HasFilter || (beatmapInfo.RulesetID == new ManiaRuleset().LegacyID && keys.IsInRange(ManiaBeatmapConverter.GetColumnCountForNonConvert(beatmapInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
|
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
|
||||||
|
@ -4,13 +4,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Tests.Mods
|
namespace osu.Game.Rulesets.Osu.Tests.Mods
|
||||||
@ -122,7 +120,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
|
|||||||
private bool checkSomeHit() => Player.ScoreProcessor.JudgedHits >= 4;
|
private bool checkSomeHit() => Player.ScoreProcessor.JudgedHits >= 4;
|
||||||
|
|
||||||
private bool objectWithIncreasedVisibilityHasIndex(int index)
|
private bool objectWithIncreasedVisibilityHasIndex(int index)
|
||||||
=> Player.Mods.Value.OfType<TestOsuModHidden>().Single().FirstObject == Player.ChildrenOfType<GameplayBeatmap>().Single().HitObjects[index];
|
=> Player.Mods.Value.OfType<TestOsuModHidden>().Single().FirstObject == Player.GameplayState.Beatmap.HitObjects[index];
|
||||||
|
|
||||||
private class TestOsuModHidden : OsuModHidden
|
private class TestOsuModHidden : OsuModHidden
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,3 @@
|
|||||||
|
[General]
|
||||||
|
Version: latest
|
||||||
|
HitCircleOverlayAboveNumber: 0
|
@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
{
|
{
|
||||||
Position = new Vector2(100, 300),
|
Position = new Vector2(100, 300),
|
||||||
},
|
},
|
||||||
accuracyHeatmap = new TestAccuracyHeatmap(new ScoreInfo { Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo })
|
accuracyHeatmap = new TestAccuracyHeatmap(new ScoreInfo { BeatmapInfo = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo })
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
@ -17,6 +17,7 @@ using osu.Framework.Testing.Input;
|
|||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu.Skinning;
|
using osu.Game.Rulesets.Osu.Skinning;
|
||||||
using osu.Game.Rulesets.Osu.UI.Cursor;
|
using osu.Game.Rulesets.Osu.UI.Cursor;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
@ -29,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
public class TestSceneGameplayCursor : OsuSkinnableTestScene
|
public class TestSceneGameplayCursor : OsuSkinnableTestScene
|
||||||
{
|
{
|
||||||
[Cached]
|
[Cached]
|
||||||
private GameplayBeatmap gameplayBeatmap;
|
private GameplayState gameplayState;
|
||||||
|
|
||||||
private OsuCursorContainer lastContainer;
|
private OsuCursorContainer lastContainer;
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
|
|
||||||
public TestSceneGameplayCursor()
|
public TestSceneGameplayCursor()
|
||||||
{
|
{
|
||||||
gameplayBeatmap = new GameplayBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
|
var ruleset = new OsuRuleset();
|
||||||
|
gameplayState = new GameplayState(CreateBeatmap(ruleset.RulesetInfo), ruleset, Array.Empty<Mod>());
|
||||||
|
|
||||||
AddStep("change background colour", () =>
|
AddStep("change background colour", () =>
|
||||||
{
|
{
|
||||||
@ -57,7 +59,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
AddSliderStep("circle size", 0f, 10f, 0f, val =>
|
AddSliderStep("circle size", 0f, 10f, 0f, val =>
|
||||||
{
|
{
|
||||||
config.SetValue(OsuSetting.AutoCursorSize, true);
|
config.SetValue(OsuSetting.AutoCursorSize, true);
|
||||||
gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = val;
|
gameplayState.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize = val;
|
||||||
Scheduler.AddOnce(() => loadContent(false));
|
Scheduler.AddOnce(() => loadContent(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
public void TestSizing(int circleSize, float userScale)
|
public void TestSizing(int circleSize, float userScale)
|
||||||
{
|
{
|
||||||
AddStep($"set user scale to {userScale}", () => config.SetValue(OsuSetting.GameplayCursorSize, userScale));
|
AddStep($"set user scale to {userScale}", () => config.SetValue(OsuSetting.GameplayCursorSize, userScale));
|
||||||
AddStep($"adjust cs to {circleSize}", () => gameplayBeatmap.BeatmapInfo.BaseDifficulty.CircleSize = circleSize);
|
AddStep($"adjust cs to {circleSize}", () => gameplayState.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize = circleSize);
|
||||||
AddStep("turn on autosizing", () => config.SetValue(OsuSetting.AutoCursorSize, true));
|
AddStep("turn on autosizing", () => config.SetValue(OsuSetting.AutoCursorSize, true));
|
||||||
|
|
||||||
AddStep("load content", () => loadContent());
|
AddStep("load content", () => loadContent());
|
||||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
private OsuPlayfield playfield { get; set; }
|
private OsuPlayfield playfield { get; set; }
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private GameplayBeatmap gameplayBeatmap { get; set; }
|
private GameplayState gameplayState { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(ISkinSource skin, OsuColour colours)
|
private void load(ISkinSource skin, OsuColour colours)
|
||||||
@ -75,12 +75,12 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (playfield == null || gameplayBeatmap == null) return;
|
if (playfield == null || gameplayState == null) return;
|
||||||
|
|
||||||
DrawableHitObject kiaiHitObject = null;
|
DrawableHitObject kiaiHitObject = null;
|
||||||
|
|
||||||
// Check whether currently in a kiai section first. This is only done as an optimisation to avoid enumerating AliveObjects when not necessary.
|
// Check whether currently in a kiai section first. This is only done as an optimisation to avoid enumerating AliveObjects when not necessary.
|
||||||
if (gameplayBeatmap.ControlPointInfo.EffectPointAt(Time.Current).KiaiMode)
|
if (gameplayState.Beatmap.ControlPointInfo.EffectPointAt(Time.Current).KiaiMode)
|
||||||
kiaiHitObject = playfield.HitObjectContainer.AliveObjects.FirstOrDefault(isTracking);
|
kiaiHitObject = playfield.HitObjectContainer.AliveObjects.FirstOrDefault(isTracking);
|
||||||
|
|
||||||
kiaiSpewer.Active.Value = kiaiHitObject != null;
|
kiaiSpewer.Active.Value = kiaiHitObject != null;
|
||||||
|
@ -35,8 +35,9 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
|
|
||||||
private Drawable hitCircleSprite;
|
private Drawable hitCircleSprite;
|
||||||
|
|
||||||
protected Drawable HitCircleOverlay { get; private set; }
|
protected Container OverlayLayer { get; private set; }
|
||||||
|
|
||||||
|
private Drawable hitCircleOverlay;
|
||||||
private SkinnableSpriteText hitCircleText;
|
private SkinnableSpriteText hitCircleText;
|
||||||
|
|
||||||
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
||||||
@ -78,17 +79,22 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
},
|
},
|
||||||
HitCircleOverlay = new KiaiFlashingSprite
|
OverlayLayer = new Container
|
||||||
{
|
{
|
||||||
Texture = overlayTexture,
|
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
},
|
Child = hitCircleOverlay = new KiaiFlashingSprite
|
||||||
|
{
|
||||||
|
Texture = overlayTexture,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasNumber)
|
if (hasNumber)
|
||||||
{
|
{
|
||||||
AddInternal(hitCircleText = new SkinnableSpriteText(new OsuSkinComponent(OsuSkinComponents.HitCircleText), _ => new OsuSpriteText
|
OverlayLayer.Add(hitCircleText = new SkinnableSpriteText(new OsuSkinComponent(OsuSkinComponents.HitCircleText), _ => new OsuSpriteText
|
||||||
{
|
{
|
||||||
Font = OsuFont.Numeric.With(size: 40),
|
Font = OsuFont.Numeric.With(size: 40),
|
||||||
UseFullGlyphHeight = false,
|
UseFullGlyphHeight = false,
|
||||||
@ -102,7 +108,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
bool overlayAboveNumber = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.HitCircleOverlayAboveNumber)?.Value ?? true;
|
bool overlayAboveNumber = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.HitCircleOverlayAboveNumber)?.Value ?? true;
|
||||||
|
|
||||||
if (overlayAboveNumber)
|
if (overlayAboveNumber)
|
||||||
ChangeInternalChildDepth(HitCircleOverlay, float.MinValue);
|
OverlayLayer.ChangeChildDepth(hitCircleOverlay, float.MinValue);
|
||||||
|
|
||||||
accentColour.BindTo(drawableObject.AccentColour);
|
accentColour.BindTo(drawableObject.AccentColour);
|
||||||
indexInCurrentCombo.BindTo(drawableOsuObject.IndexInCurrentComboBindable);
|
indexInCurrentCombo.BindTo(drawableOsuObject.IndexInCurrentComboBindable);
|
||||||
@ -147,8 +153,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
hitCircleSprite.FadeOut(legacy_fade_duration, Easing.Out);
|
hitCircleSprite.FadeOut(legacy_fade_duration, Easing.Out);
|
||||||
hitCircleSprite.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
hitCircleSprite.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
||||||
|
|
||||||
HitCircleOverlay.FadeOut(legacy_fade_duration, Easing.Out);
|
hitCircleOverlay.FadeOut(legacy_fade_duration, Easing.Out);
|
||||||
HitCircleOverlay.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
hitCircleOverlay.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
||||||
|
|
||||||
if (hasNumber)
|
if (hasNumber)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private DrawableHitObject drawableHitObject { get; set; }
|
private DrawableHitObject drawableHitObject { get; set; }
|
||||||
|
|
||||||
private Drawable proxiedHitCircleOverlay;
|
private Drawable proxiedOverlayLayer;
|
||||||
|
|
||||||
public LegacySliderHeadHitCircle()
|
public LegacySliderHeadHitCircle()
|
||||||
: base("sliderstartcircle")
|
: base("sliderstartcircle")
|
||||||
@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
proxiedHitCircleOverlay = HitCircleOverlay.CreateProxy();
|
proxiedOverlayLayer = OverlayLayer.CreateProxy();
|
||||||
|
|
||||||
if (drawableHitObject != null)
|
if (drawableHitObject != null)
|
||||||
{
|
{
|
||||||
@ -35,11 +35,11 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
|
|
||||||
private void onHitObjectApplied(DrawableHitObject drawableObject)
|
private void onHitObjectApplied(DrawableHitObject drawableObject)
|
||||||
{
|
{
|
||||||
Debug.Assert(proxiedHitCircleOverlay.Parent == null);
|
Debug.Assert(proxiedOverlayLayer.Parent == null);
|
||||||
|
|
||||||
// see logic in LegacyReverseArrow.
|
// see logic in LegacyReverseArrow.
|
||||||
(drawableObject as DrawableSliderHead)?.DrawableSlider
|
(drawableObject as DrawableSliderHead)?.DrawableSlider
|
||||||
.OverlayElementContainer.Add(proxiedHitCircleOverlay.With(d => d.Depth = float.MinValue));
|
.OverlayElementContainer.Add(proxiedOverlayLayer.With(d => d.Depth = float.MinValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private GameplayBeatmap beatmap { get; set; }
|
private GameplayState state { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuConfigManager config { get; set; }
|
private OsuConfigManager config { get; set; }
|
||||||
@ -96,10 +96,10 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
|
|||||||
{
|
{
|
||||||
float scale = userCursorScale.Value;
|
float scale = userCursorScale.Value;
|
||||||
|
|
||||||
if (autoCursorScale.Value && beatmap != null)
|
if (autoCursorScale.Value && state != null)
|
||||||
{
|
{
|
||||||
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
|
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
|
||||||
scale *= GetScaleForCircleSize(beatmap.BeatmapInfo.BaseDifficulty.CircleSize);
|
scale *= GetScaleForCircleSize(state.Beatmap.BeatmapInfo.BaseDifficulty.CircleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorScale.Value = scale;
|
cursorScale.Value = scale;
|
||||||
|
@ -25,10 +25,10 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(GameplayBeatmap gameplayBeatmap)
|
private void load(GameplayState gameplayState)
|
||||||
{
|
{
|
||||||
if (gameplayBeatmap != null)
|
if (gameplayState != null)
|
||||||
((IBindable<JudgementResult>)LastResult).BindTo(gameplayBeatmap.LastJudgementResult);
|
((IBindable<JudgementResult>)LastResult).BindTo(gameplayState.LastJudgementResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool passing;
|
private bool passing;
|
||||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(TextureStore textures, GameplayBeatmap gameplayBeatmap)
|
private void load(TextureStore textures, GameplayState gameplayState)
|
||||||
{
|
{
|
||||||
InternalChildren = new[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
@ -49,8 +49,8 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
animations[TaikoMascotAnimationState.Fail] = new TaikoMascotAnimation(TaikoMascotAnimationState.Fail),
|
animations[TaikoMascotAnimationState.Fail] = new TaikoMascotAnimation(TaikoMascotAnimationState.Fail),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (gameplayBeatmap != null)
|
if (gameplayState != null)
|
||||||
((IBindable<JudgementResult>)LastResult).BindTo(gameplayBeatmap.LastJudgementResult);
|
((IBindable<JudgementResult>)LastResult).BindTo(gameplayState.LastJudgementResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -149,5 +149,32 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[5]).LoopType);
|
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[5]).LoopType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDecodeLoopCount()
|
||||||
|
{
|
||||||
|
// all loop sequences in loop-count.osb have a total duration of 2000ms (fade in 0->1000ms, fade out 1000->2000ms).
|
||||||
|
const double loop_duration = 2000;
|
||||||
|
|
||||||
|
var decoder = new LegacyStoryboardDecoder();
|
||||||
|
|
||||||
|
using (var resStream = TestResources.OpenResource("loop-count.osb"))
|
||||||
|
using (var stream = new LineBufferedReader(resStream))
|
||||||
|
{
|
||||||
|
var storyboard = decoder.Decode(stream);
|
||||||
|
|
||||||
|
StoryboardLayer background = storyboard.Layers.Single(l => l.Depth == 3);
|
||||||
|
|
||||||
|
// stable ensures that any loop command executes at least once, even if the loop count specified in the .osb is zero or negative.
|
||||||
|
StoryboardSprite zeroTimes = background.Elements.OfType<StoryboardSprite>().Single(s => s.Path == "zero-times.png");
|
||||||
|
Assert.That(zeroTimes.EndTime, Is.EqualTo(1000 + loop_duration));
|
||||||
|
|
||||||
|
StoryboardSprite oneTime = background.Elements.OfType<StoryboardSprite>().Single(s => s.Path == "one-time.png");
|
||||||
|
Assert.That(oneTime.EndTime, Is.EqualTo(4000 + loop_duration));
|
||||||
|
|
||||||
|
StoryboardSprite manyTimes = background.Elements.OfType<StoryboardSprite>().Single(s => s.Path == "many-times.png");
|
||||||
|
Assert.That(manyTimes.EndTime, Is.EqualTo(9000 + 40 * loop_duration));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
BeatmapSetInfo importedSet;
|
ILive<BeatmapSetInfo> importedSet;
|
||||||
|
|
||||||
using (var stream = File.OpenRead(tempPath))
|
using (var stream = File.OpenRead(tempPath))
|
||||||
{
|
{
|
||||||
@ -97,7 +97,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
|
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
|
||||||
File.Delete(tempPath);
|
File.Delete(tempPath);
|
||||||
|
|
||||||
var imported = manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
|
var imported = manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
||||||
|
|
||||||
deleteBeatmapSet(imported, osu);
|
deleteBeatmapSet(imported, osu);
|
||||||
}
|
}
|
||||||
@ -172,8 +172,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
// but contents doesn't, so existing should still be used.
|
// but contents doesn't, so existing should still be used.
|
||||||
Assert.IsTrue(imported.ID == importedSecondTime.ID);
|
Assert.IsTrue(imported.ID == importedSecondTime.Value.ID);
|
||||||
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID);
|
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Value.Beatmaps.First().ID);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -226,8 +226,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Beatmaps.First().ID);
|
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Value.Beatmaps.First().ID);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -278,8 +278,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Beatmaps.First().ID);
|
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Value.Beatmaps.First().ID);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -329,8 +329,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Beatmaps.First().ID);
|
Assert.IsTrue(imported.Beatmaps.First().ID != importedSecondTime.Value.Beatmaps.First().ID);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -570,8 +570,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
var imported = await manager.Import(toImport);
|
var imported = await manager.Import(toImport);
|
||||||
|
|
||||||
Assert.NotNull(imported);
|
Assert.NotNull(imported);
|
||||||
Assert.AreEqual(null, imported.Beatmaps[0].OnlineBeatmapID);
|
Assert.AreEqual(null, imported.Value.Beatmaps[0].OnlineBeatmapID);
|
||||||
Assert.AreEqual(null, imported.Beatmaps[1].OnlineBeatmapID);
|
Assert.AreEqual(null, imported.Value.Beatmaps[1].OnlineBeatmapID);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -706,7 +706,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("subfolder")), "Files contain common subfolder");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("subfolder")), "Files contain common subfolder");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -759,8 +759,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
ensureLoaded(osu);
|
ensureLoaded(osu);
|
||||||
|
|
||||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
||||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -915,7 +915,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
||||||
|
|
||||||
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
|
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false)
|
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false)
|
||||||
@ -930,7 +930,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
||||||
|
|
||||||
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
|
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu)
|
private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu)
|
||||||
@ -945,13 +945,13 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);
|
Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Task createScoreForBeatmap(OsuGameBase osu, BeatmapInfo beatmap)
|
private static Task createScoreForBeatmap(OsuGameBase osu, BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo
|
return ImportScoreTest.LoadScoreIntoOsu(osu, new ScoreInfo
|
||||||
{
|
{
|
||||||
OnlineScoreID = 2,
|
OnlineScoreID = 2,
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
BeatmapInfoID = beatmap.ID
|
BeatmapInfoID = beatmapInfo.ID
|
||||||
}, new ImportScoreTest.TestArchiveReader());
|
}, new ImportScoreTest.TestArchiveReader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
64
osu.Game.Tests/Database/GeneralUsageTests.cs
Normal file
64
osu.Game.Tests/Database/GeneralUsageTests.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Database
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class GeneralUsageTests : RealmTest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Just test the construction of a new database works.
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void TestConstructRealm()
|
||||||
|
{
|
||||||
|
RunTestWithRealm((realmFactory, _) => { realmFactory.CreateContext().Refresh(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBlockOperations()
|
||||||
|
{
|
||||||
|
RunTestWithRealm((realmFactory, _) =>
|
||||||
|
{
|
||||||
|
using (realmFactory.BlockAllOperations())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBlockOperationsWithContention()
|
||||||
|
{
|
||||||
|
RunTestWithRealm((realmFactory, _) =>
|
||||||
|
{
|
||||||
|
ManualResetEventSlim stopThreadedUsage = new ManualResetEventSlim();
|
||||||
|
ManualResetEventSlim hasThreadedUsage = new ManualResetEventSlim();
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
using (realmFactory.CreateContext())
|
||||||
|
{
|
||||||
|
hasThreadedUsage.Set();
|
||||||
|
|
||||||
|
stopThreadedUsage.Wait();
|
||||||
|
}
|
||||||
|
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler);
|
||||||
|
|
||||||
|
hasThreadedUsage.Wait();
|
||||||
|
|
||||||
|
Assert.Throws<TimeoutException>(() =>
|
||||||
|
{
|
||||||
|
using (realmFactory.BlockAllOperations())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
stopThreadedUsage.Set();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
83
osu.Game.Tests/Database/RealmTest.cs
Normal file
83
osu.Game.Tests/Database/RealmTest.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// 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.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Nito.AsyncEx;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Database;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Database
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public abstract class RealmTest
|
||||||
|
{
|
||||||
|
private static readonly TemporaryNativeStorage storage;
|
||||||
|
|
||||||
|
static RealmTest()
|
||||||
|
{
|
||||||
|
storage = new TemporaryNativeStorage("realm-test");
|
||||||
|
storage.DeleteDirectory(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void RunTestWithRealm(Action<RealmContextFactory, Storage> testAction, [CallerMemberName] string caller = "")
|
||||||
|
{
|
||||||
|
AsyncContext.Run(() =>
|
||||||
|
{
|
||||||
|
var testStorage = storage.GetStorageForDirectory(caller);
|
||||||
|
|
||||||
|
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||||
|
{
|
||||||
|
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||||
|
testAction(realmFactory, testStorage);
|
||||||
|
|
||||||
|
realmFactory.Dispose();
|
||||||
|
|
||||||
|
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||||
|
realmFactory.Compact();
|
||||||
|
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void RunTestWithRealmAsync(Func<RealmContextFactory, Storage, Task> testAction, [CallerMemberName] string caller = "")
|
||||||
|
{
|
||||||
|
AsyncContext.Run(async () =>
|
||||||
|
{
|
||||||
|
var testStorage = storage.GetStorageForDirectory(caller);
|
||||||
|
|
||||||
|
using (var realmFactory = new RealmContextFactory(testStorage, caller))
|
||||||
|
{
|
||||||
|
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||||
|
await testAction(realmFactory, testStorage);
|
||||||
|
|
||||||
|
realmFactory.Dispose();
|
||||||
|
|
||||||
|
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||||
|
realmFactory.Compact();
|
||||||
|
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long getFileSize(Storage testStorage, RealmContextFactory realmFactory)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = testStorage.GetStream(realmFactory.Filename))
|
||||||
|
return stream?.Length ?? 0;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// windows runs may error due to file still being open.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
storage = new NativeStorage(directory.FullName);
|
storage = new NativeStorage(directory.FullName);
|
||||||
|
|
||||||
realmContextFactory = new RealmContextFactory(storage);
|
realmContextFactory = new RealmContextFactory(storage, "test");
|
||||||
keyBindingStore = new RealmKeyBindingStore(realmContextFactory);
|
keyBindingStore = new RealmKeyBindingStore(realmContextFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,9 +53,9 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
private int queryCount(GlobalAction? match = null)
|
private int queryCount(GlobalAction? match = null)
|
||||||
{
|
{
|
||||||
using (var usage = realmContextFactory.GetForRead())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
var results = usage.Realm.All<RealmKeyBinding>();
|
var results = realm.All<RealmKeyBinding>();
|
||||||
if (match.HasValue)
|
if (match.HasValue)
|
||||||
results = results.Where(k => k.ActionInt == (int)match.Value);
|
results = results.Where(k => k.ActionInt == (int)match.Value);
|
||||||
return results.Count();
|
return results.Count();
|
||||||
@ -69,26 +69,24 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
keyBindingStore.Register(testContainer, Enumerable.Empty<RulesetInfo>());
|
keyBindingStore.Register(testContainer, Enumerable.Empty<RulesetInfo>());
|
||||||
|
|
||||||
using (var primaryUsage = realmContextFactory.GetForRead())
|
using (var primaryRealm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
var backBinding = primaryUsage.Realm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
var backBinding = primaryRealm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||||
|
|
||||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.Escape }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.Escape }));
|
||||||
|
|
||||||
var tsr = ThreadSafeReference.Create(backBinding);
|
var tsr = ThreadSafeReference.Create(backBinding);
|
||||||
|
|
||||||
using (var usage = realmContextFactory.GetForWrite())
|
using (var threadedContext = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
var binding = usage.Realm.ResolveReference(tsr);
|
var binding = threadedContext.ResolveReference(tsr);
|
||||||
binding.KeyCombination = new KeyCombination(InputKey.BackSpace);
|
threadedContext.Write(() => binding.KeyCombination = new KeyCombination(InputKey.BackSpace));
|
||||||
|
|
||||||
usage.Commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||||
|
|
||||||
// check still correct after re-query.
|
// check still correct after re-query.
|
||||||
backBinding = primaryUsage.Realm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
backBinding = primaryRealm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||||
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
|
|||||||
match = shouldMatch;
|
match = shouldMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Matches(BeatmapInfo beatmap) => match;
|
public bool Matches(BeatmapInfo beatmapInfo) => match;
|
||||||
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value) => false;
|
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value) => false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
|
|||||||
{
|
{
|
||||||
public string CustomValue { get; set; }
|
public string CustomValue { get; set; }
|
||||||
|
|
||||||
public bool Matches(BeatmapInfo beatmap) => true;
|
public bool Matches(BeatmapInfo beatmapInfo) => true;
|
||||||
|
|
||||||
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
|
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value)
|
||||||
{
|
{
|
||||||
|
@ -156,20 +156,49 @@ namespace osu.Game.Tests.Online
|
|||||||
{
|
{
|
||||||
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
|
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
public Task<BeatmapSetInfo> CurrentImportTask { get; private set; }
|
public Task<ILive<BeatmapSetInfo>> CurrentImportTask { get; private set; }
|
||||||
|
|
||||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null, WorkingBeatmap defaultBeatmap = null)
|
||||||
=> new TestDownloadRequest(set);
|
: base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap)
|
||||||
|
|
||||||
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null, WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
|
||||||
: base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap, performOnlineLookups)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default)
|
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, GameHost host)
|
||||||
{
|
{
|
||||||
await AllowImport.Task.ConfigureAwait(false);
|
return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, api, host);
|
||||||
return await (CurrentImportTask = base.Import(item, archive, lowPriority, cancellationToken)).ConfigureAwait(false);
|
}
|
||||||
|
|
||||||
|
protected override BeatmapModelDownloader CreateBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider api, GameHost host)
|
||||||
|
{
|
||||||
|
return new TestBeatmapModelDownloader(modelManager, api, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestBeatmapModelDownloader : BeatmapModelDownloader
|
||||||
|
{
|
||||||
|
public TestBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider apiProvider, GameHost gameHost)
|
||||||
|
: base(modelManager, apiProvider, gameHost)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
||||||
|
=> new TestDownloadRequest(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestBeatmapModelManager : BeatmapModelManager
|
||||||
|
{
|
||||||
|
private readonly TestBeatmapManager testBeatmapManager;
|
||||||
|
|
||||||
|
public TestBeatmapModelManager(TestBeatmapManager testBeatmapManager, Storage storage, IDatabaseContextFactory databaseContextFactory, RulesetStore rulesetStore, IAPIProvider apiProvider, GameHost gameHost)
|
||||||
|
: base(storage, databaseContextFactory, rulesetStore, gameHost)
|
||||||
|
{
|
||||||
|
this.testBeatmapManager = testBeatmapManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<ILive<BeatmapSetInfo>> Import(BeatmapSetInfo item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await testBeatmapManager.AllowImport.Task.ConfigureAwait(false);
|
||||||
|
return await (testBeatmapManager.CurrentImportTask = base.Import(item, archive, lowPriority, cancellationToken)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
osu.Game.Tests/Resources/loop-count.osb
Normal file
15
osu.Game.Tests/Resources/loop-count.osb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
osu file format v14
|
||||||
|
|
||||||
|
[Events]
|
||||||
|
Sprite,Background,TopCentre,"zero-times.png",320,240
|
||||||
|
L,1000,0
|
||||||
|
F,0,0,1000,0,1
|
||||||
|
F,0,1000,2000,1,0
|
||||||
|
Sprite,Background,TopCentre,"one-time.png",320,240
|
||||||
|
L,4000,1
|
||||||
|
F,0,0,1000,0,1
|
||||||
|
F,0,1000,2000,1,0
|
||||||
|
Sprite,Background,TopCentre,"many-times.png",320,240
|
||||||
|
L,9000,40
|
||||||
|
F,0,0,1000,0,1
|
||||||
|
F,0,1000,2000,1,0
|
@ -141,7 +141,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||||
|
|
||||||
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.Beatmap.ID)));
|
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.BeatmapInfo.ID)));
|
||||||
Assert.That(scoreManager.Query(s => s.ID == imported.ID).DeletePending, Is.EqualTo(true));
|
Assert.That(scoreManager.Query(s => s.ID == imported.ID).DeletePending, Is.EqualTo(true));
|
||||||
|
|
||||||
var secondImport = await LoadScoreIntoOsu(osu, imported);
|
var secondImport = await LoadScoreIntoOsu(osu, imported);
|
||||||
@ -181,7 +181,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
score.Beatmap ??= beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
|
score.BeatmapInfo ??= beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
|
||||||
score.Ruleset ??= new OsuRuleset().RulesetInfo;
|
score.Ruleset ??= new OsuRuleset().RulesetInfo;
|
||||||
|
|
||||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||||
|
@ -196,7 +196,7 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
private async Task<SkinInfo> loadSkinIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
private async Task<SkinInfo> loadSkinIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
||||||
{
|
{
|
||||||
var skinManager = osu.Dependencies.Get<SkinManager>();
|
var skinManager = osu.Dependencies.Get<SkinManager>();
|
||||||
return await skinManager.Import(archive);
|
return (await skinManager.Import(archive)).Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Tests.Skins
|
|||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
var imported = beatmaps.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-beatmap.osz"))).Result;
|
var imported = beatmaps.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-beatmap.osz"))).Result;
|
||||||
beatmap = beatmaps.GetWorkingBeatmap(imported.Beatmaps[0]);
|
beatmap = beatmaps.GetWorkingBeatmap(imported.Value.Beatmaps[0]);
|
||||||
beatmap.LoadTrack();
|
beatmap.LoadTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Skins
|
|||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
var imported = skins.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-skin.osk"))).Result;
|
var imported = skins.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-skin.osk"))).Result;
|
||||||
skin = skins.GetSkin(imported);
|
skin = skins.GetSkin(imported.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -232,7 +232,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
AddStep("Transition to Results", () => player.Push(results = new FadeAccessibleResults(new ScoreInfo
|
AddStep("Transition to Results", () => player.Push(results = new FadeAccessibleResults(new ScoreInfo
|
||||||
{
|
{
|
||||||
User = new User { Username = "osu!" },
|
User = new User { Username = "osu!" },
|
||||||
Beatmap = new TestBeatmap(Ruleset.Value).BeatmapInfo,
|
BeatmapInfo = new TestBeatmap(Ruleset.Value).BeatmapInfo,
|
||||||
Ruleset = Ruleset.Value,
|
Ruleset = Ruleset.Value,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
private void setupUserSettings()
|
private void setupUserSettings()
|
||||||
{
|
{
|
||||||
AddUntilStep("Song select is current", () => songSelect.IsCurrentScreen());
|
AddUntilStep("Song select is current", () => songSelect.IsCurrentScreen());
|
||||||
AddUntilStep("Song select has selection", () => songSelect.Carousel?.SelectedBeatmap != null);
|
AddUntilStep("Song select has selection", () => songSelect.Carousel?.SelectedBeatmapInfo != null);
|
||||||
AddStep("Set default user settings", () =>
|
AddStep("Set default user settings", () =>
|
||||||
{
|
{
|
||||||
SelectedMods.Value = SelectedMods.Value.Concat(new[] { new OsuModNoFail() }).ToArray();
|
SelectedMods.Value = SelectedMods.Value.Concat(new[] { new OsuModNoFail() }).ToArray();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -17,6 +18,8 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Replays;
|
using osu.Game.Replays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Replays;
|
using osu.Game.Rulesets.Replays;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -38,7 +41,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
private TestReplayRecorder recorder;
|
private TestReplayRecorder recorder;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
|
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() =>
|
||||||
@ -57,7 +60,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Recorder = recorder = new TestReplayRecorder(new Score
|
Recorder = recorder = new TestReplayRecorder(new Score
|
||||||
{
|
{
|
||||||
Replay = replay,
|
Replay = replay,
|
||||||
ScoreInfo = { Beatmap = gameplayBeatmap.BeatmapInfo }
|
ScoreInfo = { BeatmapInfo = gameplayState.Beatmap.BeatmapInfo }
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
|
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -13,6 +14,8 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Replays;
|
using osu.Game.Replays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Replays;
|
using osu.Game.Rulesets.Replays;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -30,7 +33,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
private readonly TestRulesetInputManager recordingManager;
|
private readonly TestRulesetInputManager recordingManager;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
|
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
||||||
|
|
||||||
public TestSceneReplayRecording()
|
public TestSceneReplayRecording()
|
||||||
{
|
{
|
||||||
@ -48,7 +51,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Recorder = new TestReplayRecorder(new Score
|
Recorder = new TestReplayRecorder(new Score
|
||||||
{
|
{
|
||||||
Replay = replay,
|
Replay = replay,
|
||||||
ScoreInfo = { Beatmap = gameplayBeatmap.BeatmapInfo }
|
ScoreInfo = { BeatmapInfo = gameplayState.Beatmap.BeatmapInfo }
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos)
|
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos)
|
||||||
|
@ -25,6 +25,8 @@ using osu.Game.Online.Spectator;
|
|||||||
using osu.Game.Replays;
|
using osu.Game.Replays;
|
||||||
using osu.Game.Replays.Legacy;
|
using osu.Game.Replays.Legacy;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Replays;
|
using osu.Game.Rulesets.Replays;
|
||||||
using osu.Game.Rulesets.Replays.Types;
|
using osu.Game.Rulesets.Replays.Types;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
@ -62,7 +64,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
private SpectatorClient spectatorClient { get; set; }
|
private SpectatorClient spectatorClient { get; set; }
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
|
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() =>
|
||||||
@ -354,7 +356,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
internal class TestReplayRecorder : ReplayRecorder<TestAction>
|
internal class TestReplayRecorder : ReplayRecorder<TestAction>
|
||||||
{
|
{
|
||||||
public TestReplayRecorder()
|
public TestReplayRecorder()
|
||||||
: base(new Score { ScoreInfo = { Beatmap = new BeatmapInfo() } })
|
: base(new Score { ScoreInfo = { BeatmapInfo = new BeatmapInfo() } })
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays.Login;
|
using osu.Game.Overlays.Login;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Menus
|
namespace osu.Game.Tests.Visual.Menus
|
||||||
@ -30,12 +31,25 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasicLogin()
|
public void TestLoginSuccess()
|
||||||
{
|
{
|
||||||
AddStep("logout", () => API.Logout());
|
AddStep("logout", () => API.Logout());
|
||||||
|
|
||||||
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLoginFailure()
|
||||||
|
{
|
||||||
|
AddStep("logout", () =>
|
||||||
|
{
|
||||||
|
API.Logout();
|
||||||
|
((DummyAPIAccess)API).FailNextLogin();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("enter password", () => loginPanel.ChildrenOfType<OsuPasswordTextBox>().First().Text = "password");
|
||||||
|
AddStep("submit", () => loginPanel.ChildrenOfType<OsuButton>().First(b => b.Text.ToString() == "Sign in").TriggerClick());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
AddStep("import beatmap with track", () =>
|
AddStep("import beatmap with track", () =>
|
||||||
{
|
{
|
||||||
var setWithTrack = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).Result;
|
var setWithTrack = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).Result;
|
||||||
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(setWithTrack.Beatmaps.First());
|
Beatmap.Value = Game.BeatmapManager.GetWorkingBeatmap(setWithTrack.Value.Beatmaps.First());
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("bind to track change", () =>
|
AddStep("bind to track change", () =>
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Accuracy = 0.8,
|
Accuracy = 0.8,
|
||||||
MaxCombo = 500,
|
MaxCombo = 500,
|
||||||
Combo = 250,
|
Combo = 250,
|
||||||
Beatmap = beatmapInfo,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User { Username = "Test user" },
|
User = new User { Username = "Test user" },
|
||||||
Date = DateTimeOffset.Now,
|
Date = DateTimeOffset.Now,
|
||||||
OnlineScoreID = 12345,
|
OnlineScoreID = 12345,
|
||||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Accuracy = 0.8,
|
Accuracy = 0.8,
|
||||||
MaxCombo = 500,
|
MaxCombo = 500,
|
||||||
Combo = 250,
|
Combo = 250,
|
||||||
Beatmap = beatmapInfo,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User { Username = "Test user" },
|
User = new User { Username = "Test user" },
|
||||||
Date = DateTimeOffset.Now,
|
Date = DateTimeOffset.Now,
|
||||||
OnlineScoreID = 12345,
|
OnlineScoreID = 12345,
|
||||||
|
@ -126,7 +126,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).Result;
|
}).Result.Value;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"import {i} succeeded", () => imported != null);
|
AddAssert($"import {i} succeeded", () => imported != null);
|
||||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
Ruleset = new OsuRuleset().RulesetInfo
|
Ruleset = new OsuRuleset().RulesetInfo
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).Result;
|
}).Result.Value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +130,9 @@ namespace osu.Game.Tests.Visual.Navigation
|
|||||||
{
|
{
|
||||||
Hash = Guid.NewGuid().ToString(),
|
Hash = Guid.NewGuid().ToString(),
|
||||||
OnlineScoreID = i,
|
OnlineScoreID = i,
|
||||||
Beatmap = beatmap.Beatmaps.First(),
|
BeatmapInfo = beatmap.Beatmaps.First(),
|
||||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||||
}).Result;
|
}).Result.Value;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"import {i} succeeded", () => imported != null);
|
AddAssert($"import {i} succeeded", () => imported != null);
|
||||||
|
@ -233,7 +233,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("shown beatmaps of current ruleset", () => overlay.Header.HeaderContent.Picker.Difficulties.All(b => b.Beatmap.Ruleset.Equals(overlay.Header.RulesetSelector.Current.Value)));
|
AddAssert("shown beatmaps of current ruleset", () => overlay.Header.HeaderContent.Picker.Difficulties.All(b => b.BeatmapInfo.Ruleset.Equals(overlay.Header.RulesetSelector.Current.Value)));
|
||||||
AddAssert("left-most beatmap selected", () => overlay.Header.HeaderContent.Picker.Difficulties.First().State == BeatmapPicker.DifficultySelectorState.Selected);
|
AddAssert("left-most beatmap selected", () => overlay.Header.HeaderContent.Picker.Difficulties.First().State == BeatmapPicker.DifficultySelectorState.Selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +58,10 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
var firstBeatmap = createBeatmap();
|
var firstBeatmap = createBeatmap();
|
||||||
var secondBeatmap = createBeatmap();
|
var secondBeatmap = createBeatmap();
|
||||||
|
|
||||||
AddStep("set first set", () => successRate.Beatmap = firstBeatmap);
|
AddStep("set first set", () => successRate.BeatmapInfo = firstBeatmap);
|
||||||
AddAssert("ratings set", () => successRate.Graph.Metrics == firstBeatmap.Metrics);
|
AddAssert("ratings set", () => successRate.Graph.Metrics == firstBeatmap.Metrics);
|
||||||
|
|
||||||
AddStep("set second set", () => successRate.Beatmap = secondBeatmap);
|
AddStep("set second set", () => successRate.BeatmapInfo = secondBeatmap);
|
||||||
AddAssert("ratings set", () => successRate.Graph.Metrics == secondBeatmap.Metrics);
|
AddAssert("ratings set", () => successRate.Graph.Metrics == secondBeatmap.Metrics);
|
||||||
|
|
||||||
static BeatmapInfo createBeatmap() => new BeatmapInfo
|
static BeatmapInfo createBeatmap() => new BeatmapInfo
|
||||||
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestOnlyFailMetrics()
|
public void TestOnlyFailMetrics()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => successRate.Beatmap = new BeatmapInfo
|
AddStep("set beatmap", () => successRate.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metrics = new BeatmapMetrics
|
Metrics = new BeatmapMetrics
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestEmptyMetrics()
|
public void TestEmptyMetrics()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => successRate.Beatmap = new BeatmapInfo
|
AddStep("set beatmap", () => successRate.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metrics = new BeatmapMetrics()
|
Metrics = new BeatmapMetrics()
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
PP = 1047.21,
|
PP = 1047.21,
|
||||||
Rank = ScoreRank.SH,
|
Rank = ScoreRank.SH,
|
||||||
Beatmap = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
PP = 134.32,
|
PP = 134.32,
|
||||||
Rank = ScoreRank.A,
|
Rank = ScoreRank.A,
|
||||||
Beatmap = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
PP = 96.83,
|
PP = 96.83,
|
||||||
Rank = ScoreRank.S,
|
Rank = ScoreRank.S,
|
||||||
Beatmap = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
var noPPScore = new ScoreInfo
|
var noPPScore = new ScoreInfo
|
||||||
{
|
{
|
||||||
Rank = ScoreRank.B,
|
Rank = ScoreRank.B,
|
||||||
Beatmap = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
{
|
{
|
||||||
beatmap.BeatmapInfo.BaseDifficulty.CircleSize = 1;
|
beatmap.BeatmapInfo.BaseDifficulty.CircleSize = 1;
|
||||||
|
|
||||||
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result;
|
importedSet = manager.Import(beatmap.BeatmapInfo.BeatmapSet).Result.Value;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("load room", () =>
|
AddStep("load room", () =>
|
||||||
|
@ -71,7 +71,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
Id = 2,
|
Id = 2,
|
||||||
Username = "peppy",
|
Username = "peppy",
|
||||||
},
|
},
|
||||||
Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo,
|
BeatmapInfo = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo,
|
||||||
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
|
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
|
||||||
TotalScore = 2845370,
|
TotalScore = 2845370,
|
||||||
Accuracy = accuracy,
|
Accuracy = accuracy,
|
||||||
|
@ -35,7 +35,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
|
|
||||||
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
|
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
|
||||||
{
|
{
|
||||||
Beatmap = createTestBeatmap(author)
|
BeatmapInfo = createTestBeatmap(author)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
|
|
||||||
AddStep("show excess mods score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo, true)
|
AddStep("show excess mods score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo, true)
|
||||||
{
|
{
|
||||||
Beatmap = createTestBeatmap(author)
|
BeatmapInfo = createTestBeatmap(author)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
AddAssert("mapper name present", () => this.ChildrenOfType<OsuSpriteText>().Any(spriteText => spriteText.Current.Value == "mapper_name"));
|
AddAssert("mapper name present", () => this.ChildrenOfType<OsuSpriteText>().Any(spriteText => spriteText.Current.Value == "mapper_name"));
|
||||||
@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
{
|
{
|
||||||
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
|
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
|
||||||
{
|
{
|
||||||
Beatmap = createTestBeatmap(null)
|
BeatmapInfo = createTestBeatmap(null)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
AddAssert("mapped by text not present", () =>
|
AddAssert("mapped by text not present", () =>
|
||||||
@ -79,7 +79,7 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
showPanel(new TestScoreInfo(ruleset.RulesetInfo)
|
showPanel(new TestScoreInfo(ruleset.RulesetInfo)
|
||||||
{
|
{
|
||||||
Mods = mods,
|
Mods = mods,
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmap,
|
||||||
Date = default,
|
Date = default,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -337,8 +337,8 @@ namespace osu.Game.Tests.Visual.Ranking
|
|||||||
public UnrankedSoloResultsScreen(ScoreInfo score)
|
public UnrankedSoloResultsScreen(ScoreInfo score)
|
||||||
: base(score, true)
|
: base(score, true)
|
||||||
{
|
{
|
||||||
Score.Beatmap.OnlineBeatmapID = 0;
|
Score.BeatmapInfo.OnlineBeatmapID = 0;
|
||||||
Score.Beatmap.Status = BeatmapSetOnlineStatus.Pending;
|
Score.BeatmapInfo.Status = BeatmapSetOnlineStatus.Pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -7,6 +7,7 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Settings.Sections.Input;
|
using osu.Game.Overlays.Settings.Sections.Input;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -230,6 +231,22 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
AddAssert("first binding selected", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFilteringHidesResetSectionButtons()
|
||||||
|
{
|
||||||
|
SearchTextBox searchTextBox = null;
|
||||||
|
|
||||||
|
AddStep("add any search term", () =>
|
||||||
|
{
|
||||||
|
searchTextBox = panel.ChildrenOfType<SearchTextBox>().Single();
|
||||||
|
searchTextBox.Current.Value = "chat";
|
||||||
|
});
|
||||||
|
AddUntilStep("all reset section bindings buttons hidden", () => panel.ChildrenOfType<ResetButton>().All(button => button.Alpha == 0));
|
||||||
|
|
||||||
|
AddStep("clear search term", () => searchTextBox.Current.Value = string.Empty);
|
||||||
|
AddUntilStep("all reset section bindings buttons shown", () => panel.ChildrenOfType<ResetButton>().All(button => button.Alpha == 1));
|
||||||
|
}
|
||||||
|
|
||||||
private void checkBinding(string name, string keyName)
|
private void checkBinding(string name, string keyName)
|
||||||
{
|
{
|
||||||
AddAssert($"Check {name} is bound to {keyName}", () =>
|
AddAssert($"Check {name} is bound to {keyName}", () =>
|
||||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNoMod()
|
public void TestNoMod()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = exampleBeatmapInfo);
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = exampleBeatmapInfo);
|
||||||
|
|
||||||
AddStep("no mods selected", () => SelectedMods.Value = Array.Empty<Mod>());
|
AddStep("no mods selected", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestManiaFirstBarText()
|
public void TestManiaFirstBarText()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = new BeatmapInfo
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Ruleset = rulesets.GetRuleset(3),
|
Ruleset = rulesets.GetRuleset(3),
|
||||||
BaseDifficulty = new BeatmapDifficulty
|
BaseDifficulty = new BeatmapDifficulty
|
||||||
@ -84,11 +84,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestEasyMod()
|
public void TestEasyMod()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = exampleBeatmapInfo);
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = exampleBeatmapInfo);
|
||||||
|
|
||||||
AddStep("select EZ mod", () =>
|
AddStep("select EZ mod", () =>
|
||||||
{
|
{
|
||||||
var ruleset = advancedStats.Beatmap.Ruleset.CreateInstance();
|
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance();
|
||||||
SelectedMods.Value = new[] { ruleset.CreateMod<ModEasy>() };
|
SelectedMods.Value = new[] { ruleset.CreateMod<ModEasy>() };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,11 +101,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestHardRockMod()
|
public void TestHardRockMod()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = exampleBeatmapInfo);
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = exampleBeatmapInfo);
|
||||||
|
|
||||||
AddStep("select HR mod", () =>
|
AddStep("select HR mod", () =>
|
||||||
{
|
{
|
||||||
var ruleset = advancedStats.Beatmap.Ruleset.CreateInstance();
|
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance();
|
||||||
SelectedMods.Value = new[] { ruleset.CreateMod<ModHardRock>() };
|
SelectedMods.Value = new[] { ruleset.CreateMod<ModHardRock>() };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -118,13 +118,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestUnchangedDifficultyAdjustMod()
|
public void TestUnchangedDifficultyAdjustMod()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = exampleBeatmapInfo);
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = exampleBeatmapInfo);
|
||||||
|
|
||||||
AddStep("select unchanged Difficulty Adjust mod", () =>
|
AddStep("select unchanged Difficulty Adjust mod", () =>
|
||||||
{
|
{
|
||||||
var ruleset = advancedStats.Beatmap.Ruleset.CreateInstance();
|
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance();
|
||||||
var difficultyAdjustMod = ruleset.CreateMod<ModDifficultyAdjust>();
|
var difficultyAdjustMod = ruleset.CreateMod<ModDifficultyAdjust>();
|
||||||
difficultyAdjustMod.ReadFromDifficulty(advancedStats.Beatmap.BaseDifficulty);
|
difficultyAdjustMod.ReadFromDifficulty(advancedStats.BeatmapInfo.BaseDifficulty);
|
||||||
SelectedMods.Value = new[] { difficultyAdjustMod };
|
SelectedMods.Value = new[] { difficultyAdjustMod };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,13 +137,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestChangedDifficultyAdjustMod()
|
public void TestChangedDifficultyAdjustMod()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => advancedStats.Beatmap = exampleBeatmapInfo);
|
AddStep("set beatmap", () => advancedStats.BeatmapInfo = exampleBeatmapInfo);
|
||||||
|
|
||||||
AddStep("select changed Difficulty Adjust mod", () =>
|
AddStep("select changed Difficulty Adjust mod", () =>
|
||||||
{
|
{
|
||||||
var ruleset = advancedStats.Beatmap.Ruleset.CreateInstance();
|
var ruleset = advancedStats.BeatmapInfo.Ruleset.CreateInstance();
|
||||||
var difficultyAdjustMod = ruleset.CreateMod<OsuModDifficultyAdjust>();
|
var difficultyAdjustMod = ruleset.CreateMod<OsuModDifficultyAdjust>();
|
||||||
var originalDifficulty = advancedStats.Beatmap.BaseDifficulty;
|
var originalDifficulty = advancedStats.BeatmapInfo.BaseDifficulty;
|
||||||
|
|
||||||
difficultyAdjustMod.ReadFromDifficulty(originalDifficulty);
|
difficultyAdjustMod.ReadFromDifficulty(originalDifficulty);
|
||||||
difficultyAdjustMod.DrainRate.Value = originalDifficulty.DrainRate - 0.5f;
|
difficultyAdjustMod.DrainRate.Value = originalDifficulty.DrainRate - 0.5f;
|
||||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>();
|
private readonly Stack<BeatmapSetInfo> selectedSets = new Stack<BeatmapSetInfo>();
|
||||||
private readonly HashSet<int> eagerSelectedIDs = new HashSet<int>();
|
private readonly HashSet<int> eagerSelectedIDs = new HashSet<int>();
|
||||||
|
|
||||||
private BeatmapInfo currentSelection => carousel.SelectedBeatmap;
|
private BeatmapInfo currentSelection => carousel.SelectedBeatmapInfo;
|
||||||
|
|
||||||
private const int set_count = 5;
|
private const int set_count = 5;
|
||||||
|
|
||||||
@ -75,11 +75,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
AddStep("store selection", () => selection = carousel.SelectedBeatmap);
|
AddStep("store selection", () => selection = carousel.SelectedBeatmapInfo);
|
||||||
if (isIterating)
|
if (isIterating)
|
||||||
AddUntilStep("selection changed", () => carousel.SelectedBeatmap != selection);
|
AddUntilStep("selection changed", () => carousel.SelectedBeatmapInfo != selection);
|
||||||
else
|
else
|
||||||
AddUntilStep("selection not changed", () => carousel.SelectedBeatmap == selection);
|
AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo == selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("Set non-empty mode filter", () =>
|
AddStep("Set non-empty mode filter", () =>
|
||||||
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1) }, false));
|
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(1) }, false));
|
||||||
|
|
||||||
AddAssert("Something is selected", () => carousel.SelectedBeatmap != null);
|
AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -562,7 +562,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("filter to ruleset 0", () =>
|
AddStep("filter to ruleset 0", () =>
|
||||||
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false));
|
carousel.Filter(new FilterCriteria { Ruleset = rulesets.AvailableRulesets.ElementAt(0) }, false));
|
||||||
AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
|
AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
|
||||||
AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmap.RulesetID == 0);
|
AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmapInfo.RulesetID == 0);
|
||||||
|
|
||||||
AddStep("remove mixed set", () =>
|
AddStep("remove mixed set", () =>
|
||||||
{
|
{
|
||||||
@ -653,7 +653,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
carousel.Filter(new FilterCriteria { SearchText = Guid.NewGuid().ToString() }, false);
|
carousel.Filter(new FilterCriteria { SearchText = Guid.NewGuid().ToString() }, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("selection lost", () => carousel.SelectedBeatmap == null);
|
AddAssert("selection lost", () => carousel.SelectedBeatmapInfo == null);
|
||||||
|
|
||||||
AddStep("Restore different ruleset filter", () =>
|
AddStep("Restore different ruleset filter", () =>
|
||||||
{
|
{
|
||||||
@ -661,7 +661,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
|
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("selection changed", () => carousel.SelectedBeatmap != manySets.First().Beatmaps.First());
|
AddAssert("selection changed", () => carousel.SelectedBeatmapInfo != manySets.First().Beatmaps.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
AddAssert("Selection was random", () => eagerSelectedIDs.Count > 2);
|
AddAssert("Selection was random", () => eagerSelectedIDs.Count > 2);
|
||||||
@ -763,9 +763,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddUntilStep($"selected is set{set}{(diff.HasValue ? $" diff{diff.Value}" : "")}", () =>
|
AddUntilStep($"selected is set{set}{(diff.HasValue ? $" diff{diff.Value}" : "")}", () =>
|
||||||
{
|
{
|
||||||
if (diff != null)
|
if (diff != null)
|
||||||
return carousel.SelectedBeatmap == carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First();
|
return carousel.SelectedBeatmapInfo == carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First();
|
||||||
|
|
||||||
return carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Contains(carousel.SelectedBeatmap);
|
return carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Contains(carousel.SelectedBeatmapInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
private void setSelected(int set, int diff) =>
|
private void setSelected(int set, int diff) =>
|
||||||
@ -800,7 +800,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
carousel.RandomAlgorithm.Value = RandomSelectAlgorithm.RandomPermutation;
|
carousel.RandomAlgorithm.Value = RandomSelectAlgorithm.RandomPermutation;
|
||||||
|
|
||||||
if (!selectedSets.Any() && carousel.SelectedBeatmap != null)
|
if (!selectedSets.Any() && carousel.SelectedBeatmapInfo != null)
|
||||||
selectedSets.Push(carousel.SelectedBeatmapSet);
|
selectedSets.Push(carousel.SelectedBeatmapSet);
|
||||||
|
|
||||||
carousel.SelectNextRandom();
|
carousel.SelectNextRandom();
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestAllMetrics()
|
public void TestAllMetrics()
|
||||||
{
|
{
|
||||||
AddStep("all metrics", () => details.Beatmap = new BeatmapInfo
|
AddStep("all metrics", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestAllMetricsExceptSource()
|
public void TestAllMetricsExceptSource()
|
||||||
{
|
{
|
||||||
AddStep("all except source", () => details.Beatmap = new BeatmapInfo
|
AddStep("all except source", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestOnlyRatings()
|
public void TestOnlyRatings()
|
||||||
{
|
{
|
||||||
AddStep("ratings", () => details.Beatmap = new BeatmapInfo
|
AddStep("ratings", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
@ -117,7 +117,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestOnlyFailsAndRetries()
|
public void TestOnlyFailsAndRetries()
|
||||||
{
|
{
|
||||||
AddStep("fails retries", () => details.Beatmap = new BeatmapInfo
|
AddStep("fails retries", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Version = "Only Retries and Fails",
|
Version = "Only Retries and Fails",
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
@ -144,7 +144,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNoMetrics()
|
public void TestNoMetrics()
|
||||||
{
|
{
|
||||||
AddStep("no metrics", () => details.Beatmap = new BeatmapInfo
|
AddStep("no metrics", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
Version = "No Metrics",
|
Version = "No Metrics",
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
@ -166,13 +166,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestNullBeatmap()
|
public void TestNullBeatmap()
|
||||||
{
|
{
|
||||||
AddStep("null beatmap", () => details.Beatmap = null);
|
AddStep("null beatmap", () => details.BeatmapInfo = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestOnlineMetrics()
|
public void TestOnlineMetrics()
|
||||||
{
|
{
|
||||||
AddStep("online ratings/retries/fails", () => details.Beatmap = new BeatmapInfo
|
AddStep("online ratings/retries/fails", () => details.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 162,
|
OnlineBeatmapID = 162,
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
||||||
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
|
beatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
|
||||||
|
|
||||||
leaderboard.Beatmap = beatmapInfo;
|
leaderboard.BeatmapInfo = beatmapInfo;
|
||||||
});
|
});
|
||||||
|
|
||||||
clearScores();
|
clearScores();
|
||||||
@ -186,7 +186,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
private void checkCount(int expected) =>
|
private void checkCount(int expected) =>
|
||||||
AddUntilStep("Correct count displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count() == expected);
|
AddUntilStep("Correct count displayed", () => leaderboard.ChildrenOfType<LeaderboardScore>().Count() == expected);
|
||||||
|
|
||||||
private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmap)
|
private static ScoreInfo[] generateSampleScores(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
@ -197,7 +197,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 6602580,
|
Id = 6602580,
|
||||||
@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 4608074,
|
Id = 4608074,
|
||||||
@ -235,7 +235,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 1014222,
|
Id = 1014222,
|
||||||
@ -254,7 +254,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 1541390,
|
Id = 1541390,
|
||||||
@ -273,7 +273,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 2243452,
|
Id = 2243452,
|
||||||
@ -292,7 +292,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 2705430,
|
Id = 2705430,
|
||||||
@ -311,7 +311,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 7151382,
|
Id = 7151382,
|
||||||
@ -330,7 +330,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 2051389,
|
Id = 2051389,
|
||||||
@ -349,7 +349,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 6169483,
|
Id = 6169483,
|
||||||
@ -368,7 +368,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
MaxCombo = 244,
|
MaxCombo = 244,
|
||||||
TotalScore = 1707827,
|
TotalScore = 1707827,
|
||||||
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
//Mods = new Mod[] { new OsuModHidden(), new OsuModHardRock(), },
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
User = new User
|
User = new User
|
||||||
{
|
{
|
||||||
Id = 6702666,
|
Id = 6702666,
|
||||||
@ -385,7 +385,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
private void showBeatmapWithStatus(BeatmapSetOnlineStatus status)
|
private void showBeatmapWithStatus(BeatmapSetOnlineStatus status)
|
||||||
{
|
{
|
||||||
leaderboard.Beatmap = new BeatmapInfo
|
leaderboard.BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapID = 1113057,
|
OnlineBeatmapID = 1113057,
|
||||||
Status = status,
|
Status = status,
|
||||||
|
@ -192,7 +192,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
}).ToList()
|
}).ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
return Game.BeatmapManager.Import(beatmapSet).Result;
|
return Game.BeatmapManager.Import(beatmapSet).Result.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);
|
private bool ensureAllBeatmapSetsImported(IEnumerable<BeatmapSetInfo> beatmapSets) => beatmapSets.All(set => set != null);
|
||||||
|
@ -145,7 +145,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("select next and enter", () =>
|
AddStep("select next and enter", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>()
|
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>()
|
||||||
.First(b => ((CarouselBeatmap)b.Item).Beatmap != songSelect.Carousel.SelectedBeatmap));
|
.First(b => ((CarouselBeatmap)b.Item).BeatmapInfo != songSelect.Carousel.SelectedBeatmapInfo));
|
||||||
|
|
||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("select next and enter", () =>
|
AddStep("select next and enter", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>()
|
InputManager.MoveMouseTo(songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmap>()
|
||||||
.First(b => ((CarouselBeatmap)b.Item).Beatmap != songSelect.Carousel.SelectedBeatmap));
|
.First(b => ((CarouselBeatmap)b.Item).BeatmapInfo != songSelect.Carousel.SelectedBeatmapInfo));
|
||||||
|
|
||||||
InputManager.PressButton(MouseButton.Left);
|
InputManager.PressButton(MouseButton.Left);
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
createSongSelect();
|
createSongSelect();
|
||||||
addRulesetImportStep(2);
|
addRulesetImportStep(2);
|
||||||
AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null);
|
AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmapInfo == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -322,13 +322,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
changeRuleset(2);
|
changeRuleset(2);
|
||||||
addRulesetImportStep(2);
|
addRulesetImportStep(2);
|
||||||
addRulesetImportStep(1);
|
addRulesetImportStep(1);
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.RulesetID == 2);
|
||||||
|
|
||||||
changeRuleset(1);
|
changeRuleset(1);
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 1);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.RulesetID == 1);
|
||||||
|
|
||||||
changeRuleset(0);
|
changeRuleset(0);
|
||||||
AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmap == null);
|
AddUntilStep("no selection", () => songSelect.Carousel.SelectedBeatmapInfo == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -338,7 +338,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
changeRuleset(2);
|
changeRuleset(2);
|
||||||
|
|
||||||
addRulesetImportStep(2);
|
addRulesetImportStep(2);
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.RulesetID == 2);
|
||||||
|
|
||||||
addRulesetImportStep(0);
|
addRulesetImportStep(0);
|
||||||
addRulesetImportStep(0);
|
addRulesetImportStep(0);
|
||||||
@ -355,7 +355,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.Equals(target));
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.Equals(target));
|
||||||
|
|
||||||
// this is an important check, to make sure updateComponentFromBeatmap() was actually run
|
// this is an important check, to make sure updateComponentFromBeatmap() was actually run
|
||||||
AddUntilStep("selection shown on wedge", () => songSelect.CurrentBeatmapDetailsBeatmap.BeatmapInfo.Equals(target));
|
AddUntilStep("selection shown on wedge", () => songSelect.CurrentBeatmapDetailsBeatmap.BeatmapInfo.Equals(target));
|
||||||
@ -368,7 +368,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
changeRuleset(2);
|
changeRuleset(2);
|
||||||
|
|
||||||
addRulesetImportStep(2);
|
addRulesetImportStep(2);
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.RulesetID == 2);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.RulesetID == 2);
|
||||||
|
|
||||||
addRulesetImportStep(0);
|
addRulesetImportStep(0);
|
||||||
addRulesetImportStep(0);
|
addRulesetImportStep(0);
|
||||||
@ -385,7 +385,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap.Equals(target));
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo.Equals(target));
|
||||||
|
|
||||||
AddUntilStep("has correct ruleset", () => Ruleset.Value.ID == 0);
|
AddUntilStep("has correct ruleset", () => Ruleset.Value.ID == 0);
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
{
|
{
|
||||||
createSongSelect();
|
createSongSelect();
|
||||||
addManyTestMaps();
|
addManyTestMaps();
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo != null);
|
||||||
|
|
||||||
bool startRequested = false;
|
bool startRequested = false;
|
||||||
|
|
||||||
@ -473,13 +473,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
// used for filter check below
|
// used for filter check below
|
||||||
AddStep("allow convert display", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, true));
|
AddStep("allow convert display", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, true));
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo != null);
|
||||||
|
|
||||||
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nonono");
|
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nonono");
|
||||||
|
|
||||||
AddUntilStep("dummy selected", () => Beatmap.Value is DummyWorkingBeatmap);
|
AddUntilStep("dummy selected", () => Beatmap.Value is DummyWorkingBeatmap);
|
||||||
|
|
||||||
AddUntilStep("has no selection", () => songSelect.Carousel.SelectedBeatmap == null);
|
AddUntilStep("has no selection", () => songSelect.Carousel.SelectedBeatmapInfo == null);
|
||||||
|
|
||||||
BeatmapInfo target = null;
|
BeatmapInfo target = null;
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo != null);
|
||||||
|
|
||||||
AddAssert("selected only shows expected ruleset (plus converts)", () =>
|
AddAssert("selected only shows expected ruleset (plus converts)", () =>
|
||||||
{
|
{
|
||||||
@ -502,16 +502,16 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
// special case for converts checked here.
|
// special case for converts checked here.
|
||||||
return selectedPanel.ChildrenOfType<FilterableDifficultyIcon>().All(i =>
|
return selectedPanel.ChildrenOfType<FilterableDifficultyIcon>().All(i =>
|
||||||
i.IsFiltered || i.Item.Beatmap.Ruleset.ID == targetRuleset || i.Item.Beatmap.Ruleset.ID == 0);
|
i.IsFiltered || i.Item.BeatmapInfo.Ruleset.ID == targetRuleset || i.Item.BeatmapInfo.Ruleset.ID == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("carousel has correct", () => songSelect.Carousel.SelectedBeatmap?.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddUntilStep("carousel has correct", () => songSelect.Carousel.SelectedBeatmapInfo?.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
AddUntilStep("game has correct", () => Beatmap.Value.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddUntilStep("game has correct", () => Beatmap.Value.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
|
|
||||||
AddStep("reset filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = string.Empty);
|
AddStep("reset filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = string.Empty);
|
||||||
|
|
||||||
AddAssert("game still correct", () => Beatmap.Value?.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddAssert("game still correct", () => Beatmap.Value?.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
AddAssert("carousel still correct", () => songSelect.Carousel.SelectedBeatmap.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddAssert("carousel still correct", () => songSelect.Carousel.SelectedBeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -522,13 +522,13 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
changeRuleset(0);
|
changeRuleset(0);
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo != null);
|
||||||
|
|
||||||
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nonono");
|
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nonono");
|
||||||
|
|
||||||
AddUntilStep("dummy selected", () => Beatmap.Value is DummyWorkingBeatmap);
|
AddUntilStep("dummy selected", () => Beatmap.Value is DummyWorkingBeatmap);
|
||||||
|
|
||||||
AddUntilStep("has no selection", () => songSelect.Carousel.SelectedBeatmap == null);
|
AddUntilStep("has no selection", () => songSelect.Carousel.SelectedBeatmapInfo == null);
|
||||||
|
|
||||||
BeatmapInfo target = null;
|
BeatmapInfo target = null;
|
||||||
|
|
||||||
@ -540,15 +540,15 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
Beatmap.Value = manager.GetWorkingBeatmap(target);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmap != null);
|
AddUntilStep("has selection", () => songSelect.Carousel.SelectedBeatmapInfo != null);
|
||||||
|
|
||||||
AddUntilStep("carousel has correct", () => songSelect.Carousel.SelectedBeatmap?.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddUntilStep("carousel has correct", () => songSelect.Carousel.SelectedBeatmapInfo?.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
AddUntilStep("game has correct", () => Beatmap.Value.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
AddUntilStep("game has correct", () => Beatmap.Value.BeatmapInfo.OnlineBeatmapID == target.OnlineBeatmapID);
|
||||||
|
|
||||||
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nononoo");
|
AddStep("set filter text", () => songSelect.FilterControl.ChildrenOfType<SearchTextBox>().First().Text = "nononoo");
|
||||||
|
|
||||||
AddUntilStep("game lost selection", () => Beatmap.Value is DummyWorkingBeatmap);
|
AddUntilStep("game lost selection", () => Beatmap.Value is DummyWorkingBeatmap);
|
||||||
AddAssert("carousel lost selection", () => songSelect.Carousel.SelectedBeatmap == null);
|
AddAssert("carousel lost selection", () => songSelect.Carousel.SelectedBeatmapInfo == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -581,9 +581,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
createSongSelect();
|
createSongSelect();
|
||||||
addRulesetImportStep(0);
|
addRulesetImportStep(0);
|
||||||
AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last()));
|
AddStep("Move to last difficulty", () => songSelect.Carousel.SelectBeatmap(songSelect.Carousel.BeatmapSets.First().Beatmaps.Last()));
|
||||||
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmap.ID);
|
AddStep("Store current ID", () => previousID = songSelect.Carousel.SelectedBeatmapInfo.ID);
|
||||||
AddStep("Hide first beatmap", () => manager.Hide(songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First()));
|
AddStep("Hide first beatmap", () => manager.Hide(songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First()));
|
||||||
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmap.ID == previousID);
|
AddAssert("Selected beatmap has not changed", () => songSelect.Carousel.SelectedBeatmapInfo.ID == previousID);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -641,7 +641,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("Selected beatmap correct", () => songSelect.Carousel.SelectedBeatmap == filteredBeatmap);
|
AddAssert("Selected beatmap correct", () => songSelect.Carousel.SelectedBeatmapInfo == filteredBeatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -717,7 +717,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("Find an icon for different ruleset", () =>
|
AddStep("Find an icon for different ruleset", () =>
|
||||||
{
|
{
|
||||||
difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
|
difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
|
||||||
.First(icon => icon.Item.Beatmap.Ruleset.ID == 3);
|
.First(icon => icon.Item.BeatmapInfo.Ruleset.ID == 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("Check ruleset is osu!", () => Ruleset.Value.ID == 0);
|
AddAssert("Check ruleset is osu!", () => Ruleset.Value.ID == 0);
|
||||||
@ -735,7 +735,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.ID == 3);
|
AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.ID == 3);
|
||||||
|
|
||||||
AddAssert("Selected beatmap still same set", () => songSelect.Carousel.SelectedBeatmap.BeatmapSet.ID == previousSetID);
|
AddAssert("Selected beatmap still same set", () => songSelect.Carousel.SelectedBeatmapInfo.BeatmapSet.ID == previousSetID);
|
||||||
AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.ID == 3);
|
AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.ID == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,7 +751,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("import huge difficulty count map", () =>
|
AddStep("import huge difficulty count map", () =>
|
||||||
{
|
{
|
||||||
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.ID != 2).ToArray();
|
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.ID != 2).ToArray();
|
||||||
imported = manager.Import(createTestBeatmapSet(usableRulesets, 50)).Result;
|
imported = manager.Import(createTestBeatmapSet(usableRulesets, 50)).Result.Value;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First()));
|
AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First()));
|
||||||
@ -767,7 +767,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
AddStep("Find group icon for different ruleset", () =>
|
AddStep("Find group icon for different ruleset", () =>
|
||||||
{
|
{
|
||||||
groupIcon = set.ChildrenOfType<FilterableGroupedDifficultyIcon>()
|
groupIcon = set.ChildrenOfType<FilterableGroupedDifficultyIcon>()
|
||||||
.First(icon => icon.Items.First().Beatmap.Ruleset.ID == 3);
|
.First(icon => icon.Items.First().BeatmapInfo.Ruleset.ID == 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("Check ruleset is osu!", () => Ruleset.Value.ID == 0);
|
AddAssert("Check ruleset is osu!", () => Ruleset.Value.ID == 0);
|
||||||
@ -781,7 +781,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.ID == 3);
|
AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.ID == 3);
|
||||||
|
|
||||||
AddAssert("Check first item in group selected", () => Beatmap.Value.BeatmapInfo.Equals(groupIcon.Items.First().Beatmap));
|
AddAssert("Check first item in group selected", () => Beatmap.Value.BeatmapInfo.Equals(groupIcon.Items.First().BeatmapInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -805,7 +805,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
songSelect.PresentScore(new ScoreInfo
|
songSelect.PresentScore(new ScoreInfo
|
||||||
{
|
{
|
||||||
User = new User { Username = "woo" },
|
User = new User { Username = "woo" },
|
||||||
Beatmap = getPresentBeatmap(),
|
BeatmapInfo = getPresentBeatmap(),
|
||||||
Ruleset = getPresentBeatmap().Ruleset
|
Ruleset = getPresentBeatmap().Ruleset
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -837,7 +837,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
songSelect.PresentScore(new ScoreInfo
|
songSelect.PresentScore(new ScoreInfo
|
||||||
{
|
{
|
||||||
User = new User { Username = "woo" },
|
User = new User { Username = "woo" },
|
||||||
Beatmap = getPresentBeatmap(),
|
BeatmapInfo = getPresentBeatmap(),
|
||||||
Ruleset = getPresentBeatmap().Ruleset
|
Ruleset = getPresentBeatmap().Ruleset
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -856,7 +856,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.FindIndex(b => b == info);
|
private int getBeatmapIndex(BeatmapSetInfo set, BeatmapInfo info) => set.Beatmaps.FindIndex(b => b == info);
|
||||||
|
|
||||||
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmap);
|
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmapInfo);
|
||||||
|
|
||||||
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, FilterableDifficultyIcon icon)
|
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, FilterableDifficultyIcon icon)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
private ScoreManager scoreManager;
|
private ScoreManager scoreManager;
|
||||||
|
|
||||||
private readonly List<ScoreInfo> importedScores = new List<ScoreInfo>();
|
private readonly List<ScoreInfo> importedScores = new List<ScoreInfo>();
|
||||||
private BeatmapInfo beatmap;
|
|
||||||
|
private BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly DialogOverlay dialogOverlay;
|
private readonly DialogOverlay dialogOverlay;
|
||||||
@ -55,7 +56,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Size = new Vector2(550f, 450f),
|
Size = new Vector2(550f, 450f),
|
||||||
Scope = BeatmapLeaderboardScope.Local,
|
Scope = BeatmapLeaderboardScope.Local,
|
||||||
Beatmap = new BeatmapInfo
|
BeatmapInfo = new BeatmapInfo
|
||||||
{
|
{
|
||||||
ID = 1,
|
ID = 1,
|
||||||
Metadata = new BeatmapMetadata
|
Metadata = new BeatmapMetadata
|
||||||
@ -84,15 +85,15 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
|
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, null, ContextFactory, Scheduler));
|
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory, Scheduler));
|
||||||
|
|
||||||
beatmap = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).Result.Beatmaps[0];
|
beatmapInfo = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).Result.Value.Beatmaps[0];
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++)
|
for (int i = 0; i < 50; i++)
|
||||||
{
|
{
|
||||||
var score = new ScoreInfo
|
var score = new ScoreInfo
|
||||||
{
|
{
|
||||||
OnlineScoreID = i,
|
OnlineScoreID = i,
|
||||||
Beatmap = beatmap,
|
BeatmapInfo = beatmapInfo,
|
||||||
BeatmapInfoID = beatmap.ID,
|
BeatmapInfoID = beatmapInfo.ID,
|
||||||
Accuracy = RNG.NextDouble(),
|
Accuracy = RNG.NextDouble(),
|
||||||
TotalScore = RNG.Next(1, 1000000),
|
TotalScore = RNG.Next(1, 1000000),
|
||||||
MaxCombo = RNG.Next(1, 1000),
|
MaxCombo = RNG.Next(1, 1000),
|
||||||
@ -100,7 +101,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
User = new User { Username = "TestUser" },
|
User = new User { Username = "TestUser" },
|
||||||
};
|
};
|
||||||
|
|
||||||
importedScores.Add(scoreManager.Import(score).Result);
|
importedScores.Add(scoreManager.Import(score).Result.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
@ -115,7 +116,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
leaderboard.Scores = null;
|
leaderboard.Scores = null;
|
||||||
leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables
|
leaderboard.FinishTransforms(true); // After setting scores, we may be waiting for transforms to expire drawables
|
||||||
|
|
||||||
leaderboard.Beatmap = beatmap;
|
leaderboard.BeatmapInfo = beatmapInfo;
|
||||||
leaderboard.RefreshScores(); // Required in the case that the beatmap hasn't changed
|
leaderboard.RefreshScores(); // Required in the case that the beatmap hasn't changed
|
||||||
});
|
});
|
||||||
|
|
||||||
|
77
osu.Game.Tests/Visual/UserInterface/TestSceneOsuFont.cs
Normal file
77
osu.Game.Tests/Visual/UserInterface/TestSceneOsuFont.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
public class TestSceneOsuFont : OsuTestScene
|
||||||
|
{
|
||||||
|
private OsuSpriteText spriteText;
|
||||||
|
|
||||||
|
private readonly BindableBool useAlternates = new BindableBool();
|
||||||
|
private readonly Bindable<FontWeight> weight = new Bindable<FontWeight>(FontWeight.Regular);
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Child = spriteText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AllowMultiline = true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
useAlternates.BindValueChanged(_ => updateFont());
|
||||||
|
weight.BindValueChanged(_ => updateFont(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFont()
|
||||||
|
{
|
||||||
|
FontUsage usage = useAlternates.Value ? OsuFont.TorusAlternate : OsuFont.Torus;
|
||||||
|
spriteText.Font = usage.With(size: 40, weight: weight.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestTorusAlternates()
|
||||||
|
{
|
||||||
|
AddStep("set all ASCII letters", () => spriteText.Text = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
|
abcdefghijklmnopqrstuvwxyz");
|
||||||
|
AddStep("set all alternates", () => spriteText.Text = @"A Á Ă Â Ä À Ā Ą Å Ã
|
||||||
|
Æ B D Ð Ď Đ E É Ě Ê
|
||||||
|
Ë Ė È Ē Ę F G Ğ Ģ Ġ
|
||||||
|
H I Í Î Ï İ Ì Ī Į K
|
||||||
|
Ķ O Œ P Þ Q R Ŕ Ř Ŗ
|
||||||
|
T Ŧ Ť Ţ Ț V W Ẃ Ŵ Ẅ
|
||||||
|
Ẁ X Y Ý Ŷ Ÿ Ỳ a á ă
|
||||||
|
â ä à ā ą å ã æ b d
|
||||||
|
ď đ e é ě ê ë ė è ē
|
||||||
|
ę f g ğ ģ ġ k ķ m n
|
||||||
|
ń ň ņ ŋ ñ o œ p þ q
|
||||||
|
t ŧ ť ţ ț u ú û ü ù
|
||||||
|
ű ū ų ů w ẃ ŵ ẅ ẁ x
|
||||||
|
y ý ŷ ÿ ỳ");
|
||||||
|
|
||||||
|
AddToggleStep("toggle alternates", alternates => useAlternates.Value = alternates);
|
||||||
|
|
||||||
|
addSetWeightStep(FontWeight.Light);
|
||||||
|
addSetWeightStep(FontWeight.Regular);
|
||||||
|
addSetWeightStep(FontWeight.SemiBold);
|
||||||
|
addSetWeightStep(FontWeight.Bold);
|
||||||
|
|
||||||
|
void addSetWeightStep(FontWeight newWeight) => AddStep($"set weight {newWeight}", () => weight.Value = newWeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
|
||||||
<PackageReference Include="DeepEqual" Version="2.0.0" />
|
<PackageReference Include="DeepEqual" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
|
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
|
||||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
||||||
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
|
|
||||||
private void success(APIBeatmap apiBeatmap)
|
private void success(APIBeatmap apiBeatmap)
|
||||||
{
|
{
|
||||||
var beatmap = apiBeatmap.ToBeatmap(rulesets);
|
var beatmap = apiBeatmap.ToBeatmapInfo(rulesets);
|
||||||
Add(new TournamentBeatmapPanel(beatmap)
|
Add(new TournamentBeatmapPanel(beatmap)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
|
|
||||||
private FillFlowContainer<TournamentBeatmapPanel> fillFlow;
|
private FillFlowContainer<TournamentBeatmapPanel> fillFlow;
|
||||||
|
|
||||||
private BeatmapInfo beatmap;
|
private BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
@ -44,12 +44,12 @@ namespace osu.Game.Tournament.Tests.Components
|
|||||||
|
|
||||||
private void success(APIBeatmap apiBeatmap)
|
private void success(APIBeatmap apiBeatmap)
|
||||||
{
|
{
|
||||||
beatmap = apiBeatmap.ToBeatmap(rulesets);
|
beatmapInfo = apiBeatmap.ToBeatmapInfo(rulesets);
|
||||||
var mods = rulesets.GetRuleset(Ladder.Ruleset.Value.ID ?? 0).CreateInstance().AllMods;
|
var mods = rulesets.GetRuleset(Ladder.Ruleset.Value.ID ?? 0).CreateInstance().AllMods;
|
||||||
|
|
||||||
foreach (var mod in mods)
|
foreach (var mod in mods)
|
||||||
{
|
{
|
||||||
fillFlow.Add(new TournamentBeatmapPanel(beatmap, mod.Acronym)
|
fillFlow.Add(new TournamentBeatmapPanel(beatmapInfo, mod.Acronym)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre
|
||||||
|
@ -21,22 +21,22 @@ namespace osu.Game.Tournament.Components
|
|||||||
{
|
{
|
||||||
public class SongBar : CompositeDrawable
|
public class SongBar : CompositeDrawable
|
||||||
{
|
{
|
||||||
private BeatmapInfo beatmap;
|
private BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
public const float HEIGHT = 145 / 2f;
|
public const float HEIGHT = 145 / 2f;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
public BeatmapInfo Beatmap
|
public BeatmapInfo BeatmapInfo
|
||||||
{
|
{
|
||||||
get => beatmap;
|
get => beatmapInfo;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (beatmap == value)
|
if (beatmapInfo == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beatmap = value;
|
beatmapInfo = value;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,18 +95,18 @@ namespace osu.Game.Tournament.Components
|
|||||||
|
|
||||||
private void update()
|
private void update()
|
||||||
{
|
{
|
||||||
if (beatmap == null)
|
if (beatmapInfo == null)
|
||||||
{
|
{
|
||||||
flow.Clear();
|
flow.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bpm = beatmap.BeatmapSet.OnlineInfo.BPM;
|
var bpm = beatmapInfo.BeatmapSet.OnlineInfo.BPM;
|
||||||
var length = beatmap.Length;
|
var length = beatmapInfo.Length;
|
||||||
string hardRockExtra = "";
|
string hardRockExtra = "";
|
||||||
string srExtra = "";
|
string srExtra = "";
|
||||||
|
|
||||||
var ar = beatmap.BaseDifficulty.ApproachRate;
|
var ar = beatmapInfo.BaseDifficulty.ApproachRate;
|
||||||
|
|
||||||
if ((mods & LegacyMods.HardRock) > 0)
|
if ((mods & LegacyMods.HardRock) > 0)
|
||||||
{
|
{
|
||||||
@ -132,9 +132,9 @@ namespace osu.Game.Tournament.Components
|
|||||||
default:
|
default:
|
||||||
stats = new (string heading, string content)[]
|
stats = new (string heading, string content)[]
|
||||||
{
|
{
|
||||||
("CS", $"{beatmap.BaseDifficulty.CircleSize:0.#}{hardRockExtra}"),
|
("CS", $"{beatmapInfo.BaseDifficulty.CircleSize:0.#}{hardRockExtra}"),
|
||||||
("AR", $"{ar:0.#}{hardRockExtra}"),
|
("AR", $"{ar:0.#}{hardRockExtra}"),
|
||||||
("OD", $"{beatmap.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}"),
|
("OD", $"{beatmapInfo.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}"),
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -142,15 +142,15 @@ namespace osu.Game.Tournament.Components
|
|||||||
case 3:
|
case 3:
|
||||||
stats = new (string heading, string content)[]
|
stats = new (string heading, string content)[]
|
||||||
{
|
{
|
||||||
("OD", $"{beatmap.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}"),
|
("OD", $"{beatmapInfo.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}"),
|
||||||
("HP", $"{beatmap.BaseDifficulty.DrainRate:0.#}{hardRockExtra}")
|
("HP", $"{beatmapInfo.BaseDifficulty.DrainRate:0.#}{hardRockExtra}")
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
stats = new (string heading, string content)[]
|
stats = new (string heading, string content)[]
|
||||||
{
|
{
|
||||||
("CS", $"{beatmap.BaseDifficulty.CircleSize:0.#}{hardRockExtra}"),
|
("CS", $"{beatmapInfo.BaseDifficulty.CircleSize:0.#}{hardRockExtra}"),
|
||||||
("AR", $"{ar:0.#}"),
|
("AR", $"{ar:0.#}"),
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@ -186,7 +186,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new DiffPiece(stats),
|
new DiffPiece(stats),
|
||||||
new DiffPiece(("Star Rating", $"{beatmap.StarDifficulty:0.#}{srExtra}"))
|
new DiffPiece(("Star Rating", $"{beatmapInfo.StarDifficulty:0.#}{srExtra}"))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
@ -229,7 +229,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new TournamentBeatmapPanel(beatmap)
|
new TournamentBeatmapPanel(beatmapInfo)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Width = 0.5f,
|
Width = 0.5f,
|
||||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
{
|
{
|
||||||
public class TournamentBeatmapPanel : CompositeDrawable
|
public class TournamentBeatmapPanel : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo BeatmapInfo;
|
||||||
private readonly string mod;
|
private readonly string mod;
|
||||||
|
|
||||||
private const float horizontal_padding = 10;
|
private const float horizontal_padding = 10;
|
||||||
@ -32,11 +32,11 @@ namespace osu.Game.Tournament.Components
|
|||||||
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
||||||
private Box flash;
|
private Box flash;
|
||||||
|
|
||||||
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mod = null)
|
public TournamentBeatmapPanel(BeatmapInfo beatmapInfo, string mod = null)
|
||||||
{
|
{
|
||||||
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
if (beatmapInfo == null) throw new ArgumentNullException(nameof(beatmapInfo));
|
||||||
|
|
||||||
Beatmap = beatmap;
|
BeatmapInfo = beatmapInfo;
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
Width = 400;
|
Width = 400;
|
||||||
Height = HEIGHT;
|
Height = HEIGHT;
|
||||||
@ -61,7 +61,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = OsuColour.Gray(0.5f),
|
Colour = OsuColour.Gray(0.5f),
|
||||||
BeatmapSet = Beatmap.BeatmapSet,
|
BeatmapSet = BeatmapInfo.BeatmapSet,
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -75,8 +75,8 @@ namespace osu.Game.Tournament.Components
|
|||||||
new TournamentSpriteText
|
new TournamentSpriteText
|
||||||
{
|
{
|
||||||
Text = new RomanisableString(
|
Text = new RomanisableString(
|
||||||
$"{Beatmap.Metadata.ArtistUnicode ?? Beatmap.Metadata.Artist} - {Beatmap.Metadata.TitleUnicode ?? Beatmap.Metadata.Title}",
|
$"{BeatmapInfo.Metadata.ArtistUnicode ?? BeatmapInfo.Metadata.Artist} - {BeatmapInfo.Metadata.TitleUnicode ?? BeatmapInfo.Metadata.Title}",
|
||||||
$"{Beatmap.Metadata.Artist} - {Beatmap.Metadata.Title}"),
|
$"{BeatmapInfo.Metadata.Artist} - {BeatmapInfo.Metadata.Title}"),
|
||||||
Font = OsuFont.Torus.With(weight: FontWeight.Bold),
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold),
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
@ -93,7 +93,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
},
|
},
|
||||||
new TournamentSpriteText
|
new TournamentSpriteText
|
||||||
{
|
{
|
||||||
Text = Beatmap.Metadata.AuthorString,
|
Text = BeatmapInfo.Metadata.AuthorString,
|
||||||
Padding = new MarginPadding { Right = 20 },
|
Padding = new MarginPadding { Right = 20 },
|
||||||
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
||||||
},
|
},
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
},
|
},
|
||||||
new TournamentSpriteText
|
new TournamentSpriteText
|
||||||
{
|
{
|
||||||
Text = Beatmap.Version,
|
Text = BeatmapInfo.Version,
|
||||||
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
var found = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap.OnlineBeatmapID);
|
var found = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == BeatmapInfo.OnlineBeatmapID);
|
||||||
|
|
||||||
bool doFlash = found != choice;
|
bool doFlash = found != choice;
|
||||||
choice = found;
|
choice = found;
|
||||||
|
@ -94,7 +94,7 @@ namespace osu.Game.Tournament.IPC
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
beatmapLookupRequest = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
|
beatmapLookupRequest = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
|
||||||
beatmapLookupRequest.Success += b => Beatmap.Value = b.ToBeatmap(Rulesets);
|
beatmapLookupRequest.Success += b => Beatmap.Value = b.ToBeatmapInfo(Rulesets);
|
||||||
API.Queue(beatmapLookupRequest);
|
API.Queue(beatmapLookupRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace osu.Game.Tournament.Screens
|
|||||||
private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap)
|
private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap)
|
||||||
{
|
{
|
||||||
SongBar.FadeInFromZero(300, Easing.OutQuint);
|
SongBar.FadeInFromZero(300, Easing.OutQuint);
|
||||||
SongBar.Beatmap = beatmap.NewValue;
|
SongBar.BeatmapInfo = beatmap.NewValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
|
|
||||||
req.Success += res =>
|
req.Success += res =>
|
||||||
{
|
{
|
||||||
Model.BeatmapInfo = res.ToBeatmap(rulesets);
|
Model.BeatmapInfo = res.ToBeatmapInfo(rulesets);
|
||||||
updatePanel();
|
updatePanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
|
|
||||||
req.Success += res =>
|
req.Success += res =>
|
||||||
{
|
{
|
||||||
Model.BeatmapInfo = res.ToBeatmap(rulesets);
|
Model.BeatmapInfo = res.ToBeatmapInfo(rulesets);
|
||||||
updatePanel();
|
updatePanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,11 +147,11 @@ namespace osu.Game.Tournament.Screens.MapPool
|
|||||||
|
|
||||||
if (map != null)
|
if (map != null)
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButton.Left && map.Beatmap.OnlineBeatmapID != null)
|
if (e.Button == MouseButton.Left && map.BeatmapInfo.OnlineBeatmapID != null)
|
||||||
addForBeatmap(map.Beatmap.OnlineBeatmapID.Value);
|
addForBeatmap(map.BeatmapInfo.OnlineBeatmapID.Value);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID);
|
var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.BeatmapInfo.OnlineBeatmapID);
|
||||||
|
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +182,7 @@ namespace osu.Game.Tournament
|
|||||||
{
|
{
|
||||||
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
|
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
|
||||||
API.Perform(req);
|
API.Perform(req);
|
||||||
b.BeatmapInfo = req.Result?.ToBeatmap(RulesetStore);
|
b.BeatmapInfo = req.Result?.ToBeatmapInfo(RulesetStore);
|
||||||
|
|
||||||
addedInfo = true;
|
addedInfo = true;
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ namespace osu.Game.Tournament
|
|||||||
{
|
{
|
||||||
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
|
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
|
||||||
req.Perform(API);
|
req.Perform(API);
|
||||||
b.BeatmapInfo = req.Result?.ToBeatmap(RulesetStore);
|
b.BeatmapInfo = req.Result?.ToBeatmapInfo(RulesetStore);
|
||||||
|
|
||||||
addedInfo = true;
|
addedInfo = true;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
// GetDifficultyAsync will fall back to existing data from BeatmapInfo if not locally available
|
// GetDifficultyAsync will fall back to existing data from BeatmapInfo if not locally available
|
||||||
// (contrary to GetAsync)
|
// (contrary to GetAsync)
|
||||||
GetDifficultyAsync(bindable.Beatmap, rulesetInfo, mods, cancellationToken)
|
GetDifficultyAsync(bindable.BeatmapInfo, rulesetInfo, mods, cancellationToken)
|
||||||
.ContinueWith(t =>
|
.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
// We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.
|
// We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.
|
||||||
@ -262,7 +262,7 @@ namespace osu.Game.Beatmaps
|
|||||||
private StarDifficulty computeDifficulty(in DifficultyCacheLookup key)
|
private StarDifficulty computeDifficulty(in DifficultyCacheLookup key)
|
||||||
{
|
{
|
||||||
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
||||||
var beatmapInfo = key.Beatmap;
|
var beatmapInfo = key.BeatmapInfo;
|
||||||
var rulesetInfo = key.Ruleset;
|
var rulesetInfo = key.Ruleset;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -270,7 +270,7 @@ namespace osu.Game.Beatmaps
|
|||||||
var ruleset = rulesetInfo.CreateInstance();
|
var ruleset = rulesetInfo.CreateInstance();
|
||||||
Debug.Assert(ruleset != null);
|
Debug.Assert(ruleset != null);
|
||||||
|
|
||||||
var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(key.Beatmap));
|
var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(key.BeatmapInfo));
|
||||||
var attributes = calculator.Calculate(key.OrderedMods);
|
var attributes = calculator.Calculate(key.OrderedMods);
|
||||||
|
|
||||||
return new StarDifficulty(attributes);
|
return new StarDifficulty(attributes);
|
||||||
@ -300,21 +300,21 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
public readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
public readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo BeatmapInfo;
|
||||||
public readonly RulesetInfo Ruleset;
|
public readonly RulesetInfo Ruleset;
|
||||||
|
|
||||||
public readonly Mod[] OrderedMods;
|
public readonly Mod[] OrderedMods;
|
||||||
|
|
||||||
public DifficultyCacheLookup([NotNull] BeatmapInfo beatmap, [CanBeNull] RulesetInfo ruleset, IEnumerable<Mod> mods)
|
public DifficultyCacheLookup([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo ruleset, IEnumerable<Mod> mods)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
BeatmapInfo = beatmapInfo;
|
||||||
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
||||||
Ruleset = ruleset ?? Beatmap.Ruleset;
|
Ruleset = ruleset ?? BeatmapInfo.Ruleset;
|
||||||
OrderedMods = mods?.OrderBy(m => m.Acronym).Select(mod => mod.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
OrderedMods = mods?.OrderBy(m => m.Acronym).Select(mod => mod.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(DifficultyCacheLookup other)
|
public bool Equals(DifficultyCacheLookup other)
|
||||||
=> Beatmap.ID == other.Beatmap.ID
|
=> BeatmapInfo.ID == other.BeatmapInfo.ID
|
||||||
&& Ruleset.ID == other.Ruleset.ID
|
&& Ruleset.ID == other.Ruleset.ID
|
||||||
&& OrderedMods.SequenceEqual(other.OrderedMods);
|
&& OrderedMods.SequenceEqual(other.OrderedMods);
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
var hashCode = new HashCode();
|
var hashCode = new HashCode();
|
||||||
|
|
||||||
hashCode.Add(Beatmap.ID);
|
hashCode.Add(BeatmapInfo.ID);
|
||||||
hashCode.Add(Ruleset.ID);
|
hashCode.Add(Ruleset.ID);
|
||||||
|
|
||||||
foreach (var mod in OrderedMods)
|
foreach (var mod in OrderedMods)
|
||||||
@ -334,12 +334,12 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
private class BindableStarDifficulty : Bindable<StarDifficulty?>
|
private class BindableStarDifficulty : Bindable<StarDifficulty?>
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo BeatmapInfo;
|
||||||
public readonly CancellationToken CancellationToken;
|
public readonly CancellationToken CancellationToken;
|
||||||
|
|
||||||
public BindableStarDifficulty(BeatmapInfo beatmap, CancellationToken cancellationToken)
|
public BindableStarDifficulty(BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
BeatmapInfo = beatmapInfo;
|
||||||
CancellationToken = cancellationToken;
|
CancellationToken = cancellationToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,111 +6,67 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Track;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Lists;
|
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Statistics;
|
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps.Formats;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Objects;
|
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the storage and retrieval of Beatmaps/WorkingBeatmaps.
|
/// Handles general operations related to global beatmap management.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
public partial class BeatmapManager : DownloadableArchiveModelManager<BeatmapSetInfo, BeatmapSetFileInfo>, IDisposable, IBeatmapResourceProvider
|
public class BeatmapManager : IModelDownloader<BeatmapSetInfo>, IModelManager<BeatmapSetInfo>, IModelFileManager<BeatmapSetInfo, BeatmapSetFileInfo>, ICanAcceptFiles, IWorkingBeatmapCache, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
private readonly BeatmapModelManager beatmapModelManager;
|
||||||
/// Fired when a single difficulty has been hidden.
|
private readonly BeatmapModelDownloader beatmapModelDownloader;
|
||||||
/// </summary>
|
|
||||||
public IBindable<WeakReference<BeatmapInfo>> BeatmapHidden => beatmapHidden;
|
|
||||||
|
|
||||||
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapHidden = new Bindable<WeakReference<BeatmapInfo>>();
|
private readonly WorkingBeatmapCache workingBeatmapCache;
|
||||||
|
private readonly BeatmapOnlineLookupQueue onlineBeatmapLookupQueue;
|
||||||
/// <summary>
|
|
||||||
/// Fired when a single difficulty has been restored.
|
|
||||||
/// </summary>
|
|
||||||
public IBindable<WeakReference<BeatmapInfo>> BeatmapRestored => beatmapRestored;
|
|
||||||
|
|
||||||
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapRestored = new Bindable<WeakReference<BeatmapInfo>>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
|
|
||||||
/// </summary>
|
|
||||||
public readonly WorkingBeatmap DefaultBeatmap;
|
|
||||||
|
|
||||||
public override IEnumerable<string> HandledExtensions => new[] { ".osz" };
|
|
||||||
|
|
||||||
protected override string[] HashableFileTypes => new[] { ".osu" };
|
|
||||||
|
|
||||||
protected override string ImportFromStablePath => ".";
|
|
||||||
|
|
||||||
protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage();
|
|
||||||
|
|
||||||
private readonly RulesetStore rulesets;
|
|
||||||
private readonly BeatmapStore beatmaps;
|
|
||||||
private readonly AudioManager audioManager;
|
|
||||||
private readonly IResourceStore<byte[]> resources;
|
|
||||||
private readonly LargeTextureStore largeTextureStore;
|
|
||||||
private readonly ITrackStore trackStore;
|
|
||||||
|
|
||||||
[CanBeNull]
|
|
||||||
private readonly GameHost host;
|
|
||||||
|
|
||||||
[CanBeNull]
|
|
||||||
private readonly BeatmapOnlineLookupQueue onlineLookupQueue;
|
|
||||||
|
|
||||||
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null,
|
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null,
|
||||||
WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
||||||
: base(storage, contextFactory, api, new BeatmapStore(contextFactory), host)
|
|
||||||
{
|
{
|
||||||
this.rulesets = rulesets;
|
beatmapModelManager = CreateBeatmapModelManager(storage, contextFactory, rulesets, api, host);
|
||||||
this.audioManager = audioManager;
|
beatmapModelDownloader = CreateBeatmapModelDownloader(beatmapModelManager, api, host);
|
||||||
this.resources = resources;
|
workingBeatmapCache = CreateWorkingBeatmapCache(audioManager, resources, new FileStore(contextFactory, storage).Store, defaultBeatmap, host);
|
||||||
this.host = host;
|
|
||||||
|
|
||||||
DefaultBeatmap = defaultBeatmap;
|
workingBeatmapCache.BeatmapManager = beatmapModelManager;
|
||||||
|
|
||||||
beatmaps = (BeatmapStore)ModelStore;
|
|
||||||
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
|
|
||||||
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
|
|
||||||
beatmaps.ItemRemoved += removeWorkingCache;
|
|
||||||
beatmaps.ItemUpdated += removeWorkingCache;
|
|
||||||
|
|
||||||
if (performOnlineLookups)
|
if (performOnlineLookups)
|
||||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
{
|
||||||
|
onlineBeatmapLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||||
largeTextureStore = new LargeTextureStore(host?.CreateTextureLoaderStore(Files.Store));
|
beatmapModelManager.OnlineLookupQueue = onlineBeatmapLookupQueue;
|
||||||
trackStore = audioManager.GetTrackStore(Files.Store);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
|
protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(BeatmapModelManager modelManager, IAPIProvider api, GameHost host)
|
||||||
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
|
{
|
||||||
|
return new BeatmapModelDownloader(modelManager, api, host);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == ".osz";
|
protected virtual WorkingBeatmapCache CreateWorkingBeatmapCache(AudioManager audioManager, IResourceStore<byte[]> resources, IResourceStore<byte[]> storage, WorkingBeatmap defaultBeatmap, GameHost host) =>
|
||||||
|
new WorkingBeatmapCache(audioManager, resources, storage, defaultBeatmap, host);
|
||||||
|
|
||||||
|
protected virtual BeatmapModelManager CreateBeatmapModelManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, GameHost host) =>
|
||||||
|
new BeatmapModelManager(storage, contextFactory, rulesets, host);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new <see cref="WorkingBeatmap"/>.
|
||||||
|
/// </summary>
|
||||||
public WorkingBeatmap CreateNew(RulesetInfo ruleset, User user)
|
public WorkingBeatmap CreateNew(RulesetInfo ruleset, User user)
|
||||||
{
|
{
|
||||||
var metadata = new BeatmapMetadata
|
var metadata = new BeatmapMetadata
|
||||||
@ -134,112 +90,22 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var working = Import(set).Result;
|
var imported = beatmapModelManager.Import(set).Result.Value;
|
||||||
return GetWorkingBeatmap(working.Beatmaps.First());
|
|
||||||
|
return GetWorkingBeatmap(imported.Beatmaps.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
|
#region Delegation to BeatmapModelManager (methods which previously existed locally).
|
||||||
{
|
|
||||||
if (archive != null)
|
|
||||||
beatmapSet.Beatmaps = createBeatmapDifficulties(beatmapSet.Files);
|
|
||||||
|
|
||||||
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
|
||||||
{
|
|
||||||
// remove metadata from difficulties where it matches the set
|
|
||||||
if (beatmapSet.Metadata.Equals(b.Metadata))
|
|
||||||
b.Metadata = null;
|
|
||||||
|
|
||||||
b.BeatmapSet = beatmapSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
validateOnlineIds(beatmapSet);
|
|
||||||
|
|
||||||
bool hadOnlineBeatmapIDs = beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0);
|
|
||||||
|
|
||||||
if (onlineLookupQueue != null)
|
|
||||||
await onlineLookupQueue.UpdateAsync(beatmapSet, cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// ensure at least one beatmap was able to retrieve or keep an online ID, else drop the set ID.
|
|
||||||
if (hadOnlineBeatmapIDs && !beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0))
|
|
||||||
{
|
|
||||||
if (beatmapSet.OnlineBeatmapSetID != null)
|
|
||||||
{
|
|
||||||
beatmapSet.OnlineBeatmapSetID = null;
|
|
||||||
LogForModel(beatmapSet, "Disassociating beatmap set ID due to loss of all beatmap IDs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void PreImport(BeatmapSetInfo beatmapSet)
|
|
||||||
{
|
|
||||||
if (beatmapSet.Beatmaps.Any(b => b.BaseDifficulty == null))
|
|
||||||
throw new InvalidOperationException($"Cannot import {nameof(BeatmapInfo)} with null {nameof(BeatmapInfo.BaseDifficulty)}.");
|
|
||||||
|
|
||||||
// check if a set already exists with the same online id, delete if it does.
|
|
||||||
if (beatmapSet.OnlineBeatmapSetID != null)
|
|
||||||
{
|
|
||||||
var existingOnlineId = beatmaps.ConsumableItems.FirstOrDefault(b => b.OnlineBeatmapSetID == beatmapSet.OnlineBeatmapSetID);
|
|
||||||
|
|
||||||
if (existingOnlineId != null)
|
|
||||||
{
|
|
||||||
Delete(existingOnlineId);
|
|
||||||
|
|
||||||
// in order to avoid a unique key constraint, immediately remove the online ID from the previous set.
|
|
||||||
existingOnlineId.OnlineBeatmapSetID = null;
|
|
||||||
foreach (var b in existingOnlineId.Beatmaps)
|
|
||||||
b.OnlineBeatmapID = null;
|
|
||||||
|
|
||||||
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineBeatmapSetID ({beatmapSet.OnlineBeatmapSetID}). It has been deleted.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateOnlineIds(BeatmapSetInfo beatmapSet)
|
|
||||||
{
|
|
||||||
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList();
|
|
||||||
|
|
||||||
// ensure all IDs are unique
|
|
||||||
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
|
|
||||||
{
|
|
||||||
LogForModel(beatmapSet, "Found non-unique IDs, resetting...");
|
|
||||||
resetIds();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find any existing beatmaps in the database that have matching online ids
|
|
||||||
var existingBeatmaps = QueryBeatmaps(b => beatmapIds.Contains(b.OnlineBeatmapID)).ToList();
|
|
||||||
|
|
||||||
if (existingBeatmaps.Count > 0)
|
|
||||||
{
|
|
||||||
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
|
|
||||||
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
|
|
||||||
var existing = CheckForExisting(beatmapSet);
|
|
||||||
|
|
||||||
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
|
|
||||||
{
|
|
||||||
LogForModel(beatmapSet, "Found existing import with IDs already, resetting...");
|
|
||||||
resetIds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool CheckLocalAvailability(BeatmapSetInfo model, IQueryable<BeatmapSetInfo> items)
|
|
||||||
=> base.CheckLocalAvailability(model, items)
|
|
||||||
|| (model.OnlineBeatmapSetID != null && items.Any(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID));
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a beatmap difficulty.
|
/// Fired when a single difficulty has been hidden.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap difficulty to hide.</param>
|
public IBindable<WeakReference<BeatmapInfo>> BeatmapHidden => beatmapModelManager.BeatmapHidden;
|
||||||
public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restore a beatmap difficulty.
|
/// Fired when a single difficulty has been restored.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap difficulty to restore.</param>
|
public IBindable<WeakReference<BeatmapInfo>> BeatmapRestored => beatmapModelManager.BeatmapRestored;
|
||||||
public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
|
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
|
||||||
@ -247,109 +113,13 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <param name="info">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
|
/// <param name="info">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
|
||||||
/// <param name="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
|
/// <param name="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
|
||||||
/// <param name="beatmapSkin">The beatmap <see cref="ISkin"/> content to write, null if to be omitted.</param>
|
/// <param name="beatmapSkin">The beatmap <see cref="ISkin"/> content to write, null if to be omitted.</param>
|
||||||
public virtual void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
public virtual void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null) => beatmapModelManager.Save(info, beatmapContent, beatmapSkin);
|
||||||
{
|
|
||||||
var setInfo = info.BeatmapSet;
|
|
||||||
|
|
||||||
using (var stream = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
|
||||||
new LegacyBeatmapEncoder(beatmapContent, beatmapSkin).Encode(sw);
|
|
||||||
|
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
using (ContextFactory.GetForWrite())
|
|
||||||
{
|
|
||||||
var beatmapInfo = setInfo.Beatmaps.Single(b => b.ID == info.ID);
|
|
||||||
var metadata = beatmapInfo.Metadata ?? setInfo.Metadata;
|
|
||||||
|
|
||||||
// grab the original file (or create a new one if not found).
|
|
||||||
var fileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase)) ?? new BeatmapSetFileInfo();
|
|
||||||
|
|
||||||
// metadata may have changed; update the path with the standard format.
|
|
||||||
beatmapInfo.Path = $"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.Version}].osu";
|
|
||||||
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
|
|
||||||
|
|
||||||
// update existing or populate new file's filename.
|
|
||||||
fileInfo.Filename = beatmapInfo.Path;
|
|
||||||
|
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
|
||||||
ReplaceFile(setInfo, fileInfo, stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removeWorkingCache(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly WeakList<BeatmapManagerWorkingBeatmap> workingCache = new WeakList<BeatmapManagerWorkingBeatmap>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="beatmapInfo">The beatmap to lookup.</param>
|
|
||||||
/// <returns>A <see cref="WorkingBeatmap"/> instance correlating to the provided <see cref="BeatmapInfo"/>.</returns>
|
|
||||||
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
|
|
||||||
{
|
|
||||||
// if there are no files, presume the full beatmap info has not yet been fetched from the database.
|
|
||||||
if (beatmapInfo?.BeatmapSet?.Files.Count == 0)
|
|
||||||
{
|
|
||||||
int lookupId = beatmapInfo.ID;
|
|
||||||
beatmapInfo = QueryBeatmap(b => b.ID == lookupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (beatmapInfo?.BeatmapSet == null)
|
|
||||||
return DefaultBeatmap;
|
|
||||||
|
|
||||||
lock (workingCache)
|
|
||||||
{
|
|
||||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID);
|
|
||||||
if (working != null)
|
|
||||||
return working;
|
|
||||||
|
|
||||||
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
|
|
||||||
|
|
||||||
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(beatmapInfo, this));
|
|
||||||
|
|
||||||
// best effort; may be higher than expected.
|
|
||||||
GlobalStatistics.Get<int>(nameof(Beatmaps), $"Cached {nameof(WorkingBeatmap)}s").Value = workingCache.Count();
|
|
||||||
|
|
||||||
return working;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query">The query.</param>
|
|
||||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
|
||||||
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
|
||||||
|
|
||||||
protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import)
|
|
||||||
{
|
|
||||||
if (!base.CanSkipImport(existing, import))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return existing.Beatmaps.Any(b => b.OnlineBeatmapID != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool CanReuseExisting(BeatmapSetInfo existing, BeatmapSetInfo import)
|
|
||||||
{
|
|
||||||
if (!base.CanReuseExisting(existing, import))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var existingIds = existing.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
|
||||||
var importIds = import.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
|
||||||
|
|
||||||
// force re-import if we are not in a sane state.
|
|
||||||
return existing.OnlineBeatmapSetID == import.OnlineBeatmapSetID && existingIds.SequenceEqual(importIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
public List<BeatmapSetInfo> GetAllUsableBeatmapSets(IncludedDetails includes = IncludedDetails.All, bool includeProtected = false) =>
|
public List<BeatmapSetInfo> GetAllUsableBeatmapSets(IncludedDetails includes = IncludedDetails.All, bool includeProtected = false) => beatmapModelManager.GetAllUsableBeatmapSets(includes, includeProtected);
|
||||||
GetAllUsableBeatmapSetsEnumerable(includes, includeProtected).ToList();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s. Note that files are not populated.
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s. Note that files are not populated.
|
||||||
@ -357,34 +127,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||||
/// <param name="includeProtected">Whether to include protected (system) beatmaps. These should not be included for gameplay playable use cases.</param>
|
/// <param name="includeProtected">Whether to include protected (system) beatmaps. These should not be included for gameplay playable use cases.</param>
|
||||||
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
public IEnumerable<BeatmapSetInfo> GetAllUsableBeatmapSetsEnumerable(IncludedDetails includes, bool includeProtected = false)
|
public IEnumerable<BeatmapSetInfo> GetAllUsableBeatmapSetsEnumerable(IncludedDetails includes, bool includeProtected = false) => beatmapModelManager.GetAllUsableBeatmapSetsEnumerable(includes, includeProtected);
|
||||||
{
|
|
||||||
IQueryable<BeatmapSetInfo> queryable;
|
|
||||||
|
|
||||||
switch (includes)
|
|
||||||
{
|
|
||||||
case IncludedDetails.Minimal:
|
|
||||||
queryable = beatmaps.BeatmapSetsOverview;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IncludedDetails.AllButRuleset:
|
|
||||||
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IncludedDetails.AllButFiles:
|
|
||||||
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
queryable = beatmaps.ConsumableItems;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsEnumerable used here to avoid applying the WHERE in sql. When done so, ef core 2.x uses an incorrect ORDER BY
|
|
||||||
// clause which causes queries to take 5-10x longer.
|
|
||||||
// TODO: remove if upgrading to EF core 3.x.
|
|
||||||
return queryable.AsEnumerable().Where(s => !s.DeletePending && (includeProtected || !s.Protected));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
@ -392,207 +135,204 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||||
/// <returns>Results from the provided query.</returns>
|
/// <returns>Results from the provided query.</returns>
|
||||||
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query, IncludedDetails includes = IncludedDetails.All)
|
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query, IncludedDetails includes = IncludedDetails.All) => beatmapModelManager.QueryBeatmapSets(query, includes);
|
||||||
{
|
|
||||||
IQueryable<BeatmapSetInfo> queryable;
|
|
||||||
|
|
||||||
switch (includes)
|
|
||||||
{
|
|
||||||
case IncludedDetails.Minimal:
|
|
||||||
queryable = beatmaps.BeatmapSetsOverview;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IncludedDetails.AllButRuleset:
|
|
||||||
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IncludedDetails.AllButFiles:
|
|
||||||
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
queryable = beatmaps.ConsumableItems;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryable.AsNoTracking().Where(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
public BeatmapInfo QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().FirstOrDefault(query);
|
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmapModelManager.QueryBeatmapSet(query);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">The query.</param>
|
/// <param name="query">The query.</param>
|
||||||
/// <returns>Results from the provided query.</returns>
|
/// <returns>Results from the provided query.</returns>
|
||||||
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().Where(query);
|
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query) => beatmapModelManager.QueryBeatmaps(query);
|
||||||
|
|
||||||
protected override string HumanisedModelName => "beatmap";
|
/// <summary>
|
||||||
|
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query.</param>
|
||||||
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
|
public BeatmapInfo QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => beatmapModelManager.QueryBeatmap(query);
|
||||||
|
|
||||||
protected override BeatmapSetInfo CreateModel(ArchiveReader reader)
|
/// <summary>
|
||||||
|
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
|
||||||
|
/// </summary>
|
||||||
|
public WorkingBeatmap DefaultBeatmap => workingBeatmapCache.DefaultBeatmap;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when a notification should be presented to the user.
|
||||||
|
/// </summary>
|
||||||
|
public Action<Notification> PostNotification
|
||||||
{
|
{
|
||||||
// let's make sure there are actually .osu files to import.
|
set
|
||||||
string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu", StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(mapName))
|
|
||||||
{
|
{
|
||||||
Logger.Log($"No beatmap files found in the beatmap archive ({reader.Name}).", LoggingTarget.Database);
|
beatmapModelManager.PostNotification = value;
|
||||||
return null;
|
beatmapModelDownloader.PostNotification = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Beatmap beatmap;
|
|
||||||
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
|
|
||||||
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
|
||||||
|
|
||||||
return new BeatmapSetInfo
|
|
||||||
{
|
|
||||||
OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID,
|
|
||||||
Beatmaps = new List<BeatmapInfo>(),
|
|
||||||
Metadata = beatmap.Metadata,
|
|
||||||
DateAdded = DateTimeOffset.UtcNow
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create all required <see cref="BeatmapInfo"/>s for the provided archive.
|
/// Fired when the user requests to view the resulting import.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<BeatmapInfo> createBeatmapDifficulties(List<BeatmapSetFileInfo> files)
|
public Action<IEnumerable<ILive<BeatmapSetInfo>>> PresentImport { set => beatmapModelManager.PostImport = value; }
|
||||||
{
|
|
||||||
var beatmapInfos = new List<BeatmapInfo>();
|
|
||||||
|
|
||||||
foreach (var file in files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
|
/// <summary>
|
||||||
{
|
/// Delete a beatmap difficulty.
|
||||||
using (var raw = Files.Store.GetStream(file.FileInfo.StoragePath))
|
/// </summary>
|
||||||
using (var ms = new MemoryStream()) // we need a memory stream so we can seek
|
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
|
||||||
using (var sr = new LineBufferedReader(ms))
|
public void Hide(BeatmapInfo beatmapInfo) => beatmapModelManager.Hide(beatmapInfo);
|
||||||
{
|
|
||||||
raw.CopyTo(ms);
|
|
||||||
ms.Position = 0;
|
|
||||||
|
|
||||||
var decoder = Decoder.GetDecoder<Beatmap>(sr);
|
/// <summary>
|
||||||
IBeatmap beatmap = decoder.Decode(sr);
|
/// Restore a beatmap difficulty.
|
||||||
|
/// </summary>
|
||||||
string hash = ms.ComputeSHA2Hash();
|
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
|
||||||
|
public void Restore(BeatmapInfo beatmapInfo) => beatmapModelManager.Restore(beatmapInfo);
|
||||||
if (beatmapInfos.Any(b => b.Hash == hash))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
beatmap.BeatmapInfo.Path = file.Filename;
|
|
||||||
beatmap.BeatmapInfo.Hash = hash;
|
|
||||||
beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();
|
|
||||||
|
|
||||||
var ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
|
|
||||||
beatmap.BeatmapInfo.Ruleset = ruleset;
|
|
||||||
|
|
||||||
// TODO: this should be done in a better place once we actually need to dynamically update it.
|
|
||||||
beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0;
|
|
||||||
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
|
||||||
beatmap.BeatmapInfo.BPM = 60000 / beatmap.GetMostCommonBeatLength();
|
|
||||||
|
|
||||||
beatmapInfos.Add(beatmap.BeatmapInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return beatmapInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double calculateLength(IBeatmap b)
|
|
||||||
{
|
|
||||||
if (!b.HitObjects.Any())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
var lastObject = b.HitObjects.Last();
|
|
||||||
|
|
||||||
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
|
|
||||||
double endTime = lastObject.GetEndTime();
|
|
||||||
double startTime = b.HitObjects.First().StartTime;
|
|
||||||
|
|
||||||
return endTime - startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeWorkingCache(BeatmapSetInfo info)
|
|
||||||
{
|
|
||||||
if (info.Beatmaps == null) return;
|
|
||||||
|
|
||||||
foreach (var b in info.Beatmaps)
|
|
||||||
removeWorkingCache(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeWorkingCache(BeatmapInfo info)
|
|
||||||
{
|
|
||||||
lock (workingCache)
|
|
||||||
{
|
|
||||||
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
|
||||||
if (working != null)
|
|
||||||
workingCache.Remove(working);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
onlineLookupQueue?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IResourceStorageProvider
|
|
||||||
|
|
||||||
TextureStore IBeatmapResourceProvider.LargeTextureStore => largeTextureStore;
|
|
||||||
ITrackStore IBeatmapResourceProvider.Tracks => trackStore;
|
|
||||||
AudioManager IStorageResourceProvider.AudioManager => audioManager;
|
|
||||||
IResourceStore<byte[]> IStorageResourceProvider.Files => Files.Store;
|
|
||||||
IResourceStore<byte[]> IStorageResourceProvider.Resources => resources;
|
|
||||||
IResourceStore<TextureUpload> IStorageResourceProvider.CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => host?.CreateTextureLoaderStore(underlyingStore);
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
#region Implementation of IModelManager<BeatmapSetInfo>
|
||||||
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
|
||||||
/// </summary>
|
public bool IsAvailableLocally(BeatmapSetInfo model)
|
||||||
private class DummyConversionBeatmap : WorkingBeatmap
|
|
||||||
{
|
{
|
||||||
private readonly IBeatmap beatmap;
|
return beatmapModelManager.IsAvailableLocally(model);
|
||||||
|
|
||||||
public DummyConversionBeatmap(IBeatmap beatmap)
|
|
||||||
: base(beatmap.BeatmapInfo, null)
|
|
||||||
{
|
|
||||||
this.beatmap = beatmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IBeatmap GetBeatmap() => beatmap;
|
|
||||||
protected override Texture GetBackground() => null;
|
|
||||||
protected override Track GetBeatmapTrack() => null;
|
|
||||||
protected internal override ISkin GetSkin() => null;
|
|
||||||
public override Stream GetStream(string storagePath) => null;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
public IBindable<WeakReference<BeatmapSetInfo>> ItemUpdated => beatmapModelManager.ItemUpdated;
|
||||||
/// The level of detail to include in database results.
|
|
||||||
/// </summary>
|
|
||||||
public enum IncludedDetails
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Only include beatmap difficulties and set level metadata.
|
|
||||||
/// </summary>
|
|
||||||
Minimal,
|
|
||||||
|
|
||||||
/// <summary>
|
public IBindable<WeakReference<BeatmapSetInfo>> ItemRemoved => beatmapModelManager.ItemRemoved;
|
||||||
/// Include all difficulties, rulesets, difficulty metadata but no files.
|
|
||||||
/// </summary>
|
|
||||||
AllButFiles,
|
|
||||||
|
|
||||||
/// <summary>
|
public Task ImportFromStableAsync(StableStorage stableStorage)
|
||||||
/// Include everything except ruleset. Used for cases where we aren't sure the ruleset is present but still want to consume the beatmap.
|
{
|
||||||
/// </summary>
|
return beatmapModelManager.ImportFromStableAsync(stableStorage);
|
||||||
AllButRuleset,
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void Export(BeatmapSetInfo item)
|
||||||
/// Include everything.
|
{
|
||||||
/// </summary>
|
beatmapModelManager.Export(item);
|
||||||
All
|
}
|
||||||
|
|
||||||
|
public void ExportModelTo(BeatmapSetInfo model, Stream outputStream)
|
||||||
|
{
|
||||||
|
beatmapModelManager.ExportModelTo(model, outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(BeatmapSetInfo item)
|
||||||
|
{
|
||||||
|
beatmapModelManager.Update(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(BeatmapSetInfo item)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Delete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(List<BeatmapSetInfo> items, bool silent = false)
|
||||||
|
{
|
||||||
|
beatmapModelManager.Delete(items, silent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Undelete(List<BeatmapSetInfo> items, bool silent = false)
|
||||||
|
{
|
||||||
|
beatmapModelManager.Undelete(items, silent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Undelete(BeatmapSetInfo item)
|
||||||
|
{
|
||||||
|
beatmapModelManager.Undelete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of IModelDownloader<BeatmapSetInfo>
|
||||||
|
|
||||||
|
public IBindable<WeakReference<ArchiveDownloadRequest<BeatmapSetInfo>>> DownloadBegan => beatmapModelDownloader.DownloadBegan;
|
||||||
|
|
||||||
|
public IBindable<WeakReference<ArchiveDownloadRequest<BeatmapSetInfo>>> DownloadFailed => beatmapModelDownloader.DownloadFailed;
|
||||||
|
|
||||||
|
public bool Download(BeatmapSetInfo model, bool minimiseDownloadSize = false)
|
||||||
|
{
|
||||||
|
return beatmapModelDownloader.Download(model, minimiseDownloadSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArchiveDownloadRequest<BeatmapSetInfo> GetExistingDownload(BeatmapSetInfo model)
|
||||||
|
{
|
||||||
|
return beatmapModelDownloader.GetExistingDownload(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of ICanAcceptFiles
|
||||||
|
|
||||||
|
public Task Import(params string[] paths)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Import(params ImportTask[] tasks)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<ILive<BeatmapSetInfo>>> Import(ProgressNotification notification, params ImportTask[] tasks)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(notification, tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ILive<BeatmapSetInfo>> Import(ImportTask task, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(task, lowPriority, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ILive<BeatmapSetInfo>> Import(ArchiveReader archive, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(archive, lowPriority, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ILive<BeatmapSetInfo>> Import(BeatmapSetInfo item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return beatmapModelManager.Import(item, archive, lowPriority, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> HandledExtensions => beatmapModelManager.HandledExtensions;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of IWorkingBeatmapCache
|
||||||
|
|
||||||
|
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo importedBeatmap) => workingBeatmapCache.GetWorkingBeatmap(importedBeatmap);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of IModelFileManager<in BeatmapSetInfo,in BeatmapSetFileInfo>
|
||||||
|
|
||||||
|
public void ReplaceFile(BeatmapSetInfo model, BeatmapSetFileInfo file, Stream contents, string filename = null)
|
||||||
|
{
|
||||||
|
beatmapModelManager.ReplaceFile(model, file, contents, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteFile(BeatmapSetInfo model, BeatmapSetFileInfo file)
|
||||||
|
{
|
||||||
|
beatmapModelManager.DeleteFile(model, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddFile(BeatmapSetInfo model, Stream contents, string filename)
|
||||||
|
{
|
||||||
|
beatmapModelManager.AddFile(model, contents, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of IDisposable
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
onlineBeatmapLookupQueue?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,215 +0,0 @@
|
|||||||
// 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.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using osu.Framework.Development;
|
|
||||||
using osu.Framework.IO.Network;
|
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Game.Database;
|
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using SharpCompress.Compressors;
|
|
||||||
using SharpCompress.Compressors.BZip2;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
|
||||||
{
|
|
||||||
public partial class BeatmapManager
|
|
||||||
{
|
|
||||||
[ExcludeFromDynamicCompile]
|
|
||||||
private class BeatmapOnlineLookupQueue : IDisposable
|
|
||||||
{
|
|
||||||
private readonly IAPIProvider api;
|
|
||||||
private readonly Storage storage;
|
|
||||||
|
|
||||||
private const int update_queue_request_concurrency = 4;
|
|
||||||
|
|
||||||
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapOnlineLookupQueue));
|
|
||||||
|
|
||||||
private FileWebRequest cacheDownloadRequest;
|
|
||||||
|
|
||||||
private const string cache_database_name = "online.db";
|
|
||||||
|
|
||||||
public BeatmapOnlineLookupQueue(IAPIProvider api, Storage storage)
|
|
||||||
{
|
|
||||||
this.api = api;
|
|
||||||
this.storage = storage;
|
|
||||||
|
|
||||||
// avoid downloading / using cache for unit tests.
|
|
||||||
if (!DebugUtils.IsNUnitRunning && !storage.Exists(cache_database_name))
|
|
||||||
prepareLocalCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task UpdateAsync(BeatmapSetInfo beatmapSet, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return Task.WhenAll(beatmapSet.Beatmaps.Select(b => UpdateAsync(beatmapSet, b, cancellationToken)).ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: expose this when we need to do individual difficulty lookups.
|
|
||||||
protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmap, CancellationToken cancellationToken)
|
|
||||||
=> Task.Factory.StartNew(() => lookup(beatmapSet, beatmap), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
|
||||||
|
|
||||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
if (checkLocalCache(set, beatmap))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (api?.State.Value != APIState.Online)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var req = new GetBeatmapRequest(beatmap);
|
|
||||||
|
|
||||||
req.Failure += fail;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// intentionally blocking to limit web request concurrency
|
|
||||||
api.Perform(req);
|
|
||||||
|
|
||||||
var res = req.Result;
|
|
||||||
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
beatmap.Status = res.Status;
|
|
||||||
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
|
||||||
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
|
||||||
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
|
||||||
|
|
||||||
if (beatmap.Metadata != null)
|
|
||||||
beatmap.Metadata.AuthorID = res.AuthorID;
|
|
||||||
|
|
||||||
if (beatmap.BeatmapSet.Metadata != null)
|
|
||||||
beatmap.BeatmapSet.Metadata.AuthorID = res.AuthorID;
|
|
||||||
|
|
||||||
LogForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fail(Exception e)
|
|
||||||
{
|
|
||||||
beatmap.OnlineBeatmapID = null;
|
|
||||||
LogForModel(set, $"Online retrieval failed for {beatmap} ({e.Message})");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void prepareLocalCache()
|
|
||||||
{
|
|
||||||
string cacheFilePath = storage.GetFullPath(cache_database_name);
|
|
||||||
string compressedCacheFilePath = $"{cacheFilePath}.bz2";
|
|
||||||
|
|
||||||
cacheDownloadRequest = new FileWebRequest(compressedCacheFilePath, $"https://assets.ppy.sh/client-resources/{cache_database_name}.bz2?{DateTimeOffset.UtcNow:yyyyMMdd}");
|
|
||||||
|
|
||||||
cacheDownloadRequest.Failed += ex =>
|
|
||||||
{
|
|
||||||
File.Delete(compressedCacheFilePath);
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
|
|
||||||
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
|
||||||
};
|
|
||||||
|
|
||||||
cacheDownloadRequest.Finished += () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = File.OpenRead(cacheDownloadRequest.Filename))
|
|
||||||
using (var outStream = File.OpenWrite(cacheFilePath))
|
|
||||||
using (var bz2 = new BZip2Stream(stream, CompressionMode.Decompress, false))
|
|
||||||
bz2.CopyTo(outStream);
|
|
||||||
|
|
||||||
// set to null on completion to allow lookups to begin using the new source
|
|
||||||
cacheDownloadRequest = null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
File.Delete(compressedCacheFilePath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
cacheDownloadRequest.PerformAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool checkLocalCache(BeatmapSetInfo set, BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
// download is in progress (or was, and failed).
|
|
||||||
if (cacheDownloadRequest != null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// database is unavailable.
|
|
||||||
if (!storage.Exists(cache_database_name))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(beatmap.MD5Hash)
|
|
||||||
&& string.IsNullOrEmpty(beatmap.Path)
|
|
||||||
&& beatmap.OnlineBeatmapID == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var db = new SqliteConnection(DatabaseContextFactory.CreateDatabaseConnectionString("online.db", storage)))
|
|
||||||
{
|
|
||||||
db.Open();
|
|
||||||
|
|
||||||
using (var cmd = db.CreateCommand())
|
|
||||||
{
|
|
||||||
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved, user_id FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineBeatmapID OR filename = @Path";
|
|
||||||
|
|
||||||
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmap.MD5Hash));
|
|
||||||
cmd.Parameters.Add(new SqliteParameter("@OnlineBeatmapID", beatmap.OnlineBeatmapID ?? (object)DBNull.Value));
|
|
||||||
cmd.Parameters.Add(new SqliteParameter("@Path", beatmap.Path));
|
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
|
||||||
{
|
|
||||||
if (reader.Read())
|
|
||||||
{
|
|
||||||
var status = (BeatmapSetOnlineStatus)reader.GetByte(2);
|
|
||||||
|
|
||||||
beatmap.Status = status;
|
|
||||||
beatmap.BeatmapSet.Status = status;
|
|
||||||
beatmap.BeatmapSet.OnlineBeatmapSetID = reader.GetInt32(0);
|
|
||||||
beatmap.OnlineBeatmapID = reader.GetInt32(1);
|
|
||||||
|
|
||||||
if (beatmap.Metadata != null)
|
|
||||||
beatmap.Metadata.AuthorID = reader.GetInt32(3);
|
|
||||||
|
|
||||||
if (beatmap.BeatmapSet.Metadata != null)
|
|
||||||
beatmap.BeatmapSet.Metadata.AuthorID = reader.GetInt32(3);
|
|
||||||
|
|
||||||
LogForModel(set, $"Cached local retrieval for {beatmap}.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogForModel(set, $"Cached local retrieval for {beatmap} failed with {ex}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
cacheDownloadRequest?.Dispose();
|
|
||||||
updateScheduler?.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
21
osu.Game/Beatmaps/BeatmapModelDownloader.cs
Normal file
21
osu.Game/Beatmaps/BeatmapModelDownloader.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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 osu.Framework.Platform;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
public class BeatmapModelDownloader : ModelDownloader<BeatmapSetInfo>
|
||||||
|
{
|
||||||
|
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
|
||||||
|
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
|
||||||
|
|
||||||
|
public BeatmapModelDownloader(BeatmapModelManager beatmapModelManager, IAPIProvider api, GameHost host = null)
|
||||||
|
: base(beatmapModelManager, api, host)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
473
osu.Game/Beatmaps/BeatmapModelManager.cs
Normal file
473
osu.Game/Beatmaps/BeatmapModelManager.cs
Normal file
@ -0,0 +1,473 @@
|
|||||||
|
// 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.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.IO;
|
||||||
|
using osu.Game.IO.Archives;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles ef-core storage of beatmaps.
|
||||||
|
/// </summary>
|
||||||
|
[ExcludeFromDynamicCompile]
|
||||||
|
public class BeatmapModelManager : ArchiveModelManager<BeatmapSetInfo, BeatmapSetFileInfo>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when a single difficulty has been hidden.
|
||||||
|
/// </summary>
|
||||||
|
public IBindable<WeakReference<BeatmapInfo>> BeatmapHidden => beatmapHidden;
|
||||||
|
|
||||||
|
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapHidden = new Bindable<WeakReference<BeatmapInfo>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when a single difficulty has been restored.
|
||||||
|
/// </summary>
|
||||||
|
public IBindable<WeakReference<BeatmapInfo>> BeatmapRestored => beatmapRestored;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An online lookup queue component which handles populating online beatmap metadata.
|
||||||
|
/// </summary>
|
||||||
|
public BeatmapOnlineLookupQueue OnlineLookupQueue { private get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The game working beatmap cache, used to invalidate entries on changes.
|
||||||
|
/// </summary>
|
||||||
|
public WorkingBeatmapCache WorkingBeatmapCache { private get; set; }
|
||||||
|
|
||||||
|
private readonly Bindable<WeakReference<BeatmapInfo>> beatmapRestored = new Bindable<WeakReference<BeatmapInfo>>();
|
||||||
|
|
||||||
|
public override IEnumerable<string> HandledExtensions => new[] { ".osz" };
|
||||||
|
|
||||||
|
protected override string[] HashableFileTypes => new[] { ".osu" };
|
||||||
|
|
||||||
|
protected override string ImportFromStablePath => ".";
|
||||||
|
|
||||||
|
protected override Storage PrepareStableStorage(StableStorage stableStorage) => stableStorage.GetSongStorage();
|
||||||
|
|
||||||
|
private readonly BeatmapStore beatmaps;
|
||||||
|
private readonly RulesetStore rulesets;
|
||||||
|
|
||||||
|
public BeatmapModelManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, GameHost host = null)
|
||||||
|
: base(storage, contextFactory, new BeatmapStore(contextFactory), host)
|
||||||
|
{
|
||||||
|
this.rulesets = rulesets;
|
||||||
|
|
||||||
|
beatmaps = (BeatmapStore)ModelStore;
|
||||||
|
beatmaps.BeatmapHidden += b => beatmapHidden.Value = new WeakReference<BeatmapInfo>(b);
|
||||||
|
beatmaps.BeatmapRestored += b => beatmapRestored.Value = new WeakReference<BeatmapInfo>(b);
|
||||||
|
beatmaps.ItemRemoved += b => WorkingBeatmapCache?.Invalidate(b);
|
||||||
|
beatmaps.ItemUpdated += obj => WorkingBeatmapCache?.Invalidate(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path)?.ToLowerInvariant() == ".osz";
|
||||||
|
|
||||||
|
protected override async Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (archive != null)
|
||||||
|
beatmapSet.Beatmaps = createBeatmapDifficulties(beatmapSet.Files);
|
||||||
|
|
||||||
|
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
||||||
|
{
|
||||||
|
// remove metadata from difficulties where it matches the set
|
||||||
|
if (beatmapSet.Metadata.Equals(b.Metadata))
|
||||||
|
b.Metadata = null;
|
||||||
|
|
||||||
|
b.BeatmapSet = beatmapSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
validateOnlineIds(beatmapSet);
|
||||||
|
|
||||||
|
bool hadOnlineBeatmapIDs = beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0);
|
||||||
|
|
||||||
|
if (OnlineLookupQueue != null)
|
||||||
|
await OnlineLookupQueue.UpdateAsync(beatmapSet, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// ensure at least one beatmap was able to retrieve or keep an online ID, else drop the set ID.
|
||||||
|
if (hadOnlineBeatmapIDs && !beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID > 0))
|
||||||
|
{
|
||||||
|
if (beatmapSet.OnlineBeatmapSetID != null)
|
||||||
|
{
|
||||||
|
beatmapSet.OnlineBeatmapSetID = null;
|
||||||
|
LogForModel(beatmapSet, "Disassociating beatmap set ID due to loss of all beatmap IDs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PreImport(BeatmapSetInfo beatmapSet)
|
||||||
|
{
|
||||||
|
if (beatmapSet.Beatmaps.Any(b => b.BaseDifficulty == null))
|
||||||
|
throw new InvalidOperationException($"Cannot import {nameof(BeatmapInfo)} with null {nameof(BeatmapInfo.BaseDifficulty)}.");
|
||||||
|
|
||||||
|
// check if a set already exists with the same online id, delete if it does.
|
||||||
|
if (beatmapSet.OnlineBeatmapSetID != null)
|
||||||
|
{
|
||||||
|
var existingOnlineId = beatmaps.ConsumableItems.FirstOrDefault(b => b.OnlineBeatmapSetID == beatmapSet.OnlineBeatmapSetID);
|
||||||
|
|
||||||
|
if (existingOnlineId != null)
|
||||||
|
{
|
||||||
|
Delete(existingOnlineId);
|
||||||
|
|
||||||
|
// in order to avoid a unique key constraint, immediately remove the online ID from the previous set.
|
||||||
|
existingOnlineId.OnlineBeatmapSetID = null;
|
||||||
|
foreach (var b in existingOnlineId.Beatmaps)
|
||||||
|
b.OnlineBeatmapID = null;
|
||||||
|
|
||||||
|
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineBeatmapSetID ({beatmapSet.OnlineBeatmapSetID}). It has been deleted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateOnlineIds(BeatmapSetInfo beatmapSet)
|
||||||
|
{
|
||||||
|
var beatmapIds = beatmapSet.Beatmaps.Where(b => b.OnlineBeatmapID.HasValue).Select(b => b.OnlineBeatmapID).ToList();
|
||||||
|
|
||||||
|
// ensure all IDs are unique
|
||||||
|
if (beatmapIds.GroupBy(b => b).Any(g => g.Count() > 1))
|
||||||
|
{
|
||||||
|
LogForModel(beatmapSet, "Found non-unique IDs, resetting...");
|
||||||
|
resetIds();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find any existing beatmaps in the database that have matching online ids
|
||||||
|
var existingBeatmaps = QueryBeatmaps(b => beatmapIds.Contains(b.OnlineBeatmapID)).ToList();
|
||||||
|
|
||||||
|
if (existingBeatmaps.Count > 0)
|
||||||
|
{
|
||||||
|
// reset the import ids (to force a re-fetch) *unless* they match the candidate CheckForExisting set.
|
||||||
|
// we can ignore the case where the new ids are contained by the CheckForExisting set as it will either be used (import skipped) or deleted.
|
||||||
|
var existing = CheckForExisting(beatmapSet);
|
||||||
|
|
||||||
|
if (existing == null || existingBeatmaps.Any(b => !existing.Beatmaps.Contains(b)))
|
||||||
|
{
|
||||||
|
LogForModel(beatmapSet, "Found existing import with IDs already, resetting...");
|
||||||
|
resetIds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete a beatmap difficulty.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
|
||||||
|
public void Hide(BeatmapInfo beatmapInfo) => beatmaps.Hide(beatmapInfo);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restore a beatmap difficulty.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
|
||||||
|
public void Restore(BeatmapInfo beatmapInfo) => beatmaps.Restore(beatmapInfo);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapInfo">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
|
||||||
|
/// <param name="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
|
||||||
|
/// <param name="beatmapSkin">The beatmap <see cref="ISkin"/> content to write, null if to be omitted.</param>
|
||||||
|
public virtual void Save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
||||||
|
{
|
||||||
|
var setInfo = beatmapInfo.BeatmapSet;
|
||||||
|
|
||||||
|
using (var stream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var sw = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||||
|
new LegacyBeatmapEncoder(beatmapContent, beatmapSkin).Encode(sw);
|
||||||
|
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
using (ContextFactory.GetForWrite())
|
||||||
|
{
|
||||||
|
beatmapInfo = setInfo.Beatmaps.Single(b => b.ID == beatmapInfo.ID);
|
||||||
|
var metadata = beatmapInfo.Metadata ?? setInfo.Metadata;
|
||||||
|
|
||||||
|
// grab the original file (or create a new one if not found).
|
||||||
|
var fileInfo = setInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, beatmapInfo.Path, StringComparison.OrdinalIgnoreCase)) ?? new BeatmapSetFileInfo();
|
||||||
|
|
||||||
|
// metadata may have changed; update the path with the standard format.
|
||||||
|
beatmapInfo.Path = $"{metadata.Artist} - {metadata.Title} ({metadata.Author}) [{beatmapInfo.Version}].osu";
|
||||||
|
beatmapInfo.MD5Hash = stream.ComputeMD5Hash();
|
||||||
|
|
||||||
|
// update existing or populate new file's filename.
|
||||||
|
fileInfo.Filename = beatmapInfo.Path;
|
||||||
|
|
||||||
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
ReplaceFile(setInfo, fileInfo, stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkingBeatmapCache?.Invalidate(beatmapInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query.</param>
|
||||||
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
|
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
||||||
|
|
||||||
|
protected override bool CanSkipImport(BeatmapSetInfo existing, BeatmapSetInfo import)
|
||||||
|
{
|
||||||
|
if (!base.CanSkipImport(existing, import))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return existing.Beatmaps.Any(b => b.OnlineBeatmapID != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool CanReuseExisting(BeatmapSetInfo existing, BeatmapSetInfo import)
|
||||||
|
{
|
||||||
|
if (!base.CanReuseExisting(existing, import))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var existingIds = existing.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
||||||
|
var importIds = import.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
||||||
|
|
||||||
|
// force re-import if we are not in a sane state.
|
||||||
|
return existing.OnlineBeatmapSetID == import.OnlineBeatmapSetID && existingIds.SequenceEqual(importIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
|
public List<BeatmapSetInfo> GetAllUsableBeatmapSets(IncludedDetails includes = IncludedDetails.All, bool includeProtected = false) =>
|
||||||
|
GetAllUsableBeatmapSetsEnumerable(includes, includeProtected).ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s. Note that files are not populated.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||||
|
/// <param name="includeProtected">Whether to include protected (system) beatmaps. These should not be included for gameplay playable use cases.</param>
|
||||||
|
/// <returns>A list of available <see cref="BeatmapSetInfo"/>.</returns>
|
||||||
|
public IEnumerable<BeatmapSetInfo> GetAllUsableBeatmapSetsEnumerable(IncludedDetails includes, bool includeProtected = false)
|
||||||
|
{
|
||||||
|
IQueryable<BeatmapSetInfo> queryable;
|
||||||
|
|
||||||
|
switch (includes)
|
||||||
|
{
|
||||||
|
case IncludedDetails.Minimal:
|
||||||
|
queryable = beatmaps.BeatmapSetsOverview;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IncludedDetails.AllButRuleset:
|
||||||
|
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IncludedDetails.AllButFiles:
|
||||||
|
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
queryable = beatmaps.ConsumableItems;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsEnumerable used here to avoid applying the WHERE in sql. When done so, ef core 2.x uses an incorrect ORDER BY
|
||||||
|
// clause which causes queries to take 5-10x longer.
|
||||||
|
// TODO: remove if upgrading to EF core 3.x.
|
||||||
|
return queryable.AsEnumerable().Where(s => !s.DeletePending && (includeProtected || !s.Protected));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query.</param>
|
||||||
|
/// <param name="includes">The level of detail to include in the returned objects.</param>
|
||||||
|
/// <returns>Results from the provided query.</returns>
|
||||||
|
public IEnumerable<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query, IncludedDetails includes = IncludedDetails.All)
|
||||||
|
{
|
||||||
|
IQueryable<BeatmapSetInfo> queryable;
|
||||||
|
|
||||||
|
switch (includes)
|
||||||
|
{
|
||||||
|
case IncludedDetails.Minimal:
|
||||||
|
queryable = beatmaps.BeatmapSetsOverview;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IncludedDetails.AllButRuleset:
|
||||||
|
queryable = beatmaps.BeatmapSetsWithoutRuleset;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IncludedDetails.AllButFiles:
|
||||||
|
queryable = beatmaps.BeatmapSetsWithoutFiles;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
queryable = beatmaps.ConsumableItems;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryable.AsNoTracking().Where(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query.</param>
|
||||||
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
|
public BeatmapInfo QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().FirstOrDefault(query);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a lookup query on available <see cref="BeatmapInfo"/>s.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query.</param>
|
||||||
|
/// <returns>Results from the provided query.</returns>
|
||||||
|
public IQueryable<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query) => beatmaps.Beatmaps.AsNoTracking().Where(query);
|
||||||
|
|
||||||
|
public override string HumanisedModelName => "beatmap";
|
||||||
|
|
||||||
|
protected override bool CheckLocalAvailability(BeatmapSetInfo model, IQueryable<BeatmapSetInfo> items)
|
||||||
|
=> base.CheckLocalAvailability(model, items)
|
||||||
|
|| (model.OnlineBeatmapSetID != null && items.Any(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID));
|
||||||
|
|
||||||
|
protected override BeatmapSetInfo CreateModel(ArchiveReader reader)
|
||||||
|
{
|
||||||
|
// let's make sure there are actually .osu files to import.
|
||||||
|
string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(mapName))
|
||||||
|
{
|
||||||
|
Logger.Log($"No beatmap files found in the beatmap archive ({reader.Name}).", LoggingTarget.Database);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Beatmap beatmap;
|
||||||
|
using (var stream = new LineBufferedReader(reader.GetStream(mapName)))
|
||||||
|
beatmap = Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
|
||||||
|
|
||||||
|
return new BeatmapSetInfo
|
||||||
|
{
|
||||||
|
OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID,
|
||||||
|
Beatmaps = new List<BeatmapInfo>(),
|
||||||
|
Metadata = beatmap.Metadata,
|
||||||
|
DateAdded = DateTimeOffset.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create all required <see cref="BeatmapInfo"/>s for the provided archive.
|
||||||
|
/// </summary>
|
||||||
|
private List<BeatmapInfo> createBeatmapDifficulties(List<BeatmapSetFileInfo> files)
|
||||||
|
{
|
||||||
|
var beatmapInfos = new List<BeatmapInfo>();
|
||||||
|
|
||||||
|
foreach (var file in files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
using (var raw = Files.Store.GetStream(file.FileInfo.StoragePath))
|
||||||
|
using (var ms = new MemoryStream()) // we need a memory stream so we can seek
|
||||||
|
using (var sr = new LineBufferedReader(ms))
|
||||||
|
{
|
||||||
|
raw.CopyTo(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
|
||||||
|
var decoder = Decoder.GetDecoder<Beatmap>(sr);
|
||||||
|
IBeatmap beatmap = decoder.Decode(sr);
|
||||||
|
|
||||||
|
string hash = ms.ComputeSHA2Hash();
|
||||||
|
|
||||||
|
if (beatmapInfos.Any(b => b.Hash == hash))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
beatmap.BeatmapInfo.Path = file.Filename;
|
||||||
|
beatmap.BeatmapInfo.Hash = hash;
|
||||||
|
beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();
|
||||||
|
|
||||||
|
var ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
|
||||||
|
beatmap.BeatmapInfo.Ruleset = ruleset;
|
||||||
|
|
||||||
|
// TODO: this should be done in a better place once we actually need to dynamically update it.
|
||||||
|
beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0;
|
||||||
|
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
||||||
|
beatmap.BeatmapInfo.BPM = 60000 / beatmap.GetMostCommonBeatLength();
|
||||||
|
|
||||||
|
beatmapInfos.Add(beatmap.BeatmapInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return beatmapInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateLength(IBeatmap b)
|
||||||
|
{
|
||||||
|
if (!b.HitObjects.Any())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var lastObject = b.HitObjects.Last();
|
||||||
|
|
||||||
|
//TODO: this isn't always correct (consider mania where a non-last object may last for longer than the last in the list).
|
||||||
|
double endTime = lastObject.GetEndTime();
|
||||||
|
double startTime = b.HitObjects.First().StartTime;
|
||||||
|
|
||||||
|
return endTime - startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
||||||
|
/// </summary>
|
||||||
|
private class DummyConversionBeatmap : WorkingBeatmap
|
||||||
|
{
|
||||||
|
private readonly IBeatmap beatmap;
|
||||||
|
|
||||||
|
public DummyConversionBeatmap(IBeatmap beatmap)
|
||||||
|
: base(beatmap.BeatmapInfo, null)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IBeatmap GetBeatmap() => beatmap;
|
||||||
|
protected override Texture GetBackground() => null;
|
||||||
|
protected override Track GetBeatmapTrack() => null;
|
||||||
|
protected internal override ISkin GetSkin() => null;
|
||||||
|
public override Stream GetStream(string storagePath) => null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The level of detail to include in database results.
|
||||||
|
/// </summary>
|
||||||
|
public enum IncludedDetails
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Only include beatmap difficulties and set level metadata.
|
||||||
|
/// </summary>
|
||||||
|
Minimal,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include all difficulties, rulesets, difficulty metadata but no files.
|
||||||
|
/// </summary>
|
||||||
|
AllButFiles,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include everything except ruleset. Used for cases where we aren't sure the ruleset is present but still want to consume the beatmap.
|
||||||
|
/// </summary>
|
||||||
|
AllButRuleset,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Include everything.
|
||||||
|
/// </summary>
|
||||||
|
All
|
||||||
|
}
|
||||||
|
}
|
222
osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs
Normal file
222
osu.Game/Beatmaps/BeatmapOnlineLookupQueue.cs
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
// 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.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using osu.Framework.Development;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Threading;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using SharpCompress.Compressors;
|
||||||
|
using SharpCompress.Compressors.BZip2;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A component which handles population of online IDs for beatmaps using a two part lookup procedure.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// On creating the component, a copy of a database containing metadata for a large subset of beatmaps (stored to <see cref="cache_database_name"/>) will be downloaded if not already present locally.
|
||||||
|
/// This will always be checked before doing a second online query to get required metadata.
|
||||||
|
/// </remarks>
|
||||||
|
[ExcludeFromDynamicCompile]
|
||||||
|
public class BeatmapOnlineLookupQueue : IDisposable
|
||||||
|
{
|
||||||
|
private readonly IAPIProvider api;
|
||||||
|
private readonly Storage storage;
|
||||||
|
|
||||||
|
private const int update_queue_request_concurrency = 4;
|
||||||
|
|
||||||
|
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(update_queue_request_concurrency, nameof(BeatmapOnlineLookupQueue));
|
||||||
|
|
||||||
|
private FileWebRequest cacheDownloadRequest;
|
||||||
|
|
||||||
|
private const string cache_database_name = "online.db";
|
||||||
|
|
||||||
|
public BeatmapOnlineLookupQueue(IAPIProvider api, Storage storage)
|
||||||
|
{
|
||||||
|
this.api = api;
|
||||||
|
this.storage = storage;
|
||||||
|
|
||||||
|
// avoid downloading / using cache for unit tests.
|
||||||
|
if (!DebugUtils.IsNUnitRunning && !storage.Exists(cache_database_name))
|
||||||
|
prepareLocalCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task UpdateAsync(BeatmapSetInfo beatmapSet, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.WhenAll(beatmapSet.Beatmaps.Select(b => UpdateAsync(beatmapSet, b, cancellationToken)).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: expose this when we need to do individual difficulty lookups.
|
||||||
|
protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
|
||||||
|
=> Task.Factory.StartNew(() => lookup(beatmapSet, beatmapInfo), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||||
|
|
||||||
|
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
if (checkLocalCache(set, beatmapInfo))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (api?.State.Value != APIState.Online)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var req = new GetBeatmapRequest(beatmapInfo);
|
||||||
|
|
||||||
|
req.Failure += fail;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// intentionally blocking to limit web request concurrency
|
||||||
|
api.Perform(req);
|
||||||
|
|
||||||
|
var res = req.Result;
|
||||||
|
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
beatmapInfo.Status = res.Status;
|
||||||
|
beatmapInfo.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||||
|
beatmapInfo.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||||
|
beatmapInfo.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||||
|
|
||||||
|
if (beatmapInfo.Metadata != null)
|
||||||
|
beatmapInfo.Metadata.AuthorID = res.AuthorID;
|
||||||
|
|
||||||
|
if (beatmapInfo.BeatmapSet.Metadata != null)
|
||||||
|
beatmapInfo.BeatmapSet.Metadata.AuthorID = res.AuthorID;
|
||||||
|
|
||||||
|
logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fail(Exception e)
|
||||||
|
{
|
||||||
|
beatmapInfo.OnlineBeatmapID = null;
|
||||||
|
logForModel(set, $"Online retrieval failed for {beatmapInfo} ({e.Message})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareLocalCache()
|
||||||
|
{
|
||||||
|
string cacheFilePath = storage.GetFullPath(cache_database_name);
|
||||||
|
string compressedCacheFilePath = $"{cacheFilePath}.bz2";
|
||||||
|
|
||||||
|
cacheDownloadRequest = new FileWebRequest(compressedCacheFilePath, $"https://assets.ppy.sh/client-resources/{cache_database_name}.bz2?{DateTimeOffset.UtcNow:yyyyMMdd}");
|
||||||
|
|
||||||
|
cacheDownloadRequest.Failed += ex =>
|
||||||
|
{
|
||||||
|
File.Delete(compressedCacheFilePath);
|
||||||
|
File.Delete(cacheFilePath);
|
||||||
|
|
||||||
|
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache download failed: {ex}", LoggingTarget.Database);
|
||||||
|
};
|
||||||
|
|
||||||
|
cacheDownloadRequest.Finished += () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = File.OpenRead(cacheDownloadRequest.Filename))
|
||||||
|
using (var outStream = File.OpenWrite(cacheFilePath))
|
||||||
|
using (var bz2 = new BZip2Stream(stream, CompressionMode.Decompress, false))
|
||||||
|
bz2.CopyTo(outStream);
|
||||||
|
|
||||||
|
// set to null on completion to allow lookups to begin using the new source
|
||||||
|
cacheDownloadRequest = null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Log($"{nameof(BeatmapOnlineLookupQueue)}'s online cache extraction failed: {ex}", LoggingTarget.Database);
|
||||||
|
File.Delete(cacheFilePath);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
File.Delete(compressedCacheFilePath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
cacheDownloadRequest.PerformAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool checkLocalCache(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
// download is in progress (or was, and failed).
|
||||||
|
if (cacheDownloadRequest != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// database is unavailable.
|
||||||
|
if (!storage.Exists(cache_database_name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(beatmapInfo.MD5Hash)
|
||||||
|
&& string.IsNullOrEmpty(beatmapInfo.Path)
|
||||||
|
&& beatmapInfo.OnlineBeatmapID == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var db = new SqliteConnection(DatabaseContextFactory.CreateDatabaseConnectionString("online.db", storage)))
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
|
||||||
|
using (var cmd = db.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved, user_id FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineBeatmapID OR filename = @Path";
|
||||||
|
|
||||||
|
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmapInfo.MD5Hash));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter("@OnlineBeatmapID", beatmapInfo.OnlineBeatmapID ?? (object)DBNull.Value));
|
||||||
|
cmd.Parameters.Add(new SqliteParameter("@Path", beatmapInfo.Path));
|
||||||
|
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
var status = (BeatmapSetOnlineStatus)reader.GetByte(2);
|
||||||
|
|
||||||
|
beatmapInfo.Status = status;
|
||||||
|
beatmapInfo.BeatmapSet.Status = status;
|
||||||
|
beatmapInfo.BeatmapSet.OnlineBeatmapSetID = reader.GetInt32(0);
|
||||||
|
beatmapInfo.OnlineBeatmapID = reader.GetInt32(1);
|
||||||
|
|
||||||
|
if (beatmapInfo.Metadata != null)
|
||||||
|
beatmapInfo.Metadata.AuthorID = reader.GetInt32(3);
|
||||||
|
|
||||||
|
if (beatmapInfo.BeatmapSet.Metadata != null)
|
||||||
|
beatmapInfo.BeatmapSet.Metadata.AuthorID = reader.GetInt32(3);
|
||||||
|
|
||||||
|
logForModel(set, $"Cached local retrieval for {beatmapInfo}.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logForModel(set, $"Cached local retrieval for {beatmapInfo} failed with {ex}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logForModel(BeatmapSetInfo set, string message) =>
|
||||||
|
ArchiveModelManager<BeatmapSetInfo, BeatmapSetFileInfo>.LogForModel(set, $"[{nameof(BeatmapOnlineLookupQueue)}] {message}");
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
cacheDownloadRequest?.Dispose();
|
||||||
|
updateScheduler?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -25,40 +25,40 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hide a <see cref="BeatmapInfo"/> in the database.
|
/// Hide a <see cref="BeatmapInfo"/> in the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to hide.</param>
|
/// <param name="beatmapInfo">The beatmap to hide.</param>
|
||||||
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
||||||
public bool Hide(BeatmapInfo beatmap)
|
public bool Hide(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
using (ContextFactory.GetForWrite())
|
using (ContextFactory.GetForWrite())
|
||||||
{
|
{
|
||||||
Refresh(ref beatmap, Beatmaps);
|
Refresh(ref beatmapInfo, Beatmaps);
|
||||||
|
|
||||||
if (beatmap.Hidden) return false;
|
if (beatmapInfo.Hidden) return false;
|
||||||
|
|
||||||
beatmap.Hidden = true;
|
beatmapInfo.Hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeatmapHidden?.Invoke(beatmap);
|
BeatmapHidden?.Invoke(beatmapInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restore a previously hidden <see cref="BeatmapInfo"/>.
|
/// Restore a previously hidden <see cref="BeatmapInfo"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to restore.</param>
|
/// <param name="beatmapInfo">The beatmap to restore.</param>
|
||||||
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
||||||
public bool Restore(BeatmapInfo beatmap)
|
public bool Restore(BeatmapInfo beatmapInfo)
|
||||||
{
|
{
|
||||||
using (ContextFactory.GetForWrite())
|
using (ContextFactory.GetForWrite())
|
||||||
{
|
{
|
||||||
Refresh(ref beatmap, Beatmaps);
|
Refresh(ref beatmapInfo, Beatmaps);
|
||||||
|
|
||||||
if (!beatmap.Hidden) return false;
|
if (!beatmapInfo.Hidden) return false;
|
||||||
|
|
||||||
beatmap.Hidden = false;
|
beatmapInfo.Hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeatmapRestored?.Invoke(beatmap);
|
BeatmapRestored?.Invoke(beatmapInfo);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ namespace osu.Game.Beatmaps
|
|||||||
if (!recommendedDifficultyMapping.TryGetValue(r, out var recommendation))
|
if (!recommendedDifficultyMapping.TryGetValue(r, out var recommendation))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BeatmapInfo beatmap = beatmaps.Where(b => b.Ruleset.Equals(r)).OrderBy(b =>
|
BeatmapInfo beatmapInfo = beatmaps.Where(b => b.Ruleset.Equals(r)).OrderBy(b =>
|
||||||
{
|
{
|
||||||
var difference = b.StarDifficulty - recommendation;
|
var difference = b.StarDifficulty - recommendation;
|
||||||
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
|
|
||||||
if (beatmap != null)
|
if (beatmapInfo != null)
|
||||||
return beatmap;
|
return beatmapInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
}
|
}
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
private readonly BeatmapInfo beatmap;
|
private readonly BeatmapInfo beatmapInfo;
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private readonly RulesetInfo ruleset;
|
private readonly RulesetInfo ruleset;
|
||||||
@ -56,26 +56,26 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DifficultyIcon"/> with a given <see cref="RulesetInfo"/> and <see cref="Mod"/> combination.
|
/// Creates a new <see cref="DifficultyIcon"/> with a given <see cref="RulesetInfo"/> and <see cref="Mod"/> combination.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to show the difficulty of.</param>
|
/// <param name="beatmapInfo">The beatmap to show the difficulty of.</param>
|
||||||
/// <param name="ruleset">The ruleset to show the difficulty with.</param>
|
/// <param name="ruleset">The ruleset to show the difficulty with.</param>
|
||||||
/// <param name="mods">The mods to show the difficulty with.</param>
|
/// <param name="mods">The mods to show the difficulty with.</param>
|
||||||
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
||||||
public DifficultyIcon([NotNull] BeatmapInfo beatmap, [CanBeNull] RulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true)
|
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true)
|
||||||
: this(beatmap, shouldShowTooltip)
|
: this(beatmapInfo, shouldShowTooltip)
|
||||||
{
|
{
|
||||||
this.ruleset = ruleset ?? beatmap.Ruleset;
|
this.ruleset = ruleset ?? beatmapInfo.Ruleset;
|
||||||
this.mods = mods ?? Array.Empty<Mod>();
|
this.mods = mods ?? Array.Empty<Mod>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DifficultyIcon"/> that follows the currently-selected ruleset and mods.
|
/// Creates a new <see cref="DifficultyIcon"/> that follows the currently-selected ruleset and mods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to show the difficulty of.</param>
|
/// <param name="beatmapInfo">The beatmap to show the difficulty of.</param>
|
||||||
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
||||||
/// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param>
|
/// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param>
|
||||||
public DifficultyIcon([NotNull] BeatmapInfo beatmap, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
|
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap ?? throw new ArgumentNullException(nameof(beatmap));
|
this.beatmapInfo = beatmapInfo ?? throw new ArgumentNullException(nameof(beatmapInfo));
|
||||||
this.shouldShowTooltip = shouldShowTooltip;
|
this.shouldShowTooltip = shouldShowTooltip;
|
||||||
this.performBackgroundDifficultyLookup = performBackgroundDifficultyLookup;
|
this.performBackgroundDifficultyLookup = performBackgroundDifficultyLookup;
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
Child = background = new Box
|
Child = background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = colours.ForStarDifficulty(beatmap.StarDifficulty) // Default value that will be re-populated once difficulty calculation completes
|
Colour = colours.ForStarDifficulty(beatmapInfo.StarDifficulty) // Default value that will be re-populated once difficulty calculation completes
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new ConstrainedIconContainer
|
new ConstrainedIconContainer
|
||||||
@ -114,27 +114,27 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
||||||
Icon = (ruleset ?? beatmap.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
|
Icon = (ruleset ?? beatmapInfo.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (performBackgroundDifficultyLookup)
|
if (performBackgroundDifficultyLookup)
|
||||||
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmap, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
|
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmapInfo, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
|
||||||
else
|
else
|
||||||
difficultyBindable.Value = new StarDifficulty(beatmap.StarDifficulty, 0);
|
difficultyBindable.Value = new StarDifficulty(beatmapInfo.StarDifficulty, 0);
|
||||||
|
|
||||||
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars));
|
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars));
|
||||||
}
|
}
|
||||||
|
|
||||||
ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.GetCustomTooltip() => new DifficultyIconTooltip();
|
ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.GetCustomTooltip() => new DifficultyIconTooltip();
|
||||||
|
|
||||||
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmap, difficultyBindable) : null;
|
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmapInfo, difficultyBindable) : null;
|
||||||
|
|
||||||
private class DifficultyRetriever : Component
|
private class DifficultyRetriever : Component
|
||||||
{
|
{
|
||||||
public readonly Bindable<StarDifficulty> StarDifficulty = new Bindable<StarDifficulty>();
|
public readonly Bindable<StarDifficulty> StarDifficulty = new Bindable<StarDifficulty>();
|
||||||
|
|
||||||
private readonly BeatmapInfo beatmap;
|
private readonly BeatmapInfo beatmapInfo;
|
||||||
private readonly RulesetInfo ruleset;
|
private readonly RulesetInfo ruleset;
|
||||||
private readonly IReadOnlyList<Mod> mods;
|
private readonly IReadOnlyList<Mod> mods;
|
||||||
|
|
||||||
@ -143,9 +143,9 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapDifficultyCache difficultyCache { get; set; }
|
private BeatmapDifficultyCache difficultyCache { get; set; }
|
||||||
|
|
||||||
public DifficultyRetriever(BeatmapInfo beatmap, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
|
public DifficultyRetriever(BeatmapInfo beatmapInfo, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
this.beatmapInfo = beatmapInfo;
|
||||||
this.ruleset = ruleset;
|
this.ruleset = ruleset;
|
||||||
this.mods = mods;
|
this.mods = mods;
|
||||||
}
|
}
|
||||||
@ -157,8 +157,8 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
{
|
{
|
||||||
difficultyCancellation = new CancellationTokenSource();
|
difficultyCancellation = new CancellationTokenSource();
|
||||||
localStarDifficulty = ruleset != null
|
localStarDifficulty = ruleset != null
|
||||||
? difficultyCache.GetBindableDifficulty(beatmap, ruleset, mods, difficultyCancellation.Token)
|
? difficultyCache.GetBindableDifficulty(beatmapInfo, ruleset, mods, difficultyCancellation.Token)
|
||||||
: difficultyCache.GetBindableDifficulty(beatmap, difficultyCancellation.Token);
|
: difficultyCache.GetBindableDifficulty(beatmapInfo, difficultyCancellation.Token);
|
||||||
localStarDifficulty.BindValueChanged(d =>
|
localStarDifficulty.BindValueChanged(d =>
|
||||||
{
|
{
|
||||||
if (d.NewValue is StarDifficulty diff)
|
if (d.NewValue is StarDifficulty diff)
|
||||||
|
@ -89,7 +89,7 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
|
|
||||||
public void SetContent(DifficultyIconTooltipContent content)
|
public void SetContent(DifficultyIconTooltipContent content)
|
||||||
{
|
{
|
||||||
difficultyName.Text = content.Beatmap.Version;
|
difficultyName.Text = content.BeatmapInfo.Version;
|
||||||
|
|
||||||
starDifficulty.UnbindAll();
|
starDifficulty.UnbindAll();
|
||||||
starDifficulty.BindTo(content.Difficulty);
|
starDifficulty.BindTo(content.Difficulty);
|
||||||
@ -109,12 +109,12 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
|
|
||||||
internal class DifficultyIconTooltipContent
|
internal class DifficultyIconTooltipContent
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo BeatmapInfo;
|
||||||
public readonly IBindable<StarDifficulty> Difficulty;
|
public readonly IBindable<StarDifficulty> Difficulty;
|
||||||
|
|
||||||
public DifficultyIconTooltipContent(BeatmapInfo beatmap, IBindable<StarDifficulty> difficulty)
|
public DifficultyIconTooltipContent(BeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
BeatmapInfo = beatmapInfo;
|
||||||
Difficulty = difficulty;
|
Difficulty = difficulty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,8 +176,8 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
case "L":
|
case "L":
|
||||||
{
|
{
|
||||||
var startTime = Parsing.ParseDouble(split[1]);
|
var startTime = Parsing.ParseDouble(split[1]);
|
||||||
var loopCount = Parsing.ParseInt(split[2]);
|
var repeatCount = Parsing.ParseInt(split[2]);
|
||||||
timelineGroup = storyboardSprite?.AddLoop(startTime, loopCount);
|
timelineGroup = storyboardSprite?.AddLoop(startTime, Math.Max(0, repeatCount - 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
osu.Game/Beatmaps/IWorkingBeatmapCache.cs
Normal file
15
osu.Game/Beatmaps/IWorkingBeatmapCache.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
public interface IWorkingBeatmapCache
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapInfo">The beatmap to lookup.</param>
|
||||||
|
/// <returns>A <see cref="WorkingBeatmap"/> instance correlating to the provided <see cref="BeatmapInfo"/>.</returns>
|
||||||
|
WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,18 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Framework.Lists;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Statistics;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
@ -16,8 +21,96 @@ using osu.Game.Storyboards;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
public partial class BeatmapManager
|
public class WorkingBeatmapCache : IBeatmapResourceProvider, IWorkingBeatmapCache
|
||||||
{
|
{
|
||||||
|
private readonly WeakList<BeatmapManagerWorkingBeatmap> workingCache = new WeakList<BeatmapManagerWorkingBeatmap>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
|
||||||
|
/// </summary>
|
||||||
|
public readonly WorkingBeatmap DefaultBeatmap;
|
||||||
|
|
||||||
|
public BeatmapModelManager BeatmapManager { private get; set; }
|
||||||
|
|
||||||
|
private readonly AudioManager audioManager;
|
||||||
|
private readonly IResourceStore<byte[]> resources;
|
||||||
|
private readonly LargeTextureStore largeTextureStore;
|
||||||
|
private readonly ITrackStore trackStore;
|
||||||
|
private readonly IResourceStore<byte[]> files;
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
private readonly GameHost host;
|
||||||
|
|
||||||
|
public WorkingBeatmapCache([NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, IResourceStore<byte[]> files, WorkingBeatmap defaultBeatmap = null, GameHost host = null)
|
||||||
|
{
|
||||||
|
DefaultBeatmap = defaultBeatmap;
|
||||||
|
|
||||||
|
this.audioManager = audioManager;
|
||||||
|
this.resources = resources;
|
||||||
|
this.host = host;
|
||||||
|
this.files = files;
|
||||||
|
largeTextureStore = new LargeTextureStore(host?.CreateTextureLoaderStore(files));
|
||||||
|
trackStore = audioManager.GetTrackStore(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Invalidate(BeatmapSetInfo info)
|
||||||
|
{
|
||||||
|
if (info.Beatmaps == null) return;
|
||||||
|
|
||||||
|
foreach (var b in info.Beatmaps)
|
||||||
|
Invalidate(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Invalidate(BeatmapInfo info)
|
||||||
|
{
|
||||||
|
lock (workingCache)
|
||||||
|
{
|
||||||
|
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == info.ID);
|
||||||
|
if (working != null)
|
||||||
|
workingCache.Remove(working);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
|
||||||
|
{
|
||||||
|
// if there are no files, presume the full beatmap info has not yet been fetched from the database.
|
||||||
|
if (beatmapInfo?.BeatmapSet?.Files.Count == 0)
|
||||||
|
{
|
||||||
|
int lookupId = beatmapInfo.ID;
|
||||||
|
beatmapInfo = BeatmapManager.QueryBeatmap(b => b.ID == lookupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (beatmapInfo?.BeatmapSet == null)
|
||||||
|
return DefaultBeatmap;
|
||||||
|
|
||||||
|
lock (workingCache)
|
||||||
|
{
|
||||||
|
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID);
|
||||||
|
if (working != null)
|
||||||
|
return working;
|
||||||
|
|
||||||
|
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
|
||||||
|
|
||||||
|
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(beatmapInfo, this));
|
||||||
|
|
||||||
|
// best effort; may be higher than expected.
|
||||||
|
GlobalStatistics.Get<int>(nameof(Beatmaps), $"Cached {nameof(WorkingBeatmap)}s").Value = workingCache.Count();
|
||||||
|
|
||||||
|
return working;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IResourceStorageProvider
|
||||||
|
|
||||||
|
TextureStore IBeatmapResourceProvider.LargeTextureStore => largeTextureStore;
|
||||||
|
ITrackStore IBeatmapResourceProvider.Tracks => trackStore;
|
||||||
|
AudioManager IStorageResourceProvider.AudioManager => audioManager;
|
||||||
|
IResourceStore<byte[]> IStorageResourceProvider.Files => files;
|
||||||
|
IResourceStore<byte[]> IStorageResourceProvider.Resources => resources;
|
||||||
|
IResourceStore<TextureUpload> IStorageResourceProvider.CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => host?.CreateTextureLoaderStore(underlyingStore);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
private class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
private class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
||||||
{
|
{
|
@ -14,6 +14,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Database;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.IO.Legacy;
|
using osu.Game.IO.Legacy;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
@ -27,7 +28,7 @@ namespace osu.Game.Collections
|
|||||||
/// This is currently reading and writing from the osu-stable file format. This is a temporary arrangement until we refactor the
|
/// This is currently reading and writing from the osu-stable file format. This is a temporary arrangement until we refactor the
|
||||||
/// database backing the game. Going forward writing should be done in a similar way to other model stores.
|
/// database backing the game. Going forward writing should be done in a similar way to other model stores.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class CollectionManager : Component
|
public class CollectionManager : Component, IPostNotifications
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Database version in stable-compatible YYYYMMDD format.
|
/// Database version in stable-compatible YYYYMMDD format.
|
||||||
@ -106,9 +107,6 @@ namespace osu.Game.Collections
|
|||||||
backgroundSave();
|
backgroundSave();
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set an endpoint for notifications to be posted to.
|
|
||||||
/// </summary>
|
|
||||||
public Action<Notification> PostNotification { protected get; set; }
|
public Action<Notification> PostNotification { protected get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||||
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>
|
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>, IModelFileManager<TModel, TFileModel>, IPostImports<TModel>
|
||||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
||||||
where TFileModel : class, INamedFileInfo, new()
|
where TFileModel : class, INamedFileInfo, new()
|
||||||
{
|
{
|
||||||
@ -57,9 +57,6 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly ThreadedTaskScheduler import_scheduler_low_priority = new ThreadedTaskScheduler(import_queue_request_concurrency, nameof(ArchiveModelManager<TModel, TFileModel>));
|
private static readonly ThreadedTaskScheduler import_scheduler_low_priority = new ThreadedTaskScheduler(import_queue_request_concurrency, nameof(ArchiveModelManager<TModel, TFileModel>));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set an endpoint for notifications to be posted to.
|
|
||||||
/// </summary>
|
|
||||||
public Action<Notification> PostNotification { protected get; set; }
|
public Action<Notification> PostNotification { protected get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -135,13 +132,13 @@ namespace osu.Game.Database
|
|||||||
return Import(notification, tasks);
|
return Import(notification, tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<IEnumerable<TModel>> Import(ProgressNotification notification, params ImportTask[] tasks)
|
public async Task<IEnumerable<ILive<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks)
|
||||||
{
|
{
|
||||||
if (tasks.Length == 0)
|
if (tasks.Length == 0)
|
||||||
{
|
{
|
||||||
notification.CompletionText = $"No {HumanisedModelName}s were found to import!";
|
notification.CompletionText = $"No {HumanisedModelName}s were found to import!";
|
||||||
notification.State = ProgressNotificationState.Completed;
|
notification.State = ProgressNotificationState.Completed;
|
||||||
return Enumerable.Empty<TModel>();
|
return Enumerable.Empty<ILive<TModel>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Progress = 0;
|
notification.Progress = 0;
|
||||||
@ -149,7 +146,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
int current = 0;
|
int current = 0;
|
||||||
|
|
||||||
var imported = new List<TModel>();
|
var imported = new List<ILive<TModel>>();
|
||||||
|
|
||||||
bool isLowPriorityImport = tasks.Length > low_priority_import_batch_size;
|
bool isLowPriorityImport = tasks.Length > low_priority_import_batch_size;
|
||||||
|
|
||||||
@ -203,12 +200,12 @@ namespace osu.Game.Database
|
|||||||
? $"Imported {imported.First()}!"
|
? $"Imported {imported.First()}!"
|
||||||
: $"Imported {imported.Count} {HumanisedModelName}s!";
|
: $"Imported {imported.Count} {HumanisedModelName}s!";
|
||||||
|
|
||||||
if (imported.Count > 0 && PresentImport != null)
|
if (imported.Count > 0 && PostImport != null)
|
||||||
{
|
{
|
||||||
notification.CompletionText += " Click to view.";
|
notification.CompletionText += " Click to view.";
|
||||||
notification.CompletionClickAction = () =>
|
notification.CompletionClickAction = () =>
|
||||||
{
|
{
|
||||||
PresentImport?.Invoke(imported);
|
PostImport?.Invoke(imported);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -227,11 +224,11 @@ namespace osu.Game.Database
|
|||||||
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
/// <returns>The imported model, if successful.</returns>
|
/// <returns>The imported model, if successful.</returns>
|
||||||
internal async Task<TModel> Import(ImportTask task, bool lowPriority = false, CancellationToken cancellationToken = default)
|
public async Task<ILive<TModel>> Import(ImportTask task, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
TModel import;
|
ILive<TModel> import;
|
||||||
using (ArchiveReader reader = task.GetReader())
|
using (ArchiveReader reader = task.GetReader())
|
||||||
import = await Import(reader, lowPriority, cancellationToken).ConfigureAwait(false);
|
import = await Import(reader, lowPriority, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
@ -246,16 +243,13 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LogForModel(import, $@"Could not delete original file after import ({task})", e);
|
LogForModel(import?.Value, $@"Could not delete original file after import ({task})", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return import;
|
return import;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public Action<IEnumerable<ILive<TModel>>> PostImport { protected get; set; }
|
||||||
/// Fired when the user requests to view the resulting import.
|
|
||||||
/// </summary>
|
|
||||||
public Action<IEnumerable<TModel>> PresentImport;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Silently import an item from an <see cref="ArchiveReader"/>.
|
/// Silently import an item from an <see cref="ArchiveReader"/>.
|
||||||
@ -263,7 +257,7 @@ namespace osu.Game.Database
|
|||||||
/// <param name="archive">The archive to be imported.</param>
|
/// <param name="archive">The archive to be imported.</param>
|
||||||
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
public Task<TModel> Import(ArchiveReader archive, bool lowPriority = false, CancellationToken cancellationToken = default)
|
public Task<ILive<TModel>> Import(ArchiveReader archive, bool lowPriority = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
@ -274,7 +268,7 @@ namespace osu.Game.Database
|
|||||||
model = CreateModel(archive);
|
model = CreateModel(archive);
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
return Task.FromResult<TModel>(null);
|
return Task.FromResult<ILive<TModel>>(new EntityFrameworkLive<TModel>(null));
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException)
|
||||||
{
|
{
|
||||||
@ -349,7 +343,7 @@ namespace osu.Game.Database
|
|||||||
/// <param name="archive">An optional archive to use for model population.</param>
|
/// <param name="archive">An optional archive to use for model population.</param>
|
||||||
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
public virtual async Task<TModel> Import(TModel item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default) => await Task.Factory.StartNew(async () =>
|
public virtual async Task<ILive<TModel>> Import(TModel item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default) => await Task.Factory.StartNew(async () =>
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
@ -375,7 +369,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
LogForModel(item, @$"Found existing (optimised) {HumanisedModelName} for {item} (ID {existing.ID}) – skipping import.");
|
LogForModel(item, @$"Found existing (optimised) {HumanisedModelName} for {item} (ID {existing.ID}) – skipping import.");
|
||||||
Undelete(existing);
|
Undelete(existing);
|
||||||
return existing;
|
return existing.ToEntityFrameworkLive();
|
||||||
}
|
}
|
||||||
|
|
||||||
LogForModel(item, @"Found existing (optimised) but failed pre-check.");
|
LogForModel(item, @"Found existing (optimised) but failed pre-check.");
|
||||||
@ -421,7 +415,7 @@ namespace osu.Game.Database
|
|||||||
// existing item will be used; rollback new import and exit early.
|
// existing item will be used; rollback new import and exit early.
|
||||||
rollback();
|
rollback();
|
||||||
flushEvents(true);
|
flushEvents(true);
|
||||||
return existing;
|
return existing.ToEntityFrameworkLive();
|
||||||
}
|
}
|
||||||
|
|
||||||
LogForModel(item, @"Found existing but failed re-use check.");
|
LogForModel(item, @"Found existing but failed re-use check.");
|
||||||
@ -454,7 +448,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
flushEvents(true);
|
flushEvents(true);
|
||||||
return item;
|
return item.ToEntityFrameworkLive();
|
||||||
}, cancellationToken, TaskCreationOptions.HideScheduler, lowPriority ? import_scheduler_low_priority : import_scheduler).Unwrap().ConfigureAwait(false);
|
}, cancellationToken, TaskCreationOptions.HideScheduler, lowPriority ? import_scheduler_low_priority : import_scheduler).Unwrap().ConfigureAwait(false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -479,7 +473,7 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model">The item to export.</param>
|
/// <param name="model">The item to export.</param>
|
||||||
/// <param name="outputStream">The output stream to export to.</param>
|
/// <param name="outputStream">The output stream to export to.</param>
|
||||||
protected virtual void ExportModelTo(TModel model, Stream outputStream)
|
public virtual void ExportModelTo(TModel model, Stream outputStream)
|
||||||
{
|
{
|
||||||
using (var archive = ZipArchive.Create())
|
using (var archive = ZipArchive.Create())
|
||||||
{
|
{
|
||||||
@ -745,9 +739,6 @@ namespace osu.Game.Database
|
|||||||
/// <returns>Whether to perform deletion.</returns>
|
/// <returns>Whether to perform deletion.</returns>
|
||||||
protected virtual bool ShouldDeleteArchive(string path) => false;
|
protected virtual bool ShouldDeleteArchive(string path) => false;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
|
|
||||||
/// </summary>
|
|
||||||
public Task ImportFromStableAsync(StableStorage stableStorage)
|
public Task ImportFromStableAsync(StableStorage stableStorage)
|
||||||
{
|
{
|
||||||
var storage = PrepareStableStorage(stableStorage);
|
var storage = PrepareStableStorage(stableStorage);
|
||||||
@ -805,6 +796,17 @@ namespace osu.Game.Database
|
|||||||
/// <returns>An existing model which matches the criteria to skip importing, else null.</returns>
|
/// <returns>An existing model which matches the criteria to skip importing, else null.</returns>
|
||||||
protected TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
|
protected TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
|
||||||
|
|
||||||
|
public bool IsAvailableLocally(TModel model) => CheckLocalAvailability(model, ModelStore.ConsumableItems.Where(m => !m.DeletePending));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs implementation specific comparisons to determine whether a given model is present in the local store.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The <typeparamref name="TModel"/> whose existence needs to be checked.</param>
|
||||||
|
/// <param name="items">The usable items present in the store.</param>
|
||||||
|
/// <returns>Whether the <typeparamref name="TModel"/> exists.</returns>
|
||||||
|
protected virtual bool CheckLocalAvailability(TModel model, IQueryable<TModel> items)
|
||||||
|
=> model.ID > 0 && items.Any(i => i.ID == model.ID && i.Files.Any());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether import can be skipped after finding an existing import early in the process.
|
/// Whether import can be skipped after finding an existing import early in the process.
|
||||||
/// Only valid when <see cref="ComputeHash"/> is not overridden.
|
/// Only valid when <see cref="ComputeHash"/> is not overridden.
|
||||||
@ -841,7 +843,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>();
|
private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>();
|
||||||
|
|
||||||
protected virtual string HumanisedModelName => $"{typeof(TModel).Name.Replace(@"Info", "").ToLower()}";
|
public virtual string HumanisedModelName => $"{typeof(TModel).Name.Replace(@"Info", "").ToLower()}";
|
||||||
|
|
||||||
#region Event handling / delaying
|
#region Event handling / delaying
|
||||||
|
|
||||||
|
34
osu.Game/Database/EntityFrameworkLive.cs
Normal file
34
osu.Game/Database/EntityFrameworkLive.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public class EntityFrameworkLive<T> : ILive<T> where T : class
|
||||||
|
{
|
||||||
|
public EntityFrameworkLive(T item)
|
||||||
|
{
|
||||||
|
Value = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Guid ID => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public void PerformRead(Action<T> perform)
|
||||||
|
{
|
||||||
|
perform(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TReturn PerformRead<TReturn>(Func<T, TReturn> perform)
|
||||||
|
{
|
||||||
|
return perform(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PerformWrite(Action<T> perform)
|
||||||
|
{
|
||||||
|
perform(Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Value { get; }
|
||||||
|
}
|
||||||
|
}
|
14
osu.Game/Database/EntityFrameworkLiveExtensions.cs
Normal file
14
osu.Game/Database/EntityFrameworkLiveExtensions.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public static class EntityFrameworkLiveExtensions
|
||||||
|
{
|
||||||
|
public static ILive<T> ToEntityFrameworkLive<T>(this T item)
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
return new EntityFrameworkLive<T>(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
Guid ID { get; set; }
|
Guid ID { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
osu.Game/Database/ILive.cs
Normal file
42
osu.Game/Database/ILive.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper to provide access to database backed classes in a thread-safe manner.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The databased type.</typeparam>
|
||||||
|
public interface ILive<out T> where T : class // TODO: Add IHasGuidPrimaryKey once we don't need EF support any more.
|
||||||
|
{
|
||||||
|
Guid ID { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a read operation on this live object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="perform">The action to perform.</param>
|
||||||
|
void PerformRead(Action<T> perform);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a read operation on this live object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="perform">The action to perform.</param>
|
||||||
|
TReturn PerformRead<TReturn>(Func<T, TReturn> perform);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a write operation on this live object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="perform">The action to perform.</param>
|
||||||
|
void PerformWrite(Action<T> perform);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolve the value of this instance on the current thread's context.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// After resolving the data should not be passed between threads.
|
||||||
|
/// </remarks>
|
||||||
|
T Value { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace osu.Game.Database
|
|||||||
/// Represents a <see cref="IModelManager{TModel}"/> that can download new models from an external source.
|
/// Represents a <see cref="IModelManager{TModel}"/> that can download new models from an external source.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
public interface IModelDownloader<TModel> : IModelManager<TModel>
|
public interface IModelDownloader<TModel> : IPostNotifications
|
||||||
where TModel : class
|
where TModel : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -26,13 +26,6 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IBindable<WeakReference<ArchiveDownloadRequest<TModel>>> DownloadFailed { get; }
|
IBindable<WeakReference<ArchiveDownloadRequest<TModel>>> DownloadFailed { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks whether a given <typeparamref name="TModel"/> is already available in the local store.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">The <typeparamref name="TModel"/> whose existence needs to be checked.</param>
|
|
||||||
/// <returns>Whether the <typeparamref name="TModel"/> exists.</returns>
|
|
||||||
bool IsAvailableLocally(TModel model);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Begin a download for the requested <typeparamref name="TModel"/>.
|
/// Begin a download for the requested <typeparamref name="TModel"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
36
osu.Game/Database/IModelFileManager.cs
Normal file
36
osu.Game/Database/IModelFileManager.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// 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.IO;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public interface IModelFileManager<in TModel, in TFileModel>
|
||||||
|
where TModel : class
|
||||||
|
where TFileModel : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Replace an existing file with a new version.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to operate on.</param>
|
||||||
|
/// <param name="file">The existing file to be replaced.</param>
|
||||||
|
/// <param name="contents">The new file contents.</param>
|
||||||
|
/// <param name="filename">An optional filename for the new file. Will use the previous filename if not specified.</param>
|
||||||
|
void ReplaceFile(TModel model, TFileModel file, Stream contents, string filename = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an existing file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to operate on.</param>
|
||||||
|
/// <param name="file">The existing file to be deleted.</param>
|
||||||
|
void DeleteFile(TModel model, TFileModel file);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to operate on.</param>
|
||||||
|
/// <param name="contents">The new file contents.</param>
|
||||||
|
/// <param name="filename">The filename for the new file.</param>
|
||||||
|
void AddFile(TModel model, Stream contents, string filename);
|
||||||
|
}
|
||||||
|
}
|
65
osu.Game/Database/IModelImporter.cs
Normal file
65
osu.Game/Database/IModelImporter.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// 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.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Game.IO.Archives;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class which handles importing of asociated models to the game store.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
|
public interface IModelImporter<TModel> : IPostNotifications
|
||||||
|
where TModel : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Import one or more <typeparamref name="TModel"/> items from filesystem <paramref name="paths"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This will be treated as a low priority import if more than one path is specified; use <see cref="ArchiveModelManager{TModel,TFileModel}.Import(osu.Game.Database.ImportTask[])"/> to always import at standard priority.
|
||||||
|
/// This will post notifications tracking progress.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="paths">One or more archive locations on disk.</param>
|
||||||
|
Task Import(params string[] paths);
|
||||||
|
|
||||||
|
Task Import(params ImportTask[] tasks);
|
||||||
|
|
||||||
|
Task<IEnumerable<ILive<TModel>>> Import(ProgressNotification notification, params ImportTask[] tasks);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Import one <typeparamref name="TModel"/> from the filesystem and delete the file on success.
|
||||||
|
/// Note that this bypasses the UI flow and should only be used for special cases or testing.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="task">The <see cref="ImportTask"/> containing data about the <typeparamref name="TModel"/> to import.</param>
|
||||||
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
|
/// <returns>The imported model, if successful.</returns>
|
||||||
|
Task<ILive<TModel>> Import(ImportTask task, bool lowPriority = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Silently import an item from an <see cref="ArchiveReader"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="archive">The archive to be imported.</param>
|
||||||
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
|
Task<ILive<TModel>> Import(ArchiveReader archive, bool lowPriority = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Silently import an item from a <typeparamref name="TModel"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The model to be imported.</param>
|
||||||
|
/// <param name="archive">An optional archive to use for model population.</param>
|
||||||
|
/// <param name="lowPriority">Whether this is a low priority import.</param>
|
||||||
|
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||||
|
Task<ILive<TModel>> Import(TModel item, ArchiveReader archive = null, bool lowPriority = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A user displayable name for the model type associated with this manager.
|
||||||
|
/// </summary>
|
||||||
|
string HumanisedModelName => $"{typeof(TModel).Name.Replace(@"Info", "").ToLower()}";
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,12 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.IO;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -10,7 +14,7 @@ namespace osu.Game.Database
|
|||||||
/// Represents a model manager that publishes events when <typeparamref name="TModel"/>s are added or removed.
|
/// Represents a model manager that publishes events when <typeparamref name="TModel"/>s are added or removed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
public interface IModelManager<TModel>
|
public interface IModelManager<TModel> : IModelImporter<TModel>
|
||||||
where TModel : class
|
where TModel : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -24,5 +28,63 @@ namespace osu.Game.Database
|
|||||||
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IBindable<WeakReference<TModel>> ItemRemoved { get; }
|
IBindable<WeakReference<TModel>> ItemRemoved { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is a temporary method and will likely be replaced by a full-fledged (and more correctly placed) migration process in the future.
|
||||||
|
/// </summary>
|
||||||
|
Task ImportFromStableAsync(StableStorage stableStorage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exports an item to a legacy (.zip based) package.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The item to export.</param>
|
||||||
|
void Export(TModel item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exports an item to the given output stream.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The item to export.</param>
|
||||||
|
/// <param name="outputStream">The output stream to export to.</param>
|
||||||
|
void ExportModelTo(TModel model, Stream outputStream);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform an update of the specified item.
|
||||||
|
/// TODO: Support file additions/removals.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The item to update.</param>
|
||||||
|
void Update(TModel item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an item from the manager.
|
||||||
|
/// Is a no-op for already deleted items.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The item to delete.</param>
|
||||||
|
/// <returns>false if no operation was performed</returns>
|
||||||
|
bool Delete(TModel item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete multiple items.
|
||||||
|
/// This will post notifications tracking progress.
|
||||||
|
/// </summary>
|
||||||
|
void Delete(List<TModel> items, bool silent = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restore multiple items that were previously deleted.
|
||||||
|
/// This will post notifications tracking progress.
|
||||||
|
/// </summary>
|
||||||
|
void Undelete(List<TModel> items, bool silent = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restore an item that was previously deleted. Is a no-op if the item is not in a deleted state, or has its protected flag set.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The item to restore</param>
|
||||||
|
void Undelete(TModel item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a given <typeparamref name="TModel"/> is already available in the local store.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The <typeparamref name="TModel"/> whose existence needs to be checked.</param>
|
||||||
|
/// <returns>Whether the <typeparamref name="TModel"/> exists.</returns>
|
||||||
|
bool IsAvailableLocally(TModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
osu.Game/Database/IPostImports.cs
Normal file
17
osu.Game/Database/IPostImports.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public interface IPostImports<out TModel>
|
||||||
|
where TModel : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when the user requests to view the resulting import.
|
||||||
|
/// </summary>
|
||||||
|
public Action<IEnumerable<ILive<TModel>>> PostImport { set; }
|
||||||
|
}
|
||||||
|
}
|
16
osu.Game/Database/IPostNotifications.cs
Normal file
16
osu.Game/Database/IPostNotifications.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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 osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public interface IPostNotifications
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// And action which will be fired when a notification should be presented to the user.
|
||||||
|
/// </summary>
|
||||||
|
public Action<Notification> PostNotification { set; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,20 +9,12 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main realm context, bound to the update thread.
|
/// The main realm context, bound to the update thread.
|
||||||
/// If querying from a non-update thread is needed, use <see cref="GetForRead"/> or <see cref="GetForWrite"/> to receive a context instead.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Realm Context { get; }
|
Realm Context { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a fresh context for read usage.
|
/// Create a new realm context for use on the current thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
RealmContextFactory.RealmUsage GetForRead();
|
Realm CreateContext();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request a context for write usage.
|
|
||||||
/// This method may block if a write is already active on a different thread.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>A usage containing a usable context.</returns>
|
|
||||||
RealmContextFactory.RealmWriteUsage GetForWrite();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,24 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using Humanizer;
|
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Overlays.Notifications;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Humanizer;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
/// <summary>
|
public abstract class ModelDownloader<TModel> : IModelDownloader<TModel>
|
||||||
/// An <see cref="ArchiveModelManager{TModel, TFileModel}"/> that has the ability to download models using an <see cref="IAPIProvider"/> and
|
where TModel : class, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>
|
||||||
/// import them into the store.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
|
||||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
|
||||||
public abstract class DownloadableArchiveModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>, IModelDownloader<TModel>
|
|
||||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>
|
|
||||||
where TFileModel : class, INamedFileInfo, new()
|
|
||||||
{
|
{
|
||||||
|
public Action<Notification> PostNotification { protected get; set; }
|
||||||
|
|
||||||
public IBindable<WeakReference<ArchiveDownloadRequest<TModel>>> DownloadBegan => downloadBegan;
|
public IBindable<WeakReference<ArchiveDownloadRequest<TModel>>> DownloadBegan => downloadBegan;
|
||||||
|
|
||||||
private readonly Bindable<WeakReference<ArchiveDownloadRequest<TModel>>> downloadBegan = new Bindable<WeakReference<ArchiveDownloadRequest<TModel>>>();
|
private readonly Bindable<WeakReference<ArchiveDownloadRequest<TModel>>> downloadBegan = new Bindable<WeakReference<ArchiveDownloadRequest<TModel>>>();
|
||||||
@ -32,18 +27,15 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private readonly Bindable<WeakReference<ArchiveDownloadRequest<TModel>>> downloadFailed = new Bindable<WeakReference<ArchiveDownloadRequest<TModel>>>();
|
private readonly Bindable<WeakReference<ArchiveDownloadRequest<TModel>>> downloadFailed = new Bindable<WeakReference<ArchiveDownloadRequest<TModel>>>();
|
||||||
|
|
||||||
|
private readonly IModelManager<TModel> modelManager;
|
||||||
private readonly IAPIProvider api;
|
private readonly IAPIProvider api;
|
||||||
|
|
||||||
private readonly List<ArchiveDownloadRequest<TModel>> currentDownloads = new List<ArchiveDownloadRequest<TModel>>();
|
private readonly List<ArchiveDownloadRequest<TModel>> currentDownloads = new List<ArchiveDownloadRequest<TModel>>();
|
||||||
|
|
||||||
private readonly MutableDatabaseBackedStoreWithFileIncludes<TModel, TFileModel> modelStore;
|
protected ModelDownloader(IModelManager<TModel> modelManager, IAPIProvider api, IIpcHost importHost = null)
|
||||||
|
|
||||||
protected DownloadableArchiveModelManager(Storage storage, IDatabaseContextFactory contextFactory, IAPIProvider api, MutableDatabaseBackedStoreWithFileIncludes<TModel, TFileModel> modelStore,
|
|
||||||
IIpcHost importHost = null)
|
|
||||||
: base(storage, contextFactory, modelStore, importHost)
|
|
||||||
{
|
{
|
||||||
|
this.modelManager = modelManager;
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.modelStore = modelStore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -54,12 +46,6 @@ namespace osu.Game.Database
|
|||||||
/// <returns>The request object.</returns>
|
/// <returns>The request object.</returns>
|
||||||
protected abstract ArchiveDownloadRequest<TModel> CreateDownloadRequest(TModel model, bool minimiseDownloadSize);
|
protected abstract ArchiveDownloadRequest<TModel> CreateDownloadRequest(TModel model, bool minimiseDownloadSize);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Begin a download for the requested <typeparamref name="TModel"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">The <typeparamref name="TModel"/> to be downloaded.</param>
|
|
||||||
/// <param name="minimiseDownloadSize">Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle.</param>
|
|
||||||
/// <returns>Whether the download was started.</returns>
|
|
||||||
public bool Download(TModel model, bool minimiseDownloadSize = false)
|
public bool Download(TModel model, bool minimiseDownloadSize = false)
|
||||||
{
|
{
|
||||||
if (!canDownload(model)) return false;
|
if (!canDownload(model)) return false;
|
||||||
@ -82,7 +68,7 @@ namespace osu.Game.Database
|
|||||||
Task.Factory.StartNew(async () =>
|
Task.Factory.StartNew(async () =>
|
||||||
{
|
{
|
||||||
// This gets scheduled back to the update thread, but we want the import to run in the background.
|
// This gets scheduled back to the update thread, but we want the import to run in the background.
|
||||||
var imported = await Import(notification, new ImportTask(filename)).ConfigureAwait(false);
|
var imported = await modelManager.Import(notification, new ImportTask(filename)).ConfigureAwait(false);
|
||||||
|
|
||||||
// for now a failed import will be marked as a failed download for simplicity.
|
// for now a failed import will be marked as a failed download for simplicity.
|
||||||
if (!imported.Any())
|
if (!imported.Any())
|
||||||
@ -117,21 +103,10 @@ namespace osu.Game.Database
|
|||||||
notification.State = ProgressNotificationState.Cancelled;
|
notification.State = ProgressNotificationState.Cancelled;
|
||||||
|
|
||||||
if (!(error is OperationCanceledException))
|
if (!(error is OperationCanceledException))
|
||||||
Logger.Error(error, $"{HumanisedModelName.Titleize()} download failed!");
|
Logger.Error(error, $"{modelManager.HumanisedModelName.Titleize()} download failed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAvailableLocally(TModel model) => CheckLocalAvailability(model, modelStore.ConsumableItems.Where(m => !m.DeletePending));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Performs implementation specific comparisons to determine whether a given model is present in the local store.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">The <typeparamref name="TModel"/> whose existence needs to be checked.</param>
|
|
||||||
/// <param name="items">The usable items present in the store.</param>
|
|
||||||
/// <returns>Whether the <typeparamref name="TModel"/> exists.</returns>
|
|
||||||
protected virtual bool CheckLocalAvailability(TModel model, IQueryable<TModel> items)
|
|
||||||
=> model.ID > 0 && items.Any(i => i.ID == model.ID && i.Files.Any());
|
|
||||||
|
|
||||||
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.Equals(model));
|
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.Equals(model));
|
||||||
|
|
||||||
private bool canDownload(TModel model) => GetExistingDownload(model) == null && api != null;
|
private bool canDownload(TModel model) => GetExistingDownload(model) == null && api != null;
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
@ -10,80 +9,117 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Statistics;
|
using osu.Framework.Statistics;
|
||||||
using osu.Game.Input.Bindings;
|
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A factory which provides both the main (update thread bound) realm context and creates contexts for async usage.
|
||||||
|
/// </summary>
|
||||||
public class RealmContextFactory : Component, IRealmFactory
|
public class RealmContextFactory : Component, IRealmFactory
|
||||||
{
|
{
|
||||||
private readonly Storage storage;
|
private readonly Storage storage;
|
||||||
|
|
||||||
private const string database_name = @"client";
|
/// <summary>
|
||||||
|
/// The filename of this realm.
|
||||||
|
/// </summary>
|
||||||
|
public readonly string Filename;
|
||||||
|
|
||||||
private const int schema_version = 6;
|
private const int schema_version = 6;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock object which is held for the duration of a write operation (via <see cref="GetForWrite"/>).
|
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly object writeLock = new object();
|
private readonly SemaphoreSlim contextCreationLock = new SemaphoreSlim(1);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections.
|
|
||||||
/// </summary>
|
|
||||||
private readonly SemaphoreSlim blockingLock = new SemaphoreSlim(1);
|
|
||||||
|
|
||||||
private static readonly GlobalStatistic<int> reads = GlobalStatistics.Get<int>("Realm", "Get (Read)");
|
|
||||||
private static readonly GlobalStatistic<int> writes = GlobalStatistics.Get<int>("Realm", "Get (Write)");
|
|
||||||
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>("Realm", "Dirty Refreshes");
|
private static readonly GlobalStatistic<int> refreshes = GlobalStatistics.Get<int>("Realm", "Dirty Refreshes");
|
||||||
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>("Realm", "Contexts (Created)");
|
private static readonly GlobalStatistic<int> contexts_created = GlobalStatistics.Get<int>("Realm", "Contexts (Created)");
|
||||||
private static readonly GlobalStatistic<int> pending_writes = GlobalStatistics.Get<int>("Realm", "Pending writes");
|
|
||||||
private static readonly GlobalStatistic<int> active_usages = GlobalStatistics.Get<int>("Realm", "Active usages");
|
|
||||||
|
|
||||||
private readonly object updateContextLock = new object();
|
private readonly object contextLock = new object();
|
||||||
|
private Realm? context;
|
||||||
private Realm context;
|
|
||||||
|
|
||||||
public Realm Context
|
public Realm Context
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!ThreadSafety.IsUpdateThread)
|
if (!ThreadSafety.IsUpdateThread)
|
||||||
throw new InvalidOperationException($"Use {nameof(GetForRead)} or {nameof(GetForWrite)} when performing realm operations from a non-update thread");
|
throw new InvalidOperationException($"Use {nameof(CreateContext)} when performing realm operations from a non-update thread");
|
||||||
|
|
||||||
lock (updateContextLock)
|
lock (contextLock)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
context = createContext();
|
context = CreateContext();
|
||||||
Logger.Log($"Opened realm \"{context.Config.DatabasePath}\" at version {context.Config.SchemaVersion}");
|
Logger.Log($"Opened realm \"{context.Config.DatabasePath}\" at version {context.Config.SchemaVersion}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// creating a context will ensure our schema is up-to-date and migrated.
|
// creating a context will ensure our schema is up-to-date and migrated.
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmContextFactory(Storage storage)
|
public RealmContextFactory(Storage storage, string filename)
|
||||||
{
|
{
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
|
|
||||||
|
Filename = filename;
|
||||||
|
|
||||||
|
const string realm_extension = ".realm";
|
||||||
|
|
||||||
|
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
|
||||||
|
Filename += realm_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmUsage GetForRead()
|
/// <summary>
|
||||||
|
/// Compact this realm.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Compact() => Realm.Compact(getConfiguration());
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
{
|
{
|
||||||
reads.Value++;
|
base.Update();
|
||||||
return new RealmUsage(createContext());
|
|
||||||
|
lock (contextLock)
|
||||||
|
{
|
||||||
|
if (context?.Refresh() == true)
|
||||||
|
refreshes.Value++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RealmWriteUsage GetForWrite()
|
public Realm CreateContext()
|
||||||
{
|
{
|
||||||
writes.Value++;
|
if (IsDisposed)
|
||||||
pending_writes.Value++;
|
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||||
|
|
||||||
Monitor.Enter(writeLock);
|
try
|
||||||
return new RealmWriteUsage(createContext(), writeComplete);
|
{
|
||||||
|
contextCreationLock.Wait();
|
||||||
|
|
||||||
|
contexts_created.Value++;
|
||||||
|
|
||||||
|
return Realm.GetInstance(getConfiguration());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
contextCreationLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RealmConfiguration getConfiguration()
|
||||||
|
{
|
||||||
|
return new RealmConfiguration(storage.GetFullPath(Filename, true))
|
||||||
|
{
|
||||||
|
SchemaVersion = schema_version,
|
||||||
|
MigrationCallback = onMigration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -99,165 +135,63 @@ namespace osu.Game.Database
|
|||||||
if (IsDisposed)
|
if (IsDisposed)
|
||||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
||||||
|
|
||||||
|
// TODO: this can be added for safety once we figure how to bypass in test
|
||||||
|
// if (!ThreadSafety.IsUpdateThread)
|
||||||
|
// throw new InvalidOperationException($"{nameof(BlockAllOperations)} must be called from the update thread.");
|
||||||
|
|
||||||
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
|
||||||
|
|
||||||
blockingLock.Wait();
|
|
||||||
flushContexts();
|
|
||||||
|
|
||||||
return new InvokeOnDisposal<RealmContextFactory>(this, endBlockingSection);
|
|
||||||
|
|
||||||
static void endBlockingSection(RealmContextFactory factory)
|
|
||||||
{
|
|
||||||
factory.blockingLock.Release();
|
|
||||||
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
|
|
||||||
lock (updateContextLock)
|
|
||||||
{
|
|
||||||
if (context?.Refresh() == true)
|
|
||||||
refreshes.Value++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Realm createContext()
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (IsDisposed)
|
contextCreationLock.Wait();
|
||||||
throw new ObjectDisposedException(nameof(RealmContextFactory));
|
|
||||||
|
|
||||||
blockingLock.Wait();
|
lock (contextLock)
|
||||||
|
|
||||||
contexts_created.Value++;
|
|
||||||
|
|
||||||
return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true))
|
|
||||||
{
|
{
|
||||||
SchemaVersion = schema_version,
|
context?.Dispose();
|
||||||
MigrationCallback = onMigration,
|
context = null;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const int sleep_length = 200;
|
||||||
|
int timeout = 5000;
|
||||||
|
|
||||||
|
// see https://github.com/realm/realm-dotnet/discussions/2657
|
||||||
|
while (!Compact())
|
||||||
|
{
|
||||||
|
Thread.Sleep(sleep_length);
|
||||||
|
timeout -= sleep_length;
|
||||||
|
|
||||||
|
if (timeout < 0)
|
||||||
|
throw new TimeoutException("Took too long to acquire lock");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
catch
|
||||||
{
|
{
|
||||||
blockingLock.Release();
|
contextCreationLock.Release();
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeComplete()
|
return new InvokeOnDisposal<RealmContextFactory>(this, factory =>
|
||||||
{
|
|
||||||
Monitor.Exit(writeLock);
|
|
||||||
pending_writes.Value--;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onMigration(Migration migration, ulong lastSchemaVersion)
|
|
||||||
{
|
|
||||||
switch (lastSchemaVersion)
|
|
||||||
{
|
{
|
||||||
case 5:
|
factory.contextCreationLock.Release();
|
||||||
// let's keep things simple. changing the type of the primary key is a bit involved.
|
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
||||||
migration.NewRealm.RemoveAll<RealmKeyBinding>();
|
});
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void flushContexts()
|
|
||||||
{
|
|
||||||
Logger.Log(@"Flushing realm contexts...", LoggingTarget.Database);
|
|
||||||
Debug.Assert(blockingLock.CurrentCount == 0);
|
|
||||||
|
|
||||||
Realm previousContext;
|
|
||||||
|
|
||||||
lock (updateContextLock)
|
|
||||||
{
|
|
||||||
previousContext = context;
|
|
||||||
context = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for all threaded usages to finish
|
|
||||||
while (active_usages.Value > 0)
|
|
||||||
Thread.Sleep(50);
|
|
||||||
|
|
||||||
previousContext?.Dispose();
|
|
||||||
|
|
||||||
Logger.Log(@"Realm contexts flushed.", LoggingTarget.Database);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
|
lock (contextLock)
|
||||||
|
{
|
||||||
|
context?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsDisposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
// intentionally block all operations indefinitely. this ensures that nothing can start consuming a new context after disposal.
|
// intentionally block context creation indefinitely. this ensures that nothing can start consuming a new context after disposal.
|
||||||
BlockAllOperations();
|
contextCreationLock.Wait();
|
||||||
blockingLock?.Dispose();
|
contextCreationLock.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A usage of realm from an arbitrary thread.
|
|
||||||
/// </summary>
|
|
||||||
public class RealmUsage : IDisposable
|
|
||||||
{
|
|
||||||
public readonly Realm Realm;
|
|
||||||
|
|
||||||
internal RealmUsage(Realm context)
|
|
||||||
{
|
|
||||||
active_usages.Value++;
|
|
||||||
Realm = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes this instance, calling the initially captured action.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Dispose()
|
|
||||||
{
|
|
||||||
Realm?.Dispose();
|
|
||||||
active_usages.Value--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A transaction used for making changes to realm data.
|
|
||||||
/// </summary>
|
|
||||||
public class RealmWriteUsage : RealmUsage
|
|
||||||
{
|
|
||||||
private readonly Action onWriteComplete;
|
|
||||||
private readonly Transaction transaction;
|
|
||||||
|
|
||||||
internal RealmWriteUsage(Realm context, Action onWriteComplete)
|
|
||||||
: base(context)
|
|
||||||
{
|
|
||||||
this.onWriteComplete = onWriteComplete;
|
|
||||||
transaction = Realm.BeginWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Commit all changes made in this transaction.
|
|
||||||
/// </summary>
|
|
||||||
public void Commit() => transaction.Commit();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Revert all changes made in this transaction.
|
|
||||||
/// </summary>
|
|
||||||
public void Rollback() => transaction.Rollback();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes this instance, calling the initially captured action.
|
|
||||||
/// </summary>
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
// rollback if not explicitly committed.
|
|
||||||
transaction?.Dispose();
|
|
||||||
|
|
||||||
base.Dispose();
|
|
||||||
|
|
||||||
onWriteComplete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,26 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using AutoMapper;
|
|
||||||
using osu.Game.Input.Bindings;
|
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
public static class RealmExtensions
|
public static class RealmExtensions
|
||||||
{
|
{
|
||||||
private static readonly IMapper mapper = new MapperConfiguration(c =>
|
public static void Write(this Realm realm, Action<Realm> function)
|
||||||
{
|
{
|
||||||
c.ShouldMapField = fi => false;
|
using var transaction = realm.BeginWrite();
|
||||||
c.ShouldMapProperty = pi => pi.SetMethod != null && pi.SetMethod.IsPublic;
|
function(realm);
|
||||||
|
transaction.Commit();
|
||||||
c.CreateMap<RealmKeyBinding, RealmKeyBinding>();
|
|
||||||
}).CreateMapper();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a detached copy of the each item in the collection.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="items">A list of managed <see cref="RealmObject"/>s to detach.</param>
|
|
||||||
/// <typeparam name="T">The type of object.</typeparam>
|
|
||||||
/// <returns>A list containing non-managed copies of provided items.</returns>
|
|
||||||
public static List<T> Detach<T>(this IEnumerable<T> items) where T : RealmObject
|
|
||||||
{
|
|
||||||
var list = new List<T>();
|
|
||||||
|
|
||||||
foreach (var obj in items)
|
|
||||||
list.Add(obj.Detach());
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static T Write<T>(this Realm realm, Func<Realm, T> function)
|
||||||
/// Create a detached copy of the item.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item">The managed <see cref="RealmObject"/> to detach.</param>
|
|
||||||
/// <typeparam name="T">The type of object.</typeparam>
|
|
||||||
/// <returns>A non-managed copy of provided item. Will return the provided item if already detached.</returns>
|
|
||||||
public static T Detach<T>(this T item) where T : RealmObject
|
|
||||||
{
|
{
|
||||||
if (!item.IsManaged)
|
using var transaction = realm.BeginWrite();
|
||||||
return item;
|
var result = function(realm);
|
||||||
|
transaction.Commit();
|
||||||
return mapper.Map<T>(item);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
osu.Game/Database/RealmObjectExtensions.cs
Normal file
51
osu.Game/Database/RealmObjectExtensions.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// 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.Collections.Generic;
|
||||||
|
using AutoMapper;
|
||||||
|
using osu.Game.Input.Bindings;
|
||||||
|
using Realms;
|
||||||
|
|
||||||
|
namespace osu.Game.Database
|
||||||
|
{
|
||||||
|
public static class RealmObjectExtensions
|
||||||
|
{
|
||||||
|
private static readonly IMapper mapper = new MapperConfiguration(c =>
|
||||||
|
{
|
||||||
|
c.ShouldMapField = fi => false;
|
||||||
|
c.ShouldMapProperty = pi => pi.SetMethod != null && pi.SetMethod.IsPublic;
|
||||||
|
|
||||||
|
c.CreateMap<RealmKeyBinding, RealmKeyBinding>();
|
||||||
|
}).CreateMapper();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a detached copy of the each item in the collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="items">A list of managed <see cref="RealmObject"/>s to detach.</param>
|
||||||
|
/// <typeparam name="T">The type of object.</typeparam>
|
||||||
|
/// <returns>A list containing non-managed copies of provided items.</returns>
|
||||||
|
public static List<T> Detach<T>(this IEnumerable<T> items) where T : RealmObject
|
||||||
|
{
|
||||||
|
var list = new List<T>();
|
||||||
|
|
||||||
|
foreach (var obj in items)
|
||||||
|
list.Add(obj.Detach());
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a detached copy of the item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The managed <see cref="RealmObject"/> to detach.</param>
|
||||||
|
/// <typeparam name="T">The type of object.</typeparam>
|
||||||
|
/// <returns>A non-managed copy of provided item. Will return the provided item if already detached.</returns>
|
||||||
|
public static T Detach<T>(this T item) where T : RealmObject
|
||||||
|
{
|
||||||
|
if (!item.IsManaged)
|
||||||
|
return item;
|
||||||
|
|
||||||
|
return mapper.Map<T>(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.AccountCreation
|
namespace osu.Game.Graphics
|
||||||
{
|
{
|
||||||
public class ErrorTextFlowContainer : OsuTextFlowContainer
|
public class ErrorTextFlowContainer : OsuTextFlowContainer
|
||||||
{
|
{
|
@ -21,6 +21,8 @@ namespace osu.Game.Graphics
|
|||||||
|
|
||||||
public static FontUsage Torus => GetFont(Typeface.Torus, weight: FontWeight.Regular);
|
public static FontUsage Torus => GetFont(Typeface.Torus, weight: FontWeight.Regular);
|
||||||
|
|
||||||
|
public static FontUsage TorusAlternate => GetFont(Typeface.TorusAlternate, weight: FontWeight.Regular);
|
||||||
|
|
||||||
public static FontUsage Inter => GetFont(Typeface.Inter, weight: FontWeight.Regular);
|
public static FontUsage Inter => GetFont(Typeface.Inter, weight: FontWeight.Regular);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -57,6 +59,9 @@ namespace osu.Game.Graphics
|
|||||||
case Typeface.Torus:
|
case Typeface.Torus:
|
||||||
return "Torus";
|
return "Torus";
|
||||||
|
|
||||||
|
case Typeface.TorusAlternate:
|
||||||
|
return "Torus-Alternate";
|
||||||
|
|
||||||
case Typeface.Inter:
|
case Typeface.Inter:
|
||||||
return "Inter";
|
return "Inter";
|
||||||
}
|
}
|
||||||
@ -113,6 +118,7 @@ namespace osu.Game.Graphics
|
|||||||
{
|
{
|
||||||
Venera,
|
Venera,
|
||||||
Torus,
|
Torus,
|
||||||
|
TorusAlternate,
|
||||||
Inter,
|
Inter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ using osu.Framework.Input.Bindings;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using Realms;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ namespace osu.Game.Input
|
|||||||
{
|
{
|
||||||
List<string> combinations = new List<string>();
|
List<string> combinations = new List<string>();
|
||||||
|
|
||||||
using (var context = realmFactory.GetForRead())
|
using (var context = realmFactory.CreateContext())
|
||||||
{
|
{
|
||||||
foreach (var action in context.Realm.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction))
|
foreach (var action in context.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction))
|
||||||
{
|
{
|
||||||
string str = action.KeyCombination.ReadableString();
|
string str = action.KeyCombination.ReadableString();
|
||||||
|
|
||||||
@ -52,26 +53,27 @@ namespace osu.Game.Input
|
|||||||
/// <param name="rulesets">The rulesets to populate defaults from.</param>
|
/// <param name="rulesets">The rulesets to populate defaults from.</param>
|
||||||
public void Register(KeyBindingContainer container, IEnumerable<RulesetInfo> rulesets)
|
public void Register(KeyBindingContainer container, IEnumerable<RulesetInfo> rulesets)
|
||||||
{
|
{
|
||||||
using (var usage = realmFactory.GetForWrite())
|
using (var realm = realmFactory.CreateContext())
|
||||||
|
using (var transaction = realm.BeginWrite())
|
||||||
{
|
{
|
||||||
// intentionally flattened to a list rather than querying against the IQueryable, as nullable fields being queried against aren't indexed.
|
// intentionally flattened to a list rather than querying against the IQueryable, as nullable fields being queried against aren't indexed.
|
||||||
// this is much faster as a result.
|
// this is much faster as a result.
|
||||||
var existingBindings = usage.Realm.All<RealmKeyBinding>().ToList();
|
var existingBindings = realm.All<RealmKeyBinding>().ToList();
|
||||||
|
|
||||||
insertDefaults(usage, existingBindings, container.DefaultKeyBindings);
|
insertDefaults(realm, existingBindings, container.DefaultKeyBindings);
|
||||||
|
|
||||||
foreach (var ruleset in rulesets)
|
foreach (var ruleset in rulesets)
|
||||||
{
|
{
|
||||||
var instance = ruleset.CreateInstance();
|
var instance = ruleset.CreateInstance();
|
||||||
foreach (var variant in instance.AvailableVariants)
|
foreach (var variant in instance.AvailableVariants)
|
||||||
insertDefaults(usage, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
|
insertDefaults(realm, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
usage.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertDefaults(RealmContextFactory.RealmUsage usage, List<RealmKeyBinding> existingBindings, IEnumerable<IKeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
private void insertDefaults(Realm realm, List<RealmKeyBinding> existingBindings, IEnumerable<IKeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||||
{
|
{
|
||||||
// compare counts in database vs defaults for each action type.
|
// compare counts in database vs defaults for each action type.
|
||||||
foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
|
foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
|
||||||
@ -83,7 +85,7 @@ namespace osu.Game.Input
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// insert any defaults which are missing.
|
// insert any defaults which are missing.
|
||||||
usage.Realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding
|
realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding
|
||||||
{
|
{
|
||||||
KeyCombinationString = k.KeyCombination.ToString(),
|
KeyCombinationString = k.KeyCombination.ToString(),
|
||||||
ActionInt = (int)k.Action,
|
ActionInt = (int)k.Action,
|
||||||
|
@ -35,9 +35,8 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public string WebsiteRootUrl { get; }
|
public string WebsiteRootUrl { get; }
|
||||||
|
|
||||||
/// <summary>
|
public Exception LastLoginError { get; private set; }
|
||||||
/// The username/email provided by the user when initiating a login.
|
|
||||||
/// </summary>
|
|
||||||
public string ProvidedUsername { get; private set; }
|
public string ProvidedUsername { get; private set; }
|
||||||
|
|
||||||
private string password;
|
private string password;
|
||||||
@ -136,14 +135,23 @@ namespace osu.Game.Online.API
|
|||||||
// save the username at this point, if the user requested for it to be.
|
// save the username at this point, if the user requested for it to be.
|
||||||
config.SetValue(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
|
config.SetValue(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
|
||||||
|
|
||||||
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(ProvidedUsername, password))
|
if (!authentication.HasValidAccessToken)
|
||||||
{
|
{
|
||||||
//todo: this fails even on network-related issues. we should probably handle those differently.
|
LastLoginError = null;
|
||||||
//NotificationOverlay.ShowMessage("Login failed!");
|
|
||||||
log.Add(@"Login failed!");
|
try
|
||||||
password = null;
|
{
|
||||||
authentication.Clear();
|
authentication.AuthenticateWithLogin(ProvidedUsername, password);
|
||||||
continue;
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//todo: this fails even on network-related issues. we should probably handle those differently.
|
||||||
|
LastLoginError = e;
|
||||||
|
log.Add(@"Login failed!");
|
||||||
|
password = null;
|
||||||
|
authentication.Clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var userReq = new GetUserRequest();
|
var userReq = new GetUserRequest();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user