Skip to content

Commit 252a9ac

Browse files
committed
Adding notes fixes
Made added notes tween to the same rhythm Fixed issues when adding notes being considered active at wrong times
1 parent 5b17978 commit 252a9ac

5 files changed

Lines changed: 48 additions & 20 deletions

File tree

scenes/BattleDirector/BattleDirector.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private Note GetNote(NoteArrow arrow)
7676
return _notes[arrow.NoteIdx];
7777
}
7878

79-
private bool AddNoteToLane(Note note)
79+
private bool AddNoteToLane(Note note, bool isActive = true)
8080
{
8181
//Don't add dupe notes
8282
if (_notes.Any(nt => nt.Type == note.Type && nt.Beat == note.Beat))
@@ -86,6 +86,7 @@ private bool AddNoteToLane(Note note)
8686
_notes = _notes.Append(note).ToArray();
8787
//Get noteArrow from CM
8888
var arrow = CM.AddArrowToLane(note, _notes.Length - 1);
89+
arrow.IsActive = isActive;
8990
_laneData[(int)note.Type] = _laneData[(int)note.Type].Append(arrow).ToArray();
9091
return true;
9192
}
@@ -167,7 +168,7 @@ private void CheckMiss()
167168
if (_laneData[i].Length <= 0)
168169
continue;
169170
double beatDif = (curBeat - GetFirstNote((NoteArrow.ArrowType)i).Beat);
170-
if (beatDif > 1 && _laneData[i].First().Visible) //Can change, currently using visible as a stand in for already activated.
171+
if (beatDif > 1 && _laneData[i].First().IsActive)
171172
{
172173
_laneData[i].First().NoteHit();
173174
HandleTiming((NoteArrow.ArrowType)i, Math.Abs(beatDif));
@@ -179,7 +180,10 @@ private void CheckNoteTiming(NoteArrow.ArrowType type)
179180
{
180181
double curBeat = TimeKeeper.CurrentTime / (60 / (double)_curSong.Bpm) % CM.BeatsPerLoop;
181182
if (_laneData[(int)type].Length == 0)
183+
{
184+
PlayerAddNote(type, (int)Math.Round(curBeat));
182185
return;
186+
}
183187
double beatDif = Math.Abs(curBeat - GetFirstNote(type).Beat);
184188
if (beatDif > 1)
185189
{
@@ -225,7 +229,6 @@ private void PlayerAddNote(NoteArrow.ArrowType type, int beat)
225229
{
226230
// can also add some sort of keybind here to also have pressed
227231
// in case the user just presses the note too early and spawns a note
228-
//TODO: Sync new notes animations with the rest.
229232
GD.Print(
230233
$"Player trying to place {type} typed note at beat: "
231234
+ beat
@@ -235,7 +238,7 @@ private void PlayerAddNote(NoteArrow.ArrowType type, int beat)
235238
if (NotePlacementBar.CanPlaceNote())
236239
{
237240
Note exampleNote = new Note(type, beat % CM.BeatsPerLoop);
238-
if (AddNoteToLane(exampleNote))
241+
if (AddNoteToLane(exampleNote, false))
239242
NotePlacementBar.PlacedNote();
240243
}
241244
}

scenes/BattleDirector/NotePlacementBar.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public partial class NotePlacementBar : Node
55
{
6-
const int MaxValue = 100;
6+
const int MaxValue = 50;
77
int currentBarValue;
88
int currentCombo;
99
int comboMult;
@@ -59,9 +59,7 @@ public bool CanPlaceNote()
5959

6060
private void DetermineComboMult()
6161
{
62-
comboMult = currentCombo / notesToIncreaseCombo;
63-
if (comboMult == 0)
64-
comboMult = 1;
62+
comboMult = currentCombo / notesToIncreaseCombo + 1;
6563
}
6664

6765
public void UpdateNotePlacementBar(int newValue)

scenes/ChartViewport/ChartManager.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public partial class ChartManager : SubViewportContainer
1616
[Export]
1717
public CanvasGroup ChartLoopables;
1818

19+
private Node _arrowGroup;
20+
1921
[Signal]
2022
public delegate void NotePressedEventHandler(ArrowType arrowType);
2123

@@ -47,9 +49,29 @@ public void PrepChart(BattleDirector.SongData songData)
4749
TimeKeeper.Bpm = songData.Bpm;
4850

4951
InitBackgrounds();
52+
_arrowGroup = ChartLoopables.GetNode<Node>("ArrowGroup");
5053

5154
IH.Connect(nameof(InputHandler.NotePressed), new Callable(this, nameof(OnNotePressed)));
5255
IH.Connect(nameof(InputHandler.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
56+
57+
//This could be good as a function to call on something, to have many things animated to the beat.
58+
var tween = GetTree().CreateTween();
59+
tween
60+
.TweenMethod(
61+
Callable.From((Vector2 scale) => TweenArrows(scale)),
62+
new Vector2(0.07f, 0.07f),
63+
new Vector2(0.07f, 0.07f) * 1.25f,
64+
60f / TimeKeeper.Bpm / 2
65+
)
66+
.SetEase(Tween.EaseType.Out)
67+
.SetTrans(Tween.TransitionType.Elastic);
68+
tween.TweenMethod(
69+
Callable.From((Vector2 scale) => TweenArrows(scale)),
70+
new Vector2(0.07f, 0.07f) * 1.25f,
71+
new Vector2(0.07f, 0.07f),
72+
60f / TimeKeeper.Bpm / 2
73+
);
74+
tween.SetLoops().Play();
5375
}
5476

5577
private void InitBackgrounds()
@@ -66,6 +88,15 @@ private void InitBackgrounds()
6688
}
6789
}
6890

91+
private void TweenArrows(Vector2 scale)
92+
{
93+
foreach (var node in _arrowGroup.GetChildren())
94+
{
95+
NoteArrow arrow = (NoteArrow)node;
96+
arrow.Scale = scale;
97+
}
98+
}
99+
69100
public NoteArrow AddArrowToLane(Note note, int noteIdx)
70101
{
71102
var newNote = CreateNote(note.Type, note.Beat);
@@ -80,7 +111,7 @@ private NoteArrow CreateNote(ArrowType arrow, int beat = 0)
80111
NoteArrow newArrow = noteScene.Instantiate<NoteArrow>();
81112
newArrow.Init(IH.Arrows[(int)arrow]);
82113

83-
ChartLoopables.AddChild(newArrow);
114+
_arrowGroup.AddChild(newArrow);
84115
newArrow.Bounds = (float)((double)beat / BeatsPerLoop * (ChartLength / 2));
85116
return newArrow;
86117
}

scenes/ChartViewport/ChartViewport.tscn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ anchor_mode = 0
3131
[node name="ChartLoopables" type="CanvasGroup" parent="SubViewport"]
3232
unique_name_in_owner = true
3333

34-
[node name="ChartBG1" type="TextureRect" parent="SubViewport/ChartLoopables"]
34+
[node name="ArrowGroup" type="Node" parent="SubViewport/ChartLoopables"]
35+
36+
[node name="ChartBG2" type="TextureRect" parent="SubViewport/ChartLoopables"]
3537
modulate = Color(2, 2, 2, 1)
3638
offset_right = 701.0
3739
offset_bottom = 300.0
3840
texture = ExtResource("1_0wnka")
3941
script = ExtResource("3_5u57h")
4042

41-
[node name="ChartBG2" type="TextureRect" parent="SubViewport/ChartLoopables"]
43+
[node name="ChartBG1" type="TextureRect" parent="SubViewport/ChartLoopables"]
4244
modulate = Color(2, 2, 2, 1)
4345
offset_right = 701.0
4446
offset_bottom = 300.0

scenes/NoteManager/scripts/NoteArrow.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum ArrowType
1616

1717
public int NoteIdx;
1818
public float Bounds;
19+
public bool IsActive;
1920

2021
public void Init(InputHandler.ArrowData parentArrowData)
2122
{
@@ -24,15 +25,6 @@ public void Init(InputHandler.ArrowData parentArrowData)
2425
SelfModulate = parentArrowData.Color;
2526
Position += Vector2.Down * (parentArrowData.Node.GlobalPosition.Y);
2627
RotationDegrees = parentArrowData.Node.RotationDegrees;
27-
28-
//This could be good as a function to call on something, to have many things animated to the beat.
29-
var tween = CreateTween();
30-
tween.TweenProperty(this, "scale", Scale, 60f / TimeKeeper.Bpm / 2);
31-
tween.SetEase(Tween.EaseType.In);
32-
tween.SetTrans(Tween.TransitionType.Elastic);
33-
tween.TweenProperty(this, "scale", Scale * 1.25f, 60f / TimeKeeper.Bpm / 2);
34-
tween.SetLoops();
35-
tween.Play();
3628
}
3729

3830
public override void _Process(double delta)
@@ -54,10 +46,12 @@ public override void _Process(double delta)
5446
public void OnLoop()
5547
{
5648
Visible = true;
49+
IsActive = true;
5750
}
5851

5952
public void NoteHit()
6053
{
6154
Visible = false;
55+
IsActive = false;
6256
}
6357
}

0 commit comments

Comments
 (0)