Files
crtr/Assets/Cryville/Crtr/Browsing/ChartResourceImporter.cs

23 lines
797 B
C#

using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cryville.Crtr.Browsing {
public class ChartResourceImporter : ResourceConverter {
static readonly string[] SUPPORTED_FORMATS = { ".umgc" };
public override string[] GetSupportedFormats() {
return SUPPORTED_FORMATS;
}
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
var meta = Path.Combine(file.Directory.FullName, "meta.json");
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
return new Resource[] { new ChartResource(data.name, file) };
}
}
}
}