Skip to content

Commit 4fce2c9

Browse files
committed
Prevent Importing non osu!mania beatmaps
1 parent 5868cb1 commit 4fce2c9

File tree

3 files changed

+34
-54
lines changed

3 files changed

+34
-54
lines changed

source/funkin/data/song/importer/OsuManiaData.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef OsuManiaData =
99
var General:
1010
{
1111
var PreviewTime:Int;
12+
var Mode:Int; // Should only be 3 if you are sure this is a mania beatmap
1213
};
1314
var Editor:
1415
{

source/funkin/ui/debug/charting/dialogs/ChartEditorWelcomeDialog.hx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class ChartEditorWelcomeDialog extends ChartEditorBaseDialog
3333
this.splashCreateFromSongBasicOnly.onClick = _ -> onClickLinkCreateBasicOnly();
3434
this.splashCreateFromSongErectOnly.onClick = _ -> onClickLinkCreateErectOnly();
3535
this.splashCreateFromSongBasicErect.onClick = _ -> onClickLinkCreateBasicErect();
36-
this.splashImportChartLegacy.onClick = _ -> onClickLinkImportChartLegacy();
37-
this.splashImportChartOsuMania.onClick = _ -> onClickLinkImportOsuMania();
38-
this.splashImportChartStepMania.onClick = _ -> onClickLinkImportStepMania();
36+
this.splashImportChartLegacy.onClick = _ -> onClickLinkImport("legacy");
37+
this.splashImportChartOsuMania.onClick = _ -> onClickLinkImport("osumania");
38+
this.splashImportChartStepMania.onClick = _ -> onClickLinkImport('stepmania');
3939

4040
// Add items to the Recent Charts list
4141
#if sys
@@ -233,42 +233,16 @@ class ChartEditorWelcomeDialog extends ChartEditorBaseDialog
233233
}
234234

235235
/**
236-
* Called when the user clicks the "Import Chart: FNF Legacy" link in the dialog.
236+
* Called when the user clicks on any "Import Chart" link in the dialog.
237237
* Reassign this function to change the behavior.
238238
*/
239-
public function onClickLinkImportChartLegacy():Void
239+
public function onClickLinkImport(format:String):Void
240240
{
241241
// Hide the welcome dialog
242242
this.hideDialog(DialogButton.CANCEL);
243243

244-
// Open the "Import Chart" dialog
245-
chartEditorState.openImportChartWizard('legacy', false);
246-
}
247-
248-
/**
249-
* Called when the user clicks the "Import Chart: Osu! Mania" link in the dialog.
250-
* Reassign this function to change the behavior.
251-
*/
252-
public function onClickLinkImportOsuMania():Void
253-
{
254-
// Hide the welcome dialog
255-
this.hideDialog(DialogButton.CANCEL);
256-
257-
// Open the "Import Chart" dialog
258-
chartEditorState.openImportChartWizard('osumania', false);
259-
}
260-
261-
/**
262-
* Called when the user clicks the "Import Chart: StepMania" link in the dialog.
263-
* Reassign this function to change the behavior.
264-
*/
265-
public function onClickLinkImportStepMania():Void
266-
{
267-
// Hide the welcome dialog
268-
this.hideDialog(DialogButton.CANCEL);
269-
270-
// Open the "Import Chart" dialog
271-
chartEditorState.openImportChartWizard('stepmania', false);
244+
// Open the "Import Chart" dialog for specified format
245+
chartEditorState.openImportChartWizard(format, false);
272246
}
273247
}
274248
#end

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

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,25 +1065,11 @@ class ChartEditorDialogHandler
10651065
{
10661066
case 'legacy': 'FNF Legacy';
10671067
case 'stepmania': 'StepMania';
1068-
case 'osumania': 'Osu!Mania';
1068+
case 'osumania': 'osu!Mania';
10691069
default: 'Unknown';
10701070
}
10711071

1072-
var fileFilter = switch (format)
1073-
{
1074-
case 'legacy':
1075-
[
1076-
{label: 'JSON Data File (.json)', extension: 'json'}];
1077-
case 'stepmania':
1078-
[
1079-
{label: 'StepMania File (.sm)', extension: 'sm'}];
1080-
case 'osumania':
1081-
[
1082-
{label: 'OSU! Beatmap File (.osu)', extension: 'osu'}];
1083-
default: null;
1084-
}
1085-
1086-
var fileExt = switch (format)
1072+
var fileExt:String = switch (format)
10871073
{
10881074
case 'osumania':
10891075
"osu";
@@ -1092,6 +1078,18 @@ class ChartEditorDialogHandler
10921078
default: "json";
10931079
}
10941080

1081+
var fileFilterLabel:String = switch (fileExt)
1082+
{
1083+
case 'json':
1084+
'JSON Data File';
1085+
case 'sm':
1086+
'StepMania File';
1087+
case 'osu':
1088+
'osu! Beatmap File';
1089+
default: "Unknown File Type";
1090+
};
1091+
fileFilterLabel += ' (.$fileExt)';
1092+
10951093
dialog.title = 'Import Chart - ${prettyFormat}';
10961094

10971095
var buttonCancel:Null<Button> = dialog.findComponent('dialogCancel', Button);
@@ -1166,8 +1164,6 @@ class ChartEditorDialogHandler
11661164
return;
11671165
}
11681166

1169-
trace('Parsed StepMania data for ' + stepmaniaData.Metadata.Title);
1170-
11711167
songMetadata = StepManiaImporter.migrateChartMetadata(stepmaniaData);
11721168
songChartData = StepManiaImporter.migrateChartData(stepmaniaData);
11731169

@@ -1178,7 +1174,14 @@ class ChartEditorDialogHandler
11781174

11791175
if (osuManiaData == null)
11801176
{
1181-
state.error('Failure', 'Failed to parse Osu!Mania beatmap file (${path.file}.${path.ext})');
1177+
state.error('Failure', 'Failed to parse osu!Mania beatmap file (${path.file}.${path.ext})');
1178+
return;
1179+
}
1180+
else if (osuManiaData.General.Mode != 3)
1181+
{
1182+
var modes = ["osu!", "osu!taiko", "osu!catch"];
1183+
state.error('Failure',
1184+
'Not a osu!mania beatmap!\nGiven beatmap seems to be a ${modes[osuManiaData.General.Mode]} beatmap (${path.file}.${path.ext})');
11821185
return;
11831186
}
11841187

@@ -1199,9 +1202,11 @@ class ChartEditorDialogHandler
11991202
state.success('Success', '$loadedText (${path.file}.${path.ext})');
12001203
};
12011204

1205+
// TODO / BUG: File filtering not working on mac finder dialog, so we don't use it for now
1206+
var fileTypes = #if !mac [
1207+
{label: fileFilterLabel, extension: fileExt}] #else [] #end;
12021208
importBox.onClick = function(_) {
1203-
// TODO / BUG: File filtering not working on mac finder dialog, so we don't use it for now
1204-
Dialogs.openBinaryFile('Import Chart - ${prettyFormat}', #if !mac fileFilter ?? [] #else [] #end, function(selectedFile:SelectedFileInfo) {
1209+
Dialogs.openBinaryFile('Import Chart - ${prettyFormat}', fileTypes, function(selectedFile:SelectedFileInfo) {
12051210
if (selectedFile != null && selectedFile.bytes != null)
12061211
{
12071212
@:nullSafety(Off)

0 commit comments

Comments
 (0)