From 4851f49ad5e71604e9fc24770ea720a1e78851e1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Oct 2016 16:35:14 -0400 Subject: [PATCH] Add basic osu! hit object parsing --- osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs | 40 +++++++++++++++++++-- osu.Game/Beatmaps/Objects/Osu/Spinner.cs | 2 +- osu.Game/Beatmaps/Samples/HitSampleInfo.cs | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs index 0edf3909d4..1f069677c9 100644 --- a/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs +++ b/osu.Game/Beatmaps/Objects/Osu/OsuBaseHit.cs @@ -1,17 +1,53 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; +using osu.Game.Beatmaps.Samples; namespace osu.Game.Beatmaps.Objects.Osu { public abstract class OsuBaseHit : HitObject { - public Vector2 Position; + public Vector2 Position { get; set; } + public bool NewCombo { get; set; } + + [Flags] + private enum HitObjectType + { + Circle = 1, + Slider = 2, + NewCombo = 4, + Spinner = 8, + } public static OsuBaseHit Parse(string val) { - return null; + string[] split = val.Split(','); + var type = (HitObjectType)int.Parse(split[3]); + bool combo = type.HasFlag(HitObjectType.NewCombo); + type &= ~HitObjectType.NewCombo; + OsuBaseHit result; + switch (type) + { + case HitObjectType.Circle: + result = new Circle(); + break; + case HitObjectType.Slider: + result = new Slider(); + break; + case HitObjectType.Spinner: + result = new Spinner(); + break; + default: + throw new InvalidOperationException($@"Unknown hit object type {type}"); + } + result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1])); + result.StartTime = double.Parse(split[2]); + result.Sample = new HitSampleInfo { Type = (SampleType)int.Parse(split[3]) }; + result.NewCombo = combo; + // TODO: "addition" field + return result; } } } diff --git a/osu.Game/Beatmaps/Objects/Osu/Spinner.cs b/osu.Game/Beatmaps/Objects/Osu/Spinner.cs index 8426e0b529..e19af7c5ba 100644 --- a/osu.Game/Beatmaps/Objects/Osu/Spinner.cs +++ b/osu.Game/Beatmaps/Objects/Osu/Spinner.cs @@ -3,7 +3,7 @@ namespace osu.Game.Beatmaps.Objects.Osu { - public class Spinner + public class Spinner : OsuBaseHit { } } diff --git a/osu.Game/Beatmaps/Samples/HitSampleInfo.cs b/osu.Game/Beatmaps/Samples/HitSampleInfo.cs index 4083a528aa..2598669336 100644 --- a/osu.Game/Beatmaps/Samples/HitSampleInfo.cs +++ b/osu.Game/Beatmaps/Samples/HitSampleInfo.cs @@ -5,6 +5,6 @@ namespace osu.Game.Beatmaps.Samples { public class HitSampleInfo : SampleInfo { - SampleType Type; + public SampleType Type { get; set; } } }