Skip to content

Commit b2bce28

Browse files
committed
[修改]1. 修改协议导出函数抽象
1 parent 6956f36 commit b2bce28

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

ProtoExport/Program.cs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace GameFrameX.ProtoExport
44
{
55
internal static class Program
66
{
7-
private static IProtoGenerateHelper ProtoGenerateHelper;
8-
97
private static int Main(string[] args)
108
{
119
var launcherOptions = Parser.Default.ParseArguments<LauncherOptions>(args).Value;
@@ -21,46 +19,7 @@ private static int Main(string[] args)
2119
return 1;
2220
}
2321

24-
if (!Directory.Exists(launcherOptions.OutputPath))
25-
{
26-
Directory.CreateDirectory(launcherOptions.OutputPath);
27-
}
28-
29-
30-
var types = typeof(IProtoGenerateHelper).Assembly.GetTypes();
31-
foreach (var type in types)
32-
{
33-
var attrs = type.GetCustomAttributes(typeof(ModeAttribute), true);
34-
if (attrs?.Length > 0 && (attrs[0] is ModeAttribute modeAttribute) && modeAttribute.Mode == modeType)
35-
{
36-
ProtoGenerateHelper = (IProtoGenerateHelper)Activator.CreateInstance(type);
37-
break;
38-
}
39-
}
40-
41-
var files = Directory.GetFiles(launcherOptions.InputPath, "*.proto", SearchOption.AllDirectories);
42-
43-
var messageInfoLists = new List<MessageInfoList>(files.Length);
44-
foreach (var file in files)
45-
{
46-
var operationCodeInfo = MessageHelper.Parse(File.ReadAllText(file), Path.GetFileNameWithoutExtension(file), launcherOptions.OutputPath, launcherOptions.IsGenerateErrorCode);
47-
messageInfoLists.Add(operationCodeInfo);
48-
switch (modeType)
49-
{
50-
case ModeType.Server:
51-
case ModeType.Unity:
52-
ProtoGenerateHelper?.Run(operationCodeInfo, launcherOptions.OutputPath, launcherOptions.NamespaceName);
53-
break;
54-
case ModeType.TypeScript:
55-
ProtoGenerateHelper?.Run(operationCodeInfo, launcherOptions.OutputPath, Path.GetFileNameWithoutExtension(file));
56-
break;
57-
default:
58-
throw new ArgumentOutOfRangeException();
59-
}
60-
}
61-
62-
ProtoGenerateHelper?.Post(messageInfoLists, launcherOptions.OutputPath);
63-
22+
ProtoBufMessageHandler.Start(launcherOptions, modeType);
6423

6524
Console.WriteLine("导出成功,按任意键退出");
6625
Console.ReadKey();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace GameFrameX.ProtoExport;
2+
3+
public static class ProtoBufMessageHandler
4+
{
5+
private static IProtoGenerateHelper ProtoGenerateHelper;
6+
7+
public static void Start(LauncherOptions launcherOptions, ModeType modeType)
8+
{
9+
if (!Directory.Exists(launcherOptions.OutputPath))
10+
{
11+
Directory.CreateDirectory(launcherOptions.OutputPath);
12+
}
13+
14+
var types = typeof(IProtoGenerateHelper).Assembly.GetTypes();
15+
foreach (var type in types)
16+
{
17+
var attrs = type.GetCustomAttributes(typeof(ModeAttribute), true);
18+
if (attrs?.Length > 0 && (attrs[0] is ModeAttribute modeAttribute) && modeAttribute.Mode == modeType)
19+
{
20+
ProtoGenerateHelper = (IProtoGenerateHelper)Activator.CreateInstance(type);
21+
break;
22+
}
23+
}
24+
25+
var files = Directory.GetFiles(launcherOptions.InputPath, "*.proto", SearchOption.AllDirectories);
26+
27+
var messageInfoLists = new List<MessageInfoList>(files.Length);
28+
foreach (var file in files)
29+
{
30+
var operationCodeInfo = MessageHelper.Parse(File.ReadAllText(file), Path.GetFileNameWithoutExtension(file), launcherOptions.OutputPath, launcherOptions.IsGenerateErrorCode);
31+
messageInfoLists.Add(operationCodeInfo);
32+
switch (modeType)
33+
{
34+
case ModeType.Server:
35+
case ModeType.Unity:
36+
ProtoGenerateHelper?.Run(operationCodeInfo, launcherOptions.OutputPath, launcherOptions.NamespaceName);
37+
break;
38+
case ModeType.TypeScript:
39+
ProtoGenerateHelper?.Run(operationCodeInfo, launcherOptions.OutputPath, Path.GetFileNameWithoutExtension(file));
40+
break;
41+
default:
42+
throw new ArgumentOutOfRangeException();
43+
}
44+
}
45+
46+
ProtoGenerateHelper?.Post(messageInfoLists, launcherOptions.OutputPath);
47+
}
48+
}

0 commit comments

Comments
 (0)