//------------------------------------------------------------------------------ // // This code was generated by a tool. // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ using Luban; namespace Server.Config { public partial class ResConfigCategory : ConfigSingleton { public const string TableName = Tables.ResConfigCategory; private readonly System.Collections.Generic.Dictionary _dataMap; private readonly System.Collections.Generic.List _dataList; public ResConfigCategory() { _dataMap = new System.Collections.Generic.Dictionary(); _dataList = new System.Collections.Generic.List(); this.ReLoadData(); } public sealed override void ReLoadData() { // 备份旧数据,以便加载失败时回滚 var oldDataList = new System.Collections.Generic.List(_dataList); _dataMap.Clear(); _dataList.Clear(); try { byte[] data = TableManager.Instance.GetTableData(TableName); LoadData(new ByteBuf(data)); } catch { // 加载失败,回滚到旧数据 _dataMap.Clear(); _dataList.Clear(); foreach (var item in oldDataList) { _dataList.Add(item); _dataMap.Add(item.Id, item); } throw; } } protected sealed override void LoadData(ByteBuf _buf) { for(int n = _buf.ReadSize() ; n > 0 ; --n) { ResConfig _v; _v = ResConfig.DeserializeResConfig(_buf); _dataList.Add(_v); _dataMap.Add(_v.Id, _v); } PostInit(); } public System.Collections.Generic.Dictionary DataMap => _dataMap; public System.Collections.Generic.List DataList => _dataList; public ResConfig GetOrDefault(int key) => _dataMap.TryGetValue(key, out var v) ? v : null; public ResConfig Get(int key) => _dataMap[key]; public ResConfig this[int key] => _dataMap[key]; public bool Contain(int key) => _dataMap.ContainsKey(key); partial void PostInit(); } }