From 239c95f793bffee538a19424c6ad7c7166452352 Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 12 Feb 2025 04:50:15 -0300 Subject: [PATCH 01/25] replace Song.songName with songId --- source/funkin/data/Song.hx | 78 ++++++++++++------------- source/funkin/states/FreeplayState.hx | 25 ++++---- source/funkin/states/SongSelectState.hx | 4 +- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 0683da36..c798e9a4 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -85,18 +85,18 @@ typedef SongMetadata = @:structInit class Song { - public var songName:String = ''; - public var folder:String = ''; + public final songId:String; + public final folder:String = ''; public var difficulties:Array = []; + public var charts(get, null):Array; - function get_charts() - return (charts == null) ? charts = Song.getCharts(this) : charts; + function get_charts() return charts ?? (charts = Song.getCharts(this)); - public function new(songName:String, ?folder:String = '', ?difficulties:Array) + public function new(songId:String, ?folder:String, ?difficulties:Array) { - this.songName = songName; - this.folder = folder != null ? folder : ''; - this.difficulties = difficulties != null ? difficulties : []; + this.songId = songId; + this.folder = folder ?? ''; + this.difficulties = difficulties ?? []; } public function play(?difficultyName:String = ''){ @@ -108,7 +108,7 @@ class Song } public function toString() - return '$folder:$songName'; + return '$folder:$songId'; //// @@ -182,11 +182,11 @@ class Song { Paths.currentModDirectory = song.folder; - #if USING_MOONCHART - final songName = Paths.formatToSongPath(song.songName); + final songId:String = Paths.formatToSongPath(song.songId); + final charts:Map = []; + #if USING_MOONCHART var folder:String = ''; - var charts:Map = []; function processFileName(unprocessedName:String) { var fileName:String = unprocessedName.toLowerCase(); @@ -200,12 +200,12 @@ class Song switch (fileFormat) { case FNF_LEGACY_PSYCH | FNF_LEGACY: - if (fileName == '$songName.json') { + if (fileName == '$songId.json') { charts.set("normal", true); return; } - else if (fileName.startsWith('$songName-')) { - final extension_dot = songName.length + 1; + else if (fileName.startsWith('$songId-')) { + final extension_dot = songId.length + 1; charts.set(fileName.substr(extension_dot, fileName.length - extension_dot - 5), true); return; } @@ -221,11 +221,11 @@ class Song }else{ var woExtension:String = Path.withoutExtension(filePath); - if (woExtension == songName){ + if (woExtension == songId){ charts.set("normal", true); return; } - if (woExtension.startsWith('$songName-')){ + if (woExtension.startsWith('$songId-')){ var split = woExtension.split("-"); split.shift(); var diff = split.join("-"); @@ -241,7 +241,7 @@ class Song } if (song.folder == "") { - folder = Paths.getPreloadPath('songs/$songName/'); + folder = Paths.getPreloadPath('songs/$songId/'); Paths.iterateDirectory(folder, processFileName); } #if MODS_ALLOWED @@ -250,7 +250,7 @@ class Song var spoon:Array = []; var crumb:Array = []; - folder = Paths.mods('${song.folder}/songs/$songName/'); + folder = Paths.mods('${song.folder}/songs/$songId/'); Paths.iterateDirectory(folder, (fileName)->{ if (isAMoonchartRecognizedFile(fileName)){ spoon.push(folder+fileName); @@ -260,8 +260,8 @@ class Song var ALL_FILES_DETECTED_FORMAT = findFormat(spoon); if (ALL_FILES_DETECTED_FORMAT == FNF_VSLICE) { - var chartsFilePath:String = folder + songName + '-chart.json'; - var metadataPath:String = folder + songName + '-metadata.json'; + var chartsFilePath:String = folder + songId + '-chart.json'; + var metadataPath:String = folder + songId + '-metadata.json'; var chart = new moonchart.formats.fnf.FNFVSlice().fromFile(chartsFilePath, metadataPath); for (diff in chart.diffs) charts.set(diff, true); @@ -271,7 +271,7 @@ class Song //// #if PE_MOD_COMPATIBILITY - folder = Paths.mods('${song.folder}/data/$songName/'); + folder = Paths.mods('${song.folder}/data/$songId/'); Paths.iterateDirectory(folder, processFileName); #end } @@ -297,21 +297,19 @@ class Song return chartNames; #else - final songName = Paths.formatToSongPath(song.songName); - final charts = new haxe.ds.StringMap(); function processFileName(unprocessedName:String) { var fileName:String = unprocessedName.toLowerCase(); - if (fileName == '$songName.json'){ + if (fileName == '$songId.json'){ charts.set("normal", true); return; } - else if (!fileName.startsWith('$songName-') || !fileName.endsWith('.json')){ + else if (!fileName.startsWith('$songId-') || !fileName.endsWith('.json')){ return; } - final extension_dot = songName.length + 1; + final extension_dot = songId.length + 1; charts.set(fileName.substr(extension_dot, fileName.length - extension_dot - 5), true); } @@ -319,17 +317,17 @@ class Song if (song.folder == "") { #if PE_MOD_COMPATIBILITY - Paths.iterateDirectory(Paths.getPreloadPath('data/$songName/'), processFileName); + Paths.iterateDirectory(Paths.getPreloadPath('data/$songId/'), processFileName); #end - Paths.iterateDirectory(Paths.getPreloadPath('songs/$songName/'), processFileName); + Paths.iterateDirectory(Paths.getPreloadPath('songs/$songId/'), processFileName); } #if MODS_ALLOWED else { #if PE_MOD_COMPATIBILITY - Paths.iterateDirectory(Paths.mods('${song.folder}/data/$songName/'), processFileName); + Paths.iterateDirectory(Paths.mods('${song.folder}/data/$songId/'), processFileName); #end - Paths.iterateDirectory(Paths.mods('${song.folder}/songs/$songName/'), processFileName); + Paths.iterateDirectory(Paths.mods('${song.folder}/songs/$songId/'), processFileName); } #end @@ -592,7 +590,7 @@ class Song static public function loadSong(toPlay:Song, ?difficulty:String, ?difficultyIdx:Int = 1) { Paths.currentModDirectory = toPlay.folder; - var songLowercase:String = Paths.formatToSongPath(toPlay.songName); + var songId:String = toPlay.songId; var diffSuffix:String; var rawDifficulty:String = difficulty; @@ -620,7 +618,7 @@ class Song inline function findVSlice():Bool { // less strict v-slice format detection - var sowy = 'songs/$songLowercase/$songLowercase'; + var sowy = 'songs/$songId/$songId'; var basePath:String; if (toPlay.folder == "") @@ -640,7 +638,7 @@ class Song var converted = new SupportedFormat().fromFormat(chart, rawDifficulty); var chart:JsonSong = cast converted.data.song; chart.path = chartsFilePath; - chart.song = songLowercase; + chart.song = songId; chart.tracks = null; SONG = onLoadJson(chart); found = true; @@ -657,12 +655,12 @@ class Song // Or dont since this current method lets you do a dumb thing AKA have 2 diff chart formats in a folder LOL var files:Array = []; - if (diffSuffix != '') files.push(songLowercase + diffSuffix); - files.push(songLowercase); + if (diffSuffix != '') files.push(songId + diffSuffix); + files.push(songId); for (ext in moonchartExtensions) { for (input in files) { - var path:String = Paths.formatToSongPath(songLowercase) + '/' + Paths.formatToSongPath(input) + '.' + ext; + var path:String = Paths.formatToSongPath(songId) + '/' + Paths.formatToSongPath(input) + '.' + ext; var filePath:String = Paths.getPath("songs/" + path); var fileFormat:Format = findFormat([filePath]); @@ -678,7 +676,7 @@ class Song SONG = switch(fileFormat) { case FNF_LEGACY_PSYCH | FNF_LEGACY | "FNF_TROLL": - Song.loadFromJson(songLowercase + diffSuffix, songLowercase); + Song.loadFromJson(songId + diffSuffix, songId); default: trace('Converting from format $fileFormat!'); @@ -693,7 +691,7 @@ class Song var converted = new SupportedFormat().fromFormat(chart, rawDifficulty); var chart:JsonSong = cast converted.data.song; chart.path = filePath; - chart.song = songLowercase; + chart.song = songId; onLoadJson(chart); } @@ -712,7 +710,7 @@ class Song return; } #else - var SONG:SwagSong = Song.loadFromJson(songLowercase + diffSuffix, songLowercase); + var SONG:SwagSong = Song.loadFromJson(songId + diffSuffix, songId); #end PlayState.SONG = SONG; diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index 5cde8c83..419e8345 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -17,7 +17,7 @@ class FreeplayState extends MusicBeatState public static var comingFromPlayState:Bool = false; var menu = new AlphabetMenu(); - var songMeta:Array = []; + var songData:Array = []; var bgGrp = new FlxTypedGroup(); var bg:FlxSprite; @@ -55,17 +55,20 @@ class FreeplayState extends MusicBeatState continue; for (songName in week.songs){ - var metadata:Song = {songName: songName, folder: week.directory, difficulties: week.difficulties != null ? week.difficulties : []}; + var songId = Paths.formatToSongPath(songName); + var song:Song = { + songId: songId, + folder: week.directory, + difficulties: week.difficulties ?? [] + }; - /* - if (metadata.charts.length == 0){ - trace('${week.directory}: $songName doesn\'t have any available charts!'); + if (Main.showDebugTraces && song.charts.length == 0) { + trace('"$song" doesn\'t have any available charts!'); continue; } - */ - menu.addTextOption(songName.replace("-", " ").capitalize()).ID = songMeta.length; - songMeta.push(metadata); + menu.addTextOption(songName.replace("-", " ").capitalize()).ID = songData.length; + songData.push(song); } } @@ -74,7 +77,7 @@ class FreeplayState extends MusicBeatState add(menu); menu.controls = controls; - menu.callbacks.onSelect = (selectedIdx, _) -> onSelectSong(songMeta[selectedIdx]); + menu.callbacks.onSelect = (selectedIdx, _) -> onSelectSong(songData[selectedIdx]); menu.callbacks.onAccept = (_, _) -> onAccept(); //// @@ -194,7 +197,7 @@ class FreeplayState extends MusicBeatState MusicBeatState.switchState(new funkin.states.MainMenuState()); }else if (controls.RESET){ - var songName:String = selectedSongData.songName; + var songName:String = selectedSongData.songId; var _dStrId:String = 'difficultyName_$curDiffStr'; var diffName:String = Paths.getString(_dStrId, curDiffStr); @@ -233,7 +236,7 @@ class FreeplayState extends MusicBeatState function refreshScore() { var data = selectedSongData; - var record = Highscore.getRecord(data.songName, curDiffStr); + var record = Highscore.getRecord(data.songId, curDiffStr); targetRating = Highscore.getRatingRecord(record) * 100; if(ClientPrefs.showWifeScore) diff --git a/source/funkin/states/SongSelectState.hx b/source/funkin/states/SongSelectState.hx index f126fafa..01a0940c 100644 --- a/source/funkin/states/SongSelectState.hx +++ b/source/funkin/states/SongSelectState.hx @@ -118,7 +118,7 @@ class SongSelectState extends MusicBeatState hPadding + (Math.floor(id/verticalLimit) * width), vPadding + (ySpace*(id%verticalLimit)), width, - songMeta[id].songName, + songMeta[id].songId, textSize ); text.wordWrap = false; @@ -241,7 +241,7 @@ class SongChartSelec extends MusicBeatState override function create() { - add(new FlxText(0, 5, FlxG.width, songMeta.songName).setFormat(null, 20, 0xFFFFFFFF, CENTER)); + add(new FlxText(0, 5, FlxG.width, songMeta.songId).setFormat(null, 20, 0xFFFFFFFF, CENTER)); for (id in 0...alts.length){ var alt = alts[id]; From 0124298269ed22e514f79a1726afdeb3653e496b Mon Sep 17 00:00:00 2001 From: riconuts Date: Tue, 18 Feb 2025 22:03:41 -0300 Subject: [PATCH 02/25] Update Song.hx --- source/funkin/data/Song.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index c798e9a4..7059a739 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -606,7 +606,7 @@ class Song difficulty = 'normal'; diffSuffix = ''; }else{ - difficulty = difficulty.trim().toLowerCase(); + difficulty = Paths.formatToSongPath(difficulty); diffSuffix = '-$difficulty'; } @@ -660,7 +660,7 @@ class Song for (ext in moonchartExtensions) { for (input in files) { - var path:String = Paths.formatToSongPath(songId) + '/' + Paths.formatToSongPath(input) + '.' + ext; + var path:String = '$songId/${Paths.formatToSongPath(input)}.$ext'; var filePath:String = Paths.getPath("songs/" + path); var fileFormat:Format = findFormat([filePath]); From 3f2ae048fe8af908844ee5130a3e7fd377400432 Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 19 Feb 2025 00:53:39 -0300 Subject: [PATCH 03/25] getDifficultyFileSuffix func --- source/funkin/data/Song.hx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 7059a739..3d284c0e 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -335,6 +335,12 @@ class Song #end } + // TODO: GEt rid of this, just save the charts as "-normal" grrrr + public inline static function getDifficultyFileSuffix(diff:String) { + diff = Paths.formatToSongPath(diff); + return (diff=="" || diff=="normal") ? "" : '-$diff'; + } + public static function loadFromJson(jsonInput:String, folder:String, ?isSongJson:Bool = true):Null { var path:String = Paths.formatToSongPath(folder) + '/' + Paths.formatToSongPath(jsonInput) + '.json'; @@ -591,8 +597,6 @@ class Song Paths.currentModDirectory = toPlay.folder; var songId:String = toPlay.songId; - var diffSuffix:String; - var rawDifficulty:String = difficulty; if (difficulty == null || difficulty == "") { @@ -602,13 +606,7 @@ class Song difficulty = toPlay.charts[0]; } - if (difficulty == "normal") { - difficulty = 'normal'; - diffSuffix = ''; - }else{ - difficulty = Paths.formatToSongPath(difficulty); - diffSuffix = '-$difficulty'; - } + var diffSuffix:String = getDifficultyFileSuffix(difficulty); if (Main.showDebugTraces) trace('loadSong', toPlay, difficulty); From 56e790d571dce01678627c733042b0da379392dc Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 12 Feb 2025 05:20:12 -0300 Subject: [PATCH 04/25] Song.metadata & Song.getSongFile --- source/funkin/data/Song.hx | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 3d284c0e..d8b335f9 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -90,7 +90,8 @@ class Song public var difficulties:Array = []; public var charts(get, null):Array; - function get_charts() return charts ?? (charts = Song.getCharts(this)); + public var metadata(get, null):SongMetadata; + public var songPath(get, null):String; public function new(songId:String, ?folder:String, ?difficulties:Array) { @@ -99,6 +100,9 @@ class Song this.difficulties = difficulties ?? []; } + public function getSongFile(fileName:String) + return '$songPath/$fileName'; + public function play(?difficultyName:String = ''){ var idx = charts.indexOf(difficultyName); if (idx != -1) @@ -110,6 +114,34 @@ class Song public function toString() return '$folder:$songId'; + // + function get_charts() + return charts ?? (charts = Song.getCharts(this)); + + function get_metadata() { + if (metadata != null) return metadata; + + var path:String = getSongFile('metadata.json'); + var json:SongMetadata = Paths.getJson(path); + + if (json == null) { + json = {}; + if (Main.showDebugTraces) + trace('$this: No metadata found. Maybe add some? $path'); + } + + return metadata = json; + } + + function get_songPath() { + return if (songPath != null) + songPath; + else if (folder == '') + songPath = Paths.getPreloadPath('songs/$songId'); + else + songPath = Paths.mods('$folder/songs/$songId'); + } + //// public static function getMetadataInfo(metadata:SongMetadata):Array { @@ -616,16 +648,8 @@ class Song inline function findVSlice():Bool { // less strict v-slice format detection - var sowy = 'songs/$songId/$songId'; - var basePath:String; - - if (toPlay.folder == "") - basePath = Paths.getPreloadPath(sowy); - else - basePath = Paths.mods(toPlay.folder + '/' + sowy); - - var chartsFilePath = '$basePath-chart.json'; - var metadataPath = '$basePath-metadata.json'; + var chartsFilePath = toPlay.getSongFile('$songId-chart.json'); + var metadataPath = toPlay.getSongFile('$songId-metadata.json'); var found:Bool = false; if (Paths.exists(chartsFilePath) && Paths.exists(metadataPath)) { From 28cb6b5fade184c63585793a8b4d19cda589458a Mon Sep 17 00:00:00 2001 From: riconuts Date: Tue, 18 Feb 2025 21:54:54 -0300 Subject: [PATCH 05/25] Paths.getFolderPath --- source/funkin/Paths.hx | 3 +++ source/funkin/data/Song.hx | 27 +++++---------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/source/funkin/Paths.hx b/source/funkin/Paths.hx index 092c7417..9f1c98d6 100644 --- a/source/funkin/Paths.hx +++ b/source/funkin/Paths.hx @@ -571,6 +571,9 @@ class Paths return null; } + public static inline function getFolderPath(folder:String = ""):String + return (folder == "") ? getPreloadPath() : mods(folder); + //// public static var currentModDirectory(default, set):String = ''; static function set_currentModDirectory(v:String){ diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index d8b335f9..e89ff93d 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -134,12 +134,7 @@ class Song } function get_songPath() { - return if (songPath != null) - songPath; - else if (folder == '') - songPath = Paths.getPreloadPath('songs/$songId'); - else - songPath = Paths.mods('$folder/songs/$songId'); + return songPath ?? (songPath = Paths.getFolderPath(this.folder) + '/songs/$songId'); } //// @@ -345,23 +340,11 @@ class Song charts.set(fileName.substr(extension_dot, fileName.length - extension_dot - 5), true); } - - if (song.folder == "") - { - #if PE_MOD_COMPATIBILITY - Paths.iterateDirectory(Paths.getPreloadPath('data/$songId/'), processFileName); - #end - Paths.iterateDirectory(Paths.getPreloadPath('songs/$songId/'), processFileName); - } - #if MODS_ALLOWED - else - { - #if PE_MOD_COMPATIBILITY - Paths.iterateDirectory(Paths.mods('${song.folder}/data/$songId/'), processFileName); - #end - Paths.iterateDirectory(Paths.mods('${song.folder}/songs/$songId/'), processFileName); - } + var contentPath = Paths.getFolderPath(song.folder); + #if PE_MOD_COMPATIBILITY + Paths.iterateDirectory('$contentPath/data/$songId/', processFileName); #end + Paths.iterateDirectory('$contentPath/songs/$songId/', processFileName); return [for (name in charts.keys()) name]; #end From c17aae9a42dd15f7c041b85d8fb3c6cfee9619da Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 12 Feb 2025 05:50:33 -0300 Subject: [PATCH 06/25] metadata songName stuff --- source/funkin/data/FNFTroll.hx | 2 +- source/funkin/data/Song.hx | 4 +++- source/funkin/states/FreeplayState.hx | 5 ++--- source/funkin/states/PlayState.hx | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/funkin/data/FNFTroll.hx b/source/funkin/data/FNFTroll.hx index 09e46cba..59fe1fa2 100644 --- a/source/funkin/data/FNFTroll.hx +++ b/source/funkin/data/FNFTroll.hx @@ -212,7 +212,7 @@ class FNFTroll extends FNFLegacyBasic { } data.song.metadata ??= {}; - //data.song.metadata.songName = chart.meta.title; + data.song.metadata.songName = chart.meta.title; data.song.metadata.artist = chart.meta.extraData.get("SONG_ARTIST"); data.song.metadata.charter = chart.meta.extraData.get("SONG_CHARTER"); diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index e89ff93d..3375fe1e 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -15,6 +15,7 @@ import funkin.data.Section.SwagSection; import haxe.io.Path; import haxe.Json; +using funkin.CoolerStringTools; using StringTools; typedef SwagSong = { @@ -75,7 +76,7 @@ typedef SongTracks = { typedef SongMetadata = { - // ?songName:String, + ?songName:String, ?artist:String, ?charter:String, ?modcharter:String, @@ -129,6 +130,7 @@ class Song if (Main.showDebugTraces) trace('$this: No metadata found. Maybe add some? $path'); } + json.songName ??= songId.replace("-", " ").capitalize(); return metadata = json; } diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index 419e8345..e3db93d5 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -55,9 +55,8 @@ class FreeplayState extends MusicBeatState continue; for (songName in week.songs){ - var songId = Paths.formatToSongPath(songName); var song:Song = { - songId: songId, + songId: Paths.formatToSongPath(songName), folder: week.directory, difficulties: week.difficulties ?? [] }; @@ -67,7 +66,7 @@ class FreeplayState extends MusicBeatState continue; } - menu.addTextOption(songName.replace("-", " ").capitalize()).ID = songData.length; + menu.addTextOption(song.metadata.songName).ID = songData.length; songData.push(song); } } diff --git a/source/funkin/states/PlayState.hx b/source/funkin/states/PlayState.hx index 193121b3..f351e6a0 100644 --- a/source/funkin/states/PlayState.hx +++ b/source/funkin/states/PlayState.hx @@ -1035,7 +1035,7 @@ class PlayState extends MusicBeatState var stringId:String = 'difficultyName_$difficultyName'; displayedDifficulty = Paths.getString(stringId, difficultyName.replace("-"," ").capitalize()); - displayedSong = SONG.song.replace("-"," ").capitalize(); + displayedSong = metadata?.songName ?? SONG.song.replace("-"," ").capitalize(); #if DISCORD_ALLOWED // Discord RPC texts From 885a8ec43f7ac5a353f8e2506c1421691ccfae0e Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 19 Feb 2025 18:02:46 -0300 Subject: [PATCH 07/25] Update Song.hx --- source/funkin/data/Song.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 3375fe1e..16482df0 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -25,7 +25,6 @@ typedef SwagSong = { //// var song:String; - // var displayName:String; var bpm:Float; var tracks:SongTracks; // currently used From d2dc7935bcd464b7f6c1b8884ff934925f06aceb Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 13 Feb 2025 00:25:09 -0300 Subject: [PATCH 08/25] Update milf metadata.json --- default_content/base-game/songs/milf/metadata.json | 1 + 1 file changed, 1 insertion(+) diff --git a/default_content/base-game/songs/milf/metadata.json b/default_content/base-game/songs/milf/metadata.json index f4df046d..30739e9e 100644 --- a/default_content/base-game/songs/milf/metadata.json +++ b/default_content/base-game/songs/milf/metadata.json @@ -1,3 +1,4 @@ { + "songName": "M.I.L.F", "artist": "Kawai Sprite" } \ No newline at end of file From c08001d64639ad6e9cbf87caf7172d960cd69684 Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 19 Feb 2025 20:09:42 -0300 Subject: [PATCH 09/25] Update Paths.hx --- source/funkin/Paths.hx | 33 +++++++++++++++++---------------- source/funkin/data/Cache.hx | 6 +++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/funkin/Paths.hx b/source/funkin/Paths.hx index 9f1c98d6..e07f0699 100644 --- a/source/funkin/Paths.hx +++ b/source/funkin/Paths.hx @@ -252,7 +252,7 @@ class Paths inline static public function sound(key:String, ?library:String):Null { - return returnSound('sounds', key, library); + return returnFolderSound('sounds', key, library); } inline static public function soundRandom(key:String, min:Int, max:Int, ?library:String) @@ -262,12 +262,12 @@ class Paths inline static public function music(key:String, ?library:String):Null { - return returnSound('music', key, library); + return returnFolderSound('music', key, library); } inline static public function track(song:String, track:String):Null { - return returnSound('songs', '${formatToSongPath(song)}/$track'); + return returnFolderSound('songs', '${formatToSongPath(song)}/$track'); } inline static public function voices(song:String):Null @@ -528,29 +528,30 @@ class Paths return getPath('$path/$key.$SOUND_EXT'); } - public static function returnSound(path:String, key:String, ?library:String) - { - var gottenPath:String = soundPath(path, key, library); - - if (currentTrackedSounds.exists(gottenPath)) { - if (!localTrackedAssets.contains(gottenPath)) - localTrackedAssets.push(gottenPath); + inline public static function returnFolderSound(path:String, key:String, ?library:String) + return returnSound(soundPath(path, key, library), library); + + public static function returnSound(path:String, ?library:String) + { + if (currentTrackedSounds.exists(path)) { + if (!localTrackedAssets.contains(path)) + localTrackedAssets.push(path); - return currentTrackedSounds.get(gottenPath); + return currentTrackedSounds.get(path); } - var sound = getSound(gottenPath); + var sound = getSound(path); if (sound != null) { - currentTrackedSounds.set(gottenPath, sound); + currentTrackedSounds.set(path, sound); - if (!localTrackedAssets.contains(gottenPath)) - localTrackedAssets.push(gottenPath); + if (!localTrackedAssets.contains(path)) + localTrackedAssets.push(path); return sound; } if (Main.showDebugTraces) - trace('sound $path, $key => $gottenPath returned null'); + trace('sound $path returned null'); return null; } diff --git a/source/funkin/data/Cache.hx b/source/funkin/data/Cache.hx index 4211fb5f..e96b3e02 100644 --- a/source/funkin/data/Cache.hx +++ b/source/funkin/data/Cache.hx @@ -198,11 +198,11 @@ class Cache default: Paths.image(toLoad.path, toLoad.library); case SOUND: - Paths.returnSound("sounds", toLoad.path, toLoad.library); + Paths.returnFolderSound("sounds", toLoad.path, toLoad.library); case MUSIC: - Paths.returnSound("music", toLoad.path, toLoad.library); + Paths.returnFolderSound("music", toLoad.path, toLoad.library); case SONG: - Paths.returnSound("songs", toLoad.path, toLoad.library); + Paths.returnFolderSound("songs", toLoad.path, toLoad.library); } #if traceLoading From 1c092e2f7219b61397fc77cbd87ea7a9b3397859 Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 12 Feb 2025 18:51:21 -0300 Subject: [PATCH 10/25] Use Song object metadata in PlayState still making it fallback to the chart data, not sure if I want PlayState to be able to work without a reference to a Song object or not --- source/funkin/data/Song.hx | 5 ++++- source/funkin/states/PlayState.hx | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 16482df0..2d798fbf 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -722,7 +722,10 @@ class Song PlayState.SONG = SONG; PlayState.difficulty = difficultyIdx; PlayState.difficultyName = difficulty; - PlayState.isStoryMode = false; + PlayState.isStoryMode = false; + + PlayState.songPlaylist = [toPlay]; + PlayState.songPlaylistIdx = 0; } static public function switchToPlayState() diff --git a/source/funkin/states/PlayState.hx b/source/funkin/states/PlayState.hx index f351e6a0..1e73a552 100644 --- a/source/funkin/states/PlayState.hx +++ b/source/funkin/states/PlayState.hx @@ -115,6 +115,9 @@ class PlayState extends MusicBeatState public static var songPlaylist:Array = []; public static var songPlaylistIdx = 0; + private static var song(get, never):Song; + private static function get_song() return songPlaylist[songPlaylistIdx]; + public static var difficulty:Int = 1; // for psych mod shit public static var difficultyName:String = 'normal'; // should NOT be set to "" when playing normal diff!!!!! @@ -637,10 +640,10 @@ class PlayState extends MusicBeatState Conductor.changeBPM(SONG.bpm); Conductor.songPosition = Conductor.crochet * -5; - songName = Paths.formatToSongPath(SONG.song); - songHighscore = Highscore.getScore(SONG.song, difficultyName); + songName = (song?.songId) ?? Paths.formatToSongPath(SONG.song); + songHighscore = Highscore.getScore(songName, difficultyName); - metadata = SONG.metadata ?? Paths.json('songs/$songName/metadata.json'); + metadata = SONG.metadata ?? (song?.metadata); if (showDebugTraces && metadata == null) trace('No metadata for $songName. Maybe add some?'); @@ -1707,7 +1710,13 @@ class PlayState extends MusicBeatState //// for (trackName in songTrackNames) { - var newTrack = new FlxSound().loadEmbedded(Paths.track(PlayState.SONG.song, trackName)); + var sndAsset = { + if (song != null) + Paths.returnSound(song.getSongFile(trackName) + ".ogg"); + else + Paths.track(PlayState.SONG.song, trackName); + } + var newTrack = new FlxSound().loadEmbedded(sndAsset); //newTrack.volume = 0.0; newTrack.pitch = playbackRate; newTrack.filter = sndFilter; From d74a1ffb4ff9fa8b618505d225bd045730b9b0a6 Mon Sep 17 00:00:00 2001 From: riconuts Date: Tue, 18 Feb 2025 20:56:48 -0300 Subject: [PATCH 11/25] Update Song.hx --- source/funkin/data/Song.hx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 2d798fbf..5b749000 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -103,12 +103,12 @@ class Song public function getSongFile(fileName:String) return '$songPath/$fileName'; - public function play(?difficultyName:String = ''){ - var idx = charts.indexOf(difficultyName); + public function play(?chartName:String = ''){ + var idx = charts.indexOf(chartName); if (idx != -1) - return Song.playSong(this, difficultyName, idx); + return Song.playSong(this, chartName, idx); - trace('$this: Attempt to play null difficulty: ' + difficultyName); + trace('$this: Attempt to play null chart: ' + chartName); } public function toString() From 3a44c1f8e0751f1ad1e3047f5a9fdb012606a453 Mon Sep 17 00:00:00 2001 From: riconuts Date: Tue, 18 Feb 2025 21:01:21 -0300 Subject: [PATCH 12/25] remove difficultyIdx arg --- source/funkin/data/Song.hx | 16 +++++++++------- source/funkin/states/FreeplayState.hx | 4 ++-- source/funkin/states/SongSelectState.hx | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 5b749000..85f6a9df 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -104,11 +104,13 @@ class Song return '$songPath/$fileName'; public function play(?chartName:String = ''){ - var idx = charts.indexOf(chartName); - if (idx != -1) - return Song.playSong(this, chartName, idx); + if (charts.contains(chartName)) { + Song.playSong(this, chartName); + return true; + } trace('$this: Attempt to play null chart: ' + chartName); + return false; } public function toString() @@ -609,7 +611,7 @@ class Song return resultArray; } - static public function loadSong(toPlay:Song, ?difficulty:String, ?difficultyIdx:Int = 1) { + static public function loadSong(toPlay:Song, ?difficulty:String) { Paths.currentModDirectory = toPlay.folder; var songId:String = toPlay.songId; @@ -720,7 +722,7 @@ class Song #end PlayState.SONG = SONG; - PlayState.difficulty = difficultyIdx; + PlayState.difficulty = toPlay.charts.indexOf(difficulty); PlayState.difficultyName = difficulty; PlayState.isStoryMode = false; @@ -736,9 +738,9 @@ class Song LoadingState.loadAndSwitchState(new PlayState()); } - static public function playSong(song:Song, ?difficulty:String, ?difficultyIdx:Int = 1) + static public function playSong(song:Song, ?difficulty:String) { - loadSong(song, difficulty, difficultyIdx); + loadSong(song, difficulty); switchToPlayState(); } } \ No newline at end of file diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index e3db93d5..8ef2469c 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -131,7 +131,7 @@ class FreeplayState extends MusicBeatState proceed = songLoaded == selectedSong && PlayState.SONG != null; if (!proceed) { - Song.loadSong(selectedSongData, curDiffStr, curDiffIdx); + Song.loadSong(selectedSongData, curDiffStr); proceed = PlayState.SONG != null; } } @@ -156,7 +156,7 @@ class FreeplayState extends MusicBeatState // load song json and play inst if (songLoaded != selectedSong){ songLoaded = selectedSong; - Song.loadSong(selectedSongData, curDiffStr, curDiffIdx); + Song.loadSong(selectedSongData, curDiffStr); if (PlayState.SONG != null){ var instAsset = Paths.track(PlayState.SONG.song, PlayState.SONG.tracks.inst[0]); diff --git a/source/funkin/states/SongSelectState.hx b/source/funkin/states/SongSelectState.hx index 01a0940c..54c9a846 100644 --- a/source/funkin/states/SongSelectState.hx +++ b/source/funkin/states/SongSelectState.hx @@ -194,7 +194,7 @@ class SongSelectState extends MusicBeatState if (charts.length > 1) MusicBeatState.switchState(new SongChartSelec(songMeta[curSel], charts)); else if (charts.length > 0) { - Song.loadSong(songMeta[curSel], charts[0], 0); + Song.loadSong(songMeta[curSel], charts[0]); if (FlxG.keys.pressed.SHIFT) LoadingState.loadAndSwitchState(new funkin.states.editors.ChartingState()); else @@ -268,7 +268,7 @@ class SongChartSelec extends MusicBeatState MusicBeatState.switchState(new FreeplayState()); else if (controls.ACCEPT){ var daDiff = alts[curSel]; - Song.loadSong(songMeta, (daDiff=="normal") ? null : daDiff, curSel); + Song.loadSong(songMeta, (daDiff=="normal") ? null : daDiff); if (FlxG.keys.pressed.SHIFT) LoadingState.loadAndSwitchState(new funkin.states.editors.ChartingState()); else From ee0a91c02ed9914c533a62a1a4a77d35b0f0e67d Mon Sep 17 00:00:00 2001 From: riconuts Date: Tue, 18 Feb 2025 19:23:43 -0300 Subject: [PATCH 13/25] remove Song.difficulties it's only used because of psych week shit should maybe add difficulties to the metadata so menus can use them idk i want freeplay songs to be able to behave independently from their weeks/levels --- source/funkin/data/Song.hx | 16 +--------------- source/funkin/states/FreeplayState.hx | 3 +-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 85f6a9df..3a055316 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -87,17 +87,15 @@ class Song { public final songId:String; public final folder:String = ''; - public var difficulties:Array = []; public var charts(get, null):Array; public var metadata(get, null):SongMetadata; public var songPath(get, null):String; - public function new(songId:String, ?folder:String, ?difficulties:Array) + public function new(songId:String, ?folder:String) { this.songId = songId; this.folder = folder ?? ''; - this.difficulties = difficulties ?? []; } public function getSongFile(fileName:String) @@ -308,20 +306,8 @@ class Song #end var allCharts:Array = [for (name in charts.keys()) name]; - var allChartsLower:Array = [for (name in charts.keys()) name.toLowerCase()]; var chartNames:Array = []; - if (song.difficulties.length > 0){ - for(diff in song.difficulties){ - if (allChartsLower.contains(diff)){ - var index = allChartsLower.indexOf(diff); - chartNames.push(diff); - allCharts.splice(index, 1); - allChartsLower.remove(diff); - } - } - } - for (name in allCharts) chartNames.push(name); diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index 8ef2469c..b583c91d 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -57,8 +57,7 @@ class FreeplayState extends MusicBeatState for (songName in week.songs){ var song:Song = { songId: Paths.formatToSongPath(songName), - folder: week.directory, - difficulties: week.difficulties ?? [] + folder: week.directory }; if (Main.showDebugTraces && song.charts.length == 0) { From 566cfc53fcf8bfdb9dca8130a7f73505c09e92ad Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 19 Feb 2025 03:52:14 -0300 Subject: [PATCH 14/25] dont format song path hmmm might not go with this --- source/funkin/data/Song.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 3a055316..981223ae 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -210,7 +210,7 @@ class Song { Paths.currentModDirectory = song.folder; - final songId:String = Paths.formatToSongPath(song.songId); + final songId:String = song.songId; final charts:Map = []; #if USING_MOONCHART @@ -654,7 +654,7 @@ class Song for (ext in moonchartExtensions) { for (input in files) { - var path:String = '$songId/${Paths.formatToSongPath(input)}.$ext'; + var path:String = '$songId/$input.$ext'; var filePath:String = Paths.getPath("songs/" + path); var fileFormat:Format = findFormat([filePath]); From 60334f26a68b3c671aca51e9f7a28f5378069a1a Mon Sep 17 00:00:00 2001 From: riconuts Date: Wed, 19 Feb 2025 18:16:34 -0300 Subject: [PATCH 15/25] getMetadata(chart) function song variations shouldn't have their metadata embedded into the chart file from now on --- source/funkin/data/Song.hx | 63 +++++++++++++++++++-------- source/funkin/states/FreeplayState.hx | 2 +- source/funkin/states/PlayState.hx | 2 +- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 981223ae..ff8aedd9 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -88,9 +88,9 @@ class Song public final songId:String; public final folder:String = ''; - public var charts(get, null):Array; - public var metadata(get, null):SongMetadata; public var songPath(get, null):String; + public var charts(get, null):Array; + private var metadataCache = new Map(); public function new(songId:String, ?folder:String) { @@ -114,26 +114,53 @@ class Song public function toString() return '$folder:$songId'; - // - function get_charts() - return charts ?? (charts = Song.getCharts(this)); - - function get_metadata() { - if (metadata != null) return metadata; - - var path:String = getSongFile('metadata.json'); - var json:SongMetadata = Paths.getJson(path); - - if (json == null) { - json = {}; + /** get uncached metadata **/ + private function _getMetadata(chart:String):Null { + var suffix = getDifficultyFileSuffix(chart); + var fileName:String = 'metadata' + suffix + '.json'; + var path:String = getSongFile(fileName); + return Paths.getJson(path); + } + + /** + * Returns metadata for the requested chart. + * If it doesn't exist, metadata for the 'normal' chart is returned instead + * + * @param chartId The song chart for which you want to request metadata + **/ + public function getMetadata(chartId:String = "normal"):SongMetadata { + if (chartId=="") + chartId="normal"; + + if (metadataCache.exists(chartId)) { + //trace('$this: Returning cached metadata for $chartId'); + return metadataCache.get(chartId); + } + + var meta = _getMetadata(chartId); + if (meta != null) { + //trace('$this: Found metadata for $chartId'); + } + else if (chartId != "normal") { if (Main.showDebugTraces) - trace('$this: No metadata found. Maybe add some? $path'); + trace('$this: Metadata not found for [$chartId]. Using default'); + return getMetadata("normal"); } - json.songName ??= songId.replace("-", " ").capitalize(); - - return metadata = json; + else { + if (Main.showDebugTraces) + trace('$this: No metadata found! Maybe add some?'); + meta = {}; + } + meta.songName ??= songId.replace("-", " ").capitalize(); + + metadataCache.set(chartId, meta); + return meta; } + // + function get_charts() + return charts ?? (charts = Song.getCharts(this)); + function get_songPath() { return songPath ?? (songPath = Paths.getFolderPath(this.folder) + '/songs/$songId'); } diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index b583c91d..1fd77e54 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -65,7 +65,7 @@ class FreeplayState extends MusicBeatState continue; } - menu.addTextOption(song.metadata.songName).ID = songData.length; + menu.addTextOption(song.getMetadata().songName).ID = songData.length; songData.push(song); } } diff --git a/source/funkin/states/PlayState.hx b/source/funkin/states/PlayState.hx index 1e73a552..50246e46 100644 --- a/source/funkin/states/PlayState.hx +++ b/source/funkin/states/PlayState.hx @@ -643,7 +643,7 @@ class PlayState extends MusicBeatState songName = (song?.songId) ?? Paths.formatToSongPath(SONG.song); songHighscore = Highscore.getScore(songName, difficultyName); - metadata = SONG.metadata ?? (song?.metadata); + metadata = SONG.metadata ?? (song?.getMetadata(difficultyName)); if (showDebugTraces && metadata == null) trace('No metadata for $songName. Maybe add some?'); From db87a00591aabb4c8092e707c29d3492da004f8e Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 03:32:13 -0300 Subject: [PATCH 16/25] no more song structInit fuck you --- source/funkin/data/Song.hx | 1 - source/funkin/states/FreeplayState.hx | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index ff8aedd9..57aee0e0 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -82,7 +82,6 @@ typedef SongMetadata = ?extraInfo:Array, } -@:structInit class Song { public final songId:String; diff --git a/source/funkin/states/FreeplayState.hx b/source/funkin/states/FreeplayState.hx index 1fd77e54..9551e909 100644 --- a/source/funkin/states/FreeplayState.hx +++ b/source/funkin/states/FreeplayState.hx @@ -55,10 +55,10 @@ class FreeplayState extends MusicBeatState continue; for (songName in week.songs){ - var song:Song = { - songId: Paths.formatToSongPath(songName), - folder: week.directory - }; + var song = new Song( + Paths.formatToSongPath(songName), + week.directory + ); if (Main.showDebugTraces && song.charts.length == 0) { trace('"$song" doesn\'t have any available charts!'); From a8b2050afefd197272a22b1b764f10e1774168f8 Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 03:34:08 -0300 Subject: [PATCH 17/25] set default songPath on creation actually --- source/funkin/data/Song.hx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 57aee0e0..427ab5fe 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -87,7 +87,7 @@ class Song public final songId:String; public final folder:String = ''; - public var songPath(get, null):String; + public var songPath(get, default):String; public var charts(get, null):Array; private var metadataCache = new Map(); @@ -95,6 +95,7 @@ class Song { this.songId = songId; this.folder = folder ?? ''; + this.songPath = Paths.getFolderPath(this.folder) + '/songs/$songId'; } public function getSongFile(fileName:String) @@ -160,9 +161,8 @@ class Song function get_charts() return charts ?? (charts = Song.getCharts(this)); - function get_songPath() { - return songPath ?? (songPath = Paths.getFolderPath(this.folder) + '/songs/$songId'); - } + function get_songPath() + return songPath; //// From fbc3694b8d680803646c83780832572a1a2bd2b3 Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 03:38:31 -0300 Subject: [PATCH 18/25] getSongFile() checks data folder if it doesnt exist in the song folder that fucking legacy fnf that i hate --- source/funkin/data/Song.hx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 427ab5fe..a0d70db3 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -91,15 +91,41 @@ class Song public var charts(get, null):Array; private var metadataCache = new Map(); + #if PE_MOD_COMPATIBILITY + private final defaultSongPath:String; + private final dataPath:String; + + inline function isUsingDefaultSongPath():Bool { + @:bypassAccessor + return this.songPath == null; + } + #end + public function new(songId:String, ?folder:String) { this.songId = songId; this.folder = folder ?? ''; + #if !PE_MOD_COMPATIBILITY this.songPath = Paths.getFolderPath(this.folder) + '/songs/$songId'; + #else + var contentFolder = Paths.getFolderPath(this.folder); + this.defaultSongPath = '$contentFolder/songs/$songId'; + this.dataPath = '$contentFolder/data/$songId'; + #end } - public function getSongFile(fileName:String) - return '$songPath/$fileName'; + public function getSongFile(fileName:String) { + var path = '$songPath/$fileName'; + + #if PE_MOD_COMPATIBILITY + if (isUsingDefaultSongPath() && !Paths.exists(path)) { + var pp = '$dataPath/$fileName'; + if (Paths.exists(pp)) path = pp; + } + #end + + return path; + } public function play(?chartName:String = ''){ if (charts.contains(chartName)) { @@ -162,7 +188,7 @@ class Song return charts ?? (charts = Song.getCharts(this)); function get_songPath() - return songPath; + return songPath #if PE_MOD_COMPATIBILITY ?? defaultSongPath #end; //// From 5cfe4c1d35b6b3a6cf5b4257b6a241468df2f52e Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 21:58:40 -0300 Subject: [PATCH 19/25] Update Song.hx --- source/funkin/data/Song.hx | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index a0d70db3..ae611d5c 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -706,17 +706,9 @@ class Song for (ext in moonchartExtensions) { for (input in files) { - var path:String = '$songId/$input.$ext'; - var filePath:String = Paths.getPath("songs/" + path); + var filePath:String = toPlay.getSongFile('$input.$ext'); var fileFormat:Format = findFormat([filePath]); - #if PE_MOD_COMPATIBILITY - if (fileFormat == null){ - filePath = Paths.getPath("data/" + path); - fileFormat = findFormat([filePath]); - } - #end - if (fileFormat == null) continue; var formatInfo:Null = FormatDetector.getFormatData(fileFormat); From bf6f1be1d7e9a122b78a073bd672c435becb0233 Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 04:07:00 -0300 Subject: [PATCH 20/25] parseSongJson function separate from loadFromJson --- source/funkin/data/Song.hx | 47 +++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index ae611d5c..de4e73e5 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -397,22 +397,11 @@ class Song return (diff=="" || diff=="normal") ? "" : '-$diff'; } - public static function loadFromJson(jsonInput:String, folder:String, ?isSongJson:Bool = true):Null - { - var path:String = Paths.formatToSongPath(folder) + '/' + Paths.formatToSongPath(jsonInput) + '.json'; - var fullPath = Paths.getPath('songs/$path', false); - - #if PE_MOD_COMPATIBILITY - if (!Paths.exists(fullPath)) - fullPath = Paths.getPath('data/$path', false); - #end + private static function _parseSongJson(filePath:String, isChartJson:Bool = true):SwagSong { + var rawJson:Null = Paths.getContent(filePath); + if (rawJson == null) + throw 'song JSON file NOT FOUND: $filePath'; - var rawJson:Null = Paths.getContent(fullPath); - if (rawJson == null){ - trace('song JSON file not found: $path'); - return null; - } - // LOL GOING THROUGH THE BULLSHIT TO CLEAN IDK WHATS STRANGE rawJson = rawJson.trim(); while (!rawJson.endsWith("}")) @@ -420,7 +409,7 @@ class Song var uncastedJson:Dynamic = Json.parse(rawJson); var songJson:JsonSong; - if (uncastedJson.song is String){ + if (isChartJson && uncastedJson.song is String){ // PSYCH 1.0 FUCKING DUMBSHIT FIX IT RETARD // why did shadowmario make such a useless format change oh my god :sob: @@ -434,13 +423,33 @@ class Song note[2] = note[2] > 0 ? note[2] : 0; } } - }else songJson = cast uncastedJson.song; - songJson.path = fullPath; + songJson.path = filePath; + return isChartJson ? onLoadJson(songJson) : onLoadEvents(songJson); + } + + private static function parseSongJson(filePath:String, isChartJson:Bool = true):Null { + try { + return _parseSongJson(filePath, isChartJson); + }catch(e) { + trace('ERROR parsing song JSON: $filePath', e.message); + return null; + } + } + + public static function loadFromJson(jsonInput:String, folder:String, isChartJson:Bool = true):Null + { + var path:String = Paths.formatToSongPath(folder) + '/' + Paths.formatToSongPath(jsonInput) + '.json'; + var fullPath = Paths.getPath('songs/$path', false); + + #if PE_MOD_COMPATIBILITY + if (!Paths.exists(fullPath)) + fullPath = Paths.getPath('data/$path', false); + #end - return isSongJson ? onLoadJson(songJson) : onLoadEvents(songJson); + return parseSongJson(fullPath); } public static function onLoadEvents(songJson:SwagSong) { From d3bf3bee3e79a26cedf9b7f491c09d3120ceee2a Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 21:58:18 -0300 Subject: [PATCH 21/25] Update Song.hx --- source/funkin/data/Song.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index de4e73e5..b8cbb785 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -661,7 +661,6 @@ class Song static public function loadSong(toPlay:Song, ?difficulty:String) { Paths.currentModDirectory = toPlay.folder; - var songId:String = toPlay.songId; var rawDifficulty:String = difficulty; if (difficulty == null || difficulty == "") { @@ -671,7 +670,7 @@ class Song difficulty = toPlay.charts[0]; } - var diffSuffix:String = getDifficultyFileSuffix(difficulty); + var songId:String = toPlay.songId; if (Main.showDebugTraces) trace('loadSong', toPlay, difficulty); @@ -710,6 +709,7 @@ class Song // Or dont since this current method lets you do a dumb thing AKA have 2 diff chart formats in a folder LOL var files:Array = []; + var diffSuffix:String = getDifficultyFileSuffix(difficulty); if (diffSuffix != '') files.push(songId + diffSuffix); files.push(songId); @@ -719,7 +719,6 @@ class Song var fileFormat:Format = findFormat([filePath]); if (fileFormat == null) continue; - var formatInfo:Null = FormatDetector.getFormatData(fileFormat); SONG = switch(fileFormat) { case FNF_LEGACY_PSYCH | FNF_LEGACY | "FNF_TROLL": @@ -728,6 +727,7 @@ class Song default: trace('Converting from format $fileFormat!'); + var formatInfo:Null = FormatDetector.getFormatData(fileFormat); var chart:moonchart.formats.BasicFormat<{}, {}>; chart = cast Type.createInstance(formatInfo.handler, []); chart = chart.fromFile(filePath); From bab3fbc1d348ff713fc597aac0af2e62f1714086 Mon Sep 17 00:00:00 2001 From: riconuts Date: Thu, 20 Feb 2025 22:06:19 -0300 Subject: [PATCH 22/25] arghhhh what is this rawDifficulty shit for anymore --- source/funkin/data/Song.hx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index b8cbb785..812177fc 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -661,9 +661,10 @@ class Song static public function loadSong(toPlay:Song, ?difficulty:String) { Paths.currentModDirectory = toPlay.folder; - var rawDifficulty:String = difficulty; - - if (difficulty == null || difficulty == "") { + if (difficulty == "") { + difficulty = "normal"; + } + else if (difficulty == null) { if (toPlay.charts.contains("normal")) difficulty = "normal"; else @@ -686,10 +687,10 @@ class Song var found:Bool = false; if (Paths.exists(chartsFilePath) && Paths.exists(metadataPath)) { var chart = new moonchart.formats.fnf.FNFVSlice().fromFile(chartsFilePath, metadataPath); - if (chart.diffs.contains(rawDifficulty)) { + if (chart.diffs.contains(difficulty)) { trace("CONVERTING FROM VSLICE"); - var converted = new SupportedFormat().fromFormat(chart, rawDifficulty); + var converted = new SupportedFormat().fromFormat(chart, difficulty); var chart:JsonSong = cast converted.data.song; chart.path = chartsFilePath; chart.song = songId; @@ -697,7 +698,7 @@ class Song SONG = onLoadJson(chart); found = true; }else{ - trace('VSLICE FILES DO NOT CONTAIN DIFFICULTY: $rawDifficulty'); + trace('VSLICE FILES DO NOT CONTAIN DIFFICULTY: $difficulty'); } } @@ -732,10 +733,10 @@ class Song chart = cast Type.createInstance(formatInfo.handler, []); chart = chart.fromFile(filePath); - if (chart.formatMeta.supportsDiffs && !chart.diffs.contains(rawDifficulty)) + if (chart.formatMeta.supportsDiffs && !chart.diffs.contains(difficulty)) continue; - var converted = new SupportedFormat().fromFormat(chart, rawDifficulty); + var converted = new SupportedFormat().fromFormat(chart, difficulty); var chart:JsonSong = cast converted.data.song; chart.path = filePath; chart.song = songId; From f73fba002ee1700757c1ad9072e64308a95e073d Mon Sep 17 00:00:00 2001 From: riconuts Date: Fri, 21 Feb 2025 00:07:15 -0300 Subject: [PATCH 23/25] Song.getSwagSong the loadSong stuff except it doesn't set any PlayState values --- source/funkin/data/Song.hx | 166 +++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 89 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 812177fc..183b6d8c 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -183,6 +183,81 @@ class Song return meta; } + public function getSwagSong(chartId:String):Null { + if (chartId == '') + chartId = 'normal'; + + #if !USING_MOONCHART + var suffix = getDifficultyFileSuffix(chartId); + var path = getSongFile(songId + suffix); + return parseSongJson(path); + #else + + // less strict v-slice format detection + // cause it won't detect it if you place the audio files in the same folder + var chartsFilePath = getSongFile('$songId-chart.json'); + var metadataPath = getSongFile('$songId-metadata.json'); + + if (Paths.exists(chartsFilePath) && Paths.exists(metadataPath)) { + var chart = new moonchart.formats.fnf.FNFVSlice().fromFile(chartsFilePath, metadataPath); + if (chart.diffs.contains(chartId)) { + trace("CONVERTING FROM VSLICE"); + + var converted = new SupportedFormat().fromFormat(chart, chartId); + var chart:JsonSong = cast converted.data.song; + chart.path = chartsFilePath; + chart.song = songId; + chart.tracks = null; + return onLoadJson(chart); + }else{ + trace('VSLICE FILES DO NOT CONTAIN DIFFICULTY CHART: $chartId'); + } + } + + // TODO: scan through the song folder and look for the first thing that has a supported extension (if json then check if it has diffSuffix cus FNF formats!!) + // Or dont since this current method lets you do a dumb thing AKA have 2 diff chart formats in a folder LOL + + var files:Array = []; + var diffSuffix:String = getDifficultyFileSuffix(chartId); + if (diffSuffix != '') files.push(songId + diffSuffix); + files.push(songId); + + for (ext in moonchartExtensions) { + for (input in files) { + var filePath:String = getSongFile('$input.$ext'); + var fileFormat:Null = findFormat([filePath]); + + switch(fileFormat) { + case null: + continue; + + case FNF_LEGACY_PSYCH | FNF_LEGACY | "FNF_TROLL": + return parseSongJson(filePath); + + default: + trace('Converting from format $fileFormat!'); + + var formatInfo:Null = FormatDetector.getFormatData(fileFormat); + var chart:moonchart.formats.BasicFormat<{}, {}>; + chart = cast Type.createInstance(formatInfo.handler, []); + chart = chart.fromFile(filePath); + + if (chart.formatMeta.supportsDiffs && !chart.diffs.contains(chartId)) + continue; + + var converted = new SupportedFormat().fromFormat(chart, chartId); + var chart:JsonSong = cast converted.data.song; + chart.path = filePath; + chart.song = songId; + return onLoadJson(chart); + } + } + } + + return null; + #end + } + // function get_charts() return charts ?? (charts = Song.getCharts(this)); @@ -670,98 +745,11 @@ class Song else difficulty = toPlay.charts[0]; } - - var songId:String = toPlay.songId; - + if (Main.showDebugTraces) trace('loadSong', toPlay, difficulty); - - #if USING_MOONCHART - var SONG:Null = null; - - inline function findVSlice():Bool { - // less strict v-slice format detection - var chartsFilePath = toPlay.getSongFile('$songId-chart.json'); - var metadataPath = toPlay.getSongFile('$songId-metadata.json'); - - var found:Bool = false; - if (Paths.exists(chartsFilePath) && Paths.exists(metadataPath)) { - var chart = new moonchart.formats.fnf.FNFVSlice().fromFile(chartsFilePath, metadataPath); - if (chart.diffs.contains(difficulty)) { - trace("CONVERTING FROM VSLICE"); - - var converted = new SupportedFormat().fromFormat(chart, difficulty); - var chart:JsonSong = cast converted.data.song; - chart.path = chartsFilePath; - chart.song = songId; - chart.tracks = null; - SONG = onLoadJson(chart); - found = true; - }else{ - trace('VSLICE FILES DO NOT CONTAIN DIFFICULTY: $difficulty'); - } - } - - return found; - } - - if (!findVSlice()) { - // TODO: scan through the song folder and look for the first thing that has a supported extension (if json then check if it has diffSuffix cus FNF formats!!) - // Or dont since this current method lets you do a dumb thing AKA have 2 diff chart formats in a folder LOL - - var files:Array = []; - var diffSuffix:String = getDifficultyFileSuffix(difficulty); - if (diffSuffix != '') files.push(songId + diffSuffix); - files.push(songId); - - for (ext in moonchartExtensions) { - for (input in files) { - var filePath:String = toPlay.getSongFile('$input.$ext'); - var fileFormat:Format = findFormat([filePath]); - - if (fileFormat == null) continue; - - SONG = switch(fileFormat) { - case FNF_LEGACY_PSYCH | FNF_LEGACY | "FNF_TROLL": - Song.loadFromJson(songId + diffSuffix, songId); - - default: - trace('Converting from format $fileFormat!'); - - var formatInfo:Null = FormatDetector.getFormatData(fileFormat); - var chart:moonchart.formats.BasicFormat<{}, {}>; - chart = cast Type.createInstance(formatInfo.handler, []); - chart = chart.fromFile(filePath); - - if (chart.formatMeta.supportsDiffs && !chart.diffs.contains(difficulty)) - continue; - - var converted = new SupportedFormat().fromFormat(chart, difficulty); - var chart:JsonSong = cast converted.data.song; - chart.path = filePath; - chart.song = songId; - onLoadJson(chart); - } - - break; - } - if (SONG != null) - break; - } - } - - if (SONG == null) { - PlayState.SONG = null; - - // Find a better way to show the error to the user - trace("No file format found for the chart!"); - return; - } - #else - var SONG:SwagSong = Song.loadFromJson(songId + diffSuffix, songId); - #end - PlayState.SONG = SONG; + PlayState.SONG = toPlay.getSwagSong(difficulty); PlayState.difficulty = toPlay.charts.indexOf(difficulty); PlayState.difficultyName = difficulty; PlayState.isStoryMode = false; From dbf49ff3e810a819f218f84b4270b9b8afd5fc0a Mon Sep 17 00:00:00 2001 From: riconuts Date: Fri, 21 Feb 2025 00:11:33 -0300 Subject: [PATCH 24/25] Update SongSelectState.hx --- source/funkin/states/SongSelectState.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/funkin/states/SongSelectState.hx b/source/funkin/states/SongSelectState.hx index 54c9a846..c6ba708b 100644 --- a/source/funkin/states/SongSelectState.hx +++ b/source/funkin/states/SongSelectState.hx @@ -267,8 +267,8 @@ class SongChartSelec extends MusicBeatState if (controls.BACK) MusicBeatState.switchState(new FreeplayState()); else if (controls.ACCEPT){ - var daDiff = alts[curSel]; - Song.loadSong(songMeta, (daDiff=="normal") ? null : daDiff); + Song.loadSong(songMeta, alts[curSel]); + if (FlxG.keys.pressed.SHIFT) LoadingState.loadAndSwitchState(new funkin.states.editors.ChartingState()); else From 9a518c256d037a81cb2db5906ed0f26bf5b338ff Mon Sep 17 00:00:00 2001 From: riconuts Date: Fri, 21 Feb 2025 00:21:57 -0300 Subject: [PATCH 25/25] Update Song.hx --- source/funkin/data/Song.hx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/source/funkin/data/Song.hx b/source/funkin/data/Song.hx index 183b6d8c..b1a2ce02 100644 --- a/source/funkin/data/Song.hx +++ b/source/funkin/data/Song.hx @@ -128,13 +128,7 @@ class Song } public function play(?chartName:String = ''){ - if (charts.contains(chartName)) { - Song.playSong(this, chartName); - return true; - } - - trace('$this: Attempt to play null chart: ' + chartName); - return false; + Song.playSong(this, chartName); } public function toString()