【特性】新增gen_types类型 data_template 以及新增配套参数--template_name,用于模板生成自定义格式的配置数据
parent
2fde2a481e
commit
434d52ed8d
|
|
@ -21,9 +21,12 @@ namespace Luban.Job.Cfg
|
||||||
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
[Option("output_data_json_monolithic_file", Required = false, HelpText = "output monolithic json file")]
|
||||||
public string OutputDataJsonMonolithicFile { get; set; }
|
public string OutputDataJsonMonolithicFile { get; set; }
|
||||||
|
|
||||||
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_resources . can be multi")]
|
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_json,code_cs_unity_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_resources,data_template . can be multi")]
|
||||||
public string GenType { get; set; }
|
public string GenType { get; set; }
|
||||||
|
|
||||||
|
[Option("template_name", Required = false, HelpText = "template name. use with gen_types=data_template")]
|
||||||
|
public string TemplateName { get; set; }
|
||||||
|
|
||||||
[Option('s', "service", Required = true, HelpText = "service")]
|
[Option('s', "service", Required = true, HelpText = "service")]
|
||||||
public string Service { get; set; }
|
public string Service { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
using Luban.Common.Protos;
|
||||||
|
using Luban.Job.Cfg.Cache;
|
||||||
|
using Luban.Job.Cfg.Utils;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.Generate
|
||||||
|
{
|
||||||
|
[Render("data_template")]
|
||||||
|
class TemplateDataScatterRender : DataRenderBase
|
||||||
|
{
|
||||||
|
public override void Render(GenContext ctx)
|
||||||
|
{
|
||||||
|
string genType = ctx.GenArgs.TemplateName;
|
||||||
|
foreach (var table in ctx.ExportTables)
|
||||||
|
{
|
||||||
|
ctx.Tasks.Add(Task.Run(() =>
|
||||||
|
{
|
||||||
|
var file = RenderFileUtil.GetOutputFileName(genType, table.OutputDataFile);
|
||||||
|
var records = ctx.Assembly.GetTableExportDataList(table);
|
||||||
|
if (!FileRecordCacheManager.Ins.TryGetRecordOutputData(table, records, genType, out string md5))
|
||||||
|
{
|
||||||
|
var content = DataExporterUtil.ToTemplateOutputData(table, records, genType);
|
||||||
|
md5 = CacheFileUtil.GenStringOrBytesMd5AndAddCache(file, content);
|
||||||
|
FileRecordCacheManager.Ins.AddCachedRecordOutputData(table, records, genType, md5);
|
||||||
|
}
|
||||||
|
ctx.GenDataFilesInOutputDataDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -87,6 +87,11 @@ namespace Luban.Job.Cfg
|
||||||
errMsg = "--input_l10n_text_files must be provided with --output_l10n_not_translated_text_file";
|
errMsg = "--input_l10n_text_files must be provided with --output_l10n_not_translated_text_file";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (genTypes.Contains("data_template") ^ !string.IsNullOrWhiteSpace(options.TemplateName))
|
||||||
|
{
|
||||||
|
errMsg = "gen_types data_template should use with --template_name";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(options.BranchName) ^ string.IsNullOrWhiteSpace(options.BranchInputDataDir))
|
if (string.IsNullOrWhiteSpace(options.BranchName) ^ string.IsNullOrWhiteSpace(options.BranchInputDataDir))
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,14 @@ namespace Luban.Job.Cfg.Utils
|
||||||
{
|
{
|
||||||
public static class DataExporterUtil
|
public static class DataExporterUtil
|
||||||
{
|
{
|
||||||
|
public static string ToTemplateOutputData(DefTable table, List<Record> records, string templateName)
|
||||||
|
{
|
||||||
|
Template template = StringTemplateUtil.GetTemplate($"config/data/{templateName}");
|
||||||
|
return template.RenderData(table, records.Select(r => r.Data).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
public static object ToOutputData(DefTable table, List<Record> records, string dataType)
|
public static object ToOutputData(DefTable table, List<Record> records, string dataType)
|
||||||
{
|
{
|
||||||
if (StringTemplateUtil.TryGetTemplate($"config/data/{dataType[5..]}", out Template template))
|
|
||||||
{
|
|
||||||
return template.RenderData(table, records.Select(r => r.Data).ToList());
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (dataType)
|
switch (dataType)
|
||||||
{
|
{
|
||||||
case "data_bin":
|
case "data_bin":
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Luban.Job.Common.Utils
|
||||||
|
|
||||||
public static string GetOutputFileName(string genType, string fileName)
|
public static string GetOutputFileName(string genType, string fileName)
|
||||||
{
|
{
|
||||||
return $"{(genType.EndsWith("lua") ? fileName.Replace('.', '_') : fileName)}.{GetOutputFileSuffix(genType)}";
|
return $"{(genType.Contains("lua") ? fileName.Replace('.', '_') : fileName)}.{GetOutputFileSuffix(genType)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue