1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 14:12:55 +08:00

Fix regression in testing logic

This commit is contained in:
Dean Herbert 2018-11-06 18:32:59 +09:00
parent 5a4292717f
commit afb3b38098
6 changed files with 247 additions and 178 deletions

View File

@ -9,8 +9,7 @@ namespace osu.Game.Tournament.Tests
{
public class LadderTestCase : OsuTestCase
{
[Resolved]
protected LadderInfo Ladder { get; set; }
protected LadderInfo Ladder { get; private set; }
}
}

View File

@ -25,7 +25,13 @@ namespace osu.Game.Tournament.Tests
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Ladder = manager.CreateInfo();
var newInfo = manager.CreateInfo();
Ladder.Teams = newInfo.Teams;
Ladder.Groupings = newInfo.Groupings;
Ladder.Pairings = newInfo.Pairings;
Ladder.Progressions = newInfo.Progressions;
}
}
}

View File

@ -7,7 +7,7 @@ using osu.Game.Screens.Backgrounds;
namespace osu.Game.Tournament.Tests
{
public class TournamentTestBrowser : TournamentGame
public class TournamentTestBrowser : TournamentGameBase
{
protected override void LoadComplete()
{

View File

@ -23,77 +23,116 @@ using OpenTK;
namespace osu.Game.Tournament.Screens.Showcase
{
public class ShowcaseScreen : OsuScreen
public class SongBar : CompositeDrawable
{
private readonly Container panel;
private readonly Container panelContents;
private BeatmapInfo beatmap;
[Resolved]
private APIAccess api { get; set; }
public BeatmapInfo Beatmap
{
get { return beatmap; }
set
{
if (beatmap == value)
return;
[Resolved]
private RulesetStore rulesets { get; set; }
beatmap = value;
update();
}
}
private int lastBeatmapId;
private int lastMods;
private LegacyMods mods;
public LegacyMods Mods
{
get { return mods; }
set
{
mods = value;
update();
}
}
private Container panelContents;
[BackgroundDependencyLoader]
private void load()
{
var stable = new StableStorage();
RelativeSizeAxes = Axes.Both;
const string file_ipc_filename = "ipc.txt";
if (stable.Exists(file_ipc_filename))
InternalChildren = new Drawable[]
{
Scheduler.AddDelayed(delegate
new Container
{
try
Masking = true,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -10,
Width = 0.95f,
Height = TournamentBeatmapPanel.HEIGHT,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Children = new Drawable[]
{
using (var stream = stable.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
new Box
{
var beatmapId = int.Parse(sr.ReadLine());
var mods = int.Parse(sr.ReadLine());
if (lastBeatmapId == beatmapId)
return;
lastMods = mods;
lastBeatmapId = beatmapId;
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
req.Success += success;
api.Queue(req);
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.93f),
},
new Container
{
Masking = true,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.7f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.86f),
},
panelContents = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
},
new OsuLogo
{
Triangles = false,
Colour = OsuColour.Gray(0.33f),
Scale = new Vector2(0.08f),
Margin = new MarginPadding(50),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
}
catch
{
// file might be in use.
}
}, 250, true);
}
}
};
}
private void success(APIBeatmap apiBeatmap)
private void update()
{
panel.FadeInFromZero(300, Easing.OutQuint);
if (beatmap == null)
{
panelContents.Clear();
return;
}
var beatmap = apiBeatmap.ToBeatmap(rulesets);
var legacyMods = (LegacyMods)lastMods;
var bpm = beatmap.BeatmapSet.OnlineInfo.BPM;
var length = beatmap.OnlineInfo.Length;
string extra = "";
var ar = beatmap.BaseDifficulty.ApproachRate;
if ((legacyMods & LegacyMods.HardRock) > 0)
if ((mods & LegacyMods.HardRock) > 0)
{
//ar *= 1.4f;
extra = "*";
}
if ((legacyMods & LegacyMods.DoubleTime) > 0)
if ((mods & LegacyMods.DoubleTime) > 0)
{
//ar *= 1.5f;
bpm *= 1.5f;
@ -142,63 +181,73 @@ namespace osu.Game.Tournament.Screens.Showcase
}
};
}
}
public class ShowcaseScreen : OsuScreen
{
[Resolved]
private APIAccess api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }
private int lastBeatmapId;
private int lastMods;
private readonly SongBar songBar;
public ShowcaseScreen()
{
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
Add(songBar = new SongBar
{
new Container
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre
});
}
[BackgroundDependencyLoader]
private void load()
{
var stable = new StableStorage();
const string file_ipc_filename = "ipc.txt";
if (stable.Exists(file_ipc_filename))
{
Scheduler.AddDelayed(delegate
{
Masking = true,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -10,
Width = 0.95f,
Height = TournamentBeatmapPanel.HEIGHT,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Children = new Drawable[]
try
{
new Box
using (var stream = stable.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.93f),
},
panel = new Container
{
Masking = true,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.7f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.86f),
},
panelContents = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
},
new OsuLogo
{
Triangles = false,
Colour = OsuColour.Gray(0.33f),
Scale = new Vector2(0.08f),
Margin = new MarginPadding(50),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
var beatmapId = int.Parse(sr.ReadLine());
var mods = int.Parse(sr.ReadLine());
if (lastBeatmapId == beatmapId)
return;
lastMods = mods;
lastBeatmapId = beatmapId;
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
req.Success += success;
api.Queue(req);
}
}
}
};
catch
{
// file might be in use.
}
}, 250, true);
}
}
private void success(APIBeatmap apiBeatmap)
{
songBar.FadeInFromZero(300, Easing.OutQuint);
songBar.Mods = (LegacyMods)lastMods;
songBar.Beatmap = apiBeatmap.ToBeatmap(rulesets);
}
/// <summary>

View File

@ -1,81 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Tournament.Screens;
using osu.Game.Tournament.Screens.Ladder.Components;
namespace osu.Game.Tournament
{
public class TournamentGame : OsuGameBase
public class TournamentGame : TournamentGameBase
{
private const string bracket_filename = "bracket.json";
protected LadderInfo Ladder;
private Storage storage;
private DependencyContainer dependencies;
[Cached]
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
[BackgroundDependencyLoader]
private void load(Storage storage)
{
this.storage = storage;
string content = null;
if (storage.Exists(bracket_filename))
{
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
content = sr.ReadToEnd();
}
Ladder = content != null ? JsonConvert.DeserializeObject<LadderInfo>(content) : new LadderInfo();
dependencies.Cache(Ladder);
bool addedInfo = false;
foreach (var g in Ladder.Groupings)
foreach (var b in g.Beatmaps)
{
if (b.BeatmapInfo == null)
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
req.Success += i => b.BeatmapInfo = i.ToBeatmap(RulesetStore);
req.Perform(API);
addedInfo = true;
}
}
if (addedInfo)
SaveChanges();
Add(new OsuButton
{
Text = "Save Changes",
Width = 140,
Height = 50,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Padding = new MarginPadding(10),
Action = SaveChanges,
});
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -83,19 +14,5 @@ namespace osu.Game.Tournament
MenuCursorContainer.Cursor.Alpha = 0;
}
protected virtual void SaveChanges()
{
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(Ladder,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
}));
}
}
}
}

View File

@ -0,0 +1,98 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Tournament.Screens.Ladder.Components;
namespace osu.Game.Tournament
{
public abstract class TournamentGameBase : OsuGameBase
{
private const string bracket_filename = "bracket.json";
protected LadderInfo Ladder;
private Storage storage;
private DependencyContainer dependencies;
[Cached]
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
return dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
}
[BackgroundDependencyLoader]
private void load(Storage storage)
{
this.storage = storage;
string content = null;
if (storage.Exists(bracket_filename))
using (Stream stream = storage.GetStream(bracket_filename, FileAccess.Read, FileMode.Open))
using (var sr = new StreamReader(stream))
{
content = sr.ReadToEnd();
}
Ladder = content != null ? JsonConvert.DeserializeObject<LadderInfo>(content) : new LadderInfo();
dependencies.Cache(Ladder);
bool addedInfo = false;
foreach (var g in Ladder.Groupings)
foreach (var b in g.Beatmaps)
if (b.BeatmapInfo == null)
{
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
req.Success += i => b.BeatmapInfo = i.ToBeatmap(RulesetStore);
req.Perform(API);
addedInfo = true;
}
if (addedInfo)
SaveChanges();
Add(new OsuButton
{
Text = "Save Changes",
Width = 140,
Height = 50,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Padding = new MarginPadding(10),
Action = SaveChanges,
});
}
protected override void LoadComplete()
{
MenuCursorContainer.Cursor.Alpha = 0;
}
protected virtual void SaveChanges()
{
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
using (var sw = new StreamWriter(stream))
{
sw.Write(JsonConvert.SerializeObject(Ladder,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore
}));
}
}
}
}