mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 14:22:55 +08:00
Add base for event parsing code.
This commit is contained in:
parent
2f8556a44a
commit
74c23ff6d8
@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Game.Beatmaps.Events;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -17,6 +18,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
public BeatmapInfo BeatmapInfo;
|
public BeatmapInfo BeatmapInfo;
|
||||||
public TimingInfo TimingInfo = new TimingInfo();
|
public TimingInfo TimingInfo = new TimingInfo();
|
||||||
|
public EventInfo EventInfo = new EventInfo();
|
||||||
public readonly List<Color4> ComboColors = new List<Color4>
|
public readonly List<Color4> ComboColors = new List<Color4>
|
||||||
{
|
{
|
||||||
new Color4(17, 136, 170, 255),
|
new Color4(17, 136, 170, 255),
|
||||||
@ -40,6 +42,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo;
|
BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo;
|
||||||
TimingInfo = original?.TimingInfo ?? TimingInfo;
|
TimingInfo = original?.TimingInfo ?? TimingInfo;
|
||||||
|
EventInfo = original?.EventInfo ?? EventInfo;
|
||||||
ComboColors = original?.ComboColors ?? ComboColors;
|
ComboColors = original?.ComboColors ?? ComboColors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,11 @@
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Events
|
namespace osu.Game.Beatmaps.Events
|
||||||
{
|
{
|
||||||
public enum EventType
|
public class BackgroundEvent : Event
|
||||||
{
|
{
|
||||||
Background = 0,
|
/// <summary>
|
||||||
Video = 1,
|
/// The file name.
|
||||||
Break = 2,
|
/// </summary>
|
||||||
Colour = 3,
|
public string Filename;
|
||||||
Sprite = 4,
|
|
||||||
Sample = 5,
|
|
||||||
Animation = 6
|
|
||||||
}
|
}
|
||||||
}
|
}
|
28
osu.Game/Beatmaps/Events/BreakEvent.cs
Normal file
28
osu.Game/Beatmaps/Events/BreakEvent.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps.Events
|
||||||
|
{
|
||||||
|
public class BreakEvent : Event
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum duration required for a break to have any effect.
|
||||||
|
/// </summary>
|
||||||
|
private const double min_break_duration = 650;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The break end time.
|
||||||
|
/// </summary>
|
||||||
|
public double EndTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The duration of the break.
|
||||||
|
/// </summary>
|
||||||
|
public double Duration => EndTime - StartTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the break has any effect. Breaks that are too short are culled before they reach the EventInfo.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasEffect => Duration >= min_break_duration;
|
||||||
|
}
|
||||||
|
}
|
13
osu.Game/Beatmaps/Events/Event.cs
Normal file
13
osu.Game/Beatmaps/Events/Event.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps.Events
|
||||||
|
{
|
||||||
|
public abstract class Event
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The event start time.
|
||||||
|
/// </summary>
|
||||||
|
public double StartTime;
|
||||||
|
}
|
||||||
|
}
|
26
osu.Game/Beatmaps/Events/EventInfo.cs
Normal file
26
osu.Game/Beatmaps/Events/EventInfo.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps.Events
|
||||||
|
{
|
||||||
|
public class EventInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All the background events.
|
||||||
|
/// </summary>
|
||||||
|
public readonly List<BackgroundEvent> Backgrounds = new List<BackgroundEvent>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All the break events.
|
||||||
|
/// </summary>
|
||||||
|
public readonly List<BreakEvent> Breaks = new List<BreakEvent>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total duration of all breaks.
|
||||||
|
/// </summary>
|
||||||
|
public double TotalBreakTime => Breaks.Sum(b => b.Duration);
|
||||||
|
}
|
||||||
|
}
|
@ -204,23 +204,42 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
|
|
||||||
private void handleEvents(Beatmap beatmap, string val)
|
private void handleEvents(Beatmap beatmap, string val)
|
||||||
{
|
{
|
||||||
if (val.StartsWith(@"//"))
|
|
||||||
return;
|
|
||||||
if (val.StartsWith(@" "))
|
|
||||||
return; // TODO
|
|
||||||
string[] split = val.Split(',');
|
string[] split = val.Split(',');
|
||||||
|
|
||||||
EventType type;
|
EventType type;
|
||||||
int intType;
|
if (!Enum.TryParse(split[0], out type))
|
||||||
if (!int.TryParse(split[0], out intType))
|
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
||||||
|
|
||||||
|
// Todo: Implement the rest
|
||||||
|
switch (type)
|
||||||
{
|
{
|
||||||
if (!Enum.TryParse(split[0], out type))
|
case EventType.Video:
|
||||||
throw new InvalidDataException($@"Unknown event type {split[0]}");
|
case EventType.Background:
|
||||||
|
string filename = split[2].Trim('"');
|
||||||
|
|
||||||
|
beatmap.EventInfo.Backgrounds.Add(new BackgroundEvent
|
||||||
|
{
|
||||||
|
StartTime = double.Parse(split[1], NumberFormatInfo.InvariantInfo),
|
||||||
|
Filename = filename
|
||||||
|
});
|
||||||
|
|
||||||
|
if (type == EventType.Background)
|
||||||
|
beatmap.BeatmapInfo.Metadata.BackgroundFile = filename;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case EventType.Break:
|
||||||
|
var breakEvent = new BreakEvent
|
||||||
|
{
|
||||||
|
StartTime = double.Parse(split[1], NumberFormatInfo.InvariantInfo),
|
||||||
|
EndTime = double.Parse(split[2], NumberFormatInfo.InvariantInfo)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!breakEvent.HasEffect)
|
||||||
|
return;
|
||||||
|
|
||||||
|
beatmap.EventInfo.Breaks.Add(breakEvent);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
type = (EventType)intType;
|
|
||||||
// TODO: Parse and store the rest of the event
|
|
||||||
if (type == EventType.Background)
|
|
||||||
beatmap.BeatmapInfo.Metadata.BackgroundFile = split[2].Trim('"');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTimingPoints(Beatmap beatmap, string val)
|
private void handleTimingPoints(Beatmap beatmap, string val)
|
||||||
@ -330,6 +349,9 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
if (string.IsNullOrEmpty(line))
|
if (string.IsNullOrEmpty(line))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (line.StartsWith(" ") || line.StartsWith("_") || line.StartsWith("//"))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (line.StartsWith(@"osu file format v"))
|
if (line.StartsWith(@"osu file format v"))
|
||||||
{
|
{
|
||||||
beatmap.BeatmapInfo.BeatmapVersion = int.Parse(line.Substring(17));
|
beatmap.BeatmapInfo.BeatmapVersion = int.Parse(line.Substring(17));
|
||||||
@ -390,5 +412,16 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
Soft = 2,
|
Soft = 2,
|
||||||
Drum = 3
|
Drum = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal enum EventType
|
||||||
|
{
|
||||||
|
Background = 0,
|
||||||
|
Video = 1,
|
||||||
|
Break = 2,
|
||||||
|
Colour = 3,
|
||||||
|
Sprite = 4,
|
||||||
|
Sample = 5,
|
||||||
|
Animation = 6
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,10 @@
|
|||||||
<Compile Include="Audio\SampleInfoList.cs" />
|
<Compile Include="Audio\SampleInfoList.cs" />
|
||||||
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
|
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
|
||||||
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
|
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
|
||||||
|
<Compile Include="Beatmaps\Events\BackgroundEvent.cs" />
|
||||||
|
<Compile Include="Beatmaps\Events\BreakEvent.cs" />
|
||||||
|
<Compile Include="Beatmaps\Events\Event.cs" />
|
||||||
|
<Compile Include="Beatmaps\Events\EventInfo.cs" />
|
||||||
<Compile Include="Online\API\Requests\PostMessageRequest.cs" />
|
<Compile Include="Online\API\Requests\PostMessageRequest.cs" />
|
||||||
<Compile Include="Online\Chat\ErrorMessage.cs" />
|
<Compile Include="Online\Chat\ErrorMessage.cs" />
|
||||||
<Compile Include="Overlays\Chat\ChatTabControl.cs" />
|
<Compile Include="Overlays\Chat\ChatTabControl.cs" />
|
||||||
@ -342,7 +346,6 @@
|
|||||||
<Compile Include="Beatmaps\Formats\BeatmapDecoder.cs" />
|
<Compile Include="Beatmaps\Formats\BeatmapDecoder.cs" />
|
||||||
<Compile Include="Beatmaps\Formats\OsuLegacyDecoder.cs" />
|
<Compile Include="Beatmaps\Formats\OsuLegacyDecoder.cs" />
|
||||||
<Compile Include="Beatmaps\IO\OszArchiveReader.cs" />
|
<Compile Include="Beatmaps\IO\OszArchiveReader.cs" />
|
||||||
<Compile Include="Beatmaps\Events\EventType.cs" />
|
|
||||||
<Compile Include="Graphics\UserInterface\Volume\VolumeMeter.cs" />
|
<Compile Include="Graphics\UserInterface\Volume\VolumeMeter.cs" />
|
||||||
<Compile Include="Database\BeatmapSetInfo.cs" />
|
<Compile Include="Database\BeatmapSetInfo.cs" />
|
||||||
<Compile Include="Database\BeatmapMetadata.cs" />
|
<Compile Include="Database\BeatmapMetadata.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user