Skip to content

Commit 09f5f82

Browse files
committed
[增加]1. 增加协议导出工具
1 parent b2bce28 commit 09f5f82

File tree

14 files changed

+426
-0
lines changed

14 files changed

+426
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.idea
22
ProtoExport/obj
33
ProtoExport/bin
4+
ToolGUI/bin
5+
ToolGUI/obj
6+
*.user

GameFrameX.Tools.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtoExport", "ProtoExport\ProtoExport.csproj", "{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}"
44
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolGUI", "ToolGUI\ToolGUI.csproj", "{986FC612-FC98-41DD-894F-9DE6A55C9728}"
6+
EndProject
57
Global
68
GlobalSection(SolutionConfigurationPlatforms) = preSolution
79
Debug|Any CPU = Debug|Any CPU
@@ -12,5 +14,9 @@ Global
1214
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
1315
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
1416
{DF321DFA-1AB7-4135-8A6F-7A788F3D4DDC}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{986FC612-FC98-41DD-894F-9DE6A55C9728}.Release|Any CPU.Build.0 = Release|Any CPU
1521
EndGlobalSection
1622
EndGlobal

ToolGUI/App.axaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="ToolGUI.App"
4+
xmlns:local="using:ToolGUI"
5+
RequestedThemeVariant="Default">
6+
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
7+
8+
<Application.DataTemplates>
9+
<local:ViewLocator/>
10+
</Application.DataTemplates>
11+
12+
<Application.Styles>
13+
<FluentTheme />
14+
</Application.Styles>
15+
</Application>

ToolGUI/App.axaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Data.Core;
4+
using Avalonia.Data.Core.Plugins;
5+
using System.Linq;
6+
using Avalonia.Markup.Xaml;
7+
using ToolGUI.ViewModels;
8+
using ToolGUI.Views;
9+
10+
namespace ToolGUI;
11+
12+
public partial class App : Application
13+
{
14+
public override void Initialize()
15+
{
16+
AvaloniaXamlLoader.Load(this);
17+
}
18+
19+
public override void OnFrameworkInitializationCompleted()
20+
{
21+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
22+
{
23+
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
24+
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
25+
DisableAvaloniaDataAnnotationValidation();
26+
desktop.MainWindow = new MainWindow
27+
{
28+
DataContext = new MainWindowViewModel(),
29+
};
30+
}
31+
32+
base.OnFrameworkInitializationCompleted();
33+
}
34+
35+
private void DisableAvaloniaDataAnnotationValidation()
36+
{
37+
// Get an array of plugins to remove
38+
var dataValidationPluginsToRemove =
39+
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
40+
41+
// remove each entry found
42+
foreach (var plugin in dataValidationPluginsToRemove)
43+
{
44+
BindingPlugins.DataValidators.Remove(plugin);
45+
}
46+
}
47+
}

ToolGUI/Assets/logo.ico

4.19 KB
Binary file not shown.

ToolGUI/Models/SettingData.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using GameFrameX.ProtoExport;
4+
using Newtonsoft.Json;
5+
6+
namespace ToolGUI.Models;
7+
8+
public class SettingData
9+
{
10+
Dictionary<string, LauncherOptions> Options { get; set; }
11+
12+
public SettingData()
13+
{
14+
Options = new Dictionary<string, LauncherOptions>();
15+
Options.Add("Server", new LauncherOptions { Mode = ModeType.Server.ToString(), IsGenerateErrorCode = true, NamespaceName = "GameFrameX.Proto.Proto", OutputPath = "./../../../../../Server/GameFrameX.Proto/Proto", InputPath = "./../../../../../Protobuf" });
16+
Options.Add("Unity", new LauncherOptions { Mode = ModeType.Unity.ToString(), IsGenerateErrorCode = true, NamespaceName = "Hotfix.Proto", OutputPath = "./../../../../../Unity/Assets/Hotfix/Proto", InputPath = "./../../../../../Protobuf" });
17+
Options.Add("TypeScript", new LauncherOptions { Mode = ModeType.TypeScript.ToString(), IsGenerateErrorCode = true, NamespaceName = "", OutputPath = "./../../../../../Laya/src/gameframex/protobuf", InputPath = "./../../../../../Protobuf" });
18+
}
19+
20+
public static SettingData Instance { get; } = new SettingData();
21+
22+
public static LauncherOptions GetOptions(string mode)
23+
{
24+
if (string.IsNullOrWhiteSpace(mode))
25+
{
26+
return default;
27+
}
28+
29+
return Instance.Options.GetValueOrDefault(mode);
30+
}
31+
32+
public const string SettingPath = "Setting.json";
33+
34+
public static void LoadSetting()
35+
{
36+
if (File.Exists(SettingPath))
37+
{
38+
var json = File.ReadAllText(SettingPath);
39+
Instance.Options = JsonConvert.DeserializeObject<Dictionary<string, LauncherOptions>>(json);
40+
}
41+
}
42+
43+
public static void SaveSetting()
44+
{
45+
File.WriteAllText(SettingPath, JsonConvert.SerializeObject(Instance.Options, Formatting.Indented));
46+
}
47+
}

ToolGUI/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Avalonia;
2+
using System;
3+
4+
namespace ToolGUI;
5+
6+
sealed class Program
7+
{
8+
// Initialization code. Don't use any Avalonia, third-party APIs or any
9+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
10+
// yet and stuff might break.
11+
[STAThread]
12+
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
13+
14+
// Avalonia configuration, don't remove; also used by visual designer.
15+
public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>()
16+
.UsePlatformDetect()
17+
.WithInterFont()
18+
.LogToTrace();
19+
}

ToolGUI/ToolGUI.csproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>disable</Nullable>
6+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
7+
<ApplicationManifest>app.manifest</ApplicationManifest>
8+
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9+
<LangVersion>10</LangVersion>
10+
<PublishSingleFile>true</PublishSingleFile>
11+
<PublishTrimmed>true</PublishTrimmed>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<AvaloniaResource Include="Assets\**" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="Avalonia" Version="11.2.1" />
20+
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
21+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
22+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
23+
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
24+
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
25+
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
26+
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
27+
</PackageReference>
28+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
29+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<ProjectReference Include="..\ProtoExport\ProtoExport.csproj" />
34+
</ItemGroup>
35+
</Project>

ToolGUI/ViewLocator.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.Templates;
4+
using ToolGUI.ViewModels;
5+
6+
namespace ToolGUI;
7+
8+
public class ViewLocator : IDataTemplate
9+
{
10+
11+
public Control Build(object param)
12+
{
13+
if (param is null)
14+
return null;
15+
16+
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
17+
var type = Type.GetType(name);
18+
19+
if (type != null)
20+
{
21+
return (Control)Activator.CreateInstance(type)!;
22+
}
23+
24+
return new TextBlock { Text = "Not Found: " + name };
25+
}
26+
27+
public bool Match(object data)
28+
{
29+
return data is ViewModelBase;
30+
}
31+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace ToolGUI.ViewModels;
2+
3+
public partial class MainWindowViewModel : ViewModelBase
4+
{
5+
public string Greeting { get; } = "Welcome to Avalonia!";
6+
}

0 commit comments

Comments
 (0)