【调整】合并data_json2和data_json格式,统一为data_json但使用data_json2的格式

【修复】修复 生成的data_json_monolithic json文件中,表名错误地使用了bool值的bug
main
walon 2021-08-20 17:56:49 +08:00
parent bea3edf0ca
commit 15d1e0b07e
4 changed files with 137 additions and 31 deletions

View File

@ -21,19 +21,6 @@ namespace Luban.Job.Cfg.DataExporters
x.WriteEndArray(); x.WriteEndArray();
} }
public string ToStringValue(DType data)
{
switch (data)
{
case DInt dint: return dint.Value.ToString();
case DLong dlong: return dlong.Value.ToString();
case DString dstring: return dstring.Value;
case DEnum denum: return denum.Value.ToString();
case DShort dshort: return dshort.Value.ToString();
default: throw new NotSupportedException($"data_json2 not support key type:{data.GetType().Name}");
}
}
public void WriteAsObject(DefTable table, List<Record> datas, DefAssembly ass, Utf8JsonWriter x) public void WriteAsObject(DefTable table, List<Record> datas, DefAssembly ass, Utf8JsonWriter x)
{ {
switch (table.Mode) switch (table.Mode)
@ -52,7 +39,7 @@ namespace Luban.Job.Cfg.DataExporters
{ {
var indexFieldData = rec.Data.GetField(indexName); var indexFieldData = rec.Data.GetField(indexName);
x.WritePropertyName(ToStringValue(indexFieldData)); x.WritePropertyName(indexFieldData.Apply(ToJsonPropertyNameVisitor.Ins));
this.Accept(rec.Data, ass, x); this.Accept(rec.Data, ass, x);
} }

View File

@ -0,0 +1,129 @@
using Luban.Job.Cfg.Datas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Cfg.DataVisitors
{
class ToJsonPropertyNameVisitor : IDataFuncVisitor<string>
{
public static ToJsonPropertyNameVisitor Ins { get; } = new();
public string Accept(DBool type)
{
throw new NotSupportedException();
}
public string Accept(DByte type)
{
return type.Value.ToString();
}
public string Accept(DShort type)
{
return type.Value.ToString();
}
public string Accept(DFshort type)
{
return type.Value.ToString();
}
public string Accept(DInt type)
{
return type.Value.ToString();
}
public string Accept(DFint type)
{
return type.Value.ToString();
}
public string Accept(DLong type)
{
return type.Value.ToString();
}
public string Accept(DFlong type)
{
return type.Value.ToString();
}
public string Accept(DFloat type)
{
throw new NotSupportedException();
}
public string Accept(DDouble type)
{
throw new NotSupportedException();
}
public string Accept(DEnum type)
{
return type.Value.ToString();
}
public string Accept(DString type)
{
return type.Value.ToString();
}
public string Accept(DBytes type)
{
throw new NotSupportedException();
}
public string Accept(DText type)
{
throw new NotSupportedException();
}
public string Accept(DBean type)
{
throw new NotSupportedException();
}
public string Accept(DArray type)
{
throw new NotSupportedException();
}
public string Accept(DList type)
{
throw new NotSupportedException();
}
public string Accept(DSet type)
{
throw new NotSupportedException();
}
public string Accept(DMap type)
{
throw new NotSupportedException();
}
public string Accept(DVector2 type)
{
throw new NotSupportedException();
}
public string Accept(DVector3 type)
{
throw new NotSupportedException();
}
public string Accept(DVector4 type)
{
throw new NotSupportedException();
}
public string Accept(DDateTime type)
{
throw new NotSupportedException();
}
}
}

View File

@ -46,7 +46,7 @@ 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_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 . 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_go_bin,code_go_json,code_cpp_bin,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json_monolithic,data_resources . can be multi")]
public string GenType { get; set; } public string GenType { get; set; }
[Option('s', "service", Required = true, HelpText = "service")] [Option('s', "service", Required = true, HelpText = "service")]
@ -126,8 +126,7 @@ namespace Luban.Job.Cfg
switch (genType) switch (genType)
{ {
case "data_bin": return "bin"; case "data_bin": return "bin";
case "data_json": case "data_json": return "json";
case "data_json2": return "json";
case "data_lua": return "lua"; case "data_lua": return "lua";
default: throw new Exception($"not support output data type:{genType}"); default: throw new Exception($"not support output data type:{genType}");
} }
@ -168,7 +167,8 @@ namespace Luban.Job.Cfg
errMsg = "--outputcodedir missing"; errMsg = "--outputcodedir missing";
return false; return false;
} }
if (genTypes.Any(t => t.StartsWith("data_", StringComparison.Ordinal))) List<string> dataGenTypes = genTypes.Where(t => t.StartsWith("data_", StringComparison.Ordinal)).ToList();
if (dataGenTypes.Count > 0)
{ {
if (string.IsNullOrWhiteSpace(inputDataDir)) if (string.IsNullOrWhiteSpace(inputDataDir))
{ {
@ -384,7 +384,6 @@ namespace Luban.Job.Cfg
} }
case "data_bin": case "data_bin":
case "data_json": case "data_json":
case "data_json2":
case "data_lua": case "data_lua":
{ {
await CheckLoadCfgDataAsync(); await CheckLoadCfgDataAsync();
@ -787,7 +786,7 @@ namespace {ctx.TopModule}
{ {
allJsonTask.Add(Task.Run(() => allJsonTask.Add(Task.Run(() =>
{ {
return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json2"); return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json");
})); }));
} }
@ -800,7 +799,7 @@ namespace {ctx.TopModule}
{ {
lines.Add(","); lines.Add(",");
} }
lines.Add($"\"{exportTables[i].NeedExport}\":"); lines.Add($"\"{exportTables[i].FullName}\":");
lines.Add(await allJsonTask[i]); lines.Add(await allJsonTask[i]);
} }
lines.Add("}"); lines.Add("}");

View File

@ -30,7 +30,6 @@ namespace Luban.Job.Cfg.Utils
return bytes; return bytes;
} }
case "data_json": case "data_json":
case "data_json2":
{ {
// data_json与data_json2格式区别在于 // data_json与data_json2格式区别在于
// data_json的map格式是 [[key1,value1],[] ..] // data_json的map格式是 [[key1,value1],[] ..]
@ -42,15 +41,7 @@ namespace Luban.Job.Cfg.Utils
SkipValidation = false, SkipValidation = false,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(System.Text.Unicode.UnicodeRanges.All), Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(System.Text.Unicode.UnicodeRanges.All),
}); });
if (dataType == "data_json") Json2Exportor.Ins.WriteAsObject(table, records, table.Assembly, jsonWriter);
{
JsonExportor.Ins.WriteAsArray(records, table.Assembly, jsonWriter);
}
else
{
Json2Exportor.Ins.WriteAsObject(table, records, table.Assembly, jsonWriter);
}
jsonWriter.Flush(); jsonWriter.Flush();
return System.Text.Encoding.UTF8.GetString(DataUtil.StreamToBytes(ss)); return System.Text.Encoding.UTF8.GetString(DataUtil.StreamToBytes(ss));
} }