mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 08:22:56 +08:00
refactor down
and wasLeft
management into respective PressHandler
classes
This commit is contained in:
parent
581ae2f679
commit
2a02566283
@ -39,6 +39,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
private double lastStateChangeTime;
|
private double lastStateChangeTime;
|
||||||
|
|
||||||
private DrawableOsuRuleset ruleset = null!;
|
private DrawableOsuRuleset ruleset = null!;
|
||||||
|
private PressHandler pressHandler = null!;
|
||||||
|
|
||||||
private bool hasReplay;
|
private bool hasReplay;
|
||||||
private bool legacyReplay;
|
private bool legacyReplay;
|
||||||
@ -56,10 +57,16 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
if (osuInputManager.ReplayInputHandler != null)
|
if (osuInputManager.ReplayInputHandler != null)
|
||||||
{
|
{
|
||||||
hasReplay = true;
|
hasReplay = true;
|
||||||
|
|
||||||
|
Debug.Assert(ruleset.ReplayScore != null);
|
||||||
legacyReplay = ruleset.ReplayScore.ScoreInfo.IsLegacyScore;
|
legacyReplay = ruleset.ReplayScore.ScoreInfo.IsLegacyScore;
|
||||||
|
|
||||||
|
pressHandler = new LegacyReplayPressHandler(this);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pressHandler = new PressHandler(this);
|
||||||
osuInputManager.AllowGameplayInputs = false;
|
osuInputManager.AllowGameplayInputs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,20 +138,6 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
isDownState = down;
|
isDownState = down;
|
||||||
lastStateChangeTime = time;
|
lastStateChangeTime = time;
|
||||||
|
|
||||||
// legacy replays do not contain key-presses with Relax mod, so they need to be triggered by themselves.
|
|
||||||
if (legacyReplay)
|
|
||||||
{
|
|
||||||
if (!down)
|
|
||||||
{
|
|
||||||
osuInputManager.KeyBindingContainer.TriggerReleased(wasLeft ? OsuAction.RightButton : OsuAction.LeftButton);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
osuInputManager.KeyBindingContainer.TriggerPressed(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
|
|
||||||
wasLeft = !wasLeft;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
state = new ReplayState<OsuAction>
|
state = new ReplayState<OsuAction>
|
||||||
{
|
{
|
||||||
PressedActions = new List<OsuAction>()
|
PressedActions = new List<OsuAction>()
|
||||||
@ -152,11 +145,53 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
|
|
||||||
if (down)
|
if (down)
|
||||||
{
|
{
|
||||||
state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
|
pressHandler.HandlePress(wasLeft);
|
||||||
wasLeft = !wasLeft;
|
wasLeft = !wasLeft;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pressHandler.HandleRelease(wasLeft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
state.Apply(osuInputManager.CurrentState, osuInputManager);
|
private class PressHandler
|
||||||
|
{
|
||||||
|
protected readonly OsuModRelax Mod;
|
||||||
|
|
||||||
|
public PressHandler(OsuModRelax mod)
|
||||||
|
{
|
||||||
|
Mod = mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void HandlePress(bool wasLeft)
|
||||||
|
{
|
||||||
|
Mod.state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
|
||||||
|
Mod.state.Apply(Mod.osuInputManager.CurrentState, Mod.osuInputManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void HandleRelease(bool wasLeft)
|
||||||
|
{
|
||||||
|
Mod.state.Apply(Mod.osuInputManager.CurrentState, Mod.osuInputManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// legacy replays do not contain key-presses with Relax mod, so they need to be triggered by themselves.
|
||||||
|
private class LegacyReplayPressHandler : PressHandler
|
||||||
|
{
|
||||||
|
public LegacyReplayPressHandler(OsuModRelax mod)
|
||||||
|
: base(mod)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandlePress(bool wasLeft)
|
||||||
|
{
|
||||||
|
Mod.osuInputManager.KeyBindingContainer.TriggerPressed(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleRelease(bool wasLeft)
|
||||||
|
{
|
||||||
|
Mod.osuInputManager.KeyBindingContainer.TriggerReleased(wasLeft ? OsuAction.RightButton : OsuAction.LeftButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user