|
| 1 | +using System; |
| 2 | +using Godot; |
| 3 | +using ArrowType = NoteArrow.ArrowType; |
| 4 | + |
| 5 | +/* |
| 6 | +//Lets say this inits all the initial notes and manages the chart BG. |
| 7 | +
|
| 8 | +//What does this do? |
| 9 | +//Input, visual looping, timing, battle stuff, combo, note creation |
| 10 | +
|
| 11 | +//Focus on the looping |
| 12 | + This should manage creating sprites for notes??? |
| 13 | + This should manage subview camera pos and zoom. |
| 14 | +
|
| 15 | +Movement should primarily be done from a parent node |
| 16 | +!!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 |
| 17 | +BackGround probably needs 2 sprites or parallax: |
| 18 | + Get a set length, based on viewport and loop/song length (Const PLAYWIDTH) |
| 19 | + Once one BG hits a certain left pos return it to the right pos |
| 20 | +
|
| 21 | +Notes are similar, but only need 1 representation. |
| 22 | + Once hits left bounds return to right bounds |
| 23 | + (Something else should probably manage refreshing, input, etc) |
| 24 | + Can probably use an object pool |
| 25 | +
|
| 26 | +If timing based input checking: |
| 27 | + This is enough, notes are visually just sprites |
| 28 | + Collision based - This might need to manage that, or have a sister manager that does, notes need more stuff on their own |
| 29 | + */ |
| 30 | + |
| 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 | + */ |
| 35 | +public partial class ChartManager : SubViewportContainer |
| 36 | +{ |
| 37 | + //Nodes from scene |
| 38 | + [Export] |
| 39 | + public NoteManager NM; |
| 40 | + |
| 41 | + [Export] |
| 42 | + public CanvasGroup ChartLoopables; |
| 43 | + |
| 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; |
| 51 | + private double _loopLen; //secs |
| 52 | + private int _beatsPerLoop; |
| 53 | + |
| 54 | + private void InitBackgrounds() |
| 55 | + { |
| 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; |
| 58 | + foreach (Node child in ChartLoopables.GetChildren()) |
| 59 | + { |
| 60 | + if (child is Loopable) |
| 61 | + { |
| 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++; |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + private void InitNotes(Note[] notes) |
| 75 | + { |
| 76 | + foreach (Note noteData in notes) |
| 77 | + { |
| 78 | + CreateNote(noteData.Type, noteData.Beat); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public void PrepChart(BattleDirector.SongData songData, Note[] notes) |
| 83 | + { |
| 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; |
| 103 | + } |
| 104 | + |
| 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); |
| 111 | + |
| 112 | + ChartLoopables.AddChild(note); |
| 113 | + return note; |
| 114 | + } |
| 115 | + |
| 116 | + //TODO: Queue next notes. Needs Timing System |
| 117 | + /*The logic: |
| 118 | + *Spawn in pos is a proportion (intended beat/beats per loop) = (intended pos/track length in px) -> |
| 119 | + * intended pos = intended beat / bpl * track length |
| 120 | + * |
| 121 | + * Respawn (probably obj pool, or for now new instantiation) |
| 122 | + * 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 |
| 123 | + */ |
| 124 | +} |
0 commit comments