diff --git a/source/funkin/states/editors/ChartEditorState.hx b/source/funkin/states/editors/ChartEditorState.hx index 22c4770a..885a1fec 100644 --- a/source/funkin/states/editors/ChartEditorState.hx +++ b/source/funkin/states/editors/ChartEditorState.hx @@ -5,6 +5,7 @@ import funkin.data.Chart; import haxe.ds.IntMap; import haxe.Json; import haxe.io.Bytes; +import haxe.io.Path; import lime.media.AudioBuffer; @@ -969,10 +970,8 @@ class ChartEditorState extends haxe.ui.backend.flixel.UIState function prepareEventsUI():Void { #if MODS_ALLOWED - var eventPushedMap:Map = new Map(); var directories:Array = []; - #if MODS_ALLOWED directories.push(Paths.mods('data/events/')); directories.push(Paths.mods(Mods.currentModDirectory + '/data/events/')); for (mod in Mods.globalMods) @@ -982,49 +981,38 @@ class ChartEditorState extends haxe.ui.backend.flixel.UIState directories.push(Paths.mods(Mods.currentModDirectory + '/events/')); for (mod in Mods.globalMods) directories.push(Paths.mods(mod + '/events/')); - #end - var eventexts = ['.txt', '.hx', '.hxs', '.hscript']; - var removeShit = [4, 3, 4, 8]; + var eventexts = FunkinScript.H_EXTS.concat(["txt"]); + + var pushedEvents:Array = []; + for (event in eventStuff) pushedEvents.push(event[0]); for (i in 0...directories.length) { var directory:String = directories[i]; - if (!FunkinAssets.exists(directory)) continue; - - for (file in FunkinAssets.readDirectory(directory)) + if (FunkinAssets.exists(directory)) { - var path = haxe.io.Path.join([directory, file]); - for (ext in 0...eventexts.length) + var files = FunkinAssets.readDirectory(directory); + files.sort((a, b) -> return Path.extension(a) == "txt" ? 1 : 0); + + for (file in files) { - if (FunkinAssets.isDirectory(path) || file == 'readme.txt' || !file.endsWith(eventexts[ext])) continue; - - var fileToCheck:String = file.substr(0, file.length - removeShit[ext]); - - if (eventPushedMap.exists(fileToCheck)) break; - - eventPushedMap.set(fileToCheck, true); - - for (x in ['.hx', '.hxs', '.hscript']) + var path = Path.join([directory, file]); + if (!FunkinAssets.isDirectory(path) && file != 'readme.txt' && eventexts.contains(Path.extension(file))) { - if (file.endsWith(x)) + var fileToCheck:String = Path.withoutExtension(file); + if (!pushedEvents.contains(fileToCheck)) { - eventStuff.push([fileToCheck, 'scripted description']); - break; - } - else - { - eventStuff.push([fileToCheck, File.getContent(path)]); - break; + if (FunkinScript.H_EXTS.contains(Path.extension(file))) + eventStuff.push([fileToCheck, 'scripted description']); + else + eventStuff.push([fileToCheck, File.getContent(path)]); } + pushedEvents.push(fileToCheck); } - - break; } } } - eventPushedMap.clear(); - eventPushedMap = null; #end ui.songDialog.eventDropdown.populateList([for (ev in eventStuff) {id: ev[0], text: (ev[0].length == 0 ? 'None' : ev[0])}]); diff --git a/source/funkin/states/editors/OLDChartEditorState.hx b/source/funkin/states/editors/OLDChartEditorState.hx index 5b6140b2..59165a70 100644 --- a/source/funkin/states/editors/OLDChartEditorState.hx +++ b/source/funkin/states/editors/OLDChartEditorState.hx @@ -5,6 +5,7 @@ import funkin.data.Chart; import haxe.ds.IntMap; import haxe.Json; import haxe.io.Bytes; +import haxe.io.Path; import lime.media.AudioBuffer; @@ -650,7 +651,7 @@ class OLDChartEditorState extends MusicBeatState { for (file in FunkinAssets.readDirectory(directory)) { - var path = haxe.io.Path.join([directory, file]); + var path = Path.join([directory, file]); var isXml = false; if (!FunkinAssets.isDirectory(path) && (file.endsWith('.json') || (file.endsWith('.xml') && (isXml = true)))) { @@ -1302,7 +1303,7 @@ class OLDChartEditorState extends MusicBeatState { for (file in FunkinAssets.readDirectory(directory)) { - var path = haxe.io.Path.join([directory, file]); + var path = Path.join([directory, file]); if (!FunkinAssets.isDirectory(path)) { for (ext in FunkinScript.H_EXTS) @@ -1368,10 +1369,8 @@ class OLDChartEditorState extends MusicBeatState tab_group_event.name = 'Events'; #if MODS_ALLOWED - var eventPushedMap:Map = new Map(); var directories:Array = []; - #if MODS_ALLOWED directories.push(Paths.mods('data/events/')); directories.push(Paths.mods(Mods.currentModDirectory + '/data/events/')); for (mod in Mods.globalMods) @@ -1381,49 +1380,38 @@ class OLDChartEditorState extends MusicBeatState directories.push(Paths.mods(Mods.currentModDirectory + '/events/')); for (mod in Mods.globalMods) directories.push(Paths.mods(mod + '/events/')); - #end - var eventexts = ['.txt', '.hx', '.hxs', '.hscript']; - var removeShit = [4, 3, 4, 8]; + var eventexts = FunkinScript.H_EXTS.concat(["txt"]); + + var pushedEvents:Array = []; + for (event in eventStuff) pushedEvents.push(event[0]); for (i in 0...directories.length) { var directory:String = directories[i]; if (FunkinAssets.exists(directory)) { - for (file in FunkinAssets.readDirectory(directory)) + var files = FunkinAssets.readDirectory(directory); + files.sort((a, b) -> return Path.extension(a) == "txt" ? 1 : 0); + + for (file in files) { - var path = haxe.io.Path.join([directory, file]); - for (ext in 0...eventexts.length) + var path = Path.join([directory, file]); + if (!FunkinAssets.isDirectory(path) && file != 'readme.txt' && eventexts.contains(Path.extension(file))) { - if (!FunkinAssets.isDirectory(path) && file != 'readme.txt' && file.endsWith(eventexts[ext])) + var fileToCheck:String = Path.withoutExtension(file); + if (!pushedEvents.contains(fileToCheck)) { - var fileToCheck:String = file.substr(0, file.length - removeShit[ext]); - if (!eventPushedMap.exists(fileToCheck)) - { - eventPushedMap.set(fileToCheck, true); - for (x in ['.hx', '.hxs', '.hscript']) - { - if (file.endsWith(x)) - { - eventStuff.push([fileToCheck, 'scripted description']); - break; - } - else - { - eventStuff.push([fileToCheck, File.getContent(path)]); - break; - } - } - } - break; + if (FunkinScript.H_EXTS.contains(Path.extension(file))) + eventStuff.push([fileToCheck, 'scripted description']); + else + eventStuff.push([fileToCheck, File.getContent(path)]); } + pushedEvents.push(fileToCheck); } } } } - eventPushedMap.clear(); - eventPushedMap = null; #end descText = new FlxText(20, 200, 0, eventStuff[0][0]);