diff --git a/source/Caching.hx b/source/Caching.hx index 2c6fb50..1cbbcd6 100644 --- a/source/Caching.hx +++ b/source/Caching.hx @@ -83,6 +83,7 @@ class Caching extends MusicBeatState var images = []; var music = []; + var charts = []; trace("caching images..."); @@ -99,6 +100,7 @@ class Caching extends MusicBeatState { music.push(i); } + toBeDone = Lambda.count(images) + Lambda.count(music); @@ -120,6 +122,7 @@ class Caching extends MusicBeatState done++; } + trace("Finished caching..."); FlxG.switchState(new TitleState()); diff --git a/source/DiffCalc.hx b/source/DiffCalc.hx new file mode 100644 index 0000000..72cfa56 --- /dev/null +++ b/source/DiffCalc.hx @@ -0,0 +1,96 @@ +import Song.SwagSong; + +class SmallNote // basically Note.hx but small as fuck +{ + public var strumTime:Float; + public var noteData:Int; + + public function new(strum,data) + { + strumTime = strum; + noteData = data; + } +} + +class DiffCalc +{ + public static function CalculateDiff(song:SwagSong) + { + // cleaned notes + var cleanedNotes:Array = []; + + // find all of the notes + for(i in song.notes) // sections + { + for (ii in i.sectionNotes) // notes + { + var gottaHit = true; + if (ii[2] >= 1) // skip helds + continue; + if (ii[1] > 3) // if the note data is greater than 3 + gottaHit = !i.mustHitSection; + if (gottaHit) + cleanedNotes.push(new SmallNote(ii[0],ii[1])); + } + } + + cleanedNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime)); + + var firstNoteTime = cleanedNotes[0].strumTime; + + trace(firstNoteTime); + + // normalize the notes + for(i in cleanedNotes) + { + i.strumTime = (i.strumTime - firstNoteTime) * 2; + } + + // length in segments of the song + var length = ((cleanedNotes[cleanedNotes.length - 1].strumTime / 1000) / 0.5); + + trace(length); + + // hackey way of creating a array with a length + var segments:Array = new_Array(1,Std.int(length)); + + // algo loop + for(i in cleanedNotes) + { + var index = Std.int(i.strumTime / 1000); + if (index + 1 > segments.length) + continue; + segments[index] = segments[index] + 1; + } + + // get the average of all of the segments + var sum:Float = 0; + + var newLength = segments.length; + + for (i in segments) + { + if (i == 0) // remove empty/breaks + { + newLength--; + continue; + } + sum += i / .5; // half it because otherwise instead of nps its just fucking notes per half second which is dumb and stupid + } + + trace(sum + " - " + newLength); + + return HelperFunctions.truncateFloat(sum / newLength,2); + } + + static public function new_Array( ArrayType:T, Length:Int ):Array { + var empty:Null = null; + var newArray:Array = new Array(); + + for ( i in 0...Length ) { + newArray.push( empty ); + } + + return newArray; + } +} \ No newline at end of file diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index 243d970..64ea9c4 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -1,5 +1,6 @@ package; +import Song.SwagSong; import flixel.input.gamepad.FlxGamepad; import flash.text.TextField; import flixel.FlxG; @@ -29,6 +30,7 @@ class FreeplayState extends MusicBeatState var scoreText:FlxText; var comboText:FlxText; var diffText:FlxText; + var diffCalcText:FlxText; var lerpScore:Int = 0; var intendedScore:Int = 0; var combo:String = ''; @@ -38,6 +40,20 @@ class FreeplayState extends MusicBeatState private var iconArray:Array = []; + public static var songData:Map> = []; + + public static function loadDiff(diff:Int, format:String, name:String, array:Array) + { + try + { + array.push(Song.loadFromJson(Highscore.formatSong(format, diff), name)); + } + catch(ex) + { + // do nada + } + } + override function create() { var initSonglist = CoolUtil.coolTextFile(Paths.txt('freeplaySonglist')); @@ -45,7 +61,21 @@ class FreeplayState extends MusicBeatState for (i in 0...initSonglist.length) { var data:Array = initSonglist[i].split(':'); - songs.push(new SongMetadata(data[0], Std.parseInt(data[2]), data[1])); + var meta = new SongMetadata(data[0], Std.parseInt(data[2]), data[1]); + songs.push(meta); + var format = StringTools.replace(meta.songName, " ", "-"); + switch (format) { + case 'Dad-Battle': format = 'Dadbattle'; + case 'Philly-Nice': format = 'Philly'; + } + + var diffs = []; + FreeplayState.loadDiff(0,format,meta.songName,diffs); + FreeplayState.loadDiff(1,format,meta.songName,diffs); + FreeplayState.loadDiff(2,format,meta.songName,diffs); + FreeplayState.songData.set(meta.songName,diffs); + trace('loaded diffs for ' + meta.songName); + } /* @@ -101,7 +131,7 @@ class FreeplayState extends MusicBeatState scoreText.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE, RIGHT); // scoreText.alignment = RIGHT; - var scoreBG:FlxSprite = new FlxSprite(scoreText.x - 6, 0).makeGraphic(Std.int(FlxG.width * 0.35), 66, 0xFF000000); + var scoreBG:FlxSprite = new FlxSprite(scoreText.x - 6, 0).makeGraphic(Std.int(FlxG.width * 0.35), 105, 0xFF000000); scoreBG.alpha = 0.6; add(scoreBG); @@ -109,6 +139,10 @@ class FreeplayState extends MusicBeatState diffText.font = scoreText.font; add(diffText); + diffCalcText = new FlxText(scoreText.x, scoreText.y + 66, 0, "", 24); + diffCalcText.font = scoreText.font; + add(diffCalcText); + comboText = new FlxText(diffText.x + 100, diffText.y, 0, "", 24); comboText.font = diffText.font; add(comboText); @@ -238,14 +272,20 @@ class FreeplayState extends MusicBeatState case 'Dad-Battle': songFormat = 'Dadbattle'; case 'Philly-Nice': songFormat = 'Philly'; } - - trace(songs[curSelected].songName); + var hmm; + try + { + hmm = songData.get(songs[curSelected].songName)[curDifficulty]; + if (hmm == null) + return; + } + catch(ex) + { + return; + } - var poop:String = Highscore.formatSong(songFormat, curDifficulty); - trace(poop); - - PlayState.SONG = Song.loadFromJson(poop, songs[curSelected].songName); + PlayState.SONG = hmm; PlayState.isStoryMode = false; PlayState.storyDifficulty = curDifficulty; PlayState.storyWeek = songs[curSelected].week; @@ -274,7 +314,7 @@ class FreeplayState extends MusicBeatState intendedScore = Highscore.getScore(songHighscore, curDifficulty); combo = Highscore.getCombo(songHighscore, curDifficulty); #end - + diffCalcText.text = 'RATING: ${DiffCalc.CalculateDiff(songData.get(songs[curSelected].songName)[curDifficulty])}'; diffText.text = CoolUtil.difficultyFromInt(curDifficulty).toUpperCase(); } @@ -310,6 +350,8 @@ class FreeplayState extends MusicBeatState // lerpScore = 0; #end + diffCalcText.text = 'RATING: ${DiffCalc.CalculateDiff(songData.get(songs[curSelected].songName)[curDifficulty])}'; + #if PRELOAD_ALL FlxG.sound.playMusic(Paths.inst(songs[curSelected].songName), 0); #end