Skip to content

Commit

Permalink
1. Add more 4 cases
Browse files Browse the repository at this point in the history
2. Implemenrt change in gameplay.
  • Loading branch information
andy840119 committed Aug 2, 2020
1 parent 45a26d1 commit 69b31c8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 15 deletions.
4 changes: 4 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public class TestCaseSaitenStatus : OsuTestScene
[TestCase(SaitenStatusMode.OSXDoesNotSupported)]
[TestCase(SaitenStatusMode.WindowsMicrophonePermissionDeclined)]
[TestCase(SaitenStatusMode.NoMicrophoneDevice)]
[TestCase(SaitenStatusMode.NotSaitening)]
[TestCase(SaitenStatusMode.AutoPlay)]
[TestCase(SaitenStatusMode.Edit)]
[TestCase(SaitenStatusMode.Saitening)]
[TestCase(SaitenStatusMode.NotInitialized)]
public void TestMode(SaitenStatusMode mode)
{
AddStep("create mod display", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.UI.Components;

namespace osu.Game.Rulesets.Karaoke.Configuration
{
Expand Down Expand Up @@ -50,6 +51,9 @@ public KaraokeSessionStatics(KaraokeRulesetConfigManager config, IBeatmap beatma

// Practice
Set<LyricLine>(KaraokeRulesetSession.NowLyric, null);

// Saiten stsus
Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotInitialized);
}

private T getValue<T>(KaraokeRulesetSetting setting) => rulesetConfigManager.GetBindable<T>(setting).Value;
Expand All @@ -75,5 +79,8 @@ public enum KaraokeRulesetSession

// Practice
NowLyric,

// Saiten status
SaitenStatus,
}
}
35 changes: 29 additions & 6 deletions osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
using osu.Framework.Input.Handlers.Microphone;
using osu.Framework.Input.StateChanges.Events;
using osu.Framework.Input.States;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Input.Handlers;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.UI.Components;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Edit;
Expand All @@ -34,27 +36,48 @@ public KaraokeInputManager(RulesetInfo ruleset)
private IBeatmap beatmap;

[BackgroundDependencyLoader(true)]
private void load(KaraokeRulesetConfigManager config, IBindable<IReadOnlyList<Mod>> mods, IBindable<WorkingBeatmap> beatmap, EditorBeatmap editorBeatmap)
private void load(KaraokeRulesetConfigManager config, IBindable<IReadOnlyList<Mod>> mods, IBindable<WorkingBeatmap> beatmap, KaraokeSessionStatics session, EditorBeatmap editorBeatmap)
{
if (editorBeatmap != null)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Edit);
return;
}

this.beatmap = beatmap.Value.Beatmap;

var disableMicrophoneDeviceByMod = mods.Value.OfType<IApplicableToMicrophone>().Any(x => !x.MicrophoneEnabled);
if (disableMicrophoneDeviceByMod)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.AutoPlay);
return;
}


var beatmapSaitenable = beatmap.Value.Beatmap.IsScorable();
if (!beatmapSaitenable)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotSaitening);
return;
}

var selectedDevice = config.GetBindable<string>(KaraokeRulesetSetting.MicrophoneDevice).Value;
var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList();
try
{
var selectedDevice = config.GetBindable<string>(KaraokeRulesetSetting.MicrophoneDevice).Value;
var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList();

// Find index by selection id
var deviceIndex = microphoneList.IndexOf(selectedDevice);
AddHandler(new OsuTKMicrophoneHandler(deviceIndex));

// Find index by selection id
var deviceIndex = microphoneList.IndexOf(selectedDevice);
AddHandler(new OsuTKMicrophoneHandler(deviceIndex));
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Saitening);
}
catch(Exception ex)
{
Logger.Error(ex, "Microphone initialize error.");
// todo : set real error by exception
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.WindowsMicrophonePermissionDeclined);
}
}

protected override InputState CreateInitialState()
Expand Down
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

namespace osu.Game.Rulesets.Karaoke.Mods
{
public class KaraokeModDisableNote : Mod, IApplicableToHitObject, IApplicableToMicrophone
public class KaraokeModDisableNote : Mod, IApplicableToHitObject
{
public override string Name => "Disable note";
public override string Acronym => "DN";
public override double ScoreMultiplier => 0;
public override IconUsage? Icon => KaraokeIcon.ModDisableNote;
public override ModType Type => ModType.Fun;

public bool MicrophoneEnabled => false;

public void ApplyToHitObject(HitObject hitObject)
{
if (hitObject is Note note)
Expand Down
54 changes: 49 additions & 5 deletions osu.Game.Rulesets.Karaoke/UI/Components/SaitenStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@ public SaitenStatus(SaitenStatusMode statusMode)
Spacing = new Vector2(5);
Direction = FillDirection.Horizontal;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
SaitenStatusMode = statusMode;
}

private SaitenStatusMode statusMode;

public SaitenStatusMode SaitenStatusMode
{
get => statusMode;
set
{
CreateIcon(statusMode == SaitenStatusMode.Saitening),
CreateStatusSpriteText(GetSaitenStatusText(statusMode))
};
statusMode = value;
Children = new Drawable[]
{
CreateIcon(statusMode == SaitenStatusMode.Saitening),
CreateStatusSpriteText(GetSaitenStatusText(statusMode))
};
}
}

protected virtual string GetSaitenStatusText(SaitenStatusMode statusMode)
Expand All @@ -64,10 +76,18 @@ protected virtual string GetSaitenStatusText(SaitenStatusMode statusMode)
return "Osx device haven't support saiten system yet :(";
case SaitenStatusMode.WindowsMicrophonePermissionDeclined:
return "Open lazer with admin permission to enable saiten system.";
case SaitenStatusMode.NotSaitening:
return "This beatmap is not saitenable.";
case SaitenStatusMode.AutoPlay:
return "Auto play mode.";
case SaitenStatusMode.Edit:
return "Edit mode.";
case SaitenStatusMode.Saitening:
return "Saiteining...";
case SaitenStatusMode.NotInitialized:
return "Weird... Should not goes to here :thinking:";
default:
return "Oops...";
return "Weird... Should not goes to here either :oops:";
}
}

Expand Down Expand Up @@ -141,10 +161,34 @@ public enum SaitenStatusMode
[Description("No microphone device.")]
NoMicrophoneDevice,

/// <summary>
/// Beatmap is not scoring.
/// </summary>
[Description("No saitening.")]
NotSaitening,

/// <summary>
/// Beatmap is not scoring.
/// </summary>
[Description("Autoplay.")]
AutoPlay,

/// <summary>
/// In edit mode.
/// </summary>
[Description("Edit mode.")]
Edit,

/// <summary>
/// Everything works well.
/// </summary>
[Description("Saitening...")]
Saitening,

/// <summary>
/// Microphone statis is not initialized.
/// </summary>
[Description("Not initialized.")]
NotInitialized,
}
}
7 changes: 6 additions & 1 deletion osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public NotePlayfield(int columns)
},
}
},
new SaitenStatus(SaitenStatusMode.Saitening)
saitenStatus = new SaitenStatus(SaitenStatusMode.NotInitialized)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Expand Down Expand Up @@ -305,6 +305,11 @@ private void load(OsuColour colours, KaraokeSessionStatics session)
realTimeSaitenVisualization.LineColour = colours.Yellow;

session.BindWith(KaraokeRulesetSession.SaitenPitch, saitenPitch);

session.GetBindable<SaitenStatusMode>(KaraokeRulesetSession.SaitenStatus).BindValueChanged(e =>
{
saitenStatus.SaitenStatusMode = e.NewValue;
});
}

public bool OnPressed(KaraokeSaitenAction action)
Expand Down

0 comments on commit 69b31c8

Please sign in to comment.