mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Initial support code for beatmap loading
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Framework.OS;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using SQLite;
|
||||
|
||||
namespace osu.Game.Database
|
||||
@ -17,6 +21,46 @@ namespace osu.Game.Database
|
||||
Connection.CreateTable<BeatmapSet>();
|
||||
Connection.CreateTable<Beatmap>();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBeatmap(ArchiveReader input)
|
||||
{
|
||||
var metadata = input.ReadMetadata();
|
||||
if (Connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
return;
|
||||
string[] mapNames = input.ReadBeatmaps();
|
||||
var beatmapSet = new BeatmapSet { BeatmapSetID = metadata.BeatmapSetID };
|
||||
var beatmapMetadata = new BeatmapMetadata
|
||||
{
|
||||
Title = metadata.Title,
|
||||
TitleUnicode = metadata.TitleUnicode,
|
||||
Artist = metadata.Artist,
|
||||
ArtistUnicode = metadata.ArtistUnicode,
|
||||
Author = metadata.Author,
|
||||
Source = metadata.Source,
|
||||
Tags = metadata.Tags,
|
||||
Mode = metadata.Mode,
|
||||
PreviewTime = metadata.PreviewTime,
|
||||
AudioFile = metadata.AudioFile,
|
||||
BackgroundFile = metadata.BackgroundFile,
|
||||
};
|
||||
var maps = new List<Beatmap>();
|
||||
foreach (var name in mapNames)
|
||||
{
|
||||
using (var stream = new StreamReader(input.ReadFile(name)))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
var beatmap = decoder.Decode(stream);
|
||||
maps.Add(new Beatmap
|
||||
{
|
||||
ID = beatmap.BeatmapID,
|
||||
BeatmapSetID = metadata.BeatmapSetID,
|
||||
// TODO: Import more things
|
||||
});
|
||||
}
|
||||
}
|
||||
beatmapSet.BeatmapMetadataID = Connection.Insert(beatmapMetadata);
|
||||
Connection.Insert(beatmapSet);
|
||||
Connection.InsertAll(maps);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user