mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge branch 'master'
Conflicts: osu.Game/osu.Game.csproj
This commit is contained in:
18
osu.Game/Beatmaps/BaseDifficulty.cs
Normal file
18
osu.Game/Beatmaps/BaseDifficulty.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class BaseDifficulty
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int ID { get; set; }
|
||||
public float DrainRate { get; set; }
|
||||
public float CircleSize { get; set; }
|
||||
public float OverallDifficulty { get; set; }
|
||||
public float ApproachRate { get; set; }
|
||||
public float SliderMultiplier { get; set; }
|
||||
public float SliderTickRate { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,68 @@
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps.Objects;
|
||||
using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
using osu.Game.Users;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class Beatmap
|
||||
{
|
||||
public List<HitObject> HitObjects;
|
||||
|
||||
public List<ControlPoint> ControlPoints;
|
||||
|
||||
public string Difficulty;
|
||||
public User Creator;
|
||||
[PrimaryKey]
|
||||
public int BeatmapID { get; set; }
|
||||
[NotNull, Indexed]
|
||||
public int BeatmapSetID { get; set; }
|
||||
[Indexed]
|
||||
public int BeatmapMetadataID { get; set; }
|
||||
public int BaseDifficultyID { get; set; }
|
||||
[Ignore]
|
||||
public List<HitObject> HitObjects { get; set; }
|
||||
[Ignore]
|
||||
public List<ControlPoint> ControlPoints { get; set; }
|
||||
[Ignore]
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
[Ignore]
|
||||
public BaseDifficulty BaseDifficulty { get; set; }
|
||||
[Ignore]
|
||||
public List<Color4> ComboColors { get; set; }
|
||||
|
||||
// General
|
||||
public int AudioLeadIn { get; set; }
|
||||
public bool Countdown { get; set; }
|
||||
public SampleSet SampleSet { get; set; }
|
||||
public float StackLeniency { get; set; }
|
||||
public bool SpecialStyle { get; set; }
|
||||
public PlayMode Mode { get; set; }
|
||||
public bool LetterboxInBreaks { get; set; }
|
||||
public bool WidescreenStoryboard { get; set; }
|
||||
|
||||
// Editor
|
||||
// This bookmarks stuff is necessary because DB doesn't know how to store int[]
|
||||
public string StoredBookmarks { get; internal set; }
|
||||
[Ignore]
|
||||
public int[] Bookmarks
|
||||
{
|
||||
get
|
||||
{
|
||||
return StoredBookmarks.Split(',').Select(b => int.Parse(b)).ToArray();
|
||||
}
|
||||
set
|
||||
{
|
||||
StoredBookmarks = string.Join(",", value);
|
||||
}
|
||||
}
|
||||
public double DistanceSpacing { get; set; }
|
||||
public int BeatDivisor { get; set; }
|
||||
public int GridSize { get; set; }
|
||||
public double TimelineZoom { get; set; }
|
||||
|
||||
// Metadata
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
26
osu.Game/Beatmaps/BeatmapMetadata.cs
Normal file
26
osu.Game/Beatmaps/BeatmapMetadata.cs
Normal file
@ -0,0 +1,26 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.GameModes.Play;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class BeatmapMetadata
|
||||
{
|
||||
[PrimaryKey]
|
||||
public int ID { get; set; }
|
||||
|
||||
public int BeatmapSetID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string TitleUnicode { get; set; }
|
||||
public string Artist { get; set; }
|
||||
public string ArtistUnicode { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public int PreviewTime { get; set; }
|
||||
public string AudioFile { get; set; }
|
||||
public string BackgroundFile { get; set; }
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Users;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
@ -11,10 +12,15 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public class BeatmapSet
|
||||
{
|
||||
[PrimaryKey]
|
||||
public int BeatmapSetID { get; set; }
|
||||
[NotNull, Indexed]
|
||||
public int BeatmapMetadataID { get; set; }
|
||||
[Ignore]
|
||||
public List<Beatmap> Beatmaps { get; protected set; }
|
||||
|
||||
public Metadata Metadata;
|
||||
|
||||
public User Creator;
|
||||
[Ignore]
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
[Ignore]
|
||||
public User Creator { get; set; }
|
||||
}
|
||||
}
|
||||
|
14
osu.Game/Beatmaps/Events/EventType.cs
Normal file
14
osu.Game/Beatmaps/Events/EventType.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
namespace osu.Game.Beatmaps.Events
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
Background = 0,
|
||||
Video = 1,
|
||||
Break = 2,
|
||||
Colour = 3,
|
||||
Sprite = 4,
|
||||
Sample = 5,
|
||||
Animation = 6
|
||||
}
|
||||
}
|
25
osu.Game/Beatmaps/Formats/BeatmapDecoder.cs
Normal file
25
osu.Game/Beatmaps/Formats/BeatmapDecoder.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public abstract class BeatmapDecoder
|
||||
{
|
||||
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
|
||||
|
||||
public static BeatmapDecoder GetDecoder(TextReader stream)
|
||||
{
|
||||
var line = stream.ReadLine().Trim();
|
||||
if (!decoders.ContainsKey(line))
|
||||
throw new IOException(@"Unknown file format");
|
||||
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
|
||||
}
|
||||
|
||||
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
|
||||
{
|
||||
decoders[magic] = typeof(T);
|
||||
}
|
||||
|
||||
public abstract Beatmap Decode(TextReader stream);
|
||||
}
|
272
osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs
Normal file
272
osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs
Normal file
@ -0,0 +1,272 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps.Events;
|
||||
using osu.Game.Beatmaps.Objects;
|
||||
using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.GameModes.Play;
|
||||
|
||||
namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public class OsuLegacyDecoder : BeatmapDecoder
|
||||
{
|
||||
public static void Register()
|
||||
{
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v14");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v13");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v12");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v11");
|
||||
AddDecoder<OsuLegacyDecoder>(@"osu file format v10");
|
||||
// TODO: Not sure how far back to go, or differences between versions
|
||||
}
|
||||
|
||||
private enum Section
|
||||
{
|
||||
None,
|
||||
General,
|
||||
Editor,
|
||||
Metadata,
|
||||
Difficulty,
|
||||
Events,
|
||||
TimingPoints,
|
||||
Colours,
|
||||
HitObjects,
|
||||
}
|
||||
|
||||
private void handleGeneral(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case @"AudioFilename":
|
||||
beatmap.Metadata.AudioFile = val;
|
||||
break;
|
||||
case @"AudioLeadIn":
|
||||
beatmap.AudioLeadIn = int.Parse(val);
|
||||
break;
|
||||
case @"PreviewTime":
|
||||
beatmap.Metadata.PreviewTime = int.Parse(val);
|
||||
break;
|
||||
case @"Countdown":
|
||||
beatmap.Countdown = int.Parse(val) == 1;
|
||||
break;
|
||||
case @"SampleSet":
|
||||
beatmap.SampleSet = (SampleSet)Enum.Parse(typeof(SampleSet), val);
|
||||
break;
|
||||
case @"StackLeniency":
|
||||
beatmap.StackLeniency = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"Mode":
|
||||
beatmap.Mode = (PlayMode)int.Parse(val);
|
||||
break;
|
||||
case @"LetterboxInBreaks":
|
||||
beatmap.LetterboxInBreaks = int.Parse(val) == 1;
|
||||
break;
|
||||
case @"SpecialStyle":
|
||||
beatmap.SpecialStyle = int.Parse(val) == 1;
|
||||
break;
|
||||
case @"WidescreenStoryboard":
|
||||
beatmap.WidescreenStoryboard = int.Parse(val) == 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEditor(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case @"Bookmarks":
|
||||
beatmap.StoredBookmarks = val;
|
||||
break;
|
||||
case @"DistanceSpacing":
|
||||
beatmap.DistanceSpacing = double.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"BeatDivisor":
|
||||
beatmap.BeatDivisor = int.Parse(val);
|
||||
break;
|
||||
case @"GridSize":
|
||||
beatmap.GridSize = int.Parse(val);
|
||||
break;
|
||||
case @"TimelineZoom":
|
||||
beatmap.TimelineZoom = double.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMetadata(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case @"Title":
|
||||
beatmap.Metadata.Title = val;
|
||||
break;
|
||||
case @"TitleUnicode":
|
||||
beatmap.Metadata.TitleUnicode = val;
|
||||
break;
|
||||
case @"Artist":
|
||||
beatmap.Metadata.Artist = val;
|
||||
break;
|
||||
case @"ArtistUnicode":
|
||||
beatmap.Metadata.ArtistUnicode = val;
|
||||
break;
|
||||
case @"Creator":
|
||||
beatmap.Metadata.Author = val;
|
||||
break;
|
||||
case @"Version":
|
||||
beatmap.Version = val;
|
||||
break;
|
||||
case @"Source":
|
||||
beatmap.Metadata.Source = val;
|
||||
break;
|
||||
case @"Tags":
|
||||
beatmap.Metadata.Tags = val;
|
||||
break;
|
||||
case @"BeatmapID":
|
||||
beatmap.BeatmapID = int.Parse(val);
|
||||
break;
|
||||
case @"BeatmapSetID":
|
||||
beatmap.BeatmapSetID = int.Parse(val);
|
||||
beatmap.Metadata.BeatmapSetID = int.Parse(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDifficulty(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case @"HPDrainRate":
|
||||
beatmap.BaseDifficulty.DrainRate = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"CircleSize":
|
||||
beatmap.BaseDifficulty.CircleSize = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"OverallDifficulty":
|
||||
beatmap.BaseDifficulty.OverallDifficulty = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"ApproachRate":
|
||||
beatmap.BaseDifficulty.ApproachRate = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"SliderMultiplier":
|
||||
beatmap.BaseDifficulty.SliderMultiplier = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
case @"SliderTickRate":
|
||||
beatmap.BaseDifficulty.SliderTickRate = float.Parse(val, NumberFormatInfo.InvariantInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEvents(Beatmap beatmap, string val)
|
||||
{
|
||||
if (val.StartsWith(@"//"))
|
||||
return;
|
||||
if (val.StartsWith(@" "))
|
||||
return; // TODO
|
||||
string[] split = val.Split(',');
|
||||
EventType type;
|
||||
int _type;
|
||||
if (!int.TryParse(split[0], out _type))
|
||||
{
|
||||
if (!Enum.TryParse(split[0], out type))
|
||||
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
||||
}
|
||||
else
|
||||
type = (EventType)_type;
|
||||
// TODO: Parse and store the rest of the event
|
||||
if (type == EventType.Background)
|
||||
beatmap.Metadata.BackgroundFile = split[2].Trim('"');
|
||||
}
|
||||
|
||||
private void handleTimingPoints(Beatmap beatmap, string val)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void handleColours(Beatmap beatmap, string key, string val)
|
||||
{
|
||||
string[] split = val.Split(',');
|
||||
if (split.Length != 3)
|
||||
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B): {val}");
|
||||
byte r, g, b;
|
||||
if (!byte.TryParse(split[0], out r) || !byte.TryParse(split[1], out g) || !byte.TryParse(split[2], out b))
|
||||
throw new InvalidOperationException($@"Color must be specified with 8-bit integer components");
|
||||
// Note: the combo index specified in the beatmap is discarded
|
||||
beatmap.ComboColors.Add(new Color4
|
||||
{
|
||||
R = r / 255f,
|
||||
G = g / 255f,
|
||||
B = b / 255f,
|
||||
A = 1f,
|
||||
});
|
||||
}
|
||||
|
||||
public override Beatmap Decode(TextReader stream)
|
||||
{
|
||||
var beatmap = new Beatmap
|
||||
{
|
||||
Metadata = new BeatmapMetadata(),
|
||||
BaseDifficulty = new BaseDifficulty(),
|
||||
HitObjects = new List<HitObject>(),
|
||||
ControlPoints = new List<ControlPoint>(),
|
||||
ComboColors = new List<Color4>(),
|
||||
};
|
||||
var section = Section.None;
|
||||
string line;
|
||||
while (true)
|
||||
{
|
||||
line = stream.ReadLine();
|
||||
if (line == null)
|
||||
break;
|
||||
line = line.Trim();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
if (line.StartsWith(@"osu file format v"))
|
||||
continue;
|
||||
|
||||
if (line.StartsWith(@"[") && line.EndsWith(@"]"))
|
||||
{
|
||||
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
|
||||
throw new InvalidDataException($@"Unknown osu section {line}");
|
||||
continue;
|
||||
}
|
||||
|
||||
string val = line, key = null;
|
||||
if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects)
|
||||
{
|
||||
key = val.Remove(val.IndexOf(':')).Trim();
|
||||
val = val.Substring(val.IndexOf(':') + 1).Trim();
|
||||
}
|
||||
switch (section)
|
||||
{
|
||||
case Section.General:
|
||||
handleGeneral(beatmap, key, val);
|
||||
break;
|
||||
case Section.Editor:
|
||||
handleEditor(beatmap, key, val);
|
||||
break;
|
||||
case Section.Metadata:
|
||||
handleMetadata(beatmap, key, val);
|
||||
break;
|
||||
case Section.Difficulty:
|
||||
handleDifficulty(beatmap, key, val);
|
||||
break;
|
||||
case Section.Events:
|
||||
handleEvents(beatmap, val);
|
||||
break;
|
||||
case Section.TimingPoints:
|
||||
handleTimingPoints(beatmap, val);
|
||||
break;
|
||||
case Section.Colours:
|
||||
handleColours(beatmap, key, val);
|
||||
break;
|
||||
case Section.HitObjects:
|
||||
beatmap.HitObjects.Add(HitObject.Parse(beatmap.Mode, val));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return beatmap;
|
||||
}
|
||||
}
|
||||
}
|
48
osu.Game/Beatmaps/IO/ArchiveReader.cs
Normal file
48
osu.Game/Beatmaps/IO/ArchiveReader.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public abstract class ArchiveReader : IDisposable
|
||||
{
|
||||
private class Reader
|
||||
{
|
||||
public Func<BasicStorage, string, bool> Test { get; set; }
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
|
||||
private static List<Reader> readers { get; } = new List<Reader>();
|
||||
|
||||
public static ArchiveReader GetReader(BasicStorage storage, string path)
|
||||
{
|
||||
foreach (var reader in readers)
|
||||
{
|
||||
if (reader.Test(storage, path))
|
||||
return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path));
|
||||
}
|
||||
throw new IOException(@"Unknown file format");
|
||||
}
|
||||
|
||||
protected static void AddReader<T>(Func<BasicStorage, string, bool> test) where T : ArchiveReader
|
||||
{
|
||||
readers.Add(new Reader { Test = test, Type = typeof(T) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the beatmap metadata from this archive.
|
||||
/// </summary>
|
||||
public abstract BeatmapMetadata ReadMetadata();
|
||||
/// <summary>
|
||||
/// Gets a list of beatmap file names.
|
||||
/// </summary>
|
||||
public abstract string[] ReadBeatmaps();
|
||||
/// <summary>
|
||||
/// Opens a stream for reading a specific file from this archive.
|
||||
/// </summary>
|
||||
public abstract Stream ReadFile(string name);
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
61
osu.Game/Beatmaps/IO/OszArchiveReader.cs
Normal file
61
osu.Game/Beatmaps/IO/OszArchiveReader.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Ionic.Zip;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public sealed class OszArchiveReader : ArchiveReader
|
||||
{
|
||||
public static void Register()
|
||||
{
|
||||
AddReader<OszArchiveReader>((storage, path) =>
|
||||
{
|
||||
using (var stream = storage.GetStream(path))
|
||||
return ZipFile.IsZipFile(stream, false);
|
||||
});
|
||||
OsuLegacyDecoder.Register();
|
||||
}
|
||||
|
||||
private ZipFile archive { get; set; }
|
||||
private string[] beatmaps { get; set; }
|
||||
private Beatmap firstMap { get; set; }
|
||||
|
||||
public OszArchiveReader(Stream archiveStream)
|
||||
{
|
||||
archive = ZipFile.Read(archiveStream);
|
||||
beatmaps = archive.Entries.Where(e => e.FileName.EndsWith(@".osu"))
|
||||
.Select(e => e.FileName).ToArray();
|
||||
if (beatmaps.Length == 0)
|
||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
firstMap = decoder.Decode(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] ReadBeatmaps()
|
||||
{
|
||||
return beatmaps;
|
||||
}
|
||||
|
||||
public override Stream ReadFile(string name)
|
||||
{
|
||||
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||
if (entry == null)
|
||||
throw new FileNotFoundException();
|
||||
return entry.OpenReader();
|
||||
}
|
||||
|
||||
public override BeatmapMetadata ReadMetadata()
|
||||
{
|
||||
return firstMap.Metadata;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
archive.Dispose();
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Beatmaps
|
||||
{
|
||||
public class Metadata
|
||||
{
|
||||
public string Artist;
|
||||
public string Title;
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Beatmaps.Objects.Osu;
|
||||
using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.GameModes.Play;
|
||||
|
||||
namespace osu.Game.Beatmaps.Objects
|
||||
{
|
||||
@ -16,5 +18,17 @@ namespace osu.Game.Beatmaps.Objects
|
||||
public double Duration => (EndTime ?? StartTime) - StartTime;
|
||||
|
||||
public HitSampleInfo Sample;
|
||||
|
||||
public static HitObject Parse(PlayMode mode, string val)
|
||||
{
|
||||
//TODO: move to modular HitObjectParser system rather than static parsing. (https://github.com/ppy/osu/pull/60/files#r83135780)
|
||||
switch (mode)
|
||||
{
|
||||
case PlayMode.Osu:
|
||||
return OsuBaseHit.Parse(val);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,59 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//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,
|
||||
CircleNewCombo = 5,
|
||||
SliderNewCombo = 6,
|
||||
Spinner = 8,
|
||||
ColourHax = 122,
|
||||
Hold = 128,
|
||||
ManiaLong = 128,
|
||||
}
|
||||
|
||||
public static OsuBaseHit Parse(string val)
|
||||
{
|
||||
string[] split = val.Split(',');
|
||||
var type = (HitObjectType)int.Parse(split[3]);
|
||||
bool combo = type.HasFlag(HitObjectType.NewCombo);
|
||||
type &= (HitObjectType)0xF;
|
||||
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[4]) };
|
||||
result.NewCombo = combo;
|
||||
// TODO: "addition" field
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace osu.Game.Beatmaps.Objects.Osu
|
||||
{
|
||||
public class Spinner
|
||||
public class Spinner : OsuBaseHit
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@ namespace osu.Game.Beatmaps.Samples
|
||||
{
|
||||
public class HitSampleInfo : SampleInfo
|
||||
{
|
||||
SampleType Type;
|
||||
public SampleType Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user