-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cs
More file actions
116 lines (105 loc) · 3.16 KB
/
InputHandler.cs
File metadata and controls
116 lines (105 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
115
116
using System;
using System.Collections.Generic;
using FunkEngine;
using Godot;
/**
* @class InputHandler
* @brief InputHandler to handle input, and manage note checkers. WIP
*/
public partial class InputHandler : Node2D
{
[Signal]
public delegate void NotePressedEventHandler(ArrowType arrowType);
[Signal]
public delegate void NoteReleasedEventHandler(ArrowType arrowType);
public ArrowData[] Arrows = new ArrowData[]
{
new ArrowData()
{
Color = Colors.Green,
Key = "arrowUp",
Type = ArrowType.Up,
},
new ArrowData()
{
Color = Colors.Aqua,
Key = "arrowDown",
Type = ArrowType.Down,
},
new ArrowData()
{
Color = Colors.HotPink,
Key = "arrowLeft",
Type = ArrowType.Left,
},
new ArrowData()
{
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 void FeedbackEffect(ArrowType arrow, string text)
{
// Get the particle node for this arrow
var particles = Arrows[(int)arrow].Node.Particles;
// Set the particle amount based on timing
int particleAmount;
switch (text)
{
case "Perfect":
particleAmount = 10; // A lot of particles for Perfect
break;
case "Great":
particleAmount = 7; // Moderate amount for Great
break;
case "Good":
particleAmount = 4; // Few particles for Good
break;
default:
return; // No particles for a miss
}
particles.Emit(particleAmount);
}
public override void _Ready()
{
InitializeArrowCheckers();
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventJoypadButton)
{
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "CONTROLLER");
}
}
public override void _Process(double delta)
{
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
if (Input.GetConnectedJoypads().Count <= 0 && scheme == "CONTROLLER")
{
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "ARROWS");
}
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);
}
}
}
}