-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, rename some naming from .lrc to .kar
- Loading branch information
1 parent
f9823b1
commit 2e116b1
Showing
9 changed files
with
53 additions
and
60 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.IO; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; | ||
using osu.Game.Rulesets.Karaoke.Integration.Formats; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Screens.Edit; | ||
using FileInfo = System.IO.FileInfo; | ||
|
@@ -19,15 +20,15 @@ public partial class ImportLyricManager : Component | |
{ | ||
public static string[] LyricFormatExtensions { get; } = { ".lrc", ".kar", ".txt" }; | ||
|
||
private const string backup_lrc_name = "backup.lrc"; | ||
private const string backup_file_name = "backup"; | ||
|
||
[Resolved] | ||
private EditorBeatmap editorBeatmap { get; set; } = null!; | ||
|
||
[Resolved] | ||
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!; | ||
|
||
public void ImportLrcFile(FileInfo info) | ||
public void ImportFile(FileInfo info) | ||
{ | ||
if (!info.Exists) | ||
throw new FileNotFoundException("Lyric file does not found!"); | ||
|
@@ -37,32 +38,43 @@ public void ImportLrcFile(FileInfo info) | |
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); | ||
var oldFile = set.Files.FirstOrDefault(f => f.Filename == backup_file_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); | ||
beatmaps.ReplaceFile(set, oldFile, stream, backup_file_name); | ||
else | ||
beatmaps.AddFile(set, stream, backup_lrc_name); | ||
beatmaps.AddFile(set, stream, backup_file_name); | ||
*/ | ||
|
||
// Import and replace all the file. | ||
using var reader = new LineBufferedReader(stream); | ||
|
||
var decoder = new LrcDecoder(); | ||
var lrcBeatmap = decoder.Decode(reader); | ||
string content = reader.ReadToEnd(); | ||
var lyrics = decodeLyrics(content, info.Extension); | ||
|
||
// remove all hit objects (note and lyric) from beatmap | ||
editorBeatmap.Clear(); | ||
|
||
// then re-add the lyric. | ||
var lyrics = lrcBeatmap.HitObjects.OfType<Lyric>(); | ||
editorBeatmap.AddRange(lyrics); | ||
} | ||
|
||
private static Lyric[] decodeLyrics(string content, string extension) | ||
{ | ||
IDecoder<Lyric[]> decoder = extension switch | ||
{ | ||
".lrc" => new LrcDecoder(), | ||
".kar" => new KarDecoder(), | ||
".txt" => new LyricTextDecoder(), | ||
_ => throw new NotSupportedException("Unsupported lyric file format"), | ||
}; | ||
|
||
return decoder.Decode(content); | ||
} | ||
|
||
public void AbortImport() | ||
{ | ||
editorBeatmap.Clear(); | ||
|