Tidy up DatabaseWorkingBeatmap.

This commit is contained in:
Dean Herbert 2017-03-23 10:07:26 +09:00
parent 9601e143d4
commit 859ee5d316
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
1 changed files with 10 additions and 18 deletions

View File

@ -21,12 +21,13 @@ public DatabaseWorkingBeatmap(BeatmapDatabase database, BeatmapInfo beatmapInfo,
} }
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo); private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
protected override Beatmap GetBeatmap() protected override Beatmap GetBeatmap()
{ {
Beatmap beatmap;
try try
{ {
Beatmap beatmap;
using (var reader = getReader()) using (var reader = getReader())
{ {
BeatmapDecoder decoder; BeatmapDecoder decoder;
@ -40,42 +41,33 @@ protected override Beatmap GetBeatmap()
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile))) using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
decoder.Decode(stream, beatmap); decoder.Decode(stream, beatmap);
} }
return beatmap;
} }
catch { return null; } catch { return null; }
return beatmap;
} }
protected override Texture GetBackground() protected override Texture GetBackground()
{ {
Texture background;
if (BeatmapInfo?.Metadata?.BackgroundFile == null) if (BeatmapInfo?.Metadata?.BackgroundFile == null)
return null; return null;
try try
{ {
using (var reader = getReader()) using (var reader = getReader())
{ return new TextureStore(new RawTextureLoaderStore(reader), false).Get(BeatmapInfo.Metadata.BackgroundFile);
background = new TextureStore(
new RawTextureLoaderStore(reader),
false).Get(BeatmapInfo.Metadata.BackgroundFile);
}
} }
catch { return null; } catch { return null; }
return background;
} }
private ArchiveReader trackReader;
protected override Track GetTrack() protected override Track GetTrack()
{ {
Track track;
try try
{ {
//store a reference to the reader as we may continue accessing the stream in the background. var trackData = getReader()?.GetStream(BeatmapInfo.Metadata.AudioFile);
trackReader = getReader(); return trackData == null ? null : new TrackBass(trackData);
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
track = trackData == null ? null : new TrackBass(trackData);
} }
catch { return null; } catch { return null; }
return track;
} }
} }
} }