-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMapDataStore.cs
66 lines (57 loc) · 1.97 KB
/
MapDataStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Mapperator.Model;
using osu.Framework.IO.Stores;
namespace Mapperator.DemoApp.Game;
public class MapDataStore : IResourceStore<IEnumerable<IEnumerable<MapDataPoint>>>
{
private readonly IResourceStore<byte[]> store;
public MapDataStore(IResourceStore<byte[]> resourceStore)
{
store = resourceStore;
}
public void Dispose()
{
store.Dispose();
}
private static IEnumerable<string> iterateLines(StreamReader reader)
{
while (!reader.EndOfStream)
{
yield return reader.ReadLine();
}
}
public IEnumerable<IEnumerable<MapDataPoint>> Get(string name)
{
using Stream stream = store.GetStream(name);
if (stream is null) return null;
using StreamReader reader = new StreamReader(stream);
var (version, data) = DataSerializer.DeserializeBeatmapData(iterateLines(reader).ToArray());
if (version != 1)
throw new NotImplementedException($"Data version {version} is not currently supported in MapDataStore");
return data;
}
public Task<IEnumerable<IEnumerable<MapDataPoint>>> GetAsync(string name, CancellationToken cancellationToken = new())
{
using Stream stream = store.GetStream(name);
if (stream is null) return null;
using StreamReader reader = new StreamReader(stream);
var (version, data) = DataSerializer.DeserializeBeatmapData(iterateLines(reader));
if (version != 1)
throw new NotImplementedException($"Data version {version} is not currently supported in MapDataStore");
return Task.FromResult(data);
}
public Stream GetStream(string name)
{
return store.GetStream(name);
}
public IEnumerable<string> GetAvailableResources()
{
return store.GetAvailableResources();
}
}