【调整】config code_cs_unity_editor_json生成的enum类改成普通枚举类。额外生成一个枚举元数据类。

main
walon 2022-02-24 11:10:10 +08:00
parent e977a363ef
commit c0d91dfa81
6 changed files with 24 additions and 18 deletions

View File

@ -19,14 +19,9 @@ namespace Luban.Job.Cfg.TypeVisitors
return "string";
}
public override string Accept(TEnum type)
{
return "string";
}
public override string Accept(TText type)
{
return "Bright.Config.EditorText";
return CfgConstStrings.EditorTextTypeName;
}
}
}

View File

@ -15,7 +15,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public override string Accept(TEnum type)
{
return $"\"{(type.DefineEnum.Items.Count > 0 ? type.DefineEnum.Items[0].Name : "")}\"";
return $"{(type.DefineEnum.Items.Count > 0 ? $"{type.Apply(CsEditorDefineTypeName.Ins)}."+type.DefineEnum.Items[0].Name : "default")}";
}
public override string Accept(TText type)

View File

@ -61,7 +61,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TEnum type, string json, string x)
{
return $"if(!{json}.IsString) {{ throw new SerializationException(); }} {x} = {json};";
return $"if({json}.IsString) {{ {x} = ({type.Apply(CsEditorDefineTypeName.Ins)})System.Enum.Parse(typeof({type.Apply(CsEditorDefineTypeName.Ins)}), {json}); }} else if({json}.IsNumber) {{ {x} = ({type.Apply(CsEditorDefineTypeName.Ins)})(int){json}; }} else {{ throw new SerializationException(); }} ";
}
public string Accept(TString type, string json, string x)

View File

@ -61,7 +61,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TEnum type, string jsonName, string jsonFieldName, string value)
{
return $"{jsonName}[\"{jsonFieldName}\"] = new JSONString({value});";
return $"{jsonName}[\"{jsonFieldName}\"] = new JSONNumber((int){value});";
}
public string Accept(TString type, string jsonName, string jsonFieldName, string value)
@ -81,17 +81,17 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TVector2 type, string jsonName, string jsonFieldName, string value)
{
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.X; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.Y; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.x; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.y; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
}
public string Accept(TVector3 type, string jsonName, string jsonFieldName, string value)
{
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.X; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.Y; __vjson[\"z\"] = {value}{(type.IsNullable ? ".Value" : "")}.Z; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.x; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.y; __vjson[\"z\"] = {value}{(type.IsNullable ? ".Value" : "")}.z; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
}
public string Accept(TVector4 type, string jsonName, string jsonFieldName, string value)
{
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.X; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.Y; __vjson[\"z\"] = {value}{(type.IsNullable ? ".Value" : "")}.Z; __vjson[\"w\"] = {value}{(type.IsNullable ? ".Value" : "")}.W; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
return $"{{ var __vjson = new JSONObject(); __vjson[\"x\"] = {value}{(type.IsNullable ? ".Value" : "")}.x; __vjson[\"y\"] = {value}{(type.IsNullable ? ".Value" : "")}.y; __vjson[\"z\"] = {value}{(type.IsNullable ? ".Value" : "")}.z; __vjson[\"w\"] = {value}{(type.IsNullable ? ".Value" : "")}.w; {jsonName}[\"{jsonFieldName}\"] = __vjson; }}";
}
public string Accept(TDateTime type, string jsonName, string jsonFieldName, string value)

View File

@ -12,11 +12,6 @@ namespace Luban.Job.Cfg.TypeVisitors
{
public static new CsEditorUnderlyingDefineTypeName Ins { get; } = new CsEditorUnderlyingDefineTypeName();
public override string Accept(TEnum type)
{
return "string";
}
public override string Accept(TText type)
{
return CfgConstStrings.EditorTextTypeName;

View File

@ -7,12 +7,28 @@
namespace {{x.namespace_with_editor_top_module}}
{
{{~if comment != '' ~}}
/// <summary>
/// {{comment | html.escape}}
/// </summary>
{{~end~}}
public static partial class {{name}}
{{~if x.is_flags~}}
[System.Flags]
{{~end~}}
public enum {{name}}
{
{{~ for item in items ~}}
{{~if item.comment != '' ~}}
/// <summary>
/// {{item.escape_comment}}
/// </summary>
{{~end~}}
{{item.name}} = {{item.value}},
{{~end~}}
}
public static partial class {{name}}_Metadata
{
{{~ for item in items ~}}
public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");