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.
31 lines
1 KiB
C#
31 lines
1 KiB
C#
using System.Collections.Immutable;
|
|
using System.Text.Json;
|
|
|
|
namespace Yuanshen.Common.Data.Excel;
|
|
|
|
public sealed class ExcelTable
|
|
{
|
|
private readonly ImmutableArray<ExcelItem> _items;
|
|
private readonly ImmutableDictionary<uint, ExcelItem> _itemsById;
|
|
|
|
public ExcelTable(JsonDocument document, Type type)
|
|
{
|
|
ImmutableArray<ExcelItem>.Builder items = ImmutableArray.CreateBuilder<ExcelItem>();
|
|
|
|
foreach (JsonElement element in document.RootElement.EnumerateArray())
|
|
{
|
|
if (element.ValueKind != JsonValueKind.Object)
|
|
throw new ArgumentException("Excel table root must be an array of objects");
|
|
|
|
items.Add((element.Deserialize(type) as ExcelItem)!);
|
|
}
|
|
|
|
_items = items.ToImmutable();
|
|
_itemsById = _items.ToImmutableDictionary(item => item.ExcelId);
|
|
}
|
|
|
|
public IReadOnlyList<ExcelItem> Items => _items;
|
|
|
|
public TExcel? GetById<TExcel>(uint id) where TExcel : ExcelItem
|
|
=> _itemsById.TryGetValue(id, out ExcelItem? item) ? item as TExcel : null;
|
|
}
|