-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This needs more test coverage before proper release. Color is not yet implemented.
- Loading branch information
1 parent
6562b06
commit db3f440
Showing
10 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class AnimationEvent : EventBase | ||
{ | ||
internal AnimationEvent() | ||
{ | ||
} | ||
|
||
public string Layer { get; internal set; } | ||
public string Origin { get; internal set; } | ||
public string Path { get; internal set; } | ||
public float X { get; internal set; } | ||
public float Y { get; internal set; } | ||
public int FrameCount { get; internal set; } | ||
public double FrameDelay { get; internal set; } | ||
public string LoopType { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class BackgroundEvent : EventBase | ||
{ | ||
internal BackgroundEvent() | ||
{ | ||
} | ||
|
||
public string Path { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class BreakEvent : EventBase | ||
{ | ||
internal BreakEvent() | ||
{ | ||
} | ||
|
||
public double StartTime { get; internal set; } | ||
public double EndTime { get; internal set; } | ||
|
||
public double BreakTime => EndTime - StartTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System; | ||
|
||
namespace osu_database_reader.Components.Events | ||
{ | ||
public abstract class EventBase | ||
{ | ||
public string Line { get; internal set; } | ||
|
||
public static EventBase FromString(string line) | ||
{ | ||
if (string.IsNullOrEmpty(line)) | ||
throw new ArgumentException(line); | ||
|
||
try | ||
{ | ||
var split = line.Split(','); | ||
|
||
// https://github.com/ppy/osu/blob/7654df94f6f37b8382be7dfcb4f674e03bd35427/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs#L103 | ||
// https://github.com/ppy/osu/blob/7654df94f6f37b8382be7dfcb4f674e03bd35427/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs#L301 | ||
switch (split[0]) | ||
{ | ||
case "0": | ||
case "Background": | ||
{ | ||
// fields 1, 3 and 4 are unknown | ||
var path = split[2].Trim('"'); | ||
|
||
return new BackgroundEvent | ||
{ | ||
Path = path, | ||
Line = line, | ||
}; | ||
} | ||
case "1": | ||
case "Video": | ||
{ | ||
var offset = int.Parse(split[1], Constants.NumberFormat); | ||
var path = split[2].Trim('"'); | ||
|
||
return new VideoEvent | ||
{ | ||
Offset = offset, | ||
Path = path, | ||
Line = line, | ||
}; | ||
} | ||
case "2": | ||
case "Break": | ||
{ | ||
var start = double.Parse(split[1], Constants.NumberFormat); | ||
var end = double.Parse(split[2], Constants.NumberFormat); | ||
|
||
return new BreakEvent | ||
{ | ||
StartTime = start, | ||
EndTime = end, | ||
Line = line, | ||
}; | ||
} | ||
/* | ||
case "3": | ||
case "Colour": | ||
{ | ||
// TODO | ||
} | ||
*/ | ||
case "4": | ||
case "Sprite": | ||
{ | ||
var layer = split[1]; | ||
var origin = split[2]; | ||
var path = split[3].Trim('"'); | ||
var x = float.Parse(split[4], Constants.NumberFormat); | ||
var y = float.Parse(split[5], Constants.NumberFormat); | ||
|
||
return new SpriteEvent | ||
{ | ||
Layer = layer, | ||
Origin = origin, | ||
Path = path, | ||
X = x, | ||
Y = y, | ||
Line = line, | ||
}; | ||
} | ||
case "5": | ||
case "Sample": | ||
{ | ||
var time = double.Parse(split[1], Constants.NumberFormat); | ||
var layer = split[2]; | ||
var path = split[3]; | ||
|
||
var volume = split.Length > 3 ? float.Parse(split[4], Constants.NumberFormat) : (float?) null; | ||
|
||
return new SampleEvent | ||
{ | ||
Time = time, | ||
Layer = layer, | ||
Path = path, | ||
Volume = volume, | ||
Line = line, | ||
}; | ||
} | ||
case "6": | ||
case "Animation": | ||
{ | ||
var layer = split[1]; | ||
var origin = split[2]; | ||
var path = split[3].Trim('"'); | ||
var x = float.Parse(split[4], Constants.NumberFormat); | ||
var y = float.Parse(split[5], Constants.NumberFormat); | ||
var frameCount = int.Parse(split[6], Constants.NumberFormat); | ||
var frameDelay = double.Parse(split[7], Constants.NumberFormat); | ||
|
||
var loopType = split.Length > 8 ? split[8] : null; | ||
|
||
return new AnimationEvent | ||
{ | ||
Layer = layer, | ||
Origin = origin, | ||
Path = path, | ||
X = x, | ||
Y = y, | ||
FrameCount = frameCount, | ||
FrameDelay = frameDelay, | ||
LoopType = loopType, | ||
Line = line, | ||
}; | ||
} | ||
default: | ||
{ | ||
return new FallbackEvent | ||
{ | ||
Line = line, | ||
}; | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
return new FallbackEvent | ||
{ | ||
Line = line, | ||
}; | ||
} | ||
} | ||
|
||
private class FallbackEvent : EventBase | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class SampleEvent : EventBase | ||
{ | ||
internal SampleEvent() | ||
{ | ||
} | ||
|
||
public double Time { get; internal set; } | ||
public string Layer { get; internal set; } | ||
public string Path { get; internal set; } | ||
public float? Volume { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class SpriteEvent : EventBase | ||
{ | ||
internal SpriteEvent() | ||
{ | ||
} | ||
|
||
public string Layer { get; internal set; } | ||
public string Origin { get; internal set; } | ||
public string Path { get; internal set; } | ||
public float X { get; internal set; } | ||
public float Y { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace osu_database_reader.Components.Events | ||
{ | ||
public class VideoEvent : EventBase | ||
{ | ||
internal VideoEvent() | ||
{ | ||
} | ||
|
||
public int Offset { get; internal set; } | ||
public string Path { get; internal set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters