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+ }
0 commit comments