mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存
拓展自定义鲁班加载配置,支持懒加载 默认使用懒加载,未使用的配置不会载入内存
This commit is contained in:
@@ -7,12 +7,12 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// 配置加载器。
|
||||
/// </summary>
|
||||
public class ConfigLoader:Singleton<ConfigLoader>
|
||||
public class ConfigLoader : Singleton<ConfigLoader>
|
||||
{
|
||||
private bool _init = false;
|
||||
|
||||
|
||||
private Tables _tables;
|
||||
|
||||
|
||||
public Tables Tables
|
||||
{
|
||||
get
|
||||
@@ -21,6 +21,7 @@ public class ConfigLoader:Singleton<ConfigLoader>
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
return _tables;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +31,7 @@ public class ConfigLoader:Singleton<ConfigLoader>
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
_tables = new Tables(LoadByteBuf);
|
||||
_tables = new Tables(LoadIdxByteBuf, LoadByteBuf);
|
||||
_init = true;
|
||||
}
|
||||
|
||||
@@ -41,7 +42,19 @@ public class ConfigLoader:Singleton<ConfigLoader>
|
||||
/// <returns>ByteBuf</returns>
|
||||
private ByteBuf LoadByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"{SettingsUtils.FrameworkGlobalSettings.ConfigFolderName}{file}.bytes");
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>(file);
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载懒加载Index。
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
private ByteBuf LoadIdxByteBuf(string file)
|
||||
{
|
||||
var textAssets = GameModule.Resource.LoadAsset<TextAsset>($"Idx_{file}");
|
||||
byte[] ret = textAssets.bytes;
|
||||
return new ByteBuf(ret);
|
||||
}
|
||||
@@ -49,16 +62,11 @@ public class ConfigLoader:Singleton<ConfigLoader>
|
||||
|
||||
public class ConfigSystem : BaseLogicSys<ConfigSystem>
|
||||
{
|
||||
public Tables Tables => ConfigLoader.Instance.Tables;
|
||||
|
||||
public override bool OnInit()
|
||||
{
|
||||
Log.Warning("ConfigSystem OnInit");
|
||||
InitConfig();
|
||||
return base.OnInit();
|
||||
}
|
||||
|
||||
private void InitConfig()
|
||||
{
|
||||
ConfigLoader.Instance.Load();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -7,57 +7,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace GameConfig.Battle
|
||||
{
|
||||
|
||||
public partial class TbBuff
|
||||
{
|
||||
private readonly Dictionary<int, Battle.BuffConfig> _dataMap;
|
||||
private readonly List<Battle.BuffConfig> _dataList;
|
||||
|
||||
public TbBuff(ByteBuf _buf)
|
||||
public partial class TbBuff
|
||||
{
|
||||
_dataMap = new Dictionary<int, Battle.BuffConfig>();
|
||||
_dataList = new List<Battle.BuffConfig>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
public static TbBuff Instance { get; private set; }
|
||||
private bool _readAll = false;
|
||||
private Dictionary<int, Battle.BuffConfig> _dataMap;
|
||||
private List<Battle.BuffConfig> _dataList;
|
||||
public Dictionary<int, Battle.BuffConfig> DataMap
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataMap;
|
||||
}
|
||||
}
|
||||
public List<Battle.BuffConfig> 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 TbBuff(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
_dataMap = new Dictionary<int, Battle.BuffConfig>();
|
||||
_dataList = new List<Battle.BuffConfig>();
|
||||
_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.BuffConfig this[int key] => Get(key);
|
||||
public Battle.BuffConfig Get(int key)
|
||||
{
|
||||
Battle.BuffConfig _v;
|
||||
if(_dataMap.TryGetValue(key, out _v))
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
ResetByteBuf(_indexMap[key]);
|
||||
_v = Battle.BuffConfig.DeserializeBuffConfig(_buf);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.BuffID, _v);
|
||||
_dataMap[_v.BuffID] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<int, Battle.BuffConfig> DataMap => _dataMap;
|
||||
public List<Battle.BuffConfig> DataList => _dataList;
|
||||
|
||||
public Battle.BuffConfig GetOrDefault(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public Battle.BuffConfig Get(int key) => _dataMap[key];
|
||||
public Battle.BuffConfig this[int key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
public Battle.BuffConfig GetOrDefault(int key)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return Get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
|
||||
private void ResetByteBuf(int readerInex = 0)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
if( _buf == null)
|
||||
{
|
||||
if (_buf == null)
|
||||
{
|
||||
_buf = _dataLoader();
|
||||
}
|
||||
}
|
||||
_buf.ReaderIndex = readerInex;
|
||||
}
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
||||
private ByteBuf _buf = null;
|
||||
private Dictionary<string, object> tables;
|
||||
public void CacheTables(Dictionary<string, object> _tables)
|
||||
{
|
||||
tables = _tables;
|
||||
}
|
||||
partial void PostInit();
|
||||
}
|
||||
}
|
@@ -7,57 +7,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace GameConfig.Battle
|
||||
{
|
||||
|
||||
public partial class TbBuffAttr
|
||||
{
|
||||
private readonly Dictionary<int, Battle.BuffAttrConfig> _dataMap;
|
||||
private readonly List<Battle.BuffAttrConfig> _dataList;
|
||||
|
||||
public TbBuffAttr(ByteBuf _buf)
|
||||
public partial class TbBuffAttr
|
||||
{
|
||||
_dataMap = new Dictionary<int, Battle.BuffAttrConfig>();
|
||||
_dataList = new List<Battle.BuffAttrConfig>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
public static TbBuffAttr Instance { get; private set; }
|
||||
private bool _readAll = false;
|
||||
private Dictionary<int, Battle.BuffAttrConfig> _dataMap;
|
||||
private List<Battle.BuffAttrConfig> _dataList;
|
||||
public Dictionary<int, Battle.BuffAttrConfig> DataMap
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataMap;
|
||||
}
|
||||
}
|
||||
public List<Battle.BuffAttrConfig> 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 TbBuffAttr(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
_dataMap = new Dictionary<int, Battle.BuffAttrConfig>();
|
||||
_dataList = new List<Battle.BuffAttrConfig>();
|
||||
_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.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);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.BuffID, _v);
|
||||
_dataMap[_v.BuffID] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<int, Battle.BuffAttrConfig> DataMap => _dataMap;
|
||||
public List<Battle.BuffAttrConfig> DataList => _dataList;
|
||||
|
||||
public Battle.BuffAttrConfig GetOrDefault(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public Battle.BuffAttrConfig Get(int key) => _dataMap[key];
|
||||
public Battle.BuffAttrConfig this[int key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
public Battle.BuffAttrConfig GetOrDefault(int key)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return Get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
|
||||
private void ResetByteBuf(int readerInex = 0)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
if( _buf == null)
|
||||
{
|
||||
if (_buf == null)
|
||||
{
|
||||
_buf = _dataLoader();
|
||||
}
|
||||
}
|
||||
_buf.ReaderIndex = readerInex;
|
||||
}
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
||||
private ByteBuf _buf = null;
|
||||
private Dictionary<string, object> tables;
|
||||
public void CacheTables(Dictionary<string, object> _tables)
|
||||
{
|
||||
tables = _tables;
|
||||
}
|
||||
partial void PostInit();
|
||||
}
|
||||
}
|
@@ -7,57 +7,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace GameConfig.Battle
|
||||
{
|
||||
|
||||
public partial class TbSkill
|
||||
{
|
||||
private readonly Dictionary<int, Battle.SkillBaseConfig> _dataMap;
|
||||
private readonly List<Battle.SkillBaseConfig> _dataList;
|
||||
|
||||
public TbSkill(ByteBuf _buf)
|
||||
public partial class TbSkill
|
||||
{
|
||||
_dataMap = new Dictionary<int, Battle.SkillBaseConfig>();
|
||||
_dataList = new List<Battle.SkillBaseConfig>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
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);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.Id, _v);
|
||||
_dataMap[_v.Id] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<int, Battle.SkillBaseConfig> DataMap => _dataMap;
|
||||
public List<Battle.SkillBaseConfig> DataList => _dataList;
|
||||
|
||||
public Battle.SkillBaseConfig GetOrDefault(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public Battle.SkillBaseConfig Get(int key) => _dataMap[key];
|
||||
public Battle.SkillBaseConfig this[int key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
public Battle.SkillBaseConfig GetOrDefault(int key)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return Get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
|
||||
private void ResetByteBuf(int readerInex = 0)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
if( _buf == null)
|
||||
{
|
||||
if (_buf == null)
|
||||
{
|
||||
_buf = _dataLoader();
|
||||
}
|
||||
}
|
||||
_buf.ReaderIndex = readerInex;
|
||||
}
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
||||
private ByteBuf _buf = null;
|
||||
private Dictionary<string, object> tables;
|
||||
public void CacheTables(Dictionary<string, object> _tables)
|
||||
{
|
||||
tables = _tables;
|
||||
}
|
||||
partial void PostInit();
|
||||
}
|
||||
}
|
@@ -8,9 +8,9 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
|
||||
|
||||
namespace GameConfig
|
||||
{
|
||||
{
|
||||
|
||||
public partial class Tables
|
||||
{
|
||||
public item.TbItem TbItem {get; }
|
||||
@@ -18,36 +18,26 @@ public partial class Tables
|
||||
public Battle.TbBuff TbBuff {get; }
|
||||
public Battle.TbBuffAttr TbBuffAttr {get; }
|
||||
|
||||
public Tables(System.Func<string, ByteBuf> loader)
|
||||
public Tables(System.Func<string, ByteBuf> idxLoader,System.Func<string, ByteBuf> dataLoader)
|
||||
{
|
||||
var tables = new System.Collections.Generic.Dictionary<string, object>();
|
||||
TbItem = new item.TbItem(loader("item_tbitem"));
|
||||
TbItem = new item.TbItem(idxLoader("item_tbitem"),"item_tbitem",dataLoader);
|
||||
tables.Add("item.TbItem", TbItem);
|
||||
TbSkill = new Battle.TbSkill(loader("battle_tbskill"));
|
||||
TbSkill = new Battle.TbSkill(idxLoader("battle_tbskill"),"battle_tbskill",dataLoader);
|
||||
tables.Add("Battle.TbSkill", TbSkill);
|
||||
TbBuff = new Battle.TbBuff(loader("battle_tbbuff"));
|
||||
TbBuff = new Battle.TbBuff(idxLoader("battle_tbbuff"),"battle_tbbuff",dataLoader);
|
||||
tables.Add("Battle.TbBuff", TbBuff);
|
||||
TbBuffAttr = new Battle.TbBuffAttr(loader("battle_tbbuffattr"));
|
||||
TbBuffAttr = new Battle.TbBuffAttr(idxLoader("battle_tbbuffattr"),"battle_tbbuffattr",dataLoader);
|
||||
tables.Add("Battle.TbBuffAttr", TbBuffAttr);
|
||||
|
||||
PostInit();
|
||||
TbItem.Resolve(tables);
|
||||
TbSkill.Resolve(tables);
|
||||
TbBuff.Resolve(tables);
|
||||
TbBuffAttr.Resolve(tables);
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
TbItem.TranslateText(translator);
|
||||
TbSkill.TranslateText(translator);
|
||||
TbBuff.TranslateText(translator);
|
||||
TbBuffAttr.TranslateText(translator);
|
||||
TbItem.CacheTables(tables);
|
||||
TbSkill.CacheTables(tables);
|
||||
TbBuff.CacheTables(tables);
|
||||
TbBuffAttr.CacheTables(tables);
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
@@ -22,7 +22,6 @@ public sealed partial class Item : Bright.Config.BeanBase
|
||||
UpgradeToItemId = _buf.ReadInt();
|
||||
if(_buf.ReadBool()){ ExpireTime = _buf.ReadInt(); } else { ExpireTime = null; }
|
||||
BatchUseable = _buf.ReadBool();
|
||||
Quality = (item.EQuality)_buf.ReadInt();
|
||||
ExchangeStream = item.ItemExchange.DeserializeItemExchange(_buf);
|
||||
{int n0 = System.Math.Min(_buf.ReadSize(), _buf.Size);ExchangeList = new System.Collections.Generic.List<item.ItemExchange>(n0);for(var i0 = 0 ; i0 < n0 ; i0++) { item.ItemExchange _e0; _e0 = item.ItemExchange.DeserializeItemExchange(_buf); ExchangeList.Add(_e0);}}
|
||||
ExchangeColumn = item.ItemExchange.DeserializeItemExchange(_buf);
|
||||
@@ -64,10 +63,6 @@ public sealed partial class Item : Bright.Config.BeanBase
|
||||
/// </summary>
|
||||
public bool BatchUseable { get; private set; }
|
||||
/// <summary>
|
||||
/// 品质
|
||||
/// </summary>
|
||||
public item.EQuality Quality { get; private set; }
|
||||
/// <summary>
|
||||
/// 道具兑换配置
|
||||
/// </summary>
|
||||
public item.ItemExchange ExchangeStream { get; private set; }
|
||||
@@ -106,7 +101,6 @@ public sealed partial class Item : Bright.Config.BeanBase
|
||||
+ "UpgradeToItemId:" + UpgradeToItemId + ","
|
||||
+ "ExpireTime:" + ExpireTime + ","
|
||||
+ "BatchUseable:" + BatchUseable + ","
|
||||
+ "Quality:" + Quality + ","
|
||||
+ "ExchangeStream:" + ExchangeStream + ","
|
||||
+ "ExchangeList:" + Bright.Common.StringUtil.CollectionToString(ExchangeList) + ","
|
||||
+ "ExchangeColumn:" + ExchangeColumn + ","
|
||||
|
@@ -7,57 +7,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using Bright.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace GameConfig.item
|
||||
{
|
||||
|
||||
public partial class TbItem
|
||||
{
|
||||
private readonly Dictionary<int, item.Item> _dataMap;
|
||||
private readonly List<item.Item> _dataList;
|
||||
|
||||
public TbItem(ByteBuf _buf)
|
||||
public partial class TbItem
|
||||
{
|
||||
_dataMap = new Dictionary<int, item.Item>();
|
||||
_dataList = new List<item.Item>();
|
||||
|
||||
for(int n = _buf.ReadSize() ; n > 0 ; --n)
|
||||
public static TbItem Instance { get; private set; }
|
||||
private bool _readAll = false;
|
||||
private Dictionary<int, item.Item> _dataMap;
|
||||
private List<item.Item> _dataList;
|
||||
public Dictionary<int, item.Item> DataMap
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!_readAll)
|
||||
{
|
||||
ReadAll();
|
||||
_readAll = true;
|
||||
}
|
||||
return _dataMap;
|
||||
}
|
||||
}
|
||||
public List<item.Item> 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 TbItem(ByteBuf _buf, string _tbName, System.Func<string, ByteBuf> _loader)
|
||||
{
|
||||
Instance = this;
|
||||
_dataMap = new Dictionary<int, item.Item>();
|
||||
_dataList = new List<item.Item>();
|
||||
_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 item.Item this[int key] => Get(key);
|
||||
public item.Item Get(int key)
|
||||
{
|
||||
item.Item _v;
|
||||
if(_dataMap.TryGetValue(key, out _v))
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
ResetByteBuf(_indexMap[key]);
|
||||
_v = item.Item.DeserializeItem(_buf);
|
||||
_dataList.Add(_v);
|
||||
_dataMap.Add(_v.Id, _v);
|
||||
_dataMap[_v.Id] = _v;
|
||||
_v.Resolve(tables);
|
||||
if(_indexMap.Count == _dataMap.Count)
|
||||
{
|
||||
_buf = null;
|
||||
}
|
||||
return _v;
|
||||
}
|
||||
PostInit();
|
||||
}
|
||||
|
||||
public Dictionary<int, item.Item> DataMap => _dataMap;
|
||||
public List<item.Item> DataList => _dataList;
|
||||
|
||||
public item.Item GetOrDefault(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;
|
||||
public item.Item Get(int key) => _dataMap[key];
|
||||
public item.Item this[int key] => _dataMap[key];
|
||||
|
||||
public void Resolve(Dictionary<string, object> _tables)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
public item.Item GetOrDefault(int key)
|
||||
{
|
||||
v.Resolve(_tables);
|
||||
if(_indexMap.TryGetValue(key,out var _))
|
||||
{
|
||||
return Get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PostResolve();
|
||||
}
|
||||
|
||||
public void TranslateText(System.Func<string, string, string> translator)
|
||||
{
|
||||
foreach(var v in _dataList)
|
||||
|
||||
private void ResetByteBuf(int readerInex = 0)
|
||||
{
|
||||
v.TranslateText(translator);
|
||||
if( _buf == null)
|
||||
{
|
||||
if (_buf == null)
|
||||
{
|
||||
_buf = _dataLoader();
|
||||
}
|
||||
}
|
||||
_buf.ReaderIndex = readerInex;
|
||||
}
|
||||
}
|
||||
|
||||
partial void PostInit();
|
||||
partial void PostResolve();
|
||||
}
|
||||
|
||||
}
|
||||
private ByteBuf _buf = null;
|
||||
private Dictionary<string, object> tables;
|
||||
public void CacheTables(Dictionary<string, object> _tables)
|
||||
{
|
||||
tables = _tables;
|
||||
}
|
||||
partial void PostInit();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user