/// <summary> /// Adds any new files that are currently not cached. /// Used if the user adds a file to the folder. /// </summary> /// <param name="files"></param> private static void AddNonCachedFiles(List <string> files) { var maps = FetchAll(); foreach (var file in files) { if (maps.Any(x => BackslashToForward(file) == BackslashToForward($"{GlobalConfig.Load().SongDirectory}/{x.Directory}/{x.Path}"))) { continue; } // Found map that isn't cached in the database yet. try { var map = Map.FromChart(ChartFile.Parse(file, false), file); map.CalculateDifficulties(); InsertMap(map, file); } catch (Exception e) { Logger.Log(e); } } }
public void InstantiatePrefab(string display, ChartFile chart, System.IO.DirectoryInfo chartDirectory) { GameObject songButton = Instantiate(Resources.Load("Prefabs/SongListButton")) as GameObject; songButton.transform.SetParent(ListContent.transform, false); songButton.GetComponentInChildren <Text>().text = display; songButton.GetComponent <Button>().onClick.AddListener(() => LoadMap(chart, chartDirectory)); }
/// <summary> /// Responsible for converting a ChartFile object, to a Map object /// a Map object is one that is stored in the db. /// </summary> /// <param name="chart"></param> /// <param name="path"></param> /// <returns></returns> public static Map FromChart(ChartFile chart, string path, bool skipPathSetting = false) { var map = new Map { Artist = chart.Artist, Title = chart.Title, HighestRank = Grade.None, AudioPath = chart.SoundFile, AudioPreviewTime = chart.PreviewStart, BackgroundPath = "", Description = "", MapId = chart.ID, MapSetId = 0, Creator = chart.Creator, DifficultyName = chart.Difficulty, Source = chart.Source, Tags = chart.Tags, SongLength = 0, NoteCount = 0, SliderCount = 0, SpinnerCount = 0 }; if (!skipPathSetting) { try { map.Md5Checksum = MapsetHelper.GetMd5Checksum(path); map.Directory = new DirectoryInfo(System.IO.Path.GetDirectoryName(path) ?? throw new InvalidOperationException()).Name.Replace("\\", "/"); map.Path = System.IO.Path.GetFileName(path)?.Replace("\\", "/"); map.LastFileWrite = File.GetLastWriteTimeUtc(map.Path); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } } try { map.Bpm = chart.BPM; } catch (Exception) { map.Bpm = 0; } map.DateAdded = DateTime.Now; return(map); }
public void ConvertOsuMap() { Logger.Log("Selecting .osu file"); string path = StandaloneFileBrowser.OpenFilePanel("Select .osu file", Application.dataPath + "/../Charts/", new ExtensionFilter[] { _extOsuFilter }, false)[0]; if (path.Length <= 0) { return; } FileInfo chartFile = new FileInfo(path); if (!chartFile.Exists) { if (new DirectoryInfo(path).Exists) { Logger.Log("Converting folders is not supported yet"); return; } Logger.Log("Chartfile not found"); return; } var chart = ChartFile.ConvertOsuFile(path); string artist = ChartFile.FixPath(chart.Artist); string title = ChartFile.FixPath(chart.Title); string creator = ChartFile.FixPath(chart.Creator); GlobalConfig tss = (GlobalConfig)ConfigManager.GetOrLoadOrAdd <GlobalConfig>(); DirectoryInfo chartPath = new DirectoryInfo(tss.SongDirectory + $"/{artist} - {title} ({creator})/"); chart.Speed = 23; chart.Save(Path.Combine(chartPath.FullName, $"{artist} - {title} ({creator}) [{chart.Difficulty}]")); FileInfo audio = new FileInfo(Path.Combine(chartPath.FullName, chart.SoundFile)); if (!audio.Exists) { File.Copy(chartFile.Directory.FullName + @"\" + chart.SoundFile, audio.FullName); } }
/// <summary> /// </summary> public static void ForceUpdateMaps() { for (var i = 0; i < MapsToUpdate.Count; i++) { try { var path = $"{GlobalConfig.Load().SongDirectory}/{MapsToUpdate[i].Directory}/{MapsToUpdate[i].Path}"; if (!File.Exists(path)) { continue; } var map = Map.FromChart(ChartFile.Parse(path, false), path); map.CalculateDifficulties(); map.Id = MapsToUpdate[i].Id; if (map.Id == 0) { map.Id = InsertMap(map, path); } else { UpdateMap(map); } MapsToUpdate[i] = map; MapManager.Selected.Value = map; } catch (Exception e) { Logger.Log(e); } } MapsToUpdate.Clear(); OrderAndSetMapsets(); var selectedMapset = MapManager.Mapsets.Find(x => x.Maps.Any(y => y.Id == MapManager.Selected.Value.Id)); MapManager.Selected.Value = selectedMapset.Maps.Find(x => x.Id == MapManager.Selected.Value.Id); }
/// <summary> /// Loads the .chart, .osu or .sm file for a map. /// /// </summary> /// <returns></returns> /// <exception cref="ArgumentException"></exception> public ChartFile LoadChart(bool checkValidity = true) { // Reference to the parsed .chart file ChartFile chart; // Handle osu! maps as well switch (Game) { case MapGame.DrumSmasher: var chartPath = $"{GlobalConfig.Load().SongDirectory}/{Directory}/{Path}"; chart = ChartFile.Parse(chartPath, checkValidity); break; case MapGame.Osu: chart = null; //TODO: Load osu chart file break; default: throw new InvalidEnumArgumentException(); } return(chart); }
public void LoadMap(ChartFile chart, System.IO.DirectoryInfo chartDirectory) { if (_sceneActionActive) { return; } if (ErrorPanel.activeSelf) { return; } _sceneActionActive = true; if (chart == null) { ErrorPanel.GetComponentInChildren <Text>().text = "No charts in Charts folder."; ErrorPanel.SetActive(true); Logger.Log("No chart selected"); return; } if (chart != null) { Logger.Log("Chart loaded, Switching to Taiko"); LoadedChart = chart; _sceneActionActive = false; SwitchToTaiko(chartDirectory); } else { ErrorPanel.GetComponentInChildren <Text>().text = "Failed to load Chart"; ErrorPanel.SetActive(true); Logger.Log("Failed to load chart"); } _sceneActionActive = false; }
public void OnSceneLoaded(DirectoryInfo chartFolder, ChartFile cf, List <(string, float)> mods)
public static void OnSceneLoaded(ChartFile chart, DirectoryInfo chartDirectory, List <(string, float)> mods = null)