yuanshen/Yuanshen.Common/Data/Excel/ExcelTableCollection.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +03:00

33 lines
1.1 KiB
C#

using System.Collections.Immutable;
using System.Reflection;
using Yuanshen.Common.Data.Excel.Attributes;
using Yuanshen.Common.Data.Provider;
namespace Yuanshen.Common.Data.Excel;
public sealed class ExcelTableCollection
{
private readonly ImmutableDictionary<ExcelType, ExcelTable> _tables;
public ExcelTableCollection(IAssetProvider assetProvider)
{
ImmutableDictionary<ExcelType, ExcelTable>.Builder builder =
ImmutableDictionary.CreateBuilder<ExcelType, ExcelTable>();
IEnumerable<Type> types = Assembly.GetExecutingAssembly().GetTypes()
.Where(type => type.GetCustomAttribute<ExcelAttribute>() != null);
foreach (Type type in types)
{
ExcelAttribute attribute = type.GetCustomAttribute<ExcelAttribute>()!;
builder.Add(attribute.Type, new ExcelTable(assetProvider.GetExcelTableJson(attribute.AssetName), type));
}
_tables = builder.ToImmutable();
}
public ExcelTable GetTable(ExcelType type) => _tables[type];
public TExcel? GetExcel<TExcel>(ExcelType type, uint id) where TExcel : ExcelItem
=> _tables[type].GetById<TExcel>(id);
}