AlicizaX/Config/Tools/Templates/cs-bin/tables.sbn
陈思海 eb38f67131 init
2025-01-23 19:06:48 +08:00

89 lines
2.9 KiB
Plaintext

using System;
using Luban;
using AlicizaX.Config.Runtime;
{{namespace_with_grace_begin __namespace}}
public partial class {{__name}}
{
{{~for table in __tables ~}}
{{~if table.comment != '' ~}}
/// <summary>
/// {{escape_comment table.comment}}
/// </summary>
{{~end~}}
internal {{table.full_name}} {{format_property_name __code_style table.name}} { private set; get; }
{{~end~}}
private ConfigComponent m_ConfigComponent;
public void Init(ConfigComponent configComponent)
{
m_ConfigComponent = configComponent;
configComponent.RemoveAllConfigs();
}
/// <summary>
/// 是否加载完成
/// </summary>
public bool IsLoaded { get; private set; }
/// <summary>
/// 异步加载配置文件
/// </summary>
/// <param name="loader">加载器</param>
public async System.Threading.Tasks.Task LoadAsync(System.Func<string, System.Threading.Tasks.Task<ByteBuf>> loader)
{
if (IsLoaded)
{
return;
}
IsLoaded = false;
m_ConfigComponent.RemoveAllConfigs();
var loadTasks = new System.Collections.Generic.List<System.Threading.Tasks.Task>();
{{~for table in __tables ~}}
{{format_property_name __code_style table.name}} = new {{table.full_name}}(() => loader("{{table.output_data_file}}"));
loadTasks.Add({{format_property_name __code_style table.name}}.LoadAsync());
m_ConfigComponent.Add(nameof({{table.full_name}}), {{format_property_name __code_style table.name}});
{{~end~}}
await System.Threading.Tasks.Task.WhenAll(loadTasks);
Refresh();
IsLoaded = true;
}
/// <summary>
/// 设置本地化的适配器
/// </summary>
/// <param name="translator">适配器对象</param>
/// <exception cref="InvalidOperationException">如果未加载完成将抛出此异常</exception>
public void SetTranslateText(System.Func<string, string, string> translator)
{
if (IsLoaded == false)
{
throw new InvalidOperationException("Table is not loaded!");
}
{{~for table in __tables ~}}
{{format_property_name __code_style table.name}}.TranslateText(translator);
{{~end~}}
}
private void ResolveRef()
{
{{~for table in __tables ~}}
{{format_property_name __code_style table.name}}.ResolveRef(this);
{{~end~}}
PostResolveRef();
}
public void Refresh()
{
PostInit();
ResolveRef();
}
partial void PostInit();
partial void PostResolveRef();
}
{{namespace_with_grace_end __namespace}}