Skip to content

Commit 441fed5

Browse files
committed
Variation fallback & add missing chartdata difficulties to metadata
1 parent a2a1b0b commit 441fed5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

source/funkin/ui/debug/charting/handlers/ChartEditorImportExportHandler.hx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,31 @@ class ChartEditorImportExportHandler
118118
state.songMetadata = newSongMetadata;
119119
state.songChartData = newSongChartData;
120120

121-
if (!state.songMetadata.exists(state.selectedVariation))
121+
var variationMetadata:Null<SongMetadata> = state.songMetadata.get(state.selectedVariation);
122+
if (variationMetadata == null)
122123
{
123-
state.selectedVariation = Constants.DEFAULT_VARIATION;
124+
// Use the default variation, or the first available variation if that doesn't exist for some reason.
125+
if (state.availableDifficulties.indexOf(Constants.DEFAULT_VARIATION) < 0) state.selectedVariation = state.availableVariations[0];
126+
else state.selectedVariation = Constants.DEFAULT_VARIATION;
127+
128+
variationMetadata = state.songMetadata.get(state.selectedVariation);
129+
}
130+
131+
for (variation in state.availableVariations)
132+
{
133+
var metadata:Null<SongMetadata> = state.songMetadata.get(variation);
134+
if(metadata == null) return;
135+
var chartdata:Null<SongChartData> = state.songChartData.get(variation);
136+
if(chartdata == null) return;
137+
// Add the chartdata difficulties to the metadata difficulties if they don't exist so that the editor properly loads them.
138+
var keys:Array<String> = [for (x in chartdata.scrollSpeed.keys()) x];
139+
keys = keys.concat([for (x in chartdata.notes.keys()) x]);
140+
for (key in keys)
141+
{
142+
metadata.playData.difficulties.pushUnique(key);
143+
}
124144
}
145+
125146
// Use the first available difficulty as a fallback if the currently selected one cannot be found.
126147
if (state.availableDifficulties.indexOf(state.selectedDifficulty) < 0) state.selectedDifficulty = state.availableDifficulties[0];
127148

0 commit comments

Comments
 (0)