public OsuBeatmap(RelativeFileInfo AudioFileName = default, int AudioLeadIn = 0, Hash AudioHash = default, int PreviewTime = -1, OsuCountdown Countdown = OsuCountdown.Normal, OsuSampleSet SampleSet = OsuSampleSet.Normal, decimal StackLeniency = 0.7M, OsuGameMode Mode = OsuGameMode.Osu, bool LetterboxInBreaks = false, bool StoryFireInFront = true, bool UseSkinSprites = true, bool AlwaysShowPlayfield = false, OsuDrawPosition OverlayPosition = OsuDrawPosition.NoChange, string SkinPreference = "", bool EpilepsyWarning = false, int CountdownOffset = 0, bool SpecialStyle = false, bool WidescreenStoryboard = false, bool SamplesMatchPlaybackRate = false, int[] Bookmarks = default, decimal DistanceSpacing = 0M, decimal BeatDivisor = 0M, int GridSize = 0, decimal TimelineZoom = 0M, string Title = "", string TitleUnicode = "", string Artist = "", string ArtistUnicode = "", string Creator = "", string Version = "", string Source = "", string[] Tags = default, int BeatmapID = 0, int BeatmapSetID = 0, decimal HPDrainRate = 5M, decimal CircleSize = 5M, decimal OverallDifficulty = 5M, decimal ApproachRate = 5M, decimal SliderMultiplier = 1M, decimal SliderTickRate = 1M, OsuEvent[] Events = default, OsuTimingPoint[] TimingPoints = default, OsuHitObject[] HitObjects = default) { this.AudioFileName = AudioFileName /* ?? throw new ArgumentNullException(nameof(AudioFileName))*/; this.AudioLeadIn = AudioLeadIn; #pragma warning disable CS0612 // Type or member is obsolete this.AudioHash = AudioHash /* ?? throw new ArgumentNullException(nameof(AudioHash))*/; #pragma warning restore CS0612 // Type or member is obsolete this.PreviewTime = PreviewTime; this.Countdown = Countdown; this.SampleSet = SampleSet; this.StackLeniency = StackLeniency; this.Mode = Mode; this.LetterboxInBreaks = LetterboxInBreaks; #pragma warning disable CS0612 // Type or member is obsolete this.StoryFireInFront = StoryFireInFront; #pragma warning restore CS0612 // Type or member is obsolete this.UseSkinSprites = UseSkinSprites; #pragma warning disable CS0612 // Type or member is obsolete this.AlwaysShowPlayfield = AlwaysShowPlayfield; #pragma warning restore CS0612 // Type or member is obsolete this.OverlayPosition = OverlayPosition; this.SkinPreference = SkinPreference /* ?? throw new ArgumentNullException(nameof(SkinPreference))*/; this.EpilepsyWarning = EpilepsyWarning; this.CountdownOffset = CountdownOffset; this.SpecialStyle = SpecialStyle; this.WidescreenStoryboard = WidescreenStoryboard; this.SamplesMatchPlaybackRate = SamplesMatchPlaybackRate; this.Bookmarks = Bookmarks /* ?? throw new ArgumentNullException(nameof(Bookmarks))*/; this.DistanceSpacing = DistanceSpacing; this.BeatDivisor = BeatDivisor; this.GridSize = GridSize; this.TimelineZoom = TimelineZoom; this.Title = Title /* ?? throw new ArgumentNullException(nameof(Title))*/; this.TitleUnicode = TitleUnicode /* ?? throw new ArgumentNullException(nameof(TitleUnicode))*/; this.Artist = Artist /* ?? throw new ArgumentNullException(nameof(Artist))*/; this.ArtistUnicode = ArtistUnicode /* ?? throw new ArgumentNullException(nameof(ArtistUnicode))*/; this.Creator = Creator /* ?? throw new ArgumentNullException(nameof(Creator))*/; this.Version = Version /* ?? throw new ArgumentNullException(nameof(Version))*/; this.Source = Source /* ?? throw new ArgumentNullException(nameof(Source))*/; this.Tags = Tags /* ?? throw new ArgumentNullException(nameof(Tags))*/; this.BeatmapID = BeatmapID; this.BeatmapSetID = BeatmapSetID; this.HPDrainRate = HPDrainRate; this.CircleSize = CircleSize; this.OverallDifficulty = OverallDifficulty; this.ApproachRate = ApproachRate; this.SliderMultiplier = SliderMultiplier; this.SliderTickRate = SliderTickRate; this.Events = Events /* ?? throw new ArgumentNullException(nameof(Events))*/; this.TimingPoints = TimingPoints /* ?? throw new ArgumentNullException(nameof(TimingPoints))*/; this.HitObjects = HitObjects /* ?? throw new ArgumentNullException(nameof(HitObjects))*/; }
public static void GetGeneralFields(List <string> Lines, out RelativeFileInfo AudioFileName, out int AudioLeadIn, out Hash AudioHash, out int PreviewTime, out OsuCountdown Countdown, out OsuSampleSet SampleSet, out decimal StackLeniency, out OsuGameMode Mode, out bool LetterboxInBreaks, out bool StoryFireInFront, out bool UseSkinSprites, out bool AlwaysShowPlayfield, out OsuDrawPosition OverlayPosition, out string SkinPreference, out bool EpilepsyWarning, out int CountdownOffset, out bool SpecialStyle, out bool WidescreenStoryboard, out bool SamplesMatchPlaybackRate) { AudioFileName = default; AudioLeadIn = CountdownOffset = 0; AudioHash = default; PreviewTime = -1; Countdown = OsuCountdown.Normal; SampleSet = OsuSampleSet.Normal; StackLeniency = 0.7M; Mode = OsuGameMode.Osu; LetterboxInBreaks = AlwaysShowPlayfield = EpilepsyWarning = SpecialStyle = WidescreenStoryboard = SamplesMatchPlaybackRate = false; StoryFireInFront = UseSkinSprites = true; OverlayPosition = OsuDrawPosition.NoChange; SkinPreference = default; //Debug.WriteLine("Iterating through General values"); foreach ((string Key, string Value) in GetValues(Lines, ": ")) { switch (Key) { case @"audiofilename": //Debug.WriteLine($"\tFound: {Key} == {Value}"); AudioFileName = Value.ConvertToRelativeFileInfo(); break; case @"audioleadin": //Debug.WriteLine($"\tFound: {Key} == {Value}"); AudioLeadIn = Value.ConvertToInt(0); break; case @"audiohash": //Debug.WriteLine($"\tFound: {Key} == {Value}"); //TODO Implement obtaining pre-generated hash stored in string AudioHash = null; break; case @"previewtime": //Debug.WriteLine($"\tFound: {Key} == {Value}"); PreviewTime = Value.ConvertToInt(-1); break; case @"countdown": //Debug.WriteLine($"\tFound: {Key} == {Value}"); Countdown = Value.ConvertToEnum <OsuCountdown>(); break; case @"sampleset": //Debug.WriteLine($"\tFound: {Key} == {Value}"); SampleSet = Value.ConvertToEnum <OsuSampleSet>(); break; case @"stackleniency": //Debug.WriteLine($"\tFound: {Key} == {Value}"); StackLeniency = Value.ConvertToDecimal(0.7M); break; case @"mode": //Debug.WriteLine($"\tFound: {Key} == {Value}"); Mode = Value.ConvertToEnum <OsuGameMode>(); break; case @"letterboxinbreaks": //Debug.WriteLine($"\tFound: {Key} == {Value}"); LetterboxInBreaks = Value.ConvertToBool(); break; case @"storyfireinfront": //Debug.WriteLine($"\tFound: {Key} == {Value}"); StoryFireInFront = Value.ConvertToBool(); break; case @"useskinsprites": //Debug.WriteLine($"\tFound: {Key} == {Value}"); UseSkinSprites = Value.ConvertToBool(); break; case @"alwaysshowplayfield": //Debug.WriteLine($"\tFound: {Key} == {Value}"); AlwaysShowPlayfield = Value.ConvertToBool(); break; case @"overlayposition": //Debug.WriteLine($"\tFound: {Key} == {Value}"); OverlayPosition = Value.ConvertToEnum <OsuDrawPosition>(); break; case @"skinpreference": //Debug.WriteLine($"\tFound: {Key} == {Value}"); SkinPreference = Value; break; case @"epilepsywarning": //Debug.WriteLine($"\tFound: {Key} == {Value}"); EpilepsyWarning = Value.ConvertToBool(); break; case @"countdownoffset": //Debug.WriteLine($"\tFound: {Key} == {Value}"); CountdownOffset = Value.ConvertToInt(0); break; case @"specialstyle": //Debug.WriteLine($"\tFound: {Key} == {Value}"); SpecialStyle = Value.ConvertToBool(); break; case @"widescreenstoryboard": //Debug.WriteLine($"\tFound: {Key} == {Value}"); WidescreenStoryboard = Value.ConvertToBool(); break; case @"samplesmatchplaybackrate": //Debug.WriteLine($"\tFound: {Key} == {Value}"); SamplesMatchPlaybackRate = Value.ConvertToBool(); break; } } }
public static OsuBeatmap GetBeatmap(string[] Lines, bool ParseGeneralValues = true, bool ParseEditorValues = true, bool ParseMetadataValues = true, bool ParseDifficultyValues = true, bool ParseEvents = true, bool ParseTimingPoints = true, bool ParseHitObjects = true) { Lines = NormaliseLines(Lines).ToArray(); List <string> GeneralValues = new List <string>(); List <string> EditorValues = new List <string>(); List <string> MetadataValues = new List <string>(); List <string> DifficultyValues = new List <string>(); List <string> EventValues = new List <string>(); List <string> TimingPointValues = new List <string>(); //List<string> ColourValues = new List<string>(); List <string> HitObjectValues = new List <string>(); string Section = null; // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (string Line in Lines) { if (Line.TrimStart(' ').StartsWith("//")) { continue; } //Ignore comments if (TryGetSection(Line, out string NewSection)) { //Debug.WriteLine($"\tEntered new section {NewSection}..."); Section = NewSection; } switch (Section) { case "general" when ParseGeneralValues: if (Line.Contains(": ")) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'General'"); GeneralValues.Add(Line); } break; case "editor" when ParseEditorValues: if (Line.Contains(": ")) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'Editor'"); EditorValues.Add(Line); } break; case "metadata" when ParseMetadataValues: if (Line.Contains(":")) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'Metadata'"); MetadataValues.Add(Line); } break; case "difficulty" when ParseDifficultyValues: if (Line.Contains(':')) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'Difficulty'"); DifficultyValues.Add(Line); } break; case "events" when ParseEvents: if (Line.Contains(',')) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'Events'"); EventValues.Add(Line); } break; case "timingpoints" when ParseTimingPoints: if (Line.Contains(',')) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'TimingPoints'"); TimingPointValues.Add(Line); } break; //case "colours": //TODO Implement Colours Support // if (Line.Contains(" : ")) { // ColourValues.Add(Line); // } // break; case "hitobjects" when ParseHitObjects: if (Line.Contains(',')) { //Debug.WriteLine($"\t\tLine '{Line}' is of type 'HitObjects'"); HitObjectValues.Add(Line); } break; } } //Debug.WriteLine("\tParsing General Fields..."); RelativeFileInfo AudioFileName = default; int AudioLeadIn = 0, CountdownOffset = 0, PreviewTime = -1; Hash AudioHash = default; OsuCountdown Countdown = OsuCountdown.Normal; OsuSampleSet SampleSet = OsuSampleSet.Normal; decimal StackLeniency = 0.7M; OsuGameMode Mode = OsuGameMode.Osu; bool LetterboxInBreaks = false, AlwaysShowPlayfield = false, EpilepsyWarning = false, SpecialStyle = false, WidescreenStoryboard = false, SamplesMatchPlaybackRate = false; bool StoryFireInFront = true, UseSkinSprites = true; OsuDrawPosition OverlayPosition = OsuDrawPosition.NoChange; string SkinPreference = default; if (ParseGeneralValues) { GetGeneralFields(GeneralValues, out AudioFileName, out AudioLeadIn, out AudioHash, out PreviewTime, out Countdown, out SampleSet, out StackLeniency, out Mode, out LetterboxInBreaks, out StoryFireInFront, out UseSkinSprites, out AlwaysShowPlayfield, out OverlayPosition, out SkinPreference, out EpilepsyWarning, out CountdownOffset, out SpecialStyle, out WidescreenStoryboard, out SamplesMatchPlaybackRate); } //Debug.WriteLine("\tParsing Editor Fields..."); int[] Bookmarks = Array.Empty <int>(); decimal DistanceSpacing = 0M, BeatDivisor = 0M, TimelineZoom = 0M; int GridSize = 0; if (ParseEditorValues) { GetEditorFields(EditorValues, out Bookmarks, out DistanceSpacing, out BeatDivisor, out GridSize, out TimelineZoom); } //Debug.WriteLine("\tParsing Metadata Fields..."); string Title = string.Empty, TitleUnicode = string.Empty, Artist = string.Empty, ArtistUnicode = string.Empty, Creator = string.Empty, Version = string.Empty, Source = string.Empty; string[] Tags = Array.Empty <string>(); int BeatmapID = 0, BeatmapSetID = 0; if (ParseMetadataValues) { GetMetadataFields(MetadataValues, out Title, out TitleUnicode, out Artist, out ArtistUnicode, out Creator, out Version, out Source, out Tags, out BeatmapID, out BeatmapSetID); } //Debug.WriteLine("\tParsing Difficulty Fields..."); decimal HPDrainRate = 5M, CircleSize = 5M, OverallDifficulty = 5M, ApproachRate = 5M, SliderMultiplier = 5M, SliderTickRate = 5M; if (ParseDifficultyValues) { GetDifficultyFields(DifficultyValues, out HPDrainRate, out CircleSize, out OverallDifficulty, out ApproachRate, out SliderMultiplier, out SliderTickRate); } //Debug.WriteLine("\tParsing Event Fields..."); OsuEvent[] Events = Array.Empty <OsuEvent>(); if (ParseEvents) { GetEventsField(EventValues, out Events); } //Debug.WriteLine("\tParsing TimingPoint Fields..."); OsuTimingPoint[] TimingPoints = Array.Empty <OsuTimingPoint>(); if (ParseTimingPoints) { GetTimingPointField(TimingPointValues, out TimingPoints); } //Debug.WriteLine("\tParsing HitObject Fields..."); OsuHitObject[] HitObjects = Array.Empty <OsuHitObject>(); if (ParseHitObjects) { GetHitObjectsField(HitObjectValues, out HitObjects); } return(new OsuBeatmap(AudioFileName, AudioLeadIn, AudioHash, PreviewTime, Countdown, SampleSet, StackLeniency, Mode, LetterboxInBreaks, StoryFireInFront, UseSkinSprites, AlwaysShowPlayfield, OverlayPosition, SkinPreference, EpilepsyWarning, CountdownOffset, SpecialStyle, WidescreenStoryboard, SamplesMatchPlaybackRate, Bookmarks, DistanceSpacing, BeatDivisor, GridSize, TimelineZoom, Title, TitleUnicode, Artist, ArtistUnicode, Creator, Version, Source, Tags, BeatmapID, BeatmapSetID, HPDrainRate, CircleSize, OverallDifficulty, ApproachRate, SliderMultiplier, SliderTickRate, Events, TimingPoints, HitObjects)); }