//------------------------------------------------------------------------------ // // 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 Bright.Serialization; using System.Collections.Generic; using System.Linq; namespace GameConfig.Battle { public partial class TbBuffAttr { public static TbBuffAttr Instance { get; private set; } private bool _readAll = false; private Dictionary _dataMap; private List _dataList; public Dictionary DataMap { get { if(!_readAll) { ReadAll(); _readAll = true; } return _dataMap; } } public List DataList { get { if(!_readAll) { ReadAll(); _readAll = true; } return _dataList; } } private Dictionary _indexMap; public List Indexes; private System.Func _dataLoader; private void ReadAll() { _dataList.Clear(); foreach(var index in Indexes) { var v = Get(index); _dataMap[index] = v; _dataList.Add(v); } } public TbBuffAttr(ByteBuf _buf, string _tbName, System.Func _loader) { Instance = this; _dataMap = new Dictionary(); _dataList = new List(); _indexMap = new Dictionary(); _dataLoader = new System.Func(() => _loader(_tbName)); for (int n = _buf.ReadSize(); n > 0; --n) { int key; key = _buf.ReadInt(); int index = _buf.ReadInt(); _indexMap[key] = index; } Indexes = _indexMap.Keys.ToList(); PostInit(); } public Battle.BuffAttrConfig this[int key] => Get(key); public Battle.BuffAttrConfig Get(int key) { Battle.BuffAttrConfig _v; if(_dataMap.TryGetValue(key, out _v)) { return _v; } ResetByteBuf(_indexMap[key]); _v = Battle.BuffAttrConfig.DeserializeBuffAttrConfig(_buf); _dataMap[_v.BuffID] = _v; _v.Resolve(tables); if(_indexMap.Count == _dataMap.Count) { _buf = null; } return _v; } public Battle.BuffAttrConfig GetOrDefault(int key) { if(_indexMap.TryGetValue(key,out var _)) { return Get(key); } return null; } private void ResetByteBuf(int readerInex = 0) { if( _buf == null) { if (_buf == null) { _buf = _dataLoader(); } } _buf.ReaderIndex = readerInex; } private ByteBuf _buf = null; private Dictionary tables; public void CacheTables(Dictionary _tables) { tables = _tables; } partial void PostInit(); } }