-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cs
More file actions
127 lines (116 loc) · 3.47 KB
/
InputHandler.cs
File metadata and controls
127 lines (116 loc) · 3.47 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
117
118
119
120
121
122
123
124
125
126
127
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();
LoadControlScheme();
}
private void LoadControlScheme()
{
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
foreach (var arrow in Arrows)
{
var events = InputMap.ActionGetEvents(arrow.Key);
foreach (var inputEvent in events)
{
InputMap.ActionEraseEvent(arrow.Key, inputEvent);
}
}
var selectedScheme = ControlSchemes.Schemes[scheme];
foreach (var arrow in Arrows)
{
if (selectedScheme.ContainsKey(arrow.Key))
{
InputEventKey eventKey = new InputEventKey();
eventKey.Keycode = (Key)Enum.Parse(typeof(Key), selectedScheme[arrow.Key]);
InputMap.ActionAddEvent(arrow.Key, eventKey);
}
}
}
public override void _Process(double delta)
{
foreach (var arrow in Arrows)
{
if (Input.IsActionJustPressed(arrow.Key))
{
EmitSignal(nameof(NotePressed), (int)arrow.Type);
arrow.Node.SetPressed(true);
}
else if (Input.IsActionJustReleased(arrow.Key))
{
EmitSignal(nameof(NoteReleased), (int)arrow.Type);
arrow.Node.SetPressed(false);
}
}
}
}