/// <summary> /// 新增歌曲資訊至 BeatmapList /// </summary> /// <param name="packageName">歌曲包名稱</param> /// <param name="osuFilePath">.osu檔路徑</param> public static int InsertBeatmap(string packageName, string osuFilePath) { var beatmap = new BeatmapSimple(osuFilePath); if (beatmap.General.Mode != 3 || beatmap.Difficulty.CircleSize != 4) { return(0); } using (var songList = new SqliteManager(Application.streamingAssetsPath, "GameData.db") { Table = "BeatmapList" }) { using (var dr = songList.Select($"BeatmapID = {beatmap.Metadata.BeatmapID}", "BeatmapID")) { if (!dr.HasRows) { // MP3 轉 WAV if (Path.GetExtension(beatmap.General.AudioFilename) == ".mp3") { var src = Path.Combine(Application.streamingAssetsPath, "Songs", packageName, beatmap.General.AudioFilename); var dst = Path.ChangeExtension(src, ".wav"); beatmap.General.AudioFilename = Path.ChangeExtension(beatmap.General.AudioFilename, ".wav"); // 如果該素材尚未轉檔,轉換之 if (!File.Exists(dst)) { NAudioPlayer.ConvertMp3ToWav(src); // 刪除原始檔 File.Delete(src); } } // 新增至資料庫 songList.Insert( beatmap.Metadata.BeatmapID, beatmap.Metadata.BeatmapSetID, beatmap.Metadata.Title, beatmap.Metadata.TitleUnicode, beatmap.Metadata.Artist, beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Creator, beatmap.Metadata.Version, packageName, beatmap.Events.Filename, beatmap.General.AudioFilename, Path.GetFileName(osuFilePath) ); // 新增至圖譜清單 BeatmapTileList.BeatmapTileDatas.Add(new BeatmapTileData( beatmap.Metadata.BeatmapID, beatmap.Metadata.BeatmapSetID, beatmap.Metadata.Title, beatmap.Metadata.TitleUnicode, beatmap.Metadata.Artist, beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Creator, beatmap.Metadata.Version, packageName, beatmap.Events.Filename, beatmap.General.AudioFilename, Path.GetFileName(osuFilePath) )); return(1); } } return(0); } }