-
Notifications
You must be signed in to change notification settings - Fork 0
Note effects #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Note effects #50
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0b2063
added note queue system
cornerloan 5e97038
Merge branch 'Sprint-2' into note-effects
cornerloan 2c5311a
temporary changes, will fix later
cornerloan 3b79813
added loading notes from JSON file
cornerloan a7f9dee
updated battledirector to pull the note from queue
cornerloan 9567f84
Added a reference to the Note in NoteArrow
cornerloan 8e3ab6c
Merge branch 'Sprint-2' into note-effects
LifeHckr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "AccountName": null, | ||
| "Notes": { | ||
| "PlayerBase": 2, | ||
| "PlayerDouble": 1 | ||
| }, | ||
| "Relics": {}, | ||
| "Settings": {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<string, int> LoadNotes() | ||
| { | ||
| var saveData = LoadSaveData(); | ||
| if (saveData != null && saveData.Notes != null) | ||
| { | ||
| return saveData.Notes; | ||
| } | ||
| else | ||
| { | ||
| return new Dictionary<string, int>(); | ||
| } | ||
| } | ||
|
|
||
| // 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<SaveData>(json); | ||
| return data; | ||
| } | ||
| } | ||
|
|
||
| public class SaveData | ||
| { | ||
| public string AccountName { get; set; } | ||
| public Dictionary<string, int> Notes { get; set; } = new Dictionary<string, int>(); | ||
| public Dictionary<string, object> Relics { get; set; } = new Dictionary<string, object>(); | ||
| public Dictionary<string, float> Settings { get; set; } = new Dictionary<string, float>(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Godot; | ||
|
|
||
| public partial class NoteQueue : Node | ||
| { | ||
| [Export] | ||
| private Sprite2D _currentNote; | ||
|
|
||
| [Export] | ||
| private Sprite2D _nextNote; | ||
|
|
||
| private Queue<Note> _noteQueue = new Queue<Note>(); | ||
| private Dictionary<string, Texture2D> _noteSprites = new Dictionary<string, Texture2D>(); | ||
|
|
||
| public override void _Ready() | ||
| { | ||
| _noteSprites["PlayerBase"] = GD.Load<Texture2D>( | ||
| "res://scenes/CustomNotes/assets/single_note.png" | ||
| ); | ||
| _noteSprites["PlayerDouble"] = GD.Load<Texture2D>( | ||
| "res://scenes/CustomNotes/assets/double_note.png" | ||
| ); | ||
|
|
||
| LoadQueueFromSave(); | ||
| ScrambleQueue(); | ||
| UpdateQueue(); | ||
| } | ||
|
|
||
| // Loads the notes from SaveData.json, and adds them to the queue | ||
| public void LoadQueueFromSave() | ||
| { | ||
| Dictionary<string, int> savedNotes = SaveSystem.LoadNotes(); | ||
| foreach (var noteEntry in savedNotes) | ||
| { | ||
| string noteName = noteEntry.Key; | ||
| int numNotes = noteEntry.Value; | ||
|
|
||
| for (int i = 0; i < numNotes; i++) | ||
| { | ||
| GD.Print($"Creating note from noteName: {noteName}"); | ||
| AddNoteToQueue(CreateNoteFromName(noteName)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Creates a note from a string of the note's name. | ||
| private Note CreateNoteFromName(string noteName) | ||
| { | ||
| if (noteName == "PlayerBase") | ||
| return Scribe.NoteDictionary[1]; | ||
|
|
||
| if (noteName == "PlayerDouble") | ||
| return Scribe.NoteDictionary[2]; | ||
|
|
||
| GD.Print($"Failed to create not from noteName: {noteName}"); | ||
| return null; | ||
| } | ||
|
|
||
| public void AddNoteToQueue(Note noteType) | ||
| { | ||
| _noteQueue.Enqueue(noteType); | ||
| UpdateQueue(); | ||
| } | ||
|
|
||
| // Returns current note, and removes it from the queue | ||
| public Note GetCurrentNote() | ||
| { | ||
| if (_noteQueue.Count > 0) | ||
| { | ||
| return _noteQueue.Peek(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public void DequeueNote() | ||
| { | ||
| _noteQueue.Dequeue(); | ||
| UpdateQueue(); | ||
| } | ||
|
|
||
| // Updates the queue's graphics | ||
| private void UpdateQueue() | ||
| { | ||
| if (_noteQueue.Count > 0 && _noteSprites.ContainsKey(_noteQueue.Peek().Name)) | ||
| _currentNote.Texture = _noteSprites[_noteQueue.Peek().Name]; | ||
| else | ||
| _currentNote.Texture = null; | ||
|
|
||
| if (_noteQueue.Count > 1) | ||
| { | ||
| Note[] notes = _noteQueue.ToArray(); | ||
| if (_noteSprites.ContainsKey(notes[1].Name)) | ||
| _nextNote.Texture = _noteSprites[notes[1].Name]; | ||
| else | ||
| _nextNote.Texture = null; | ||
| } | ||
| else | ||
| { | ||
| _nextNote.Texture = null; | ||
| } | ||
| } | ||
|
|
||
| // Fisher-Yates shuffle from: https://stackoverflow.com/a/1262619 | ||
| public void ScrambleQueue() | ||
| { | ||
| List<Note> tempList = new List<Note>(_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<Note>(tempList); | ||
| } | ||
|
|
||
| //TODO: MAYBE? implement saving the notequeue to savedata | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| [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" node_paths=PackedStringArray("_currentNote", "_nextNote")] | ||
| layout_mode = 3 | ||
| anchors_preset = 15 | ||
| anchor_right = 1.0 | ||
| 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") | ||
|
|
||
| [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") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔