1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-06 12:13:03 +08:00

Merge branch 'master' into diffcalc/refactor-strain-logic

This commit is contained in:
Dan Balasescu 2021-04-05 14:16:34 +09:00 committed by GitHub
commit 5bf0889379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 168 additions and 31 deletions

View File

@ -77,5 +77,11 @@ namespace osu.Game.Tests.Visual.Editing
AddStep("start clock again", Clock.Start); AddStep("start clock again", Clock.Start);
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500); AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
} }
protected override void Dispose(bool isDisposing)
{
Beatmap.Disabled = false;
base.Dispose(isDisposing);
}
} }
} }

View File

@ -0,0 +1,79 @@
// 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.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Editing
{
public class TestSceneEditorSeeking : EditorTestScene
{
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset)
{
var beatmap = base.CreateBeatmap(ruleset);
beatmap.BeatmapInfo.BeatDivisor = 1;
beatmap.ControlPointInfo = new ControlPointInfo();
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 1000 });
beatmap.ControlPointInfo.Add(2000, new TimingControlPoint { BeatLength = 500 });
return beatmap;
}
[Test]
public void TestSnappedSeeking()
{
AddStep("seek to 0", () => EditorClock.Seek(0));
AddAssert("time is 0", () => EditorClock.CurrentTime == 0);
pressAndCheckTime(Key.Right, 1000);
pressAndCheckTime(Key.Right, 2000);
pressAndCheckTime(Key.Right, 2500);
pressAndCheckTime(Key.Right, 3000);
pressAndCheckTime(Key.Left, 2500);
pressAndCheckTime(Key.Left, 2000);
pressAndCheckTime(Key.Left, 1000);
}
[Test]
public void TestSnappedSeekingAfterControlPointChange()
{
AddStep("seek to 0", () => EditorClock.Seek(0));
AddAssert("time is 0", () => EditorClock.CurrentTime == 0);
pressAndCheckTime(Key.Right, 1000);
pressAndCheckTime(Key.Right, 2000);
pressAndCheckTime(Key.Right, 2500);
pressAndCheckTime(Key.Right, 3000);
AddStep("remove 2nd timing point", () =>
{
EditorBeatmap.BeginChange();
var group = EditorBeatmap.ControlPointInfo.GroupAt(2000);
EditorBeatmap.ControlPointInfo.RemoveGroup(group);
EditorBeatmap.EndChange();
});
pressAndCheckTime(Key.Left, 2000);
pressAndCheckTime(Key.Left, 1000);
pressAndCheckTime(Key.Right, 2000);
pressAndCheckTime(Key.Right, 3000);
}
private void pressAndCheckTime(Key key, double expectedTime)
{
AddStep($"press {key}", () => InputManager.Key(key));
AddUntilStep($"time is {expectedTime}", () => Precision.AlmostEquals(expectedTime, EditorClock.CurrentTime, 1));
}
}
}

View File

@ -1,9 +1,13 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Tournament.Components; using osu.Game.Tournament.Components;
using osu.Game.Tournament.Screens.Gameplay; using osu.Game.Tournament.Screens.Gameplay;
using osu.Game.Tournament.Screens.Gameplay.Components;
namespace osu.Game.Tournament.Tests.Screens namespace osu.Game.Tournament.Tests.Screens
{ {
@ -18,5 +22,24 @@ namespace osu.Game.Tournament.Tests.Screens
Add(new GameplayScreen()); Add(new GameplayScreen());
Add(chat); Add(chat);
} }
[Test]
public void TestWarmup()
{
checkScoreVisibility(false);
toggleWarmup();
checkScoreVisibility(true);
toggleWarmup();
checkScoreVisibility(false);
}
private void checkScoreVisibility(bool visible)
=> AddUntilStep($"scores {(visible ? "shown" : "hidden")}",
() => this.ChildrenOfType<TeamScore>().All(score => score.Alpha == (visible ? 1 : 0)));
private void toggleWarmup()
=> AddStep("toggle warmup", () => this.ChildrenOfType<TourneyButton>().First().Click());
} }
} }

View File

@ -10,6 +10,7 @@ using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osu.Game.Tournament.IO;
using osu.Game.Tournament.IPC; using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osu.Game.Users; using osu.Game.Users;
@ -28,7 +29,7 @@ namespace osu.Game.Tournament.Tests
protected MatchIPCInfo IPCInfo { get; private set; } = new MatchIPCInfo(); protected MatchIPCInfo IPCInfo { get; private set; } = new MatchIPCInfo();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(Storage storage) private void load(TournamentStorage storage)
{ {
Ladder.Ruleset.Value ??= rulesetStore.AvailableRulesets.First(); Ladder.Ruleset.Value ??= rulesetStore.AvailableRulesets.First();

View File

@ -27,17 +27,16 @@ namespace osu.Game.Tournament.Models
private const string config_path = "stable.json"; private const string config_path = "stable.json";
private readonly Storage storage; private readonly Storage configStorage;
public StableInfo(Storage storage) public StableInfo(TournamentStorage storage)
{ {
TournamentStorage tStorage = (TournamentStorage)storage; configStorage = storage.AllTournaments;
this.storage = tStorage.AllTournaments;
if (!storage.Exists(config_path)) if (!configStorage.Exists(config_path))
return; return;
using (Stream stream = storage.GetStream(config_path, FileAccess.Read, FileMode.Open)) using (Stream stream = configStorage.GetStream(config_path, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream)) using (var sr = new StreamReader(stream))
{ {
JsonConvert.PopulateObject(sr.ReadToEnd(), this); JsonConvert.PopulateObject(sr.ReadToEnd(), this);
@ -46,7 +45,7 @@ namespace osu.Game.Tournament.Models
public void SaveChanges() public void SaveChanges()
{ {
using (var stream = storage.GetStream(config_path, FileAccess.Write, FileMode.Create)) using (var stream = configStorage.GetStream(config_path, FileAccess.Write, FileMode.Create))
using (var sw = new StreamWriter(stream)) using (var sw = new StreamWriter(stream))
{ {
sw.Write(JsonConvert.SerializeObject(this, sw.Write(JsonConvert.SerializeObject(this,

View File

@ -95,7 +95,11 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, },
}; };
}
protected override void LoadComplete()
{
base.LoadComplete();
updateDisplay(); updateDisplay();
} }

View File

@ -14,9 +14,21 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
{ {
private readonly TeamScore score; private readonly TeamScore score;
private bool showScore;
public bool ShowScore public bool ShowScore
{ {
set => score.FadeTo(value ? 1 : 0, 200); get => showScore;
set
{
if (showScore == value)
return;
showScore = value;
if (IsLoaded)
updateDisplay();
}
} }
public TeamDisplay(TournamentTeam team, TeamColour colour, Bindable<int?> currentTeamScore, int pointsToWin) public TeamDisplay(TournamentTeam team, TeamColour colour, Bindable<int?> currentTeamScore, int pointsToWin)
@ -92,5 +104,18 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
} }
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
updateDisplay();
FinishTransforms(true);
}
private void updateDisplay()
{
score.FadeTo(ShowScore ? 1 : 0, 200);
}
} }
} }

View File

@ -391,7 +391,7 @@ namespace osu.Game.Online.Leaderboards
if (score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null) if (score.Mods.Length > 0 && modsContainer.Any(s => s.IsHovered) && songSelect != null)
items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = score.Mods)); items.Add(new OsuMenuItem("Use these mods", MenuItemType.Highlighted, () => songSelect.Mods.Value = score.Mods));
if (score.Files.Count > 0) if (score.Files?.Count > 0)
items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(score))); items.Add(new OsuMenuItem("Export", MenuItemType.Standard, () => scoreManager.Export(score)));
if (score.ID != 0) if (score.ID != 0)

View File

@ -122,22 +122,6 @@ namespace osu.Game.Screens.Edit
return; return;
} }
beatDivisor.Value = loadableBeatmap.BeatmapInfo.BeatDivisor;
beatDivisor.BindValueChanged(divisor => loadableBeatmap.BeatmapInfo.BeatDivisor = divisor.NewValue);
// Todo: should probably be done at a DrawableRuleset level to share logic with Player.
clock = new EditorClock(loadableBeatmap, beatDivisor) { IsCoupled = false };
UpdateClockSource();
dependencies.CacheAs(clock);
AddInternal(clock);
clock.SeekingOrStopped.BindValueChanged(_ => updateSampleDisabledState());
// todo: remove caching of this and consume via editorBeatmap?
dependencies.Cache(beatDivisor);
try try
{ {
playableBeatmap = loadableBeatmap.GetPlayableBeatmap(loadableBeatmap.BeatmapInfo.Ruleset); playableBeatmap = loadableBeatmap.GetPlayableBeatmap(loadableBeatmap.BeatmapInfo.Ruleset);
@ -154,6 +138,22 @@ namespace osu.Game.Screens.Edit
return; return;
} }
beatDivisor.Value = playableBeatmap.BeatmapInfo.BeatDivisor;
beatDivisor.BindValueChanged(divisor => playableBeatmap.BeatmapInfo.BeatDivisor = divisor.NewValue);
// Todo: should probably be done at a DrawableRuleset level to share logic with Player.
clock = new EditorClock(playableBeatmap, beatDivisor) { IsCoupled = false };
UpdateClockSource();
dependencies.CacheAs(clock);
AddInternal(clock);
clock.SeekingOrStopped.BindValueChanged(_ => updateSampleDisabledState());
// todo: remove caching of this and consume via editorBeatmap?
dependencies.Cache(beatDivisor);
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.Skin)); AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.Skin));
dependencies.CacheAs(editorBeatmap); dependencies.CacheAs(editorBeatmap);
changeHandler = new EditorChangeHandler(editorBeatmap); changeHandler = new EditorChangeHandler(editorBeatmap);

View File

@ -42,12 +42,12 @@ namespace osu.Game.Screens.Edit
/// </summary> /// </summary>
public bool IsSeeking { get; private set; } public bool IsSeeking { get; private set; }
public EditorClock(WorkingBeatmap beatmap, BindableBeatDivisor beatDivisor) public EditorClock(IBeatmap beatmap, BindableBeatDivisor beatDivisor)
: this(beatmap.Beatmap.ControlPointInfo, beatmap.Track.Length, beatDivisor) : this(beatmap.ControlPointInfo, beatDivisor)
{ {
} }
public EditorClock(ControlPointInfo controlPointInfo, double trackLength, BindableBeatDivisor beatDivisor) public EditorClock(ControlPointInfo controlPointInfo, BindableBeatDivisor beatDivisor)
{ {
this.beatDivisor = beatDivisor; this.beatDivisor = beatDivisor;
@ -57,7 +57,7 @@ namespace osu.Game.Screens.Edit
} }
public EditorClock() public EditorClock()
: this(new ControlPointInfo(), 1000, new BindableBeatDivisor()) : this(new ControlPointInfo(), new BindableBeatDivisor())
{ {
} }

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual
protected EditorClockTestScene() protected EditorClockTestScene()
{ {
Clock = new EditorClock(new ControlPointInfo(), 5000, BeatDivisor) { IsCoupled = false }; Clock = new EditorClock(new ControlPointInfo(), BeatDivisor) { IsCoupled = false };
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)