@@ -118,10 +118,31 @@ class ChartEditorImportExportHandler
118
118
state .songMetadata = newSongMetadata ;
119
119
state .songChartData = newSongChartData ;
120
120
121
- if (! state .songMetadata .exists (state .selectedVariation ))
121
+ var variationMetadata : Null <SongMetadata > = state .songMetadata .get (state .selectedVariation );
122
+ if (variationMetadata == null )
122
123
{
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
+ }
124
144
}
145
+
125
146
// Use the first available difficulty as a fallback if the currently selected one cannot be found.
126
147
if (state .availableDifficulties .indexOf (state .selectedDifficulty ) < 0 ) state .selectedDifficulty = state .availableDifficulties [0 ];
127
148
0 commit comments