-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartManager.cs
More file actions
136 lines (117 loc) · 4.49 KB
/
ChartManager.cs
File metadata and controls
136 lines (117 loc) · 4.49 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
128
129
130
131
132
133
134
135
136
using System;
using System.Linq;
using FunkEngine;
using Godot;
/**
* @class ChartManager
* @brief Chart Manager is meant to handle the visual aspects of a battle. Setting up the chart background, initial notes, and handle looping. WIP
*/
public partial class ChartManager : SubViewportContainer
{
//Nodes from scene
[Export]
public InputHandler IH;
[Export]
public CanvasGroup ChartLoopables;
private Node _arrowGroup;
[Signal]
public delegate void NotePressedEventHandler(ArrowType arrowType);
[Signal]
public delegate void NoteReleasedEventHandler(ArrowType arrowType);
//Arbitrary vars, play with these
//Might move this to be song specific? For now, should never go below ~2000, else visual break because there isn't enough room to loop.
private double ChartLength = 5000;
private double _loopLen; //secs
public int BeatsPerLoop;
public void OnNotePressed(ArrowType type)
{
EmitSignal(nameof(NotePressed), (int)type);
}
public void OnNoteReleased(ArrowType type)
{
EmitSignal(nameof(NoteReleased), (int)type);
}
public void PrepChart(SongData songData)
{
_loopLen = songData.SongLength / songData.NumLoops;
TimeKeeper.LoopLength = (float)_loopLen;
BeatsPerLoop = (int)(_loopLen / (60f / songData.Bpm));
ChartLength = (float)_loopLen * (float)Math.Floor(ChartLength / _loopLen);
TimeKeeper.ChartLength = (float)ChartLength;
TimeKeeper.Bpm = songData.Bpm;
_arrowGroup = ChartLoopables.GetNode<Node>("ArrowGroup");
IH.Connect(nameof(InputHandler.NotePressed), new Callable(this, nameof(OnNotePressed)));
IH.Connect(nameof(InputHandler.NoteReleased), new Callable(this, nameof(OnNoteReleased)));
//This could be good as a function to call on something, to have many things animated to the beat.
var tween = GetTree().CreateTween();
tween
.TweenMethod(
Callable.From((Vector2 scale) => TweenArrows(scale)),
Vector2.One * .8f,
Vector2.One,
60f / TimeKeeper.Bpm / 2
)
.SetEase(Tween.EaseType.Out)
.SetTrans(Tween.TransitionType.Elastic);
tween.TweenMethod(
Callable.From((Vector2 scale) => TweenArrows(scale)),
Vector2.One,
Vector2.One * .8f,
60f / TimeKeeper.Bpm / 2
);
tween.SetLoops().Play();
}
private void TweenArrows(Vector2 scale)
{
foreach (var node in _arrowGroup.GetChildren())
{
NoteArrow arrow = (NoteArrow)node;
arrow.Scale = scale;
}
}
public NoteArrow AddArrowToLane(
ArrowType type,
int beat,
Note note,
Color colorOverride = default
)
{
var newNote = CreateNote(type, note, beat); //TODO: Notes on track have unqiue visuals
var loopArrow = CreateNote(type, note, beat + BeatsPerLoop); //Create a dummy arrow for looping visuals
if (colorOverride != default)
{
newNote.SelfModulate = colorOverride;
loopArrow.SelfModulate = colorOverride;
}
newNote.NoteRef = note;
return newNote;
}
private NoteArrow CreateNote(ArrowType arrow, Note note, int beat = 0)
{
var noteScene = ResourceLoader.Load<PackedScene>("res://scenes/NoteManager/note.tscn");
NoteArrow newArrow = noteScene.Instantiate<NoteArrow>();
newArrow.Init(IH.Arrows[(int)arrow], beat, note);
newArrow.OutlineSprite.Modulate = IH.Arrows[(int)arrow].Color;
_arrowGroup.AddChild(newArrow);
newArrow.Bounds = (float)((double)beat / BeatsPerLoop * (ChartLength / 2));
newArrow.Position += Vector2.Right * newArrow.Bounds * 10; //temporary fix for notes spawning and instantly calling loop from originating at 0,0
return newArrow;
}
public void ComboText(string text, ArrowType arrow, int currentCombo)
{
TextParticle newText = new TextParticle();
AddChild(newText);
newText.Position = IH.Arrows[(int)arrow].Node.Position - newText.Size/2;
IH.FeedbackEffect(arrow, text);
newText.Text = text + $" {currentCombo}";
}
public override void _ExitTree()
{
GD.Print("[DEBUG] Stopping tweens before exiting the scene...");
foreach (var tween in GetTree().GetProcessedTweens())
{
tween.Stop();
GD.Print("[DEBUG] Stopped tween.");
}
}
}