diff --git a/Assets/GameScripts/HotFix/GameProto/ConfigLoader.cs b/Assets/GameScripts/HotFix/GameProto/ConfigLoader.cs index 23218d9f..1df552c3 100644 --- a/Assets/GameScripts/HotFix/GameProto/ConfigLoader.cs +++ b/Assets/GameScripts/HotFix/GameProto/ConfigLoader.cs @@ -1,14 +1,11 @@ -using System.Collections.Generic; -using System.Threading; using Bright.Serialization; -using Cysharp.Threading.Tasks; using GameBase; using GameConfig; using TEngine; using UnityEngine; /// -/// 配置加载器 +/// 配置加载器。 /// public class ConfigLoader:Singleton { @@ -22,84 +19,46 @@ public class ConfigLoader:Singleton { if (!_init) { - Log.Error("Config not loaded. You need Take LoadAsync at first."); + Load(); } return _tables; } } - - private readonly Dictionary _configs = new Dictionary(); - + /// - /// 异步加载配置。 + /// 加载配置。 /// - public async UniTask LoadAsync() + public void Load() { - _tables = new Tables(); - await _tables.LoadAsync(LoadByteBufAsync); + _tables = new Tables(LoadByteBuf); _init = true; } /// - /// 异步加载二进制配置。 + /// 加载二进制配置。 /// /// FileName /// ByteBuf - private async UniTask LoadByteBufAsync(string file) + private ByteBuf LoadByteBuf(string file) { -#if false - GameTickWatcher gameTickWatcher = new GameTickWatcher(); -#endif - byte[] ret; - var location = file; - if (_configs.TryGetValue(location, out var config)) - { - ret = config.bytes; - } - else - { - var textAssets = await GameModule.Resource.LoadAssetAsync(location,CancellationToken.None); - ret = textAssets.bytes; - RegisterTextAssets(file, textAssets); - } -#if false - Log.Warning($"LoadByteBuf {file} used time {gameTickWatcher.ElapseTime()}"); -#endif + var textAssets = GameModule.Resource.LoadAsset($"{SettingsUtils.FrameworkGlobalSettings.ConfigFolderName}{file}.bytes"); + byte[] ret = textAssets.bytes; return new ByteBuf(ret); } - - /// - /// 注册配置资源。 - /// - /// 资源Key。 - /// 资源实例。 - /// 注册成功。 - private bool RegisterTextAssets(string key, TextAsset value) - { - if (string.IsNullOrEmpty(key)) - { - return false; - } - - if (value == null) - { - return false; - } - _configs[key] = value; - return true; - } } public class ConfigSystem : BaseLogicSys { public override bool OnInit() { - InitConfig().Forget(); + Log.Warning("ConfigSystem OnInit"); + InitConfig(); return base.OnInit(); } - private async UniTaskVoid InitConfig() + private void InitConfig() { - await ConfigLoader.Instance.LoadAsync(); + ConfigLoader.Instance.Load(); } -} \ No newline at end of file +} + diff --git a/Assets/GameScripts/HotFix/GameProto/GameConfig/Tables.cs b/Assets/GameScripts/HotFix/GameProto/GameConfig/Tables.cs index 1c6bfd48..fc20ad45 100644 --- a/Assets/GameScripts/HotFix/GameProto/GameConfig/Tables.cs +++ b/Assets/GameScripts/HotFix/GameProto/GameConfig/Tables.cs @@ -6,53 +6,36 @@ // //------------------------------------------------------------------------------ using Bright.Serialization; -using Cysharp.Threading.Tasks; -using System.Collections.Generic; + namespace GameConfig +{ +public partial class Tables { - -public sealed class Tables -{ - public item.TbItem TbItem {get; private set; } - public Battle.TbSkill TbSkill {get; private set; } - public Battle.TbBuff TbBuff {get; private set; } - public Battle.TbBuffAttr TbBuffAttr {get; private set; } + public item.TbItem TbItem {get; } + public Battle.TbSkill TbSkill {get; } + public Battle.TbBuff TbBuff {get; } + public Battle.TbBuffAttr TbBuffAttr {get; } - public Tables() { } - - public async UniTask LoadAsync(System.Func> loader) + public Tables(System.Func loader) { var tables = new System.Collections.Generic.Dictionary(); - List list = new List(); - list.Add(UniTask.Create(async () => - { - TbItem = new item.TbItem(await loader("item_tbitem")); - tables.Add("item.TbItem", TbItem); - })); - list.Add(UniTask.Create(async () => - { - TbSkill = new Battle.TbSkill(await loader("battle_tbskill")); - tables.Add("Battle.TbSkill", TbSkill); - })); - list.Add(UniTask.Create(async () => - { - TbBuff = new Battle.TbBuff(await loader("battle_tbbuff")); - tables.Add("Battle.TbBuff", TbBuff); - })); - list.Add(UniTask.Create(async () => - { - TbBuffAttr = new Battle.TbBuffAttr(await loader("battle_tbbuffattr")); - tables.Add("Battle.TbBuffAttr", TbBuffAttr); - })); - - await UniTask.WhenAll(list); + TbItem = new item.TbItem(loader("item_tbitem")); + tables.Add("item.TbItem", TbItem); + TbSkill = new Battle.TbSkill(loader("battle_tbskill")); + tables.Add("Battle.TbSkill", TbSkill); + TbBuff = new Battle.TbBuff(loader("battle_tbbuff")); + tables.Add("Battle.TbBuff", TbBuff); + TbBuffAttr = new Battle.TbBuffAttr(loader("battle_tbbuffattr")); + tables.Add("Battle.TbBuffAttr", TbBuffAttr); + PostInit(); TbItem.Resolve(tables); TbSkill.Resolve(tables); TbBuff.Resolve(tables); TbBuffAttr.Resolve(tables); + PostResolve(); } public void TranslateText(System.Func translator) @@ -62,6 +45,9 @@ public sealed class Tables TbBuff.TranslateText(translator); TbBuffAttr.TranslateText(translator); } + + partial void PostInit(); + partial void PostResolve(); } } \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameProto/GameConfig/item/Item.cs b/Assets/GameScripts/HotFix/GameProto/GameConfig/item/Item.cs index 6a313ae5..11d2813a 100644 --- a/Assets/GameScripts/HotFix/GameProto/GameConfig/item/Item.cs +++ b/Assets/GameScripts/HotFix/GameProto/GameConfig/item/Item.cs @@ -22,6 +22,7 @@ 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(n0);for(var i0 = 0 ; i0 < n0 ; i0++) { item.ItemExchange _e0; _e0 = item.ItemExchange.DeserializeItemExchange(_buf); ExchangeList.Add(_e0);}} ExchangeColumn = item.ItemExchange.DeserializeItemExchange(_buf); @@ -63,6 +64,10 @@ public sealed partial class Item : Bright.Config.BeanBase /// public bool BatchUseable { get; private set; } /// + /// 品质 + /// + public item.EQuality Quality { get; private set; } + /// /// 道具兑换配置 /// public item.ItemExchange ExchangeStream { get; private set; } @@ -101,6 +106,7 @@ 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 + "," diff --git a/Luban/CustomTemplate_Client/ConfigLoader.cs b/Luban/CustomTemplate_Client/ConfigLoader.cs new file mode 100644 index 00000000..1df552c3 --- /dev/null +++ b/Luban/CustomTemplate_Client/ConfigLoader.cs @@ -0,0 +1,64 @@ +using Bright.Serialization; +using GameBase; +using GameConfig; +using TEngine; +using UnityEngine; + +/// +/// 配置加载器。 +/// +public class ConfigLoader:Singleton +{ + private bool _init = false; + + private Tables _tables; + + public Tables Tables + { + get + { + if (!_init) + { + Load(); + } + return _tables; + } + } + + /// + /// 加载配置。 + /// + public void Load() + { + _tables = new Tables(LoadByteBuf); + _init = true; + } + + /// + /// 加载二进制配置。 + /// + /// FileName + /// ByteBuf + private ByteBuf LoadByteBuf(string file) + { + var textAssets = GameModule.Resource.LoadAsset($"{SettingsUtils.FrameworkGlobalSettings.ConfigFolderName}{file}.bytes"); + byte[] ret = textAssets.bytes; + return new ByteBuf(ret); + } +} + +public class ConfigSystem : BaseLogicSys +{ + public override bool OnInit() + { + Log.Warning("ConfigSystem OnInit"); + InitConfig(); + return base.OnInit(); + } + + private void InitConfig() + { + ConfigLoader.Instance.Load(); + } +} + diff --git a/Luban/CustomTemplate_Client_UniTask/ConfigLoader.cs b/Luban/CustomTemplate_Client_UniTask/ConfigLoader.cs new file mode 100644 index 00000000..0a52cfe1 --- /dev/null +++ b/Luban/CustomTemplate_Client_UniTask/ConfigLoader.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.Threading; +using Bright.Serialization; +using Cysharp.Threading.Tasks; +using GameBase; +using GameConfig; +using TEngine; +using UnityEngine; + +/// +/// 配置加载器 +/// +public class ConfigLoader:Singleton +{ + private bool _init = false; + + private Tables _tables; + + public Tables Tables + { + get + { + if (!_init) + { +#if !UNITY_WEBGL + _init = true; + +#endif + Log.Error("Config not loaded. You need Take LoadAsync at first."); + } + return _tables; + } + } + + private readonly Dictionary _configs = new Dictionary(); + + /// + /// 异步加载配置。 + /// + public async UniTask LoadAsync() + { + _tables = new Tables(); + await _tables.LoadAsync(LoadByteBufAsync); + _init = true; + } + + /// + /// 异步加载二进制配置。 + /// + /// FileName + /// ByteBuf + private async UniTask LoadByteBufAsync(string file) + { +#if false + GameTickWatcher gameTickWatcher = new GameTickWatcher(); +#endif + byte[] ret; + var location = file; + if (_configs.TryGetValue(location, out var config)) + { + ret = config.bytes; + } + else + { + var textAssets = await GameModule.Resource.LoadAssetAsync(location,CancellationToken.None); + ret = textAssets.bytes; + RegisterTextAssets(file, textAssets); + } +#if false + Log.Warning($"LoadByteBuf {file} used time {gameTickWatcher.ElapseTime()}"); +#endif + return new ByteBuf(ret); + } + + /// + /// 注册配置资源。 + /// + /// 资源Key。 + /// 资源实例。 + /// 注册成功。 + private bool RegisterTextAssets(string key, TextAsset value) + { + if (string.IsNullOrEmpty(key)) + { + return false; + } + + if (value == null) + { + return false; + } + _configs[key] = value; + return true; + } +} + +public class ConfigSystem : BaseLogicSys +{ + public override bool OnInit() + { + Log.Warning("ConfigSystem OnInit"); + InitConfig().Forget(); + return base.OnInit(); + } + + private async UniTaskVoid InitConfig() + { + await ConfigLoader.Instance.LoadAsync(); + } +} \ No newline at end of file diff --git a/Luban/CustomTemplate/config/cs_bin/bean.tpl b/Luban/CustomTemplate_Client_UniTask/config/cs_bin/bean.tpl similarity index 100% rename from Luban/CustomTemplate/config/cs_bin/bean.tpl rename to Luban/CustomTemplate_Client_UniTask/config/cs_bin/bean.tpl diff --git a/Luban/CustomTemplate/config/cs_bin/table.tpl b/Luban/CustomTemplate_Client_UniTask/config/cs_bin/table.tpl similarity index 100% rename from Luban/CustomTemplate/config/cs_bin/table.tpl rename to Luban/CustomTemplate_Client_UniTask/config/cs_bin/table.tpl diff --git a/Luban/CustomTemplate/config/cs_bin/tables.tpl b/Luban/CustomTemplate_Client_UniTask/config/cs_bin/tables.tpl similarity index 100% rename from Luban/CustomTemplate/config/cs_bin/tables.tpl rename to Luban/CustomTemplate_Client_UniTask/config/cs_bin/tables.tpl diff --git a/Luban/CustomTemplate_Server_Task/config/cs_bin/bean.tpl b/Luban/CustomTemplate_Server_Task/config/cs_bin/bean.tpl new file mode 100644 index 00000000..7ce5006e --- /dev/null +++ b/Luban/CustomTemplate_Server_Task/config/cs_bin/bean.tpl @@ -0,0 +1,115 @@ +using Bright.Serialization; +using System.Collections.Generic; +{{ + name = x.name + parent_def_type = x.parent_def_type + export_fields = x.export_fields + hierarchy_export_fields = x.hierarchy_export_fields +}} + +{{cs_start_name_space_grace x.namespace_with_top_module}} +{{~if x.comment != '' ~}} +/// +/// {{x.escape_comment}} +/// +{{~end~}} +public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} Bright.Config.BeanBase {{end}} +{ + public {{name}}(ByteBuf _buf) {{if parent_def_type}} : base(_buf) {{end}} + { + {{~ for field in export_fields ~}} + {{cs_deserialize '_buf' field.convention_name field.ctype}} + {{~if field.index_field~}} + foreach(var _v in {{field.convention_name}}) + { + {{field.convention_name}}_Index.Add(_v.{{field.index_field.convention_name}}, _v); + } + {{~end~}} + {{~end~}} + PostInit(); + } + + public static {{name}} Deserialize{{name}}(ByteBuf _buf) + { + {{~if x.is_abstract_type~}} + switch (_buf.ReadInt()) + { + {{~for child in x.hierarchy_not_abstract_children~}} + case {{child.full_name}}.__ID__: return new {{child.full_name}}(_buf); + {{~end~}} + default: throw new SerializationException(); + } + {{~else~}} + return new {{x.full_name}}(_buf); + {{~end~}} + } + + {{~ for field in export_fields ~}} +{{~if field.comment != '' ~}} + /// + /// {{field.escape_comment}} + /// +{{~end~}} + public {{cs_define_type field.ctype}} {{field.convention_name}} { get; private set; } + {{~if field.index_field~}} + public readonly Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}> {{field.convention_name}}_Index = new Dictionary<{{cs_define_type field.index_field.ctype}}, {{cs_define_type field.ctype.element_type}}>(); + {{~end~}} + {{~if field.gen_ref~}} + public {{field.cs_ref_validator_define}} + {{~end~}} + {{~if (gen_datetime_mills field.ctype) ~}} + public long {{field.convention_name}}_Millis => {{field.convention_name}} * 1000L; + {{~end~}} + {{~if field.gen_text_key~}} + public {{cs_define_text_key_field field}} { get; } + {{~end~}} + {{~end~}} + +{{~if !x.is_abstract_type~}} + public const int __ID__ = {{x.id}}; + public override int GetTypeId() => __ID__; +{{~end~}} + + public {{x.cs_method_modifier}} void Resolve(Dictionary _tables) + { + {{~if parent_def_type~}} + base.Resolve(_tables); + {{~end~}} + {{~ for field in export_fields ~}} + {{~if field.gen_ref~}} + {{cs_ref_validator_resolve field}} + {{~else if field.has_recursive_ref~}} + {{cs_recursive_resolve field '_tables'}} + {{~end~}} + {{~end~}} + PostResolve(); + } + + public {{x.cs_method_modifier}} void TranslateText(System.Func translator) + { + {{~if parent_def_type~}} + base.TranslateText(translator); + {{~end~}} + {{~ for field in export_fields ~}} + {{~if field.gen_text_key~}} + {{cs_translate_text field 'translator'}} + {{~else if field.has_recursive_text~}} + {{cs_recursive_translate_text field 'translator'}} + {{~end~}} + {{~end~}} + } + + public override string ToString() + { + return "{{full_name}}{ " + {{~for field in hierarchy_export_fields ~}} + + "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + "," + {{~end~}} + + "}"; + } + + partial void PostInit(); + partial void PostResolve(); +} + +{{cs_end_name_space_grace x.namespace_with_top_module}} \ No newline at end of file diff --git a/Luban/CustomTemplate_Server_Task/config/cs_bin/table.tpl b/Luban/CustomTemplate_Server_Task/config/cs_bin/table.tpl new file mode 100644 index 00000000..516c1764 --- /dev/null +++ b/Luban/CustomTemplate_Server_Task/config/cs_bin/table.tpl @@ -0,0 +1,173 @@ +using Bright.Serialization; +using System.Collections.Generic; + + +{{cs_start_name_space_grace x.namespace_with_top_module}} + {{ + name = x.name + key_type = x.key_ttype + key_type1 = x.key_ttype1 + key_type2 = x.key_ttype2 + value_type = x.value_ttype + }} +{{~if x.comment != '' ~}} +/// +/// {{x.escape_comment}} +/// +{{~end~}} +public partial class {{name}} +{ + {{~if x.is_map_table ~}} + private readonly Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> _dataMap; + private readonly List<{{cs_define_type value_type}}> _dataList; + + public {{name}}(ByteBuf _buf) + { + _dataMap = new Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}>(); + _dataList = new List<{{cs_define_type value_type}}>(); + + for(int n = _buf.ReadSize() ; n > 0 ; --n) + { + {{cs_define_type value_type}} _v; + {{cs_deserialize '_buf' '_v' value_type}} + _dataList.Add(_v); + _dataMap.Add(_v.{{x.index_field.convention_name}}, _v); + } + PostInit(); + } + + public Dictionary<{{cs_define_type key_type}}, {{cs_define_type value_type}}> DataMap => _dataMap; + public List<{{cs_define_type value_type}}> DataList => _dataList; + +{{~if value_type.is_dynamic~}} + public T GetOrDefaultAs({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => _dataMap.TryGetValue(key, out var v) ? (T)v : null; + public T GetAs({{cs_define_type key_type}} key) where T : {{cs_define_type value_type}} => (T)_dataMap[key]; +{{~end~}} + public {{cs_define_type value_type}} GetOrDefault({{cs_define_type key_type}} key) => _dataMap.TryGetValue(key, out var v) ? v : null; + public {{cs_define_type value_type}} Get({{cs_define_type key_type}} key) => _dataMap[key]; + public {{cs_define_type value_type}} this[{{cs_define_type key_type}} key] => _dataMap[key]; + + public void Resolve(Dictionary _tables) + { + foreach(var v in _dataList) + { + v.Resolve(_tables); + } + PostResolve(); + } + + public void TranslateText(System.Func translator) + { + foreach(var v in _dataList) + { + v.TranslateText(translator); + } + } + {{~else if x.is_list_table ~}} + private readonly List<{{cs_define_type value_type}}> _dataList; + + {{~if x.is_union_index~}} + private {{cs_table_union_map_type_name x}} _dataMapUnion; + {{~else if !x.index_list.empty?~}} + {{~for idx in x.index_list~}} + private Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}> _dataMap_{{idx.index_field.name}}; + {{~end~}} + {{~end~}} + + public {{name}}(ByteBuf _buf) + { + _dataList = new List<{{cs_define_type value_type}}>(); + + for(int n = _buf.ReadSize() ; n > 0 ; --n) + { + {{cs_define_type value_type}} _v; + {{cs_deserialize '_buf' '_v' value_type}} + _dataList.Add(_v); + } + {{~if x.is_union_index~}} + _dataMapUnion = new {{cs_table_union_map_type_name x}}(); + foreach(var _v in _dataList) + { + _dataMapUnion.Add(({{cs_table_key_list x "_v"}}), _v); + } + {{~else if !x.index_list.empty?~}} + {{~for idx in x.index_list~}} + _dataMap_{{idx.index_field.name}} = new Dictionary<{{cs_define_type idx.type}}, {{cs_define_type value_type}}>(); + {{~end~}} + foreach(var _v in _dataList) + { + {{~for idx in x.index_list~}} + _dataMap_{{idx.index_field.name}}.Add(_v.{{idx.index_field.convention_name}}, _v); + {{~end~}} + } + {{~end~}} + PostInit(); + } + + + public List<{{cs_define_type value_type}}> DataList => _dataList; + + {{~if x.is_union_index~}} + public {{cs_define_type value_type}} Get({{cs_table_get_param_def_list x}}) => _dataMapUnion.TryGetValue(({{cs_table_get_param_name_list x}}), out {{cs_define_type value_type}} __v) ? __v : null; + {{~else if !x.index_list.empty? ~}} + {{~for idx in x.index_list~}} + public {{cs_define_type value_type}} GetBy{{idx.index_field.convention_name}}({{cs_define_type idx.type}} key) => _dataMap_{{idx.index_field.name}}.TryGetValue(key, out {{cs_define_type value_type}} __v) ? __v : null; + {{~end~}} + {{~end~}} + + public void Resolve(Dictionary _tables) + { + foreach(var v in _dataList) + { + v.Resolve(_tables); + } + PostResolve(); + } + + public void TranslateText(System.Func translator) + { + foreach(var v in _dataList) + { + v.TranslateText(translator); + } + } + {{~else~}} + + private readonly {{cs_define_type value_type}} _data; + + public {{name}}(ByteBuf _buf) + { + int n = _buf.ReadSize(); + if (n != 1) throw new SerializationException("table mode=one, but size != 1"); + {{cs_deserialize '_buf' '_data' value_type}} + PostInit(); + } + + + {{~ for field in value_type.bean.hierarchy_export_fields ~}} +{{~if field.comment != '' ~}} + /// + /// {{field.escape_comment}} + /// +{{~end~}} + public {{cs_define_type field.ctype}} {{field.convention_name}} => _data.{{field.convention_name}}; + {{~end~}} + + public void Resolve(Dictionary _tables) + { + _data.Resolve(_tables); + PostResolve(); + } + + public void TranslateText(System.Func translator) + { + _data.TranslateText(translator); + } + + {{~end~}} + + partial void PostInit(); + partial void PostResolve(); +} + +{{cs_end_name_space_grace x.namespace_with_top_module}} \ No newline at end of file diff --git a/Luban/CustomTemplate_Server_Task/config/cs_bin/tables.tpl b/Luban/CustomTemplate_Server_Task/config/cs_bin/tables.tpl new file mode 100644 index 00000000..4b638b1a --- /dev/null +++ b/Luban/CustomTemplate_Server_Task/config/cs_bin/tables.tpl @@ -0,0 +1,46 @@ +using Bright.Serialization; +using System.Threading.Tasks; + +{{ + name = x.name + namespace = x.namespace + tables = x.tables +}} +namespace {{namespace}} +{ + +public sealed class {{name}} +{ + {{~for table in tables ~}} +{{~if table.comment != '' ~}} + /// + /// {{table.escape_comment}} + /// +{{~end~}} + public {{table.full_name}} {{table.name}} {get; private set; } + {{~end~}} + + public {{name}}() { } + + public async Task LoadAsync(System.Func> loader) + { + var tables = new System.Collections.Generic.Dictionary(); + {{~for table in tables ~}} + {{table.name}} = new {{table.full_name}}(await loader("{{table.output_data_file}}")); + tables.Add("{{table.full_name}}", {{table.name}}); + {{~end~}} + + {{~for table in tables ~}} + {{table.name}}.Resolve(tables); + {{~end~}} + } + + public void TranslateText(System.Func translator) + { + {{~for table in tables ~}} + {{table.name}}.TranslateText(translator); + {{~end~}} + } +} + +} \ No newline at end of file diff --git a/Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl b/Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl index 4b638b1a..0ab51ba5 100644 --- a/Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl +++ b/Luban/Luban.ClientServer/Templates/config/cs_bin/tables.tpl @@ -1,15 +1,14 @@ using Bright.Serialization; -using System.Threading.Tasks; {{ name = x.name namespace = x.namespace tables = x.tables + }} -namespace {{namespace}} -{ - -public sealed class {{name}} + +{{cs_start_name_space_grace x.namespace}} +public partial class {{name}} { {{~for table in tables ~}} {{~if table.comment != '' ~}} @@ -17,22 +16,22 @@ public sealed class {{name}} /// {{table.escape_comment}} /// {{~end~}} - public {{table.full_name}} {{table.name}} {get; private set; } + public {{table.full_name}} {{table.name}} {get; } {{~end~}} - public {{name}}() { } - - public async Task LoadAsync(System.Func> loader) + public {{name}}(System.Func loader) { var tables = new System.Collections.Generic.Dictionary(); {{~for table in tables ~}} - {{table.name}} = new {{table.full_name}}(await loader("{{table.output_data_file}}")); + {{table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}")); tables.Add("{{table.full_name}}", {{table.name}}); {{~end~}} + PostInit(); {{~for table in tables ~}} {{table.name}}.Resolve(tables); {{~end~}} + PostResolve(); } public void TranslateText(System.Func translator) @@ -41,6 +40,9 @@ public sealed class {{name}} {{table.name}}.TranslateText(translator); {{~end~}} } + + partial void PostInit(); + partial void PostResolve(); } -} \ No newline at end of file +{{cs_end_name_space_grace x.namespace}} \ No newline at end of file diff --git a/Luban/gen_code_bin_to_project.bat b/Luban/gen_code_bin_to_project.bat index 92dd7669..c596c670 100644 --- a/Luban/gen_code_bin_to_project.bat +++ b/Luban/gen_code_bin_to_project.bat @@ -4,14 +4,17 @@ set WORKSPACE=.. set GEN_CLIENT=%WORKSPACE%\Luban\Luban.ClientServer\Luban.ClientServer.exe set CONF_ROOT=%WORKSPACE%\Luban\Config set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas +set CUSTOM_TEMP=%WORKSPACE%\Luban\CustomTemplate_Client -%GEN_CLIENT% --template_search_path CustomTemplate -j cfg --^ +xcopy %CUSTOM_TEMP%\ConfigLoader.cs %WORKSPACE%\Assets\GameScripts\HotFix\GameProto\\ConfigLoader.cs /s /e /i /y + +%GEN_CLIENT% -j cfg --^ -d %CONF_ROOT%\Defines\__root__.xml ^ --input_data_dir %CONF_ROOT%\Datas ^ --output_code_dir %WORKSPACE%/Assets/GameScripts/HotFix/GameProto/GameConfig ^ - --output_data_dir %WORKSPACE%/Assets/AssetRaw/Configs/bytes/ ^ + --output_data_dir ..\GenerateDatas\bytes ^ --gen_types code_cs_unity_bin,data_bin ^ - -s client + -s all echo ======== 生成配置文件结束 ======== diff --git a/Luban/gen_code_bin_to_project_unitask.bat b/Luban/gen_code_bin_to_project_unitask.bat new file mode 100644 index 00000000..7d97ccfd --- /dev/null +++ b/Luban/gen_code_bin_to_project_unitask.bat @@ -0,0 +1,21 @@ +cd /d %~dp0 +set WORKSPACE=.. + +set GEN_CLIENT=%WORKSPACE%\Luban\Luban.ClientServer\Luban.ClientServer.exe +set CONF_ROOT=%WORKSPACE%\Luban\Config +set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas +set CUSTOM_TEMP=%WORKSPACE%\Luban\CustomTemplate_Client_UniTask + +xcopy %CUSTOM_TEMP%\ConfigLoader.cs %WORKSPACE%\Assets\GameScripts\HotFix\GameProto\\ConfigLoader.cs /s /e /i /y + +%GEN_CLIENT% --template_search_path CustomTemplate_Client_UniTask -j cfg --^ + -d %CONF_ROOT%\Defines\__root__.xml ^ + --input_data_dir %CONF_ROOT%\Datas ^ + --output_code_dir %WORKSPACE%/Assets/GameScripts/HotFix/GameProto/GameConfig ^ + --output_data_dir %WORKSPACE%/Assets/AssetRaw/Configs/bytes/ ^ + --gen_types code_cs_unity_bin,data_bin ^ + -s client + +echo ======== 生成配置文件结束 ======== + +pause \ No newline at end of file diff --git a/Luban/gen_code_bin_to_server.bat b/Luban/gen_code_bin_to_server.bat index 1208fdb7..a878f52e 100644 --- a/Luban/gen_code_bin_to_server.bat +++ b/Luban/gen_code_bin_to_server.bat @@ -5,7 +5,7 @@ set GEN_CLIENT=%WORKSPACE%\Luban\Luban.ClientServer\Luban.ClientServer.exe set CONF_ROOT=%WORKSPACE%\Luban\Config set DATA_OUTPUT=%ROOT_PATH%..\GenerateDatas -%GEN_CLIENT% -j cfg --^ +%GEN_CLIENT% --template_search_path CustomTemplate_Server_Task -j cfg --^ -d %CONF_ROOT%\Defines\__root__.xml ^ --input_data_dir %CONF_ROOT%\Datas ^ --output_code_dir %WORKSPACE%/DotNet/Logic/src/Config/GameConfig ^