Skip to content

Commit e3070c2

Browse files
committed
Organization
1 parent 1f507de commit e3070c2

2 files changed

Lines changed: 69 additions & 68 deletions

File tree

scenes/BattleDirector/BattleDirector.cs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
public partial class BattleDirector : Node2D
1212
{
13+
#region Declarations
1314
private HealthBar Player;
1415
private HealthBar Enemy;
1516

@@ -37,7 +38,9 @@ public struct SongData
3738
public double SongLength;
3839
public int NumLoops;
3940
}
41+
#endregion
4042

43+
#region Note Handling
4144
//Assume queue structure for notes in each lane.
4245
//Can eventually make this its own structure
4346
private readonly NoteArrow[][] _laneData = new NoteArrow[][]
@@ -72,6 +75,36 @@ private Note GetNote(NoteArrow arrow)
7275
return _notes[arrow.NoteIdx];
7376
}
7477

78+
private bool AddNoteToLane(Note note)
79+
{
80+
//Don't add dupe notes
81+
if (_notes.Any(nt => nt.Type == note.Type && nt.Beat == note.Beat))
82+
{
83+
return false;
84+
}
85+
_notes = _notes.Append(note).ToArray();
86+
//Get noteArrow from CM
87+
var arrow = CM.AddArrowToLane(note, _notes.Length - 1);
88+
_laneData[(int)note.Type] = _laneData[(int)note.Type].Append(arrow).ToArray();
89+
return true;
90+
}
91+
#endregion
92+
93+
//Creeate dummy notes
94+
private void AddExampleNote()
95+
{
96+
for (int i = 0; i < 4; i++)
97+
{
98+
Note exampleNote = new Note(NoteArrow.ArrowType.Up, i + 3);
99+
AddNoteToLane(exampleNote);
100+
}
101+
for (int i = 0; i < 1; i++)
102+
{
103+
Note exampleNote = new Note(NoteArrow.ArrowType.Left, i + 4);
104+
AddNoteToLane(exampleNote);
105+
}
106+
}
107+
75108
public override void _Ready()
76109
{
77110
_curSong = new SongData
@@ -97,34 +130,7 @@ public override void _Process(double delta)
97130
CheckMiss();
98131
}
99132

100-
//Creeate dummy notes
101-
private void AddExampleNote()
102-
{
103-
for (int i = 0; i < 4; i++)
104-
{
105-
Note exampleNote = new Note(NoteArrow.ArrowType.Up, i + 3);
106-
AddNoteToLane(exampleNote);
107-
}
108-
for (int i = 0; i < 1; i++)
109-
{
110-
Note exampleNote = new Note(NoteArrow.ArrowType.Left, i + 4);
111-
AddNoteToLane(exampleNote);
112-
}
113-
}
114-
115-
private bool AddNoteToLane(Note note)
116-
{
117-
//Don't add dupe notes
118-
if (_notes.Any(nt => nt.Type == note.Type && nt.Beat == note.Beat))
119-
{
120-
return false;
121-
}
122-
_notes = _notes.Append(note).ToArray();
123-
//Get noteArrow from CM
124-
var arrow = CM.AddArrowToLane(note, _notes.Length - 1);
125-
_laneData[(int)note.Type] = _laneData[(int)note.Type].Append(arrow).ToArray();
126-
return true;
127-
}
133+
#region Input
128134

129135
private void OnNotePressed(NoteArrow.ArrowType type)
130136
{
@@ -149,6 +155,19 @@ private void CheckMiss()
149155
}
150156
}
151157

158+
private void CheckNoteTiming(NoteArrow.ArrowType type)
159+
{
160+
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
161+
if (_laneData[(int)type].Length == 0)
162+
return;
163+
double beatDif = Math.Abs(curBeat - GetFirstNote(type).Beat);
164+
if (beatDif > 1)
165+
return;
166+
GD.Print("Note Hit. Dif: " + beatDif);
167+
_laneData[(int)type].First().NoteHit();
168+
HandleTiming(type, beatDif);
169+
}
170+
152171
private void HandleTiming(NoteArrow.ArrowType type, double beatDif)
153172
{
154173
//Cycle note queue
@@ -179,25 +198,7 @@ private void HandleTiming(NoteArrow.ArrowType type, double beatDif)
179198
NotePlacementBar.MissNote();
180199
}
181200
}
182-
183-
private void CheckNoteTiming(NoteArrow.ArrowType type)
184-
{
185-
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm);
186-
if (_laneData[(int)type].Length == 0)
187-
{
188-
PlayerAddNote(type, (int)curBeat);
189-
return;
190-
}
191-
double beatDif = Math.Abs(curBeat - GetFirstNote(type).Beat);
192-
if (beatDif > 1)
193-
{
194-
PlayerAddNote(type, (int)curBeat);
195-
return;
196-
}
197-
GD.Print("Note Hit. Dif: " + beatDif);
198-
_laneData[(int)type].First().NoteHit();
199-
HandleTiming(type, beatDif);
200-
}
201+
#endregion
201202

202203
private void PlayerAddNote(NoteArrow.ArrowType type, int beat)
203204
{

scenes/ChartViewport/ChartManager.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ public partial class ChartManager : SubViewportContainer
2727
private double _loopLen; //secs
2828
public int BeatsPerLoop;
2929

30-
private void InitBackgrounds()
30+
public void OnNotePressed(ArrowType type)
3131
{
32-
int i = 0;
33-
foreach (Node child in ChartLoopables.GetChildren())
34-
{
35-
if (child is not Loopable)
36-
continue;
37-
Loopable loopable = (Loopable)child;
38-
loopable.SetSize(new Vector2((float)ChartLength / 2 + 1, Size.Y));
39-
loopable.Bounds = (float)ChartLength / 2 * i;
40-
i++;
41-
}
32+
EmitSignal(nameof(NotePressed), (int)type);
33+
}
34+
35+
public void OnNoteReleased(ArrowType type)
36+
{
37+
EmitSignal(nameof(NoteReleased), (int)type);
4238
}
4339

4440
public void PrepChart(BattleDirector.SongData songData)
@@ -55,6 +51,20 @@ public void PrepChart(BattleDirector.SongData songData)
5551
IH.Connect(nameof(InputHandler.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
5652
}
5753

54+
private void InitBackgrounds()
55+
{
56+
int i = 0;
57+
foreach (Node child in ChartLoopables.GetChildren())
58+
{
59+
if (child is not Loopable)
60+
continue;
61+
Loopable loopable = (Loopable)child;
62+
loopable.SetSize(new Vector2((float)ChartLength / 2 + 1, Size.Y));
63+
loopable.Bounds = (float)ChartLength / 2 * i;
64+
i++;
65+
}
66+
}
67+
5868
//TODO: Rework these?
5969
public NoteArrow AddArrowToLane(Note note, int noteIdx)
6070
{
@@ -79,14 +89,4 @@ private NoteArrow CreateNote(InputHandler.ArrowData arrowData)
7989
ChartLoopables.AddChild(note);
8090
return note;
8191
}
82-
83-
public void OnNotePressed(ArrowType type)
84-
{
85-
EmitSignal(nameof(NotePressed), (int)type);
86-
}
87-
88-
public void OnNoteReleased(ArrowType type)
89-
{
90-
EmitSignal(nameof(NoteReleased), (int)type);
91-
}
9292
}

0 commit comments

Comments
 (0)