mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 08:53:20 +08:00
Load beatmap data from an optional osb file.
This commit is contained in:
parent
c5cf6a6909
commit
a504c73f33
@ -21,6 +21,7 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
|
|
||||||
private string basePath { get; set; }
|
private string basePath { get; set; }
|
||||||
private string[] beatmaps { get; set; }
|
private string[] beatmaps { get; set; }
|
||||||
|
private string storyboard { get; set; }
|
||||||
private Beatmap firstMap { get; set; }
|
private Beatmap firstMap { get; set; }
|
||||||
|
|
||||||
public LegacyFilesystemReader(string path)
|
public LegacyFilesystemReader(string path)
|
||||||
@ -29,6 +30,7 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
||||||
if (beatmaps.Length == 0)
|
if (beatmaps.Length == 0)
|
||||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
||||||
|
storyboard = Directory.GetFiles(basePath, @"*.osb").Select(f => Path.GetFileName(f)).FirstOrDefault();
|
||||||
using (var stream = new StreamReader(GetStream(beatmaps[0])))
|
using (var stream = new StreamReader(GetStream(beatmaps[0])))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
@ -41,6 +43,11 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
return beatmaps;
|
return beatmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ReadStoryboard()
|
||||||
|
{
|
||||||
|
return storyboard;
|
||||||
|
}
|
||||||
|
|
||||||
public override Stream GetStream(string name)
|
public override Stream GetStream(string name)
|
||||||
{
|
{
|
||||||
return File.OpenRead(Path.Combine(basePath, name));
|
return File.OpenRead(Path.Combine(basePath, name));
|
||||||
|
@ -7,6 +7,8 @@ using System.IO;
|
|||||||
using osu.Game.Modes.Objects;
|
using osu.Game.Modes.Objects;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Beatmaps.Timing;
|
||||||
|
using osu.Game.Database;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Formats
|
namespace osu.Game.Beatmaps.Formats
|
||||||
{
|
{
|
||||||
@ -34,6 +36,11 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Decode(TextReader stream, Beatmap beatmap)
|
||||||
|
{
|
||||||
|
ParseFile(stream, beatmap);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual Beatmap Process(Beatmap beatmap)
|
public virtual Beatmap Process(Beatmap beatmap)
|
||||||
{
|
{
|
||||||
ApplyColours(beatmap);
|
ApplyColours(beatmap);
|
||||||
@ -41,7 +48,23 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
return beatmap;
|
return beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Beatmap ParseFile(TextReader stream);
|
protected virtual Beatmap ParseFile(TextReader stream)
|
||||||
|
{
|
||||||
|
var beatmap = new Beatmap
|
||||||
|
{
|
||||||
|
HitObjects = new List<HitObject>(),
|
||||||
|
ControlPoints = new List<ControlPoint>(),
|
||||||
|
ComboColors = new List<Color4>(),
|
||||||
|
BeatmapInfo = new BeatmapInfo
|
||||||
|
{
|
||||||
|
Metadata = new BeatmapMetadata(),
|
||||||
|
BaseDifficulty = new BaseDifficulty(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ParseFile(stream, beatmap);
|
||||||
|
return beatmap;
|
||||||
|
}
|
||||||
|
protected abstract void ParseFile(TextReader stream, Beatmap beatmap);
|
||||||
|
|
||||||
public virtual void ApplyColours(Beatmap b)
|
public virtual void ApplyColours(Beatmap b)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
{
|
{
|
||||||
public class ConstructableBeatmapDecoder : BeatmapDecoder
|
public class ConstructableBeatmapDecoder : BeatmapDecoder
|
||||||
{
|
{
|
||||||
protected override Beatmap ParseFile(TextReader stream)
|
protected override void ParseFile(TextReader stream, Beatmap beatmap)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -233,20 +233,8 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Beatmap ParseFile(TextReader stream)
|
protected override void ParseFile(TextReader stream, Beatmap beatmap)
|
||||||
{
|
{
|
||||||
var beatmap = new Beatmap
|
|
||||||
{
|
|
||||||
HitObjects = new List<HitObject>(),
|
|
||||||
ControlPoints = new List<ControlPoint>(),
|
|
||||||
ComboColors = new List<Color4>(),
|
|
||||||
BeatmapInfo = new BeatmapInfo
|
|
||||||
{
|
|
||||||
Metadata = new BeatmapMetadata(),
|
|
||||||
BaseDifficulty = new BaseDifficulty(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
HitObjectParser parser = null;
|
HitObjectParser parser = null;
|
||||||
|
|
||||||
var section = Section.None;
|
var section = Section.None;
|
||||||
@ -309,8 +297,6 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return beatmap;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract string[] ReadBeatmaps();
|
public abstract string[] ReadBeatmaps();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Gets the storyboard file name.
|
||||||
|
/// </summary>
|
||||||
|
public abstract string ReadStoryboard();
|
||||||
|
/// <summary>
|
||||||
/// Opens a stream for reading a specific file from this archive.
|
/// Opens a stream for reading a specific file from this archive.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract Stream GetStream(string name);
|
public abstract Stream GetStream(string name);
|
||||||
|
@ -26,8 +26,9 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
private Stream archiveStream;
|
private Stream archiveStream;
|
||||||
private ZipFile archive;
|
private ZipFile archive;
|
||||||
private string[] beatmaps;
|
private string[] beatmaps;
|
||||||
|
private string storyboard;
|
||||||
private Beatmap firstMap;
|
private Beatmap firstMap;
|
||||||
|
|
||||||
public OszArchiveReader(Stream archiveStream)
|
public OszArchiveReader(Stream archiveStream)
|
||||||
{
|
{
|
||||||
this.archiveStream = archiveStream;
|
this.archiveStream = archiveStream;
|
||||||
@ -36,6 +37,8 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
.Select(e => e.FileName).ToArray();
|
.Select(e => e.FileName).ToArray();
|
||||||
if (beatmaps.Length == 0)
|
if (beatmaps.Length == 0)
|
||||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
||||||
|
storyboard = archive.Entries.Where(e => e.FileName.EndsWith(@".osb"))
|
||||||
|
.Select(e => e.FileName).FirstOrDefault();
|
||||||
using (var stream = new StreamReader(GetStream(beatmaps[0])))
|
using (var stream = new StreamReader(GetStream(beatmaps[0])))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
@ -48,6 +51,11 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
return beatmaps;
|
return beatmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ReadStoryboard()
|
||||||
|
{
|
||||||
|
return storyboard;
|
||||||
|
}
|
||||||
|
|
||||||
public override Stream GetStream(string name)
|
public override Stream GetStream(string name)
|
||||||
{
|
{
|
||||||
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||||
|
@ -18,6 +18,8 @@ namespace osu.Game.Beatmaps
|
|||||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
||||||
private readonly BeatmapDatabase database;
|
private readonly BeatmapDatabase database;
|
||||||
|
|
||||||
|
public readonly bool WithStoryboard;
|
||||||
|
|
||||||
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
|
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
|
||||||
|
|
||||||
private Texture background;
|
private Texture background;
|
||||||
@ -58,8 +60,18 @@ namespace osu.Game.Beatmaps
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = getReader())
|
using (var reader = getReader())
|
||||||
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
{
|
||||||
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
|
BeatmapDecoder decoder;
|
||||||
|
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
||||||
|
{
|
||||||
|
decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
|
beatmap = decoder?.Decode(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null)
|
||||||
|
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
|
||||||
|
decoder?.Decode(stream, beatmap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
@ -103,11 +115,12 @@ namespace osu.Game.Beatmaps
|
|||||||
this.beatmap = beatmap;
|
this.beatmap = beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database)
|
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database, bool withStoryboard = false)
|
||||||
{
|
{
|
||||||
BeatmapInfo = beatmapInfo;
|
BeatmapInfo = beatmapInfo;
|
||||||
BeatmapSetInfo = beatmapSetInfo;
|
BeatmapSetInfo = beatmapSetInfo;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
this.WithStoryboard = withStoryboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
@ -137,6 +137,7 @@ namespace osu.Game.Database
|
|||||||
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
|
beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
beatmapSet.StoryboardFile = reader.ReadStoryboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
Import(new[] { beatmapSet });
|
Import(new[] { beatmapSet });
|
||||||
@ -169,7 +170,7 @@ namespace osu.Game.Database
|
|||||||
return Query<BeatmapSetInfo>().FirstOrDefault(s => s.OnlineBeatmapSetID == id);
|
return Query<BeatmapSetInfo>().FirstOrDefault(s => s.OnlineBeatmapSetID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null)
|
public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null, bool withStoryboard = false)
|
||||||
{
|
{
|
||||||
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID);
|
var beatmapSetInfo = Query<BeatmapSetInfo>().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID);
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ namespace osu.Game.Database
|
|||||||
if (beatmapInfo.Metadata == null)
|
if (beatmapInfo.Metadata == null)
|
||||||
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
beatmapInfo.Metadata = beatmapSetInfo.Metadata;
|
||||||
|
|
||||||
var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this);
|
var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this, withStoryboard);
|
||||||
|
|
||||||
previous?.TransferTo(working);
|
previous?.TransferTo(working);
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ namespace osu.Game.Database
|
|||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
|
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
public string StoryboardFile { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace osu.Game.Screens.Play
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Beatmap == null)
|
if (Beatmap == null)
|
||||||
Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo);
|
Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo, withStoryboard: true);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user