1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneModPresetColumn.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

194 lines
6.9 KiB
C#
Raw Normal View History

// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
2022-07-24 00:01:11 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2022-07-24 00:01:11 +08:00
using osu.Framework.Testing;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
2022-07-24 00:01:11 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneModPresetColumn : OsuTestScene
{
2022-07-24 00:01:11 +08:00
protected override bool UseFreshStoragePerRun => true;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
2022-07-24 00:01:11 +08:00
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(Realm);
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("reset storage", () =>
{
Realm.Write(realm =>
{
realm.RemoveAll<ModPreset>();
realm.Add(createTestPresets());
});
});
}
[Test]
public void TestBasicOperation()
{
2022-07-24 00:01:11 +08:00
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddStep("create content", () => Child = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
2022-07-24 00:01:11 +08:00
Child = new ModPresetColumn
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
});
2022-07-24 00:01:11 +08:00
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
AddStep("change ruleset to mania", () => Ruleset.Value = rulesets.GetRuleset(3));
AddUntilStep("1 panel visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 1);
AddStep("add another mania preset", () => Realm.Write(r => r.Add(new ModPreset
{
Name = "and another one",
Mods = new Mod[]
{
new ManiaModMirror(),
new ManiaModNightcore(),
new ManiaModHardRock()
},
Ruleset = rulesets.GetRuleset(3).AsNonNull()
})));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("add another osu! preset", () => Realm.Write(r => r.Add(new ModPreset
{
Name = "hdhr",
Mods = new Mod[]
{
new OsuModHidden(),
new OsuModHardRock()
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
})));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("remove mania preset", () => Realm.Write(r =>
{
var toRemove = r.All<ModPreset>().Single(preset => preset.Name == "Different ruleset");
r.Remove(toRemove);
}));
AddUntilStep("1 panel visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 1);
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddUntilStep("4 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 4);
}
[Test]
public void TestSoftDeleteSupport()
{
AddStep("set osu! ruleset", () => Ruleset.Value = rulesets.GetRuleset(0));
AddStep("create content", () => Child = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
Child = new ModPresetColumn
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
});
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
AddStep("soft delete preset", () => Realm.Write(r =>
{
var toSoftDelete = r.All<ModPreset>().Single(preset => preset.Name == "AR0");
toSoftDelete.DeletePending = true;
}));
AddUntilStep("2 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
AddStep("soft delete all presets", () => Realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>())
preset.DeletePending = true;
}));
AddUntilStep("no panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 0);
AddStep("undelete preset", () => Realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>())
preset.DeletePending = false;
}));
AddUntilStep("3 panels visible", () => this.ChildrenOfType<ModPresetPanel>().Count() == 3);
}
2022-07-24 00:01:11 +08:00
private IEnumerable<ModPreset> createTestPresets() => new[]
{
new ModPreset
{
Name = "First preset",
Description = "Please ignore",
Mods = new Mod[]
{
new OsuModHardRock(),
new OsuModDoubleTime()
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "AR0",
Description = "For good readers",
Mods = new Mod[]
{
new OsuModDifficultyAdjust
{
ApproachRate = { Value = 0 }
}
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "This preset is going to have an extraordinarily long name",
Description = "This is done so that the capability to truncate overlong texts may be demonstrated",
Mods = new Mod[]
{
new OsuModFlashlight(),
new OsuModSpinIn()
2022-07-24 00:01:11 +08:00
},
Ruleset = rulesets.GetRuleset(0).AsNonNull()
},
new ModPreset
{
Name = "Different ruleset",
Description = "Just to shake things up",
Mods = new Mod[]
{
new ManiaModKey4(),
new ManiaModFadeIn()
},
Ruleset = rulesets.GetRuleset(3).AsNonNull()
}
};
}
}