Skip to content

Commit

Permalink
Merge pull request #1811 from andy840119/apply-auto-generator-into-ed…
Browse files Browse the repository at this point in the history
…itor

Apply auto generator into editor.
  • Loading branch information
andy840119 authored Dec 24, 2022
2 parents c735b37 + 775ca74 commit aba9146
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Testing;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
Expand Down Expand Up @@ -71,6 +72,20 @@ public virtual void SetUp()
});
}

protected virtual bool IncludeAutoGenerator => false;

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
if (!IncludeAutoGenerator)
{
return base.CreateChildDependencies(parent);
}

var baseDependencies = new DependencyContainer(base.CreateChildDependencies(parent));
baseDependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager());
return baseDependencies;
}

protected void SetUpEditorBeatmap(Action<EditorBeatmap> action)
{
AddStep("Prepare testing beatmap", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,43 @@
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Tests.Helper;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Beatmaps;

public partial class BeatmapPagesChangeHandlerTest : BaseChangeHandlerTest<BeatmapPagesChangeHandler>
{
protected override bool IncludeAutoGenerator => true;

[Test]
public void TestGeneratePage()
{
PrepareHitObject(TestCaseTagHelper.ParseLyric("[1000,3000]:karaoke"), false);

TriggerHandlerChanged(c => c.AutoGenerate());

AssertKaraokeBeatmap(karaokeBeatmap =>
{
var pages = karaokeBeatmap.PageInfo.SortedPages;

Assert.AreEqual(2, pages.Count);

Assert.AreEqual(1000, pages[0].Time);
Assert.AreEqual(3000, pages[1].Time);
});
}

[Test]
public void TestGeneratePageWithInvalidCase()
{
// there's no time-info inside.
PrepareHitObject(new Lyric(), false);

TriggerHandlerChangedWithException<NotGeneratableException>(c => c.AutoGenerate());
}

[Test]
public void TestAdd()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Edit.Utils;
Expand All @@ -18,12 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics
{
public partial class LyricAutoGenerateChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricAutoGenerateChangeHandler>
{
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var baseDependencies = new DependencyContainer(base.CreateChildDependencies(parent));
baseDependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager());
return baseDependencies;
}
protected override bool IncludeAutoGenerator => true;

#region Reference lyric

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.Screens.Edit.Beatmap.Configs;

[TestFixture]
public partial class TestSceneBeatmapGeneratorConfigDialog : OsuTestScene
{
[BackgroundDependencyLoader]
private void load()
{
var config = new KaraokeRulesetEditGeneratorConfigManager();
Dependencies.Cache(config);
}

[TestCase(typeof(PageGeneratorConfigDialog), TestName = nameof(PageGeneratorConfigDialog))]
public void TestGenerate(Type configType)
{
AddStep("Show dialog", () =>
{
Schedule(() =>
{
Child = Activator.CreateInstance(configType) as Drawable;
Child?.Show();
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps;
using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages;

Expand Down Expand Up @@ -58,6 +59,7 @@ private void load()

Dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
Dependencies.CacheAs<ILyricsProvider>(lyricsProvider);
Dependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric;
Expand All @@ -19,6 +20,9 @@ protected override void InitialiseDefaults()
{
base.InitialiseDefaults();

// Beatmap page
SetDefault(KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig, CreateDefaultConfig<PageGeneratorConfig>());

// Language detection
SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig<ReferenceLyricDetectorConfig>());

Expand All @@ -37,6 +41,9 @@ protected override void InitialiseDefaults()
// Time tag generator
SetDefault(KaraokeRulesetEditGeneratorSetting.JaTimeTagGeneratorConfig, CreateDefaultConfig<JaTimeTagGeneratorConfig>());
SetDefault(KaraokeRulesetEditGeneratorSetting.ZhTimeTagGeneratorConfig, CreateDefaultConfig<ZhTimeTagGeneratorConfig>());

// Language detection
SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig<ReferenceLyricDetectorConfig>());
}

protected static T CreateDefaultConfig<T>() where T : IHasConfig<T>, new()
Expand All @@ -45,6 +52,9 @@ protected override void InitialiseDefaults()

public enum KaraokeRulesetEditGeneratorSetting
{
// Beatmap
BeatmapPageGeneratorConfig,

// Reference lyric detection.
ReferenceLyricDetectorConfig,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,46 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages;

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;

public partial class BeatmapPagesChangeHandler : BeatmapPropertyChangeHandler, IBeatmapPagesChangeHandler
{
[Resolved, AllowNull]
private KaraokeRulesetEditGeneratorConfigManager generatorConfigManager { get; set; }

public LocalisableString? GetNotGeneratableMessage()
{
var config = getGeneratorConfig();
var generator = new PageGenerator(config);
return generator.GetInvalidMessage(KaraokeBeatmap);
}

public void AutoGenerate()
{
var config = getGeneratorConfig();
var generator = new PageGenerator(config);
var pages = generator.Generate(KaraokeBeatmap);

performPageInfoChanged(pageInfo =>
{
if (config.ClearExistPages)
pageInfo.Pages.Clear();

pageInfo.Pages.AddRange(pages);
});
}

private PageGeneratorConfig getGeneratorConfig()
=> generatorConfigManager.Get<PageGeneratorConfig>(KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig);

public void Add(Page page)
{
performPageInfoChanged(pageInfo =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Localisation;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps;

public interface IBeatmapPagesChangeHandler
{
LocalisableString? GetNotGeneratableMessage();

void AutoGenerate();

void Add(Page page);

void Remove(Page page);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Karaoke.Edit.Checks;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages;

public partial class GenericSection : GeneratorConfigSection<PageGeneratorConfig>
{
private readonly LabelledSliderBar<double> minTimeTextBox;
private readonly LabelledSliderBar<double> maxTimeTextButton;
private readonly LabelledSwitchButton clearExistPagesSwitchButton;

protected override string Title => "Generic";

public GenericSection(Bindable<PageGeneratorConfig> current)
: base(current)
{
Children = new Drawable[]
{
minTimeTextBox = new LabelledSliderBar<double>
{
Label = "Min time",
Description = "Min interval between pages.",
Current = new BindableDouble
{
MinValue = CheckBeatmapPageInfo.MIN_INTERVAL,
MaxValue = CheckBeatmapPageInfo.MAX_INTERVAL,
Precision = 0.1f,
}
},
maxTimeTextButton = new LabelledSliderBar<double>
{
Label = "Max time",
Description = "Max interval between pages.",
Current = new BindableDouble
{
MinValue = CheckBeatmapPageInfo.MIN_INTERVAL,
MaxValue = CheckBeatmapPageInfo.MAX_INTERVAL,
Precision = 0.1f,
}
},
clearExistPagesSwitchButton = new LabelledSwitchButton
{
Label = "Clear the exist page.",
Description = "Clear the exist page after generated.",
},
};

RegisterConfig(minTimeTextBox.Current, nameof(PageGeneratorConfig.MinTime));
RegisterConfig(maxTimeTextButton.Current, nameof(PageGeneratorConfig.MaxTime));
RegisterConfig(clearExistPagesSwitchButton.Current, nameof(PageGeneratorConfig.ClearExistPages));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Game.Overlays;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages
{
public partial class PageGeneratorConfigDialog : GeneratorConfigDialog<PageGeneratorConfig>
{
protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig;

protected override OverlayColourScheme OverlayColourScheme => OverlayColourScheme.Green;

protected override string Title => "Page generator config.";

protected override string Description => "Change config for page generator.";

protected override GeneratorConfigSection[] CreateConfigSection(Bindable<PageGeneratorConfig> current)
{
return new GeneratorConfigSection[]
{
new GenericSection(current),
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages
{
public partial class PageGeneratorConfigPopover : GeneratorConfigPopover<PageGeneratorConfig>
{
protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig;

protected override GeneratorConfigSection[] CreateConfigSection(Bindable<PageGeneratorConfig> current)
{
return new GeneratorConfigSection[]
{
new GenericSection(current),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages;

public enum PageEditorEditMode
{
Generate,

Edit,

Verify
Expand Down
Loading

0 comments on commit aba9146

Please sign in to comment.