【调整】config code_cs_unity_editor_json生成的enum类改成普通枚举类。额外生成一个枚举元数据类。
parent
e977a363ef
commit
c0d91dfa81
|
|
@ -19,14 +19,9 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
return "string";
|
return "string";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Accept(TEnum type)
|
|
||||||
{
|
|
||||||
return "string";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Accept(TText type)
|
public override string Accept(TText type)
|
||||||
{
|
{
|
||||||
return "Bright.Config.EditorText";
|
return CfgConstStrings.EditorTextTypeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public override string Accept(TEnum type)
|
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)
|
public override string Accept(TText type)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TEnum type, string json, string x)
|
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)
|
public string Accept(TString type, string json, string x)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TEnum type, string jsonName, string jsonFieldName, string value)
|
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)
|
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)
|
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)
|
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)
|
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)
|
public string Accept(TDateTime type, string jsonName, string jsonFieldName, string value)
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,6 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
{
|
{
|
||||||
public static new CsEditorUnderlyingDefineTypeName Ins { get; } = new CsEditorUnderlyingDefineTypeName();
|
public static new CsEditorUnderlyingDefineTypeName Ins { get; } = new CsEditorUnderlyingDefineTypeName();
|
||||||
|
|
||||||
public override string Accept(TEnum type)
|
|
||||||
{
|
|
||||||
return "string";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Accept(TText type)
|
public override string Accept(TText type)
|
||||||
{
|
{
|
||||||
return CfgConstStrings.EditorTextTypeName;
|
return CfgConstStrings.EditorTextTypeName;
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,28 @@
|
||||||
|
|
||||||
namespace {{x.namespace_with_editor_top_module}}
|
namespace {{x.namespace_with_editor_top_module}}
|
||||||
{
|
{
|
||||||
|
|
||||||
{{~if comment != '' ~}}
|
{{~if comment != '' ~}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{comment | html.escape}}
|
/// {{comment | html.escape}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{~end~}}
|
{{~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 ~}}
|
{{~ for item in items ~}}
|
||||||
public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");
|
public static readonly {{itemType}} {{item.name}} = new {{itemType}}("{{item.name}}", "{{item.alias}}", {{item.int_value}}, "{{item.comment}}");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue