-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from andy840119/andy840119/import-namespace
Create import manager
- Loading branch information
Showing
25 changed files
with
264 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
osu.Game.Rulesets.Karaoke/Edit/Import/ImportLyricDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Overlays; | ||
using osu.Game.Overlays.Dialog; | ||
using System; | ||
using System.IO; | ||
using osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Import | ||
{ | ||
public class ImportLyricDialog : PopupDialog | ||
{ | ||
[Resolved] | ||
private ImportManager importManager { get; set; } | ||
|
||
[Resolved] | ||
private DialogOverlay dialogOverlay { get; set; } | ||
|
||
public ImportLyricDialog(FileInfo info, Action<bool> resetAction = null) | ||
{ | ||
BodyText = "Import lyric file will clean-up all exist lyric."; | ||
|
||
Icon = FontAwesome.Regular.TrashAlt; | ||
HeaderText = @"Confirm import lyric file?"; | ||
Buttons = new PopupDialogButton[] | ||
{ | ||
new PopupDialogOkButton | ||
{ | ||
Text = @"Yes. Go for it.", | ||
Action = () => | ||
{ | ||
var success = processImport(info); | ||
resetAction?.Invoke(success); | ||
} | ||
}, | ||
new PopupDialogCancelButton | ||
{ | ||
Text = @"No! Abort mission!", | ||
}, | ||
}; | ||
} | ||
|
||
private bool processImport(FileInfo info) | ||
{ | ||
try | ||
{ | ||
importManager.ImportLrcFile(info); | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.CheckCircle, | ||
HeaderText = @"Import success", | ||
BodyText = "Lyrics has been imported." | ||
}); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
switch (ex) | ||
{ | ||
case FileNotFoundException fileNotFoundException: | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.QuestionCircle, | ||
HeaderText = @"File not found", | ||
BodyText = fileNotFoundException.Message, | ||
}); | ||
break; | ||
|
||
case FileLoadException loadException: | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.QuestionCircle, | ||
HeaderText = @"File not found", | ||
BodyText = loadException.Message, | ||
}); | ||
break; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; | ||
using osu.Game.Screens.Edit; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Import | ||
{ | ||
public class ImportManager : Component | ||
{ | ||
public static string[] LyricFotmatExtensions { get; } = { ".lrc", ".kar" }; | ||
public static string[] NicokaraSkinFotmatExtensions { get; } = { ".nkmproj" }; | ||
|
||
private const string backup_lrc_name = "backup.lrc"; | ||
|
||
[Resolved] | ||
private EditorBeatmap editorBeatmap { get; set; } | ||
|
||
[Resolved] | ||
private IBindable<WorkingBeatmap> beatmap { get; set; } | ||
|
||
public void ImportLrcFile(FileInfo info) | ||
{ | ||
if (!info.Exists) | ||
throw new FileNotFoundException("Lyric file does not found!"); | ||
|
||
var isFormatMatch = LyricFotmatExtensions.Contains(info.Extension); | ||
if (!isFormatMatch) | ||
throw new FileLoadException("Only .lrc or .kar karaoke file is supported now"); | ||
|
||
var set = beatmap.Value.BeatmapSetInfo; | ||
var oldFile = set.Files?.FirstOrDefault(f => f.Filename == backup_lrc_name); | ||
|
||
using (var stream = info.OpenRead()) | ||
{ | ||
// todo : make a backup if has new lyric file. | ||
/* | ||
if (oldFile != null) | ||
beatmaps.ReplaceFile(set, oldFile, stream, backup_lrc_name); | ||
else | ||
beatmaps.AddFile(set, stream, backup_lrc_name); | ||
*/ | ||
|
||
// Import and replace all the file. | ||
using (var reader = new IO.LineBufferedReader(stream)) | ||
{ | ||
var decoder = new LrcDecoder(); | ||
var lrcBeatmap = decoder.Decode(reader); | ||
|
||
// todo : remove all notes and lyric | ||
// or just clear all beatmap because not really sure is singer should be removed also? | ||
|
||
// then re-add the lyric. | ||
} | ||
} | ||
} | ||
|
||
public void ImportNicokaraSkinFile(FileInfo info) | ||
{ | ||
if (!info.Exists) | ||
throw new FileNotFoundException("Nicokara file does not found!"); | ||
|
||
var isFormatMatch = NicokaraSkinFotmatExtensions.Contains(info.Extension); | ||
if (isFormatMatch) | ||
throw new FileLoadException("Nicokara's skin extension should be .nkmproj"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.