/// <summary> /// Create columns from the beatmap /// </summary> /// <param name="beatmap"></param> private void CreateColumns() { // Create one column for each key being used for (int i = 1; i <= KeyCount; i++) { Columns[i - 1] = new Column(i); } int objectCount = 0; // Add arcs to the columns foreach (Arc arc in CurrentBeatmap.Arcs) { for (int i = 0; i < KeyCount; i++) { if (BeatmapHelper.IsColumn(arc, i)) { Columns[i].AddHitObject ( new HitObject(arc.Time, (int)(i / (float)KeyCount * 360), KeyCount, CurrentArcsSpeed, Hidden), CurrentArcsSpeed * CurrentSpeedMultiplier, Crosshair.GetZLocation() ); objectCount++; } } } // Compute the beatmap's highest possible score, // for displaying the current display_score later on maxScore = Scoring.GetMaxScore(objectCount); }
/// <summary> /// Initializes the current GameplayView with the provided beatmap. /// </summary> /// <param name="beatmap">The beatmap to play through</param> public void Init(Beatmap beatmap) { try { if (!beatmap.FullyLoaded) { beatmap = BeatmapHelper.Load(beatmap.Path, beatmap.FileName); } // Reset in case it wasn't properly handled outside Reset(); // Load values gained from config/user settings LoadConfig(beatmap); // Initialize default variables, parse beatmap InitializeVariables(beatmap); // Initialize Gameplay variables InitializeGameplay(beatmap); // Create columns and their hitobjects CreateColumns(); // Sort the hitobjects according to their first appearance for optimizing update/draw SortHitObjects(); if (AutoPlay) { LoadAutoPlay(); } // Once everything is loaded, initialize the view GetGameplayView().Init(); // Start audio and gameplay StartGameplay(); // Collect any excess memory to prevent GC from starting soon, avoiding freezes. // TODO: disable GC while in gameplay GC.Collect(); Init(); } catch { // Force quit EndGameplay(); // Give warning PulsarcLogger.Warning($"There was an error attempting to load {beatmap.Title}, " + $"going back to Song Select!"); // Remove Result Screen ScreenManager.RemoveScreen(); } }
/// <summary> /// Converts an Intralism beatmap folder to a Pulsarc-compatible beatmap, and then saves the converted Beatmap to storage. /// </summary> /// <param name="folder_path">The path to the map-to-be-converted folder</param> public void Save(string folder_path) { Beatmap map = Convert(folder_path).First(); // If the map is null, or audio is null, stop saving. if (map == null || map.Audio == null) { return; } string audioPath = $"{folder_path}/{map.Audio}"; // If the path doesn't exist, stop saving. if (!File.Exists(audioPath)) { return; } int id = 0; // The folder name will look like "0 - Unknown - MapTitle - (Mapper)" string folderName = string.Join("_", ($"{id} - {map.Artist} - {map.Title} ({map.Mapper})").Split(Path.GetInvalidFileNameChars())); string dirName = $"Songs/{folderName}"; if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } // Copy Audio File File.Copy(audioPath, $"{dirName}/{map.Audio}", true); // Copy Background Image string backgroundPath = $"{folder_path}/{map.Background}"; // Find if the background exists and copy it. if (File.Exists(backgroundPath)) { try { File.Copy(backgroundPath, $"{dirName}/{map.Background}", true); } catch { PulsarcLogger.Debug("Converting the background failed! Converting wtihout background.", LogType.Runtime); } } else { map.Background = ""; } // The file name will look like "Unknown - MapTitle [Converted] (Mapper).psc" string difficultyFileName = string.Join("_", ($"{map.Artist} - {map.Title} [{map.Version}] ({map.Mapper})").Split(Path.GetInvalidFileNameChars())); BeatmapHelper.Save(map, $"{dirName}/{difficultyFileName}.psc"); }
/// <summary> /// Convert a folder of osu!mania beatmaps to Pulsarc-compatible beatmaps, and then save the converted Beatmaps to storage. /// </summary> /// <param name="folder_path">The path to the maps-to-be-converted folder</param> public void Save(string folder_path) { foreach (Beatmap map in Convert(folder_path)) { if (map.Audio != null) { string audioPath = $"{folder_path}/{map.Audio}"; if (File.Exists(audioPath)) { int id = 0; // The folder name will look like "0 - Artist - SongTitle - (Mapper)" string folderName = string.Join("_", ($"{id} - {map.Artist} - {map.Title} ({map.Mapper})").Split(Path.GetInvalidFileNameChars())); string dirName = $"Songs/{folderName}"; if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } // Copy Audio File File.Copy(audioPath, $"{dirName}/{map.Audio}", true); // Copy Background Image string backgroundPath = $"{folder_path}/{map.Background}"; if (File.Exists(backgroundPath)) { File.Copy(backgroundPath, $"{dirName}/{map.Background}", true); } else { map.Background = ""; } // The file name will look like "Artist - SongTitle [Converted] (Mapper).psc" string difficultyFileName = string.Join("_", ($"{map.Artist} - {map.Title} [{map.Version}] ({map.Mapper})").Split(Path.GetInvalidFileNameChars())); BeatmapHelper.Save(map, $"{dirName}/{difficultyFileName}.psc"); } } } }
protected async override Task OnAfterRenderAsync(bool isFirstRender) { await JSRuntime.InvokeVoidAsync("doUserSelectDir"); var queryString = QueryHelpers.ParseQuery(new Uri(NavigationManager.Uri).Query); ResourceReader = await BeatmapHelper.LoadNetworkResources(94790); /* * if (queryString.TryGetValue("sid", out var beatmapSetId)) * ResourceReader = await BeatmapHelper.LoadNetworkResources(int.Parse(beatmapSetId.ToString())); * else * //尝试发起本地上传文件请求 * ResourceReader = await BeatmapHelper.LoadLocalResources(); * * if (ResourceReader is null) * { * //错误处理 * return; * } */ Console.WriteLine("Start to select a .osb file and a .osu file (if it exist.)"); var osbFilePath = ResourceReader.EnumeratePath("*.osb").FirstOrDefault(); var osuFilePath = ResourceReader.EnumeratePath("*.osu").FirstOrDefault(); Console.WriteLine("osu file : " + osuFilePath); Console.WriteLine("osb file : " + osbFilePath); var updater = StoryboardHelper.ParseStoryboard(ResourceReader.ReadFile(osuFilePath), ResourceReader.ReadFile(osbFilePath)); Console.WriteLine($"Storyboard objects count : {updater.StoryboardObjectList.Count}"); Console.WriteLine($"Start load render resource..."); await StoryboardWindow.PrepareRenderResource(updater, ResourceReader); Console.WriteLine($"Render resource loading DONE!"); StoryboardWindow.Play(); Console.WriteLine($"OnAfterRenderAsync() end"); }
/// <summary> /// Initializes the current GameplayView with the provided beatmap. /// </summary> /// <param name="beatmap">The beatmap to play through</param> public void Init(Beatmap beatmap) { if (!beatmap.FullyLoaded) { beatmap = BeatmapHelper.Load(beatmap.Path, beatmap.FileName); } // Reset in case it wasn't properly handled outside Reset(); // Load values gained from config/user settings LoadConfig(); // Initialize default variables, parse beatmap InitializeVariables(beatmap); // Initialize Gameplay variables InitializeGameplay(beatmap); // Create columns and their hitobjects CreateColumns(); // Sort the hitobjects according to their first appearance for optimizing update/draw SortHitObjects(); if (AutoPlay) { LoadAutoPlay(); } // Once everything is loaded, initialize the view GetGameplayView().Init(); // Start audio and gameplay StartGameplay(); // Collect any excess memory to prevent GC from starting soon, avoiding freezes. // TODO: disable GC while in gameplay GC.Collect(); Init(); }
static async Task Main(string[] args) { var bufferSize = 123456; var buffer = ArrayPool <byte> .Shared.Rent(bufferSize); var memory = buffer.AsMemory().Slice(0, bufferSize); MemoryMarshal.TryGetArray <byte>(memory, out var segment); var reader = await BeatmapHelper.LoadNetworkResources(94790); Console.WriteLine("Start to select a .osb file and a .osu file (if it exist.)"); var osbFilePath = reader.EnumeratePath("*.osb").FirstOrDefault(); var osuFilePath = reader.EnumeratePath("*.osu").FirstOrDefault(); var updater = StoryboardHelper.ParseStoryboard(reader.ReadFile(osbFilePath), reader.ReadFile(osuFilePath)); Console.WriteLine(updater.StoryboardObjectList.Count); }
/// <summary> /// Make a new BeatmapData out of a Beatmap by loading /// the Beatmap from the provided path. /// </summary> /// <param name="path">Path to the Beatmap folder.</param> /// <param name="file">File name of the .psc Beatmap.</param> public BeatmapData(string path, string file) : this(BeatmapHelper.Load(path, file)) { }
/// <summary> /// Legacy. /// Initialize this gameplay view by using the folder location and /// difficulty name to find the beatmap. /// </summary> /// <param name="folder">Beatmap folder name.</param> /// <param name="diff">Difficulty name for the beatmap.</param> public void Init(string folder, string diff) => Init(BeatmapHelper.Load("Songs/" + folder, diff + ".psc"));