-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathPlayerTouchInputDetector.cs
60 lines (47 loc) · 1.92 KB
/
PlayerTouchInputDetector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Rulesets.Mods;
using osu.Game.Utils;
namespace osu.Game.Screens.Play
{
public partial class PlayerTouchInputDetector : Component
{
[Resolved]
private Player player { get; set; } = null!;
[Resolved]
private GameplayState gameplayState { get; set; } = null!;
private IBindable<bool> touchActive = new BindableBool();
[BackgroundDependencyLoader]
private void load(SessionStatics statics)
{
touchActive = statics.GetBindable<bool>(Static.TouchInputActive);
touchActive.BindValueChanged(_ => updateState());
}
private void updateState()
{
if (!touchActive.Value)
return;
if (gameplayState.HasPassed || gameplayState.HasFailed || gameplayState.HasQuit)
return;
if (gameplayState.Score.ScoreInfo.Mods.OfType<ModTouchDevice>().Any())
return;
if (player.IsBreakTime.Value)
return;
var touchDeviceMod = gameplayState.Ruleset.GetTouchDeviceMod();
if (touchDeviceMod == null)
return;
var candidateMods = player.Score.ScoreInfo.Mods.Append(touchDeviceMod).ToArray();
if (!ModUtils.CheckCompatibleSet(candidateMods, out _))
return;
// `Player` (probably rightly so) assumes immutability of mods,
// so this will not be shown immediately on the mod display in the top right.
// if this is to change, the mod immutability should be revisited.
player.Score.ScoreInfo.Mods = candidateMods;
}
}
}