2025-07-12 21:35:58 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Data;
|
|
|
|
|
using Utils;
|
|
|
|
|
|
|
|
|
|
namespace Managers
|
|
|
|
|
{
|
|
|
|
|
public class DefineManager : Singleton<DefineManager>
|
|
|
|
|
{
|
|
|
|
|
private const string coreNamespace = "Data";
|
|
|
|
|
private static readonly string[] dataSetFilePath = { "Data", "Mod" };
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, Dictionary<string, Define>> defines = new();
|
|
|
|
|
public Dictionary<string, DefinePack> packs = new();
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2025-07-13 08:56:33 +08:00
|
|
|
|
var packFolder = Configs.ConfigProcessor.GetSubFolders(new(dataSetFilePath));
|
2025-07-12 21:35:58 +08:00
|
|
|
|
foreach (var folder in packFolder)
|
|
|
|
|
{
|
|
|
|
|
var pack = new DefinePack();
|
|
|
|
|
if (pack.LoadPack(folder)) packs.Add(pack.packID, pack);
|
|
|
|
|
}
|
2025-07-13 08:56:33 +08:00
|
|
|
|
|
2025-07-14 11:40:55 +08:00
|
|
|
|
foreach (var pack in packs)
|
|
|
|
|
{
|
|
|
|
|
foreach (var define in pack.Value.defines)
|
|
|
|
|
{
|
|
|
|
|
var typeName=define.Key;
|
|
|
|
|
var defList=define.Value;
|
|
|
|
|
if (!defines.ContainsKey(typeName))
|
|
|
|
|
defines[typeName] = new Dictionary<string, Define>();
|
|
|
|
|
foreach (var def in defList)
|
|
|
|
|
{
|
|
|
|
|
defines[typeName][def.defName] = def;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查找指定定义类型的定义名对应的 Define 对象。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="defineType">定义类型</param>
|
|
|
|
|
/// <param name="defineName">定义名</param>
|
|
|
|
|
/// <returns>如果找到,返回 Define 对象;否则返回 null。</returns>
|
|
|
|
|
public Define FindDefine(string defineType, string defineName)
|
|
|
|
|
{
|
|
|
|
|
if (defines.TryGetValue(defineType, out var typeDict))
|
|
|
|
|
{
|
|
|
|
|
if (typeDict.TryGetValue(defineName, out var define))
|
|
|
|
|
{
|
|
|
|
|
return define;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-07-13 08:56:33 +08:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
if (packs == null || packs.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return "No packs available"; // 如果集合为空或为 null,返回默认信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = new System.Text.StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (var definePack in packs)
|
|
|
|
|
{
|
|
|
|
|
result.AppendLine(definePack.ToString()); // 每个元素占一行
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result.ToString();
|
|
|
|
|
}
|
2025-07-12 21:35:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|