diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorDefineTypeName.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorDefineTypeName.cs
index 0904a01..2036128 100644
--- a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorDefineTypeName.cs
+++ b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorDefineTypeName.cs
@@ -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;
}
}
}
diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorInitValueVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorInitValueVisitor.cs
index e010e85..ed1c2c8 100644
--- a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorInitValueVisitor.cs
+++ b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorInitValueVisitor.cs
@@ -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)
diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonLoad.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonLoad.cs
index 84971bd..86cdf81 100644
--- a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonLoad.cs
+++ b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonLoad.cs
@@ -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)
diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonSave.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonSave.cs
index 62804de..a33ff1e 100644
--- a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonSave.cs
+++ b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorJsonSave.cs
@@ -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)
diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorUnderlyingDefineTypeName.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorUnderlyingDefineTypeName.cs
index 5babbec..a7ac694 100644
--- a/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorUnderlyingDefineTypeName.cs
+++ b/src/Luban.Job.Cfg/Source/TypeVisitors/CsEditorUnderlyingDefineTypeName.cs
@@ -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;
diff --git a/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl b/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl
index 625dc7b..8d4a8ed 100644
--- a/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl
+++ b/src/Luban.Server/Templates/config/cs_unity_editor_json/enum.tpl
@@ -7,12 +7,28 @@
namespace {{x.namespace_with_editor_top_module}}
{
+
{{~if comment != '' ~}}
///
/// {{comment | html.escape}}
///
{{~end~}}
- public static partial class {{name}}
+ {{~if x.is_flags~}}
+ [System.Flags]
+ {{~end~}}
+ public enum {{name}}
+ {
+ {{~ for item in items ~}}
+{{~if item.comment != '' ~}}
+ ///
+ /// {{item.escape_comment}}
+ ///
+{{~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}}");