33using Godot ;
44using ArrowType = NoteArrow . ArrowType ;
55
6- /*
7- //Lets say this inits all the initial notes and manages the chart BG.
8-
9- //What does this do?
10- //Input, visual looping, timing, battle stuff, combo, note creation
11-
12- //Focus on the looping
13- This should manage creating sprites for notes???
14- This should manage subview camera pos and zoom.
15-
16- Movement should primarily be done from a parent node
17- !!Backgrounds need to be big enough/notes and beats spaced enough that when a note goes off screen, it can be teleported in position offscreen
18- BackGround probably needs 2 sprites or parallax:
19- Get a set length, based on viewport and loop/song length (Const PLAYWIDTH)
20- Once one BG hits a certain left pos return it to the right pos
21-
22- Notes are similar, but only need 1 representation.
23- Once hits left bounds return to right bounds
24- (Something else should probably manage refreshing, input, etc)
25- Can probably use an object pool
26-
27- If timing based input checking:
28- This is enough, notes are visually just sprites
29- Collision based - This might need to manage that, or have a sister manager that does, notes need more stuff on their own
30- */
31-
326/**
337 * @class ChartManager
348 * @brief Chart Manager is meant to handle the visual aspects of a battle. Setting up the chart background, initial notes, and handle looping. WIP
@@ -42,22 +16,31 @@ public partial class ChartManager : SubViewportContainer
4216 [ Export ]
4317 public CanvasGroup ChartLoopables ;
4418
45- public BattleDirector . SongData SongData ; //TODO: Maybe. Make settable from outside, but readonly
19+ [ Signal ]
20+ public delegate void NotePressedEventHandler ( ArrowType arrowType ) ;
21+
22+ [ Signal ]
23+ public delegate void NoteReleasedEventHandler ( ArrowType arrowType ) ;
4624
4725 //Arbitrary vars, play with these
48- private const double ChartLength = 2800 ; //Might move this to be song specific?
26+ private double ChartLength = 2400 ; //Might move this to be song specific?
4927
5028 //Speed that chart objs should move at, to be synced to song, in theory
51- private double _rateOfChart ;
29+ private double _rateOfChart ; //Speed objects should move at px/s
5230 private double _loopLen ; //secs
53- private int _beatsPerLoop ;
31+ public int _beatsPerLoop ;
5432
55- //TODO: Lanes
56- private NoteArrow [ ] _currentArrows = Array . Empty < NoteArrow > ( ) ;
33+ private NoteArrow [ ] [ ] _currentArrows = new NoteArrow [ ] [ ]
34+ {
35+ Array . Empty < NoteArrow > ( ) ,
36+ Array . Empty < NoteArrow > ( ) ,
37+ Array . Empty < NoteArrow > ( ) ,
38+ Array . Empty < NoteArrow > ( ) ,
39+ } ;
5740
5841 private void InitBackgrounds ( )
5942 {
60- //TODO: Get better visual for BG's, and/or create BG's on demand. Though we should only ever need 2.
43+ //TODO: Get better visual for BG's
6144 int i = 0 ;
6245 foreach ( Node child in ChartLoopables . GetChildren ( ) )
6346 {
@@ -66,9 +49,7 @@ private void InitBackgrounds()
6649 Loopable loopable = ( Loopable ) child ;
6750 //TODO: Consolidate
6851 loopable . SetSize ( new Vector2 ( ( float ) ChartLength / 2 + 1 , Size . Y ) ) ;
69- loopable . SetPosition ( new Vector2 ( ( float ) ChartLength / 2 * i , 0 ) ) ;
70- loopable . Bounds = ( float ) ChartLength / 2 ;
71- loopable . Speed = ( float ) _rateOfChart ;
52+ loopable . Bounds = ( float ) ChartLength / 2 * i ;
7253
7354 i ++ ;
7455 }
@@ -82,54 +63,73 @@ private void InitNotes(Note[] notes)
8263 if ( noteData != null )
8364 CreateNote ( noteData . Type , noteData . Beat ) ;
8465 }
66+ foreach ( Note noteData in notes ) //Temporary solution
67+ {
68+ if ( noteData != null )
69+ CreateNote ( noteData . Type , noteData . Beat + _beatsPerLoop ) ;
70+ }
8571 }
8672
8773 public void PrepChart ( BattleDirector . SongData songData , Note [ ] notes )
8874 {
89- SongData = songData ;
90-
91- _loopLen = SongData . SongLength / SongData . NumLoops ;
92- _beatsPerLoop = ( int ) ( _loopLen / ( 60f / SongData . Bpm ) ) ;
75+ _loopLen = songData . SongLength / songData . NumLoops ;
76+ TimeKeeper . LoopLength = ( float ) _loopLen ;
77+ _beatsPerLoop = ( int ) ( _loopLen / ( 60f / songData . Bpm ) ) ;
78+ ChartLength = ( float ) _loopLen * ( float ) Math . Floor ( ChartLength / _loopLen ) ;
79+ TimeKeeper . ChartLength = ( float ) ChartLength ;
9380
9481 _rateOfChart = ChartLength / 2 / _loopLen ; //px/s
9582
9683 InitBackgrounds ( ) ;
9784 InitNotes ( notes ) ;
85+
86+ NM . Connect ( nameof ( NoteManager . NotePressed ) , new Callable ( this , nameof ( OnNotePressed ) ) ) ;
87+ NM . Connect ( nameof ( NoteManager . NoteReleased ) , new Callable ( this , nameof ( OnNoteReleased ) ) ) ;
9888 }
9989
10090 //TODO: Rework these
10191 public NoteArrow CreateNote ( ArrowType arrow , int beat = 0 )
10292 {
103- var newNote = CreateNote ( NM . Arrows [ arrow ] ) ;
104- newNote . Bounds =
105- ( float ) ( ( double ) beat / _beatsPerLoop * ( ChartLength / 2 ) ) - newNote . Size . X / 2 ; //eww
93+ var newNote = CreateNote ( NM . Arrows [ ( int ) arrow ] , beat ) ;
94+ newNote . Bounds = ( float ) ( ( double ) beat / _beatsPerLoop * ( ChartLength / 2 ) ) ; //eww
10695 newNote . Position += Vector2 . Right * newNote . Bounds ;
10796 return newNote ;
10897 }
10998
110- private NoteArrow CreateNote ( NoteManager . ArrowData arrowData )
99+ private NoteArrow CreateNote ( NoteManager . ArrowData arrowData , int beat )
111100 {
112101 var noteScene = ResourceLoader . Load < PackedScene > ( "res://scenes/NoteManager/note.tscn" ) ;
113102 NoteArrow note = noteScene . Instantiate < NoteArrow > ( ) ;
114103
115- note . Init ( arrowData , ( float ) _rateOfChart , - 1 ) ;
116- _currentArrows = _currentArrows . Append ( note ) . ToArray ( ) ;
104+ note . Init ( arrowData ) ;
105+ if ( ! ( beat > _beatsPerLoop ) )
106+ {
107+ _currentArrows [ ( int ) arrowData . Type ] = _currentArrows [ ( int ) arrowData . Type ]
108+ . Append ( note )
109+ . ToArray ( ) ;
110+ }
117111 ChartLoopables . AddChild ( note ) ;
118112 return note ;
119113 }
120114
121- public void TriggerArrow ( )
115+ public void HandleNote ( ArrowType type )
116+ {
117+ _currentArrows [ ( int ) type ] . First ( ) . NoteHit ( ) ;
118+ _currentArrows [ ( int ) type ] = _currentArrows [ ( int ) type ]
119+ . Skip ( 1 )
120+ . Concat ( _currentArrows [ ( int ) type ] . Take ( 1 ) )
121+ . ToArray ( ) ;
122+ }
123+
124+ public void OnNotePressed ( ArrowType type )
122125 {
123- _currentArrows . First ( ) . NoteHit ( ) ;
124- _currentArrows = _currentArrows . Skip ( 1 ) . ToArray ( ) ;
126+ if ( _currentArrows [ ( int ) type ] . Length == 0 )
127+ return ;
128+ EmitSignal ( nameof ( NotePressed ) , ( int ) type ) ;
125129 }
126130
127- //TODO: Queue next notes. Needs Timing System
128- /*The logic:
129- *Spawn in pos is a proportion (intended beat/beats per loop) = (intended pos/track length in px) ->
130- * intended pos = intended beat / bpl * track length
131- *
132- * Respawn (probably obj pool, or for now new instantiation)
133- * 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
134- */
131+ public void OnNoteReleased ( ArrowType type )
132+ {
133+ EmitSignal ( nameof ( NoteReleased ) , ( int ) type ) ;
134+ }
135135}
0 commit comments