From 9b8fc872617cf55b9d41a0fb1a436e69995f1d53 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 17 Oct 2023 00:07:36 -0400 Subject: [PATCH] song diff menu sort --- source/funkin/play/song/Song.hx | 31 ++++++++++++++++++++++++++++++- source/funkin/ui/story/Level.hx | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/source/funkin/play/song/Song.hx b/source/funkin/play/song/Song.hx index 96eb434d2..33363e1ff 100644 --- a/source/funkin/play/song/Song.hx +++ b/source/funkin/play/song/Song.hx @@ -245,12 +245,41 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry = difficulties.keys().array().filter(function(diffId:String):Bool { if (variationId == null) return true; var difficulty:Null = difficulties.get(diffId); if (difficulty == null) return false; return difficulty.variation == variationId; }); + + // sort the difficulties, since they may be out of order in the chart JSON + // maybe be careful of lowercase/uppercase? + // also used in Level.listDifficulties()!! + var diffMap:Map = new Map(); + for (difficulty in diffFiltered) + { + var num:Int = 0; + switch (difficulty) + { + case 'easy': + num = 0; + case 'normal': + num = 1; + case 'hard': + num = 2; + case 'erect': + num = 3; + case 'nightmare': + num = 4; + } + diffMap.set(difficulty, num); + } + + diffFiltered.sort(function(a:String, b:String) { + return (diffMap.get(a) ?? 0) - (diffMap.get(b) ?? 0); + }); + + return diffFiltered; } public function hasDifficulty(diffId:String, ?variationId:String):Bool diff --git a/source/funkin/ui/story/Level.hx b/source/funkin/ui/story/Level.hx index 271039f00..c976cbfce 100644 --- a/source/funkin/ui/story/Level.hx +++ b/source/funkin/ui/story/Level.hx @@ -156,6 +156,7 @@ class Level implements IRegistryEntry } // sort the difficulties, since they may be out of order in the chart JSON + // also copy/pasted to Song.listDifficulties()! var diffMap:Map = new Map(); for (difficulty in difficulties) {