From df53254945c3ed79cb27e2b1e9702441cd88238e Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 22 Jan 2022 16:53:38 -0500 Subject: [PATCH] note data shit in progress - strumTime --- source/LatencyState.hx | 2 +- source/Note.hx | 27 +++++++++++++++++------- source/PlayState.hx | 34 ++++++++++++++++-------------- source/Section.hx | 4 +++- source/charting/ChartingState.hx | 36 +++++++++++++++++--------------- 5 files changed, 61 insertions(+), 42 deletions(-) diff --git a/source/LatencyState.hx b/source/LatencyState.hx index 9b8e75d1b..e4214577d 100644 --- a/source/LatencyState.hx +++ b/source/LatencyState.hx @@ -61,7 +61,7 @@ class LatencyState extends FlxState noteGrp.forEach(function(daNote:Note) { - daNote.y = (strumLine.y - (Conductor.songPosition - daNote.strumTime) * 0.45); + daNote.y = (strumLine.y - (Conductor.songPosition - daNote.data.strumTime) * 0.45); daNote.x = strumLine.x + 30; if (daNote.y < strumLine.y) diff --git a/source/Note.hx b/source/Note.hx index 12e3ea5e8..4b78fb137 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -16,7 +16,12 @@ import polymod.format.ParseRules.TargetSignatureElement; class Note extends FlxSprite { - public var strumTime:Float = 0; + public var data:NoteData = { + strumTime: 0, + sustainLength: 0, + altNote: false, + noteData: 0 + }; public var mustPress:Bool = false; public var followsTime:Bool = true; // used if you want the note to follow the time shit! @@ -56,7 +61,7 @@ class Note extends FlxSprite // anything below sick threshold is sick public static var arrowColors:Array = [1, 1, 1, 1]; - public function new(strumTime:Float, noteData:Int, ?prevNote:Note, ?sustainNote:Bool = false) + public function new(strumTime:Float = 0, noteData:Int, ?prevNote:Note, ?sustainNote:Bool = false) { super(); @@ -69,7 +74,7 @@ class Note extends FlxSprite x += 50; // MAKE SURE ITS DEFINITELY OFF SCREEN? y -= 2000; - this.strumTime = strumTime; + data.strumTime = strumTime; this.noteData = noteData; @@ -235,15 +240,15 @@ class Note extends FlxSprite } else { - if (!pastHalfWay && strumTime <= Conductor.songPosition) + if (!pastHalfWay && data.strumTime <= Conductor.songPosition) { pastHalfWay = true; noteSpeedMulti *= 2; } - if (strumTime > Conductor.songPosition - HIT_WINDOW) + if (data.strumTime > Conductor.songPosition - HIT_WINDOW) { // * 0.5 if sustain note, so u have to keep holding it closer to all the way thru! - if (strumTime < Conductor.songPosition + (HIT_WINDOW * (isSustainNote ? 0.5 : 1))) + if (data.strumTime < Conductor.songPosition + (HIT_WINDOW * (isSustainNote ? 0.5 : 1))) canBeHit = true; } else @@ -257,7 +262,7 @@ class Note extends FlxSprite { canBeHit = false; - if (strumTime <= Conductor.songPosition) + if (data.strumTime <= Conductor.songPosition) wasGoodHit = true; } @@ -268,3 +273,11 @@ class Note extends FlxSprite } } } + +typedef NoteData = +{ + var strumTime:Float; + var noteData:Int; + var sustainLength:Float; + var altNote:Bool; +} diff --git a/source/PlayState.hx b/source/PlayState.hx index 16bee1e93..4cdff5287 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1602,11 +1602,11 @@ class PlayState extends MusicBeatState oldNote = null; var swagNote:Note = new Note(daStrumTime, daNoteData, oldNote); - swagNote.sustainLength = songNotes.sustainLength; - swagNote.altNote = songNotes.altNote; + swagNote.data.sustainLength = songNotes.sustainLength; + swagNote.data.altNote = songNotes.altNote; swagNote.scrollFactor.set(0, 0); - var susLength:Float = swagNote.sustainLength; + var susLength:Float = swagNote.data.sustainLength; susLength = susLength / Conductor.stepCrochet; unspawnNotes.push(swagNote); @@ -1647,7 +1647,7 @@ class PlayState extends MusicBeatState function sortNotes(order:Int = FlxSort.ASCENDING, Obj1:Note, Obj2:Note) { - return FlxSort.byValues(order, Obj1.strumTime, Obj2.strumTime); + return FlxSort.byValues(order, Obj1.data.strumTime, Obj2.data.strumTime); } // ^ These two sorts also look cute together ^ @@ -2118,7 +2118,7 @@ class PlayState extends MusicBeatState } } - while (unspawnNotes[0] != null && unspawnNotes[0].strumTime - Conductor.songPosition < 1800 / SongLoad.getSpeed()) + while (unspawnNotes[0] != null && unspawnNotes[0].data.strumTime - Conductor.songPosition < 1800 / SongLoad.getSpeed()) { var dunceNote:Note = unspawnNotes[0]; notes.add(dunceNote); @@ -2145,7 +2145,8 @@ class PlayState extends MusicBeatState var strumLineMid = strumLine.y + Note.swagWidth / 2; if (daNote.followsTime) - daNote.y = (Conductor.songPosition - daNote.strumTime) * (0.45 * FlxMath.roundDecimal(SongLoad.getSpeed(), 2) * daNote.noteSpeedMulti); + daNote.y = (Conductor.songPosition - daNote.data.strumTime) * (0.45 * FlxMath.roundDecimal(SongLoad.getSpeed(), + 2) * daNote.noteSpeedMulti); if (PreferencesMenu.getPref('downscroll')) { @@ -2757,17 +2758,18 @@ class PlayState extends MusicBeatState { if (daNote.canBeHit && daNote.mustPress && !daNote.tooLate && !daNote.wasGoodHit) { - if (directionList.contains(daNote.noteData)) + if (directionList.contains(daNote.data.noteData)) { for (coolNote in possibleNotes) { - if (coolNote.noteData == daNote.noteData && Math.abs(daNote.strumTime - coolNote.strumTime) < 10) + if (coolNote.data.noteData == daNote.data.noteData + && Math.abs(daNote.data.strumTime - coolNote.data.strumTime) < 10) { // if it's the same note twice at < 10ms distance, just delete it // EXCEPT u cant delete it in this loop cuz it fucks with the collection lol dumbNotes.push(daNote); break; } - else if (coolNote.noteData == daNote.noteData && daNote.strumTime < coolNote.strumTime) + else if (coolNote.data.noteData == daNote.data.noteData && daNote.data.strumTime < coolNote.data.strumTime) { // if daNote is earlier than existing note (coolNote), replace possibleNotes.remove(coolNote); possibleNotes.push(daNote); @@ -2778,20 +2780,20 @@ class PlayState extends MusicBeatState else { possibleNotes.push(daNote); - directionList.push(daNote.noteData); + directionList.push(daNote.data.noteData); } } }); for (note in dumbNotes) { - FlxG.log.add("killing dumb ass note at " + note.strumTime); + FlxG.log.add("killing dumb ass note at " + note.data.strumTime); note.kill(); notes.remove(note, true); note.destroy(); } - possibleNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime)); + possibleNotes.sort((a, b) -> Std.int(a.data.strumTime - b.data.strumTime)); if (perfectMode) goodNoteHit(possibleNotes[0]); @@ -2804,7 +2806,7 @@ class PlayState extends MusicBeatState } for (coolNote in possibleNotes) { - if (pressArray[coolNote.noteData]) + if (pressArray[coolNote.data.noteData]) goodNoteHit(coolNote); } } @@ -2910,10 +2912,10 @@ class PlayState extends MusicBeatState if (!note.isSustainNote) { combo += 1; - popUpScore(note.strumTime, note); + popUpScore(note.data.strumTime, note); } - switch (note.noteData) + switch (note.data.noteData) { case 0: boyfriend.playAnim('singLEFT', true); @@ -2927,7 +2929,7 @@ class PlayState extends MusicBeatState playerStrums.forEach(function(spr:FlxSprite) { - if (Math.abs(note.noteData) == spr.ID) + if (Math.abs(note.data.noteData) == spr.ID) { spr.animation.play('confirm', true); } diff --git a/source/Section.hx b/source/Section.hx index b4e449326..e1fc84f5e 100644 --- a/source/Section.hx +++ b/source/Section.hx @@ -1,8 +1,10 @@ package; +import Note.NoteData; + typedef SwagSection = { - var sectionNotes:Array; + var sectionNotes:Array; var lengthInSteps:Int; var typeOfSection:Int; var mustHitSection:Bool; diff --git a/source/charting/ChartingState.hx b/source/charting/ChartingState.hx index 8228be1eb..04069ee88 100644 --- a/source/charting/ChartingState.hx +++ b/source/charting/ChartingState.hx @@ -1,6 +1,7 @@ package charting; import Conductor.BPMChangeEvent; +import Note.NoteData; import Section.SwagSection; import SongLoad.SwagSong; import dsp.FFT; @@ -29,6 +30,7 @@ import flixel.ui.FlxSpriteButton; import flixel.util.FlxColor; import haxe.CallStack.StackItem; import haxe.Json; +import haxe.Serializer; import lime.media.AudioBuffer; import lime.utils.Assets; import lime.utils.Int16Array; @@ -80,7 +82,7 @@ class ChartingState extends MusicBeatState /* * WILL BE THE CURRENT / LAST PLACED NOTE **/ - var curSelectedNote:Note; + var curSelectedNote:NoteData; var tempBpm:Float = 0; @@ -310,9 +312,10 @@ class ChartingState extends MusicBeatState { for (i in 0...SongLoad.getSong()[curSection].sectionNotes.length) { - var note = SongLoad.getSong()[curSection].sectionNotes[i]; + var note:Note = new Note(0, 0); + note.data = SongLoad.getSong()[curSection].sectionNotes[i]; note.noteData = (note.noteData + 4) % 8; - SongLoad.getSong()[curSection].sectionNotes[i] = note; + SongLoad.getSong()[curSection].sectionNotes[i] = note.data; updateGrid(); } }); @@ -1017,13 +1020,13 @@ class ChartingState extends MusicBeatState { var daSec = FlxMath.maxInt(curSection, sectionNum); - for (note in SongLoad.getSong()[daSec - sectionNum].sectionNotes) + for (noteShit in SongLoad.getSong()[daSec - sectionNum].sectionNotes) { - var strum = note.strumTime + Conductor.stepCrochet * (SongLoad.getSong()[daSec].lengthInSteps * sectionNum); + var strum = noteShit.strumTime + Conductor.stepCrochet * (SongLoad.getSong()[daSec].lengthInSteps * sectionNum); - var copiedNote:Note = new Note(strum, note.noteData); - copiedNote.sustainLength = note.sustainLength; - SongLoad.getSong()[daSec].sectionNotes.push(copiedNote); + var copiedNote:Note = new Note(strum, noteShit.noteData); + copiedNote.data.sustainLength = noteShit.sustainLength; + SongLoad.getSong()[daSec].sectionNotes.push(copiedNote.data); } updateGrid(); @@ -1095,7 +1098,7 @@ class ChartingState extends MusicBeatState curRenderedSustains.remove(curRenderedSustains.members[0], true); } - var sectionInfo:Array = SongLoad.getSong()[curSection].sectionNotes; + var sectionInfo:Array = SongLoad.getSong()[curSection].sectionNotes; if (SongLoad.getSong()[curSection].changeBPM && SongLoad.getSong()[curSection].bpm > 0) { @@ -1133,7 +1136,7 @@ class ChartingState extends MusicBeatState var daSus = i.sustainLength; var note:Note = new Note(daStrumTime, daNoteInfo % 4); - note.sustainLength = daSus; + note.data.sustainLength = daSus; note.setGraphicSize(GRID_SIZE, GRID_SIZE); note.updateHitbox(); note.x = Math.floor(daNoteInfo * GRID_SIZE); @@ -1171,7 +1174,7 @@ class ChartingState extends MusicBeatState for (i in SongLoad.getSong()[curSection].sectionNotes) { - if (i.strumTime == note.strumTime && i.noteData % 4 == note.noteData) + if (i.strumTime == note.data.strumTime && i.noteData % 4 == note.data.noteData) { curSelectedNote = SongLoad.getSong()[curSection].sectionNotes[swagNum]; } @@ -1187,7 +1190,7 @@ class ChartingState extends MusicBeatState { for (i in SongLoad.getSong()[curSection].sectionNotes) { - if (i.strumTime == note.strumTime && i.noteData % 4 == note.noteData) + if (i.strumTime == note.data.strumTime && i.noteData % 4 == note.noteData) { var placeIDK:Int = Std.int(((Math.floor(dummyArrow.y / GRID_SIZE) * GRID_SIZE)) / 40); @@ -1260,7 +1263,7 @@ class ChartingState extends MusicBeatState var daNewNote:Note = new Note(noteStrum, noteData); daNewNote.sustainLength = noteSus; daNewNote.altNote = noteAlt; - SongLoad.getSong()[curSection].sectionNotes.push(daNewNote); + SongLoad.getSong()[curSection].sectionNotes.push(daNewNote.data); curSelectedNote = SongLoad.getSong()[curSection].sectionNotes[SongLoad.getSong()[curSection].sectionNotes.length - 1]; @@ -1275,7 +1278,7 @@ class ChartingState extends MusicBeatState updateGrid(); updateNoteUI(); - // autosaveSong(); + autosaveSong(); } function getStrumTime(yPos:Float):Float @@ -1344,9 +1347,8 @@ class ChartingState extends MusicBeatState function autosaveSong():Void { - FlxG.save.data.autosave = Json.stringify({ - "song": _song - }); + FlxG.save.data.autosave = _song; + trace(FlxG.save.data.autosave); FlxG.save.flush(); }