// Copyright (c) ppy Pty Ltd . 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.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Objects; using osu.Game.Rulesets.Taiko.UI; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Taiko.Tests.Skinning { [TestFixture] public class TestSceneDrawableTaikoMascot : TaikoSkinnableTestScene { public override IReadOnlyList RequiredTypes => base.RequiredTypes.Concat(new[] { typeof(DrawableTaikoMascot), }).ToList(); [Cached(typeof(IScrollingInfo))] private ScrollingTestContainer.TestScrollingInfo info = new ScrollingTestContainer.TestScrollingInfo { Direction = { Value = ScrollingDirection.Left }, TimeRange = { Value = 5000 }, }; private IEnumerable mascots => this.ChildrenOfType(); private IEnumerable playfields => this.ChildrenOfType(); [Test] public void TestStateTextures() { AddStep("set beatmap", () => setBeatmap()); AddStep("create mascot", () => { SetContents(() => new TestDrawableTaikoMascot()); }); AddStep("clear state", () => setState(TaikoMascotAnimationState.Clear)); AddStep("kiai state", () => setState(TaikoMascotAnimationState.Kiai)); AddStep("fail state", () => setState(TaikoMascotAnimationState.Fail)); AddStep("idle state", () => setState(TaikoMascotAnimationState.Idle)); } [Test] public void TestPlayfield() { AddStep("set beatmap", () => setBeatmap()); AddStep("create drawable ruleset", () => { SetContents(() => { var ruleset = new TaikoRuleset(); return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo)); }); }); AddStep("new judgement (miss)", () => addJudgement(HitResult.Miss)); AddUntilStep("wait for fail state", () => assertState(TaikoMascotAnimationState.Fail)); AddStep("new judgement (great)", () => addJudgement(HitResult.Great)); AddUntilStep("wait for idle state", () => assertState(TaikoMascotAnimationState.Idle)); } [Test] public void TestKiai() { AddStep("set beatmap", () => setBeatmap(true)); AddUntilStep("wait for beatmap to be loaded", () => Beatmap.Value.Track.IsLoaded); AddStep("create drawable ruleset", () => { Beatmap.Value.Track.Start(); SetContents(() => { var ruleset = new TaikoRuleset(); return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo)); }); }); AddUntilStep("wait for fail state", () => assertState(TaikoMascotAnimationState.Fail)); AddStep("new judgement (great)", () => addJudgement(HitResult.Great)); AddUntilStep("wait for kiai state", () => assertState(TaikoMascotAnimationState.Kiai)); } private void setBeatmap(bool kiai = false) { var controlPointInfo = new ControlPointInfo(); controlPointInfo.Add(0, new TimingControlPoint { BeatLength = 90 }); if (kiai) controlPointInfo.Add(0, new EffectControlPoint { KiaiMode = true }); Beatmap.Value = CreateWorkingBeatmap(new Beatmap { HitObjects = new List { new Hit { Type = HitType.Centre } }, BeatmapInfo = new BeatmapInfo { BaseDifficulty = new BeatmapDifficulty(), Metadata = new BeatmapMetadata { Artist = @"Unknown", Title = @"Sample Beatmap", AuthorString = @"Craftplacer", }, Ruleset = new TaikoRuleset().RulesetInfo }, ControlPointInfo = controlPointInfo }); } private void setState(TaikoMascotAnimationState state) { foreach (var mascot in mascots) mascot.State.Value = state; } private void addJudgement(HitResult result) { foreach (var playfield in playfields) { var hit = new DrawableTestHit(new Hit(), result); Add(hit); playfield.OnNewResult(hit, new JudgementResult(hit.HitObject, new TaikoJudgement()) { Type = result }); } } private bool assertState(TaikoMascotAnimationState state) => mascots.All(d => d.State.Value == state); private class TestDrawableTaikoMascot : DrawableTaikoMascot { public TestDrawableTaikoMascot(TaikoMascotAnimationState startingState = TaikoMascotAnimationState.Idle) : base(startingState) { } public new Bindable State => base.State; } } }