Files
crtr/Assets/Cryville/Crtr/Browsing/Legacy/LegacyChartResourceManager.cs

42 lines
1.4 KiB
C#

using Cryville.Common.Unity;
using Cryville.Common;
using Cryville.Crtr.Extension;
using Newtonsoft.Json;
using System.IO;
using UnityEngine;
namespace Cryville.Crtr.Browsing.Legacy {
internal class LegacyChartResourceManager : LegacyResourceManager<LegacyChartDetail> {
protected override string Extension { get { return ".umgc"; } }
public LegacyChartResourceManager(string rootPath) : base(rootPath) { }
protected override string GetSubRootPath(string rootPath) {
return Path.Combine(rootPath, "charts");
}
protected override LegacyChartDetail GetMeta(DirectoryInfo dir) {
ChartMeta meta = null;
AsyncDelivery<Texture2D> cover = null;
var metaFile = new FileInfo(Path.Combine(dir.FullName, Extension));
if (metaFile.Exists) {
using (var reader = new StreamReader(metaFile.FullName)) {
meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
}
if (meta.cover != null && meta.cover != "") {
var coverFile = dir.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
}
}
return new LegacyChartDetail {
Cover = cover,
Meta = meta,
};
}
}
}