From e0b2063145916c89d50472e1cac1f68fcfa85490 Mon Sep 17 00:00:00 2001 From: cornerloan Date: Mon, 10 Feb 2025 00:09:04 -0800 Subject: [PATCH 1/5] added note queue system two notes will be displayed to the player, the one in the circle will be the next note that will be placed. currently supports "single" and "double" notes, where double notes are supposed to eventually give double points. --- scenes/CustomNotes/NoteQueue.cs | 86 ++++++++++++++++++ scenes/CustomNotes/NoteQueue.tscn | 26 ++++++ scenes/CustomNotes/assets/double_note.png | Bin 0 -> 637 bytes .../CustomNotes/assets/double_note.png.import | 34 +++++++ scenes/CustomNotes/assets/single_note.png | Bin 0 -> 612 bytes .../CustomNotes/assets/single_note.png.import | 34 +++++++ scenes/CustomNotes/assets/temp_note_queue.png | Bin 0 -> 4423 bytes .../assets/temp_note_queue.png.import | 34 +++++++ 8 files changed, 214 insertions(+) create mode 100644 scenes/CustomNotes/NoteQueue.cs create mode 100644 scenes/CustomNotes/NoteQueue.tscn create mode 100644 scenes/CustomNotes/assets/double_note.png create mode 100644 scenes/CustomNotes/assets/double_note.png.import create mode 100644 scenes/CustomNotes/assets/single_note.png create mode 100644 scenes/CustomNotes/assets/single_note.png.import create mode 100644 scenes/CustomNotes/assets/temp_note_queue.png create mode 100644 scenes/CustomNotes/assets/temp_note_queue.png.import diff --git a/scenes/CustomNotes/NoteQueue.cs b/scenes/CustomNotes/NoteQueue.cs new file mode 100644 index 00000000..b15f219e --- /dev/null +++ b/scenes/CustomNotes/NoteQueue.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using Godot; + +public partial class NoteQueue : Node +{ + [Export] + private Sprite2D _currentNote; + + [Export] + private Sprite2D _nextNote; + + private Queue _noteQueue = new Queue(); + private Dictionary _noteSprites = new Dictionary(); + + public override void _Ready() + { + _noteSprites["single"] = GD.Load( + "res://scenes/CustomNotes/assets/single_note.png" + ); + _noteSprites["double"] = GD.Load( + "res://scenes/CustomNotes/assets/double_note.png" + ); + + UpdateQueue(); + } + + public void AddNoteToQueue(string noteType) + { + _noteQueue.Enqueue(noteType); + UpdateQueue(); + } + + //returns current note, and removes it from the queue + public string GetCurrentNote() + { + if (_noteQueue.Count > 0) + { + string currentNoteName = _noteQueue.Dequeue(); + UpdateQueue(); + return currentNoteName; + } + return null; + } + + private void UpdateQueue() + { + if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek())) + _currentNote.Texture = _noteSprites[_noteQueue.Peek()]; + else + _currentNote.Texture = null; + + if (_noteQueue.Count > 1) + { + string[] notes = _noteQueue.ToArray(); + if (_noteSprites.ContainsKey(notes[1])) + _nextNote.Texture = _noteSprites[notes[1]]; + else + _nextNote.Texture = null; + } + else + { + _nextNote.Texture = null; + } + } + + //Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619 + public void ScrambleQueue() + { + List tempList = new List(_noteQueue); + Random rng = new Random(); + + int n = tempList.Count; + while (n > 1) + { + n--; + int k = rng.Next(n + 1); + (tempList[k], tempList[n]) = (tempList[n], tempList[k]); + } + + _noteQueue = new Queue(tempList); + } + + //TODO: should work, in order to run in game use + // noteQueueInstance.AddNoteToQueue("single"); +} diff --git a/scenes/CustomNotes/NoteQueue.tscn b/scenes/CustomNotes/NoteQueue.tscn new file mode 100644 index 00000000..62b81618 --- /dev/null +++ b/scenes/CustomNotes/NoteQueue.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=5 format=3 uid="uid://bvhpon5liybd1"] + +[ext_resource type="Script" path="res://scenes/CustomNotes/NoteQueue.cs" id="1_jeqam"] +[ext_resource type="Texture2D" uid="uid://cnyr5usjdv0ni" path="res://scenes/CustomNotes/assets/temp_note_queue.png" id="2_0p21a"] +[ext_resource type="Texture2D" uid="uid://c3chrsxrulapd" path="res://scenes/CustomNotes/assets/single_note.png" id="3_ewo1s"] +[ext_resource type="Texture2D" uid="uid://caw70lr5e1yiq" path="res://scenes/CustomNotes/assets/double_note.png" id="4_7sgy6"] + +[node name="NoteQueue" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_jeqam") + +[node name="NoteQueueSprite" type="Sprite2D" parent="."] +texture = ExtResource("2_0p21a") + +[node name="CurrentNote" type="Sprite2D" parent="."] +position = Vector2(-14, -1) +texture = ExtResource("3_ewo1s") + +[node name="NextNote" type="Sprite2D" parent="."] +position = Vector2(16, -2) +texture = ExtResource("4_7sgy6") diff --git a/scenes/CustomNotes/assets/double_note.png b/scenes/CustomNotes/assets/double_note.png new file mode 100644 index 0000000000000000000000000000000000000000..f9f8afc691f444f72f7399488c56cfe7e7805b0d GIT binary patch literal 637 zcmV-@0)qXCP)EX>4Tx04R}tkv&MmKpe$i(@LdO9PA+CkfA!+#fmtVDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRomua!V=QRK!l7YYN*3Pj8=^l6It3%dicj2e}-H#xoTkK zSU>|RB*zc_2fw>D%kgP9DVzibUTphg0toH`otABXAKP~41n@rtS6a{CXajSfq_=un z^avQ<1}?69n!E>G?f|1tx@1U>T3B0I5-3* zE0n$N@$SL?-u^w)?e7P8)pDtYn)2xY000JJOGiWi#{fqFM?V|D!T;M8Y0q^^y0^no- X6EYmyq4EX300000NkvXXu0mjf??3+j literal 0 HcmV?d00001 diff --git a/scenes/CustomNotes/assets/double_note.png.import b/scenes/CustomNotes/assets/double_note.png.import new file mode 100644 index 00000000..cabfbea9 --- /dev/null +++ b/scenes/CustomNotes/assets/double_note.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://caw70lr5e1yiq" +path="res://.godot/imported/double_note.png-b077a9744f626fbc60d331cfc2e231a0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://scenes/CustomNotes/assets/double_note.png" +dest_files=["res://.godot/imported/double_note.png-b077a9744f626fbc60d331cfc2e231a0.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/CustomNotes/assets/single_note.png b/scenes/CustomNotes/assets/single_note.png new file mode 100644 index 0000000000000000000000000000000000000000..4f62a191423febe50718c823cf17d53e346732b7 GIT binary patch literal 612 zcmV-q0-ODbP)EX>4Tx04R}tkv&MmKpe$i(@LdO9PA+CkfA!+#fmtVDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRomua!V=QRK!l7YYN*3Pj8=^l6It3%dicj2e}-H#xoTkK zSU>|RB*zc_2fw>D%kgP9DVzibUTphg0toH`otABXAKP~41n@rtS6a{CXajSfq_=un z^avQ<1}?69n!E>G?f|1tx@1U>T3B0I5-3* zE0n$N@$SL?-u^w)?e7P8)pDtYn)2xY000JJOGiWi#{fqFM?V|D!TtZ&;d!2~Er75Jq90000>R@u0hBMb0Tj4c20>gs7E@M8JL>=B_TpbuRBYB%Szc<27#y8s!RWhjlEI!G-C9+vOaoc zUsB$mDy|lM@lIBd=tk%H&)d`6Ui)PC3g4Tx)ip!*U2R0yl0m=y=cSi&s@R7YSC4Jq zeq9t5($yr(df?NU>GPEwUt0L7@4nYJR2fH-k3GGEJVp|hZ|d3~D{n>+uSzyK*Gab)LPy7cxn%YM^exAs)-ib3?&o5zXnl#~@2OZII&esam?V*G=Vg*A%jW5rb! zg{`f%*Xm#0_g+ItLj^iI@0M5-`(gT?{#Cn|N+Wx3wr}tM*8cE0^xVtq-Wv-mue(uq zVC~*VZS~8_c9-Kx=RTsD<#z_nA(#JiH`42J|FzPCuiUJqOxWfi|JSYtFo#sbzQcoc z7F%C*Rny)-hSe@wU&ANfN^AIeWXm@3h1ElUKYjS^fjuX#nm_n$btJPSXXUY|sxvj2 zkCOVR>IX~n&wjS`==S?RP2D@T_TXJb$D3_oU7c$xD}3uux27H`Il6d3*wN^nk54ot zB#U=%*?`+uzZ(+Vbl30MtNoXn*ZwQ#SJ}@8jI?Mz?$Ctx`1BY%9>td&`6eKAhi}73 zLrb6cK)it~Y5x2t__^RMTbxR;@cmw|)MG*22VROz&xxrne<&ZT^Tu~9sQmZE%f%mW z8$-T0z434AE3Hv@R^4E6t#jeXH(&SHWIo%4WLDY_;R9cF!Nx0LVT0uv*AWzF5tB4$ z24a`R20ITy;u2gok}3o|Y6khNRVTW4p+$tUv`(~9X~d1TWKh7Sm)Sv1S!OO(R!C`S zQ9^uRoQr@27QmCJ%Ti=@5H6j_%}c<0!7LG>ZU|qf6Xh9AXfkI9s6wm|<5-G|Es=@h z1JO7;%@Eo8)Nu;5>Nyz5bA(Yr87dN8H}b$ z4?%)_)?#yeL9u5bd6ta{8T2}l5TBqq zilqt9tyZp*sgw+c11XLv005X)4$PR^Oi6)8iOXm+GmXk%b?~H>0s<8z7qgIup`;X} zRBAD^jFMssB~V}*prtVxt)gg(maDa-avH^YI}5v#ESjE`Kt)3;sa7Qia$13rYK;<8 zsMJc#%-}MZ9L=a1rCLJ*4;4)jshr(H!tG=&WImACtoiO3g5X4=$)FR-#Q2oOR7CO& zbbx1owbGo^F}0M-T0jm@3VKS_a;;P?#c{P(qfkn;VoX#UC;2}; z;@p5~BL@0;Y;bhJNhp~dh2we&L+3~QjPJvb7y(kx1(}t;b8^keH7f;X1)l4!Ik{$~ zz^uS?-SvaX6*%=W1+4HNkQ2Ttb^r6D2>6=iYtBg1BOOQ@l9mv0r43pFZ0VaE2olmR ze7!oj(=;^t@djgx-yQEjzj+bszUrdeYt2 z_VRT_<0945#V_b@gLAKUHTJnaSsy4pugng+6y6_dVH05zj#>QvJ{1e_=&)A~;M~y?nJ-v+$&B&jt5#ImK=!1hL zbV#>Pz@z9dm4112&~=|izxm}zDB@lIZhcN{N)}?$T+vXS8^}Sg+UQLnX{$@nOC^g j_KNm}!x#T>cX-jKV;QI3Kjhs4i$@G8nfivLtrh Date: Mon, 10 Feb 2025 17:13:06 -0800 Subject: [PATCH 2/5] temporary changes, will fix later --- Globals/Scribe.cs | 9 ++++++++ scenes/CustomNotes/NoteQueue.cs | 37 ++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Globals/Scribe.cs b/Globals/Scribe.cs index b1b9884a..1970b280 100644 --- a/Globals/Scribe.cs +++ b/Globals/Scribe.cs @@ -27,6 +27,15 @@ public partial class Scribe : Node director.Enemy.TakeDamage((int)timing); } ), + new Note( + "PlayerDouble", + null, + 2, + (director, note, timing) => + { + director.Enemy.TakeDamage((int)timing); + } + ), }; public static readonly RelicTemplate[] RelicDictionary = new[] diff --git a/scenes/CustomNotes/NoteQueue.cs b/scenes/CustomNotes/NoteQueue.cs index b15f219e..a2113fb9 100644 --- a/scenes/CustomNotes/NoteQueue.cs +++ b/scenes/CustomNotes/NoteQueue.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using FunkEngine; using Godot; public partial class NoteQueue : Node @@ -10,51 +11,59 @@ public partial class NoteQueue : Node [Export] private Sprite2D _nextNote; - private Queue _noteQueue = new Queue(); + private Queue _noteQueue = new Queue(); private Dictionary _noteSprites = new Dictionary(); public override void _Ready() { - _noteSprites["single"] = GD.Load( + _noteSprites["PlayerBase"] = GD.Load( "res://scenes/CustomNotes/assets/single_note.png" ); - _noteSprites["double"] = GD.Load( + _noteSprites["PlayerDouble"] = GD.Load( "res://scenes/CustomNotes/assets/double_note.png" ); UpdateQueue(); } - public void AddNoteToQueue(string noteType) + public void LoadQueue(PlayerPuppet player) + { + for (int i = 0; i < player.Stats.CurNotes.Length; i++) + { + AddNoteToQueue(player.Stats.CurNotes[i]); + } + } + + public void AddNoteToQueue(Note noteType) { _noteQueue.Enqueue(noteType); UpdateQueue(); } //returns current note, and removes it from the queue - public string GetCurrentNote() + public Note GetCurrentNote() { if (_noteQueue.Count > 0) { - string currentNoteName = _noteQueue.Dequeue(); + Note currentNote = _noteQueue.Dequeue(); UpdateQueue(); - return currentNoteName; + return currentNote; } return null; } private void UpdateQueue() { - if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek())) - _currentNote.Texture = _noteSprites[_noteQueue.Peek()]; + if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek().Name)) + _currentNote.Texture = _noteSprites[_noteQueue.Peek().Name]; else _currentNote.Texture = null; if (_noteQueue.Count > 1) { - string[] notes = _noteQueue.ToArray(); - if (_noteSprites.ContainsKey(notes[1])) - _nextNote.Texture = _noteSprites[notes[1]]; + Note[] notes = _noteQueue.ToArray(); + if (_noteSprites.ContainsKey(notes[1].Name)) + _nextNote.Texture = _noteSprites[notes[1].Name]; else _nextNote.Texture = null; } @@ -67,7 +76,7 @@ private void UpdateQueue() //Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619 public void ScrambleQueue() { - List tempList = new List(_noteQueue); + List tempList = new List(_noteQueue); Random rng = new Random(); int n = tempList.Count; @@ -78,7 +87,7 @@ public void ScrambleQueue() (tempList[k], tempList[n]) = (tempList[n], tempList[k]); } - _noteQueue = new Queue(tempList); + _noteQueue = new Queue(tempList); } //TODO: should work, in order to run in game use From 3b798137a57c3fc5ef488e5e25f64dfddfac2c99 Mon Sep 17 00:00:00 2001 From: cornerloan Date: Tue, 11 Feb 2025 00:37:43 -0800 Subject: [PATCH 3/5] added loading notes from JSON file SaveData.json can store all our game's save data (unless we want to split the save data amongst different files). NoteQueue now pulls notes from the SaveData. --- Funk Engine.csproj | 3 ++ Globals/Scribe.cs | 6 ++- SaveData/SaveData.json | 9 ++++ SaveData/SaveSystem.cs | 48 ++++++++++++++++++ scenes/BattleDirector/test_battle_scene.tscn | 14 +++++- scenes/CustomNotes/NoteQueue.cs | 53 +++++++++++++++++--- scenes/CustomNotes/NoteQueue.tscn | 4 +- 7 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 SaveData/SaveData.json create mode 100644 SaveData/SaveSystem.cs diff --git a/Funk Engine.csproj b/Funk Engine.csproj index 7051324c..f8d51ba9 100644 --- a/Funk Engine.csproj +++ b/Funk Engine.csproj @@ -6,6 +6,9 @@ true FunkEngine + + + diff --git a/Globals/Scribe.cs b/Globals/Scribe.cs index 1970b280..aa155d75 100644 --- a/Globals/Scribe.cs +++ b/Globals/Scribe.cs @@ -30,10 +30,12 @@ public partial class Scribe : Node new Note( "PlayerDouble", null, - 2, + 1, (director, note, timing) => { - director.Enemy.TakeDamage((int)timing); + // can change later, but I want it like this instead of changing base + // in case we have some relic that messes with timing + director.Enemy.TakeDamage(2 * (int)timing); } ), }; diff --git a/SaveData/SaveData.json b/SaveData/SaveData.json new file mode 100644 index 00000000..1aeaf3cc --- /dev/null +++ b/SaveData/SaveData.json @@ -0,0 +1,9 @@ +{ + "AccountName": null, + "Notes": { + "PlayerBase": 2, + "PlayerDouble": 1 + }, + "Relics": {}, + "Settings": {} +} \ No newline at end of file diff --git a/SaveData/SaveSystem.cs b/SaveData/SaveSystem.cs new file mode 100644 index 00000000..7cc7af03 --- /dev/null +++ b/SaveData/SaveSystem.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using Godot; + +// TODO: implement saving + +public static class SaveSystem +{ + private static string SavePath => "res://SaveData/SaveData.json"; // Update if needed + + // Loads only the notes section + public static Dictionary LoadNotes() + { + var saveData = LoadSaveData(); + if (saveData != null && saveData.Notes != null) + { + return saveData.Notes; + } + else + { + return new Dictionary(); + } + } + + // This method loads the entire save data + public static SaveData LoadSaveData() + { + string path = ProjectSettings.GlobalizePath(SavePath); + if (!File.Exists(path)) + { + GD.PrintErr("Can't load save game"); + return null; + } + + string json = File.ReadAllText(path); + SaveData data = JsonSerializer.Deserialize(json); + return data; + } +} + +public class SaveData +{ + public string AccountName { get; set; } + public Dictionary Notes { get; set; } = new Dictionary(); + public Dictionary Relics { get; set; } = new Dictionary(); + public Dictionary Settings { get; set; } = new Dictionary(); +} diff --git a/scenes/BattleDirector/test_battle_scene.tscn b/scenes/BattleDirector/test_battle_scene.tscn index 5fb1a81c..b9ccc3db 100644 --- a/scenes/BattleDirector/test_battle_scene.tscn +++ b/scenes/BattleDirector/test_battle_scene.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=3 uid="uid://b0mrgr7h0ty1y"] +[gd_scene load_steps=9 format=3 uid="uid://b0mrgr7h0ty1y"] [ext_resource type="Script" path="res://scenes/BattleDirector/scripts/BattleDirector.cs" id="1_cwqqr"] [ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://scenes/ChartViewport/ChartViewport.tscn" id="2_cupb3"] [ext_resource type="Script" path="res://scenes/BattleDirector/scripts/Conductor.cs" id="2_pcp76"] [ext_resource type="Texture2D" uid="uid://ci0g72j8q4ec2" path="res://scenes/BattleDirector/assets/CoolBG.jpg" id="4_13o87"] [ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="7_3ko4g"] +[ext_resource type="PackedScene" uid="uid://bvhpon5liybd1" path="res://scenes/CustomNotes/NoteQueue.tscn" id="8_7wwxo"] [ext_resource type="AudioStream" uid="uid://cv6lqjj6lu36h" path="res://Audio/335571__magntron__gamemusic_120bpm.mp3" id="8_caqms"] [ext_resource type="Script" path="res://scenes/SceneTransitions/scripts/SceneChange.cs" id="9_bxa6e"] @@ -62,3 +63,14 @@ offset_right = 613.0 offset_bottom = 188.0 theme_override_font_sizes/font_size = 10 text = "Relics:" + +[node name="NoteQueue" parent="." instance=ExtResource("8_7wwxo")] +anchors_preset = 0 +anchor_right = 0.0 +anchor_bottom = 0.0 +offset_left = 100.0 +offset_top = 140.0 +offset_right = 100.0 +offset_bottom = 140.0 +grow_horizontal = 1 +grow_vertical = 1 diff --git a/scenes/CustomNotes/NoteQueue.cs b/scenes/CustomNotes/NoteQueue.cs index a2113fb9..93725852 100644 --- a/scenes/CustomNotes/NoteQueue.cs +++ b/scenes/CustomNotes/NoteQueue.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using FunkEngine; using Godot; public partial class NoteQueue : Node @@ -23,15 +22,56 @@ public override void _Ready() "res://scenes/CustomNotes/assets/double_note.png" ); + LoadQueueFromSave(); + ScrambleQueue(); UpdateQueue(); } - public void LoadQueue(PlayerPuppet player) + // Loads the notes from SaveData.json, and adds them to the queue + public void LoadQueueFromSave() { - for (int i = 0; i < player.Stats.CurNotes.Length; i++) + Dictionary savedNotes = SaveSystem.LoadNotes(); + foreach (var noteEntry in savedNotes) { - AddNoteToQueue(player.Stats.CurNotes[i]); + string noteName = noteEntry.Key; + int numNotes = noteEntry.Value; + + for (int i = 0; i < numNotes; i++) + { + AddNoteToQueue(CreateNoteFromName(noteName)); + } + } + } + + // Creates a note from a string of the note's name. + private Note CreateNoteFromName(string noteName) + { + if (noteName == "PlayerBase") + { + return new Note( + "PlayerBase", + null, + 1, + (director, note, timing) => + { + director.Enemy.TakeDamage((int)timing); + } + ); + } + if (noteName == "PlayerDouble") + { + return new Note( + "PlayerDouble", + null, + 1, + (director, note, timing) => + { + director.Enemy.TakeDamage(2 * (int)timing); + } + ); } + + return null; } public void AddNoteToQueue(Note noteType) @@ -40,7 +80,7 @@ public void AddNoteToQueue(Note noteType) UpdateQueue(); } - //returns current note, and removes it from the queue + // Returns current note, and removes it from the queue public Note GetCurrentNote() { if (_noteQueue.Count > 0) @@ -52,6 +92,7 @@ public Note GetCurrentNote() return null; } + // Updates the queue's graphics private void UpdateQueue() { if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek().Name)) @@ -73,7 +114,7 @@ private void UpdateQueue() } } - //Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619 + // Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619 public void ScrambleQueue() { List tempList = new List(_noteQueue); diff --git a/scenes/CustomNotes/NoteQueue.tscn b/scenes/CustomNotes/NoteQueue.tscn index 62b81618..d5e4b570 100644 --- a/scenes/CustomNotes/NoteQueue.tscn +++ b/scenes/CustomNotes/NoteQueue.tscn @@ -5,7 +5,7 @@ [ext_resource type="Texture2D" uid="uid://c3chrsxrulapd" path="res://scenes/CustomNotes/assets/single_note.png" id="3_ewo1s"] [ext_resource type="Texture2D" uid="uid://caw70lr5e1yiq" path="res://scenes/CustomNotes/assets/double_note.png" id="4_7sgy6"] -[node name="NoteQueue" type="Control"] +[node name="NoteQueue" type="Control" node_paths=PackedStringArray("_currentNote", "_nextNote")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -13,6 +13,8 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_jeqam") +_currentNote = NodePath("CurrentNote") +_nextNote = NodePath("NextNote") [node name="NoteQueueSprite" type="Sprite2D" parent="."] texture = ExtResource("2_0p21a") From a7f9dee67b764b8f590f641e40a42a78ce39d429 Mon Sep 17 00:00:00 2001 From: cornerloan Date: Tue, 11 Feb 2025 17:35:50 -0800 Subject: [PATCH 4/5] updated battledirector to pull the note from queue --- scenes/BattleDirector/scripts/BattleDirector.cs | 11 +++++++++++ scenes/CustomNotes/NoteQueue.cs | 13 ++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/scenes/BattleDirector/scripts/BattleDirector.cs b/scenes/BattleDirector/scripts/BattleDirector.cs index 8338ddfb..71eebaf6 100644 --- a/scenes/BattleDirector/scripts/BattleDirector.cs +++ b/scenes/BattleDirector/scripts/BattleDirector.cs @@ -32,11 +32,22 @@ public partial class BattleDirector : Node2D private SongData _curSong; + [Export] + private NoteQueue NQ; + #endregion #region Note Handling private void PlayerAddNote(ArrowType type, int beat) { + //TODO: note that should be added from the queue + Note note = NQ.GetCurrentNote(); + if (note == null) + { + GD.Print("No notes in queue"); + return; + } + GD.Print($"Player trying to place {type} typed note at beat: " + beat); if (!NotePlacementBar.CanPlaceNote()) return; diff --git a/scenes/CustomNotes/NoteQueue.cs b/scenes/CustomNotes/NoteQueue.cs index 93725852..620cc4fb 100644 --- a/scenes/CustomNotes/NoteQueue.cs +++ b/scenes/CustomNotes/NoteQueue.cs @@ -85,13 +85,17 @@ public Note GetCurrentNote() { if (_noteQueue.Count > 0) { - Note currentNote = _noteQueue.Dequeue(); - UpdateQueue(); - return currentNote; + return _noteQueue.Peek(); } return null; } + public void DequeueNote() + { + _noteQueue.Dequeue(); + UpdateQueue(); + } + // Updates the queue's graphics private void UpdateQueue() { @@ -131,6 +135,5 @@ public void ScrambleQueue() _noteQueue = new Queue(tempList); } - //TODO: should work, in order to run in game use - // noteQueueInstance.AddNoteToQueue("single"); + //TODO: MAYBE? implement saving the notequeue to savedata } From 9567f8485d232ea1cebce72e97f6f702aaa74ab2 Mon Sep 17 00:00:00 2001 From: cornerloan Date: Wed, 12 Feb 2025 23:58:59 -0800 Subject: [PATCH 5/5] Added a reference to the Note in NoteArrow NoteArrow has been given a variable of type Note to represent what special note is held in there. Notes created by the chart or enemy are assigned the type enemy, while notes placed by the player are assigned based on the noteQueue. Also, the queue doesn't "loop" so when the player runs out, they can no longer place notes. --- .../BattleDirector/scripts/BattleDirector.cs | 5 ++-- scenes/BattleDirector/scripts/Conductor.cs | 20 +++++++++----- scenes/BattleDirector/test_battle_scene.tscn | 3 ++- scenes/ChartViewport/ChartManager.cs | 9 ++++--- scenes/CustomNotes/NoteQueue.cs | 27 ++++--------------- scenes/NoteManager/scripts/NoteArrow.cs | 3 ++- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/scenes/BattleDirector/scripts/BattleDirector.cs b/scenes/BattleDirector/scripts/BattleDirector.cs index 71eebaf6..8ab209e1 100644 --- a/scenes/BattleDirector/scripts/BattleDirector.cs +++ b/scenes/BattleDirector/scripts/BattleDirector.cs @@ -48,14 +48,15 @@ private void PlayerAddNote(ArrowType type, int beat) return; } - GD.Print($"Player trying to place {type} typed note at beat: " + beat); + GD.Print($"Player trying to place {note.Name}:{type} typed note at beat: " + beat); if (!NotePlacementBar.CanPlaceNote()) return; - if (CD.AddNoteToLane(type, beat % CM.BeatsPerLoop, false)) + if (CD.AddNoteToLane(type, beat % CM.BeatsPerLoop, note, false)) { NotePlacementBar.PlacedNote(); NotePlaced?.Invoke(this); GD.Print("Note Placed."); + NQ.DequeueNote(); } } diff --git a/scenes/BattleDirector/scripts/Conductor.cs b/scenes/BattleDirector/scripts/Conductor.cs index e62ece9e..4d033b17 100644 --- a/scenes/BattleDirector/scripts/Conductor.cs +++ b/scenes/BattleDirector/scripts/Conductor.cs @@ -42,7 +42,7 @@ private bool IsNoteActive(ArrowType type, int beat) return _laneData[(int)type][beat] != null && _laneData[(int)type][beat].IsActive; } - public bool AddNoteToLane(ArrowType type, int beat, bool isActive = true) + public bool AddNoteToLane(ArrowType type, int beat, Note note, bool isActive = true) { beat %= CM.BeatsPerLoop; //Don't add dupe notes //Beat at 0 is too messy. @@ -54,12 +54,18 @@ public bool AddNoteToLane(ArrowType type, int beat, bool isActive = true) NoteArrow arrow; if (isActive) { - arrow = CM.AddArrowToLane(type, beat, Notes.Length - 1); + arrow = CM.AddArrowToLane(type, beat, Notes.Length - 1, note); arrow.NoteIdx = 1; } else { - arrow = CM.AddArrowToLane(type, beat, Notes.Length - 1, new Color(1, 0.43f, 0.26f)); + arrow = CM.AddArrowToLane( + type, + beat, + Notes.Length - 1, + note, + new Color(1, 0.43f, 0.26f) + ); arrow.NoteIdx = 0; } @@ -85,22 +91,22 @@ private void AddExampleNotes() GD.Print(CM.BeatsPerLoop); for (int i = 1; i < 15; i++) { - AddNoteToLane(ArrowType.Up, i * 4); + AddNoteToLane(ArrowType.Up, i * 4, Scribe.NoteDictionary[0]); } for (int i = 1; i < 15; i++) { - AddNoteToLane(ArrowType.Left, 4 * i + 1); + AddNoteToLane(ArrowType.Left, 4 * i + 1, Scribe.NoteDictionary[0]); } for (int i = 0; i < 10; i++) { - AddNoteToLane(ArrowType.Right, 3 * i + 32); + AddNoteToLane(ArrowType.Right, 3 * i + 32, Scribe.NoteDictionary[0]); } for (int i = 0; i < 3; i++) { - AddNoteToLane(ArrowType.Down, 8 * i + 16); + AddNoteToLane(ArrowType.Down, 8 * i + 16, Scribe.NoteDictionary[0]); } } diff --git a/scenes/BattleDirector/test_battle_scene.tscn b/scenes/BattleDirector/test_battle_scene.tscn index b9ccc3db..1a5b3557 100644 --- a/scenes/BattleDirector/test_battle_scene.tscn +++ b/scenes/BattleDirector/test_battle_scene.tscn @@ -9,12 +9,13 @@ [ext_resource type="AudioStream" uid="uid://cv6lqjj6lu36h" path="res://Audio/335571__magntron__gamemusic_120bpm.mp3" id="8_caqms"] [ext_resource type="Script" path="res://scenes/SceneTransitions/scripts/SceneChange.cs" id="9_bxa6e"] -[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NotePlacementBar", "CD", "Audio")] +[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NotePlacementBar", "CD", "Audio", "NQ")] script = ExtResource("1_cwqqr") CM = NodePath("SubViewport") NotePlacementBar = NodePath("NotePlacementBar") CD = NodePath("Conductor") Audio = NodePath("AudioStreamPlayer") +NQ = NodePath("NoteQueue") [node name="Conductor" type="Node" parent="." node_paths=PackedStringArray("CM")] script = ExtResource("2_pcp76") diff --git a/scenes/ChartViewport/ChartManager.cs b/scenes/ChartViewport/ChartManager.cs index c44c3a2c..6e024ad0 100644 --- a/scenes/ChartViewport/ChartManager.cs +++ b/scenes/ChartViewport/ChartManager.cs @@ -102,11 +102,12 @@ public NoteArrow AddArrowToLane( ArrowType type, int beat, int noteIdx, + Note note, Color colorOverride = default ) { - var newNote = CreateNote(type, beat); - var loopArrow = CreateNote(type, beat + BeatsPerLoop); //Create a dummy arrow for looping visuals + var newNote = CreateNote(type, note, beat); + var loopArrow = CreateNote(type, note, beat + BeatsPerLoop); //Create a dummy arrow for looping visuals if (colorOverride != default) { newNote.Modulate = colorOverride; @@ -116,11 +117,11 @@ public NoteArrow AddArrowToLane( return newNote; } - private NoteArrow CreateNote(ArrowType arrow, int beat = 0) + private NoteArrow CreateNote(ArrowType arrow, Note note, int beat = 0) { var noteScene = ResourceLoader.Load("res://scenes/NoteManager/note.tscn"); NoteArrow newArrow = noteScene.Instantiate(); - newArrow.Init(IH.Arrows[(int)arrow], beat); + newArrow.Init(IH.Arrows[(int)arrow], beat, note); _arrowGroup.AddChild(newArrow); newArrow.Bounds = (float)((double)beat / BeatsPerLoop * (ChartLength / 2)); diff --git a/scenes/CustomNotes/NoteQueue.cs b/scenes/CustomNotes/NoteQueue.cs index 620cc4fb..700a6c2f 100644 --- a/scenes/CustomNotes/NoteQueue.cs +++ b/scenes/CustomNotes/NoteQueue.cs @@ -38,6 +38,7 @@ public void LoadQueueFromSave() for (int i = 0; i < numNotes; i++) { + GD.Print($"Creating note from noteName: {noteName}"); AddNoteToQueue(CreateNoteFromName(noteName)); } } @@ -47,30 +48,12 @@ public void LoadQueueFromSave() private Note CreateNoteFromName(string noteName) { if (noteName == "PlayerBase") - { - return new Note( - "PlayerBase", - null, - 1, - (director, note, timing) => - { - director.Enemy.TakeDamage((int)timing); - } - ); - } + return Scribe.NoteDictionary[1]; + if (noteName == "PlayerDouble") - { - return new Note( - "PlayerDouble", - null, - 1, - (director, note, timing) => - { - director.Enemy.TakeDamage(2 * (int)timing); - } - ); - } + return Scribe.NoteDictionary[2]; + GD.Print($"Failed to create not from noteName: {noteName}"); return null; } diff --git a/scenes/NoteManager/scripts/NoteArrow.cs b/scenes/NoteManager/scripts/NoteArrow.cs index 71105b6b..220141d6 100644 --- a/scenes/NoteManager/scripts/NoteArrow.cs +++ b/scenes/NoteManager/scripts/NoteArrow.cs @@ -12,8 +12,9 @@ public partial class NoteArrow : Sprite2D public int Beat; public float Bounds; public bool IsActive; + public Note NoteRef; - public void Init(ArrowData parentArrowData, int beat) + public void Init(ArrowData parentArrowData, int beat, Note note) { ZIndex = 1;