From 7c451c16b9b0367bb0559db626bff9140219db7c Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sun, 26 Feb 2023 15:39:27 +0100 Subject: [PATCH] fixes --- buildnumber.txt | 2 +- source/funkin/chart/BaseGameParser.hx | 95 ++++++++++++++++++++++++++ source/funkin/chart/Chart.hx | 98 ++------------------------- source/funkin/game/PlayState.hx | 5 +- source/funkin/game/Strum.hx | 10 +-- source/funkin/menus/FreeplayState.hx | 2 +- 6 files changed, 111 insertions(+), 101 deletions(-) create mode 100644 source/funkin/chart/BaseGameParser.hx diff --git a/buildnumber.txt b/buildnumber.txt index eb46a8c0..d97f2fad 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2387 \ No newline at end of file +2392 \ No newline at end of file diff --git a/source/funkin/chart/BaseGameParser.hx b/source/funkin/chart/BaseGameParser.hx new file mode 100644 index 00000000..e97427f3 --- /dev/null +++ b/source/funkin/chart/BaseGameParser.hx @@ -0,0 +1,95 @@ +package funkin.chart; + +import funkin.system.Song.SwagSong; + +class BaseGameParser { + public static function parse(data:Dynamic, result:ChartData) { + // base fnf chart parsing + var data:SwagSong = data; + if (Reflect.hasField(data, "song")) { + var field:Dynamic = Reflect.field(data, "song"); + if (!(field is String)) + data = field; + } + + result.scrollSpeed = data.speed; + result.stage = data.stage; + + result.strumLines.push({ + characters: [data.player2], + opponent: true, + position: "dad", + notes: [] + }); + result.strumLines.push({ + characters: [data.player1], + opponent: false, + position: "boyfriend", + notes: [] + }); + if (data.gf != "none") { + result.strumLines.push({ + characters: [data.gf != null ? data.gf : "gf"], + opponent: true, + position: "girlfriend", + notes: [], + visible: false, + strumLinePos: 0.5 + }); + } + + var camFocusedBF:Bool = false; + var beatsPerMesure:Float = data.beatsPerMesure.getDefault(4); + var curBPM:Float = data.bpm; + var curTime:Float = 0; + var curCrochet:Float = ((60 / curBPM) * 1000); + + if (data.notes != null) for(section in data.notes) { + if (section == null) { + curTime += curCrochet * beatsPerMesure; + continue; // Yoshi Engine charts crash fix + } + + if (camFocusedBF != (camFocusedBF = section.mustHitSection)) { + result.events.push({ + time: curTime, + type: CAM_MOVEMENT, + params: [camFocusedBF ? 1 : 0] + }); + } + + if (section.sectionNotes != null) for(note in section.sectionNotes) { + if (note[1] < 0) continue; + + var daStrumTime:Float = note[0]; + var daNoteData:Int = Std.int(note[1] % 8); + var daNoteType:Int = Std.int(note[1] / 8); + var gottaHitNote:Bool = daNoteData >= 4 ? !section.mustHitSection : section.mustHitSection; + + if (note.length > 2) { + if (note[3] is Int) + daNoteType = Chart.addNoteType(result, data.noteTypes[Std.int(note[3])-1]); + else if (note[3] is String) + daNoteType = Chart.addNoteType(result, note[3]); + } else { + daNoteType = Chart.addNoteType(result, data.noteTypes[daNoteType-1]); + } + + + result.strumLines[gottaHitNote ? 1 : 0].notes.push({ + time: daStrumTime, + id: daNoteData % 4, + type: daNoteType, + sLen: note[2] + }); + } + + if (section.changeBPM && section.bpm != curBPM) { + // TODO: BPM CHANGE EVENT + curCrochet = ((60 / (curBPM = section.bpm)) * 1000); + } + + curTime += curCrochet * beatsPerMesure; + } + } +} \ No newline at end of file diff --git a/source/funkin/chart/Chart.hx b/source/funkin/chart/Chart.hx index a75e10d8..6b6058c8 100644 --- a/source/funkin/chart/Chart.hx +++ b/source/funkin/chart/Chart.hx @@ -14,12 +14,12 @@ import sys.FileSystem; using StringTools; class Chart { - public static function loadChartMeta(songName:String, difficulty:String = "normal") { + public static function loadChartMeta(songName:String, difficulty:String = "normal", fromMods:Bool = true) { var metaPath = Paths.file('songs/${songName.toLowerCase()}/meta.json'); var metaDiffPath = Paths.file('songs/${songName.toLowerCase()}/meta-${difficulty.toLowerCase()}.json'); var data:ChartMetaData = null; - var fromMods:Bool = false; + var fromMods:Bool = fromMods; for(path in [metaDiffPath, metaPath]) { if (Assets.exists(path)) { fromMods = Paths.assetsTree.existsSpecific(path, "TEXT", MODS); @@ -97,103 +97,19 @@ class Chart { } if (Reflect.hasField(data, "codenameChart") && Reflect.field(data, "codenameChart") == true) { + // codename chart base = data; } else { - // base fnf chart parsing - var data:SwagSong = data; - if (Reflect.hasField(data, "song")) { - var field:Dynamic = Reflect.field(data, "song"); - if (!(field is String)) - data = field; - } - - base.scrollSpeed = data.speed; - base.stage = data.stage; - - base.strumLines.push({ - characters: [data.player2], - opponent: true, - position: "dad", - notes: [] - }); - base.strumLines.push({ - characters: [data.player1], - opponent: false, - position: "boyfriend", - notes: [] - }); - if (data.gf != "none") { - base.strumLines.push({ - characters: [data.gf != null ? data.gf : "gf"], - opponent: true, - position: "girlfriend", - notes: [], - visible: false, - strumLinePos: 0.5 - }); - } - - var camFocusedBF:Bool = false; - var beatsPerMesure:Float = data.beatsPerMesure.getDefault(4); - var curBPM:Float = data.bpm; - var curTime:Float = 0; - var curCrochet:Float = ((60 / curBPM) * 1000); - - if (data.notes != null) for(section in data.notes) { - if (section == null) { - curTime += curCrochet * beatsPerMesure; - continue; // Yoshi Engine charts crash fix - } - - if (camFocusedBF != (camFocusedBF = section.mustHitSection)) { - base.events.push({ - time: curTime, - type: CAM_MOVEMENT, - params: [camFocusedBF ? 1 : 0] - }); - } - - if (section.sectionNotes != null) for(note in section.sectionNotes) { - if (note[1] < 0) continue; - - var daStrumTime:Float = note[0]; - var daNoteData:Int = Std.int(note[1] % 8); - var daNoteType:Int = Std.int(note[1] / 8); - var gottaHitNote:Bool = daNoteData >= 4 ? !section.mustHitSection : section.mustHitSection; - - if (note.length > 2) { - if (note[3] is Int) - daNoteType = addNoteType(base, data.noteTypes[Std.int(note[3])-1]); - else if (note[3] is String) - daNoteType = addNoteType(base, note[3]); - } else { - daNoteType = addNoteType(base, data.noteTypes[daNoteType-1]); - } - - - base.strumLines[gottaHitNote ? 1 : 0].notes.push({ - time: daStrumTime, - id: daNoteData % 4, - type: daNoteType, - sLen: note[2] - }); - } - - if (section.changeBPM && section.bpm != curBPM) { - // TODO: BPM CHANGE EVENT - curCrochet = ((60 / (curBPM = section.bpm)) * 1000); - } - - curTime += curCrochet * beatsPerMesure; - } + // base game chart + BaseGameParser.parse(data, base); } if (base.meta == null) - base.meta = loadChartMeta(songName, difficulty); + base.meta = loadChartMeta(songName, difficulty, base.fromMods); return base; } - private static function addNoteType(chart:ChartData, noteTypeName:String):Int { + public static function addNoteType(chart:ChartData, noteTypeName:String):Int { switch(noteTypeName.trim()) { case "Default Note" | null | "": return 0; diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index e74848a0..fcbbfc48 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1086,10 +1086,9 @@ class PlayState extends MusicBeatState if (generatedMusic && players[curCameraTarget] != null) { - var strumLine = players[curCameraTarget]; var pos = FlxPoint.get(); var r = 0; - for(c in strumLine.characters) { + for(c in players[curCameraTarget].characters) { if (c == null) continue; var cpos = c.getCameraPosition(); pos.x += cpos.x; @@ -1101,7 +1100,7 @@ class PlayState extends MusicBeatState pos.x /= r; pos.y /= r; - var event = scripts.event("onCameraMove", EventManager.get(CamMoveEvent).recycle(pos, strumLine, r)); + var event = scripts.event("onCameraMove", EventManager.get(CamMoveEvent).recycle(pos, players[curCameraTarget], r)); if (!event.cancelled) camFollow.setPosition(pos.x, pos.y); } diff --git a/source/funkin/game/Strum.hx b/source/funkin/game/Strum.hx index dc2fa9dc..ff9413e1 100644 --- a/source/funkin/game/Strum.hx +++ b/source/funkin/game/Strum.hx @@ -52,8 +52,8 @@ class Strum extends FlxSprite { daNote.__strumCameras = lastDrawCameras; daNote.__strum = this; daNote.scrollFactor.set(scrollFactor.x, scrollFactor.y); - var noteAngle = daNote.__noteAngle = getNotesAngle(daNote); - daNote.angle = daNote.isSustainNote ? noteAngle : angle; + daNote.__noteAngle = getNotesAngle(daNote); + daNote.angle = daNote.isSustainNote ? daNote.__noteAngle : angle; if (daNote.strumRelativePos) { daNote.setPosition(daNote.isSustainNote ? ((Note.swagWidth - daNote.width) / 2) : 0, (daNote.strumTime - Conductor.songPosition) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2))); @@ -64,9 +64,9 @@ class Strum extends FlxSprite { if (daNote.isSustainNote) offset.y -= N_WIDTHDIV2; - if (Std.int(noteAngle % 360) != 0) { - var noteAngleCos = FlxMath.fastCos(noteAngle / PIX180); - var noteAngleSin = FlxMath.fastSin(noteAngle / PIX180); + if (Std.int(daNote.__noteAngle % 360) != 0) { + var noteAngleCos = FlxMath.fastCos(daNote.__noteAngle / PIX180); + var noteAngleSin = FlxMath.fastSin(daNote.__noteAngle / PIX180); var aOffset:FlxPoint = FlxPoint.get( (daNote.origin.x / daNote.scale.x) - daNote.offset.x, diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 276796a0..507dfe38 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -406,7 +406,7 @@ class FreeplaySonglist { if (songsFound.length > 0) { for(s in songsFound) - songs.push(Chart.loadChartMeta(s)); + songs.push(Chart.loadChartMeta(s, "normal", source == MODS)); return false; } return true;