-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cs
More file actions
114 lines (103 loc) · 3.16 KB
/
InputHandler.cs
File metadata and controls
114 lines (103 loc) · 3.16 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using FunkEngine;
using Godot;
/**
* <summary>InputHandler to handle note checkers, and bubble input events upwards.</summary>
*/
public partial class InputHandler : Node2D
{
[Signal]
public delegate void NotePressedEventHandler(ArrowType arrowType);
[Signal]
public delegate void NoteReleasedEventHandler(ArrowType arrowType);
public readonly CheckerData[] Arrows = new CheckerData[]
{
new CheckerData()
{
Color = Colors.Green,
Key = "arrowUp",
Type = ArrowType.Up,
},
new CheckerData()
{
Color = Colors.Aqua,
Key = "arrowDown",
Type = ArrowType.Down,
},
new CheckerData()
{
Color = Colors.HotPink,
Key = "arrowLeft",
Type = ArrowType.Left,
},
new CheckerData()
{
Color = Colors.Red,
Key = "arrowRight",
Type = ArrowType.Right,
},
};
private void InitializeArrowCheckers()
{
//Set the color of the arrows
for (int i = 0; i < Arrows.Length; i++)
{
Arrows[i].Node = GetNode<NoteChecker>("noteCheckers/" + Arrows[i].Key);
Arrows[i].Node.SetColor(Arrows[i].Color);
}
}
public override void _Ready()
{
InitializeArrowCheckers();
}
public override void _Process(double delta)
{
//TODO: Add change control scheme signal, so we don't query each frame.
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputType).As<string>();
if (Input.GetConnectedJoypads().Count <= 0 && scheme == "CONTROLLER")
{
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputType, "WASD");
}
foreach (var arrow in Arrows)
{
if (Input.IsActionJustPressed(scheme + "_" + arrow.Key))
{
EmitSignal(nameof(NotePressed), (int)arrow.Type);
arrow.Node.SetPressed(true);
}
else if (Input.IsActionJustReleased(scheme + "_" + arrow.Key))
{
EmitSignal(nameof(NoteReleased), (int)arrow.Type);
arrow.Node.SetPressed(false);
}
}
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventJoypadButton)
{ //Force Controller if controller was pressed
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputType, "CONTROLLER");
}
}
public void FeedbackEffect(ArrowType arrow, Timing timed)
{
// Get the particle node for this arrow
var particles = Arrows[(int)arrow].Node.Particles;
// Set the particle amount based on timing
int particleAmount;
switch (timed)
{
case Timing.Perfect:
particleAmount = 10;
break;
case Timing.Good:
particleAmount = 7;
break;
case Timing.Okay:
particleAmount = 4;
break;
default:
return;
}
particles.Emit(particleAmount);
}
}