【特性】cfg新增data_json2格式。 与data_json区别在于 data_json的map导出成[[k1,v1], ...] 而data_json2的map导出格式为 { k1:v1, ... }
parent
b3eaee60ca
commit
d47094a130
|
|
@ -0,0 +1,56 @@
|
||||||
|
using Luban.Job.Cfg.Datas;
|
||||||
|
using Luban.Job.Cfg.Defs;
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Cfg.DataExporters
|
||||||
|
{
|
||||||
|
class Json2Exportor : JsonExportor
|
||||||
|
{
|
||||||
|
public new static Json2Exportor Ins { get; } = new();
|
||||||
|
|
||||||
|
public override void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
||||||
|
{
|
||||||
|
var keyType = type.Type.KeyType;
|
||||||
|
if (keyType is not TString
|
||||||
|
&& keyType is not TInt
|
||||||
|
&& keyType is not TLong)
|
||||||
|
{
|
||||||
|
throw new Exception($"data_json2格式只支持key为int,long,string类型的map");
|
||||||
|
}
|
||||||
|
x.WriteStartObject();
|
||||||
|
foreach (var d in type.Datas)
|
||||||
|
{
|
||||||
|
switch (d.Key)
|
||||||
|
{
|
||||||
|
case DString ds:
|
||||||
|
{
|
||||||
|
x.WritePropertyName(ds.Value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DInt di:
|
||||||
|
{
|
||||||
|
x.WritePropertyName(di.Value.ToString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DLong dl:
|
||||||
|
{
|
||||||
|
x.WritePropertyName(dl.Value.ToString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new Exception($"data_json2格式只支持key为int,long,string类型的map");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.Value.Apply(this, ass, x);
|
||||||
|
}
|
||||||
|
x.WriteEndObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -150,7 +150,7 @@ namespace Luban.Job.Cfg.DataExporters
|
||||||
WriteList(type.Datas, ass, x);
|
WriteList(type.Datas, ass, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
public virtual void Accept(DMap type, DefAssembly ass, Utf8JsonWriter x)
|
||||||
{
|
{
|
||||||
x.WriteStartArray();
|
x.WriteStartArray();
|
||||||
foreach (var d in type.Datas)
|
foreach (var d in type.Datas)
|
||||||
|
|
|
||||||
|
|
@ -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_python27_json,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,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_python27_json,code_python3_json,code_typescript_bin,code_typescript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic . 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")]
|
||||||
|
|
@ -128,7 +128,8 @@ namespace Luban.Job.Cfg
|
||||||
switch (genType)
|
switch (genType)
|
||||||
{
|
{
|
||||||
case "data_bin": return "bin";
|
case "data_bin": return "bin";
|
||||||
case "data_json": return "json";
|
case "data_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}");
|
||||||
}
|
}
|
||||||
|
|
@ -385,6 +386,7 @@ 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();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,11 @@ namespace Luban.Job.Cfg.Utils
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
case "data_json":
|
case "data_json":
|
||||||
|
case "data_json2":
|
||||||
{
|
{
|
||||||
|
// data_json与data_json2格式区别在于
|
||||||
|
// data_json的map格式是 [[key1,value1],[] ..]
|
||||||
|
// data_json2的map格式是 { key1:value1, ...}
|
||||||
var ss = new MemoryStream();
|
var ss = new MemoryStream();
|
||||||
var jsonWriter = new Utf8JsonWriter(ss, new JsonWriterOptions()
|
var jsonWriter = new Utf8JsonWriter(ss, new JsonWriterOptions()
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +42,15 @@ 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),
|
||||||
});
|
});
|
||||||
JsonExportor.Ins.WriteList(records, table.Assembly, jsonWriter);
|
if (dataType == "data_json")
|
||||||
|
{
|
||||||
|
JsonExportor.Ins.WriteList(records, table.Assembly, jsonWriter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
Json2Exportor.Ins.WriteList(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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue