Files
TEngine/Assets/GameScripts/HotFix/GameProto/GameConfig/Battle/TbSkill.cs
ALEXTANG e071c20214 拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存
拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存
2023-08-17 23:07:07 +08:00

126 lines
3.7 KiB
C#

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Bright.Serialization;
using System.Collections.Generic;
using System.Linq;
namespace GameConfig.Battle
{
public partial class TbSkill
{
public static TbSkill Instance { get; private set; }
private bool _readAll = false;
private Dictionary<int, Battle.SkillBaseConfig> _dataMap;
private List<Battle.SkillBaseConfig> _dataList;
public Dictionary<int, Battle.SkillBaseConfig> DataMap
{
get
{
if(!_readAll)
{
ReadAll();
_readAll = true;
}
return _dataMap;
}
}
public List<Battle.SkillBaseConfig> DataList
{
get
{
if(!_readAll)
{
ReadAll();
_readAll = true;
}
return _dataList;
}
}
private Dictionary<int,int> _indexMap;
public List<int> Indexes;
private System.Func<ByteBuf> _dataLoader;
private void ReadAll()
{
_dataList.Clear();
foreach(var index in Indexes)
{
var v = Get(index);
_dataMap[index] = v;
_dataList.Add(v);
}
}
public TbSkill(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
{
Instance = this;
_dataMap = new Dictionary<int, Battle.SkillBaseConfig>();
_dataList = new List<Battle.SkillBaseConfig>();
_indexMap = new Dictionary<int, int>();
_dataLoader = new System.Func<ByteBuf>(() => _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.SkillBaseConfig this[int key] => Get(key);
public Battle.SkillBaseConfig Get(int key)
{
Battle.SkillBaseConfig _v;
if(_dataMap.TryGetValue(key, out _v))
{
return _v;
}
ResetByteBuf(_indexMap[key]);
_v = Battle.SkillBaseConfig.DeserializeSkillBaseConfig(_buf);
_dataMap[_v.Id] = _v;
_v.Resolve(tables);
if(_indexMap.Count == _dataMap.Count)
{
_buf = null;
}
return _v;
}
public Battle.SkillBaseConfig 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<string, object> tables;
public void CacheTables(Dictionary<string, object> _tables)
{
tables = _tables;
}
partial void PostInit();
}
}