57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
|
|
namespace MetaAssets;
|
|
|
|
|
|
// HANDOVER: 메타 데이터를 로딩해 주는 클래스 이다.
|
|
// 본 로직들은 ServerBase 모듈로 이관 시켜야 한다.
|
|
|
|
|
|
public static class ContentLoader
|
|
{
|
|
public static T? loadFile<T>(string dataDir, string fileName) where T : ContentTableBase<T>
|
|
{
|
|
try
|
|
{
|
|
string exactPath = Path.GetFullPath(dataDir);
|
|
|
|
string data = System.IO.File.ReadAllText(Path.Combine(dataDir, fileName));
|
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(data);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"content load fail. dataDir: {dataDir}, fileName: {fileName}", ex);
|
|
}
|
|
}
|
|
|
|
public static T? loadMultipleFiles<T>(string dataDir, string filePattern) where T : ContentTableBase<T>
|
|
{
|
|
var files = Directory.GetFiles(dataDir, filePattern, SearchOption.TopDirectoryOnly);
|
|
|
|
List<T> tables = new List<T>();
|
|
foreach (string file in files)
|
|
{
|
|
string data = System.IO.File.ReadAllText(file);
|
|
T? json = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(data);
|
|
|
|
if(json != null)
|
|
tables.Add(json);
|
|
}
|
|
|
|
T? oneTable = null;
|
|
foreach (var table in tables)
|
|
{
|
|
if (oneTable == null)
|
|
oneTable = table;
|
|
else
|
|
oneTable.merge(table);
|
|
}
|
|
|
|
return oneTable;
|
|
}
|
|
}
|