Skip to content

Commit f20cedb

Browse files
committed
Integrated Notes and Chart
Restructured file organization Consolidated visual information to ChartManager Reworked Note into NoteArrow to represent chart indications Skeleton classes for eventual objects
1 parent 61f18db commit f20cedb

19 files changed

Lines changed: 386 additions & 342 deletions

Classes/Note.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Godot;
3+
4+
/**
5+
* @class Note
6+
* @brief Data structure class for holding data and methods for a battle time note. WIP
7+
*/
8+
public partial class Note : Resource
9+
{
10+
public int Beat;
11+
public NoteArrow.ArrowType Type;
12+
13+
public Note(NoteArrow.ArrowType type = NoteArrow.ArrowType.Up, int beat = 0)
14+
{
15+
Beat = beat;
16+
Type = type;
17+
}
18+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using Godot;
3+
4+
/**
5+
* @class BattleDirector
6+
* @brief Higher priority director to manage battle effects. Can directly access managers, which should signal up to Director WIP
7+
*/
8+
public partial class BattleDirector : Node2D
9+
{
10+
[Export]
11+
public ChartManager CM;
12+
13+
[Export]
14+
public NoteManager NM;
15+
16+
//TODO: Slowly add data based on what it needs.
17+
public struct SongData
18+
{
19+
public int Bpm;
20+
public double SongLength;
21+
public int NumLoops;
22+
}
23+
24+
private SongData _curSong;
25+
private Note[] _notes;
26+
27+
public override void _Ready()
28+
{
29+
AddExampleNote();
30+
31+
CM.PrepChart(_curSong, _notes);
32+
//TODO: Hook up signals
33+
}
34+
35+
private void AddExampleNote()
36+
{
37+
//Create Dummy Song Data
38+
_curSong = new SongData
39+
{
40+
Bpm = 120,
41+
SongLength = 160,
42+
NumLoops = 5,
43+
};
44+
//Add note
45+
_notes = new Note[1];
46+
_notes[0] = new Note(NoteArrow.ArrowType.Left, 32);
47+
}
48+
}

scenes/ChartViewport/ChartBg.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using System;
22
using Godot;
3+
using ArrowType = NoteArrow.ArrowType;
34

5+
/*
46
//Lets say this inits all the initial notes and manages the chart BG.
57
68
//What does this do?
79
//Input, visual looping, timing, battle stuff, combo, note creation
810
911
//Focus on the looping
10-
/*
11-
1212
This should manage creating sprites for notes???
1313
This should manage subview camera pos and zoom.
1414
@@ -28,88 +28,97 @@ Can probably use an object pool
2828
Collision based - This might need to manage that, or have a sister manager that does, notes need more stuff on their own
2929
*/
3030

31+
/**
32+
* @class ChartManager
33+
* @brief Chart Manager is meant to handle the visual aspects of a battle. Setting up the chart background, initial notes, and handle looping. WIP
34+
*/
3135
public partial class ChartManager : SubViewportContainer
3236
{
33-
//Simulated variables, remove later
34-
private const int Bpm = 120;
35-
private const double SongLength = 160; //secs
36-
37-
//Arbitrary vars, play with these
38-
private const double ChartLength = 1400;
39-
private const int NumLoops = 5; //TODO: Loops should be based on measures of a song?
40-
4137
//Nodes from scene
38+
[Export]
39+
public NoteManager NM;
40+
4241
[Export]
4342
public CanvasGroup ChartLoopables;
4443

44+
public BattleDirector.SongData SongData; //TODO: Maybe. Make settable from outside, but readonly
45+
46+
//Arbitrary vars, play with these
47+
private const double ChartLength = 1400; //Might move this to be song specific?
48+
49+
//Speed that chart objs should move at, to be synced to song, in theory
50+
private double _rateOfChart;
4551
private double _loopLen; //secs
4652
private int _beatsPerLoop;
4753

48-
public override void _Ready()
54+
private void InitBackgrounds()
4955
{
50-
_loopLen = SongLength / NumLoops;
51-
_beatsPerLoop = (int)(_loopLen / (60f / Bpm));
52-
53-
ChartLoopables = GetNode<CanvasGroup>("%ChartLoopables");
54-
55-
speedL = 700 / _loopLen; // px/s
56-
GD.Print(speedL);
57-
56+
//TODO: Get better visual for BG's, and/or create BG's on demand. Though we should only ever need 2.
57+
int i = 0;
5858
foreach (Node child in ChartLoopables.GetChildren())
5959
{
60-
if (child is ChartBg)
60+
if (child is Loopable)
6161
{
62-
ChartBg chartBg = (ChartBg)child;
63-
chartBg.Speed = (float)speedL;
62+
Loopable loopable = (Loopable)child;
63+
//TODO: Consolidate
64+
loopable.SetSize(new Vector2((float)ChartLength / 2 + 1, Size.Y));
65+
loopable.SetPosition(new Vector2((float)ChartLength / 2 * i, 0));
66+
loopable.Bounds = (float)ChartLength / 2;
67+
loopable.Speed = (float)_rateOfChart;
68+
69+
i++;
6470
}
6571
}
72+
}
6673

67-
InitTestNote();
74+
private void InitNotes(Note[] notes)
75+
{
76+
foreach (Note noteData in notes)
77+
{
78+
CreateNote(noteData.Type, noteData.Beat);
79+
}
6880
}
6981

70-
public override void _Process(double delta)
82+
public void PrepChart(BattleDirector.SongData songData, Note[] notes)
7183
{
72-
//ChartLoopables.Position += 10 * Vector2.Left;
73-
ProcessTestNote(delta);
84+
SongData = songData;
85+
86+
_loopLen = SongData.SongLength / SongData.NumLoops;
87+
_beatsPerLoop = (int)(_loopLen / (60f / SongData.Bpm));
88+
89+
_rateOfChart = 700 / _loopLen; //px/s
90+
91+
InitBackgrounds();
92+
InitNotes(notes);
93+
}
94+
95+
//TODO: Rework these
96+
public NoteArrow CreateNote(ArrowType arrow, int beat = 0)
97+
{
98+
var newNote = CreateNote(NM.Arrows[arrow]);
99+
newNote.Bounds =
100+
(float)((double)beat / _beatsPerLoop * (ChartLength / 2)) - newNote.Size.X / 2; //eww
101+
newNote.Position += Vector2.Right * newNote.Bounds;
102+
return newNote;
74103
}
75104

76-
//Test code TODO: REMOVE LATER
77-
private Sprite2D[] _testNotes = new Sprite2D[4];
78-
private float[] _testBeats = { 60, 30, 32, 10 };
79-
private double speedL;
105+
private NoteArrow CreateNote(NoteManager.ArrowData arrowData)
106+
{
107+
var noteScene = ResourceLoader.Load<PackedScene>("res://scenes/NoteManager/note.tscn");
108+
var note = noteScene.Instantiate<NoteArrow>();
109+
110+
note.Init(arrowData, (float)_rateOfChart, -1);
80111

112+
ChartLoopables.AddChild(note);
113+
return note;
114+
}
115+
116+
//TODO: Queue next notes. Needs Timing System
81117
/*The logic:
82118
*Spawn in pos is a proportion (intended beat/beats per loop) = (intended pos/track length in px) ->
83119
* intended pos = intended beat / bpl * track length
84120
*
85121
* Respawn (probably obj pool, or for now new instantiation)
86122
* When a note's pos is at its intended initial pos, queue up and spawn the next note of its beat at intended pos + track length
87123
*/
88-
public void InitTestNote()
89-
{
90-
_testNotes[0] = GetNode<Sprite2D>("%TestNote");
91-
_testNotes[1] = GetNode<Sprite2D>("%TestNote2");
92-
_testNotes[2] = GetNode<Sprite2D>("%TestNote3");
93-
_testNotes[3] = GetNode<Sprite2D>("%TestNote4");
94-
int i = 0;
95-
foreach (Sprite2D note in _testNotes)
96-
{
97-
note.Position = new Vector2(_testBeats[i] / _beatsPerLoop * 700, 150);
98-
i++;
99-
}
100-
}
101-
102-
public void ProcessTestNote(double delta)
103-
{
104-
int i = 0;
105-
foreach (Sprite2D note in _testNotes)
106-
{
107-
if (note.Position.X <= (_testBeats[i] / _beatsPerLoop * 700) - 700)
108-
{
109-
note.Position = new Vector2(_testBeats[i] / _beatsPerLoop * 700, 150);
110-
}
111-
note.Position += Vector2.Left * (float)speedL * (float)delta;
112-
i++;
113-
}
114-
}
115124
}
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://dfevfib11kou1"]
1+
[gd_scene load_steps=5 format=3 uid="uid://dfevfib11kou1"]
22

33
[ext_resource type="Texture2D" uid="uid://b0tvsewgnf2x7" path="res://icon.svg" id="1_0wnka"]
44
[ext_resource type="Script" path="res://scenes/ChartViewport/ChartManager.cs" id="1_ruh2l"]
5-
[ext_resource type="Script" path="res://scenes/ChartViewport/ChartBg.cs" id="3_runyu"]
5+
[ext_resource type="Script" path="res://scenes/ChartViewport/Loopable.cs" id="3_5u57h"]
6+
[ext_resource type="PackedScene" uid="uid://bn8txx53xlguw" path="res://scenes/NoteManager/note_manager.tscn" id="4_fd5fw"]
67

7-
[node name="VPContainer" type="SubViewportContainer" node_paths=PackedStringArray("ChartLoopables")]
8+
[node name="VPContainer" type="SubViewportContainer" node_paths=PackedStringArray("NM", "ChartLoopables")]
89
offset_right = 480.0
910
offset_bottom = 220.0
1011
script = ExtResource("1_ruh2l")
12+
NM = NodePath("SubViewport/noteManager")
1113
ChartLoopables = NodePath("SubViewport/ChartLoopables")
1214

1315
[node name="SubViewport" type="SubViewport" parent="."]
@@ -18,13 +20,6 @@ render_target_update_mode = 4
1820
[node name="Camera2D" type="Camera2D" parent="SubViewport"]
1921
position = Vector2(240, 110)
2022

21-
[node name="MockPlayhead" type="Sprite2D" parent="SubViewport"]
22-
modulate = Color(0, 0, 0, 0.615686)
23-
z_index = 1
24-
position = Vector2(60, 120)
25-
scale = Vector2(0.1, 2)
26-
texture = ExtResource("1_0wnka")
27-
2823
[node name="ChartLoopables" type="CanvasGroup" parent="SubViewport"]
2924
unique_name_in_owner = true
3025

@@ -34,7 +29,7 @@ offset_top = -46.0
3429
offset_right = 701.0
3530
offset_bottom = 254.0
3631
texture = ExtResource("1_0wnka")
37-
script = ExtResource("3_runyu")
32+
script = ExtResource("3_5u57h")
3833

3934
[node name="ChartBG2" type="TextureRect" parent="SubViewport/ChartLoopables"]
4035
modulate = Color(2, 2, 2, 1)
@@ -43,24 +38,6 @@ offset_top = -46.0
4338
offset_right = 1401.0
4439
offset_bottom = 254.0
4540
texture = ExtResource("1_0wnka")
46-
script = ExtResource("3_runyu")
41+
script = ExtResource("3_5u57h")
4742

48-
[node name="TestNote" type="Sprite2D" parent="SubViewport/ChartLoopables"]
49-
unique_name_in_owner = true
50-
scale = Vector2(0.3, 0.3)
51-
texture = ExtResource("1_0wnka")
52-
53-
[node name="TestNote2" type="Sprite2D" parent="SubViewport/ChartLoopables"]
54-
unique_name_in_owner = true
55-
scale = Vector2(0.3, 0.3)
56-
texture = ExtResource("1_0wnka")
57-
58-
[node name="TestNote3" type="Sprite2D" parent="SubViewport/ChartLoopables"]
59-
unique_name_in_owner = true
60-
scale = Vector2(0.3, 0.3)
61-
texture = ExtResource("1_0wnka")
62-
63-
[node name="TestNote4" type="Sprite2D" parent="SubViewport/ChartLoopables"]
64-
unique_name_in_owner = true
65-
scale = Vector2(0.3, 0.3)
66-
texture = ExtResource("1_0wnka")
43+
[node name="noteManager" parent="SubViewport" instance=ExtResource("4_fd5fw")]

scenes/ChartViewport/Loopable.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using Godot;
3+
4+
/**
5+
* @class Loopable
6+
* @brief A general class fo textures on the chart which should have a position at which point they loop. WIP
7+
*/
8+
public partial class Loopable : TextureRect
9+
{
10+
public float Bounds = 700f; //px Pos to loop or do something at.
11+
public float Speed = 5; //px/s
12+
13+
// Called every frame. 'delta' is the elapsed time since the previous frame.
14+
public override void _Process(double delta)
15+
{
16+
if (Position.X <= -Bounds)
17+
{
18+
Loop();
19+
}
20+
Position += Speed * Vector2.Left * (float)delta;
21+
}
22+
23+
public virtual void Loop()
24+
{
25+
Position = new Vector2(Bounds, Position.Y);
26+
}
27+
}

scenes/ChartViewport/test_scene.tscn

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
[gd_scene load_steps=2 format=3 uid="uid://b0mrgr7h0ty1y"]
1+
[gd_scene load_steps=3 format=3 uid="uid://b0mrgr7h0ty1y"]
22

33
[ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://scenes/ChartViewport/ChartViewport.tscn" id="1_1vh1u"]
4+
[ext_resource type="Script" path="res://scenes/ChartViewport/BattleDirector.cs" id="1_jbxt1"]
45

5-
[node name="TestScene" type="Node2D"]
6+
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NM")]
7+
script = ExtResource("1_jbxt1")
8+
CM = NodePath("SubViewport")
9+
NM = NodePath("SubViewport/SubViewport/noteManager")
610

711
[node name="SubViewport" parent="." instance=ExtResource("1_1vh1u")]
812
offset_left = 80.0

scripts/noteSystem/assets/right-arrow.png.import renamed to scenes/NoteManager/assets/right-arrow.png.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
importer="texture"
44
type="CompressedTexture2D"
55
uid="uid://bucvj4fquqpkr"
6-
path="res://.godot/imported/right-arrow.png-8f579df18e1ada04d965b123ceaf76a0.ctex"
6+
path="res://.godot/imported/right-arrow.png-b3005485b42777a77a9d39fbba48875d.ctex"
77
metadata={
88
"vram_texture": false
99
}
1010

1111
[deps]
1212

13-
source_file="res://scripts/noteSystem/assets/right-arrow.png"
14-
dest_files=["res://.godot/imported/right-arrow.png-8f579df18e1ada04d965b123ceaf76a0.ctex"]
13+
source_file="res://scenes/NoteManager/assets/right-arrow.png"
14+
dest_files=["res://.godot/imported/right-arrow.png-b3005485b42777a77a9d39fbba48875d.ctex"]
1515

1616
[params]
1717

0 commit comments

Comments
 (0)