mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Make saving the ladder to disk a button-based operation rather than on dispose
This commit is contained in:
parent
77055f6d5c
commit
c26d226a75
43
osu.Game.Tournament.Tests/LadderTestCase.cs
Normal file
43
osu.Game.Tournament.Tests/LadderTestCase.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
|
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests
|
||||||
|
{
|
||||||
|
public abstract class LadderTestCase : OsuTestCase
|
||||||
|
{
|
||||||
|
protected LadderInfo Ladder;
|
||||||
|
|
||||||
|
protected LadderTestCase()
|
||||||
|
{
|
||||||
|
Ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
|
||||||
|
|
||||||
|
Add(new OsuButton
|
||||||
|
{
|
||||||
|
Text = "Save Changes",
|
||||||
|
Width = 140,
|
||||||
|
Height = 50,
|
||||||
|
Anchor = Anchor.BottomRight,
|
||||||
|
Origin = Anchor.BottomRight,
|
||||||
|
Padding = new MarginPadding(10),
|
||||||
|
Action = SaveChanges,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void SaveChanges()
|
||||||
|
{
|
||||||
|
File.WriteAllText(@"bracket.json", JsonConvert.SerializeObject(Ladder,
|
||||||
|
new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +1,31 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Tests.Visual;
|
|
||||||
using osu.Game.Tournament.Screens.Ladder;
|
using osu.Game.Tournament.Screens.Ladder;
|
||||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests
|
namespace osu.Game.Tournament.Tests
|
||||||
{
|
{
|
||||||
public class TestCaseLadderManager : OsuTestCase
|
public class TestCaseLadderManager : LadderTestCase
|
||||||
{
|
{
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly LadderManager manager;
|
private readonly LadderManager manager;
|
||||||
|
|
||||||
public TestCaseLadderManager()
|
public TestCaseLadderManager()
|
||||||
{
|
{
|
||||||
var ladder = File.Exists(@"bracket.json") ? JsonConvert.DeserializeObject<LadderInfo>(File.ReadAllText(@"bracket.json")) : new LadderInfo();
|
Add(new OsuContextMenuContainer
|
||||||
|
|
||||||
Child = new OsuContextMenuContainer
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = manager = new LadderManager(ladder)
|
Child = manager = new LadderManager(Ladder)
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void SaveChanges()
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
Ladder = manager.CreateInfo();
|
||||||
|
base.SaveChanges();
|
||||||
File.WriteAllText(@"bracket.json", JsonConvert.SerializeObject(manager.CreateInfo(),
|
|
||||||
new JsonSerializerSettings
|
|
||||||
{
|
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
|
||||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user